如何找到循环的平均等待时间及其随着时间的流逝

How to Find the average waiting time of a round robin and its turn over time

本文关键字:时间 流逝 平均等待时间 何找 循环      更新时间:2023-10-16

所以我在如何创建代码,甚至是如何获取循环计划的平均时间的公式以及随着时间的流逝的转弯是我的代码是我的代码,这是我的代码罗宾人可以给我一些提示吗?如何改进我的代码?以及如何获得平均等待时间?

#include<iostream>
using namespace std;
int main(){
    int number;
    int interval;
    cout<<"How many Process Need: ";
    cin>>number;
    cout<<"Time Quantum: ";
    cin>>interval;
    int array[number];
    for(int i=0;i<number;i++)
    {
        cout<<"Process Time for Job "<<i+1<<": ";
        cin>>array[i];
    }
    for(int z=0;z<number;z++)
    {
        for(int i=0;i<number;i++)
        {
            if(array[i]-interval>=interval-1)
            {
                for(int x=1;x<=interval;x++)
                {
                    cout<<"Job "<<i+1<<"t";
                }
                array[i]=array[i]-interval;
            }
            else
            {
                for(int x=1;x<=array[i];x++)
                {
                    cout<<"Job "<<i+1<<"t";
                }
                array[i]=0;
            }
        }
    }
    cout<<endl;
    system("pause");
    return 0;   
}

我不完全确定您要使用源代码要实现的目标,但是肯定不会"测量" RR计划方案中的平均等待时间和随着时间的流逝。

如果您确实想介绍给定的OS的RR方案,则需要解决内核空间。目前,我能想到的是,您需要使用诸如struct timespec之类的东西来捕获微型第二级的时间戳。在内核空间中,每当调用一个过程时,都会捕获时间戳。之后您必须统计地分析这些时间戳。

以上是软件解决方案。我曾经使用过的硬件解决方案涉及具有已知给定频率和计数器的振荡器。每次在内核中调用一个过程时,我都会将FPGA计数器值推到缓冲区。通过将缓冲区推到文件并与Excel进行分析,我能够确定内核RR调度方案。

不确定以上是否有帮助。