1

我在虚拟机上安装了 minix3,并希望我可以操纵当前的队列选择算法,以便我可以将其从优先级顺序更改为包含随机分类的低优先级作业的优先级顺序。我能够发现我需要更改的代码部分在 proc.c 中,具体部分是 pick_proc.c。

/*===========================================================================*
 *                pick_proc                     * 
 *===========================================================================*/
PRIVATE struct proc * pick_proc(void)
{
    /* Decide who to run now.  A new process is selected and returned.
     * When a billable process is selected, record it in 'bill_ptr', so that the 
     * clock task can tell who to bill for system time.
     */
    register struct proc *rp;  /* process to run */
    int q;                     /* iterate over queues */

    /* Check each of the scheduling queues for ready processes. The number of
     * queues is defined in proc.h, and priorities are set in the task table.
     * The lowest queue contains IDLE, which is always ready.
     */
    for (q=0; q < NR_SCHED_QUEUES; q++) {    
        if(!(rp = rdy_head[q])) {
            TRACE(VF_PICKPROC, printf("queue %d empty\n", q););
            continue;
        }

        u64_t timecount;
        u32_t randdom;
        read_tsc_64(&timecount);
        rand = timecount.lo;

        #if DEBUG_RACE
        rp = random_process(rdy_head[q]);
        #endif

        TRACE(VF_PICKPROC, printf("found %s / %d on queue %d\n", 
              rp->p_name, rp->p_endpoint, q););
        assert(proc_is_runnable(rp));
        if (priv(rp)->s_flags & BILLABLE)         
            bill_ptr = rp;        /* bill for system time */
        return rp;
    } 
    return NULL;
}

我已经放了一些代码来开始随机化过程,但我不知道从哪里开始。我知道我需要在这个文件中添加一些东西,但我不确定哪些变量做了什么以及我需要更改哪些指针。我希望有人能告诉我如何做到这一点,或者指出我需要改变哪一部分来帮助我继续前进。现在我很困。

4

1 回答 1

0

感觉像是一个微妙的问题;更改算法可能会使高优先级任务无法完成。Q1:什么是“低优先级任务”?那是 NR_SCHED_QUEUES/2 吗?Q2:在您愿意选择较低优先级的任务之前,最多必须等待多少个较高优先级的任务?回答这个问题后,您可以将 for 循环中的 q=0 更改为例如 q=low_tasks 并从那里选择一个进程。

for (p=0, q=0; q < NR_SCHED_QUEUES/2; q++)
    p += rdy_tail[q] - rdy_head[q]; // number of processes in this queue
if (p<some_value) q= NR_SCHED_QUEUES / 2; else q= 0;

for (; q < NR_SCHED_QUEUES; q++) {    
    if(!(rp = rdy_head[q])) {
        TRACE(VF_PICKPROC, printf("queue %d empty\n", q););
        continue;
    }

    TRACE(VF_PICKPROC, printf("found %s / %d on queue %d\n", 
          rp->p_name, rp->p_endpoint, q););
    assert(proc_is_runnable(rp));
    if (priv(rp)->s_flags & BILLABLE)         
        bill_ptr = rp;        /* bill for system time */
    return rp;
} 
return NULL;

注意:这只是演示,不保证能正常工作!

注意:您还必须检查是否有较低优先级的任务要运行。

于 2014-10-27T13:43:06.907 回答