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

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20161103145021.28528-13-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
drivers/base/cacheinfo.c

index e9fd32e91668992e478f31423c1e56be0724e1d2..47983a2ba6216f3e51c20fc2c2e6ef23b45183bc 100644 (file)
@@ -498,57 +498,30 @@ err:
        return rc;
 }
 
-static void cache_remove_dev(unsigned int cpu)
+static int cacheinfo_cpu_online(unsigned int cpu)
 {
-       if (!cpumask_test_cpu(cpu, &cache_dev_map))
-               return;
-       cpumask_clear_cpu(cpu, &cache_dev_map);
+       int rc = detect_cache_attributes(cpu);
 
-       cpu_cache_sysfs_exit(cpu);
+       if (rc)
+               return rc;
+       rc = cache_add_dev(cpu);
+       if (rc)
+               free_cache_attributes(cpu);
+       return rc;
 }
 
-static int cacheinfo_cpu_callback(struct notifier_block *nfb,
-                                 unsigned long action, void *hcpu)
+static int cacheinfo_cpu_pre_down(unsigned int cpu)
 {
-       unsigned int cpu = (unsigned long)hcpu;
-       int rc = 0;
-
-       switch (action & ~CPU_TASKS_FROZEN) {
-       case CPU_ONLINE:
-               rc = detect_cache_attributes(cpu);
-               if (!rc)
-                       rc = cache_add_dev(cpu);
-               break;
-       case CPU_DEAD:
-               cache_remove_dev(cpu);
-               free_cache_attributes(cpu);
-               break;
-       }
-       return notifier_from_errno(rc);
+       if (cpumask_test_and_clear_cpu(cpu, &cache_dev_map))
+               cpu_cache_sysfs_exit(cpu);
+
+       free_cache_attributes(cpu);
+       return 0;
 }
 
 static int __init cacheinfo_sysfs_init(void)
 {
-       int cpu, rc = 0;
-
-       cpu_notifier_register_begin();
-
-       for_each_online_cpu(cpu) {
-               rc = detect_cache_attributes(cpu);
-               if (rc)
-                       goto out;
-               rc = cache_add_dev(cpu);
-               if (rc) {
-                       free_cache_attributes(cpu);
-                       pr_err("error populating cacheinfo..cpu%d\n", cpu);
-                       goto out;
-               }
-       }
-       __hotcpu_notifier(cacheinfo_cpu_callback, 0);
-
-out:
-       cpu_notifier_register_done();
-       return rc;
+       return cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "base/cacheinfo:online",
+                                cacheinfo_cpu_online, cacheinfo_cpu_pre_down);
 }
-
 device_initcall(cacheinfo_sysfs_init);