Skip to content

Commit bdf4fb6

Browse files
ubizjakrostedt
authored andcommitted
ring_buffer: Use try_cmpxchg instead of cmpxchg in rb_insert_pages
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in rb_insert_pages. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). No functional change intended. Link: https://lore.kernel.org/linux-trace-kernel/20230914163420.12923-1-ubizjak@gmail.com Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent a1f157c commit bdf4fb6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

kernel/trace/ring_buffer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer)
20562056
retries = 10;
20572057
success = false;
20582058
while (retries--) {
2059-
struct list_head *head_page, *prev_page, *r;
2059+
struct list_head *head_page, *prev_page;
20602060
struct list_head *last_page, *first_page;
20612061
struct list_head *head_page_with_bit;
20622062
struct buffer_page *hpage = rb_set_head_page(cpu_buffer);
@@ -2075,9 +2075,9 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer)
20752075
last_page->next = head_page_with_bit;
20762076
first_page->prev = prev_page;
20772077

2078-
r = cmpxchg(&prev_page->next, head_page_with_bit, first_page);
2079-
2080-
if (r == head_page_with_bit) {
2078+
/* caution: head_page_with_bit gets updated on cmpxchg failure */
2079+
if (try_cmpxchg(&prev_page->next,
2080+
&head_page_with_bit, first_page)) {
20812081
/*
20822082
* yay, we replaced the page pointer to our new list,
20832083
* now, we just have to update to head page's prev

0 commit comments

Comments
 (0)