I would like feedback on adding optional preemption-threshold scheduling to the FreeRTOS kernel.
Motivation
FreeRTOS currently supports preemptive and cooperative scheduling. A preemption threshold provides an intermediate model for fixed-priority tasks. Each task has its normal priority P and an optional threshold T, where T is at least P. While the task runs, another task may preempt it only if the other task’s priority is greater than T. The running task still relinquishes the processor normally when it blocks, suspends, or yields.
This can reduce context switches and bound selected non-preemptive regions without disabling all preemption. A sufficiently urgent task can still preempt a threshold-protected task.
Proposed interface
The feature would be disabled by default using a configuration option. When enabled, a task’s threshold would initially equal its priority, preserving existing scheduling behavior until the application explicitly raises it.
The initial prototype used these APIs:
void vTaskPreemptionThresholdSet( TaskHandle_t xTask,
UBaseType_t uxNewThreshold );
UBaseType_t uxTaskPreemptionThresholdGet( TaskHandle_t xTask );
For example, a task with priority 3 and threshold 4 cannot be preempted by a priority-4 task, but a priority-5 task can preempt it.
Questions
- Is preemption-threshold scheduling a feature the project would consider?
- Should the initial implementation support only single-core scheduling, or must it include SMP semantics in the first contribution?
- Would maintainers prefer a task-creation parameter, setter and getter APIs, or a different interface?
- How should a threshold interact with inherited priority and runtime priority changes?
- Should equal-priority time slicing remain independent of the threshold?
Implementation and validation plan
I have a proof of concept against an older FreeRTOS kernel copy, but I will not submit that patch directly. If the feature is considered suitable, I will implement it against the current FreeRTOS-Kernel main branch and include CMock unit tests covering task creation, wakeups, notifications, event-list removal, runtime priority changes, static allocation, and unchanged behavior when the feature is disabled.
I would appreciate guidance on the desired semantics and scope before opening a kernel pull request.