`resched_curr` 中不会立即重新安排当前任务

问题描述 投票:0回答:0

我正在为 6.0.19 版的 Linux 设计一个自定义的 Linux 调度程序。它是 rsdl scheduler 的一个版本。

现在,在分配给当前作业的时间片到期后,我需要调用调度程序,以便我可以将该任务切换到新任务(上下文切换)。为此,我执行以下操作:

task_tick_rsdl
钩子函数(由我实现)中当任务的量子达到零时,我调用函数
resched_curr
.

static void task_tick_rsdl(struct rq *rq, struct task_struct *curr, int queued)
{
    struct sched_rsdl_entity *rsdl;
    struct rsdl_rq *rsdl_rq;
    int *queue_quota;
    trace_printk("task_tick_rsdl\n");
    rsdl = &curr->rsdl;
    rsdl_rq = &rq->rsdl_rq;
    queue_quota = rsdl_rq->active->quota + rsdl_rq->curr_prio;

    update_curr(rsdl_rq);

    if (rsdl->quota && *queue_quota) {
        rsdl->quota--;
        *queue_quota = *queue_quota - 1;
    }

    printk("p = %d ; tq = %lld\n ; qq = %d; cur_prio = %d", curr->pid,
           rsdl->quota, *queue_quota, rsdl_rq->curr_prio);

    if (!(rsdl->quota > 0 && *queue_quota > 0)) {
        resched_curr(rq);
        printk("need resched\n");
    }
}

问题是,即使在要求重新安排之后,也需要几个时钟滴答才能最终触发计划。

我遇到的情况如下:

[   71.561489] picked task : pid = 170, quota = 0
[   71.561489] , prev = 36, cur = 36
[   71.561503] p = 170 ; tq = 0
[   71.561503]  ; qq = 5; cur_prio = 36
[   71.562085] need reached                  <-----------scheduler should have been called after this
[   71.562811] p = 170 ; tq = 0
[   71.562811]  ; qq = 5; cur_prio = 36
[   71.562812] need resched
[   71.563502] p = 170 ; tq = 0
[   71.563502]  ; qq = 5; cur_prio = 36
[   71.563503] need resched
[   71.564207] p = 170 ; tq = 0
[   71.564207]  ; qq = 5; cur_prio = 36
[   71.564208] need resched
[   71.564899] setting flag 1                <-----------scheduler actually called
[   71.565108] curr_prio = 36
[   71.565320] picked task : pid = 166, quota = 5
[   71.565320] , prev = 36, cur = 36

你能指导我解决这个问题吗?

c linux linux-kernel scheduling
© www.soinside.com 2019 - 2024. All rights reserved.