Skip to content
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

libpigpiod consumes too much CPU #380

Closed
knro opened this issue Apr 24, 2021 · 8 comments
Closed

libpigpiod consumes too much CPU #380

knro opened this issue Apr 24, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@knro
Copy link
Collaborator

knro commented Apr 24, 2021

Just noticed that this pigpiod takes about 7% to 10% on raspberry pi CPU while not used. @ken-self Can you please check what's going on? Since this causes the performance of the PI to degrade substantially.

@knro knro added the bug Something isn't working label Apr 24, 2021
@ken-self
Copy link
Contributor

I saw this early on and looked it up. According to the author joan2937 this is only on one of the 4 CPUs so actually 2% overall.
joan2937/pigpio#29
It is possible to reduce the sample rate with switch "-s 10" on the daemon and/or with switch "-m".
I'll give those a try to see if they help

@ken-self
Copy link
Contributor

The -m option reduces the idle CPU to zero BUT stops the Timed GPIO port option in the driver from working. I assume the sampling is needed by the watchdog timer. This driver function is primarily for triggering DSLR bulb exposures. So we could default to -m and advise DSLR users to remove the switch in the service. This should only affect those DSLR users not using libgphoto. It would also affect users using the timer function for other purposes like flashing LEDs

@knro
Copy link
Collaborator Author

knro commented Apr 25, 2021

Thanks, but even this small CPU percentage was causing the GUI to be a bit unresponsive in Raspberry PI. I suppose it's not possible to programatically trigger this on/off after starting the server somehow? INDI uses FIFO for this purpose for example.

@ken-self
Copy link
Contributor

No, it cannot be switched programatically. I'll look around for an alternative timing mechanism. I just used the built-in pigpiod hardware timer because it was convenient. But if I can find an alternativethat should work just as well and allow the -m switch to be used. Worst case I might need to restrict the timing function to just one pin.
Do you have any preferred timer? Ideally something that triggers a callback when the timer expires. I've seen some examples that use boost::asio and boost::chrono that might do the job

@knro
Copy link
Collaborator Author

knro commented Apr 26, 2021

Recently @pawel-soja added timers to INDI, but not sure if they're suitable for this kind of work?

@pawel-soja
Copy link
Contributor

That's right, but I wrote timers based on those already existing in INDI Core. The class provides an easy-to-use interface.
In the future, it will also be a precise timer. Current disadvantages:

  • works on the main thread (no change possible)
  • event loop is not woken up when adding a new timer - this causes a slight delay in the first callback call.

https://github.com/indilib/indi/blob/master/libs/indibase/timer/inditimer.h
Example:

#include "inditimer.h"
// ... //
INDI::Timer timer;
timer.callOnTimeout([](){
  // Hello!
});
timer.setSingleShot(false); // periodic timer - constant frequency of events
timer.start(10); // 10 ms

I will offer RPi support (optimization) as soon as I deal with the libASICamera2Boost - Currently, I can help, but I need the exact spot of the problem.

@ken-self
Copy link
Contributor

Thanks @pawel-soja I think I can manage on my own using inditimer

@ken-self
Copy link
Contributor

ken-self commented May 4, 2021

@knro do I need to do anything to add libpigpiod to the nightlies? indi-asi-power and indi-rpi-gpio have a dependency on it.
Latest PR adds the -m option which reduces idle CPU to near zero %. The INDI timer works well with about 1 ms error per 1000 ms which is negligible.

@knro knro closed this as completed May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants