laamaa / m8c

Cross-platform M8 tracker headless client
Other
419 stars 87 forks source link

Performance issues on raspberry pi 2, 3, etc #48

Closed SpaceyKasey closed 2 years ago

SpaceyKasey commented 2 years ago

Hey! I wanted to mention I had heard this wasn't working great on anything older than a RPI4. I had a spare RP2 that I wanted to attempt to run this on because I just didn't think it should be particularly resource intensive and found that it was maxing the CPU and barely functional. It looks like the Accelerated SDL2 render is the cause.
I switched the SDL renderer const in renderer.c to SDL_RENDERER_SOFTWARE and now it runs perfect on a PI2 using only like 10% CPU.
Thanks!
Kasey

laamaa commented 2 years ago

Yes, the program uses an accelerated renderer by default. I'd recommend using the Full KMS desktop on Raspberry Pis if it works on your system. Switching to software renderer is also possible like Kasey pointed out.

On Sun 20. Mar 2022 at 6.47, Kassandra Karan @.***> wrote:

Hey! I wanted to mention I had head this wasn't working great on anything older than a RPI4. I had a spare RP2 that I wanted to attempt to run this on because I just didn't think it should be particularly resource intensive and found that it was maxing the CPU and barely functional. It looks like the Accelerated SDL2 render is the cause. I switched the SDL renderer const in renderer.c to SDL_RENDERER_SOFTWARE and now it runs perfect on a PI2 using only like 10% CPU. Thanks! Kasey

— Reply to this email directly, view it on GitHub https://github.com/laamaa/m8c/issues/48, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNUYFQ62O7ZTIQOHIC4HZ3VA2UULANCNFSM5RE67OZA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

SpaceyKasey commented 2 years ago

Does it make sense to add a setting to config.ini for this?

daniel214 commented 2 years ago

To get it to run performantly on my RPi 3B+ I enabled both the KMS driver and the Glamor driver (as documented in #41). I think it would be good to add some of the collected, collective wisdom on getting RPi set up to the Readme.

MarcelloPersico commented 2 years ago

Hi with the chip shortage the only raspberry i can get my hands on is a zero 2 W do you think that with this precautions it will do the job? if not do you know about other SBC that can work as a replacement? thanks in advance!

daniel214 commented 2 years ago

@MarcelloPersico Please try it and report your results!

SpaceyKasey commented 2 years ago

@MarcelloPersico It may be possible on the zero 2 if you run it without X. IE no gui from a terminal. I have been playing around with this on my PI2 to improve battery life. SDL works out of the box without X as long as you build SDL2 locally instead of installing from the raspbian repo.
If you skip installing libsdl from apt and follow this guide it should work. https://stackoverflow.com/questions/57672568/sdl2-on-raspberry-pi-without-x

MarcelloPersico commented 2 years ago

@SpaceyKasey I'll try, but I'm a bit of a nwebie on linux. Do you have an email or discord where I can bother you if I run into any strange problems? It would give you at least 100 karma points I promise 🙃.

askew-etc commented 2 years ago

@SpaceyKasey Were you running this on a desktop (non-headless) system? Because I'm running it without desktop, just SDL2 on a headless system, and for the life of me I can't get the CPU usage down, it micro pauses every second. I changed it to software renderer only like you wrote, did a 'make clean' and recompiled, but it didn't make any difference.

I know it's the display program causing the issue since once when I stopped it, I didn't stop the sound - once the display stopped, the sound was fine.

On another note, you can't Alt-F4 out of the program when running it standalone though SDL with no desktop, nor can you Ctrl-C. I have to SSH in and stop the process.

SpaceyKasey commented 2 years ago

@askew-etc I was, with X disabled. I was running on a Pi 3 and it seemed to work ok. Though a friend of mine tried on her pi 2 and had issues. Also fwiw I am not pulling audio through USB, I directly wired a dac to the appropriate pins on the teensy. I have a fork where I added a key bind for quitting the app. I ended up just running it in x in software mode in the end. There are just a lot of oddities with the pi graphics drivers. One other note is that I found that the RPI driver provided by the SDL repo when you run build locally seems to have issues. The one provided by the SDL make dependencies provided by the raspbian repos seem to work better.

On Mon, Apr 18, 2022, 2:51 AM askew-etc @.***> wrote:

@SpaceyKasey https://github.com/SpaceyKasey Were you running this on a desktop (non-headless) version? Because I'm running it without desktop, just SDL2 on a headless system, and for the life of me I can't get the CPU usage down, it micro pauses every second. I changed it to software renderer only like you wrote, did a 'make clean' and recompiled, but it didn't make any difference.

I know it's the display program causing the issue since once when I stopped it, I didn't stop the sound - once the display stopped, the sound was fine.

On another note, you can't Alt-F4 out of the program when running it standalone though SDL with no desktop, nor can you Ctrl-C. I have to SSH in and stop the process.

— Reply to this email directly, view it on GitHub https://github.com/laamaa/m8c/issues/48#issuecomment-1101153850, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU4JM6TYU7FA7OAQJCW5A6TVFUBAJANCNFSM5RE67OZA . You are receiving this because you were mentioned.Message ID: @.***>

askew-etc commented 2 years ago

@SpaceyKasey Ok I'll try building SDL manually and see if that helps. I was going to look into adding a quit key but I'll grab your fork if you already did it :)

I'm running a DAC on the Pi itself (via GPIO pins, not USB) - do you have a link to docs on how to wire one directly to the Teensy? That might be my issue seeing as the CPU does quite a bit of work processing the audio.

SpaceyKasey commented 2 years ago

I didn't actually find a doc, we just probed pins after I found a couple of other mentions of people having done it.

BCLK1 (pin 20) > WSEL LRCLK1 (pin 21) > BCLK OUT1A (pin 7) > DIN

https://photos.app.goo.gl/KVf2JaBN2Wx4EVRn6

askew-etc commented 2 years ago

@SpaceyKasey Thanks for the info. Since I was using an older DAC (pHAT DAC) and the pinouts online only show the I2S lines that go to the r-pi and not what they actually are, I looked at the traces on the PCM5102 board, and was able to figure out which one was which by looking at the traces on the pHAT DAC since it uses the same chip. I now have it hooked up to the Teensy and sound working - but the same issue persists unfortunately. :( Still, this should free up some r-pi CPU usage (as well as not having to worry about audio loopback routing), and I'll work on manually building SDL next.

laamaa commented 2 years ago

There have been improvements regarding cpu usage in the latest releases and a possibility to use software rendering, closing this as further problems are likely due to the configuration on individual machines.

olablt commented 2 years ago

Did you notice any difference in audio after hooking up the DAC compared to USB loopback on RPI?

I didn't actually find a doc, we just probed pins after I found a couple of other mentions of people having done it.

BCLK1 (pin 20) > WSEL LRCLK1 (pin 21) > BCLK OUT1A (pin 7) > DIN

https://photos.app.goo.gl/KVf2JaBN2Wx4EVRn6

askew-etc commented 2 years ago

Did you notice any difference in audio after hooking up the DAC compared to USB loopback on RPI?

No actually, sounded exactly the same.