Top Banner
The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang
40

The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Dec 14, 2015

Download

Documents

Henry Oliver
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

The Implementation and Evaluation of a CPU Scheduling SimulatorMichael Jugan, Clay Taylor, Xuejuan Zhang

Page 2: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Background• CPU scheduling• A fundamental task of an operating system• OS decides when, and for how long, each process has access to

the CPU• Problem• Difficult to choose the best scheduling algorithm for a system

• Many scheduling algorithms and workloads

• Solution1. Create a process-driven scheduling simulator2. Evaluate scheduling algorithms using multiple workloads

Page 3: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Challenges• Creating a realistic simulator• Processes must be highly configurable• Must balance realism and complexity

• Performing evaluations• “Best” scheduler depends on the system’s requirements

• Must use multiple metrics and workloads• Thorough testing will indicate which algorithms are best for certain

situations.

Page 4: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Related Work• Instruction-set architecture (ISA) simulators• Popular research topic• Not directly applicable

• Lower level• Dependent on the system’s hardware

• General simulator ideas:• Customizable• Efficient• Easy to use

Page 5: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Related Work• LinSched [1]• Developed by a PhD candidate at the University of North Carolina• Used by Google• Runs the scheduling portions of Linux’s kernel in user space• Extremely realistic• Designed for systems programmers

Page 6: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Related Work• CPU Scheduling Simulator• a framework that allows you to quickly and easily design and

gather metrics for custom CPU scheduling strategies [2]• Written in C# using Microsoft Visual Studio• Developed from 2007 to 2008• Over 6,300 downloads.• No UNIX equivalent could be found

Page 7: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design1. Reads input2. Runs simulation• tracks statistics

3. Outputs results

Page 8: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

• Declares processes to run• Name• Length• Start time

Process script

Page 9: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

• Manages process’ statuses• Interacts with the scheduler

Simulator

Page 10: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

• Initial state after being read from file

• Simulator determines when each process is issued

All processes

Page 11: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

• Processes want access to the CPU

• Eligible to be scheduled

Issued processes

Page 12: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

• Tells the simulator which process should be executed by the CPU and for how much time

Scheduler

Page 13: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

1. First-in first-out (FIFO)2. Shortest job first (SJF)• Runs the process with the

least amount of remaining time.

3. Round robin (RR) • Cycles through the processes

and allots each a fixed amount of time known as a time-slice.

Scheduling Algorithms

Page 14: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

4. Priority queuing (PQ)5. Earliest deadline first (EDF) 6. Multi-level feedback

queuing (MLFQ)• Several queues• Highest priority queue has

shortest time-slice1. Selects the first process in

the highest priority queue 2. Process runs for a time-

slice, then moves to a lower priority queue

Scheduling Algorithms

Page 15: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

1. Detailed trace• Describes scheduler’s actions

and process’ stats• Useful for debugging and

understanding the scheduling algorithms

Outputs

Page 16: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design

2. Results summary • CPU utilization

• % of runtime during which the CPU is actively running a process

• Blocking time• Process switching time• Queuing time

• time a process waits to be run

• Turnaround time• time to complete a process

• percent of deadlines met• total runtime

Outputs

Page 17: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Design – Advanced Features• Process blocking• Processes may be configured to periodically block.• Simulates blocking I/O

• Regular preemption• The scheduler may notify the simulator to swap the active

process • Example: PQ scheduler may preempt the active process if a

higher priority process is recently issued.• Blocking preemption• The scheduler automatically deactivates the active process if it

begins to block. • Context switching overhead • Idle cycles when the active process changes

Page 18: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation• C++ using object-oriented design principles• Designed for UNIX• Simple to port to Windows

• Important detail:• Simulator’s time unit: “cycle”• Does not truly represent an actual CPU’s cycle• Real cycle counts should be scaled down

Execution length

Actual cycles Simulated cycles

Process A 1

Process B 2

Page 19: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation – Process Scripts• Two sections

1. Process definitions• Name• Properties

2. Issue times• issue time and process name.

• Benefits:• Process settings can be modified on one line• Naming - easier to interpret results

Page 20: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.
Page 21: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation – Simulator Class

• Two public methods:• LoadScript

• One argument• the name of a process script

• Opens and reads the process script’s contents• Creates Process objects

• Run• Three optional parameters• bool traceModeEnabled• bool preemptBlocksEnabled• unsigned long procSwitchCycles

• Performs the simulation• Interacts closely with the Scheduler object

Page 22: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation – Scheduler Class

•Base class

•Three empty virtual methods• void AddProcess(Process * p){}• Process * GetNextProcess(){}• bool ShouldPreempt(Process * active_process){}

•Methods implemented by derived classes• class FIFO: public Scheduler• class SJF: public Scheduler• etc.

Page 23: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation – Programs

• Schedule_sim• Command-line based interface to the Simulator class• Lets users quickly test multiple algorithms on different workloads

• Script_gen• Helps create process scripts

Page 24: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation – Schedule_sim• One optional parameter:• The program’s prompt text

• Four commands:1. LOAD_SCRIPT script name

2. SET_PARAMS traceModeEnabled preemptBlocksEnabled procSwitchCycles

3. RUN

4. HELP

Scheduler Name RUN Command’s Argumentsfirst-in-first-out FIFO

round robin RR timeSliceSize

shortest job first SJF

priority queuing PQ timeSliceSize

earliest deadline first EDF timeSliceSize

multi-level feedback queuing MLFQ timeSliceSize1,... , timeSliceSizeN

Page 25: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

/cs560-scheduling> ./schedule_sim ~

Page 26: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.
Page 27: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Implementation – Script_gen

• Two arguments: • Random number seed• Output filename

• Prompts user for process information:• Name• Execution time• Blocking period / length• Priority• Deadline• Static issue period• Random issue period• Quantity

• Generates process script file

issue time = static period + rand() % random period

Page 28: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

/cs560-scheduling> ./script_gen 21932 output_file~

Page 29: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

/cs560-scheduling> vim output_file~

Page 30: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Evaluation• First we verified correctness of results• Used trace mode and small workloads• Did scheduling by hand and compared

• Then we evaluated three workloads• Basic workload• Blocking workload• Deadline workload

Page 31: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Basic Workload• “Short” processes• Execution time of 100 cycles• Issue period of 100 to 400 cycles

• “Long” processes• Execution time of 1000 cycles• Issue period of 1000 to 4000 cycles

• 100 of each type issued• Gave “short” processes higher priority• No blocking or deadlines• Tested both with and without overhead

Page 32: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Basic Workload - Results

Page 33: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Overhead - Results

• Same workload and schedulers• Ideal utilization under this workload is ~55%

Page 34: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Blocking Workload

• Two types of processes• One blocks once after 50 cycles• One blocks four times after 20 cycles

• Execution time of 100 cycles• Blocking time of 1000 cycles• Issue period of 1000 to 2000 cycles• More frequent blocker has higher priority• No deadlines or overhead• Tested with and without preemption

Page 35: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Blocking Workload - Results

Page 36: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Deadline Workload• “Short” processes• Execution time of 10 cycles• Deadline of 100 cycles• Issue period of 50 cycles

• “Medium” processes• Execution time of 50 cycles• Deadline of 500 cycles• Issue period of 100 cycles

• “Long” processes• Execution time of 100 cycles• Deadline of 1000 cycles• Issue period of 250 cycles

• Increasing priority for decreasing deadline• No overhead or blocking

Page 37: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Deadline Workload - Results

• Meeting all deadlines is theoretically possible• EDF Scheduler achieves 100% deadlines met

Page 38: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Conclusion• MLFQ comes out as most well-rounded• Good average queuing and turnaround times• Reasonably resistant to performance drops• Does a good job at meeting most deadlines

• SJF and PQ are close to it in performance• However, susceptible to performance drops from blocking• Also unrealistic requirement of knowing process attributes

• Favor short processes over long ones• For PQ this was because of how we assigned priority

Page 39: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

Conclusion (Continued)• RR can emulate preemption on blocking• Also has good “fairness” by not favoring any process type• However, highly sensitive to switching overhead• Longer time slices behave more like FIFO

• FIFO favors longer processes• Like SJF/PQ, has issues with blocking without preemption

• EDF only one that met all deadlines• If meeting deadlines is required, it is the clear choice

Page 40: The Implementation and Evaluation of a CPU Scheduling Simulator Michael Jugan, Clay Taylor, Xuejuan Zhang.

References

[1] “LinSched: The Linux Scheduler Simulator”: http://www.cs.unc.edu/ ~jmc/linsched/. [Accessed May 4, 2012][2] “CPU Scheduling Simulator”: http://cpuss.codeplex.com/. [Accessed May 4, 2012]