* Re: PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED)
@ 2006-07-06 2:48 Thomas Tuttle
2006-07-06 3:01 ` Randy.Dunlap
2006-07-06 4:39 ` Andrew Morton
0 siblings, 2 replies; 6+ messages in thread
From: Thomas Tuttle @ 2006-07-06 2:48 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 361 bytes --]
Here is a new version of the patch, incorporating code style tips from
Randy Dunlap <rdunlap@xenotime.net>, and based on 2.6.17-git25, rather
than 2.6.17.1.
I noticed that there's a Heartbeat LED trigger in the git version. I
hope this isn't too similar.
--
Thomas Tuttle
http://thinkinginbinary.webhop.net/
thinkinginbinary@gmail.com
AIM: thinkinginbinary
[-- Attachment #2: ledtrig-cpu.patch --]
[-- Type: text/x-patch, Size: 4730 bytes --]
diff -udrN linux-2.6.17-git25/drivers/leds/Kconfig linux-2.6.17-git25-mine/drivers/leds/Kconfig
--- linux-2.6.17-git25/drivers/leds/Kconfig 2006-07-05 22:11:45.000000000 -0400
+++ linux-2.6.17-git25-mine/drivers/leds/Kconfig 2006-07-05 22:42:58.000000000 -0400
@@ -93,6 +93,41 @@
This allows LEDs to be controlled by IDE disk activity.
If unsure, say Y.
+config LEDS_TRIGGER_CPU
+ tristate "LED CPU Trigger"
+ depends LEDS_TRIGGERS
+ help
+ This allows LEDs to be controlled by CPU activity.
+ If unsure, say Y.
+
+config LEDS_TRIGGER_CPU_INCLUDE_USER
+ bool "Include user time in CPU trigger"
+ depends LEDS_TRIGGER_CPU
+ default y
+ help
+ This option makes user CPU time cause the CPU trigger to activate.
+
+config LEDS_TRIGGER_CPU_INCLUDE_NICE
+ bool "Include nice time in CPU trigger"
+ depends LEDS_TRIGGER_CPU
+ default n
+ help
+ This option makes nice CPU time cause the CPU trigger to activate.
+
+config LEDS_TRIGGER_CPU_INCLUDE_SYSTEM
+ bool "Include system time in CPU trigger"
+ depends LEDS_TRIGGER_CPU
+ default y
+ help
+ This option makes system CPU time cause the CPU trigger to activate.
+
+config LEDS_TRIGGER_CPU_INCLUDE_IOWAIT
+ bool "Include iowait time in CPU trigger"
+ depends LEDS_TRIGGER_CPU
+ default n
+ help
+ This option makes iowait CPU time cause the CPU trigger to activate.
+
config LEDS_TRIGGER_HEARTBEAT
tristate "LED Heartbeat Trigger"
depends LEDS_TRIGGERS
diff -udrN linux-2.6.17-git25/drivers/leds/ledtrig-cpu.c linux-2.6.17-git25-mine/drivers/leds/ledtrig-cpu.c
--- linux-2.6.17-git25/drivers/leds/ledtrig-cpu.c 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.17-git25-mine/drivers/leds/ledtrig-cpu.c 2006-07-05 22:42:38.000000000 -0400
@@ -0,0 +1,87 @@
+/*
+ * LED CPU Activity Trigger
+ *
+ * Copyright 2006 Thomas Tuttle
+ *
+ * Author: Thomas Tuttle <thinkinginbinary@gmail.com>
+ *
+ * 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/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/leds.h>
+#include <linux/kernel_stat.h>
+#include <asm/cputime.h>
+
+#define UPDATE_INTERVAL (5) /* delay between updates, in ms */
+
+static void ledtrig_cpu_timerfunc(unsigned long data);
+
+DEFINE_LED_TRIGGER(ledtrig_cpu);
+static DEFINE_TIMER(ledtrig_cpu_timer, ledtrig_cpu_timerfunc, 0, 0);
+
+static cputime64_t cpu_usage(void)
+{
+ int i;
+ cputime64_t time = cputime64_zero;
+
+ for_each_possible_cpu(i) {
+#ifdef CONFIG_LEDS_TRIGGER_CPU_INCLUDE_USER
+ time = cputime64_add(time, kstat_cpu(i).cpustat.user);
+#endif
+#ifdef CONFIG_LEDS_TRIGGER_CPU_INCLUDE_NICE
+ time = cputime64_add(time, kstat_cpu(i).cpustat.nice);
+#endif
+#ifdef CONFIG_LEDS_TRIGGER_CPU_INCLUDE_SYSTEM
+ time = cputime64_add(time, kstat_cpu(i).cpustat.system);
+#endif
+#ifdef CONFIG_LEDS_TRIGGER_CPU_INCLUDE_IOWAIT
+ time = cputime64_add(time, kstat_cpu(i).cpustat.iowait);
+#endif
+ }
+
+ return time;
+}
+
+cputime64_t last_cputime;
+
+static void ledtrig_cpu_timerfunc(unsigned long data)
+{
+ cputime64_t this_cputime = cpu_usage();
+ /* XXX: This assumes that cputime64_t can be subtracted.
+ * Nobody has defined cputime64_sub, so I had to do this instead. */
+ cputime64_t used_cputime = this_cputime - last_cputime;
+ enum led_brightness led_state = (used_cputime > 0) ? LED_FULL : LED_OFF;
+ led_trigger_event(ledtrig_cpu, led_state);
+ last_cputime = cpu_usage();
+
+ mod_timer(&ledtrig_cpu_timer, jiffies + msecs_to_jiffies(UPDATE_INTERVAL));
+}
+
+static int __init ledtrig_cpu_init(void)
+{
+ led_trigger_register_simple("cpu", &ledtrig_cpu);
+ last_cputime = cpu_usage();
+ mod_timer(&ledtrig_cpu_timer, jiffies + msecs_to_jiffies(UPDATE_INTERVAL));
+ return 0;
+}
+
+static void __exit ledtrig_cpu_exit(void)
+{
+ del_timer(&ledtrig_cpu_timer);
+ led_trigger_unregister_simple(ledtrig_cpu);
+}
+
+module_init(ledtrig_cpu_init);
+module_exit(ledtrig_cpu_exit);
+
+MODULE_AUTHOR("Thomas Tuttle <thinkinginbinary@gmail.com>");
+MODULE_DESCRIPTION("LED CPU Activity Trigger");
+MODULE_LICENSE("GPL");
diff -udrN linux-2.6.17-git25/drivers/leds/Makefile linux-2.6.17-git25-mine/drivers/leds/Makefile
--- linux-2.6.17-git25/drivers/leds/Makefile 2006-07-05 22:11:45.000000000 -0400
+++ linux-2.6.17-git25-mine/drivers/leds/Makefile 2006-07-05 22:40:52.000000000 -0400
@@ -16,4 +16,5 @@
# LED Triggers
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
+obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o
obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED)
2006-07-06 2:48 PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED) Thomas Tuttle
@ 2006-07-06 3:01 ` Randy.Dunlap
2006-07-06 3:03 ` Thomas Tuttle
2006-07-06 4:39 ` Andrew Morton
1 sibling, 1 reply; 6+ messages in thread
From: Randy.Dunlap @ 2006-07-06 3:01 UTC (permalink / raw)
To: Thomas Tuttle; +Cc: linux-kernel
On Wed, 5 Jul 2006 22:48:17 -0400 Thomas Tuttle wrote:
> Here is a new version of the patch, incorporating code style tips from
> Randy Dunlap <rdunlap@xenotime.net>, and based on 2.6.17-git25, rather
> than 2.6.17.1.
>
> I noticed that there's a Heartbeat LED trigger in the git version. I
> hope this isn't too similar.
I missed at least one thing:
Don't #include <linux/config.h>
That is done automatically now by Kbuild. Source files
should not do it. (you could wait to see if there are other comments. :)
---
~Randy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED)
2006-07-06 3:01 ` Randy.Dunlap
@ 2006-07-06 3:03 ` Thomas Tuttle
2006-07-06 3:13 ` Randy.Dunlap
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Tuttle @ 2006-07-06 3:03 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: Linux Kernel Mailing List
[-- Attachment #1: Type: text/plain, Size: 934 bytes --]
On July 05 at 23:01 EDT, Randy.Dunlap hastily scribbled:
> On Wed, 5 Jul 2006 22:48:17 -0400 Thomas Tuttle wrote:
>
> > Here is a new version of the patch, incorporating code style tips from
> > Randy Dunlap <rdunlap@xenotime.net>, and based on 2.6.17-git25, rather
> > than 2.6.17.1.
> >
> > I noticed that there's a Heartbeat LED trigger in the git version. I
> > hope this isn't too similar.
>
> I missed at least one thing:
>
> Don't #include <linux/config.h>
> That is done automatically now by Kbuild. Source files
> should not do it. (you could wait to see if there are other comments. :)
>
> ---
> ~Randy
Are you sure? Will it rebuild a file if a config entry is changed that
is simply mentioned in an #ifdef?
Is this a recent change? It wasn't working this way in 2.6.17.1--it
automatically noticed changes to the config of the file itself, but not
to config symbols tested using #ifdef.
[-- Attachment #2: Type: application/pgp-signature, Size: 191 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED)
2006-07-06 3:03 ` Thomas Tuttle
@ 2006-07-06 3:13 ` Randy.Dunlap
0 siblings, 0 replies; 6+ messages in thread
From: Randy.Dunlap @ 2006-07-06 3:13 UTC (permalink / raw)
To: Thomas Tuttle; +Cc: linux-kernel
On Wed, 5 Jul 2006 23:03:37 -0400 Thomas Tuttle wrote:
> On July 05 at 23:01 EDT, Randy.Dunlap hastily scribbled:
> > On Wed, 5 Jul 2006 22:48:17 -0400 Thomas Tuttle wrote:
> >
> > > Here is a new version of the patch, incorporating code style tips from
> > > Randy Dunlap <rdunlap@xenotime.net>, and based on 2.6.17-git25, rather
> > > than 2.6.17.1.
> > >
> > > I noticed that there's a Heartbeat LED trigger in the git version. I
> > > hope this isn't too similar.
> >
> > I missed at least one thing:
> >
> > Don't #include <linux/config.h>
> > That is done automatically now by Kbuild. Source files
> > should not do it. (you could wait to see if there are other comments. :)
> >
> > ---
> > ~Randy
>
> Are you sure? Will it rebuild a file if a config entry is changed that
> is simply mentioned in an #ifdef?
>
> Is this a recent change? It wasn't working this way in 2.6.17.1--it
> automatically noticed changes to the config of the file itself, but not
> to config symbols tested using #ifdef.
Actually the Kbuild system auto. includes <linux/autoconf.h> which is
generated from config.h. 2.6.17.* should be the same.
It's been this way since last Oct. (although I can't find that
message that was just posted today [July 5]).
http://lkml.org/lkml/2006/7/5/124
---
~Randy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED)
2006-07-06 2:48 PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED) Thomas Tuttle
2006-07-06 3:01 ` Randy.Dunlap
@ 2006-07-06 4:39 ` Andrew Morton
2006-07-06 13:54 ` Thomas Tuttle
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2006-07-06 4:39 UTC (permalink / raw)
To: Thomas Tuttle; +Cc: linux-kernel
On Wed, 5 Jul 2006 22:48:17 -0400
"Thomas Tuttle" <thinkinginbinary@gmail.com> wrote:
> Here is a new version of the patch, incorporating code style tips from
> Randy Dunlap <rdunlap@xenotime.net>, and based on 2.6.17-git25, rather
> than 2.6.17.1.
>
> I noticed that there's a Heartbeat LED trigger in the git version. I
> hope this isn't too similar.
>
> --- linux-2.6.17-git25/drivers/leds/Kconfig 2006-07-05 22:11:45.000000000 -0400
> +++ linux-2.6.17-git25-mine/drivers/leds/Kconfig 2006-07-05 22:42:58.000000000 -0400
> @@ -93,6 +93,41 @@
> This allows LEDs to be controlled by IDE disk activity.
> If unsure, say Y.
>
> +config LEDS_TRIGGER_CPU
> + tristate "LED CPU Trigger"
> + depends LEDS_TRIGGERS
> + help
> + This allows LEDs to be controlled by CPU activity.
> + If unsure, say Y.
> +
> +config LEDS_TRIGGER_CPU_INCLUDE_USER
> + bool "Include user time in CPU trigger"
> + depends LEDS_TRIGGER_CPU
> + default y
> + help
> + This option makes user CPU time cause the CPU trigger to activate.
> +
> +config LEDS_TRIGGER_CPU_INCLUDE_NICE
> + bool "Include nice time in CPU trigger"
> + depends LEDS_TRIGGER_CPU
> + default n
> + help
> + This option makes nice CPU time cause the CPU trigger to activate.
> +
> +config LEDS_TRIGGER_CPU_INCLUDE_SYSTEM
> + bool "Include system time in CPU trigger"
> + depends LEDS_TRIGGER_CPU
> + default y
> + help
> + This option makes system CPU time cause the CPU trigger to activate.
> +
> +config LEDS_TRIGGER_CPU_INCLUDE_IOWAIT
> + bool "Include iowait time in CPU trigger"
> + depends LEDS_TRIGGER_CPU
> + default n
> + help
> + This option makes iowait CPU time cause the CPU trigger to activate.
waaaaaaaaaaay too many config options. Make up your mind, man ;)
> +cputime64_t last_cputime;
static.
> +static void __exit ledtrig_cpu_exit(void)
> +{
> + del_timer(&ledtrig_cpu_timer);
del_timer_sync().
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED)
2006-07-06 4:39 ` Andrew Morton
@ 2006-07-06 13:54 ` Thomas Tuttle
0 siblings, 0 replies; 6+ messages in thread
From: Thomas Tuttle @ 2006-07-06 13:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: Richard Purdie
[-- Attachment #1.1: Type: text/plain, Size: 1184 bytes --]
On July 06 at 00:39 EDT, Andrew Morton hastily scribbled:
> On Wed, 5 Jul 2006 22:48:17 -0400
> "Thomas Tuttle" <thinkinginbinary@gmail.com> wrote:
Omigod, Andrew Morton replied to my email. Cool. Linux rocks.
> > Here is a new version of the patch, incorporating code style tips from
> > Randy Dunlap <rdunlap@xenotime.net>, and based on 2.6.17-git25, rather
> > than 2.6.17.1.
> >
> > I noticed that there's a Heartbeat LED trigger in the git version. I
> > hope this isn't too similar.
> >
>
> <snip>
>
> waaaaaaaaaaay too many config options. Make up your mind, man ;)
Okay, this new patch includes user and system, excludes iowait, and
makes nice configurable by a boolean module parameter called
include_nice, with the default being to exclude nice time.
> > +cputime64_t last_cputime;
> static.
Done.
> > +static void __exit ledtrig_cpu_exit(void)
> > +{
> > + del_timer(&ledtrig_cpu_timer);
> del_timer_sync().
Done.
I also made the trigger track the last state of the LED, and avoid
sending a trigger event unless the state has actually changed. And I
made it turn off the LED when the trigger is unloaded.
--Thomas Tuttle
[-- Attachment #1.2: ledtrig-cpu.patch --]
[-- Type: text/plain, Size: 4134 bytes --]
diff -udrN linux-2.6.17-git25/drivers/leds/Kconfig linux-2.6.17-git25-mine/drivers/leds/Kconfig
--- linux-2.6.17-git25/drivers/leds/Kconfig 2006-07-05 22:11:45.000000000 -0400
+++ linux-2.6.17-git25-mine/drivers/leds/Kconfig 2006-07-06 09:23:18.000000000 -0400
@@ -93,6 +93,13 @@
This allows LEDs to be controlled by IDE disk activity.
If unsure, say Y.
+config LEDS_TRIGGER_CPU
+ tristate "LED CPU Trigger"
+ depends LEDS_TRIGGERS
+ help
+ This allows LEDs to be controlled by CPU activity.
+ If unsure, say Y.
+
config LEDS_TRIGGER_HEARTBEAT
tristate "LED Heartbeat Trigger"
depends LEDS_TRIGGERS
diff -udrN linux-2.6.17-git25/drivers/leds/ledtrig-cpu.c linux-2.6.17-git25-mine/drivers/leds/ledtrig-cpu.c
--- linux-2.6.17-git25/drivers/leds/ledtrig-cpu.c 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.17-git25-mine/drivers/leds/ledtrig-cpu.c 2006-07-06 09:48:43.000000000 -0400
@@ -0,0 +1,89 @@
+/*
+ * LED CPU Activity Trigger
+ *
+ * Copyright 2006 Thomas Tuttle
+ *
+ * Author: Thomas Tuttle <thinkinginbinary@gmail.com>
+ *
+ * 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/leds.h>
+#include <linux/kernel_stat.h>
+#include <asm/cputime.h>
+
+MODULE_AUTHOR("Thomas Tuttle <thinkinginbinary@gmail.com>");
+MODULE_DESCRIPTION("LED CPU Activity Trigger");
+MODULE_PARM_DESC(include_nice, "Turn LED on for nice CPU time");
+MODULE_LICENSE("GPL");
+
+static int include_nice = 0;
+
+module_param(include_nice, bool, 0);
+
+#define UPDATE_INTERVAL (5) /* delay between updates, in ms */
+
+static void ledtrig_cpu_timerfunc(unsigned long data);
+
+DEFINE_LED_TRIGGER(ledtrig_cpu);
+static DEFINE_TIMER(ledtrig_cpu_timer, ledtrig_cpu_timerfunc, 0, 0);
+
+static cputime64_t cpu_usage(void)
+{
+ int i;
+ cputime64_t time = cputime64_zero;
+
+ for_each_possible_cpu(i) {
+ time = cputime64_add(time, kstat_cpu(i).cpustat.user);
+ if (include_nice)
+ time = cputime64_add(time, kstat_cpu(i).cpustat.nice);
+ time = cputime64_add(time, kstat_cpu(i).cpustat.system);
+ }
+
+ return time;
+}
+
+static enum led_brightness last_led_state;
+static cputime64_t last_cputime;
+
+static void ledtrig_cpu_timerfunc(unsigned long data)
+{
+ cputime64_t this_cputime = cpu_usage();
+ /* XXX: This assumes that cputime64_t can be subtracted.
+ * Nobody has defined cputime64_sub, so I had to do this instead. */
+ cputime64_t used_cputime = this_cputime - last_cputime;
+ enum led_brightness led_state = (used_cputime > 0) ? LED_FULL : LED_OFF;
+ if (led_state != last_led_state)
+ led_trigger_event(ledtrig_cpu, led_state);
+ last_led_state = led_state;
+ last_cputime = cpu_usage();
+
+ mod_timer(&ledtrig_cpu_timer, jiffies + msecs_to_jiffies(UPDATE_INTERVAL));
+}
+
+static int __init ledtrig_cpu_init(void)
+{
+ led_trigger_register_simple("cpu", &ledtrig_cpu);
+ led_trigger_event(ledtrig_cpu, LED_OFF);
+ last_led_state = LED_OFF;
+ last_cputime = cpu_usage();
+ mod_timer(&ledtrig_cpu_timer, jiffies + msecs_to_jiffies(UPDATE_INTERVAL));
+ return 0;
+}
+
+static void __exit ledtrig_cpu_exit(void)
+{
+ del_timer_sync(&ledtrig_cpu_timer);
+ led_trigger_event(ledtrig_cpu, LED_OFF);
+ led_trigger_unregister_simple(ledtrig_cpu);
+}
+
+module_init(ledtrig_cpu_init);
+module_exit(ledtrig_cpu_exit);
diff -udrN linux-2.6.17-git25/drivers/leds/Makefile linux-2.6.17-git25-mine/drivers/leds/Makefile
--- linux-2.6.17-git25/drivers/leds/Makefile 2006-07-05 22:11:45.000000000 -0400
+++ linux-2.6.17-git25-mine/drivers/leds/Makefile 2006-07-05 22:40:52.000000000 -0400
@@ -16,4 +16,5 @@
# LED Triggers
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
+obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o
obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
[-- Attachment #2: Type: application/pgp-signature, Size: 191 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-07-06 13:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-06 2:48 PATCH: Create new LED trigger for CPU activity (ledtrig-cpu) (UPDATED) Thomas Tuttle
2006-07-06 3:01 ` Randy.Dunlap
2006-07-06 3:03 ` Thomas Tuttle
2006-07-06 3:13 ` Randy.Dunlap
2006-07-06 4:39 ` Andrew Morton
2006-07-06 13:54 ` Thomas Tuttle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).