ring-buffer: use atomic_[set|clear]_mask in place of a cmpxchg loop
Subsystems (2)
PATCH 1/1 ring-buffer: use atomic_[set|clear]_mask in place of a cmpxchg loop
Instead of open-coding the equivalent cmpxchg loop we can just use atomic_set_mask and atomic_clear_mask to atomically OR or AND the value in &buffer->record_disabled.
---
NB: I have only tested this patch on x86_64 by booting with CONFIG_RING_BUFFER_STARTUP_TEST=y.
kernel/trace/ring_buffer.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
kernel/trace/ring_buffer.c +2 -14
@@ -3050,13 +3050,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_enable);*/ void ring_buffer_record_off (struct ring_buffer *buffer) { -unsigned int rd; -unsigned int new_rd; - -do { - rd =atomic_read (&buffer->record_disabled); - new_rd = rd |RB_BUFFER_OFF ; - }while (atomic_cmpxchg (&buffer->record_disabled, rd, new_rd) != rd); +atomic_set_mask (RB_BUFFER_OFF , &buffer->record_disabled); }EXPORT_SYMBOL_GPL (ring_buffer_record_off);
@@ -3073,13 +3067,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_off);*/ void ring_buffer_record_on (struct ring_buffer *buffer) { -unsigned int rd; -unsigned int new_rd; - -do { - rd =atomic_read (&buffer->record_disabled); - new_rd = rd & ~RB_BUFFER_OFF ; - }while (atomic_cmpxchg (&buffer->record_disabled, rd, new_rd) != rd); +atomic_clear_mask (RB_BUFFER_OFF , &buffer->record_disabled); }EXPORT_SYMBOL_GPL (ring_buffer_record_on);
Signature · 1 line
2.1.2.443.g670a3c1
Quoted 50 lines · Patrick Palka
Instead of open-coding the equivalent cmpxchg loop we can just use
atomic_set_maskandatomic_clear_maskto atomically OR or AND the value in&buffer->record_disabled.Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>Signed-off-by Patrick Palka <[email protected]>---
NB: I have only tested this patch on
x86_64by booting withCONFIG_RING_BUFFER_STARTUP_TEST=y.kernel/trace/ring_buffer.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)kernel/trace/ring_buffer.c +2
-15@@ -3050,13 +3050,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_enable);*/ void ring_buffer_record_off (struct ring_buffer *buffer) { -unsigned int rd; -unsigned int new_rd; - -do { - rd =atomic_read (&buffer->record_disabled); - new_rd = rd |RB_BUFFER_OFF ; - }while (atomic_cmpxchg (&buffer->record_disabled, rd, new_rd) != rd); +atomic_set_mask (RB_BUFFER_OFF , &buffer->record_disabled); }EXPORT_SYMBOL_GPL (ring_buffer_record_off);@@ -3073,13 +3067,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_off);*/ void ring_buffer_record_on (struct ring_buffer *buffer) { -unsigned int rd; -unsigned int new_rd; - -do { - rd =atomic_read (&buffer->record_disabled); - new_rd = rd & ~RB_BUFFER_OFF ; - }while (atomic_cmpxchg (&buffer->record_disabled, rd, new_rd) != rd); +atomic_clear_mask (RB_BUFFER_OFF , &buffer->record_disabled); }EXPORT_SYMBOL_GPL (ring_buffer_record_on); --
Quoted 2 lines
2.1.2.443.g670a3c1
It just occurred to me that atomic_clear_mask and atomic_set_mask expect to take an int *, not an atomic_t *, so this patch is bogus... Sorry for the noise.
Quoted 50 lines · Patrick Palka
Quoted 49 lines · Patrick Palka
Instead of open-coding the equivalent cmpxchg loop we can just use
atomic_set_maskandatomic_clear_maskto atomically OR or AND the value in&buffer->record_disabled.Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>Signed-off-by Patrick Palka <[email protected]>---
NB: I have only tested this patch on
x86_64by booting withCONFIG_RING_BUFFER_STARTUP_TEST=y.kernel/trace/ring_buffer.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)kernel/trace/ring_buffer.c +2
-14@@ -3050,13 +3050,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_enable);*/ void ring_buffer_record_off (struct ring_buffer *buffer) { -unsigned int rd; -unsigned int new_rd; - -do { - rd =atomic_read (&buffer->record_disabled); - new_rd = rd |RB_BUFFER_OFF ; - }while (atomic_cmpxchg (&buffer->record_disabled, rd, new_rd) != rd); +atomic_set_mask (RB_BUFFER_OFF , &buffer->record_disabled); }EXPORT_SYMBOL_GPL (ring_buffer_record_off);@@ -3073,13 +3067,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_off);*/ void ring_buffer_record_on (struct ring_buffer *buffer) { -unsigned int rd; -unsigned int new_rd; - -do { - rd =atomic_read (&buffer->record_disabled); - new_rd = rd & ~RB_BUFFER_OFF ; - }while (atomic_cmpxchg (&buffer->record_disabled, rd, new_rd) != rd); +atomic_clear_mask (RB_BUFFER_OFF , &buffer->record_disabled); }EXPORT_SYMBOL_GPL (ring_buffer_record_on);
Quoted 7 lines
Quoted 3 lines
--
2.1.2.443.g670a3c1It just occurred to me that
atomic_clear_maskandatomic_set_maskexpect to take an int *, not anatomic_t*, so this patch is bogus... Sorry for the noise.
Uh, actually, the generic implementations of these functions (defined in include/asm-generic/atomic.h) _do_ take an atomic_t *. It's the specialized x86 definitions of these functions (defined in arch/x86/include/asm/atomic.h) that take (expect) an int *. So this patch is not bogus; the x86 specializations for atomic_clear_mask and atomic_set_mask are. I will try to fix this in a separate patch.