MULTIPROGRAMMING
abstraction (service) provided by the OS:
you want to run a program, so
the OS provides you with a process,
address space (space-multiplex RAM),
execution (time-multiplex CPU),
and files (space-multiplex disks)
protection
- base and limit registers in the CPU protect the OS
and hardware from your process,
and protect processes from each other
- kernel mode for executing privileged instructions
protects the hardware from your process
- clock interrupts protect the system from your infinite loops
and allocate CPU cycles fairly
multiprogramming implemented with process table,
ready queue,
clock chip interrupt handler
process table
- array of PCBs (process control blocks) inside OS (in RAM)
- each executing process has a PCB (entry) in the process table
- each PCB contains
- state: running, ready, blocked, suspended, exited
- CPU register save area: PC, PSW, SP, base, limit, etc.
- owner, priority
- list of open files and RW positions therein
- clock ticks used since last being given the CPU
ready queue
- doubly linked list inside OS (in RAM) of all processes in the
ready state (the process at the head is in the running state)
- head and tail pointers inside the OS
- when a process changes state from running to blocked or suspended
or exited, it is taken out of the ready queue
- when a process changes state to ready (from blocked or suspended),
is it linked into the ready queue,
usually at the rear or front
clock chip interrupts
- clock chip raises system bus interrupt line and places its
device ID onto the system bus
- causes switch to CPU kernel mode and save PC register contents
in PCB pointed to by ready queue head pointer
- load PC from clock chip's entry in the interrupt vector
(the entry indexed by the device ID on the system bus)
- execute the clock chip (hardware) interrupt handler in kernel mode
- disable interrupts
- save all CPU registers in PCB pointed to by ready queue head pointer
- increment the clock ticks used field in the PCB pointed to
by ready queue head pointer
- if clock ticks used >= MAX_TICKS_ALLOWED then
- move the PCB pointed to by ready queue head pointer to the rear
of the ready queue
- change head and tail pointers, next pointers, etc.
- zero out clock ticks used in the (now different) PCB
pointed to by ready queue head pointer
- restore CPU registers from PCB pointed to by ready queue head pointer
- enable interrupts
- return from TRAP/INTERRUPT
- load PC register from PCB pointed to by ready queue head pointer
- switch to CPU user mode
- continue executing some process from where it left off after
last having the CPU
MAX_TICKS_ALLOWED is usually 7 so that each process gets a
time slice of about 100 milliseconds of CPU time
(the clock chip interrupts about 60 times a second or every 16.67
milliseconds)
home page:
http://elvis.rowan.edu/~hartley/index.html
e-mail:
hartley@elvis.rowan.edu