From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Uros Bizjak <ubizjak@gmail.com>,
Mukesh Ojha <quic_mojha@quicinc.com>
Subject: [for-next][PATCH 10/11] ring_buffer: Use try_cmpxchg instead of cmpxchg
Date: Wed, 22 Mar 2023 14:42:49 -0400 [thread overview]
Message-ID: <20230322184335.558195206@goodmis.org> (raw)
In-Reply-To: 20230322184239.594953818@goodmis.org
From: Uros Bizjak <ubizjak@gmail.com>
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old.
x86 CMPXCHG instruction returns success in ZF flag, so this change
saves a compare after cmpxchg (and related move instruction in
front of cmpxchg).
Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
fails. There is no need to re-read the value in the loop.
No functional change intended.
Link: https://lkml.kernel.org/r/20230305155532.5549-4-ubizjak@gmail.com
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Acked-by: Mukesh Ojha <quic_mojha@quicinc.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/ring_buffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 93f854433d89..2d5c3caff32d 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -4057,10 +4057,10 @@ void ring_buffer_record_off(struct trace_buffer *buffer)
unsigned int rd;
unsigned int new_rd;
+ rd = atomic_read(&buffer->record_disabled);
do {
- rd = atomic_read(&buffer->record_disabled);
new_rd = rd | RB_BUFFER_OFF;
- } while (atomic_cmpxchg(&buffer->record_disabled, rd, new_rd) != rd);
+ } while (!atomic_try_cmpxchg(&buffer->record_disabled, &rd, new_rd));
}
EXPORT_SYMBOL_GPL(ring_buffer_record_off);
@@ -4080,10 +4080,10 @@ void ring_buffer_record_on(struct trace_buffer *buffer)
unsigned int rd;
unsigned int new_rd;
+ rd = atomic_read(&buffer->record_disabled);
do {
- rd = atomic_read(&buffer->record_disabled);
new_rd = rd & ~RB_BUFFER_OFF;
- } while (atomic_cmpxchg(&buffer->record_disabled, rd, new_rd) != rd);
+ } while (!atomic_try_cmpxchg(&buffer->record_disabled, &rd, new_rd));
}
EXPORT_SYMBOL_GPL(ring_buffer_record_on);
--
2.39.1
next prev parent reply other threads:[~2023-03-22 18:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 18:42 [for-next][PATCH 00/11] tracing: Updates for 6.4 Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 01/11] ftrace: Let unregister_ftrace_direct_multi() call ftrace_free_filter() Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 02/11] ftrace: Replace uses of _ftrace_direct APIs with _ftrace_direct_multi Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 03/11] ftrace: Remove the legacy _ftrace_direct API Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 04/11] ftrace: Rename _ftrace_direct_multi APIs to _ftrace_direct APIs Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 05/11] ftrace: Store direct called addresses in their ops Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 06/11] ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 07/11] ftrace: selftest: remove broken trace_direct_tramp Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 08/11] ring_buffer: Change some static functions to void Steven Rostedt
2023-03-22 18:42 ` [for-next][PATCH 09/11] ring_buffer: Change some static functions to bool Steven Rostedt
2023-03-22 18:42 ` Steven Rostedt [this message]
2023-03-22 18:42 ` [for-next][PATCH 11/11] ftrace: Show a list of all functions that have ever been enabled Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230322184335.558195206@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=quic_mojha@quicinc.com \
--cc=ubizjak@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox