# A C-Based Framework for Low-Cost Real-Time Embedded Systems
## 8 Performance Evaluation and Analysis
### Time-Driven Execution Performance  
The time-driven execution performance of RtFw has been evaluated by considering the general overhead imposed on cyclic execution by framework synchronization and Modbus I/O time, as well as the trend of I/O time as a function of the number of PI variables to be transferred. Accordingly, in the first part of the tests, RtFw was configured to access one 16-bit input and one 16-bit output PI variable, each corresponding to a single Modbus register. Figure 12 illustrates which time measurements have been performed by means of a timing diagram. The diagram is organized vertically along the four operational layers that together implement synchronization and cyclic execution within RtFw. The topmost layer is the FreeRTOS _tick interrupt handler_, executed every 1 ms. Besides using the handler to perform internal timekeeping activites--for instance, delayed task activation--FreeRTOS supports a timer _hook_ function and invokes it from the handler on every tick. This provides a convenient timestamping point located very early in the RtFw cyclic synchronization chain. In the figure, \(t_{1}\) represents the time needed to synchronize the first layer with the second. More specifically, it is the delay between the end of the hook and timer task activation, defined as the conclusion of its passive wait operation, implemented by means of the vTaskDelayUntil FreeRTOS primitive, as described in Section 4.1. In turn, the _timer task_ in the second layer triggers the activation of the _control task_ in the third, passing through the event system also discussed in Section 4.1. Event propagation within RtFw takes an amount of time denoted as \(t_{2}\). The control task performs most of the cyclic activities of RtFw, including the activation of the fourth and last layer, the user-written _control function_. Here, measurements have been focused solely on I/O operations, because the control function content is going to vary depending on user-level application requirements and measuring its execution time in a specific case would have had little practical significance. Moreover, as explained in Section 6, mirroring between PI and shared memory variables consists of a memory-to-memory copy involving data items of small size, which is negligible unless the number of variables being copied is atypically large. Therefore, the measurements in the third layer are the total output time \(t_{O}\) and the total input time \(t_{I}\). Each of them consists of local and Modbus communication. Then, Modbus communication time was further split up to evaluate the data gathering/scattering times, called \(t_{O,1}\) and \(t_{I,2}\), respectively, as well as the output and input bus transaction times \(t_{O,2}\) and \(t_{I,1}\). Local I/O time was not singled out because it was found to be negligible with respect to Modbus communication time. Data gathering and scattering are an essential part of the Modbus I/O process because, for better efficiency, RtFw carries out bus transactions in aggregated form whenever  
Figure 12: Framework timing diagram, time-driven execution. possible. In other words, PI variables that are either all inputs or all outputs and are mapped to a contiguous range of addresses on the same board are transferred in a single bus transaction. Aggregation decisions are taken just once before cyclic activities begin, and hence, do not contribute to RtFw overhead within the control cycle itself. On every cycle, however, it is still necessary to gather the PI variables to be aggregated and copy their values into the contiguous data buffer to be used for the output transaction. Symmetrically, after an input transaction has taken place, data retrieved from the remote I/O board must be copied into the corresponding PI variables, which are scattered through memory. Table 1 summarizes experimental results. For each delay, the mean value (\(\mu\)), standard deviation (\(\sigma\)), and minimum and maximum value (Min and Max) are shown.