“Rennie Allen” <rallen@csical.com> wrote in message
news:br2cqi$d4f$1@inn.qnx.com…
Sporadic scheduling does not appear to work the way I understand
it should.
Here is how I create a sporadic thread:
pthread_attr_t attr;
sched_param param;
pthread_attr_init(&attr);
memset(¶m, ‘\0’, sizeof param);
param.sched_priority=sched_get_priority_max(SCHED_SPORADIC)-10;
param.sched_ss_low_priority=sched_get_priority_min(SCHED_SPORADIC)+5;
param.sched_ss_max_repl=3;
nsec2timespec(¶m.sched_ss_repl_period, 401000000);
nsec2timespec(¶m.sched_ss_init_budget, 201000000);
pthread_attr_setschedparam(&attr, ¶m);
pthread_attr_setschedpolicy(&attr, SCHED_SPORADIC);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_create((pthread_t *)thread, &attr, sporadic_thread, NULL);
As long as sporadic_thread blocks (at least once), the sporadic
scheduling appears to work (i.e. I can see the thread has a prio of
“53?”); however, it does not ever appear to decay to the low priority.
Should I not see it at least some time at the low priority (I never do) ?
The fact that it does not decay can be confirmed by changing the
threads code so that it does not block, at which point the system
freezes (requiring a reboot).
The scheduler should decay the priority of this thread to the lower
priority even if it never blocks, should it not (given the above
parameters) ?
Not necessarily. It depends on what the thread is doing during each
of the intervals you have defined.
If the thread consumes more than 20ms of CPU during a 40ms interval,
its priority will be dropped – I don’t think decay carries the right
connotation here – to the lower priority.
At the beginning of the next 40ms interval, it has its budget replenished,
so it can use another 20ms of CPU at the higher priority. It can do this
up to three times. If it finishes after 120 ms or doesn’t use more than
20 ms in any interval, or more after the third interval than the remaining
unused budget, the priority won’t be lowered.
This is useful if, say, the thread is handling events at a maximum arrival
rate of 5 every 40 ms, and they take on average 4 ms to handle. In such
cases,
if I take longer than 4 ms to process one and if the total exceeds 20ms, the
thread
misses its deadline, but doesn’t affect periodic threads’ deadlines.
This also allows compute-bound activities with a longer deadline, D1, to run
in up to 20 ms
chunks for a longer period as long as the sched_priority is set to the
appropriate
RMS priority for a 20ms/40ms rate, and min_priority is set below all RMS
scheduled
priorities.
e.g. D1 = Now + 120 ms.
Cost = 60 ms.
is broken in to Ci = 20 ms computations over Ti = 40 ms periods.
and Ci/Ti can be admitted in to the existing (SUM(Cj/Tj) <
Capacity, for all j < i) schedule, and
sched_priority is set to the priority derived for the 20ms/40ms
rate.
If it doesn’t exceed its total budget (60ms), it will complete by
its deadline.
Thanks for any help on this.