Skip to contentSkip to conversation

Add a network activity LED trigger

PATCH In review Florian Fainelli 5 participants 8 messages Jul 18, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add a network activity LED trigger

Hi all,

This patch adds a new LED trigger, based on network activity. It gathers activity from net/core/dev.c and can be used as a LED trigger by specifying "network-activity". Further version should allow the user to specify the network interface to bind a LED to. This trigger is a "simple" trigger as defined by the LED subsystem.

drivers/leds/Kconfig +7 -0
index 87d2046..fdc5a8a 100644
@@ -128,5 +128,12 @@ config LEDS_TRIGGER_HEARTBEAT
 	  load average.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_NETWORK_ACT
+	tristate "LED Network Activity Trigger"
+	depends on LEDS_TRIGGERS && NET
+	help
+	  This allow LEDs to be controlled by network activity at layer-3 networking.
+	  If unsure, say Y.
+
 endmenu
 
drivers/leds/Makefile +1 -0
index aa2c18e..bc899d3 100644
@@ -21,3 +21,4 @@ obj-$(CONFIG_LEDS_COBALT)		+= leds-cobalt.o
 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
+obj-$(CONFIG_LEDS_TRIGGER_NETWORK_ACT)  += ledtrig-network-activity.o
drivers/leds/ledtrig-network-activity.c new file +63 -0

63 lines not on this page · raw message

net/core/dev.c +2 -0
index ee051bb..a3a4115 100644
@@ -117,6 +117,7 @@
 #include <linux/err.h>
 #include <linux/ctype.h>
 #include <linux/if_arp.h>
+#include <linux/leds.h>
 
 /*
  *	The list of packet types we will receive (as opposed to discard)
@@ -1523,6 +1524,7 @@ gso:
 	 * stops preemption for RCU.
 	 */
 	rcu_read_lock_bh();
+	ledtrig_network_activity();
 
 	/* Updates of qdisc are serialized by queue_lock.
 	 * The struct Qdisc which is pointed to by qdisc is now a
#1 lore raw

drivers/leds/Kconfig config LEDS_TRIGGER_HEARTBEAT · line 132

Quoted 10 lines · Florian Fainelli
drivers/leds/Kconfig +2 -0
index 87d2046..fdc5a8a 100644
@@ -128,5 +128,12 @@ config LEDS_TRIGGER_HEARTBEAT
 	  load average.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_NETWORK_ACT
+	tristate "LED Network Activity Trigger"

Module isn't possible, you call the led trigger from net/core/dev.c.

Quoted 13 lines
net/core/dev.c +1 -0
index ee051bb..a3a4115 100644
@@ -117,6 +117,7 @@
 #include <linux/err.h>
 #include <linux/ctype.h>
 #include <linux/if_arp.h>
+#include <linux/leds.h>
 
 /*
  *	The list of packet types we will receive (as opposed to discard)

net/core/dev.c gso: · line 1527

Quoted 4 lines
net/core/dev.c +1 -0
@@ -1523,6 +1524,7 @@ gso:
 	 * stops preemption for RCU.
 	 */
 	rcu_read_lock_bh();
+	ledtrig_network_activity();

Besides missing a declaration and not linking without the network LED config option, its pretty ridiculous to call this for every packet just to make a led blink.

#2 lore raw

Hello Patrick,

Le mercredi 18 juillet 2007, Patrick McHardy a écrit :

Quoted 1 line

Module isn't possible, you call the led trigger from net/core/dev.c.

You are right, it just occured to me.

Quoted 3 lines

Besides missing a declaration and not linking without the network LED config option, its pretty ridiculous to call this for every packet just to make a led blink.

Could you suggest me a better way to do so ? The code was highly inspired from what is done with the IDE trigger. The declaration is done in linux/leds.h, which is included in dev.c for that purpose.

Thank you very much for your answer.

#3 lore raw
Quoted 7 lines · Florian Fainelli
Quoted 4 lines

Besides missing a declaration and not linking without the network LED config option, its pretty ridiculous to call this for every packet just to make a led blink.

Could you suggest me a better way to do so ? The code was highly inspired from what is done with the IDE trigger. The declaration is done in linux/leds.h, which is included in dev.c for that purpose.

Maybe just increment a variable and periodically check it or something like that.

#4 lore raw
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Florian Fainelli
Quoted 4 lines

Besides missing a declaration and not linking without the network LED config option, its pretty ridiculous to call this for every packet just to make a led blink.

Quoted 7 lines
Quoted 4 lines

Could you suggest me a better way to do so ? The code was highly inspired from what is done with the IDE trigger. The declaration is done in linux/leds.h, which is included in dev.c for that purpose.

Maybe just increment a variable and periodically check it or something like that.

Are there not already packet counters that the LED trigger could just look at? If it did that at say 20Hz or 10Hz, it would probably look quite reasonable without impacting on the system too much?

Richard

#5 lore raw
Quoted 12 lines · Richard Purdie
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Florian Fainelli
Quoted 5 lines

Besides missing a declaration and not linking without the network LED config option, its pretty ridiculous to call this for every packet just to make a led blink.

Could you suggest me a better way to do so ? The code was highly inspired from what is done with the IDE trigger. The declaration is done in linux/leds.h, which is included in dev.c for that purpose.

Quoted 7 lines
Quoted 3 lines

Maybe just increment a variable and periodically check it or something like that.

Are there not already packet counters that the LED trigger could just look at? If it did that at say 20Hz or 10Hz, it would probably look quite reasonable without impacting on the system too much

The qdisc counters might work, I think all qdiscs properly maintain at least byte and packet counters. Or simply check the queue length, if > 0 there is activity.

maintainer
#6 lore raw
In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Wed, 18 Jul 2007 15:54:56 +0200

Quoted 6 lines
Quoted 5 lines · Florian Fainelli
Quoted 4 lines

Besides missing a declaration and not linking without the network LED config option, its pretty ridiculous to call this for every packet just to make a led blink.

Quoted 7 lines
Quoted 4 lines

Could you suggest me a better way to do so ? The code was highly inspired from what is done with the IDE trigger. The declaration is done in linux/leds.h, which is included in dev.c for that purpose.

Maybe just increment a variable and periodically check it or something like that.

Yes please, calling this millions of times per second on a high end router is just not smart.

#7 lore raw
In reply to Florian Fainelli
Quoted 10 lines · On Wed, 18 Jul 2007 15:27:38 +0200 Florian Fainelli…

Hi all,

This patch adds a new LED trigger, based on network activity. It gathers activity from net/core/dev.c and can be used as a LED trigger by specifying "network-activity". Further version should allow the user to specify the network interface to bind a LED to. This trigger is a "simple" trigger as defined by the LED subsystem.

You are slowing down the network receive path even if LED is not used.

Doing mod_timer() is expensive, on a busy system you would be adding another lock roundtrip and list operation for each incoming packet.