1 / 39

Lecture #7

Lecture #7. CPU Scheduling. CPU Scheduling. 다중 프로그래밍 시스템에서 여러 개의 프로세스 사이에 프로세서( CPU) 사용을 스케줄링하는 것 목 적: High processor utilization High throughput number of processes completed per unit time Low response time elapsed time from the submission of a request to the beginning of the response.

lilac
Download Presentation

Lecture #7

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. Lecture #7 CPU Scheduling 신라대학교 컴퓨터공학과 운영체제

  2. CPU Scheduling • 다중 프로그래밍 시스템에서 여러 개의 프로세스 사이에 프로세서(CPU) 사용을 스케줄링하는 것 • 목 적: • High processor utilization • High throughput • number of processes completed per unit time • Low response time • elapsedtime from the submission of a request to the beginning of the response 신라대학교 컴퓨터공학과 운영체제

  3. 스케줄링 동작의 분류 • Long-term : which process to admit • Medium-term: which process to swap in or out • Short-term: which ready process to execute next 신라대학교 컴퓨터공학과 운영체제

  4. Queuing Diagram for Scheduling 신라대학교 컴퓨터공학과 운영체제

  5. Long-Term Scheduling • 어떤 프로그램을 시스템에서 실행할 수 있도록 허용할 것인가를 결정하는 작업 • 다중 프로그래밍 정도(the degree of multi-programming)를 결정한다 • 많은 프로세스를 허용하는 경우: • 모든 프로세스가 대기상태(blocked)가 될 가능성이 적어진다 • CPU 이용률을 높일 수 있다 • 각 프로세스에 대한 CPU 할당 시간이 적어진다 • 각 프로세스의 반응 시간이 길어진다 • Processor-bound 프로세스와 I/O-bound 프로세스를 적절하게 혼합될 수 있도록 허용하는 것이 효율적 신라대학교 컴퓨터공학과 운영체제

  6. Medium-Term Scheduling • Swapping decisions based on the need to manage multiprogramming • 어떤 프로세스를 swapping 할 것인지를 결정 • 메모리 관리 소프트웨어에 의해 수행 신라대학교 컴퓨터공학과 운영체제

  7. Short-Term Scheduling • 어떤 프로세스를 다음에 실행할 것인지를 결정 • CPU scheduling • Dispatcher • 준비 상태의 프로세스 중에서 다음에 실행할 프로세스를 선택 • 선택된 프로세스에게 CPU를 할당 • 문맥을 교환 • 사용자 모드로 전환 • 프로그램 실행을 위해 사용자 프로그램의 적절한 위치로 이동 – PC(program count) 설정 • CPU 스케줄링이 수행되는 시점(events): • clock interrupts • I/O interrupts • operating system calls and traps • signals 신라대학교 컴퓨터공학과 운영체제

  8. CPU 스케줄링 기준(Criteria) • 사용자 관점 기준 • Response Time(응답 시간): 프로그램이 제출된 때부터 반응을 시작하는데 걸리는 시간 • Turnaround Time(작업 반환 시간): 프로그램이 제출된 때부터 완료될 까지 걸리는 시간 • 시스템 관점 기준 • processor utilization(CPU 이용률) • Fairness(공평성) • Throughput(처리율): 단위 시간당 수행 완료하는 프로세스 수 신라대학교 컴퓨터공학과 운영체제

  9. 스케줄링 알고리즘의 특성 • 선택함수(selection function) • ready queue에 있는 프로세스들 중에서 다음에 실행한 프로세스를 결정하는 방법(기준) • 결정모드(decision mode) • 선택함수를 실행할 시점을 정의 • Nonpreemptive(비선점) • 일단 프로세스가 실행상태가 되면 실행을 종료하거나 I/O로 인해 대기상태가 될 때까지 실행을 계속하는 모드 • Preemptive(선점) • 현재 실행중인 프로세스를 중지하여 ready queue에 보내고 새로 선택된 프로세스를 실행하는 모드 • 하나의 프로세스가 오랜 시간동안 CPU를 독점하지 못하도록 함으로써 더 나은 서비스를 허용한다 신라대학교 컴퓨터공학과 운영체제

  10. Wait for I/O Wait for I/O Wait for I/O CPU-I/O Burst Cycle • 하나의 프로세스는 CPU 작업과 I/O 작업을 교대로 요구하는 동작을 반복적으로 수행 • 각 사이클은 CPU burst (typically of 5 ms)와 I/O burst(usually longer)로 구성 • 프로세스는 CPU burst로 시작하여 CPU burst로 종료 • CPU-bound process는 I/O-bound process보다 더 긴 CPU bursts을 갖는다    load store add store read from file store increment index write to file load store add store read from file    CPU Burst I/O Burst CPU Burst I/O Burst CPU Burst I/O Burst 신라대학교 컴퓨터공학과 운영체제

  11. CPU 스케줄링 알고리즘 • 선입 선처리(First Come First Served) 스케줄링 • 라운드 로빈(Round-Robin) 스케줄링 • 짧은 프로세스 우선(Shortest Process Next:SPN) 스케줄링 • 최단 잔여 시간(Shortest Remaining Time:SRT) 스케줄링 • 최고 응답률 우선(Highest Response Ratio Next:HRRN) 스케줄링 • 우선순위(Priority) 스케줄링 • 다단계 피드백 큐(Multi-level Feedback Queue) 스케줄링 • Multiprocessor 스케줄링 • 실시간 스케줄링 신라대학교 컴퓨터공학과 운영체제

  12. Service Time Arrival Time Process 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2 CPU 스케줄링 알고리즘의 비교 - Service time = total processor time needed in one (CPU-I/O) cycle - Jobs with long service time are CPU-bound jobs and are referred to as “long jobs” 신라대학교 컴퓨터공학과 운영체제

  13. 선입 선처리 스케줄링 :First Come First Served (FCFS) • 선택함수 • ready queue 에서 가장 오랫동안 대기하고 있는 프로세스를 선택 • First Come First Served(FCFS) • 결정모드 • nonpreemptive(비선점) • 프로세스는 종료하거나 대기상태가 될 때까지 실행한다 신라대학교 컴퓨터공학과 운영체제

  14. FCFS 스케줄링의 단점 • 어떤 I/O도 요구하지 않는 프로세스가 CPU를 독점할 수 있다 • CPU-bound process를 선호한다 • I/O-bound process는 CPU-bound process가 종료할 때까지 기다려야 한다 • I/O-bound process는 I/O가 완료되더라도 기다리는 상태이므로 다음 I/O을 실행하지 못한다(poor device utilization) • I/O bound process에 한 레벨 높은 우선순위를 부여함으로써 I/O device의 이용률을 높일 수 있다 신라대학교 컴퓨터공학과 운영체제

  15. 라운드-로빈(Round-Robin) 스케줄링 • 선택함수: FCFS와 같다 • 결정모드: preemptive(선점) • 프로세스는 하나의 time slice (quantum, typically from 10 to 100 ms) 동안에 실행된다 • clock interrupt가 발생하면 현재 실행중인 프로세스를 ready queue로 보내고 FCFS 방식으로 새로운 프로세스를 실행한다 신라대학교 컴퓨터공학과 운영체제

  16. Time Quantum for Round Robin (1) • Clock interrupt과 dispatching 처리를 위한 시간보다 더 크게 결정되어야 한다 • should be larger than the typical interaction • 작업 반환 시간이 커질 수 있다 신라대학교 컴퓨터공학과 운영체제

  17. Time Quantum for Round Robin (2) 신라대학교 컴퓨터공학과 운영체제

  18. Round Robin 스케줄링 분석 • 여전히 CPU-bound process를 선호한다 • I/O bound process는 time slice보다 적은 시간동안 CPU를 사용하고 I/O 요구에 대해 대기상태가 된다 • CPU-bound process는 모든 time slice 동안 실행되고 ready queue로 되돌아간다. 이때, 대기 상태의 프로세스 앞에 놓이게 된다 • 해결책: 가상 라운드 로빈(virtual round robin) • I/O가 완료되었을 때에 대기상태의 프로세스를 ready queue보다 높은 우선순위를 가지는 보조 큐(auxiliary queue)에 보낸다 신라대학교 컴퓨터공학과 운영체제

  19. Queuing for Virtual Round Robin 신라대학교 컴퓨터공학과 운영체제

  20. Shortest Process Next (SPN) 스케줄링 • 선택함수: • 가장 짧은 CPU burst time을 가진 프로세스를 선택한다 • 최소 작업 우선(Shortest Job First) 스케줄링 • 결정모드: nonpreemptive(비선점) • I/O bound process가 먼저 선택된다 • 각 프로세스의 CPU burst time을 미리 예측하여야 한다 신라대학교 컴퓨터공학과 운영체제

  21. CPU burst time 예측(1) • Let T[i] be the execution time for the i-th instance of theprocess • the actual duration of the i-th CPU burst of this process • Let S[i] be the predicted value for the i-th CPU burst of this process. The simplest choice is: • S[n+1] = (1/n) S_{i=1 to n} T[i] • To avoid recalculating the entire sum we can rewrite this as: • S[n+1] = (1/n) T[n] + ((n-1)/n) S[n] • But this convex combination gives equal weight to each instance 신라대학교 컴퓨터공학과 운영체제

  22. CPU burst time 예측(2) • But recent instances are more likely to reflect future behavior • A common technique for that is to use exponential averaging • S[n+1] = a T[n] + (1-a) S[n] ; 0 < a < 1 • more weight is put on recent instances whenever a > 1/n 신라대학교 컴퓨터공학과 운영체제

  23. SPN 스케줄링 분석 • 짧은 프로세스가 계속적으로 생성될 때에는 긴 프로세스가 starvation 될 가능성이 있다 • 비선점 방식이므로 시분할 환경에는 부적합하다 • CPU bound process가 낮은 우선순위를 가지지만 여전히 I/O을 요구하지 않는 프로세스가 CPU를 독점할 수 있다 • 대화형 응용 프로그램 실행에는 부적합 • SPN 스케줄링은 함축적으로 우선순위 기법을 수용한다 • shortest jobs are given preferences 신라대학교 컴퓨터공학과 운영체제

  24. Shortest Remaining Time (SRT) 스케줄링 • 선택함수: • 예측된 잔여 처리 시간이 가장 짧은 프로세스를 선택 • SPN 스케줄링의 선점형 • 결정모드: preemptive(선점) • 새로운 프로세스의 처리 요구 시간이 현재 수행중인 프로세스의 잔여 처리 시간보다 짧은 경우 선점된다 • 분 석: • FCFS 스케줄링보다는 공평한 스케줄링을 수행 • 실행 시간이 긴 프로세스들이 기아 상태에 빠질 가능성이 존재 • 라운드-로빈과 달리 인터럽트가 추가로 발생하지 않음 • 선점형이기 때문에 SPN보다 작업처리 시간이 훨씬 짧다 • 프로세스의 처리 시간 예측 및 프로세스 서비스 시간 계산에 대한 오버헤드가 존재 신라대학교 컴퓨터공학과 운영체제

  25. Highest Response Ratio Next (HRRN) 스케줄링 • 선택함수: • 응답 비율(RR: Response Ratio)이 가장 큰 프로세스를 선택 • RR = (CPU 대기 시간 + 예측된 서비스 시간)/예측된 서비스 시간 • 모든 프로세스들에 대한 응답 비율의 평균값을 최소화 • 결정모드: nonpreemptive(비선점) • 분 석: • 프로세스의 대기 시간을 고려하기 때문에 효과적 • 일반적으로 짧은 실행시간을 가진 프로세스가 유리 • 실행 시간이 긴 프로세스의 경우 대기 시간이 증가함에 따라 응답비율이 증가하여 짧은 실행 시간의 프로세스보다 먼저 실행 신라대학교 컴퓨터공학과 운영체제

  26. 우선순위 스케줄링 :Priority Scheduling • 우선 순위 기반의 스케줄링 • 프로세스의 우선순위를 비교 • 높은 우선순위의 프로세스를 먼저, 같은 수준의 우선순위를 가진 프로세스에 대해서는 FCFS 방식으로 선택 • 각 우선순위 레벨을 나타내는 다수의 ready queue을 사용하여 구현할 수 있다 • Multi-level queue • 낮은 우선순위 프로세스가 starvation 될 수 있다 • 동적 우선순위(dynamic priority) 사용 • 실행 시간 경과에 따라 프로세스의 우선순위를 바꾼다 신라대학교 컴퓨터공학과 운영체제

  27. 다단계 피드백 큐 스케줄링 :Multilevel Feedback Queue Scheduling • Preemptive scheduling with dynamic priorities • Several ready queues with decreasing priorities: • P(RQ0) > P(RQ1) > ... > P(RQn) • 새로운 프로세스는 RQ0에 보낸다 • Time slice가 완료되면 프로세스를 RQ1으로 보낸다. 그리고 그 다음 단계에서는 RQ2로, 계속하여RQn까지 보내도록 한다 신라대학교 컴퓨터공학과 운영체제

  28. 다단계 피드백 큐 스케줄링 :Multilevel Feedback Queue Scheduling • I/O-bound process는 높은 우선순위 큐에서 유지되는 반면에 CPU-bound process는 낮은 우선순위 큐로 옮겨간다 • Dispatcher는 RQi-1에서 RQ0까지의 큐가 비어있을 때에 RQi 에서 실행할 프로세스를 선택한다 • 긴 프로세스는 starvation 될 가능성이 있다 • 낮은 우선순위 큐에서 오래 대기한 프로세스를 높은 우선순위 큐로 이동시킴(aging)으로써 해결 신라대학교 컴퓨터공학과 운영체제

  29. Multiple Feedback Queues • 각 큐에서는 FCFS 스케줄링 • 가장 낮은 우선순위 큐에서는 Round-Robin 스케줄링 신라대학교 컴퓨터공학과 운영체제

  30. Time Quantum for MFQ Scheduling • 고정 크기의 time slice를 가지는 경우, 긴 프로세스의 작업 반환 시간이 대단히 길어질 수 있다 • 큐의 레벨에 따라 time slice를 증가시킴으로써평균 작업 반환 시간을 줄일 수 있다 • 예: time sliceof RQi = 2^{i-1} 신라대학교 컴퓨터공학과 운영체제

  31. 다중 처리기 스케줄링(Multiprocessor Scheduling) (1) • 다중 처리기(Multiprocessor)의 종류 • Loosely coupled multiprocessor • 각 프로세서가 자기 고유의 지역 메모리와 I/O 채널을 가진다 • Distributed system, clustered system 등 • Functionally specialized processors • I/O processor 등 • master processor에 의해 제어된다 • Tightly coupled multiprocessing • 모든 프로세서가 주기억장치를 공유한다 • SMP 등 신라대학교 컴퓨터공학과 운영체제

  32. 다중 처리기 스케줄링(Multiprocessor Scheduling) (2) • 프로세스 병렬성(Process Parallelism) • Synchronization Granularity • Independent Parallelism • 다수의 연관성이 없는 프로세스 사이의 병렬성 • Very coarse grained parallelism • 네트워크 노드 상의 분산 처리(distributed processing) • Coarse grained parallelism • 다중 프로그래밍 환경에서 프로세스들의 다중 처리 (multiprocessing) • Medium grained parallelism • 하나의 응용에서의 병렬 처리(Parallel processing) • Thread 수준의 병렬성 • Fine grained parallelism • 명령어 수준의 병렬성 신라대학교 컴퓨터공학과 운영체제

  33. 다중 처리기 스케줄링(Multiprocessor Scheduling) (3) • Multiprocessor thread scheduling • Load sharing • processes are not assigned to a particular processor • Gang scheduling • a set of related threads is scheduled to run on a set of processors at the same time • Dedicated processor assignment • threads are assigned to a specific processor • Dynamic scheduling • number of threads can be altered during course of execution 신라대학교 컴퓨터공학과 운영체제

  34. 다중 처리기 스케줄링(Multiprocessor Scheduling) (4) • Load Sharing(부하 분산) • 부하를 모든 프로세서에 대해 적절하게 분산한다 • 유휴 프로세서가 없음을 보장 • 중앙 집중식 스케줄러가 필요 없다 • global queue을 사용 • 단 점: • global queue에 대한 상호배제 • 선점된 프로세스가 동일한 프로세스에서 실행을 재개할 가능성이 적다 • 하나의 프로그램을 구성하는 모든 쓰레드가 동시에 프로세서를 얻어 실행할 가능성이 적다 신라대학교 컴퓨터공학과 운영체제

  35. 다중 처리기 스케줄링(Multiprocessor Scheduling) (5) • Gang Scheduling • 하나의 프로세스을 구성하는 쓰레드들에 대한 동시 스케줄링 • 응용 프로그램의 부분적인 실행으로 성능이 심각하게 떨어지는 응용 프로그램에 대해서는 유용하다 • Dedicated Processor Scheduling • 하나의 프로세스를 구성하는 모든 쓰레드를 하나의 프로세서에 할당한다 • 일부 프로세서가 유휴상태가 될 수 있다 • process switching을 피한다 신라대학교 컴퓨터공학과 운영체제

  36. 다중 처리기 스케줄링(Multiprocessor Scheduling) (6) • Dynamic Scheduling • 프로세스를 구성하는 쓰레드 수가 실행되는 동안에 동적으로 변하는 경우 • 운영체제가 각 프로세서의 부하를 고려하여 프로세서를 할당한다 신라대학교 컴퓨터공학과 운영체제

  37. 실시간 스케줄링(Real-time Scheduling) (1) • 실시간 시스템(Real-Time System) • Correctness of the system depends not only on the logical result of the computation but also on the time at which the results are produced • 분 류 : • 경성 실시간 시스템(Hard Real-Time System) • 연성 실시간 시스템(Soft Real-Time System) • 예 : • Control of laboratory experiments • Process control plants • Robotics • Air traffic control • Telecommunications 신라대학교 컴퓨터공학과 운영체제

  38. 실시간 스케줄링(Real-time Scheduling) (2) • 실시간 스케줄링(Real-Time Scheduling) • Priority-based scheduling • Priority assignment based on deadline • Not support aging • Shorter dispatch delay • Preemption points in system calls • Preemption kernel 등 신라대학교 컴퓨터공학과 운영체제

  39. 알고리즘 평가 • Which one is best? • The answer depends on: • on the system workload (extremely variable) • hardware support for the dispatcher • relative weighting of performance criteria (response time, CPU utilization, throughput...) • evaluation method used • 평가 방법 • 결정성 모형화(Deterministic Modeling) • 큐잉 모형(Queueing Model) • 모의실험(Simulation) • 구현(Implementation) 신라대학교 컴퓨터공학과 운영체제

More Related