Scheduling 0 : Levels High level scheduling: Deciding whether another process can run is process table full? user process limit reached? load to swap space or memory? Medium level scheduling: Balancing the system load swap out a process? swap in a process? Low level scheduling Deciding which process should get CPU time next.
Scheduling 1 : Objectives System throughput should be maximised. Graceful degradation of performance. No sudden collapse! Provide a tolerable response time. Consistent behaviour, wrt job priority and from day to day.
Scheduling 2 : Criteria Job Priority : Depends on Category of job: batch, on-line, real-time. CPU bound or I/O bound. Resource requirements Waiting time to date. Resources used to date.
Scheduling 3 : Low-level Low-level scheduling can be: Preemptive Current process may be interrupted by o/s. new process arrived interrupt placed blocked process in Ready queue clock interrupt (time up). Non-Preemptive Process executes until it terminates blocks on I/O or system call. Cooperative As non-preemptive except that process may give up cpu voluntarily.
Scheduling 4 : Low-level Policies i First-come-first-served, or FIFO. Non-preemptive. first process to arrive in queue gets CPU when this process stops running, next in queue gets CPU ie. the process that has been waiting longest goes next. favours cpu-bound processes. Round Robin Uses a time-slice and preemption. each process runs for a short period when timer expires, or process blocks, next process runs design issue is length of time-slice. favours cpu-bound processes
Scheduling 5 : Low-level Policies ii Shortest job first. non-preemptive process with shortest expected processing time goes first. need to calculate processing time for each job. risk of starvation for long jobs Shortest remaining time preemptive version of SJF process with shortest remaining processing time runs. preempted if new shorter job arrives in queue. risk of starvation again. need to know process run time.
Scheduling 6 : Low-level iii. Highest Response Ratio Next non-preemptive. process with the highest ratio of waiting time : run time goes next. Favours shorter jobs. Doesn t starve longer jobs Still need to know how long the job will take to complete. Priority = waiting time + runtime runtime
Scheduling 7 : Low-level iv.i Multi-level feedback queues preemptive Run Queue 0 CPU Run Queue 1 Run Queue 2 after Operating Systems, 5th Ed. Stallings, Prentice Hall
Scheduling 8 : Low-level iv.ii Long processes can get starved, therefore : time quantum = τ Process first placed on RQ0 gets time slice of length τ x 2 0 If process does not complete then move to RQ1 gets time slice of length τ x 2 1 If process does not complete then move to RQ2 gets time slice of length τ x 2 In general a process on RQ i gets time slice of length τ x 2 i
Scheduling 9 : Generic Unix Traditional time-sharing, multi-user, interactive system. Uses multi-level feedback with round-robin queues. Preemption after 1 sec. Priority is recalculated every second using Where CPU j (i) = CPU j(i 1) 2 CPU j (i) P j (i) = Base j + CPU j(i) P j (i) + nice 2 Base j j from Operating Systems, W. Stallings 5th Ed. Pearson. nice j utilization by j in time i priority of j at start of i base priority of process j user adjustment for j Process with the lowest value has the highest priority
Scheduling 9.1 : generic Unix Queues are, in order of priority Swapper Block I/O device control File Manipulation Character I/O Device control User Process
Scheduling 10 : Linux pre 2.6 Linux has one run queue, but uses several scheduling policies, a number of priority levels and a niceness factor to control scheduling: Niceness is in the range -20 to +19, (user processes only) The priority is recorded in the priority field of the task_struct and is in the range 0-99 The policy is recorded in the policy field of the task_struct Policies are SCHED_RR SCHED_FIFO SCHED_OTHER
Scheduling 10.1 : Linux pre 2.6 SCHED_RR process base priority fixed for life in the range 1.. 99 Round-Robin scheduling runs until it blocks itself -> moved to wait Q preempted by higher priority process -> run Q uses up its quantum -> moved to run Q SCHED_FIFO process base priority fixed for life in the range 1.. 99 First come first served scheduling runs until it blocks itself -> moved to wait Q preempted by higher priority process -> run Q it completes current task -> moved to run Q
Scheduling 10.2 : Linux pre 2.6 SCHED_OTHER Used for all normal processes. Process base priority fixed at 0 Process has niceness factor which affects quantum. The counter field in task_struct is the quantum for a process. Decremented every clock tick when process running. Scheduler called when value = 0. counter field value recalculated as follows counter = Scale_Factor (20 (nice) + 1) The Scale_Factor is based on the processor speed and is to ensure that the standard quantum is around 50ms.
Scheduling 10.3 : Linux pre 2.6 Remember, all runnable processes are held in the same queue! The scheduler decides which process to run next by calculating the goodness factor. For policies SCHED_RR SCHED_FIFO goodness = 1000 + priority which puts real-time processes way above ordinary processes
Scheduling 10.4 : Linux pre 2.6 SCHED_OTHER is a bit more complex goodness = p->counter; if (p->processor == this_cpu) goodness += PROC_CHANGE_PENALTY; if (p->mm == this_mm!p->mm) goodness += 1; goodness += 20 - p->nice; goto out; If the counter value is zero for all processes then it is recalculated as p->counter = (p->counter >> 1) + NICE_TO_TICKS(p->nice);