Staacks / there.oughta.be

Projects featured on my blog at https://there.oughta.be
https://there.oughta.be
GNU General Public License v3.0
101 stars 33 forks source link

No animation by using --led-daemon option #15

Closed eurosting closed 3 years ago

eurosting commented 3 years ago

I'm still on testing of LED cube. In case I run the led script like this, the animation works with 170Hz:

pi@pi-rgb:~/led $ sudo ./cpu
Initialized EGL version: 1.4
GL Viewport size: 192x64

If I start the led script as prozess, then there no animation: pi@pi-rgb:~/led $ sudo ./cpu --led-daemon

The core 3 is isolated by using isolcpus=3 option in /boot/cmdline.txt. According to htop the led prozess runs on core 3 with 100%.

My goal to reduce the FPS from 170Hz to 60-120Hz and reduce the load of cpu. And I would also like to run the animation on isolated core, to be able to use PI3 also for other purposes.

Please any advice?

eurosting commented 3 years ago

additional info. The rpi-rgb-led-matrix sample/demo runs well as prozess on core 3 and uses 75% of the core. I used this line: pi@pi-rgb:~/rpi-rgb-led-matrix/examples-api-use $ sudo ./demo -D0 --led-gpio-mapping=adafruit-hat-pwm --led-slowdown-gpio 2 --led-cols=192 --led-rows=64 --led-brightness=30 --led-daemon

Staacks commented 3 years ago

I am neither sure I understand what this parameter is supposed to do or what you expect it to do...

First of all, you should not need to do anything besides setting isolcpus=3 to get the refresh process onto its own core. Let me explain what happens when you start cpu-stats-gl:

  1. The system launches a process "cpu-stats-gl", let's call it "render process"
  2. At some point, this process loads the rgb matrix library
  3. This library then starts its own process (I think it will have the same name, but let's call it "refresh process" to distinguish it)
  4. The render process enters a loops in which it renders the image for the cube and hands the image over to the refresh process
  5. The refresh process also runs in a loop and repeatedly shows the latest image from the render process on the cube.

The refresh process is what has to run with exact timing to avoid flickering and it is designed to always only run the last core on the system (on a four core Pi, it is core 3 as we start counting with core 0). This is hard coded and cannot be changed by a parameter: https://github.com/hzeller/rpi-rgb-led-matrix/blob/9f5ffd8a93614dbf3b6262103aefea2e3ba268bd/lib/led-matrix.cc#L473

If you set isolcpus=3 you only tell your OS (or its thread scheduler) to not send any process to this CPU, so the refresh process can be on its own.

Now for the --led-daemon parameter: A daemon is not much different from a "normal" process. As far as I understand it, this just means that the process detaches from the user session (i.e. it keep running when you log out) and does not expect any user interaction. However, as this is a parameter for the rgb-panel library I do not see how it could affect the render process. So, I would only expect that this means that the refresh process detaches from the render process (and thus from the user session), which would not do anything in this case. I have to admit that I do not know what the use case is, but it is not required for the LED cube as you would simply launch the cpu-stats-gl program in a launch script and would not care whether it detaches from anything.

Am I missing the point of your question or the use case for this parameter? If not, I would close this issue as I do not think that this parameter applies here...

eurosting commented 3 years ago

Hello Sebastian, thank you very much for the explanation.

I'm using MobaXterm software to open SSH connection to Pi3. At the moment I start led animation manually like a normal prozess by using this command pi@pi-rgb:~/led $ sudo ./cpu. The animation works, but in this case I can't do anything more (the terminal is in use by the animation).

Could you please tell me how to start LED cube prozess in the "background"? Sorry, I'm a windows user. On this page I found the parameter --led-daemon, which works fine for matric examples, but not for the LED cube.

https://github.com/hzeller/rpi-rgb-led-matrix

P.S. cpu is the name of your LED cube animation

eurosting commented 3 years ago

it seems I found how to start the led cube as prozess prozess. I just add & after the command. pi@pi-rgb:~/led $ sudo ./cpu & Well, issue solved 👍

Staacks commented 3 years ago

Jepp, exactly :) An & at the end usually does the trick. If you add the command to an init script (I just launch it in /etc/rc.local, but Linux has maaaany alternatives here), don't forget to add the & there as well as most scripts do not like it if they never return.