Giter Club home page Giter Club logo

Comments (4)

nattgris avatar nattgris commented on June 18, 2024

I noticed high CPU load as well (23%), but found it to be the CO_JOB_PERIODIC timer which fires every ms with the SIGEV_THREAD notification, i.e. spawning a new thread every ms. I get high CPU usage without ever receiving a CAN message so I doubt the repeated select() is the (only) culprit.

from c-open.

nattgris avatar nattgris commented on June 18, 2024

Verified that idle CPU consumption scales with the timer period, i.e. 2 ms gives me half the load.

It would be nice if the clients of the periodic job feature could say when they are expiring, so that the timer can be armed to the time required instead of periodically. Since all callees in co_handle_periodic() seems to end up using co_is_expired() to check now against a timestamp and fixed period, this should be easily implemented by returning the time left from co_is_expired() and propagating the minimum value up the call chain to co_main() which can re-arm the timer.

Then also the CO_JOB_PERIODIC message must be force sent whenever any event causes a timer to be set, to recalculate the timeout. Maybe co_handle_periodic() can be called every iteration of the co_main() loop to cover all cases where the event passes trough the main thread? Are there others?

The main loop could probably even use the timeout feature of os_mbox_fetch() to wake up at the right time instead of keeping a separate timer around.

from c-open.

hefloryd avatar hefloryd commented on June 18, 2024

The select() issue should be fixed now, by using epoll(). The timers were reworked to use SIGEV_THREAD_ID, this avoids creating a new thread whenever the timer fires and improves the cpu-usage somewhat. It still seems fairly expensive to do periodic work at 1000Hz though.

I like the idea of calculating the next timeout dynamically, assuming jitter can be avoided (for other platforms where the timers are more reliable). Could you create a new issue for that?

from c-open.

hefloryd avatar hefloryd commented on June 18, 2024

Closed, but see #6

from c-open.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.