1 / 31

CPU Scheduling

CPU Scheduling. CPU Scheduling. Process execution a cycle of CPU execution and I/O wait figure Preemptive Non-Preemptive. The four circumstance. 1. When a process switches from the running state to the waiting state 2. When a process switches from the running state to the ready state

tan
Download Presentation

CPU Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPU Scheduling SunMoon University

  2. CPU Scheduling • Process execution • a cycle of CPU execution and I/O wait • figure • Preemptive • Non-Preemptive SunMoon University

  3. The four circumstance 1. When a process switches from the running state to the waiting state 2. When a process switches from the running state to the ready state 3. When a process switches from the waiting state to the ready state 4. When a process terminates SunMoon University

  4. scheduler • Select one of the processes in the ready queue • Short-term scheduling SunMoon University

  5. Dispatcher • gives the control of the CPU to the process selected by the scheduler • functions • switching context • switching to user mode • jumping to the proper location in the user program to restart that program • Dispatch latency : • the time it takes for dispatcher to stop one process and start another running. SunMoon University

  6. Scheduling Criteria • CPU utilization • % of time device is busy • Throughput • the number of jobs completed per unit time • Turnaround time • including I/O • Waiting time • Response time SunMoon University

  7. Scheduling Goal • fair among all processes • max. the CPU utilization and throughput • min. the turnaround / waiting / response time • optimize the average measure • minimize the max. response time • consider the worst case • interactive systems • minimize the variance in the response time SunMoon University

  8. Scheduling Algorithm • consider only one CPU burst per process • execution units • ex) 10 milliseconds • our measure of compare • average waiting time SunMoon University

  9. FiFO Scheduling(1) • First-come First-served • Easily managed with a FiFO queue • Fair • The average waiting time is often quite long • 129 pages(Fifth Edition) • One CPU-bound process and many I/O bound processes • I/O devices idle or CPU sits ilde • Non-preemptive • Troublesome for time sharing system SunMoon University

  10. CPU-Bound Pr. I/O-Bound Pr. main ( ) { int sum,j=0; while( ){ sum += j; j++; } } main( ) { FILE *fp; int j, buf[512]; fp = open(“tmp.dat”, “r+”); while( ){ j = read( fp, buf, sizeof(buf)); sum( buf, 256 ); wirte( fp, buf, 1024 ); } } FiFO Scheduling(2) SunMoon University

  11. P1 P2 P3 프로세스 실행시간 P1p2p3 24 0 24 27 30 3 3 P1 P2 P3 0 3 6 30 평균 반환 시간 : (24+27+30)/3 = 27평균 대기 시간 : (0+24+27)/3 = 17 FiFO Scheduling(3) 예 작업이 1,2,3의 순서  간트 도표(Gantt chart) 작업이 P2, P3, P1의 순서  간트 도표 평균 반환 시간 : (3+6+30)/3 = 13평균 대기 시간 : (6+0+3)/3 = 3 SunMoon University

  12. SJF Scheduling(1) • Shortest-Job-First Scheduling • Assign the CPU to the process that has the smallest next CPU burst • If the same burst, FCFS • p 130 ~ 132 • Minimize the average waiting time • Difficulty with the SJF • knowing the length of the next CPU request • figure 5.3 : p 132 • Non_preemptive SunMoon University

  13. 프로세스 실행시간 P1p2p3p4 6 평균 대기 시간 : (3+0+16+9)/4 = 7평균 반환 시간 : (3+9+16+24) / 4 = 13 3 8 7 평균 대기시간 최소 : 최적 알고리즘 SJF Scheduling(2) SunMoon University

  14. SJF Scheduling(3) • 짧은 작업을 긴 작업의 앞에 놓음  긴 작업의 대기시간 증가 • 짧은 작업의 대기시간을 줄여 평균 대기시간 감소 • SJF는 작업 스케줄링에서 많이 사용되는 기법 • 단기 스케줄링 단계에서 다음 프로세스의 프로세서 버스트 시간을 예상할 수가 없기 때문에 하드웨어 구성 어려움 - SJF 스케줄링의 근사치 사용하여 해결 SunMoon University

  15. SJF Scheduling(4) • Preemptive version • shortest-remaining time first • shorter CPU burst of new arrival process than what is left of currently executing process • p 133 SunMoon University

  16. 프로세스 도착시간 실행시간 P1p2p3p4 0 8 4 1 9 2 3 5 P1 P3 P2 P4 12 0 8 17 26 SJF Scheduling(5) 평균반환시간 : 선점 : ((17-0)+(5-1)+(26-2)+(10-3))/4 = 13 비선점 :((8-0)+(12-1)+(17-3)+(26-2))/4 = 14.25평균 대기시간 : 선점 : ((10-0)+(1-1)+(17-2)+(5-3))/4 = 6.75 비선점 :((0+(8-1)+(12-3)+ (17-2))/4 = 7.75 비선점 SunMoon University

  17. Priority Scheduling(1) • Allocate CPU to the highest priority process • SJF : a special case of the general priority scheduling • equal-priority processes : FCFS order SunMoon University

  18. Priority Scheduling(2) • Priority • is defined either internally or externally • Static priority • do not change through out execution time • easy to implement • low-overhead • Dynamic priority • response to change • more complex • greater overhead  the increased responsiveness of the system SunMoon University

  19. Priority Scheduling(3) • Purchased priority • willing to pay a extra charge • P. 134 • Non_preemptive or preemptive • when a new process arrives at the ready queue, • new process priority > running process • Problem • indefinite blocking or starvation • unfair  aging SunMoon University

  20. 프로세스 버스트시간 우선순위 3 P1p2p3p4p5 10 1 1 2 3 15 42 Priority Scheduling(4) 평균 대기시간 : 8.2 SunMoon University

  21. Deadline scheduling • Schedule the certain jobs to be completed by a specific time or deadline • high value if delivered on time • worthless if delivered later than the deadline • Very complex • Real time systems • control system • etc. SunMoon University

  22. HRN scheduling • Highest Response-Ratio Next • Brinch Hansen(1971)에 의해 개발 • Non-preemptive • Compensated version of SJF • longer jobs given favored treatment • the priority of each job is a function • P = (waiting_time + service_time) /service_time SunMoon University

  23. 준비 큐 종료 프로세서 선점 Round-Robin Scheduling(1) • Time sharing system • FCFS + time_quantum or time_slice • a time quantum : 10~100 ms • Ready queue : circular queue • Preempted SunMoon University

  24. Round-Robin Scheduling(2) • Maximum waiting time • “n” processes in the ready queue • time quantum : q • (n – 1) * q • The effect of context switching • time quantum vs. the number of context switching • figure 5.4/5.5 (p. 136 ~137) SunMoon University

  25. 반환 시간 = 작업 완료 시간 - 도착 시간 평균 반환시간 : (20+7+24+22)/4 =18.25 평균 대기시간 : (12+3+15+17) =47÷4=11.75 프로세스 도착시간 실행시간 P1p2p3p4 0 8 규정 시간량 : 4 P1 P2 P3 P4 P1 P3 P4 P3 4 1 9 2 3 5 0 4 8 12 16 20 25 26 24 Round-Robin Scheduling(3) SunMoon University

  26. Multi_level queue scheduling(1) • For situation in which processes are easily classified into different groups • foreground( interactive ) processes • background( batch ) processes • Permanently assigned to a queues on entry to the systems • low scheduling overhead • inflexible SunMoon University

  27. 최고의 우선순위 시스템 프로세스 대화형 프로세스 대화형 편집 프로세스 일괄 프로세스 학생의 프로세스 최저의 우선순위 Multi_level queue scheduling(2) 큐는 프로세서 시간 일정량 받아, 자기 큐에 있는 프로세스들을 스케줄링 • 전면 작업 큐 :순환 할당 스케줄링 위하여 프로세서 시간의 80% 할당 • 후면 작업 큐: 선입선처리(FCFS)방식으로 프로세서 시간의 20% 할당 SunMoon University

  28. Multi_level queue scheduling(3) • Figure 5.6(p. 138) • each queue has the absolute priority over lower_priority queue • different time slice between the queue SunMoon University

  29. Multi_level Feedback Queue Scheduling(1) • allows a process to move between queues • separate processes with different CPU_burst characteristics • I/O bound process • CPU bound process • aging SunMoon University

  30. 할당량 = 8 할당량 = 16 Multi_level Feedback Queue Scheduling(2) • 프로세서 버스트가 8 이하인 모든 프로세스에게 최고 우선순위 부여 • 8 ~ 24 프로세스들은 더 짧은 프로세스보다는 낮은 우선 순위 받음 • 긴 프로세스들은 큐 2로 • 큐 0과 큐 1에 프로세서 주기의 여유 생기면 FCFS 방식으로 처리 SunMoon University

  31. Multi_level Feedback Queue Scheduling(3) • Parameters of multi_level feedback q. • the number of queues • the scheduling algorithm for each q. • the method used to determine • when to upgrade a process to a higher priority queue. • when to demote a process to a lower priority queue. • Which queue a process will enter when that process needs service. SunMoon University

More Related