Skip to contentSkip to conversation

leds: trigger: Introduce a NETDEV trigger

PATCH Superseded Ben Whitten 2 participants 5 messages Dec 5, 2017 – Dec 7, 2017

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 leds: trigger: Introduce a NETDEV trigger

From: Ben Whitten <[email protected]>

The patch was converted to led_blink_oneshot, in doing so we find that the behaviour has changed. As I dont want to break 'userspace' led behaviour this patch shouldn't be merged as is. Open to suggestions.

Given an interval of 50ms and heavy throughput, the previous implementation produced a blink with 100ms period and 50% dutycycle. The led_blink_oneshot version produces a blink with 140ms period and 57% dutycycle.
I assume a fudge factor on the oneshot delay to bring the period back to 100ms would be device specific so not suitable.

Kind regards,
Ben Whitten (1):
leds: trigger: Introduce a NETDEV trigger

 .../ABI/testing/sysfs-class-led-trigger-netdev     |  45 ++
 drivers/leds/trigger/Kconfig                       |   7 +
 drivers/leds/trigger/Makefile                      |   1 +
 drivers/leds/trigger/ledtrig-netdev.c              | 507 +++++++++++++++++++++
 4 files changed, 560 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-netdev
 create mode 100644 drivers/leds/trigger/ledtrig-netdev.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/1 leds: trigger: Introduce a NETDEV trigger

From: Ben Whitten <[email protected]>

This commit introduces a NETDEV trigger for named device activity. Available triggers are link, rx, and tx.

---
Changes in v2:
Sort includes and redate documentation
Correct licence
Remove macro and replace with generic function using enums Convert blink logic in stats work to use led_blink_oneshot Uses configured brightness instead of FULL

---
 .../ABI/testing/sysfs-class-led-trigger-netdev     |  45 ++
 drivers/leds/trigger/Kconfig                       |   7 +
 drivers/leds/trigger/Makefile                      |   1 +
 drivers/leds/trigger/ledtrig-netdev.c              | 507 +++++++++++++++++++++
 4 files changed, 560 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-netdev
 create mode 100644 drivers/leds/trigger/ledtrig-netdev.c
Documentation/ABI/testing/sysfs-class-led-trigger-netdev new file +45 -0
new file mode 100644
index 0000000..451af6d
@@ -0,0 +1,45 @@
+What:		/sys/class/leds/<led>/device_name
+Date:		Dec 2017
+KernelVersion:	4.16
+Contact:	[email protected]
+Description:
+		Specifies the network device name to monitor.
+
+What:		/sys/class/leds/<led>/interval
+Date:		Dec 2017
+KernelVersion:	4.16
+Contact:	[email protected]
+Description:
+		Specifies the duration of the LED blink in milliseconds.
+		Defaults to 50 ms.
+
+What:		/sys/class/leds/<led>/link
+Date:		Dec 2017
+KernelVersion:	4.16
+Contact:	[email protected]
+Description:
+		Signal the link state of the named network device.
+		If set to 0 (default), the LED's normal state is off.
+		If set to 1, the LED's normal state reflects the link state
+		of the named network device.
+		Setting this value also immediately changes the LED state.
+
+What:		/sys/class/leds/<led>/tx
+Date:		Dec 2017
+KernelVersion:	4.16
+Contact:	[email protected]
+Description:
+		Signal transmission of data on the named network device.
+		If set to 0 (default), the LED will not blink on transmission.
+		If set to 1, the LED will blink for the milliseconds specified
+		in interval to signal transmission.
+
+What:		/sys/class/leds/<led>/rx
+Date:		Dec 2017
+KernelVersion:	4.16
+Contact:	[email protected]
+Description:
+		Signal reception of data on the named network device.
+		If set to 0 (default), the LED will not blink on reception.
+		If set to 1, the LED will blink for the milliseconds specified
+		in interval to signal reception.
drivers/leds/trigger/Kconfig +7 -0
index 3f9ddb9..4ec1853 100644
@@ -126,4 +126,11 @@ config LEDS_TRIGGER_PANIC
 	  a different trigger.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_NETDEV
+	tristate "LED Netdev Trigger"
+	depends on NET && LEDS_TRIGGERS
+	help
+	  This allows LEDs to be controlled by network device activity.
+	  If unsure, say Y.
+
 endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
index 9f2e868..59e163d 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON)	+= ledtrig-default-on.o
 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT)	+= ledtrig-transient.o
 obj-$(CONFIG_LEDS_TRIGGER_CAMERA)	+= ledtrig-camera.o
 obj-$(CONFIG_LEDS_TRIGGER_PANIC)	+= ledtrig-panic.o
+obj-$(CONFIG_LEDS_TRIGGER_NETDEV)	+= ledtrig-netdev.o
drivers/leds/trigger/ledtrig-netdev.c new file +507 -0

507 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw
In reply to Ben Whitten

Hi Ben,

Quoted 9 lines · Ben Whitten

From: Ben Whitten <[email protected]>

The patch was converted to led_blink_oneshot, in doing so we find that the behaviour has changed. As I dont want to break 'userspace' led behaviour this patch shouldn't be merged as is. Open to suggestions.

Given an interval of 50ms and heavy throughput, the previous implementation produced a blink with 100ms period and 50% dutycycle. The led_blink_oneshot version produces a blink with 140ms period and 57% dutycycle.

Please check if the LED class driver you're testing the trigger with implements blink_set op. If yes it would be good to check if it doesn't align the delay intervals to the hardware capabilities instead of failing and relying on a LED core software blink fallback.

Quoted 15 lines

I assume a fudge factor on the oneshot delay to bring the period back to 100ms would be device specific so not suitable.

Kind regards,
Ben Whitten (1):
leds: trigger: Introduce a NETDEV trigger

 .../ABI/testing/sysfs-class-led-trigger-netdev     |  45 ++
 drivers/leds/trigger/Kconfig                       |   7 +
 drivers/leds/trigger/Makefile                      |   1 +
 drivers/leds/trigger/ledtrig-netdev.c              | 507 +++++++++++++++++++++
 4 files changed, 560 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-netdev
 create mode 100644 drivers/leds/trigger/ledtrig-netdev.c
Signature · 2 lines
Best regards,
Jacek Anaszewski
#3 lore raw

Hi Jacek,

Quoted 9 lines · Jacek Anaszewski

Hi Ben,

Quoted 6 lines · Ben Whitten

From: Ben Whitten <[email protected]>

The patch was converted to led_blink_oneshot, in doing so we find that the behaviour has changed. As I dont want to break 'userspace' led behaviour this patch shouldn't be merged as is. Open to suggestions.

Quoted 8 lines
Quoted 3 lines

Given an interval of 50ms and heavy throughput, the previous implementation produced a blink with 100ms period and 50% dutycycle. The led_blink_oneshot version produces a blink with 140ms period and 57% dutycycle.

Please check if the LED class driver you're testing the trigger with implements blink_set op. If yes it would be good to check if it doesn't align the delay intervals to the hardware capabilities instead of failing and relying on a LED core software blink fallback.

The led are using gpio-led set from device tree on an embedded system, sama5 based. So as far as I can tell blink_op is NULL in this case and it then relies on
software for the blink in the form of timers.
I assume its the jiffies playing a part here, taking a jiffy or two to queue up a flash
may add 10ms to the desired 50ms delay_on/delay_off that I am seeing. Then the extra time may be due to the stats workqueue not aligning with the blink timer to
kick it off again.

Best regards,
Ben

#4 lore raw
Quoted 22 lines · Ben Whitten

Hi Jacek,

Quoted 9 lines · Jacek Anaszewski

Hi Ben,

Quoted 6 lines · Ben Whitten

From: Ben Whitten <[email protected]>

The patch was converted to led_blink_oneshot, in doing so we find that the behaviour has changed. As I dont want to break 'userspace' led behaviour this patch shouldn't be merged as is. Open to suggestions.

Quoted 8 lines
Quoted 3 lines

Given an interval of 50ms and heavy throughput, the previous implementation produced a blink with 100ms period and 50% dutycycle. The led_blink_oneshot version produces a blink with 140ms period and 57% dutycycle.

Please check if the LED class driver you're testing the trigger with implements blink_set op. If yes it would be good to check if it doesn't align the delay intervals to the hardware capabilities instead of failing and relying on a LED core software blink fallback.

Quoted 10 lines

The led are using gpio-led set from device tree on an embedded system, sama5 based. So as far as I can tell blink_op is NULL in this case and it then relies on
software for the blink in the form of timers.
I assume its the jiffies playing a part here, taking a jiffy or two to queue up a flash
may add 10ms to the desired 50ms delay_on/delay_off that I am seeing. Then the extra time may be due to the stats workqueue not aligning with the blink timer to
kick it off again.

I have found a solution. As oneshot appears run in software regardless based on the
check in led_blink_setup, cancelling the software timer in the stats worker allows for
an immidiate requeue. This brings the period back down to 110ms and looks identical to the previous implementation.

Best regards,
Ben