无法理解CPU调度概念

我必须用内核级线程编写CPU调度模拟。 我必须能够使用先来先服务(FCFS)或循环(RR)算法。 进程及其线程的数据以文本文件的形式给出。 目前我的程序将文本文件数据读入链表中。 我真的不知道如何开始模拟(我以前从未编程模拟过)。

这是我如何在FCFS的情况下进行? 当我到达第一个进程的第一个线程时,我将cpu时间添加到时钟时间。 那么我是否只需在CPU闲置时将io时间添加到时钟? 或者我应该把它放回等待队列并允许下一个线程开始在cpu中运行? 如果是这样,我如何跟踪每个线程已经被执行了多少?

这里是一个示例测试文件:

2 4 6 // number_of_processes thread_switch process_switch
1 5 // process_number(1) number_of_threads(1)
1 0 4 // thread_number(1) arrival_time(1) number_of_CPU(1)
1 15 100 // 1 cpu_time io_time
2 18 120 // 2 cpu_time io_time
3 12 100 // 3 cpu_time io_time
4 16  // 4 cpu_time 
2 4 4 // thread_number(2) arrival_time(2) number_of_CPU(2)
1 18 110
2 15 80
3 20 75
4 15
3 6 5   //thread(3)
1 40 100
2 20 70
3 15 80
4 18 90
5 50
4 8 4   //thread(4) 
1 25 60
2 15 50
3 20 80
4 18  
5 18 4  //thread(5) 
1 8 60
2 15 120
3 12 80
4 10

根据所提供的信息,I / O时间似乎不明确。 你有没有一个规范/指令去配合这个?

一般来说,我认为I / O时间为您提供了一个窗口,当前正在执行的线程可以在等待I / O请求完成时被换出。 尽管似乎没有任何迹象表明I / O时间是在CPU时间之前,之后还是混合在一起。 这可能是您在实现模拟器时预计会做出的设计决策。

对于'number_of_CPU'选项有什么影响,也存在不明确之处。 你模拟了多少CPU核心? 或者这仅仅是线程对CPU的请求数量的计数(它看起来就是这样,因为不能同时在多个CPU上运行单个线程)?

无论如何,你对于处理FCFS算法的一般方法都是正确的。 基本上你会想要维护一个请求队列,并且只要CPU处于空闲状态,你只需将下一个事情从队列中拉出来并执行。 假设一个单核CPU并忽略I / O时间,结果应该如下所示:

time=0
    Thread 1 arrives, and wants to do 15 time-units of work
        Thread 1 starts executing 15 time-units of work

time=4
    Thread 2 arrives, and wants to do 18 time-units of work
        Thread 2 is blocked because Thread 1 is executing

time=6
    Thread 3 arrives, and wants to do 40 time-units of work
        Thread 3 is blocked because Thread 1 is Executing

time=8
    Thread 4 arrives and wants to do 25 time-units of work
        Thread 4 is blocked because Thread 1 is Executing

time=15
    Thread 1 completes its initial set of work
    Thread 2 is next in the queue, and begins executing
    Thread 1 wants to do 18 time-units of work
        Thread 1 is blocked because Thread 2 is executing

time=18
    Thread 5 arrives and wants to do 8 time-units of work
        Thread 5 is blocked because Thread 2 is executing

time=33
    Thread 2 completes its initial set of work
    Thread 3 is next in the queue, and begins executing
    Thread 2 wants to do 15 time-units of work
        Thread 2 is blocked because Thread 3 is executing

...
链接地址: http://www.djcxy.com/p/84825.html

上一篇: Trouble Understanding CPU Scheduling Concepts

下一篇: Special case scheduling