Implementation
In the reference implementation, the Task Release Service is a dedicated task responsible for cleaning up the task system context of the tasks terminated by the PxDie()
function.
The TaskRS has to be started on each core where tasks are intended to be terminated and is responsible for calling the function PxDieService()
when the kernel signals by the event PXSERVICE_TASK_DIED
that a task has been terminated.
The TaskRS calls PxServiceTaskInit()
to announce itself as the service task. This service task will get events to clean up the task system context after a task dies.
Priority influence
The terminated tasks are cleaned after the PXSERVICE_TASK_DIED
event is signalled, and the TaskRS gets execution time to process the event. TaskRS is subjected to the same scheduling rules as any other task in the system. Hence, its priority will have a major impact on the delay between the task termination request and the actual cleanup.
PxDieService()
PXROS-HR uses a queue (FIFO) of task IDs to be released — "PxDieSrv Task Release Queue" will be used in the following text. This queue is used only by the kernel.
PxDieService()
goes through the PxDieSrv Task Release Queue until there is no task to be released, and for each such task, cleans up the task system context. The following steps are done:
-
Invalidates the task
-
Release the task’s private mailbox
-
Remove any allocated task stack memory
-
Remove any allocated task interrupt stack memory
-
Release the stack for the abort mechanism if not null
-
Return the task control block
-
Release the task object