-
Notifications
You must be signed in to change notification settings - Fork 48
100% CPU utilization on RPi4 #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you post the code you are running? |
Sure, I reduced it to the minimum and tested it. Still 100% on a single core: #!/usr/bin/python3
import time, struct, sys, board, busio
import digitalio
import adafruit_rfm9x
RADIO_FREQ_MHZ = 434.0
CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
radio = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
radio.tx_power = 23
radio.spreading_factor = 7
radio.enable_crc = True
radio.signal_bandwidth = 250000
if __name__ == '__main__':
try:
while True:
packet = radio.receive(timeout=10, with_ack=False, with_header=False)
if packet is not None:
print("Received: ", packet)
except KeyboardInterrupt:
sys.stdout.flush()
finally:
sys.stdout.flush() Python version is 3.9.2 |
Thanks, I tried your code on a Pi5 (snce that is what I had handy) and the load gets distributed a bit better, but I'm sure it would be the same as your results on a Pi4. I'm not really surprised since there is nothing in the code that will give the CPU a "break". I just wanted to confirm the behaviour. |
Thanks for testing :) I already saw your lib and appreciate your efforts :) I will definitely try your new lib and give feedback here. @jerryneedell litte Update: Essentially my biggest concern is that a RPi Zero in 24/7 receive mode might have a short lifespan due to constant 100% usage. |
I tried this with the new library and the CPU usage appears to be great;y reduced (on my Pi 5) - Note: I did change the frequency to 915 since I am in the USA.
Now to see if I can find my Pi4... |
Looking at the adafruit_rfm9x.py code, it may be possible to reduce the CPU usage by inserting a short sleep - something like "time.sleep(.001)" in the "receive" function -- https://github.com/adafruit/Adafruit_CircuitPython_RFM9x/blob/main/adafruit_rfm9x.py#L844 I don't think this will impact the receiver in list mode, it should just slow down the polling for the packet. Edited to add: I am curious if the 100%CPU usage is actually causing you problems or if it is just a curiosity. |
Also FYI -- On a RPi Zero2W using the new library with the example above drops the CPU usage from 100% to about 75% on one core. |
Not really, but since you are the first person to actually express an interest in using it, I will try to get back to my testing. I just need to convince myself it "does no harm". With the combined libraries and new modes, it just takes awhile to create examples and test it on both the Raspberry Pis and other MCUs. I'll post here when I make progress on releasing the new library. Thanks for the testing. |
What exactly do you mean by "harm"? If you need any testing support, I'm open to assist :) |
I just want to make sure it does note break anything that works in the current libraries. |
I ran into the same high load issue, which took a while to figure out because I was chasing missed/mangled messages. What I ended up doing was adding a 20ms delay in the receive loop where it waits for self.rx_done. The load went from mid-90% to <5%. A 50ms delay was too long and I was still missing/mangling received messages. I imagine the minimum time could be calculated based on the on-air time of the smallest packet at the fastest data rate. I get 4-5 messages as a block every 5min, and since this change, zero bad messages (actual contents checked with sha1sum on both ends). |
You may want to try the new library https://github.com/adafruit/Adafruit_CircuitPython_RFM which utilizes asyncio. It has not been released yet, so it is not in the bundle or PyPi, but you can download it from the repository if you want to give it a try. Your code changes should be minimal to use it with your existing code, take a look at the examples. Any comments or suggestions would be welcome. |
Is anyone else also facing the issue, that the CPU utilization reaches 100% on the receiving side?
I use a Pi4 2GB and have a constant 100% cpu utilization on one core.

The text was updated successfully, but these errors were encountered: