From: Thomas Gleixner <[email protected]>
Move raw_spinlock into its own file. Prepare for RT 'sleeping spinlocks' to
avoid header recursion as RT locks require rtmutex.h which in turn requires
the raw spinlock types.
No functional change.
Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/rwlock_types.h | 4 ++
include/linux/spinlock.h | 4 ++
include/linux/spinlock_types.h | 19 ----------
include/linux/spinlock_types_raw.h | 65 +++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 18 deletions(-)
create mode 100644 include/linux/spinlock_types_raw.h
---
--- a/include/linux/rwlock_types.h
+++ b/include/linux/rwlock_types.h
@@ -1,6 +1,10 @@
#ifndef __LINUX_RWLOCK_TYPES_H
#define __LINUX_RWLOCK_TYPES_H
+#if !defined(__LINUX_SPINLOCK_TYPES_H)
+# error "Do not include directly, include spinlock_types.h"
+#endif
+
/*
* include/linux/rwlock_types.h - generic rwlock type definitions
* and initializers
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -12,6 +12,8 @@
* asm/spinlock_types.h: contains the arch_spinlock_t/arch_rwlock_t and the
* initializers
*
+ * linux/spinlock_types_raw:
+ * The raw types and initializers
* linux/spinlock_types.h:
* defines the generic type and initializers
*
@@ -31,6 +33,8 @@
* contains the generic, simplified UP spinlock type.
* (which is an empty structure on non-debug builds)
*
+ * linux/spinlock_types_raw:
+ * The raw RT types and initializers
* linux/spinlock_types.h:
* defines the generic type and initializers
*
--- a/include/linux/spinlock_types.h
+++ b/include/linux/spinlock_types.h
@@ -9,24 +9,7 @@
* Released under the General Public License (GPL).
*/
-#if defined(CONFIG_SMP)
-# include <asm/spinlock_types.h>
-#else
-# include <linux/spinlock_types_up.h>
-#endif
-
-#include <linux/lockdep_types.h>
-
-typedef struct raw_spinlock {
- arch_spinlock_t raw_lock;
-#ifdef CONFIG_DEBUG_SPINLOCK
- unsigned int magic, owner_cpu;
- void *owner;
-#endif
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
- struct lockdep_map dep_map;
-#endif
-} raw_spinlock_t;
+#include <linux/spinlock_types_raw.h>
#define SPINLOCK_MAGIC 0xdead4ead
--- /dev/null
+++ b/include/linux/spinlock_types_raw.h
@@ -0,0 +1,65 @@
+#ifndef __LINUX_SPINLOCK_TYPES_RAW_H
+#define __LINUX_SPINLOCK_TYPES_RAW_H
+
+#include <linux/types.h>
+
+#if defined(CONFIG_SMP)
+# include <asm/spinlock_types.h>
+#else
+# include <linux/spinlock_types_up.h>
+#endif
+
+#include <linux/lockdep_types.h>
+
+typedef struct raw_spinlock {
+ arch_spinlock_t raw_lock;
+#ifdef CONFIG_DEBUG_SPINLOCK
+ unsigned int magic, owner_cpu;
+ void *owner;
+#endif
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ struct lockdep_map dep_map;
+#endif
+} raw_spinlock_t;
+
+#define SPINLOCK_MAGIC 0xdead4ead
+
+#define SPINLOCK_OWNER_INIT ((void *)-1L)
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+# define RAW_SPIN_DEP_MAP_INIT(lockname) \
+ .dep_map = { \
+ .name = #lockname, \
+ .wait_type_inner = LD_WAIT_SPIN, \
+ }
+# define SPIN_DEP_MAP_INIT(lockname) \
+ .dep_map = { \
+ .name = #lockname, \
+ .wait_type_inner = LD_WAIT_CONFIG, \
+ }
+#else
+# define RAW_SPIN_DEP_MAP_INIT(lockname)
+# define SPIN_DEP_MAP_INIT(lockname)
+#endif
+
+#ifdef CONFIG_DEBUG_SPINLOCK
+# define SPIN_DEBUG_INIT(lockname) \
+ .magic = SPINLOCK_MAGIC, \
+ .owner_cpu = -1, \
+ .owner = SPINLOCK_OWNER_INIT,
+#else
+# define SPIN_DEBUG_INIT(lockname)
+#endif
+
+#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
+{ \
+ .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
+ SPIN_DEBUG_INIT(lockname) \
+ RAW_SPIN_DEP_MAP_INIT(lockname) }
+
+#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
+ (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
+
+#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
+
+#endif
On 7/30/21 9:50 AM, Thomas Gleixner wrote:
> From: Thomas Gleixner <[email protected]>
>
> Move raw_spinlock into its own file. Prepare for RT 'sleeping spinlocks' to
> avoid header recursion as RT locks require rtmutex.h which in turn requires
> the raw spinlock types.
>
> No functional change.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> include/linux/rwlock_types.h | 4 ++
> include/linux/spinlock.h | 4 ++
> include/linux/spinlock_types.h | 19 ----------
> include/linux/spinlock_types_raw.h | 65 +++++++++++++++++++++++++++++++++++++
> 4 files changed, 74 insertions(+), 18 deletions(-)
> create mode 100644 include/linux/spinlock_types_raw.h
> ---
> --- a/include/linux/rwlock_types.h
> +++ b/include/linux/rwlock_types.h
> @@ -1,6 +1,10 @@
> #ifndef __LINUX_RWLOCK_TYPES_H
> #define __LINUX_RWLOCK_TYPES_H
>
> +#if !defined(__LINUX_SPINLOCK_TYPES_H)
> +# error "Do not include directly, include spinlock_types.h"
> +#endif
> +
> /*
> * include/linux/rwlock_types.h - generic rwlock type definitions
> * and initializers
> --- a/include/linux/spinlock.h
> +++ b/include/linux/spinlock.h
> @@ -12,6 +12,8 @@
> * asm/spinlock_types.h: contains the arch_spinlock_t/arch_rwlock_t and the
> * initializers
> *
> + * linux/spinlock_types_raw:
> + * The raw types and initializers
> * linux/spinlock_types.h:
> * defines the generic type and initializers
> *
> @@ -31,6 +33,8 @@
> * contains the generic, simplified UP spinlock type.
> * (which is an empty structure on non-debug builds)
> *
> + * linux/spinlock_types_raw:
> + * The raw RT types and initializers
> * linux/spinlock_types.h:
> * defines the generic type and initializers
> *
> --- a/include/linux/spinlock_types.h
> +++ b/include/linux/spinlock_types.h
> @@ -9,24 +9,7 @@
> * Released under the General Public License (GPL).
> */
>
> -#if defined(CONFIG_SMP)
> -# include <asm/spinlock_types.h>
> -#else
> -# include <linux/spinlock_types_up.h>
> -#endif
> -
> -#include <linux/lockdep_types.h>
> -
> -typedef struct raw_spinlock {
> - arch_spinlock_t raw_lock;
> -#ifdef CONFIG_DEBUG_SPINLOCK
> - unsigned int magic, owner_cpu;
> - void *owner;
> -#endif
> -#ifdef CONFIG_DEBUG_LOCK_ALLOC
> - struct lockdep_map dep_map;
> -#endif
> -} raw_spinlock_t;
> +#include <linux/spinlock_types_raw.h>
>
> #define SPINLOCK_MAGIC 0xdead4ead
>
Most of the code in spinlock_types.h are moved into
spinlock_types_raw.h. However, macros like SPINLOCK_MAGIC and those that
followed are not removed from spinlock_types.h in this patch leading to
the same set of macro definitions in two different files. Should we
eliminate the duplicate macro definitions either from spinlock_types.h
or from spinlock_types_raw.h?
Cheers,
Longman
On Wed, Aug 04 2021 at 17:17, Waiman Long wrote:
> On 7/30/21 9:50 AM, Thomas Gleixner wrote:
>> From: Thomas Gleixner <[email protected]>
>>
>
> Most of the code in spinlock_types.h are moved into
> spinlock_types_raw.h. However, macros like SPINLOCK_MAGIC and those that
> followed are not removed from spinlock_types.h in this patch leading to
> the same set of macro definitions in two different files. Should we
> eliminate the duplicate macro definitions either from spinlock_types.h
> or from spinlock_types_raw.h?
Right you are.