I created a program that simulates the fcfs scheduling algorithm. First I implemented it for a single core, then modified it for four homogenoues cpus.
I compared the results with several datasets, and for the most part they are identical.
I understand fcfs is nonpreemtive, so there are no context switches. Then each cpu holds the process until its current cpu burst is finished, from there it either terminates or does IO (goes to wait queue).
Im guessing a multi core system only improves performance if many processes are in the ready queue at the same time, otherwise only one cpu is being used.
Here is the algorithm that I implemented:
while(TRUE)
{
for(i = 0; i < NUM_CPUS; i++)
{
if(!cpu[i].idle)
{
if(cpu[i] is finished executing current burst)
{
//either move the process from the cpu to the waitQ, or terminate process if finished all bursts
if(terminatedPrs == numberOfProcess)
break;
}
}
if(waitQ->front != NULL)
{
//Check if waitQ->front is finished io
if(waitQ->front finished IO burst)
{
//insert waitQ->front to readyQ, then dequeue waitQ
}
}
if(cpu[i].idle)
{
if(readyQ->front != NULL)
{
//check if readyQ->front is ready to be executed (that is, arrival time < elapsedTime)
if(readyQ->front ready to be executed)
{
//move readyQ->front to CPU (begin executing), and dequeue readyQ
}
}
}
}
elapsedTime++;
}
Is my algorithm fine? I am getting pretty much the same average waiting time, average turnaround time and average cpu utilization.