CS 241 Section Week 4 092310 Topics This
- Slides: 27
CS 241 Section Week #4 (09/23/10)
Topics This Section MP #3 MP #4 5 -state Model Review of Scheduling Problems
MP #3
MP #3 qsort() Define your own comparison function int compare (const void *e 1, const void *e 2) { return (*(int*)e 1 - *(int*)e 2); } Merge You need to remove duplicates How do you do that? Pthreads pthread_create and pthread_join You DO NOT want to do this: for ( …) { pthread_create(…); … pthread_join(…); }
MP #4
MP 4 Forward In MP 4, you will add code to a simulator for a CPU scheduler. We provide you with the code for the simulator. You don’t need to understand this code to understand this MP. You should consider the simulator a ‘black box’ You need to implement these algorithms: fcfs, sjf, pri, ppri, rr#
MP 4 Forward You need to fill in 3 scheduling functions: scheduler_new_job() scheduler_job_finished() scheduler_quantum_expired() Note that these are the only times that the scheduler needs to make a decision! A scheduler_clean_up() function to clean up any memory your program may’ve allocated A scheduler_show_queue() function to help you debug your program You need to create your own job queue
MP 4 Forward You also need to fill in 3 statistics functions: float scheduler_average_response_time() float scheduler_average_wait_time() float scheduler_average_turnaround_time() These are called at the end of the simulation.
MP 4 Forward For success on this MP: Carefully read instructions for all details! Look at the example runs and compare your results (e. g. using ‘diff’)! Only the last five lines matter. . . depends on how you implement the optional _show_queue(). Requires a good understanding of data structures, scheduling, and pointers all in one MP! Good luck!
Five State Model
5 -State Model - Transitions 11
Review of Scheduling
Scheduling The CPU Scheduler decides which thread should be in the running state. It is called when: A thread is created or finishes A clock interrupt occurs An I/O interrupt occurs A thread yields
Scheduling The algorithms that we usually talk about are: First-Come First-Serve (FCFS) Shortest Job First (SJF) Priority Round Robin (RR)
FCFS Example Process P 1 P 2 P 3 P 4 Duration 6 8 7 3 P 1 0 Priority 4 1 3 2 P 2 6 Arrival Time 0 0 P 3 14 P 4 21 24
SJF Example Process P 1 P 2 P 3 P 4 0 Duration 6 8 7 3 P 1 3 Priority 4 1 3 2 Arrival Time 0 0 P 3 9 P 2 16 24
Priority Example Process P 1 P 2 P 3 P 4 Duration 6 8 7 3 P 2 0 P 4 8 Priority 4 1 3 2 Arrival Time 0 0 P 3 11 P 1 18 24
RR(1) Example Process P 1 P 2 P 3 P 4 Duration 6 8 7 3 Priority 4 1 3 2 Arrival Time 0 0 Quanta = 1 time unit P 1 P 2 P 3 P 4 0 12 19 24
Scheduling algorithms can be preemptive or nonpreemptive Non-preemptive: each thread chooses when to yield to the processor (e. g. when done or system call) Preemptive: scheduler forces the thread to yield (e. g. time quantum expires in RR)
Scheduling Metrics for a single job Response time = time from job submission until it’s running Waiting time = total time that the job is not running but queued Turnaround time = time b/t the job’s entry and completion
Problems
Problem #1 Job Duration Priority # J 1 6 2 J 2 4 1 J 3 5 1 These three jobs are going to arrive at our scheduler 1 time unit apart from each other (i. e. one job at time 0, one at time 1, and one at time 2), but the order hasn’t been decided yet.
Problem #1 We want to guarantee that the jobs finish in the order J 1 then J 2 then J 3
Problem #1 Which arrival order(s) guarantee this if the scheduler uses: 1) 2) 3) 4) 5) 6) FCFS? non-premptive SJF? preemptive SJF? (use remaining time, and ties are broken by arrival time) RR-1? (arriving jobs are placed on ready queue immediately) non-preemptive priority?
Problem #2 For the SJF and RR examples, calculate: 1) 2) 3) Average initial waiting time Average response time Are either of these clearly better? When would you use each?
SJF Example Process P 1 P 2 P 3 P 4 0 Duration 6 8 7 3 P 1 3 Priority 4 1 3 2 Arrival Time 0 0 P 3 9 P 2 16 24
RR(1) Example Process P 1 P 2 P 3 P 4 Duration 6 8 7 3 Priority 4 1 3 2 Arrival Time 0 0 Quanta = 1 time unit P 1 P 2 P 3 P 4 0 12 19 24
- Week by week plans for documenting children's development
- Nfpa 241
- Charging by induction
- 241 bce
- 427 266 to the nearest ten thousand
- Fon 241
- Cob 241
- Ceng 241
- Psyco 241
- Cs 241 vector mp
- Ceng 241
- Chm 241
- Definition of detail drawing
- Mappa concettuale legge 241/90
- Eee 241
- Legge 241/90 slide
- Purdue phys 241
- Bio 241
- 241 in arabic
- Revolved sectional view
- What is a removed section view
- What is half section view
- Section 2 describing energy (continued)
- Study guide chapter 10 section 1 meiosis
- Article writing school magazine
- Grade 9 persuasive writing
- What is a thematic paragraph
- Behavioural training topics