* [PATCH] seqlock: annotate spinning as unlikely() in __read_seqcount_begin
@ 2023-07-27 18:03 Mateusz Guzik
2024-11-20 11:11 ` Christian Brauner
0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Guzik @ 2023-07-27 18:03 UTC (permalink / raw)
To: peterz; +Cc: linux-kernel, Mateusz Guzik
Annotation already used to be there, but got lost in 52ac39e5db5148f7
("seqlock: seqcount_t: Implement all read APIs as statement expressions").
Does not look like it was intentional.
Without it gcc 12 decides to compile the following in path_init:
nd->m_seq = __read_seqcount_begin(&mount_lock.seqcount);
nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
into 2 cases of conditional jumps forward if the value is even, aka
branch prediction miss by default in the common case on x86-64.
With the patch jumps are only for odd values.
before:
[snip]
mov 0x104fe96(%rip),%eax # 0xffffffff82409680 <mount_lock>
test $0x1,%al
je 0xffffffff813b97fa <path_init+122>
pause
mov 0x104fe8a(%rip),%eax # 0xffffffff82409680 <mount_lock>
test $0x1,%al
jne 0xffffffff813b97ee <path_init+110>
mov %eax,0x48(%rbx)
mov 0x104fdfd(%rip),%eax # 0xffffffff82409600 <rename_lock>
test $0x1,%al
je 0xffffffff813b9813 <path_init+147>
pause
mov 0x104fdf1(%rip),%eax # 0xffffffff82409600 <rename_lock>
test $0x1,%al
jne 0xffffffff813b9807 <path_init+135>
[/snip]
after:
[snip]
mov 0x104fec6(%rip),%eax # 0xffffffff82409680 <mount_lock>
test $0x1,%al
jne 0xffffffff813b99af <path_init+607>
mov %eax,0x48(%rbx)
mov 0x104fe35(%rip),%eax # 0xffffffff82409600 <rename_lock>
test $0x1,%al
jne 0xffffffff813b999d <path_init+589>
[/snip]
Interestingly .text gets slightly smaller (as reported by size(1)):
before: 20702563
after: 20702429
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
include/linux/seqlock.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index 987a59d977c5..225eb1db35b8 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -326,7 +326,7 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, s->lock, mutex
({ \
unsigned __seq; \
\
- while ((__seq = seqprop_sequence(s)) & 1) \
+ while (unlikely((__seq = seqprop_sequence(s)) & 1)) \
cpu_relax(); \
\
kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX); \
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] seqlock: annotate spinning as unlikely() in __read_seqcount_begin
2023-07-27 18:03 [PATCH] seqlock: annotate spinning as unlikely() in __read_seqcount_begin Mateusz Guzik
@ 2024-11-20 11:11 ` Christian Brauner
0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2024-11-20 11:11 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: Christian Brauner, linux-kernel, peterz
On Thu, 27 Jul 2023 20:03:55 +0200, Mateusz Guzik wrote:
> Annotation already used to be there, but got lost in 52ac39e5db5148f7
> ("seqlock: seqcount_t: Implement all read APIs as statement expressions").
> Does not look like it was intentional.
>
> Without it gcc 12 decides to compile the following in path_init:
> nd->m_seq = __read_seqcount_begin(&mount_lock.seqcount);
> nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
>
> [...]
Applied to the vfs-6.14.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.14.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.14.misc
[1/1] seqlock: annotate spinning as unlikely() in __read_seqcount_begin
https://git.kernel.org/vfs/vfs/c/c795e8ac8471
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-20 11:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-27 18:03 [PATCH] seqlock: annotate spinning as unlikely() in __read_seqcount_begin Mateusz Guzik
2024-11-20 11:11 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox