Re: [patch 22/63] locking/spinlock: Split the lock types header

From: Waiman Long
Date: Wed Aug 04 2021 - 17:17:42 EST


On 7/30/21 9:50 AM, Thomas Gleixner wrote:
From: Thomas Gleixner <tglx@xxxxxxxxxxxxx>

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 <tglx@xxxxxxxxxxxxx>
---
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