Skip to contentSkip to conversation

PATCH: Create new LED trigger for CPU activity (ledtrig-cpu)

PATCH Thomas Tuttle 2 participants 2 messages Jul 6, 2006 LED

lore
Share & tools
lore
#0 lore raw

Here is a patch I wrote that creates a new LED trigger for CPU activity. It creates a new config option, CONFIG_LEDS_TRIGGER_CPU, as well as four suboptions to select the combination of user, nice, system, and iowait that should turn the LED on.

It's loosely based on the ledtrig-ide-disk plugin, but only for general guidance. It doesn't modify anything in the CPU scheduling code, for better or for worse; it is less efficient, because it checks the CPU time every 5ms instead of "knowing" when the CPU is idle or active, but it doesn't require changes to any other code, and is much less hairy for not digging into the scheduling stuff. (It's also more flexible, because it can deal with user/nice/system/iowait time without much effort.)

The same disclaimers from my last email (the asus_acpi LED support one) apply--I haven't written much kernel code; this is diffed against 2.6.17.1, not .3, but I don't think anything has changed; I've tested it, but no guarantees it's perfect; and I apologize for the MIME type of text/x-patch, but it should work.

Constructive comments would be greatly appreciated.

Signature · 4 lines
Thomas Tuttle
http://thinkinginbinary.webhop.net/
[email protected]
AIM: thinkinginbinary
drivers/leds/Kconfig +31 -0
diff -udrN linux-2.6.17.1/drivers/leds/Kconfig linux-2.6.17.1-mine/drivers/leds/Kconfig
@@ -80,6 +80,37 @@
 	  This allows LEDs to be controlled by a programmable timer
 	  via sysfs. 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
+	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
+	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
+	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
+	help
+	  This option makes iowait CPU time cause the CPU trigger to activate.
+
 config LEDS_TRIGGER_IDE_DISK
 	bool "LED IDE Disk Trigger"
 	depends LEDS_TRIGGERS && BLK_DEV_IDEDISK
drivers/leds/ledtrig-cpu.c +90 -0

90 lines not on this page · raw message

drivers/leds/Makefile +1 -0
diff -udrN linux-2.6.17.1/drivers/leds/Makefile linux-2.6.17.1-mine/drivers/leds/Makefile
@@ -15,3 +15,4 @@
 # 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
#1 lore raw
Quoted 4 lines · On Wed, 5 Jul 2006 21:24:17 -0400 Thomas Tuttle wrote:

Here is a patch I wrote that creates a new LED trigger for CPU activity. It creates a new config option, CONFIG_LEDS_TRIGGER_CPU, as well as four suboptions to select the combination of user, nice, system, and iowait that should turn the LED on.

What "the LED" does it turn on/off?
I'm curious how I can use it.

Quoted 9 lines

It's loosely based on the ledtrig-ide-disk plugin, but only for general guidance. It doesn't modify anything in the CPU scheduling code, for better or for worse; it is less efficient, because it checks the CPU time every 5ms instead of "knowing" when the CPU is idle or active, but it doesn't require changes to any other code, and is much less hairy for not digging into the scheduling stuff. (It's also more flexible, because it can deal with user/nice/system/iowait time without much effort.)

Quoted 5 lines

The same disclaimers from my last email (the asus_acpi LED support one) apply--I haven't written much kernel code; this is diffed against 2.6.17.1, not .3, but I don't think anything has changed; I've tested it, but no guarantees it's perfect; and I apologize for the MIME type of text/x-patch, but it should work.

It may not matter, but generally you should diff against the latest linus-mainline kernel, e.g., 2.6.7-git25 or Linus's git tree.

Quoted 1 line

Constructive comments would be greatly appreciated.

The attachment makes it difficult to review/comment. Apparently gmail munges inline patches so that's not an option (from what I have read here on lkml).

Oh, where is the LED IDE patch?

Patch comments: all seem to be for style etc.

+#define UPDATE_INTERVAL (5) // ms

Don't use // style comments, use /* ... */.

+static cputime64_t cpu_usage(void) {

Function { and } should be on separate lines.

+ for_each_possible_cpu(i) {
+ user = cputime64_add(user, kstat_cpu(i).cpustat.user);
+ nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
+ system = cputime64_add(system, kstat_cpu(i).cpustat.system);
+ idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
+ iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
+ }

We don't like ifdefs in C code very much, but since there are some below here, why not here also?

+ if (used_cputime > 0) {
+ led_trigger_event(ledtrig_cpu, LED_FULL);
+ } else {
+ led_trigger_event(ledtrig_cpu, LED_OFF);
+ }

No braces for 1-statement "blocks".

---
~Randy