xPC Target | ![]() ![]() |
Polling Mode
The polling mode for the xPC Target real-time kernel does not have the 8 us of latency that is with the interrupt mode. This is because the kernel does not allow interrupts at all, so the CPU can use this extra time for executing model code.
Polling mode is sometimes seen as a "primitive" or "brute force" real-time execution scheme. Nevertheless, when a real-time application executes at a given base sample time in interrupt mode and overloads the CPU, switching to polling mode is often the only alternative to getting the application executing at the required sample time.
Polling means that the kernel waits in an empty while loop until the time at which the next model step has to be executed is reached. Then the next model step is executed. For this at least a counter implemented in hardware has to be accessible by the kernel in order to get a base reference for when the next model step execution has to commence. The kernel polls this hardware counter. If this hardware counter must be outside the CPU, say in the chipset or even on an ISA or PCI board, the counter value can only be retrieved by an I/O or memory access cycle that again introduces latency. This latency usually eats up the freed-up time of polling mode. Fortunately, since the introduction of the Pentium CPU family from Intel, the CPU is equipped with a 64 bit counter on the CPU substrate itself, which commences counting at power-up time and counts up driven by the actual clock rate of the CPU. Even a highly clocked CPU is not likely to lead to an overflow of a 64 bit counter (2^64 * 1e-9 (1 GHz CPU) = 584 years). All in all the Pentium counter comes with the following features:
The polling execution scheme is not dependent on any interrupt source to notify the code to continue calculating the next model step. While this frees up the CPU, it means that any code that is part of the exclusively running polling loop is executed in real time, even components, which have so far been executed in background tasks. Because these background tasks are usually non-real-time tasks and can use a lot of CPU time, there is only one solution: Do not execute them. And this is the big disadvantage of polling mode: In order to be efficient, only the target application's relevant parts should be executed, and this is, in the case of xPC Target, the code representing the Simulink model itself. Therefore, host-target communication and target display updating are disabled. Because polling mode reduces the commonly known features of xPC Target to a minimum, you should choose it only as the last possible alternative to reach the required base sample time for a given model. Therefore, the following should be assured before you consider polling mode.
xpcbench
at the MATLAB command prompt gives an understanding about the best performing CPUs for xPC Target applications.
![]() | Interrupt Mode | Setting the Polling Mode | ![]() |