Skip to content

Commit dba4761

Browse files
surenbaghdasaryanakpm00
authored andcommitted
seqlock: add raw_seqcount_try_begin
Add raw_seqcount_try_begin() to opens a read critical section of the given seqcount_t if the counter is even. This enables eliding the critical section entirely if the counter is odd, instead of doing the speculation knowing it will fail. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Suren Baghdasaryan <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Suggested-by: Peter Zijlstra <[email protected]> Cc: Christian Brauner <[email protected]> Cc: David Howells <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Jann Horn <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Mateusz Guzik <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Peter Xu <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Sourav Panda <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wei Yang <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a474d84 commit dba4761

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/linux/seqlock.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex)
318318
__seq; \
319319
})
320320

321+
/**
322+
* raw_seqcount_try_begin() - begin a seqcount_t read critical section
323+
* w/o lockdep and w/o counter stabilization
324+
* @s: Pointer to seqcount_t or any of the seqcount_LOCKNAME_t variants
325+
*
326+
* Similar to raw_seqcount_begin(), except it enables eliding the critical
327+
* section entirely if odd, instead of doing the speculation knowing it will
328+
* fail.
329+
*
330+
* Useful when counter stabilization is more or less equivalent to taking
331+
* the lock and there is a slowpath that does that.
332+
*
333+
* If true, start will be set to the (even) sequence count read.
334+
*
335+
* Return: true when a read critical section is started.
336+
*/
337+
#define raw_seqcount_try_begin(s, start) \
338+
({ \
339+
start = raw_read_seqcount(s); \
340+
!(start & 1); \
341+
})
342+
321343
/**
322344
* raw_seqcount_begin() - begin a seqcount_t read critical section w/o
323345
* lockdep and w/o counter stabilization

0 commit comments

Comments
 (0)