Discussion:
[Emc-users] Thread scheduling
Nicklas Karlsson
2017-06-11 12:10:48 UTC
Permalink
Then adding a second thread with "threads" command with a period one second it seems I got a lot more read timeouts than running the same function at servo period. It might be a random error because of some or scheduling. Do anybody know how threads with different periods are scheduled in Linuxcnc?


Nicklas Karlsson
Gene Heskett
2017-06-11 20:17:19 UTC
Permalink
Post by Nicklas Karlsson
Then adding a second thread with "threads" command with a period one
second it seems I got a lot more read timeouts than running the same
function at servo period. It might be a random error because of some
or scheduling. Do anybody know how threads with different periods are
scheduled in Linuxcnc?
Nicklas Karlsson
I have been told here, that the fastest thread runs at the highest
priority and it can interrupt slower threads.

I have a second thread running at either 100 or 200 Hz, with all my
jogging stuff using that thread. So far, the only gotcha in checking out
the overall accuracy has been x related, and occurs when I accidentally
hit the soft limit, which is about 10 thou outside the X home switch.
It throws away any attempts to back all the way out
and crash, in this case drive belt pulley against the front face of the
cross-slide. Other than that, I can stand there and twist the dial left
and right, for as long as these old wrists want to do it, running it
against the MAXVEL speed limits for a minute or so, twist the dial back
to 0.00, and when the motors stop its within a thou (according to a 1"
range dial) of its starting point and the DRO is back on 0.00. Backlash
is about 1.8 thou. X screw nut needs even bigger balls fitted.

Thats good enough for the girls I go with. :)

Cheers, Gene Heskett
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
Jeff Epler
2017-06-11 21:11:00 UTC
Permalink
linuxcnc's thread model is "rate monotonic scheduling".

- the thread with the smallest period (highest frequency) must be
created first. It is created with the highest available priority
in the underlying RTOS
- subsequent threads must be ordered by frequency and get
descending priority
- all threads are bound to the same CPU/core/thread
- the RTOS needs to guarantee that faster/higher priority threads
are allowed to preempt slower/lower priority threads, but not the
other way around

Remember, rtapi/hal was designed in a day where dual processor
systems were rare unobtainium, and for 2 CPUs it made perfect sense
to imagine the UI and task as running on one CPU and realtime on the
other (isolcpus= in older kernels). Today you might choose a
different design, but remember also that for the (rare!) components
which expose multiple functions that are intended to be executed in
different threads (e.g., software stepgen), rate monotonic
scheduling can be a great simplifying assumption.

It is mainly these components which need to be reviewed and fixed if
a different thread model (such as each HAL thread being bound to a
distinct processor thread/core) is to be adopted. However, another
detail that is important is the speed (or lack of it!) to transfer a
cache line of data from one processor/thread's L1 cache to another.
For instance, if you put "fast" thread on CPU1 and "slow" thread on
CPU2, then any data that is read by "fast" thread and written by
"slow" thread has its associated cache line bounce between the two
CPUs. Furthermore, any HAL data on the same cache line would have
to "bounce" with it, potentially making for even more cache line
bounces than necessary. I hear that machinekit made each pin's data
reside on a separate cache line for this reason, but I'm unaware of
the details or the exact microbenchmarks that showed this was a good
decision.

So, yes, long story short: if your main thread has marginal timing,
adding another faster thread is going to make it start missing
deadlines.

Jeff

Loading...