Measuring Scheduler Lock Time
µC/OS-III provides facilities to measure the amount of time the scheduler is locked. This is done by setting the configuration constant OS_CFG_SCHED_LOCK_TIME_MEAS_EN
to DEF_ENABLED
in os_cfg.h
.
The measurement is started each time the scheduler is locked and ends when the scheduler is unlocked. The measurement keeps track of two values: a global scheduler lock time, and a per-task scheduler lock time. It is therefore possible to know how long each task locks the scheduler allowing the user to better optimize code.
The per-task scheduler lock time is saved in the task’s OS_TCB
during a context switch (see OSTaskSwHook()
in os_cpu_c.c
and described in Context Switching).
The unit of measure for the measured time is in CPU_TS
(timestamp) units so it is necessary to find the resolution of the timer used to measure the timestamps. For example, if the timer used for the timestamp is incremented at 1 MHz then the resolution of CPU_TS
is 1 microsecond.
Measuring the scheduler lock time adds measurement artifacts and thus increases the amount of time the scheduler is actually locked. However, measurement overhead is accounted for and the measured value represents the actual scheduler lock time as if the measurement was not present.