1. Home
  2. Explore
  3. Computer Science
  4. CPU Scheduling Concepts

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

CPU Scheduling Concepts

CPU Scheduling

CPU scheduling is the operating-system activity of deciding which ready process receives a CPU and, in systems with multiple CPUs, which process receives which CPU. Scheduling also determines how long a process may run before another scheduling decision is made.

Scheduling algorithms can be studied first with the assumption of a single CPU, which makes their core ideas easier to understand. Multiprocessor scheduling adds further issues, such as assigning processes across multiple CPUs.


CPU Bursts and I/O Bursts

A process typically alternates between periods of CPU work and periods of waiting for input/output.

  • A CPU burst is a period during which a process runs and performs operations that do not require it to wait for I/O. Arithmetic operations such as addition and multiplication are CPU work. Loads and stores are also counted as CPU time by the operating system.

  • An I/O burst is a period during which a process waits for an I/O operation, such as reading a file or receiving keyboard input. These operations generally require operating-system services.

When a running process requests I/O, its CPU burst ends. The process moves from the running state to the waiting state while the I/O operation is performed. When the I/O completes, the process moves to the ready state; it does not immediately begin running. The scheduler must select it from the ready processes before it can use the CPU again.

Memory operations and CPU time

A load or store may cause the CPU to stall while the memory system retrieves or saves data. Nevertheless, the operating system treats that time as part of the process’s CPU burst: the process is still the one assigned to the CPU. By contrast, time spent waiting for an I/O operation is not CPU time for that process.


Typical CPU-Burst Lengths

CPU bursts vary in length. In the distribution described in the source, short bursts are common: a burst around 222 milliseconds is frequent, while bursts longer than about 888 milliseconds are rare. Long bursts are uncommon in part because processes often need to perform I/O rather than continue computing for an extended period.

Even a short burst can contain substantial work. For example, a 111-gigahertz processor can perform about 10910^9109 cycles per second. If an operation takes an average of roughly 101010 cycles, the processor can perform approximately 10810^8108 such operations per second. In 111 millisecond, that is about 10510^5105 operations, or hundreds of thousands. A burst lasting a few milliseconds may therefore include a large amount of computation.

These are only estimates: different instructions take different amounts of time. An addition may take about one cycle, multiplication may take several cycles, and a load or store that misses the cache and accesses main memory may take hundreds of cycles.


The Short-Term CPU Scheduler

The short-term scheduler selects a process from the ready set and allocates the CPU to it. The ready set is often called the ready queue, but it does not have to be implemented as a literal first-in, first-out queue. It can use a data structure suited to the scheduling policy, such as a priority queue or a tree.

Many operating systems assign processes priorities. A priority-based scheduler must organize ready processes so that it can efficiently select an appropriate process.


Preemptive and Nonpreemptive Scheduling

A scheduling decision can occur at several process-state transitions.

  • When a running process requests I/O, it moves from running to waiting, so the CPU becomes available for another process.

  • When an I/O operation completes, the waiting process becomes ready and may be considered for the CPU.

  • When a process terminates, it releases the CPU.

  • In a preemptive system, a running process can also be interrupted and moved back to the ready state so that another process can run.

Preemptive scheduling

In preemptive scheduling, the operating system can take the CPU away from a process before that process voluntarily releases it. A timer can interrupt the running process after a time interval, allowing the operating system to make a new scheduling decision. This interval is often called a time quantum.

Preemption requires hardware support, especially a timer capable of generating interrupts. Without such support, the operating system cannot reliably interrupt a process that continues running.

Nonpreemptive scheduling

In nonpreemptive scheduling, the operating system does not forcibly interrupt a running process. The process keeps the CPU until it releases it, for example by requesting I/O or terminating. Scheduling decisions still occur when the CPU becomes available and when events such as I/O completion make a process ready.


The Dispatcher and Dispatch Latency

The scheduler chooses which process should run; the dispatcher carries out that choice. Its work includes:

  1. Saving the state of the process that is losing the CPU.

  2. Restoring the state of the process that is about to run.

  3. Switching execution to user mode.

  4. Jumping to the appropriate instruction in the selected process so it can resume.

Switching to user mode is essential for protection. If a user process were allowed to run with kernel privileges, it could access protected operations and resources.

The time required for the dispatcher to stop one process and start another is called dispatch latency. This time is overhead: while the dispatcher performs the switch, it is not doing useful work on behalf of the processes being scheduled.


Criteria for Evaluating Scheduling Algorithms

Scheduling algorithms are evaluated using measures of performance and responsiveness. Different criteria may conflict, so a system often has to balance them.

CPU utilization

CPU utilization is the proportion of time the CPU is busy doing work rather than idle. In general, systems aim to maximize CPU utilization.

Throughput

Throughput is the number of processes or tasks completed during a given period. Higher throughput means more work is completed per unit of time, so throughput is generally something to maximize.

Turnaround time

Turnaround time is the total time from when a task is submitted to when it is completed. It includes time spent waiting, running, and performing or waiting for I/O. Scheduling policies generally aim to minimize turnaround time.

Waiting time

Waiting time is the time a process spends in the ready queue, waiting for the CPU. It does not include time spent running or waiting for I/O. A common goal is to minimize the average waiting time across processes.

Response time

Response time is the time from a task’s submission until the system provides its first response. It is especially important for interactive systems, where users benefit from seeing a prompt response even if the task is not yet complete.


Time Quantum and Scheduling Tradeoffs

A shorter time quantum lets a preemptive scheduler give CPU time to more processes sooner. This can improve response time because interactive processes do not have to wait as long for their next opportunity to run.

However, shorter time quanta also cause more frequent context switches. Since each switch consumes time in the kernel, a large fraction of CPU time may be spent on scheduling overhead rather than useful process work. This can reduce throughput and increase turnaround time.

Thus, a shorter quantum can have competing effects:

  • Response time: often improves because processes get opportunities to run sooner.

  • Throughput: can decline because more CPU time is used for context switching.

  • Turnaround time: can increase when switching overhead delays task completion.

  • Resource efficiency: can decline if the quantum is so short that switching overhead becomes substantial.

Choosing a scheduling policy therefore involves balancing user-facing responsiveness against efficient use of system resources. The best balance depends on system goals and workload.


Focus on Average Waiting Time

A common way to compare scheduling algorithms is to calculate their average waiting time: the mean time processes spend in the ready queue. Optimizing an average gives a broad measure of behavior across a workload, though an average alone may hide unusually poor outcomes for individual processes.

Some systems may also care about extremes. For example, minimizing the maximum response time can help ensure that no interactive task waits too long. The appropriate criterion depends on whether the system prioritizes overall efficiency, typical user experience, or protection against especially long delays.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent