^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Activity LED trigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017 Willy Tarreau <w@1wt.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Partially based on Atsushi Nemoto's ledtrig-heartbeat.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "../leds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static int panic_detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct activity_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct led_classdev *led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u64 last_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u64 last_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int time_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int invert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void led_activity_function(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct activity_data *activity_data = from_timer(activity_data, t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct led_classdev *led_cdev = activity_data->led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned int target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned int usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u64 curr_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u64 curr_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) s32 diff_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) s32 diff_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE, &led_cdev->work_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) led_cdev->blink_brightness = led_cdev->new_blink_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (unlikely(panic_detected)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* full brightness in case of panic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) led_set_brightness_nosleep(led_cdev, led_cdev->blink_brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) cpus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) curr_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct kernel_cpustat kcpustat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) kcpustat_cpu_fetch(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) curr_used += kcpustat.cpustat[CPUTIME_USER]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) + kcpustat.cpustat[CPUTIME_NICE]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) + kcpustat.cpustat[CPUTIME_SYSTEM]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) + kcpustat.cpustat[CPUTIME_SOFTIRQ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) + kcpustat.cpustat[CPUTIME_IRQ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) cpus++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* We come here every 100ms in the worst case, so that's 100M ns of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * cumulated time. By dividing by 2^16, we get the time resolution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * down to 16us, ensuring we won't overflow 32-bit computations below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * even up to 3k CPUs, while keeping divides cheap on smaller systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) curr_boot = ktime_get_boottime_ns() * cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) diff_boot = (curr_boot - activity_data->last_boot) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) diff_used = (curr_used - activity_data->last_used) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) activity_data->last_boot = curr_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) activity_data->last_used = curr_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (diff_boot <= 0 || diff_used < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) usage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) else if (diff_used >= diff_boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) usage = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) usage = 100 * diff_used / diff_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Now we know the total boot_time multiplied by the number of CPUs, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * the total idle+wait time for all CPUs. We'll compare how they evolved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * since last call. The % of overall CPU usage is :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * 1 - delta_idle / delta_boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * What we want is that when the CPU usage is zero, the LED must blink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * slowly with very faint flashes that are detectable but not disturbing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * (typically 10ms every second, or 10ms ON, 990ms OFF). Then we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * blinking frequency to increase up to the point where the load is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * enough to saturate one core in multi-core systems or 50% in single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * core systems. At this point it should reach 10 Hz with a 10/90 duty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * cycle (10ms ON, 90ms OFF). After this point, the blinking frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * remains stable (10 Hz) and only the duty cycle increases to report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * the activity, up to the point where we have 90ms ON, 10ms OFF when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * all cores are saturated. It's important that the LED never stays in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * a steady state so that it's easy to distinguish an idle or saturated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * machine from a hung one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * This gives us :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * - a target CPU usage of min(50%, 100%/#CPU) for a 10% duty cycle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * (10ms ON, 90ms OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * - below target :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * ON_ms = 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * OFF_ms = 90 + (1 - usage/target) * 900
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * - above target :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * ON_ms = 10 + (usage-target)/(100%-target) * 80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * OFF_ms = 90 - (usage-target)/(100%-target) * 80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * In order to keep a good responsiveness, we cap the sleep time to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * 100 ms and keep track of the sleep time left. This allows us to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * quickly change it if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) activity_data->time_left -= 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (activity_data->time_left <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) activity_data->time_left = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) activity_data->state = !activity_data->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) led_set_brightness_nosleep(led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) (activity_data->state ^ activity_data->invert) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) led_cdev->blink_brightness : LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) target = (cpus > 1) ? (100 / cpus) : 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (usage < target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) delay = activity_data->state ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 10 : /* ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 990 - 900 * usage / target; /* OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) delay = activity_data->state ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 10 + 80 * (usage - target) / (100 - target) : /* ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 90 - 80 * (usage - target) / (100 - target); /* OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (!activity_data->time_left || delay <= activity_data->time_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) activity_data->time_left = delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) delay = min_t(int, activity_data->time_left, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mod_timer(&activity_data->timer, jiffies + msecs_to_jiffies(delay));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static ssize_t led_invert_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct activity_data *activity_data = led_trigger_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return sprintf(buf, "%u\n", activity_data->invert);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static ssize_t led_invert_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) const char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct activity_data *activity_data = led_trigger_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned long state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ret = kstrtoul(buf, 0, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) activity_data->invert = !!state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static struct attribute *activity_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) &dev_attr_invert.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ATTRIBUTE_GROUPS(activity_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int activity_activate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct activity_data *activity_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) activity_data = kzalloc(sizeof(*activity_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!activity_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) led_set_trigger_data(led_cdev, activity_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) activity_data->led_cdev = led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) timer_setup(&activity_data->timer, led_activity_function, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!led_cdev->blink_brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) led_cdev->blink_brightness = led_cdev->max_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) led_activity_function(&activity_data->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) set_bit(LED_BLINK_SW, &led_cdev->work_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static void activity_deactivate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct activity_data *activity_data = led_get_trigger_data(led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) del_timer_sync(&activity_data->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) kfree(activity_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) clear_bit(LED_BLINK_SW, &led_cdev->work_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static struct led_trigger activity_led_trigger = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .name = "activity",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .activate = activity_activate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .deactivate = activity_deactivate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .groups = activity_led_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int activity_reboot_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned long code, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) led_trigger_unregister(&activity_led_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int activity_panic_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) unsigned long code, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) panic_detected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static struct notifier_block activity_reboot_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .notifier_call = activity_reboot_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static struct notifier_block activity_panic_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .notifier_call = activity_panic_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int __init activity_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int rc = led_trigger_register(&activity_led_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) atomic_notifier_chain_register(&panic_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) &activity_panic_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) register_reboot_notifier(&activity_reboot_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void __exit activity_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) unregister_reboot_notifier(&activity_reboot_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) atomic_notifier_chain_unregister(&panic_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) &activity_panic_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) led_trigger_unregister(&activity_led_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) module_init(activity_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) module_exit(activity_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) MODULE_AUTHOR("Willy Tarreau <w@1wt.eu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) MODULE_DESCRIPTION("Activity LED trigger");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_LICENSE("GPL v2");