Measuring Interrupt Disable Time
µC/CPU provides facilities to measure the amount of time interrupts are disabled. This is done by setting the configuration constant CPU_CFG_INT_DIS_MEAS_EN
to 1 in cpu_cfg.h
.
The measurement is started each time interrupts are disabled and ends when interrupts are re-enabled. The measurement keeps track of two values: a global interrupt disable time, and an interrupt disable time for each task. Therefore, it is possible to know how long a task disables interrupts, enabling the user to better optimize their code.
The per-task interrupt disable 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. It is necessary to find out the resolution of the timer used to measure these 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 interrupt disable time obviously adds measurement artifacts and thus increases the amount of time the interrupts are disabled. However, as far as the measurement is concerned, measurement overhead is accounted for and the measured value represents the actual interrupt disable time as if the measurement was not present.
Interrupt disable time is obviously greatly affected by the speed at which the processor accesses instructions and thus, the memory access speed. In this case, the hardware designer might have introduced wait states to memory accesses, which affects overall performance of the system. This may show up as unusually long interrupt disable times.
Finally, because the interrupt disable time is also affected by the overhead caused by enabling trace calls, enable tracing only when tuning or debugging your embedded application, and disable tracing when you are finished or when you want to measure interrupt disable time without any tracing artifacts (e.g. OS_CFG_TRACE_EN
in os_cfg.h
).