Time Management Functions

Time management is another critical activity on kernels. It is required to:

  • Activate periodic tasks.

  • Check if temporal constraints are met (e.g. deadline violations).

  • Measure time intervals (e.g. self-suspension).

It is based on a system timer. There are two common modes:

  • Periodic tick: generates periodic interrupts (system ticks). The respective ISR handles the time management. All temporal attributes (e.g. period, deadline, waiting times) must be integer multiples of the clock tick.

  • Single-shot/tickless: the timer is configured for generating interrupts only when there are periodic task activations or other similar events (e.g. the termination of a task self-suspension interval).

Tick-based Systems

The tick defines the system’s temporal resolution.

  • Smaller ticks corresponds to better resolutions.

  • E.g. if tick=10 ms and task periods are: T1=20ms, T2=1290ms, T3=25ms,

A bigger tick lowers the overhead; compromise!

  • tick = GCD(Ti), i = 1..N

  • E.g. T1=20 ms, T2=1290 ms, T3=25 ms, then GCD(20,1290,25)=5 ms

  • Works but Utick doubles!

Measurement of time intervals

In tick-based systems, the kernel keeps a variable that counts the number of ticks since the system boot.

  • In FreeRTOS the system call xTaskGetTickCount() returns the number of ticks since the scheduler was initiated (via vTaskStartScheduler()).

  • The constant portTICK RATE MS can be used to calculate the (real) time from the tick rate with the resolution of one tick period.

  • Better resolutions require e.g. the use of HW timers.

Be careful with overflows.

E.g. in Pentium CPUs, with a 1GHz clock, the TSC wraps around after 486 years !!!

Management functions

Scheduler

The scheduler selects which task to execute among the (eventually) several ready tasks.

In real-time systems must be based on deterministic criteria, which must allow computing an upper bound for the time that a given task may have to wait on the ready queue.

Dispatcher

Puts in execution the task selected by the scheduler.

For preemptive systems, it may be needed to preempt (suspend the execution) of a running task. In these cases, the dispatch mechanism must also manipulate the stack.

Last updated