lib/percpu_counter: Convert to hotplug state machine
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 3 Nov 2016 14:50:00 +0000 (15:50 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 9 Nov 2016 22:45:26 +0000 (23:45 +0100)
Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20161103145021.28528-5-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
include/linux/cpuhotplug.h
lib/percpu_counter.c

index c622ab349af33ac9423648e3f8ef9a56bb875a3e..04e5f99ffc7084c4155727c66ebf849a410e4074 100644 (file)
@@ -33,6 +33,7 @@ enum cpuhp_state {
        CPUHP_FS_BUFF_DEAD,
        CPUHP_PRINTK_DEAD,
        CPUHP_MM_MEMCQ_DEAD,
+       CPUHP_PERCPU_CNT_DEAD,
        CPUHP_WORKQUEUE_PREP,
        CPUHP_POWER_NUMA_PREPARE,
        CPUHP_HRTIMERS_PREPARE,
index 72d36113ccaa8509a7140b506cdc0330690a8b15..c8cebb1370765fac92170cd0d2f8ed1ede0a01da 100644 (file)
@@ -158,25 +158,21 @@ EXPORT_SYMBOL(percpu_counter_destroy);
 int percpu_counter_batch __read_mostly = 32;
 EXPORT_SYMBOL(percpu_counter_batch);
 
-static void compute_batch_value(void)
+static int compute_batch_value(unsigned int cpu)
 {
        int nr = num_online_cpus();
 
        percpu_counter_batch = max(32, nr*2);
+       return 0;
 }
 
-static int percpu_counter_hotcpu_callback(struct notifier_block *nb,
-                                       unsigned long action, void *hcpu)
+static int percpu_counter_cpu_dead(unsigned int cpu)
 {
 #ifdef CONFIG_HOTPLUG_CPU
-       unsigned int cpu;
        struct percpu_counter *fbc;
 
-       compute_batch_value();
-       if (action != CPU_DEAD && action != CPU_DEAD_FROZEN)
-               return NOTIFY_OK;
+       compute_batch_value(cpu);
 
-       cpu = (unsigned long)hcpu;
        spin_lock_irq(&percpu_counters_lock);
        list_for_each_entry(fbc, &percpu_counters, list) {
                s32 *pcount;
@@ -190,7 +186,7 @@ static int percpu_counter_hotcpu_callback(struct notifier_block *nb,
        }
        spin_unlock_irq(&percpu_counters_lock);
 #endif
-       return NOTIFY_OK;
+       return 0;
 }
 
 /*
@@ -222,8 +218,15 @@ EXPORT_SYMBOL(__percpu_counter_compare);
 
 static int __init percpu_counter_startup(void)
 {
-       compute_batch_value();
-       hotcpu_notifier(percpu_counter_hotcpu_callback, 0);
+       int ret;
+
+       ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "lib/percpu_cnt:online",
+                               compute_batch_value, NULL);
+       WARN_ON(ret < 0);
+       ret = cpuhp_setup_state_nocalls(CPUHP_PERCPU_CNT_DEAD,
+                                       "lib/percpu_cnt:dead", NULL,
+                                       percpu_counter_cpu_dead);
+       WARN_ON(ret < 0);
        return 0;
 }
 module_init(percpu_counter_startup);