* [PATCH] LED: add LED heartbeat trigger
@ 2006-06-20 16:36 Atsushi Nemoto
2006-06-20 16:54 ` Nish Aravamudan
2006-06-21 15:01 ` Atsushi Nemoto
0 siblings, 2 replies; 7+ messages in thread
From: Atsushi Nemoto @ 2006-06-20 16:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Richard Purdie, akpm
Add an LED trigger acts like a heart beat. This can be used as a
replacement of CONFIG_HEARTBEAT code exists in some arch's timer code.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 6265062..21bb7e8 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -87,5 +87,14 @@ config LEDS_TRIGGER_IDE_DISK
This allows LEDs to be controlled by IDE disk activity.
If unsure, say Y.
+config LEDS_TRIGGER_HEARTBEAT
+ tristate "LED Heartbeat Trigger"
+ depends LEDS_TRIGGERS
+ help
+ This allows LEDs to be controlled by a CPU load average.
+ The flash frequency is a hyperbolic function of the 5-minute
+ load average.
+ If unsure, say Y.
+
endmenu
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 40f0426..1dc79b5 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c2
# LED Triggers
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
+obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
new file mode 100644
index 0000000..07ac645
--- /dev/null
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -0,0 +1,118 @@
+/*
+ * LED Heartbeat Trigger
+ *
+ * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
+ *
+ * Based on Richard Purdie's ledtrig-timer.c and some arch's
+ * CONFIG_HEARTBEAT code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/sched.h>
+#include <linux/leds.h>
+#include "leds.h"
+
+struct heartbeat_trig_data {
+ unsigned int phase;
+ unsigned int period;
+ struct timer_list timer;
+};
+
+static void led_heartbeat_function(unsigned long data)
+{
+ struct led_classdev *led_cdev = (struct led_classdev *) data;
+ struct heartbeat_trig_data *heartbeat_data = led_cdev->trigger_data;
+ unsigned long brightness = LED_OFF;
+ unsigned long delay = 0;
+
+ /* acts like an actual heart beat -- ie thump-thump-pause... */
+ switch (heartbeat_data->phase) {
+ case 0:
+ /*
+ * The hyperbolic function below modifies the
+ * heartbeat period length in dependency of the
+ * current (5min) load. It goes through the points
+ * f(0)=126, f(1)=86, f(5)=51, f(inf)->30.
+ */
+ heartbeat_data->period = 30 +
+ (672 << FSHIFT) / (5 * avenrun[0] + (7 << FSHIFT));
+ heartbeat_data->period = heartbeat_data->period * HZ / 100;
+ delay = 7 * HZ / 100;
+ heartbeat_data->phase++;
+ brightness = LED_FULL;
+ break;
+ case 1:
+ delay = heartbeat_data->period / 4 - 7 * HZ / 100;
+ heartbeat_data->phase++;
+ break;
+ case 2:
+ delay = 7 * HZ / 100;
+ heartbeat_data->phase++;
+ brightness = LED_FULL;
+ break;
+ default:
+ delay = heartbeat_data->period - heartbeat_data->period / 4 -
+ 7 * HZ / 100;
+ heartbeat_data->phase = 0;
+ break;
+ }
+
+ led_set_brightness(led_cdev, brightness);
+ mod_timer(&heartbeat_data->timer, jiffies + delay);
+}
+
+static void heartbeat_trig_activate(struct led_classdev *led_cdev)
+{
+ struct heartbeat_trig_data *heartbeat_data;
+
+ heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL);
+ if (!heartbeat_data)
+ return;
+
+ led_cdev->trigger_data = heartbeat_data;
+ init_timer(&heartbeat_data->timer);
+ heartbeat_data->timer.function = led_heartbeat_function;
+ heartbeat_data->timer.data = (unsigned long) led_cdev;
+ heartbeat_data->phase = 0;
+ led_heartbeat_function(heartbeat_data->timer.data);
+}
+
+static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
+{
+ struct heartbeat_trig_data *heartbeat_data = led_cdev->trigger_data;
+
+ if (heartbeat_data) {
+ del_timer_sync(&heartbeat_data->timer);
+ kfree(heartbeat_data);
+ }
+}
+
+static struct led_trigger heartbeat_led_trigger = {
+ .name = "heartbeat",
+ .activate = heartbeat_trig_activate,
+ .deactivate = heartbeat_trig_deactivate,
+};
+
+static int __init heartbeat_trig_init(void)
+{
+ return led_trigger_register(&heartbeat_led_trigger);
+}
+
+static void __exit heartbeat_trig_exit(void)
+{
+ led_trigger_unregister(&heartbeat_led_trigger);
+}
+
+module_init(heartbeat_trig_init);
+module_exit(heartbeat_trig_exit);
+
+MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
+MODULE_DESCRIPTION("Heartbeat LED trigger");
+MODULE_LICENSE("GPL");
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] LED: add LED heartbeat trigger
2006-06-20 16:36 [PATCH] LED: add LED heartbeat trigger Atsushi Nemoto
@ 2006-06-20 16:54 ` Nish Aravamudan
2006-06-21 14:41 ` Atsushi Nemoto
2006-06-21 15:01 ` Atsushi Nemoto
1 sibling, 1 reply; 7+ messages in thread
From: Nish Aravamudan @ 2006-06-20 16:54 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-kernel, Richard Purdie, akpm
On 6/20/06, Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:
> Add an LED trigger acts like a heart beat. This can be used as a
> replacement of CONFIG_HEARTBEAT code exists in some arch's timer code.
>
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
<snip>
> new file mode 100644
> index 0000000..07ac645
> --- /dev/null
> +++ b/drivers/leds/ledtrig-heartbeat.c
> + heartbeat_data->period = heartbeat_data->period * HZ / 100;
> + delay = 7 * HZ / 100;
Can these and the other HZ/100 users make use of the existing
*secs_to_jiffies() methods? FYI, if HZ=250, you're getting rounding
here, not sure if it's desired.
<snip>
> +static void heartbeat_trig_activate(struct led_classdev *led_cdev)
> +{
> + struct heartbeat_trig_data *heartbeat_data;
> +
> + heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL);
> + if (!heartbeat_data)
> + return;
> +
> + led_cdev->trigger_data = heartbeat_data;
> + init_timer(&heartbeat_data->timer);
> + heartbeat_data->timer.function = led_heartbeat_function;
> + heartbeat_data->timer.data = (unsigned long) led_cdev;
setup_timer()? (which will call init_timer() before returning.
Thanks,
Nish
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] LED: add LED heartbeat trigger
2006-06-20 16:54 ` Nish Aravamudan
@ 2006-06-21 14:41 ` Atsushi Nemoto
0 siblings, 0 replies; 7+ messages in thread
From: Atsushi Nemoto @ 2006-06-21 14:41 UTC (permalink / raw)
To: nish.aravamudan; +Cc: linux-kernel, rpurdie, akpm
On Tue, 20 Jun 2006 09:54:59 -0700, "Nish Aravamudan" <nish.aravamudan@gmail.com> wrote:
> Can these and the other HZ/100 users make use of the existing
> *secs_to_jiffies() methods? FYI, if HZ=250, you're getting rounding
> here, not sure if it's desired.
Thanks. The msecs_to_jiffies makes code more readable. The rounding
is not serious here.
> setup_timer()? (which will call init_timer() before returning.
Sure. I'll post a new patch soon.
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] LED: add LED heartbeat trigger
2006-06-20 16:36 [PATCH] LED: add LED heartbeat trigger Atsushi Nemoto
2006-06-20 16:54 ` Nish Aravamudan
@ 2006-06-21 15:01 ` Atsushi Nemoto
2006-06-21 15:17 ` Richard Purdie
1 sibling, 1 reply; 7+ messages in thread
From: Atsushi Nemoto @ 2006-06-21 15:01 UTC (permalink / raw)
To: linux-kernel; +Cc: rpurdie, akpm, nish.aravamudan, 7eggert
Take 2. Updated by a few comment. Thanks.
Add an LED trigger acts like a heart beat. This can be used as a
replacement of CONFIG_HEARTBEAT code exists in some arch's timer code.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 6265062..b0d73b8 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -87,5 +87,14 @@ config LEDS_TRIGGER_IDE_DISK
This allows LEDs to be controlled by IDE disk activity.
If unsure, say Y.
+config LEDS_TRIGGER_HEARTBEAT
+ tristate "LED Heartbeat Trigger"
+ depends LEDS_TRIGGERS
+ help
+ This allows LEDs to be controlled by a CPU load average.
+ The flash frequency is a hyperbolic function of the 1-minute
+ load average.
+ If unsure, say Y.
+
endmenu
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 40f0426..1dc79b5 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c2
# LED Triggers
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
+obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
new file mode 100644
index 0000000..4bf8cec
--- /dev/null
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -0,0 +1,118 @@
+/*
+ * LED Heartbeat Trigger
+ *
+ * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
+ *
+ * Based on Richard Purdie's ledtrig-timer.c and some arch's
+ * CONFIG_HEARTBEAT code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/sched.h>
+#include <linux/leds.h>
+#include "leds.h"
+
+struct heartbeat_trig_data {
+ unsigned int phase;
+ unsigned int period;
+ struct timer_list timer;
+};
+
+static void led_heartbeat_function(unsigned long data)
+{
+ struct led_classdev *led_cdev = (struct led_classdev *) data;
+ struct heartbeat_trig_data *heartbeat_data = led_cdev->trigger_data;
+ unsigned long brightness = LED_OFF;
+ unsigned long delay = 0;
+
+ /* acts like an actual heart beat -- ie thump-thump-pause... */
+ switch (heartbeat_data->phase) {
+ case 0:
+ /*
+ * The hyperbolic function below modifies the
+ * heartbeat period length in dependency of the
+ * current (1min) load. It goes through the points
+ * f(0)=1260, f(1)=860, f(5)=510, f(inf)->300.
+ */
+ heartbeat_data->period = 300 +
+ (6720 << FSHIFT) / (5 * avenrun[0] + (7 << FSHIFT));
+ heartbeat_data->period =
+ msecs_to_jiffies(heartbeat_data->period);
+ delay = msecs_to_jiffies(70);
+ heartbeat_data->phase++;
+ brightness = LED_FULL;
+ break;
+ case 1:
+ delay = heartbeat_data->period / 4 - msecs_to_jiffies(70);
+ heartbeat_data->phase++;
+ break;
+ case 2:
+ delay = msecs_to_jiffies(70);
+ heartbeat_data->phase++;
+ brightness = LED_FULL;
+ break;
+ default:
+ delay = heartbeat_data->period - heartbeat_data->period / 4 -
+ msecs_to_jiffies(70);
+ heartbeat_data->phase = 0;
+ break;
+ }
+
+ led_set_brightness(led_cdev, brightness);
+ mod_timer(&heartbeat_data->timer, jiffies + delay);
+}
+
+static void heartbeat_trig_activate(struct led_classdev *led_cdev)
+{
+ struct heartbeat_trig_data *heartbeat_data;
+
+ heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL);
+ if (!heartbeat_data)
+ return;
+
+ led_cdev->trigger_data = heartbeat_data;
+ setup_timer(&heartbeat_data->timer,
+ led_heartbeat_function, (unsigned long) led_cdev);
+ heartbeat_data->phase = 0;
+ led_heartbeat_function(heartbeat_data->timer.data);
+}
+
+static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
+{
+ struct heartbeat_trig_data *heartbeat_data = led_cdev->trigger_data;
+
+ if (heartbeat_data) {
+ del_timer_sync(&heartbeat_data->timer);
+ kfree(heartbeat_data);
+ }
+}
+
+static struct led_trigger heartbeat_led_trigger = {
+ .name = "heartbeat",
+ .activate = heartbeat_trig_activate,
+ .deactivate = heartbeat_trig_deactivate,
+};
+
+static int __init heartbeat_trig_init(void)
+{
+ return led_trigger_register(&heartbeat_led_trigger);
+}
+
+static void __exit heartbeat_trig_exit(void)
+{
+ led_trigger_unregister(&heartbeat_led_trigger);
+}
+
+module_init(heartbeat_trig_init);
+module_exit(heartbeat_trig_exit);
+
+MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
+MODULE_DESCRIPTION("Heartbeat LED trigger");
+MODULE_LICENSE("GPL");
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] LED: add LED heartbeat trigger
2006-06-21 15:01 ` Atsushi Nemoto
@ 2006-06-21 15:17 ` Richard Purdie
0 siblings, 0 replies; 7+ messages in thread
From: Richard Purdie @ 2006-06-21 15:17 UTC (permalink / raw)
To: Atsushi Nemoto, akpm, linux-kernel; +Cc: nish.aravamudan, 7eggert
On Thu, 2006-06-22 at 00:01 +0900, Atsushi Nemoto wrote:
> Add an LED trigger acts like a heart beat. This can be used as a
> replacement of CONFIG_HEARTBEAT code exists in some arch's timer code.
>
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Acked-by: Richard Purdie <rpurdie@rpsys.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <6pRqN-5QK-19@gated-at.bofh.it>]
* Re: [PATCH] LED: add LED heartbeat trigger
[not found] <6pRqN-5QK-19@gated-at.bofh.it>
@ 2006-06-20 17:39 ` Bodo Eggert
2006-06-21 14:54 ` Atsushi Nemoto
0 siblings, 1 reply; 7+ messages in thread
From: Bodo Eggert @ 2006-06-20 17:39 UTC (permalink / raw)
To: Atsushi Nemoto, Richard Purdie, akpm, linux-kernel
Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:
> + This allows LEDs to be controlled by a CPU load average.
> + The flash frequency is a hyperbolic function of the 5-minute
> + load average.
> + If unsure, say Y.
Wouldn't the 1-minute-load be better?
--
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.
http://david.woodhou.se/why-not-spf.html
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] LED: add LED heartbeat trigger
2006-06-20 17:39 ` Bodo Eggert
@ 2006-06-21 14:54 ` Atsushi Nemoto
0 siblings, 0 replies; 7+ messages in thread
From: Atsushi Nemoto @ 2006-06-21 14:54 UTC (permalink / raw)
To: 7eggert; +Cc: rpurdie, akpm, linux-kernel
On Tue, 20 Jun 2006 19:39:04 +0200, Bodo Eggert <7eggert@elstempel.de> wrote:
> > + This allows LEDs to be controlled by a CPU load average.
> > + The flash frequency is a hyperbolic function of the 5-minute
> > + load average.
> > + If unsure, say Y.
>
> Wouldn't the 1-minute-load be better?
Actually, this driver (and preceeding CONFIG_HEARTBEAT codes) is using
1-minute load average, avenrun[0]. This inconsistency has been exist
so long time (since 2.4 kernel at least). I'll fix the help text and
a comment in driver anyway.
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-06-21 15:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-20 16:36 [PATCH] LED: add LED heartbeat trigger Atsushi Nemoto
2006-06-20 16:54 ` Nish Aravamudan
2006-06-21 14:41 ` Atsushi Nemoto
2006-06-21 15:01 ` Atsushi Nemoto
2006-06-21 15:17 ` Richard Purdie
[not found] <6pRqN-5QK-19@gated-at.bofh.it>
2006-06-20 17:39 ` Bodo Eggert
2006-06-21 14:54 ` Atsushi Nemoto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®