netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Network activity LED trigger
@ 2007-03-01 21:41 Florian Fainelli
  2007-03-02 12:58 ` Florian Fainelli
  2007-03-03  2:20 ` Andi Kleen
  0 siblings, 2 replies; 12+ messages in thread
From: Florian Fainelli @ 2007-03-01 21:41 UTC (permalink / raw)
  To: netdev, Richard Purdie

Hi All,

I have been talking a bit with Richard, who is the LED API maintainer, and a 
LED trigger based on network activity would be something great.

There are somethings that concern the network stack :

- should we specify if the network driver is allowed to contribute to
the LED activity, just like it is done for random generation, at compile time

- I would like to trigger the LED based on one or several network
interfaces, maybe specify via sysfs which interface triggers which LED,
and also maybe differentiate the layer-2 activity from the layer-3
activity for instance

- A led driver could by default be bound to a network driver, or an interface 
name

As it could be very intrusive in the network stack, you might want to specify 
a bit more how you imagine a network activity trigger.

Thanks
-- 

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Network activity LED trigger
@ 2007-05-23 21:02 Florian Fainelli
  2007-05-23 22:12 ` jamal
  0 siblings, 1 reply; 12+ messages in thread
From: Florian Fainelli @ 2007-05-23 21:02 UTC (permalink / raw)
  To: hadi, Mark Brown, netdev, Richard Purdie


[-- Attachment #1.1: Type: text/plain, Size: 465 bytes --]

Here comes a basic patch that adds a network led activity. It is not 
configurable yet, but is enough to make a LED configured with 
the "network-activity" trigger to blink on network activity.

Netdev people can probably comment on the place of ledtrig_network_activity(), 
which is probably not adequate. Also the ledtrig_network_activity can be 
network device specific for instance.

Signed-off-by: Florian Fainelli <florian.fainelli@int-evry.fr>
-- 

[-- Attachment #1.2: ledtrig_network.patch --]
[-- Type: text/plain, Size: 4024 bytes --]

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 80acd08..25d2b58 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -127,5 +127,12 @@ config LEDS_TRIGGER_HEARTBEAT
 	  load average.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_NETWORK_ACT
+	tristate "LED Network Activity Trigger"
+	depends on LEDS_TRIGGER && NET
+	help
+	  This allow LEDs to be controlled by network activity at layer-3 networking.
+	  If unsure, say Y.
+
 endmenu
 
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index aa2c18e..bc899d3 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -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
diff --git a/drivers/leds/ledtrig-network-activity.c b/drivers/leds/ledtrig-network-activity.c
new file mode 100644
index 0000000..88d17bb
--- /dev/null
+++ b/drivers/leds/ledtrig-network-activity.c
@@ -0,0 +1,61 @@
+/*
+ * LED Network Activity Trigger
+ * based on ledtrig-ide-disk by Richard Purdie
+ * 
+ * Copyright 2007 Florian Fainelli <florian@openwrt.org>
+ * 
+ * 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/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/leds.h>
+
+static void ledtrig_network_timerfunc(unsigned long data);
+
+DEFINE_LED_TRIGGER(ledtrig_network);
+static DEFINE_TIMER(ledtrig_network_timer, ledtrig_network_timerfunc, 0, 0);
+static int network_activity, network_lastactivity;
+
+void ledtrig_network_activity(void)
+{
+	network_activity++;
+	if (!timer_pending(&ledtrig_network_timer))
+		mod_timer(&ledtrig_network_timer, jiffies + msecs_to_jiffies(10));
+}
+EXPORT_SYMBOL(ledtrig_network_activity);
+
+static void ledtrig_network_timerfunc(unsigned long data)
+{
+	if (network_lastactivity != network_activity) {
+		network_lastactivity = network_activity;
+		led_trigger_event(ledtrig_network, LED_FULL);
+		mod_timer(&ledtrig_network_timer, jiffies + msecs_to_jiffies(10));
+	} else {
+		led_trigger_event(ledtrig_network, LED_OFF);
+	}
+}
+
+static int __init ledtrig_network_init(void)
+{
+	led_trigger_register_simple("network-activity", &ledtrig_network);
+	return 0;
+}
+
+static void __exit ledtrig_network_exit(void)
+{
+	led_trigger_unregister_simple(ledtrig_network);
+}
+
+module_init(ledtrig_network_init);
+module_exit(ledtrig_network_exit);
+
+MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
+MODULE_DESCRIPTION("LED Network Activity trigger");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 88afcef..ed3774e 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -110,4 +110,10 @@ extern void ledtrig_ide_activity(void);
 #define ledtrig_ide_activity() do {} while(0)
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_NETWORK_ACT
+extern void ledtrig_network_activity(void);
+#else
+#define ledtrig_network_activity() do {} while(0)
+#endif
+
 #endif		/* __LINUX_LEDS_H_INCLUDED */
diff --git a/net/core/dev.c b/net/core/dev.c
index 4317c1b..9423b26 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -116,6 +116,7 @@
 #include <linux/dmaengine.h>
 #include <linux/err.h>
 #include <linux/ctype.h>
+#include <linux/leds.h>
 
 /*
  *	The list of packet types we will receive (as opposed to discard)
@@ -1451,6 +1452,8 @@ int dev_queue_xmit(struct sk_buff *skb)
 gso:
 	spin_lock_prefetch(&dev->queue_lock);
 
+	ledtrig_network_activity();
+
 	/* Disable soft irqs for various locks below. Also
 	 * stops preemption for RCU.
 	 */

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-05-23 22:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-01 21:41 Network activity LED trigger Florian Fainelli
2007-03-02 12:58 ` Florian Fainelli
2007-03-02 14:11   ` jamal
2007-03-02 14:16     ` Florian Fainelli
2007-03-02 15:16       ` jamal
2007-03-02 16:03         ` Richard Purdie
2007-03-02 16:19           ` jamal
2007-05-10 19:21       ` Florian Fainelli
2007-05-10 20:27         ` jamal
2007-03-03  2:20 ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2007-05-23 21:02 Florian Fainelli
2007-05-23 22:12 ` jamal

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).