Handle per-subsystem mutexes for CONFIG_HOTPLUG_CPU not set.
PATCH 1/1 Handle per-subsystem mutexes for CONFIG_HOTPLUG_CPU not set.
When CONFIG_HOTPLUG_CPU is not set, lock_cpu_hotplug() and unlock_cpu_hotplug() default to no-ops.
However, in case of the proposed per-subsystem hotcpu mutex scheme, the hotcpu mutexes will be taken/released, even when CONFIG_HOTPLUG_CPU is not set. This is an unnecessary overhead both w.r.t space and time ;-)
This patch
* Provides a common interface for all the subsystems to lock and unlock their per-subsystem hotcpu mutexes.
When CONFIG_HOTPLUG_CPU is not set, these operations would be no-ops.
Usage:
a) Each hotcpu aware subsystem defines the hotcpu_mutex as follows #ifdef CONFIG_HOTPLUG_CPU DEFINE_MUTEX(my_hotcpu_mutex);
#endif
b) The hotcpu aware subsystem usescpuhotplug_mutex_lock(&my_hotcpu_mutex)
andcpuhotplug_mutex_unlock(&my_hotcpu_mutex)
instead of the usual mutex_lock/mutex_unlock.
--- include/linux/cpu.h | 15 +++++++++++++++ 1 files changed, 15 insertions(+)
include/linux/cpu.h +15 -0
@@ -24,6 +24,7 @@#include <linux/compiler.h> #include <linux/cpumask.h> #include <asm/semaphore.h> +#include <linux/mutex.h> struct cpu {int node_id;/* The node which contains the CPU */
@@ -74,6 +75,17 @@ extern struct sysdev_class cpu_sysdev_cl#ifdef CONFIG_HOTPLUG_CPU /* Stop CPUs going up and down. */ + +static inline void cpuhotplug_mutex_lock (struct mutex *cpu_hp_mutex) +{ +mutex_lock (cpu_hp_mutex); +} + +static inline void cpuhotplug_mutex_unlock (struct mutex *cpu_hp_mutex) +{ +mutex_unlock (cpu_hp_mutex); +} +extern void lock_cpu_hotplug (void );extern void unlock_cpu_hotplug (void );#define hotcpu_notifier (fn, pri) { \
@@ -86,6 +98,9 @@ extern void unlock_cpu_hotplug(void);int cpu_down (unsigned int cpu);#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu))#else +#define cpuhotplug_mutex_lock (m) do { } while (0) +#define cpuhotplug_mutex_unlock (m) do { } while (0) +#define lock_cpu_hotplug () do { } while (0)#define unlock_cpu_hotplug () do { } while (0)#define lock_cpu_hotplug_interruptible () 0
Signature · 5 lines
Gautham R Shenoy Linux Technology Center IBM India. "Freedom comes with a price tag of responsibility, which is still a bargain, because Freedom is priceless!"
Quoted 7 lines · On Thu, 23 Nov 2006 18:48:52 +0530 Gautham R Shenoy <[email protected]> wrote:
When
CONFIG_HOTPLUG_CPUis not set,lock_cpu_hotplug()andunlock_cpu_hotplug()default to no-ops.However, in case of the proposed per-subsystem hotcpu mutex scheme, the hotcpu mutexes will be taken/released, even when
CONFIG_HOTPLUG_CPUis not set. This is an unnecessary overhead both w.r.t space and time ;-)
hm.
Quoted 55 lines
This patch
* Provides a common interface for all the subsystems to lock and unlock their per-subsystem hotcpu mutexes.
WhenCONFIG_HOTPLUG_CPUis not set, these operations would be no-ops.Usage:
a) Each hotcpu aware subsystem defines thehotcpu_mutexas follows #ifdefCONFIG_HOTPLUG_CPUDEFINE_MUTEX(my_hotcpu_mutex);
#endifb) The hotcpu aware subsystem uses
cpuhotplug_mutex_lock(&my_hotcpu_mutex)
andcpuhotplug_mutex_unlock(&my_hotcpu_mutex)
instead of the usual mutex_lock/mutex_unlock.Signed-off-by Gautham R Shenoy <[email protected]>--- include/linux/cpu.h | 15 +++++++++++++++ 1 files changed, 15 insertions(+)Index:
hotplug/include/linux/cpu.h
===================================================================include/linux/cpu.h +12
-0@@ -24,6 +24,7 @@#include <linux/compiler.h> #include <linux/cpumask.h> #include <asm/semaphore.h> +#include <linux/mutex.h> struct cpu {int node_id;/* The node which contains the CPU */ @@ -74,6 +75,17 @@ extern struct sysdev_class cpu_sysdev_cl#ifdef CONFIG_HOTPLUG_CPU /* Stop CPUs going up and down. */ + +static inline void cpuhotplug_mutex_lock (struct mutex *cpu_hp_mutex) +{ +mutex_lock (cpu_hp_mutex); +} + +static inline void cpuhotplug_mutex_unlock (struct mutex *cpu_hp_mutex) +{ +mutex_unlock (cpu_hp_mutex); +} +extern void lock_cpu_hotplug (void );extern void unlock_cpu_hotplug (void );#define hotcpu_notifier (fn, pri) { \
include/linux/cpu.h extern void unlock_cpu_hotplug(void); · line 103
Quoted 6 lines
include/linux/cpu.h +3
-0@@ -86,6 +98,9 @@ extern void unlock_cpu_hotplug(void);int cpu_down (unsigned int cpu);#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu))#else +#define cpuhotplug_mutex_lock (m) do { } while (0) +#define cpuhotplug_mutex_unlock (m) do { } while (0) +
But what to do about the now-unneeded mutex?
We can just leave it there if CONFIG_HOTPLUG_CPU=n but then we'll get unused variable warnings for statically-defined mutexes.
To fix that would require either
#ifdef CONFIG_HOTPLUG_CPU
#define DEFINE_MUTEX_HOTPLUG_CPU(m) DEFINE_MUTEX(m) #else
#define DEFINE_MUTEX_HOTPLUG_CPU(m)
#endif
or
#define cpuhotplug_mutex_lock(m) do { (void)(m); } while (0)
Given that the former won't work, I'd suggest the latter ;)
Hi Andrew,
Quoted 17 lines
Quoted 17 lines
Usage:
a) Each hotcpu aware subsystem defines thehotcpu_mutexas follows #ifdefCONFIG_HOTPLUG_CPUDEFINE_MUTEX(my_hotcpu_mutex);
#endifb) The hotcpu aware subsystem uses
cpuhotplug_mutex_lock(&my_hotcpu_mutex)
andcpuhotplug_mutex_unlock(&my_hotcpu_mutex)
instead of the usual mutex_lock/mutex_unlock.Signed-off-by Gautham R Shenoy <[email protected]>--- include/linux/cpu.h | 15 +++++++++++++++
[snip]
Quoted 12 lines
include/linux/cpu.h extern void unlock_cpu_hotplug(void); · line 103
Quoted 9 lines
extern void
unlock_cpu_hotplug(void);
#definehotcpu_notifier(fn, pri){ \include/linux/cpu.h +3
-0@@ -86,6 +98,9 @@ extern void unlock_cpu_hotplug(void);int cpu_down (unsigned int cpu);#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu))#else +#define cpuhotplug_mutex_lock (m) do { } while (0) +#define cpuhotplug_mutex_unlock (m) do { } while (0) +But what to do about the now-unneeded mutex?
Quoted 2 lines
We can just leave it there if
CONFIG_HOTPLUG_CPU=nbut then we'll get unused variable warnings for statically-defined mutexes.
Why even leave it there?
Can't we do something as follows, which has already been suggested in the patch description:
Each hotcpu aware subsystem defines the hotcpu_mutex as follows #ifdef CONFIG_HOTPLUG_CPU
[static] DEFINE_MUTEX(my_hotcpu_mutex);
#endif
That way, we won't be having any unneeded mutexes at all.
Quoted 8 lines
To fix that would require either
#ifdef
CONFIG_HOTPLUG_CPU
#defineDEFINE_MUTEX_HOTPLUG_CPU(m)DEFINE_MUTEX(m)#else
#defineDEFINE_MUTEX_HOTPLUG_CPU(m)
#endif
Yup, this won't work. Wish we could cook up something like this, but alas! Most of these mutexes are defined with the static keyword, which causes compile errors with CONFIG_HOTPLUG_CPU=n.
Quoted 7 lines
or
#define
cpuhotplug_mutex_lock(m)do { (void)(m); } while (0)Given that the former won't work, I'd suggest the latter ;)
regards
gautham.
Signature · 5 lines
Gautham R Shenoy Linux Technology Center IBM India. "Freedom comes with a price tag of responsibility, which is still a bargain, because Freedom is priceless!"
PATCH v2 1/1 Handle per-subsystem mutexes for CONFIG_HOTPLUG_CPU not set.
Quoted 10 lines · Gautham R Shenoy
Quoted 4 lines
But what to do about the now-unneeded mutex?
We can just leave it there if
CONFIG_HOTPLUG_CPU=nbut then we'll get unused variable warnings for statically-defined mutexes.Why even leave it there?
Can't we do something as follows, which has already been suggested in the patch description:
Quoted 6 lines
Each hotcpu aware subsystem defines the
hotcpu_mutexas follows #ifdefCONFIG_HOTPLUG_CPU
[static]DEFINE_MUTEX(my_hotcpu_mutex);
#endifThat way, we won't be having any unneeded mutexes at all.
I take back these words. In addition to the fact that this would introduce more #ifdef noise in .c files, this approach won't work in cases where we will be reusing existing mutexes as hotcpu_mutexes.
Eg: workqueue_mutex in kernel/workqueue.c and cache_chain_mutex in mm/slab.c
Quoted 6 lines
Quoted 6 lines
or
#define
cpuhotplug_mutex_lock(m)do { (void)(m); } while (0)Given that the former won't work, I'd suggest the latter ;)
The patch below implements the latter :)
This patch provides a common interface for all the subsystems to lock and unlock their per-subsystem hotcpu mutexes.
When CONFIG_HOTPLUG_CPU is not set, these operations would be no-ops.
--- include/linux/cpu.h | 15 +++++++++++++++ 1 files changed, 15 insertions(+)
include/linux/cpu.h +15 -0
@@ -24,6 +24,7 @@#include <linux/compiler.h> #include <linux/cpumask.h> #include <asm/semaphore.h> +#include <linux/mutex.h> struct cpu {int node_id;/* The node which contains the CPU */
@@ -74,6 +75,17 @@ extern struct sysdev_class cpu_sysdev_cl#ifdef CONFIG_HOTPLUG_CPU /* Stop CPUs going up and down. */ + +static inline void cpuhotplug_mutex_lock (struct mutex *cpu_hp_mutex) +{ +mutex_lock (cpu_hp_mutex); +} + +static inline void cpuhotplug_mutex_unlock (struct mutex *cpu_hp_mutex) +{ +mutex_unlock (cpu_hp_mutex); +} +extern void lock_cpu_hotplug (void );extern void unlock_cpu_hotplug (void );#define hotcpu_notifier (fn, pri) { \
@@ -86,6 +98,9 @@ extern void unlock_cpu_hotplug(void);int cpu_down (unsigned int cpu);#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu))#else +#define cpuhotplug_mutex_lock (m) do { (void)(m); } while (0) +#define cpuhotplug_mutex_unlock (m) do { (void)(m); } while (0) +#define lock_cpu_hotplug () do { } while (0)#define unlock_cpu_hotplug () do { } while (0)#define lock_cpu_hotplug_interruptible () 0
Signature · 5 lines
Gautham R Shenoy Linux Technology Center IBM India. "Freedom comes with a price tag of responsibility, which is still a bargain, because Freedom is priceless!"