1 / 12

Operating Systems 9 – scheduling

Operating Systems 9 – scheduling. PIETER HARTEL. Types of scheduling. Short-term: which runnable process to handle by which CPU Medium-term: which processes to swap in (challenge?) Long-term: which processes to accept in a batch environment

anahid
Download Presentation

Operating Systems 9 – 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. Operating Systems 9 – scheduling PIETER HARTEL

  2. Types of scheduling • Short-term: which runnable process to handle by which CPU • Medium-term: which processes to swap in (challenge?) • Long-term: which processes to accept in a batch environment • I/O scheduling: which pending I/O request to handle by which I/O device

  3. Scheduling is managing queues to minimise delays • User oriented criteria: response time, deadlines, predictability • System oriented criteria: throughput, resource utilisation • Tension? • Events include?

  4. Common scheduling policies • Round robin requires pre-emption, quantum can be varied • Example arrival&service times: A: 0&3; B: 2&6; C: 4&4; D: 6&5; E: 8&2

  5. Multi-level feedback queue : past behaviour predicts future • Round Robin in RQi for 2i time units • Promote waiting processes • Demote running processes

  6. Linux scheduling (section 10.3) • Three levels • Real-time FIFO, pre-empted only by higher priority RT FIFO • Round robin, pre-empted by clock after quantum expiry • Time sharing, lower priority, otherwise as above • Run queue per CPU with two arrays of 140 queue heads each, active and expired (i.e. out of quantum) • Dynamic priority rewards interactivity and punishes CPU hogging • Wait queue for threads waiting for events • Completely Fair Scheduling

  7. #ifndef _loop_h #define _loop_h 1 extern void loop(int N) ; #endif loop loop.h • gcc –c loop.c –o loop.o • Write a test program #include "loop.h" #define M 1690 /* Burn about N * 10 ms CPU time */ void loop(int N) { int i, j, k ; for(i = 0; i < N; i++) { for(j = 0; j < M; j++) { for(k = 0; k < M; k++) { } } } } loop.c

  8. GetpriorityThis example is a failure as it does not show priority changes int main(intargc, char* argv[]) { inti; int old = getpriority(PRIO_PROCESS, 0); printf("pri=%d\n", old); for(i=0; i < N; i++) { int new = getpriority(PRIO_PROCESS, 0); if(old != new) { old = new; printf("i=%d, pri=%d\n", i, new); } else { printf("i=%d\n", i); } loop(100); } return 0; } • Output? • gccGetpriority.c loop.o • ./a.out • Nothing happens…

  9. #define N 8 #define M 1000000 void *tproc(void *ptr) { int k, i = *((int *) ptr); intbgn = sched_getcpu(); printf("thread %d on CPU %d\n", i,bgn); for(k=0;k<M;k++) { int now = sched_getcpu(); if( bgn != now ) { printf("thread %d to CPU %d\n", i,now); break; } sched_yield(); } pthread_exit(0); } Getcpu • Output? • gccGetcpu.c -lpthread • ./a.out • ./a.out xx

  10. int main(intargc, char *argv[]) { int p, q, r; cpu_set_tcpuset; CPU_ZERO(&cpuset); CPU_SET(1, &cpuset); sched_setaffinity(parent, sizeof(cpu_set_t), &cpuset); for( p = 0; p < P; p++ ) { for( q = 0; q < Q; q++ ) { pid_t child = fork(); if (child == 0) { setpriority(PRIO_PROCESS, getpid(), p) ; for(r = 0; r < R; r++) { loop(100); } exit(0) ; } } } Nice • Output? • gccNice.cloop.o • ./a.out >junk& • top • ./a.out • ./a.outxx

  11. TimesliceThis example is a failure as it does not calculate the timeslice • Output? • gccTimeslice.cloop.o -lrt • ./a.out >a& • sleep 1 • ./a.out >b& • .sleep 1 • /a.out >c& • top int main(intargc, char *argv[]) { int i; intt[N]; structtimespec p, q; for( i = 0; i < N; i++ ) { clock_gettime(CLOCK_REALTIME, &p); loop(10) ; clock_gettime(CLOCK_REALTIME, &q); t[i] = diff( p, q ); } }

  12. Summary • Maximising resource usage, while minimising delays • Decisions • Long term: admission of processes • Medium term: swapping • Short term: CPU assignment to ready process • Criteria • Response time: users • Throughput: system

More Related