]> git.baikalelectronics.ru Git - kernel.git/commitdiff
epoll: use try_cmpxchg in list_add_tail_lockless
authorUros Bizjak <ubizjak@gmail.com>
Thu, 14 Jul 2022 17:32:55 +0000 (19:32 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 12 Sep 2022 04:55:07 +0000 (21:55 -0700)
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
list_add_tail_lockless.  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://lkml.kernel.org/r/20220714173255.12987-1-ubizjak@gmail.com
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/eventpoll.c

index 8b56b94e2f56f80afff003741c6e78bf4f7c8639..52954d4637b546870eb500c14167be8164522742 100644 (file)
@@ -1065,7 +1065,7 @@ static inline bool list_add_tail_lockless(struct list_head *new,
         * added to the list from another CPU: the winner observes
         * new->next == new.
         */
-       if (cmpxchg(&new->next, new, head) != new)
+       if (!try_cmpxchg(&new->next, &new, head))
                return false;
 
        /*