Skip to content

Commit 0e1a10f

Browse files
committed
Add sched_migrate_task() helper
This commit introduces a new API, sched_migrate_task(), which enables migration of a task between ready queues of different priority levels. The function safely removes the task from its current ready queue and enqueues it into the target queue, updating the corresponding RR cursor and ready bitmap to maintain scheduler consistency. This helper will be used in mo_task_priority() and other task management routines that adjust task priority dynamically. Future improvement: The current enqueue path allocates a new list node for each task insertion based on its TCB pointer. In the future, this can be optimized by directly transferring or reusing the existing list node between ready queues, eliminating the need for an additional malloc() and free() operations during priority migrations.
1 parent fb20c5a commit 0e1a10f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

kernel/task.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,27 @@ static void sched_dequeue_task(tcb_t *task)
406406
return;
407407
}
408408

409+
/* Task migration from origin to new priority ready queue */
410+
static void sched_migrate_task(tcb_t *task, int16_t priority)
411+
{
412+
if (unlikely(!task || !is_valid_priority(priority)))
413+
return;
414+
415+
if (task->prio == priority)
416+
return;
417+
418+
/* Remove task node from origin ready queue */
419+
sched_dequeue_task(task);
420+
421+
/* Update new properties */
422+
task->prio = priority;
423+
task->prio_level = extract_priority_level(priority);
424+
425+
/* Enqueue task node into new priority ready queue*/
426+
sched_enqueue_task(task);
427+
return;
428+
}
429+
409430
/* Handle time slice expiration for current task */
410431
void sched_tick_current_task(void)
411432
{

0 commit comments

Comments
 (0)