Discussion

Switch off the leds ?

66 62007
tkaiser  
Edited by tkaiser at Sat Nov 1, 2014 07:37

The green LED on the board can be used for a large variety of status informations by default (eg. mmc0 to indicate write activity on the SD card):
  1. root@bananas /sys/class/leds/green:ph24:led1 # cat trigger
  2. [none] battery-charging-or-full battery-charging battery-full battery-charging-blink-full-solid ac-online usb-online mmc0 timer heartbeat backlight gpio cpu0 cpu1 default-on
Copy the Code
A quick google search for "linux disk activity led" led to: http://archlinuxarm.org/forum/viewtopic.php?t=2899

And after installation of the sysstat package ("apt-get install sysstat", "yum install sysstat", "pacman -S sysstat" prior to that) the following line in /etc/rc.local should work for both USB and SATA (since these devices appear as /dev/sdX):
  1. iostat -z -d 1 sda | sed -u -e '1d' -e 's/Device.*/none/' -e 's/sd.*/default-on/' -e '/^$/d' >/sys/class/leds/green\:ph24\:led1/trigger &
Copy the Code
Or to get random flashing while accessing the disk:
  1. iostat -z -d 1 sda | sed -u -e '1d' -e 's/Device.*/none/' -e 's/sd.*/heartbeat/' -e '/^$/d' >/sys/class/leds/green\:ph24\:led1/trigger &
Copy the Code
But this will catch only disk activity exceeding a certain amount of time since the minimal check interval for iostat is 1 second...

If you want to monitor a specific device in case there's more than one disk connected you should have to parse the output of 'blkid' or /etc/mtab before and specify the correct device when calling iostat.

BTW: Using iostat many other performance indicators could be translated into LED states ("none" --> "timer" --> "heartbeat" --> "default-on" as a 'load indicator' utilizing 'iostat -c 1' or /proc/loadavg for example). And as usual: This will slightly increase CPU utilization.

tkaiser  
Edited by tkaiser at Sat Nov 1, 2014 07:28

You might also get disk statistics directly from /proc/diskstats or /sys/block/sdX/stat

For the field value's meanings have a look at https://www.kernel.org/doc/Documentation/iostats.txt

A rather primtive approach using the blue led could be something like this:
  1. root@bananas ~ # cat /usr/local/sbin/hdd-activity.sh
  2. #!/bin/bash
  3. FormerIORequests=0      
  4. while true ; do
  5.         IORequests=$(( $(awk -F" " '/sda / {print $4" + "$8}' </proc/diskstats) ))
  6.         if [ ${IORequests} -gt ${FormerIORequests} ]; then
  7.                 /usr/local/sbin/bpi_ledset eth0 bh >/dev/null
  8.         else
  9.                 /usr/local/sbin/bpi_ledset eth0 b >/dev/null
  10.         fi
  11.         sleep 0.2
  12.         FormerIORequests=${IORequests}
  13. done
Copy the Code
You could adapt the code to use the green and yellow leds on the Ethernet connector to show acticity of different disks. But the whole thing as a shell script is insane since it's 'costly': approx. 10% CPU utilization. This must be done in C

Anyone? Merging eg. this stuff here https://github.com/MeanEYE/Disk-Indicator with bpi_ledset?

tkaiser  
Edited by tkaiser at Sat Nov 1, 2014 08:34

This ugly sed one-liner for /etc/rc.local would use the board's green led to show CPU utilization based on the CPU idle percentage (above 90% no led, 50-89% slow flashing, 10-49% faster flashing, idle below 10% constant led light)
  1. iostat -c 1 | sed -u -e '1d' -e 's/avg-cpu.*//' -e '/^$/d' -e 's/^.\{1,50\}//' -e 's/[0,9].*/none/' -e 's/[5-8].*/timer/' -e 's/[1-4].*/heartbeat/' -e 's/\ .*/default-on/' >/sys/class/leds/green\:ph24\:led1/trigger &
Copy the Code
'Real time' CPU activity can be shown using
  1. echo cpu0 >/sys/class/leds/green\:ph24\:led1/trigger
Copy the Code
instead. Unfortunately you have to specify the CPU core you're interested in so when you assigned all network IRQ processing to cpu1 you won't get visual feedback via the green led when the system is busy doing network stuff. The sed one-liner using CPU idle percentage works for both CPU cores combined.

tkaiser  
And this stuff could be used to show I/O bottlenecks using the green LED based on the iowait percentage (below 10% no led, 10%-19% slow blinking, 20%-49% fast blinking, 50% or above: constant led light):
  1. iostat -c 1 | sed -u -e '1d' -e 's/avg-cpu.*//' -e '/^$/d' -e 's/^.\{1,34\}//' -e 's/[0,5-9].*/default-on/' -e 's/1.*/timer/' -e 's/[2-4].*/heartbeat/' -e 's/\ .*/none/' >/sys/class/leds/green\:ph24\:led1/trigger &
Copy the Code

Thanks all for your responses.
I'm on way to build a daemon that will :
  • Blink the blue LED as per Sata disk activities
  • Blink the "user definable" greed LED as per system Load.


For the second one, cpu0 or cpu1 is doing more or less the job, but for my basement server, it would be more interesting if I can see visually system load instead of only the punctual CPU usage.
More, using "Timer" trigger, it would be VERY easy to create cycles based on CPU load ...
"delay_off" & "delay_on" will contains the duration in millisecond when the drive is on and off ... but I duno what is the maximum value I can put here.

Stay tuned

tkaiser  
Edited by tkaiser at Mon Nov 3, 2014 03:09
destroyedlolo replied at Sun Nov 2, 2014 15:59
"delay_off" & "delay_on" will contains the duration in millisecond when the drive is on and off


Ah, interesting. Didn't realize that before. According to this thread over at cubieforums http://www.cubieforums.com/index.php/topic=1175.0.html these two files should be created automagically when one sets trigger to timer. Doesn't happen here or am I looking in the wrong place?

Edited by destroyedlolo at Mon Nov 3, 2014 15:34
tkaiser replied at Mon Nov 3, 2014 02:08
... two files should be created automagically when one sets trigger to timer. Doesn't happen here or am I looking in the wrong place?


Hum, perhaps due to your kernel.
I'm using Gentoo w/ kernel 3.4.90 and I can see those files created when I set the trigger to timer.
  1. bPI green:ph24:led1 # ls
  2. brightness  device  max_brightness  power  subsystem  trigger  uevent
  3. bPI green:ph24:led1 # echo trigger
  4. trigger
  5. bPI green:ph24:led1 # cat trigger
  6. none battery-charging-or-full battery-charging battery-full battery-charging-blink-full-solid ac-online usb-online mmc0 timer heartbeat backlight gpio [cpu0] cpu1 default-on
  7. bPI green:ph24:led1 # echo timer > trigger
  8. bPI green:ph24:led1 # ls
  9. brightness  delay_off  delay_on  device  max_brightness  power  subsystem  trigger  uevent
Copy the Code
Now, I wonder if I can create an other LED but modifying for fex.
I mean, I would use an unused IO from J12, link it to a led in the fex and control it from /sys as the green one.

If so, I'll be able to monitor both CPU0, CPU1 and system load.

Hello,

some questions about bpi_ledset.c source code : where can I found details of mtio registers ?

I think I more or less understood bits of reg26 & reg27 but what are the meaning of
  1.         mdio_write(skfd, 0x1f, 0x0000);

  2.         val = mdio_read(skfd, 2);
  3.         if ((val & 0xFFFF) != 0x001c) {
  4.                 close(skfd);
  5.                 fprintf(stderr, "unexpected PHYID1: 0x%x\n", val);
  6.                 return 1;
  7.         }

  8.         val = mdio_read(skfd, 3);
  9.         if ((val & 0xFC00) != 0xc800) {
  10.                 close(skfd);
  11.                 fprintf(stderr, "unexpected PHYID2: 0x%x\n", val);
  12.                 return 1;
  13.         }
Copy the Code
Why clearing 0x1f ? Why are we checking values on 0x02 & 0x03 ?
Obviously, I can use those lines out of the box, but it is better to understand, isn't it ?

Edited by destroyedlolo at Sun Nov 9, 2014 07:51

No reply unfortunately and the account of sqr82 seems not active anymore

Anyway, I read somewhere on the Internet the ethernet driver of the banana is an RTL8211E and the code is matching its datasheet. So moving ahead with that ...

sqr82  
destroyedlolo replied at Sun Nov 9, 2014 07:22
No reply unfortunately and the account of sqr82 seems not active anymore

Anyway, I read somewher ...

Hej,

no, he's not dead ;)

As you already observed, the code writes and reads the configuration registers of the Realtek Ethernet PHY IC via MII/MDIO-Interface.
Clearing Register 31 (0x1f) is for having a defined state to start from...as you can see in my code, the register is later written with a different value to be able to change the led configuration registers.  I read the ID of the IC via regs 2 and 3 to check if we are actually accessing the correct IC. You can run the same program on different hardware configurations as well and you don't want to simply write values blindly. That values may do something completely different or even "dangerous" to another PHY IC. In the future there may also be another version of the BPi with different PHY and a different register set. It's merely a sanity check.

As you already remarked, you can look it all up in the datasheet of the Realtek IC. Make sure that the datasheet is for the E version (other version have quite a different register set, even if the functionality seems similar).

So long,
Roman

You have to log in before you can reply Login | Sign Up

Points Rules