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

The removal of the files happens now in the prepare down stage as there is
no reason to keep them around until the cpu has actually died.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20161103145021.28528-16-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/ia64/kernel/palinfo.c

index c39c3cd3ac348a414787d4db30ec6c6181f7f6d9..b6e597860888dd554686682d5481a8163fc7c81b 100644 (file)
@@ -932,8 +932,7 @@ static const struct file_operations proc_palinfo_fops = {
        .release        = single_release,
 };
 
-static void
-create_palinfo_proc_entries(unsigned int cpu)
+static int palinfo_add_proc(unsigned int cpu)
 {
        pal_func_cpu_u_t f;
        struct proc_dir_entry *cpu_dir;
@@ -943,7 +942,7 @@ create_palinfo_proc_entries(unsigned int cpu)
 
        cpu_dir = proc_mkdir(cpustr, palinfo_dir);
        if (!cpu_dir)
-               return;
+               return -EINVAL;
 
        f.req_cpu = cpu;
 
@@ -952,42 +951,21 @@ create_palinfo_proc_entries(unsigned int cpu)
                proc_create_data(palinfo_entries[j].name, 0, cpu_dir,
                                 &proc_palinfo_fops, (void *)f.value);
        }
+       return 0;
 }
 
-static void
-remove_palinfo_proc_entries(unsigned int hcpu)
+static int palinfo_del_proc(unsigned int hcpu)
 {
        char cpustr[3+4+1];     /* cpu numbers are up to 4095 on itanic */
+
        sprintf(cpustr, "cpu%d", hcpu);
        remove_proc_subtree(cpustr, palinfo_dir);
+       return 0;
 }
 
-static int palinfo_cpu_callback(struct notifier_block *nfb,
-                                       unsigned long action, void *hcpu)
-{
-       unsigned int hotcpu = (unsigned long)hcpu;
-
-       switch (action) {
-       case CPU_ONLINE:
-       case CPU_ONLINE_FROZEN:
-               create_palinfo_proc_entries(hotcpu);
-               break;
-       case CPU_DEAD:
-       case CPU_DEAD_FROZEN:
-               remove_palinfo_proc_entries(hotcpu);
-               break;
-       }
-       return NOTIFY_OK;
-}
-
-static struct notifier_block __refdata palinfo_cpu_notifier =
-{
-       .notifier_call = palinfo_cpu_callback,
-       .priority = 0,
-};
+static enum cpuhp_state hp_online;
 
-static int __init
-palinfo_init(void)
+static int __init palinfo_init(void)
 {
        int i = 0;
 
@@ -996,25 +974,19 @@ palinfo_init(void)
        if (!palinfo_dir)
                return -ENOMEM;
 
-       cpu_notifier_register_begin();
-
-       /* Create palinfo dirs in /proc for all online cpus */
-       for_each_online_cpu(i) {
-               create_palinfo_proc_entries(i);
+       i = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ia64/palinfo:online",
+                             palinfo_add_proc, palinfo_del_proc);
+       if (i < 0) {
+               remove_proc_subtree("pal", NULL);
+               return i;
        }
-
-       /* Register for future delivery via notify registration */
-       __register_hotcpu_notifier(&palinfo_cpu_notifier);
-
-       cpu_notifier_register_done();
-
+       hp_online = i;
        return 0;
 }
 
-static void __exit
-palinfo_exit(void)
+static void __exit palinfo_exit(void)
 {
-       unregister_hotcpu_notifier(&palinfo_cpu_notifier);
+       cpuhp_remove_state(hp_online);
        remove_proc_subtree("pal", NULL);
 }