CPU scheduling

Please work out the pre-lab problems before your next lab section. The GSI/IAs will go over all problems during the lab section.

[pre-lab] 1. Response times for different scheduling algorithms

Consider the following set of processes, with the length of the CPU-burst time given in milliseconds and with their priorities (larger priority numbers imply higher priority, and, in case of a tie, you can assume first-come-first- serve ordering). The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
Job Size (time) Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2

Consider the following scheduling algorithms: First-Come-First-Served, Round-Robin (with quantum = 1), Shortest-Time-to-Completion-First, and a Non-preemptive priority. Assume context switching is free.

a. For each scheduling algorithm, show a timeline of when jobs run, and compute the response times for each job.

b. Which algorithm gives the lowest average response time?

[pre-lab] 2. Advantages and disadvantages of different scheduling algorithms

Consider typical considerations in designing CPU scheduling algorithms such as scheduling overhead, starvation/fairness, average response time, CPU utilization, and throughput. Discuss the advantages and disadvantages of the following scheduling algorithms: STCF, FCFS, round robin, non-preemptive priority, earliest-deadline first. Remember that the suitability of an algorithm often depends on the workload.

[pre-lab and in-lab] 3. Response time versus throughput

[pre-lab] A. Write a function job in C++ that is computationally expensive (e.g., sum the integers from 0 to 100000000). Measure the response time of job by calling gettimeofday at the beginning and end of the function. Compute the average response time of job by summing the response time of each execution of job, then dividing by the number of times job was called. job will be invoked by multiple threads, so make it thread safe (use C++ threading facilities).

[pre-lab] B. Write a program that calls job 32 times in a single thread. Measure the running time of the program, then print out the throughput of the program (number of jobs / running time of the program), and average response time for each job.

[in-lab] C. Speed up your program by using concurrency. Your program should still call job a total of 32 times, but it should do so in a configurable number of threads. Run the program with different numbers of threads (1, 2, 4, 8, 16, 32), and graph the average response time versus throughput as you vary the number of threads. What concurrency level produces the best (lowest) response time? What concurrency level produces the best (highest) throughput? What level of concurrency would you recommend running on this machine?