ledtrig-cpu: Handle CPU hot(un)plugging
authorPawel Moll <pawel.moll@arm.com>
Wed, 22 Jan 2014 16:32:02 +0000 (08:32 -0800)
committerBryan Wu <cooloney@gmail.com>
Thu, 27 Feb 2014 17:56:54 +0000 (09:56 -0800)
When CPU is hot(un)plugged, no syscore notification is being
generated, nor is cpuidle involved. This leaves the CPU LED
turned on, because the dying thread is doing some work (LED on)
and than it is... well, dying (LED still on :-)

Added notifier block for hot(un)plugging operations, generating
existing trigger events.

Signed-off-by: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
drivers/leds/trigger/ledtrig-cpu.c

index 118335eccc563d6944c4dd5a99409e744b5f6018..1c3ee9fcaf34c5a1cb30e0efc1bf8c8109f7dd5b 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/percpu.h>
 #include <linux/syscore_ops.h>
 #include <linux/rwsem.h>
+#include <linux/cpu.h>
 #include "../leds.h"
 
 #define MAX_NAME_LEN   8
@@ -92,6 +93,26 @@ static struct syscore_ops ledtrig_cpu_syscore_ops = {
        .resume         = ledtrig_cpu_syscore_resume,
 };
 
+static int ledtrig_cpu_notify(struct notifier_block *self,
+                                          unsigned long action, void *hcpu)
+{
+       switch (action & ~CPU_TASKS_FROZEN) {
+       case CPU_STARTING:
+               ledtrig_cpu(CPU_LED_START);
+               break;
+       case CPU_DYING:
+               ledtrig_cpu(CPU_LED_STOP);
+               break;
+       }
+
+       return NOTIFY_OK;
+}
+
+
+static struct notifier_block ledtrig_cpu_nb = {
+       .notifier_call = ledtrig_cpu_notify,
+};
+
 static int __init ledtrig_cpu_init(void)
 {
        int cpu;
@@ -113,6 +134,7 @@ static int __init ledtrig_cpu_init(void)
        }
 
        register_syscore_ops(&ledtrig_cpu_syscore_ops);
+       register_cpu_notifier(&ledtrig_cpu_nb);
 
        pr_info("ledtrig-cpu: registered to indicate activity on CPUs\n");
 
@@ -124,6 +146,8 @@ static void __exit ledtrig_cpu_exit(void)
 {
        int cpu;
 
+       unregister_cpu_notifier(&ledtrig_cpu_nb);
+
        for_each_possible_cpu(cpu) {
                struct led_trigger_cpu *trig = &per_cpu(cpu_trig, cpu);