0

So I'm kinda lost on how will I create a code or even a formula of how to get the average time of a round robin scheduling and its turn over time here is my code in round robin can anyone please give me some tips? in how to improve my codes? and how to get the average waiting time?

#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;   
}
Narkha
  • 1,197
  • 2
  • 12
  • 30
MaouAion
  • 25
  • 1
  • 5
  • You could use `time` function of C. Possibly the duplication of [Processing Time calculation](http://stackoverflow.com/questions/12231166/timing-algorithm-clock-vs-time-in-c)!. Please visit the link given before. – Wafeeq Mar 05 '14 at 15:04
  • i dont get what you are trying to say wafeeq – MaouAion Mar 05 '14 at 15:06
  • @wafeeq Unless the os has rt patch, time function is not accurate. Process scheduling is of very low duration level which would be quite sensitive. Also, time function gets called as a RR scheduled process in a higher priority queue... which may beat the purpose. – Xephon Mar 05 '14 at 15:08
  • @user2882523 I think he's trying to say use the time function to measure it. – Xephon Mar 05 '14 at 15:08
  • @Xephon I dont think that would be appropriate to use i just dont know the formula in calculating the average time and turn over time – MaouAion Mar 05 '14 at 15:10
  • @user2882523 Please see my answer. I've done profiling in an embedded linux kernel before. Not sure if my experience can help. – Xephon Mar 05 '14 at 15:16

1 Answers1

0

I'm not entirely sure what you're trying to achieve with your source code, but that surely does not "measure" the average wait time and turn over time in a RR schedule scheme.

If you truly want to profile a given OS's RR scheme, you need to tackle into kernel space. What I can think of at the moment is that you need to use something like struct timespec to capture timestamps in micro second level. In kernel space, whenever a process is invoked, capture a timestamp. You'll have to statistically analyze those timestamps afterwards.

The above is a software solution. The hardware solution I used once involves an oscillator with a known given frequency and counter in FPGA. Every time a process is invoked in kernel, I push the FPGA counter value to a buffer. By pushing out buffer to a file and analyze with Excel, I was able to determine the kernel RR scheduling scheme.

Not sure if the above helps.

Xephon
  • 393
  • 1
  • 12
  • Xephon I dont think I need a real time I think I just need to make it run with for loops that how my instructor want me to do – MaouAion Mar 05 '14 at 15:30
  • So you want a loose "estimation" of the run time? If so, use the timestamp should give you a good estimation even without the rt module. My solution with extra hardware was for production environment and we needed to be certain of the profile. Thus the extra mile. – Xephon Mar 05 '14 at 15:34