Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/5] seqlock: Cleanups
@ 2020-07-29 13:52 Peter Zijlstra
2020-07-29 13:52 ` [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g Peter Zijlstra
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Peter Zijlstra @ 2020-07-29 13:52 UTC (permalink / raw)
To: peterz, mingo, will, a.darwish
Cc: tglx, paulmck, bigeasy, rostedt, linux-kernel, corbet, davem,
netdev, linux-doc, viro, linux-fsdevel
Hi,
These are some minor cleanups that go on top of darwi's seqlock patches:
https://lkml.kernel.org/r/20200720155530.1173732-1-a.darwish@linutronix.de
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(-)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g
2020-07-29 13:52 [PATCH 0/5] seqlock: Cleanups Peter Zijlstra
@ 2020-07-29 13:52 ` Peter Zijlstra
2020-07-29 14:29 ` Ahmed S. Darwish
2020-07-29 13:52 ` [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition Peter Zijlstra
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Peter Zijlstra @ 2020-07-29 13:52 UTC (permalink / raw)
To: peterz, mingo, will, a.darwish
Cc: tglx, paulmck, bigeasy, rostedt, linux-kernel, corbet, davem,
netdev, linux-doc, viro, linux-fsdevel
__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.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/seqlock.h | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -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)); \
}
/*
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
2020-07-29 13:52 [PATCH 0/5] seqlock: Cleanups Peter Zijlstra
2020-07-29 13:52 ` [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g Peter Zijlstra
@ 2020-07-29 13:52 ` Peter Zijlstra
2020-07-29 14:38 ` Ahmed S. Darwish
2020-07-29 14:55 ` Matthew Wilcox
2020-07-29 13:52 ` [PATCH 3/5] seqlock: Fold seqcount_LOCKNAME_init() definition Peter Zijlstra
` (2 subsequent siblings)
4 siblings, 2 replies; 12+ messages in thread
From: Peter Zijlstra @ 2020-07-29 13:52 UTC (permalink / raw)
To: peterz, mingo, will, a.darwish
Cc: tglx, paulmck, bigeasy, rostedt, linux-kernel, corbet, davem,
netdev, linux-doc, viro, linux-fsdevel
Manual repetition is boring and error prone.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/seqlock.h | 140 +++++++++++++-----------------------------------
1 file changed, 38 insertions(+), 102 deletions(-)
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -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(seq
lockdep_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)), \
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/5] seqlock: Fold seqcount_LOCKNAME_init() definition
2020-07-29 13:52 [PATCH 0/5] seqlock: Cleanups Peter Zijlstra
2020-07-29 13:52 ` [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g Peter Zijlstra
2020-07-29 13:52 ` [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition Peter Zijlstra
@ 2020-07-29 13:52 ` Peter Zijlstra
2020-07-29 13:52 ` [PATCH 4/5] seqcount: Compress SEQCNT_LOCKNAME_ZERO() Peter Zijlstra
2020-07-29 13:52 ` [PATCH 5/5] seqcount: More consistent seqprop names Peter Zijlstra
4 siblings, 0 replies; 12+ messages in thread
From: Peter Zijlstra @ 2020-07-29 13:52 UTC (permalink / raw)
To: peterz, mingo, will, a.darwish
Cc: tglx, paulmck, bigeasy, rostedt, linux-kernel, corbet, davem,
netdev, linux-doc, viro, linux-fsdevel
Manual repetition is boring and error prone.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/seqlock.h | 61 +++++++++++-------------------------------------
1 file changed, 14 insertions(+), 47 deletions(-)
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -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) \
{ \
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/5] seqcount: Compress SEQCNT_LOCKNAME_ZERO()
2020-07-29 13:52 [PATCH 0/5] seqlock: Cleanups Peter Zijlstra
` (2 preceding siblings ...)
2020-07-29 13:52 ` [PATCH 3/5] seqlock: Fold seqcount_LOCKNAME_init() definition Peter Zijlstra
@ 2020-07-29 13:52 ` Peter Zijlstra
2020-07-29 13:52 ` [PATCH 5/5] seqcount: More consistent seqprop names Peter Zijlstra
4 siblings, 0 replies; 12+ messages in thread
From: Peter Zijlstra @ 2020-07-29 13:52 UTC (permalink / raw)
To: peterz, mingo, will, a.darwish
Cc: tglx, paulmck, bigeasy, rostedt, linux-kernel, corbet, davem,
netdev, linux-doc, viro, linux-fsdevel
Less is more.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/seqlock.h | 63 +++++++++++++-----------------------------------
1 file changed, 18 insertions(+), 45 deletions(-)
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -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))
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/5] seqcount: More consistent seqprop names
2020-07-29 13:52 [PATCH 0/5] seqlock: Cleanups Peter Zijlstra
` (3 preceding siblings ...)
2020-07-29 13:52 ` [PATCH 4/5] seqcount: Compress SEQCNT_LOCKNAME_ZERO() Peter Zijlstra
@ 2020-07-29 13:52 ` Peter Zijlstra
2020-07-29 14:39 ` Ahmed S. Darwish
4 siblings, 1 reply; 12+ messages in thread
From: Peter Zijlstra @ 2020-07-29 13:52 UTC (permalink / raw)
To: peterz, mingo, will, a.darwish
Cc: tglx, paulmck, bigeasy, rostedt, linux-kernel, corbet, davem,
netdev, linux-doc, viro, linux-fsdevel
Attempt uniformity and brevity.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/seqlock.h | 52 ++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 26 deletions(-)
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -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)
{
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g
2020-07-29 13:52 ` [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g Peter Zijlstra
@ 2020-07-29 14:29 ` Ahmed S. Darwish
0 siblings, 0 replies; 12+ messages in thread
From: Ahmed S. Darwish @ 2020-07-29 14:29 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mingo, will, tglx, paulmck, bigeasy, rostedt, linux-kernel,
corbet, davem, netdev, linux-doc, viro, linux-fsdevel
On Wed, Jul 29, 2020 at 03:52:50PM +0200, Peter Zijlstra wrote:
> __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.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
Acked-by: Ahmed S. Darwish <a.darwish@linutronix.de>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
2020-07-29 13:52 ` [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition Peter Zijlstra
@ 2020-07-29 14:38 ` Ahmed S. Darwish
2020-07-29 14:55 ` Matthew Wilcox
1 sibling, 0 replies; 12+ messages in thread
From: Ahmed S. Darwish @ 2020-07-29 14:38 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mingo, will, tglx, paulmck, bigeasy, rostedt, linux-kernel,
corbet, davem, netdev, linux-doc, viro, linux-fsdevel
On Wed, Jul 29, 2020 at 03:52:51PM +0200, Peter Zijlstra wrote:
> Manual repetition is boring and error prone.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
...
> +/**
> + * typedef seqcount_LOCKNAME_t - sequence counter with spinlock associated
^ associated lock
> + * @seqcount: The real sequence counter
> + * @lock: Pointer to the associated spinlock
> + *
^ Pointer to the associated write serialization lock
> + * 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/5] seqcount: More consistent seqprop names
2020-07-29 13:52 ` [PATCH 5/5] seqcount: More consistent seqprop names Peter Zijlstra
@ 2020-07-29 14:39 ` Ahmed S. Darwish
0 siblings, 0 replies; 12+ messages in thread
From: Ahmed S. Darwish @ 2020-07-29 14:39 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mingo, will, tglx, paulmck, bigeasy, rostedt, linux-kernel,
corbet, davem, netdev, linux-doc, viro, linux-fsdevel
On Wed, Jul 29, 2020 at 03:52:54PM +0200, Peter Zijlstra wrote:
> Attempt uniformity and brevity.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
Acked-by: Ahmed S. Darwish <a.darwish@linutronix.de>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
2020-07-29 13:52 ` [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition Peter Zijlstra
2020-07-29 14:38 ` Ahmed S. Darwish
@ 2020-07-29 14:55 ` Matthew Wilcox
2020-07-29 15:33 ` peterz
1 sibling, 1 reply; 12+ messages in thread
From: Matthew Wilcox @ 2020-07-29 14:55 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mingo, will, a.darwish, tglx, paulmck, bigeasy, rostedt,
linux-kernel, corbet, davem, netdev, linux-doc, viro,
linux-fsdevel
On Wed, Jul 29, 2020 at 03:52:51PM +0200, Peter Zijlstra wrote:
> 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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
2020-07-29 14:55 ` Matthew Wilcox
@ 2020-07-29 15:33 ` peterz
2020-07-29 16:19 ` peterz
0 siblings, 1 reply; 12+ messages in thread
From: peterz @ 2020-07-29 15:33 UTC (permalink / raw)
To: Matthew Wilcox
Cc: mingo, will, a.darwish, tglx, paulmck, bigeasy, rostedt,
linux-kernel, corbet, davem, netdev, linux-doc, viro,
linux-fsdevel
On Wed, Jul 29, 2020 at 03:55:07PM +0100, Matthew Wilcox wrote:
> On Wed, Jul 29, 2020 at 03:52:51PM +0200, Peter Zijlstra wrote:
> > 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.
Use ctags and add to scripts/tags.sh.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
2020-07-29 15:33 ` peterz
@ 2020-07-29 16:19 ` peterz
0 siblings, 0 replies; 12+ messages in thread
From: peterz @ 2020-07-29 16:19 UTC (permalink / raw)
To: Matthew Wilcox
Cc: mingo, will, a.darwish, tglx, paulmck, bigeasy, rostedt,
linux-kernel, corbet, davem, netdev, linux-doc, viro,
linux-fsdevel
On Wed, Jul 29, 2020 at 05:33:41PM +0200, peterz@infradead.org wrote:
> On Wed, Jul 29, 2020 at 03:55:07PM +0100, Matthew Wilcox wrote:
> > On Wed, Jul 29, 2020 at 03:52:51PM +0200, Peter Zijlstra wrote:
> > > 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.
>
> Use ctags and add to scripts/tags.sh.
I'll make the below into a proper patch.
---
diff --git a/scripts/tags.sh b/scripts/tags.sh
index 4e18ae5282a6..63b21881a873 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -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/'
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-07-29 16:19 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 13:52 [PATCH 0/5] seqlock: Cleanups Peter Zijlstra
2020-07-29 13:52 ` [PATCH 1/5] seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g Peter Zijlstra
2020-07-29 14:29 ` Ahmed S. Darwish
2020-07-29 13:52 ` [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition Peter Zijlstra
2020-07-29 14:38 ` Ahmed S. Darwish
2020-07-29 14:55 ` Matthew Wilcox
2020-07-29 15:33 ` peterz
2020-07-29 16:19 ` peterz
2020-07-29 13:52 ` [PATCH 3/5] seqlock: Fold seqcount_LOCKNAME_init() definition Peter Zijlstra
2020-07-29 13:52 ` [PATCH 4/5] seqcount: Compress SEQCNT_LOCKNAME_ZERO() Peter Zijlstra
2020-07-29 13:52 ` [PATCH 5/5] seqcount: More consistent seqprop names Peter Zijlstra
2020-07-29 14:39 ` Ahmed S. Darwish
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).