seqlock: Cleanups
Subsystems (5)
Peter Zijlstra
maintainercover seqlock: Cleanups
Hi,
These are some minor cleanups that go on top of darwi's seqlock patches:
https://lkml.kernel.org/r/[email protected]
It's mostly trimming excessive manual repetition and a few naming niggles.
The series has been exposed to 0-day for a while now, so I'm going to push the lot out to tip/locking/core.
[ 0day found a Sparse bug in it's _Generic() implementation that has since been
fixed by Luc ]
--- seqlock.h | 292 +++++++++++++++++--------------------------------------------- 1 file changed, 84 insertions(+), 208 deletions(-)
Peter Zijlstra
maintainerPATCH 1/5 seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g
__SEQ_LOCKDEP() is an expression gate for the seqcount_LOCKNAME_t::lock member. Rename it to be about the member, not the gate condition.
Later (PREEMPT_RT) patches will make the member available for !LOCKDEP configs.
--- include/linux/seqlock.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
include/linux/seqlock.h +10 -10
@@ -133,20 +133,20 @@ static inline void seqcount_lockdep_read*/ #ifdef CONFIG_LOCKDEP -#define __SEQ_LOCKDEP (expr) expr +#define __SEQ_LOCK (expr) expr#else -#define __SEQ_LOCKDEP (expr) +#define __SEQ_LOCK (expr)#endif #define SEQCOUNT_LOCKTYPE_ZERO (seq_name, assoc_lock) { \ .seqcount = SEQCNT_ZERO(seq_name.seqcount), \ - __SEQ_LOCKDEP(.lock = (assoc_lock)) \ + __SEQ_LOCK(.lock = (assoc_lock)) \ }#define seqcount_locktype_init (s, assoc_lock) \ do { \ seqcount_init(&(s)->seqcount); \ - __SEQ_LOCKDEP((s)->lock = (assoc_lock)); \ + __SEQ_LOCK((s)->lock = (assoc_lock)); \ } while (0)/**
@@ -161,7 +161,7 @@ do { \*/ typedef struct seqcount_spinlock {seqcount_t seqcount; - __SEQ_LOCKDEP(spinlock_t *lock); + __SEQ_LOCK(spinlock_t *lock); }seqcount_spinlock_t ;/**
@@ -192,7 +192,7 @@ typedef struct seqcount_spinlock {*/ typedef struct seqcount_raw_spinlock {seqcount_t seqcount; - __SEQ_LOCKDEP(raw_spinlock_t *lock); + __SEQ_LOCK(raw_spinlock_t *lock); }seqcount_raw_spinlock_t ;/**
@@ -223,7 +223,7 @@ typedef struct seqcount_raw_spinlock {*/ typedef struct seqcount_rwlock {seqcount_t seqcount; - __SEQ_LOCKDEP(rwlock_t *lock); + __SEQ_LOCK(rwlock_t *lock); }seqcount_rwlock_t ;/**
@@ -257,7 +257,7 @@ typedef struct seqcount_rwlock {*/ typedef struct seqcount_mutex {seqcount_t seqcount; - __SEQ_LOCKDEP(struct mutex *lock); + __SEQ_LOCK(struct mutex *lock); }seqcount_mutex_t ;/**
@@ -291,7 +291,7 @@ typedef struct seqcount_mutex {*/ typedef struct seqcount_ww_mutex {seqcount_t seqcount; - __SEQ_LOCKDEP(struct ww_mutex *lock); + __SEQ_LOCK(struct ww_mutex *lock); }seqcount_ww_mutex_t ;/**
@@ -329,7 +329,7 @@ __seqcount_##locktype##_preemptible(seqc static inline void \ __seqcount_##locktype##_assert(seqcount_##locktype##_t *s) \ { \ - __SEQ_LOCKDEP(lockdep_assert_held(lockmember)); \ + __SEQ_LOCK(lockdep_assert_held(lockmember)); \ }/*
Re: [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g
Quoted 9 lines · Peter Zijlstra
__SEQ_LOCKDEP()is an expression gate for theseqcount_LOCKNAME_t::lockmember. Rename it to be about the member, not the gate condition.Later (
PREEMPT_RT) patches will make the member available for !LOCKDEP configs.Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
Peter Zijlstra
maintainerPATCH 2/5 seqlock: Fold seqcount_LOCKNAME_t definition
In reply to Peter ZijlstraManual repetition is boring and error prone.
--- include/linux/seqlock.h | 140 +++++++++++++----------------------------------- 1 file changed, 38 insertions(+), 102 deletions(-)
include/linux/seqlock.h +38 -102
@@ -150,21 +150,6 @@ do { \ }while (0 )/** -* typedef seqcount_spinlock_t - sequence counter with spinlock associated -* @seqcount: The real sequence counter -* @lock: Pointer to the associated spinlock -* -* A plain sequence counter with external writer synchronization by a -* spinlock. The spinlock is associated to the sequence count in the -* static initializer or init function. This enables lockdep to validate -* that the write side critical section is properly serialized. -*/ -typedef struct seqcount_spinlock { -seqcount_t seqcount; - __SEQ_LOCK(spinlock_t *lock); -} seqcount_spinlock_t; - -/** * SEQCNT_SPINLOCK_ZERO - static initializer for seqcount_spinlock_t * @name: Name of the seqcount_spinlock_t instance * @lock: Pointer to the associated spinlock
@@ -181,21 +166,6 @@ typedef struct seqcount_spinlock {seqcount_locktype_init (s, lock)/** -* typedef seqcount_raw_spinlock_t - sequence count with raw spinlock associated -* @seqcount: The real sequence counter -* @lock: Pointer to the associated raw spinlock -* -* A plain sequence counter with external writer synchronization by a -* raw spinlock. The raw spinlock is associated to the sequence count in -* the static initializer or init function. This enables lockdep to -* validate that the write side critical section is properly serialized. - */ -typedef struct seqcount_raw_spinlock { -seqcount_t seqcount; - __SEQ_LOCK(raw_spinlock_t *lock); -}seqcount_raw_spinlock_t ; - -/** * SEQCNT_RAW_SPINLOCK_ZERO - static initializer for seqcount_raw_spinlock_t * @name: Name of the seqcount_raw_spinlock_t instance * @lock: Pointer to the associated raw_spinlock
@@ -212,21 +182,6 @@ typedef struct seqcount_raw_spinlock {seqcount_locktype_init (s, lock)/** -* typedef seqcount_rwlock_t - sequence count with rwlock associated -* @seqcount: The real sequence counter -* @lock: Pointer to the associated rwlock -* -* A plain sequence counter with external writer synchronization by a -* rwlock. The rwlock is associated to the sequence count in the static -* initializer or init function. This enables lockdep to validate that -* the write side critical section is properly serialized. - */ -typedef struct seqcount_rwlock { -seqcount_t seqcount; - __SEQ_LOCK(rwlock_t *lock); -}seqcount_rwlock_t ; - -/** * SEQCNT_RWLOCK_ZERO - static initializer for seqcount_rwlock_t * @name: Name of the seqcount_rwlock_t instance * @lock: Pointer to the associated rwlock
@@ -243,24 +198,6 @@ typedef struct seqcount_rwlock {seqcount_locktype_init (s, lock)/** -* typedef seqcount_mutex_t - sequence count with mutex associated -* @seqcount: The real sequence counter -* @lock: Pointer to the associated mutex -* -* A plain sequence counter with external writer synchronization by a -* mutex. The mutex is associated to the sequence counter in the static -* initializer or init function. This enables lockdep to validate that -* the write side critical section is properly serialized. -* -* The write side API functions write_seqcount_begin()/end() automatically -* disable and enable preemption when used with seqcount_mutex_t. - */ -typedef struct seqcount_mutex { -seqcount_t seqcount; - __SEQ_LOCK(struct mutex *lock); -}seqcount_mutex_t ; - -/** * SEQCNT_MUTEX_ZERO - static initializer for seqcount_mutex_t * @name: Name of the seqcount_mutex_t instance * @lock: Pointer to the associated mutex
@@ -277,24 +214,6 @@ typedef struct seqcount_mutex {seqcount_locktype_init (s, lock)/** -* typedef seqcount_ww_mutex_t - sequence count with ww_mutex associated -* @seqcount: The real sequence counter -* @lock: Pointer to the associated ww_mutex -* -* A plain sequence counter with external writer synchronization by a -* ww_mutex. The ww_mutex is associated to the sequence counter in the static -* initializer or init function. This enables lockdep to validate that -* the write side critical section is properly serialized. -* -* The write side API functions write_seqcount_begin()/end() automatically -* disable and enable preemption when used with seqcount_ww_mutex_t. - */ -typedef struct seqcount_ww_mutex { -seqcount_t seqcount; - __SEQ_LOCK(struct ww_mutex *lock); -}seqcount_ww_mutex_t ; - -/** * SEQCNT_WW_MUTEX_ZERO - static initializer for seqcount_ww_mutex_t * @name: Name of the seqcount_ww_mutex_t instance * @lock: Pointer to the associated ww_mutex
@@ -310,30 +229,50 @@ typedef struct seqcount_ww_mutex {#define seqcount_ww_mutex_init (s, lock) \ seqcount_locktype_init(s, lock) -/* -* @preempt: Is the associated write serialization lock preemtpible? +/** +* typedef seqcount_LOCKNAME_t - sequence counter with spinlock associated +* @seqcount: The real sequence counter +* @lock: Pointer to the associated spinlock +* +* A plain sequence counter with external writer synchronization by a +* spinlock. The spinlock is associated to the sequence count in the +* static initializer or init function. This enables lockdep to validate +* that the write side critical section is properly serialized. */ -#define SEQCOUNT_LOCKTYPE (locktype, preempt, lockmember) \ -static inline seqcount_t * \ -__seqcount_##locktype##_ptr(seqcount_##locktype##_t *s) \ + +/* +* SEQCOUNT_LOCKTYPE() - Instantiate seqcount_LOCKNAME_t and helpers +* @locktype: actual typename +* @lockname: name +* @preemptible: preemptibility of above locktype +* @lockmember: argument for lockdep_assert_held() +*/ +#define SEQCOUNT_LOCKTYPE (locktype, lockname, preemptible, lockmember) \ +typedef struct seqcount_##lockname { \ + seqcount_t seqcount; \ + __SEQ_LOCK(locktype *lock); \ +} seqcount_##lockname##_t; \ + \ +static __always_inline seqcount_t * \ +__seqcount_##lockname##_ptr(seqcount_##lockname##_t *s) \ { \ return &s->seqcount; \ } \ \ -static inline bool \ -__seqcount_##locktype##_preemptible(seqcount_##locktype##_t *s) \ +static __always_inline bool \ +__seqcount_##lockname##_preemptible(seqcount_##lockname##_t *s) \ { \ - return preempt; \ + return preemptible; \ } \ \ -static inline void \ -__seqcount_##locktype##_assert(seqcount_##locktype##_t *s) \ +static __always_inline void \ +__seqcount_##lockname##_assert(seqcount_##lockname##_t *s) \ { \ __SEQ_LOCK(lockdep_assert_held(lockmember)); \ }/* -* Similar hooks, but for plain seqcount_t +* __seqprop() for seqcount_t */ static inline seqcount_t *__seqcount_ptr (seqcount_t *s)
@@ -351,17 +290,14 @@ static inline void __seqcount_assert(seqlockdep_assert_preemption_disabled (); } -/* -* @s: Pointer to seqcount_locktype_t, generated hooks first parameter. -*/ -SEQCOUNT_LOCKTYPE(raw_spinlock, false, s->lock) -SEQCOUNT_LOCKTYPE(spinlock, false, s->lock) -SEQCOUNT_LOCKTYPE(rwlock, false, s->lock) -SEQCOUNT_LOCKTYPE(mutex, true, s->lock) -SEQCOUNT_LOCKTYPE(ww_mutex, true, &s->lock->base) +SEQCOUNT_LOCKTYPE(raw_spinlock_t, raw_spinlock, false, s->lock) +SEQCOUNT_LOCKTYPE(spinlock_t, spinlock, false, s->lock) +SEQCOUNT_LOCKTYPE(rwlock_t, rwlock, false, s->lock) +SEQCOUNT_LOCKTYPE(struct mutex, mutex, true, s->lock) +SEQCOUNT_LOCKTYPE(struct ww_mutex, ww_mutex, true, &s->lock->base) -#define __seqprop_case (s, locktype, prop) \ - seqcount_##locktype##_t: __seqcount_##locktype##_##prop((void *)(s)) +#define __seqprop_case (s, lockname, prop) \ + seqcount_##lockname##_t: __seqcount_##lockname##_##prop((void *)(s))#define __seqprop (s, prop) _Generic(*(s), \ seqcount_t: __seqcount_##prop((void *)(s)), \
Re: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
Quoted 4 lines · Peter Zijlstra
Manual repetition is boring and error prone.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
...
Quoted 2 lines
+/**
+ * typedefseqcount_LOCKNAME_t- sequence counter with spinlock associated
^ associated lock
Quoted 3 lines
+ * @seqcount: The real sequence counter
+ * @lock: Pointer to the associated spinlock
+ *
^ Pointer to the associated write serialization lock
Quoted 4 lines
+ * A plain sequence counter with external writer synchronization by a
+ * spinlock. The spinlock is associated to the sequence count in the
+ * static initializer or init function. This enables lockdep to validate
+ * that the write side critical section is properly serialized.
ditto, you forgot to change the associated spinlock language to generic locks ;-)
Thanks,
--
Ahmed S. Darwish
Linutronix GmbH
Re: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
In reply to Peter ZijlstraQuoted 1 line · Peter Zijlstra
Manual repetition is boring and error prone.
Yes, but generated functions are hard to grep for, and I'm pretty sure that kernel-doc doesn't know how to expand macros into comments that it can then extract documentation from.
I've been thinking about how to cure this (mostly in the context of page-flags.h). I don't particularly like the C preprocessor, but m4 is worse and defining our own preprocessing language seems like a terrible idea.
So I was thinking about moving the current contents of page-flags.h to include/src/page-flags.h, making linux/page-flags.h depend on src/page-flags.h and run '$(CPP) -C' to generate it. I've been a little busy recently and haven't had time to do more than muse about this, but I think it might make sense for some of our more heavily macro-templated header files.
[email protected]
maintainerRe: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
Quoted 12 lines · Matthew Wilcox
Quoted 1 line · Peter Zijlstra
Manual repetition is boring and error prone.
Yes, but generated functions are hard to grep for, and I'm pretty sure that kernel-doc doesn't know how to expand macros into comments that it can then extract documentation from.
I've been thinking about how to cure this (mostly in the context of
page-flags.h). I don't particularly like the C preprocessor, but m4 is worse and defining our own preprocessing language seems like a terrible idea.
Quoted 6 lines
So I was thinking about moving the current contents of
page-flags.htoinclude/src/page-flags.h, makinglinux/page-flags.hdepend onsrc/page-flags.hand run '$(CPP) -C' to generate it. I've been a little busy recently and haven't had time to do more than muse about this, but I think it might make sense for some of our more heavily macro-templated header files.
Use ctags and add to scripts/tags.sh.
[email protected]
maintainerRe: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
Quoted 13 lines · On Wed, Jul 29, 2020 at 05:33:41PM +0200, [email protected] wrote:
Quoted 12 lines · Matthew Wilcox
Quoted 1 line · Peter Zijlstra
Manual repetition is boring and error prone.
Yes, but generated functions are hard to grep for, and I'm pretty sure that kernel-doc doesn't know how to expand macros into comments that it can then extract documentation from.
I've been thinking about how to cure this (mostly in the context of
page-flags.h). I don't particularly like the C preprocessor, but m4 is worse and defining our own preprocessing language seems like a terrible idea.
Quoted 8 lines
Quoted 6 lines
So I was thinking about moving the current contents of
page-flags.htoinclude/src/page-flags.h, makinglinux/page-flags.hdepend onsrc/page-flags.hand run '$(CPP) -C' to generate it. I've been a little busy recently and haven't had time to do more than muse about this, but I think it might make sense for some of our more heavily macro-templated header files.Use ctags and add to
scripts/tags.sh.
I'll make the below into a proper patch.
---
scripts/tags.sh +2 -0
@@ -211,6 +211,8 @@ regex_c=( '/\<DEVICE_ATTR_\(RW\|RO\|WO\)(\([[:alnum:]_]\+\)/dev_attr_\2/' '/\<DRIVER_ATTR_\(RW\|RO\|WO\)(\([[:alnum:]_]\+\)/driver_attr_\2/' '/\<\(DEFINE\|DECLARE\)_STATIC_KEY_\(TRUE\|FALSE\)\(\|_RO\)(\([[:alnum:]_]\+\)/\4/' + '/^SEQCOUNT_LOCKTYPE(\([^,]*\),[[:space:]]*\([^,]*\),[^)]*)/seqcount_\2_t/' + '/^SEQCOUNT_LOCKTYPE(\([^,]*\),[[:space:]]*\([^,]*\),[^)]*)/seqcount_\2_init/' ) regex_kconfig=( '/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/\2/'
[tip: locking/core] seqlock,tags: Add support for SEQCOUNT_LOCKTYPE()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 6eb6d05958f3208b3dd2b5311f1a6e68abdbe5d5 Gitweb: https://git.kernel.org/tip/6eb6d05958f3208b3dd2b5311f1a6e68abdbe5d5 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 29 Jul 2020 20:12:32 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 26 Aug 2020 12:42:01 +02:00
seqlock,tags: Add support for SEQCOUNT_LOCKTYPE()
Such that we might easily find seqcount_LOCKTYPE_t and seqcount_LOCKTYPE_init().
--- scripts/tags.sh | 2 ++ 1 file changed, 2 insertions(+)
scripts/tags.sh +2 -0
@@ -201,6 +201,8 @@ regex_c=( '/\<DEVICE_ATTR_\(RW\|RO\|WO\)(\([[:alnum:]_]\+\)/dev_attr_\2/' '/\<DRIVER_ATTR_\(RW\|RO\|WO\)(\([[:alnum:]_]\+\)/driver_attr_\2/' '/\<\(DEFINE\|DECLARE\)_STATIC_KEY_\(TRUE\|FALSE\)\(\|_RO\)(\([[:alnum:]_]\+\)/\4/' + '/^SEQCOUNT_LOCKTYPE(\([^,]*\),[[:space:]]*\([^,]*\),[^)]*)/seqcount_\2_t/' + '/^SEQCOUNT_LOCKTYPE(\([^,]*\),[[:space:]]*\([^,]*\),[^)]*)/seqcount_\2_init/' ) regex_kconfig=( '/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/\2/'
Peter Zijlstra
maintainerPATCH 3/5 seqlock: Fold seqcount_LOCKNAME_init() definition
In reply to Peter ZijlstraManual repetition is boring and error prone.
--- include/linux/seqlock.h | 61 +++++++++++------------------------------------- 1 file changed, 14 insertions(+), 47 deletions(-)
include/linux/seqlock.h +14 -47
@@ -143,12 +143,6 @@ static inline void seqcount_lockdep_read __SEQ_LOCK(.lock = (assoc_lock)) \ } -#define seqcount_locktype_init (s, assoc_lock) \ -do { \ - seqcount_init(&(s)->seqcount); \ - __SEQ_LOCK((s)->lock = (assoc_lock)); \ -} while (0) -/** * SEQCNT_SPINLOCK_ZERO - static initializer for seqcount_spinlock_t * @name: Name of the seqcount_spinlock_t instance
@@ -158,14 +152,6 @@ do { \SEQCOUNT_LOCKTYPE_ZERO (name, lock)/** -* seqcount_spinlock_init - runtime initializer for seqcount_spinlock_t -* @s: Pointer to the seqcount_spinlock_t instance -* @lock: Pointer to the associated spinlock - */ -#define seqcount_spinlock_init (s, lock) \ - seqcount_locktype_init(s, lock) - -/** * SEQCNT_RAW_SPINLOCK_ZERO - static initializer for seqcount_raw_spinlock_t * @name: Name of the seqcount_raw_spinlock_t instance * @lock: Pointer to the associated raw_spinlock
@@ -174,14 +160,6 @@ do { \SEQCOUNT_LOCKTYPE_ZERO (name, lock)/** -* seqcount_raw_spinlock_init - runtime initializer for seqcount_raw_spinlock_t -* @s: Pointer to the seqcount_raw_spinlock_t instance -* @lock: Pointer to the associated raw_spinlock - */ -#define seqcount_raw_spinlock_init (s, lock) \ - seqcount_locktype_init(s, lock) - -/** * SEQCNT_RWLOCK_ZERO - static initializer for seqcount_rwlock_t * @name: Name of the seqcount_rwlock_t instance * @lock: Pointer to the associated rwlock
@@ -190,14 +168,6 @@ do { \SEQCOUNT_LOCKTYPE_ZERO (name, lock)/** -* seqcount_rwlock_init - runtime initializer for seqcount_rwlock_t -* @s: Pointer to the seqcount_rwlock_t instance -* @lock: Pointer to the associated rwlock - */ -#define seqcount_rwlock_init (s, lock) \ - seqcount_locktype_init(s, lock) - -/** * SEQCNT_MUTEX_ZERO - static initializer for seqcount_mutex_t * @name: Name of the seqcount_mutex_t instance * @lock: Pointer to the associated mutex
@@ -206,14 +176,6 @@ do { \SEQCOUNT_LOCKTYPE_ZERO (name, lock)/** -* seqcount_mutex_init - runtime initializer for seqcount_mutex_t -* @s: Pointer to the seqcount_mutex_t instance -* @lock: Pointer to the associated mutex - */ -#define seqcount_mutex_init (s, lock) \ - seqcount_locktype_init(s, lock) - -/** * SEQCNT_WW_MUTEX_ZERO - static initializer for seqcount_ww_mutex_t * @name: Name of the seqcount_ww_mutex_t instance * @lock: Pointer to the associated ww_mutex
@@ -222,15 +184,7 @@ do { \SEQCOUNT_LOCKTYPE_ZERO (name, lock)/** -* seqcount_ww_mutex_init - runtime initializer for seqcount_ww_mutex_t -* @s: Pointer to the seqcount_ww_mutex_t instance -* @lock: Pointer to the associated ww_mutex - */ -#define seqcount_ww_mutex_init (s, lock) \ - seqcount_locktype_init(s, lock) - -/** -* typedef seqcount_LOCKNAME_t - sequence counter with spinlock associated +* typedef seqcount_LOCKNAME_t - sequence counter with LOCKTYPR associated * @seqcount: The real sequence counter * @lock: Pointer to the associated spinlock *
@@ -240,6 +194,12 @@ do { \* that the write side critical section is properly serialized. */ +/** +* seqcount_LOCKNAME_init() - runtime initializer for seqcount_LOCKNAME_t +* @s: Pointer to the seqcount_LOCKNAME_t instance +* @lock: Pointer to the associated LOCKTYPE +*/ +/* * SEQCOUNT_LOCKTYPE() - Instantiate seqcount_LOCKNAME_t and helpers * @locktype: actual typename
@@ -253,6 +213,13 @@ typedef struct seqcount_##lockname {__SEQ_LOCK (locktype *lock); \ } seqcount_##lockname##_t; \ \ +static __always_inline void \ +seqcount_##lockname##_init(seqcount_##lockname##_t *s, locktype *lock) \ +{ \ + seqcount_init(&s->seqcount); \ + __SEQ_LOCK(s->lock = lock); \ +} \ + \ static __always_inline seqcount_t * \ __seqcount_##lockname##_ptr(seqcount_##lockname##_t *s) \ { \
Peter Zijlstra
maintainerPATCH 4/5 seqcount: Compress SEQCNT_LOCKNAME_ZERO()
In reply to Peter ZijlstraLess is more.
--- include/linux/seqlock.h | 63 +++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-)
include/linux/seqlock.h +18 -45
@@ -138,51 +138,6 @@ static inline void seqcount_lockdep_read#define __SEQ_LOCK (expr)#endif -#define SEQCOUNT_LOCKTYPE_ZERO (seq_name, assoc_lock) { \ - .seqcount = SEQCNT_ZERO(seq_name.seqcount), \ - __SEQ_LOCK(.lock = (assoc_lock)) \ -} - -/** -* SEQCNT_SPINLOCK_ZERO - static initializer for seqcount_spinlock_t -* @name: Name of the seqcount_spinlock_t instance -* @lock: Pointer to the associated spinlock -*/ -#define SEQCNT_SPINLOCK_ZERO (name, lock) \ - SEQCOUNT_LOCKTYPE_ZERO(name, lock) - -/** -* SEQCNT_RAW_SPINLOCK_ZERO - static initializer for seqcount_raw_spinlock_t -* @name: Name of the seqcount_raw_spinlock_t instance -* @lock: Pointer to the associated raw_spinlock -*/ -#define SEQCNT_RAW_SPINLOCK_ZERO (name, lock) \ - SEQCOUNT_LOCKTYPE_ZERO(name, lock) - -/** -* SEQCNT_RWLOCK_ZERO - static initializer for seqcount_rwlock_t -* @name: Name of the seqcount_rwlock_t instance -* @lock: Pointer to the associated rwlock -*/ -#define SEQCNT_RWLOCK_ZERO (name, lock) \ - SEQCOUNT_LOCKTYPE_ZERO(name, lock) - -/** -* SEQCNT_MUTEX_ZERO - static initializer for seqcount_mutex_t -* @name: Name of the seqcount_mutex_t instance -* @lock: Pointer to the associated mutex -*/ -#define SEQCNT_MUTEX_ZERO (name, lock) \ - SEQCOUNT_LOCKTYPE_ZERO(name, lock) - -/** -* SEQCNT_WW_MUTEX_ZERO - static initializer for seqcount_ww_mutex_t -* @name: Name of the seqcount_ww_mutex_t instance -* @lock: Pointer to the associated ww_mutex -*/ -#define SEQCNT_WW_MUTEX_ZERO (name, lock) \ - SEQCOUNT_LOCKTYPE_ZERO(name, lock) -/** * typedef seqcount_LOCKNAME_t - sequence counter with LOCKTYPR associated * @seqcount: The real sequence counter
@@ -263,6 +218,24 @@ SEQCOUNT_LOCKTYPE(rwlock_t, rwlock, fa SEQCOUNT_LOCKTYPE(struct mutex, mutex, true, s->lock) SEQCOUNT_LOCKTYPE(struct ww_mutex, ww_mutex, true, &s->lock->base) +/** +* SEQCNT_LOCKNAME_ZERO - static initializer for seqcount_LOCKNAME_t +* @name: Name of the seqcount_LOCKNAME_t instance +* @lock: Pointer to the associated LOCKTYPE +*/ + +#define SEQCOUNT_LOCKTYPE_ZERO (seq_name, assoc_lock) { \ + .seqcount = SEQCNT_ZERO(seq_name.seqcount), \ + __SEQ_LOCK(.lock = (assoc_lock)) \ +} + +#define SEQCNT_SPINLOCK_ZERO (name, lock) SEQCOUNT_LOCKTYPE_ZERO(name, lock) +#define SEQCNT_RAW_SPINLOCK_ZERO (name, lock) SEQCOUNT_LOCKTYPE_ZERO(name, lock) +#define SEQCNT_RWLOCK_ZERO (name, lock) SEQCOUNT_LOCKTYPE_ZERO(name, lock) +#define SEQCNT_MUTEX_ZERO (name, lock) SEQCOUNT_LOCKTYPE_ZERO(name, lock) +#define SEQCNT_WW_MUTEX_ZERO (name, lock) SEQCOUNT_LOCKTYPE_ZERO(name, lock) + +#define __seqprop_case (s, lockname, prop) \ seqcount_##lockname##_t: __seqcount_##lockname##_##prop((void *)(s))
Peter Zijlstra
maintainerPATCH 5/5 seqcount: More consistent seqprop names
In reply to Peter ZijlstraAttempt uniformity and brevity.
--- include/linux/seqlock.h | 52 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-)
include/linux/seqlock.h +26 -26
@@ -247,9 +247,9 @@ SEQCOUNT_LOCKTYPE(struct ww_mutex, ww_mu __seqprop_case((s), mutex, prop), \ __seqprop_case((s), ww_mutex, prop)) -#define __to_seqcount_t (s) __seqprop(s, ptr) -#define __associated_lock_exists_and_is_preemptible (s) __seqprop(s, preemptible) -#define __assert_write_section_is_protected (s) __seqprop(s, assert) +#define __seqcount_ptr (s) __seqprop(s, ptr) +#define __seqcount_lock_preemptible (s) __seqprop(s, preemptible) +#define __seqcount_assert_lock_held (s) __seqprop(s, assert)/** * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier
@@ -266,7 +266,7 @@ SEQCOUNT_LOCKTYPE(struct ww_mutex, ww_mu* Return: count to be passed to read_seqcount_retry() */ #define __read_seqcount_begin (s) \ - __read_seqcount_t_begin(__to_seqcount_t(s)) + __read_seqcount_t_begin(__seqcount_ptr(s))static inline unsigned __read_seqcount_t_begin (const seqcount_t *s) {
@@ -289,7 +289,7 @@ static inline unsigned __read_seqcount_t* Return: count to be passed to read_seqcount_retry() */ #define raw_read_seqcount_begin (s) \ - raw_read_seqcount_t_begin(__to_seqcount_t(s)) + raw_read_seqcount_t_begin(__seqcount_ptr(s))static inline unsigned raw_read_seqcount_t_begin (const seqcount_t *s) {
@@ -305,7 +305,7 @@ static inline unsigned raw_read_seqcount* Return: count to be passed to read_seqcount_retry() */ #define read_seqcount_begin (s) \ - read_seqcount_t_begin(__to_seqcount_t(s)) + read_seqcount_t_begin(__seqcount_ptr(s))static inline unsigned read_seqcount_t_begin (const seqcount_t *s) {
@@ -325,7 +325,7 @@ static inline unsigned read_seqcount_t_b* Return: count to be passed to read_seqcount_retry() */ #define raw_read_seqcount (s) \ - raw_read_seqcount_t(__to_seqcount_t(s)) + raw_read_seqcount_t(__seqcount_ptr(s))static inline unsigned raw_read_seqcount_t (const seqcount_t *s) {
@@ -353,7 +353,7 @@ static inline unsigned raw_read_seqcount* Return: count to be passed to read_seqcount_retry() */ #define raw_seqcount_begin (s) \ - raw_seqcount_t_begin(__to_seqcount_t(s)) + raw_seqcount_t_begin(__seqcount_ptr(s))static inline unsigned raw_seqcount_t_begin (const seqcount_t *s) {
@@ -380,7 +380,7 @@ static inline unsigned raw_seqcount_t_be* Return: true if a read section retry is required, else false */ #define __read_seqcount_retry (s, start) \ - __read_seqcount_t_retry(__to_seqcount_t(s), start) + __read_seqcount_t_retry(__seqcount_ptr(s), start)static inline int __read_seqcount_t_retry (const seqcount_t *s,unsigned start) {
@@ -400,7 +400,7 @@ static inline int __read_seqcount_t_retr* Return: true if a read section retry is required, else false */ #define read_seqcount_retry (s, start) \ - read_seqcount_t_retry(__to_seqcount_t(s), start) + read_seqcount_t_retry(__seqcount_ptr(s), start)static inline int read_seqcount_t_retry (const seqcount_t *s,unsigned start) {
@@ -414,10 +414,10 @@ static inline int read_seqcount_t_retry(*/ #define raw_write_seqcount_begin (s) \ do { \ - if (__associated_lock_exists_and_is_preemptible(s)) \ + if (__seqcount_lock_preemptible(s)) \ preempt_disable(); \ \ - raw_write_seqcount_t_begin(__to_seqcount_t(s)); \ + raw_write_seqcount_t_begin(__seqcount_ptr(s)); \ } while (0)static inline void raw_write_seqcount_t_begin (seqcount_t *s)
@@ -433,9 +433,9 @@ static inline void raw_write_seqcount_t_*/ #define raw_write_seqcount_end (s) \ do { \ - raw_write_seqcount_t_end(__to_seqcount_t(s)); \ + raw_write_seqcount_t_end(__seqcount_ptr(s)); \ \ - if (__associated_lock_exists_and_is_preemptible(s)) \ + if (__seqcount_lock_preemptible(s)) \ preempt_enable(); \ } while (0)
@@ -456,12 +456,12 @@ static inline void raw_write_seqcount_t_*/ #define write_seqcount_begin_nested (s, subclass) \ do { \ - __assert_write_section_is_protected(s); \ + __seqcount_assert_lock_held(s); \ \ - if (__associated_lock_exists_and_is_preemptible(s)) \ + if (__seqcount_lock_preemptible(s)) \ preempt_disable(); \ \ - write_seqcount_t_begin_nested(__to_seqcount_t(s), subclass); \ + write_seqcount_t_begin_nested(__seqcount_ptr(s), subclass); \ } while (0)static inline void write_seqcount_t_begin_nested (seqcount_t *s,int subclass)
@@ -483,12 +483,12 @@ static inline void write_seqcount_t_begi*/ #define write_seqcount_begin (s) \ do { \ - __assert_write_section_is_protected(s); \ + __seqcount_assert_lock_held(s); \ \ - if (__associated_lock_exists_and_is_preemptible(s)) \ + if (__seqcount_lock_preemptible(s)) \ preempt_disable(); \ \ - write_seqcount_t_begin(__to_seqcount_t(s)); \ + write_seqcount_t_begin(__seqcount_ptr(s)); \ } while (0)static inline void write_seqcount_t_begin (seqcount_t *s)
@@ -504,9 +504,9 @@ static inline void write_seqcount_t_begi*/ #define write_seqcount_end (s) \ do { \ - write_seqcount_t_end(__to_seqcount_t(s)); \ + write_seqcount_t_end(__seqcount_ptr(s)); \ \ - if (__associated_lock_exists_and_is_preemptible(s)) \ + if (__seqcount_lock_preemptible(s)) \ preempt_enable(); \ } while (0)
@@ -558,7 +558,7 @@ static inline void write_seqcount_t_end(* } */ #define raw_write_seqcount_barrier (s) \ - raw_write_seqcount_t_barrier(__to_seqcount_t(s)) + raw_write_seqcount_t_barrier(__seqcount_ptr(s))static inline void raw_write_seqcount_t_barrier (seqcount_t *s) {
@@ -578,7 +578,7 @@ static inline void raw_write_seqcount_t_* will complete successfully and see data older than this. */ #define write_seqcount_invalidate (s) \ - write_seqcount_t_invalidate(__to_seqcount_t(s)) + write_seqcount_t_invalidate(__seqcount_ptr(s))static inline void write_seqcount_t_invalidate (seqcount_t *s) {
@@ -604,7 +604,7 @@ static inline void write_seqcount_t_inva* checked with read_seqcount_retry(). */ #define raw_read_seqcount_latch (s) \ - raw_read_seqcount_t_latch(__to_seqcount_t(s)) + raw_read_seqcount_t_latch(__seqcount_ptr(s))static inline int raw_read_seqcount_t_latch (seqcount_t *s) {
@@ -695,7 +695,7 @@ static inline int raw_read_seqcount_t_la* patterns to manage the lifetimes of the objects within. */ #define raw_write_seqcount_latch (s) \ - raw_write_seqcount_t_latch(__to_seqcount_t(s)) + raw_write_seqcount_t_latch(__seqcount_ptr(s))static inline void raw_write_seqcount_t_latch (seqcount_t *s) {
Re: [PATCH 5/5] seqcount: More consistent seqprop names
Quoted 4 lines · Peter Zijlstra
Attempt uniformity and brevity.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>---