0

I'm programming an embedded real-time Linux device with a 4 core ARM CPU. There is a requirement for a periodic computation at 10 kHz that should not jitter too much and should never be lost. My POSIX thread can read a HW-provided 10 kHz toggle register in a busy loop and perform the computation whenever the bit is toggled.

In order to keep the SCHED_RR scheduler from interrupting the pthread I set the CPU affinity to core 2 exclusively for this thread, and the priority to 99 (maximum). A handful of other threads have CPU affinity set to cores other than 2 and priority 50. But there's still a systemd running and a bunch of other processes.

Is this enough to keep the thread from ever being interrupted by the scheduler? If not, is there a way to achieve this?

16
  • no, that is not a guarantee. Why would you do this by busy looping on a hardware toggle instead of using a timer? That seems pretty strange, and also like an explicit invitation for context switches when you don't want them. Commented Jan 15 at 16:09
  • @MarcusMüller Can timers have a better granularity than the scheduling tick (which is 10ms or so)?
    – Jens
    Commented Jan 15 at 16:13
  • yes, significantly. (also, your scheduling tick isn't that relevant in this scenario) Commented Jan 15 at 16:14
  • /proc/timer_list should "contain" a detailed rundown of all available timers you can use with timer_create or, probably more sensible in your use case, timerfd_create. Note that "I need to use some component A (be it a timer, a hardware toggle or anything else) to do a computation every 10 ms, for some unnamed component B" screams "You should tell us about what B is, and why you need to do computations every 10 ms, instead of whenever B is ready", because I bet the right solution lies that way. Commented Jan 15 at 16:19
  • @MarcusMüller B is a tracking control loop that needs to be updated at 10kHz (0.1ms!) with a set of values, with time synced to an external 1pps signal which in turn tunes a DPLL. Rocket science; it is going to space, not today, but eventually :-)
    – Jens
    Commented Jan 15 at 19:31

0

You must log in to answer this question.

Browse other questions tagged .