From: Peter Zijlstra <peterz@infradead.org>
To: peterz@infradead.org, mingo@kernel.org, will@kernel.org,
a.darwish@linutronix.de
Cc: tglx@linutronix.de, paulmck@kernel.org, bigeasy@linutronix.de,
rostedt@goodmis.org, linux-kernel@vger.kernel.org,
corbet@lwn.net, davem@davemloft.net, netdev@vger.kernel.org,
linux-doc@vger.kernel.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition
Date: Wed, 29 Jul 2020 15:52:51 +0200 [thread overview]
Message-ID: <20200729140142.347671778@infradead.org> (raw)
In-Reply-To: 20200729135249.567415950@infradead.org
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)), \
next prev parent reply other threads:[~2020-07-29 14:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Peter Zijlstra [this message]
2020-07-29 14:38 ` [PATCH 2/5] seqlock: Fold seqcount_LOCKNAME_t definition 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200729140142.347671778@infradead.org \
--to=peterz@infradead.org \
--cc=a.darwish@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).