Skip to main content

CPU simulation with example

Short answer

CPU simulation uses a queueing model: jobs queue for CPU under a policy like round‑robin. After a burst, jobs may go to disk. Example: arrivals mean 10ms, CPU 6ms, 30% go to disk (5ms). Run to compare quanta 2,4,8ms for best response time.

Explain CPU simulation with example (sketching a simulation model of a computer system).

CPU simulation models how a computer's processor handles the workload of jobs. It is done at a high level of abstraction as a queueing model: jobs arrive, wait in the ready queue, receive CPU service, use I/O devices, and leave. Its purpose is to estimate CPU utilisation, throughput and response time and to test scheduling policies without changing the real machine.

Model components

  • Jobs (entities): arrive with an inter-arrival distribution (for example exponential).
  • Ready queue: jobs waiting for the CPU.
  • CPU (server): serves according to the scheduling policy (FCFS, SJF, round robin with quantum q).
  • I/O devices (disk, printer) with their queues: a job leaves the CPU for I/O and returns.
  • Statistics: utilisation, mean queue length, response time, throughput.

Sketch of the model

 arrivals --> [ready queue] --> (  CPU  ) --> exit
                  ^                |
                  |   quantum      | I/O request
                  |   expired      v
                  +---------- [I/O queue] -> (Disk)

Logic (round robin, quantum 4 ms)

  1. A job arrives; if the CPU is free it starts, otherwise it joins the ready queue.
  2. CPU runs it for min(quantum, remaining burst).
  3. If it finishes, it leaves. If it needs I/O, it goes to the disk queue and returns to the ready queue later. If the quantum expires, it goes to the back of the ready queue.
  4. Events: arrival, CPU burst end, I/O completion.

Example

Jobs arrive every 10 ms on average. CPU time per job averages 6 ms; 30% of bursts end in a disk request with service time 5 ms.

  • Offered CPU utilisation is about 6/10 = 0.6.
  • By running a few thousand simulated jobs, we obtain mean waiting time in the ready queue and disk utilisation.
  • The analyst repeats the run with quantum 2, 4 and 8 ms to select the quantum that gives the best response time.

Simulation is preferred when scheduling and I/O interaction make exact analysis difficult.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Simulation and Modeling chapter 10 questions →