1

我想自定义 minix 文件的代码/usr/src/kernel/proc.c以实现 FCFS 算法,但我没有任何想法或线索。我已经说过,当前算法以某种优先级工作,所有进程首先进入一个队列,然后使用某种算法,然后为进程分配一些优先级。但是如果我需要实现 FCFS,那么我应该只使用一个队列。

但是如何关联这些东西呢?

4

1 回答 1

2

One possibility – probably not a good one – is to modify the enqueue() function:

PUBLIC void enqueue(register struct proc *rp)   
{
    /* Add 'rp' to one of the queues of runnable processes.  This function is 
     * responsible for inserting a process into one of the scheduling queues. 
     * The mechanism is implemented here.   The actual scheduling policy is
     * defined in sched() and pick_proc().
     */
    int q = rp->p_priority;                       /* scheduling queue to use */

Instead of assigning rp->p_priority, simply assign 0:

   int q = 0;

All processes are thereby enqueued on a a single priority queue (queue number 0) and you have a single FCFS system. Of course, that assumes that enqueue() is the only function that adds processes to queues. There's a decent chance that it is the only one, but you need to know most of the Minix kernel to be sure.

With that modification in place, you can then investigate whether there is too much space wasted supporting multiple queues. If there is, you can adjust the queue declarations appropriately. The queue structure is probably just an array of pointers; the space saving available is not great, therefore.

Note, however, that you probably don't want FCFS only; the priority queues are there for good reasons. For example, your interrupt handlers should be serviced more swiftly than the number-crunching monster that is working for SETI. That means that there needs to be some prioritization.

于 2012-03-25T18:27:45.453 回答