nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

sched/semaphore: Fix priority restoration

Open ThomasDebrunner opened this issue 3 years ago • 0 comments

Summary

Another attempt at fixing https://github.com/apache/incubator-nuttx/issues/6310 Difference to https://github.com/apache/incubator-nuttx/pull/6318 is that in this attempt, the reason for the boost (the address of the semaphore causing the boost) gets stored in the list of boosts in the tcb.

Main idea: Instead of just storing an array of priorities but forgetting to what tasks they belong to, we store the address of the semaphore as well. Then, on every boost we put a (semaphore, new_priority) tuple in the array, on every release, we remove the one that corresponds to the released semphore with the highest priority, iff we still hold a count on that semaphore, otherwise we remove all that correspond to the semaphore. At the end, we just set as the priority the maximum value of all boosts on all semaphores that are in the array

Impact

This should generally fix the priority inheritance issues seen in https://github.com/apache/incubator-nuttx/issues/6310. It passes some hand-crafted adverse tests.

After this patch, memory footprint increases by n_tasks * CONFIG_SEM_NNESTPRIO * 4 bytes more memory. This could potentially be mitigated by using a linked list with preallocated holders instead of the array in the tcb, (like with the semaphore holders list).

Testing

ThomasDebrunner avatar May 30 '22 08:05 ThomasDebrunner