* [PATCH] netdev: Use try_cmpxchg in napi_if_scheduled_mark_missed
@ 2022-08-22 14:32 Uros Bizjak
2022-08-25 23:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2022-08-22 14:32 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: Uros Bizjak, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
napi_if_scheduled_mark_missed. 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, enabling further code simplifications.
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
include/linux/netdevice.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 1a3cb93c3dcc..51c916894661 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -546,8 +546,8 @@ static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
{
unsigned long val, new;
+ val = READ_ONCE(n->state);
do {
- val = READ_ONCE(n->state);
if (val & NAPIF_STATE_DISABLE)
return true;
@@ -555,7 +555,7 @@ static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
return false;
new = val | NAPIF_STATE_MISSED;
- } while (cmpxchg(&n->state, val, new) != val);
+ } while (!try_cmpxchg(&n->state, &val, new));
return true;
}
--
2.37.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] netdev: Use try_cmpxchg in napi_if_scheduled_mark_missed
2022-08-22 14:32 [PATCH] netdev: Use try_cmpxchg in napi_if_scheduled_mark_missed Uros Bizjak
@ 2022-08-25 23:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-25 23:10 UTC (permalink / raw)
To: Uros Bizjak; +Cc: netdev, linux-kernel, davem, edumazet, kuba, pabeni
Hello:
This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 22 Aug 2022 16:32:43 +0200 you wrote:
> Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
> napi_if_scheduled_mark_missed. 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, enabling further code simplifications.
>
> [...]
Here is the summary with links:
- netdev: Use try_cmpxchg in napi_if_scheduled_mark_missed
https://git.kernel.org/netdev/net-next/c/b9030780971b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-25 23:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-22 14:32 [PATCH] netdev: Use try_cmpxchg in napi_if_scheduled_mark_missed Uros Bizjak
2022-08-25 23:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).