Simulation of dynamic periodic task execution. University homework for the "Concurrent And Real Time Programming" course held by Gabriele Manduchi and Andrea Rigoni Garola.
Simulation of dynamic periodic task execution. A pre-defined set of routines (with unique assigned name) shall be defined in advance with given processor usage, period and deadline. Every routine shall be composed of a program loop followed by a nanosleep() call. The exact amount of CPU time and consequently of the processor utilization can be done in advance using the time Linux command. The execution supervisor shall listen in TCP/IP for requests for task activation/deactivation. The received message shall specify the name of the task to be activated. A given task can be activated multiple times, starting every time a new thread running the selected routine. Before accepting a request for a new task, a response time analysis shall be carried out in order to assess the schedulability of the system.
The program is structured in four main components:
- network: network utility functions to send and receive messages from the network.
- supervisor: the core component of the system. Here are defined all the functions needed to run/stop the tasks and assess their schedulability.
- server: uses the network and supervisor components to serve the requests coming from the client (e.g starting a new task).
- client: uses the network component to connect to the server, send commands and receive responses.
The following table outlines the characteristics of the predefined routines with some default values. The values in italics cannot be modified from the configuration file, as they are inherently tied to the routines by design. Conversely, the other values are related to the tasks running the routines. However, since these values are fixed, they are considered coupled with the routines in the program.
| Routine name | Computation time | Period | Deadline |
|---|---|---|---|
| routine1 | 2 | 20 | 8 |
| routine2 | 24 | 500 | 40 |
| routine3 | 58 | 500 | 140 |
The task.conf file gives the ability to the user to change the task properties, in particular the period and the deadline associated with each routine.
All tasks that the user chooses to start will be executed with a priority proportional to their deadlines, as specified in the configuration file. This follows the Deadline Rate Monotonic ordering policy.
All tasks run on a single CPU to better simulate interference from higher-priority tasks that the user decides to execute.
By running the Makefile file in the predefined_routines folder, all the routines in the folder will be compiled and a timing benchmark will be carried out.
The timing benchmark is done by the time.sh bash script. In this script is defined the number of times that the routines are run to compute the average computation time of each routine. You can modify this variable to get an average over more executions of the routines. The default value is RUNSNO=10.
To build the system use the make command in the src folder.
Once the build process has succeeded, you can run the server that will listen for command requests from the client.
sudo ./server <port>
The client can be run with the following command:
./client <address> <port>
N.B. The sudo in the server is required to set the real time attributes of the threads.
The client can issue some commands to see or modify the status of the system. Here's a list of the commands:
help print the help message
quit stop client connection
start <routineName> start a task running the specified routine routineName
stop <task_id> stop the task with ID task_id
ls routines list the predefined routine names
ls tasks list the active tasks in the system
To close the server press CTRL+C on your keyboard.