2016-03-07 69 views
1

所以我要实现我的OS类离散事件CPU调度程序,但我不太明白它是如何工作。我读过的每一个解释/教科书总是会让我觉得这些东西对我来说有点过于抽象,无法确定它是如何实际工作的,它也不会用cpu连发和io连发(有些做但仍然没有帮助足够)。我没有发布任何我有的代码(我写了很多实际的内容,但是我想在我找出(用特朗普的话说)究竟是怎么回事之后,我会重写它)。相反,我只是想帮助找出一种我可以实现的伪代码。 我们给出了到达时间(AT),总CPU(TC),CPU爆发(CB)和Io爆发(IO)的多个进程。假设我给出:p1(AT = 1,TC = 200,CB = 10,IO = 20)和p2(AT = 1000,TC = 200,CB = 20,IO = 10)。假设我正在实施先来先服务调度程序。进程调度

我也把问号(?),我不知道。

Put all processes into eventQ 
initialize all processes.state = CREATED 
While(eventQueue not empty) process = eventQueue.getFront() 

if process.state==CREATED state, it can transition to ready 
    clock= process.AT 
    process.state = READY 
    then I add it back to the end (?) of the eventQueue. 

if process.state==READY, it can transition to run 
    clock= process.AT + process.CPU_time_had + process.IO_time_had (?) 
    CPU_Burst = process.CB * Rand(b/w 0 and process.CB) 
    if (CB >= process.TC - process.CPU_time_had) 
     then it's done I don't add it back 
     process.finish_time = clock + CB 
     continue 
    else 
     process.CPU_time_had += CB 
     (?) Not sure if I put the process into BLOCK or READY here 
     Add it to the back of eventQueue (?) 

if process.state==BLOCK 
    No idea what happens (?) 
    Or do things never get Blocked in FCFS (which would make sense) 
    Also how do IO bursts enter into this picture??? 

感谢您的帮助!

回答

0

看看每个线程的到达时间,您可以排序,从而产生到达时间首次出现与后来的到达时间之前的线程队列。运行队列线程的前端(这是一个线程调度器)。当突发的CPU时间到时,一次运行线程突发,在当前时间的到达时间加上突发的IO时间(在到达时间再次对队列进行排序)时在队列后面输入新事件。这样,其他线程可以在线程执行io时执行。

(我的回答是假设你是在同一个班我。[CIS * 3110])

+0

我很高兴有人理解吧:)我不知道什么的线程“到达时间”可能是,或者什么是'IO突发':( –

+0

IO突发如何进入这张图片?所以你说的是如果p1的到达时间+ cpu_burst

+0

他们不是IO阵阵,这是一个CPU爆裂。每个CPU突发终止,无论是外出IO,或者由线程终止。在输入文件中,有到达时间,这些是每个线程到达的时间,所以第一个CPU突发到达线程的到达时间,每个后续突发的到达时间是t他此线程的先前爆发结束,加上前一个爆发的IO时间。这个想法是,线程在CPU中执行一些东西,离开IO,然后一旦完成IO就返回。因此,安排线程,并在线程中断时对队列进行洗牌 – OxenMeat