Title: Systems Architecture, Fifth Edition
1SCSC 311 Information Systems hardware and
software
(Part I)
2Index (Part I)
- Overview of operating system
- Single-Tasking OS vs. Multitasking OS
- Resources allocation
- Interrupts
3Computer System Organization
- Computer System contains one or more CPUs,
devices (device controllers) connect through
common bus providing access to shared memory - Concurrent executing programs competing for CPU
and other shared resources
Functionality comes with great complexity!
4How do we tame complexity?
- Every piece of computer hardware is different
- Different CPU Pentium, PowerPC, MIPS
- Different amounts of memory, disk,
- Different types of devices Mice, Keyboards,
Sensors, Cameras, Fingerprint readers - Different networking environment Cable, DSL,
Wireless - Some questions we want to answer
- Do the programmers need to write a single program
that performs many independent activities? - Does every program have to be altered for every
piece of hardware? - Does a faulty program crash everything?
- Does every program have access to all hardware?
5Virtual Machine Abstraction
Application Operating System Hardware
Virtual Machine Interface
Physical Machine Interface
- For Any OS area (e.g. file systems, virtual
memory, networking, scheduling) - the hardware interface messy physical reality
- the application interface a nicer abstraction
6Components of a Computer System
OS implements a virtual machine that is easier
and safer to program and use than the raw
hardware.
7What does an Operating System do?
- OS acts as
- Coordinator
- Manages all resources
- Settles conflicting requests for resources
- Prevent errors and improper use of the computer
- Facilitator
- Provides facilities that everyone needs
- Standard Libraries, Windowing systems
- Make application programming easier, faster, less
error-prone - OS consists of
- Kernel
- service layer
- command layer
8- the users interface to OS
- Shell or GUI
- Contains set of functions executed by application
programs and command layer. - a request to execute a service layer function is
called a service call
- Manages resources
- interacts directly with hardware
- service layer functions rely on the kernel to
interact with hardware
Functions within one layer can be modified
without affecting other layers ? make OS more
maintainable
9Kernel
- Kernel is the one program running at all times on
the computer. - Kernel directly interacts with hardware
- Everything else is either system program (ships
with the OS) or application program
10OS Management Functions
- OS management functions can be loosely divided
to - oriented to hardware resources
- oriented to users and their programs
11Index (Part I)
- Overview of operating system
- Single-Tasking OS vs. Multitasking OS
- Resources allocation
- Interrupts
12Single-Tasking OS vs. Multitasking OS
- Single-Tasking OS
- Involves only two executing programs
- OS reserve resources required when it boots
up - One application program has all remaining
resources - Single tasking OS are small and efficient
why? - Application error or service call are processed
through interrupts. - When an interrupt is detected, OS takes control
of CPU back from application program - Multitasking OS
- OS and multiple application programs are running
- More flexible to build and use
- since large program can be built from smaller
independent modules or processes. - e.g. load / start / stop module without reboot
in Linux - e.g. Your PC is receiving emails while youre
editing a file - Most modern OS, such as Linux, Mac, MS Windows
- However, multitasking OS require more complicated
resource allocation scheme.
13Single-Tasking OS
- Examples of single tasking OS
- Very early computers
- Early PCs
- Embedded controllers (elevators, cars, etc)
- Single-tasking OS consists of a library of
standard services - Standard device drivers
- Interrupt handlers (next slide)
- Errors and service alls from application program
are normally processed through interrupts these
interrupts are generated by software - Math libraries
- How does single-tasking OS work? (p435)
- In a single-tasking environment, when an
application program begins executing, the
operating system grants it control of all unused
hardware
14Protection Mechanisms in Multitasking OS
- Problem Run multiple applications in such a way
that they are protected from one another - Goal
- Keep user programs from Crashing OS
- Keep user programs from Crashing each other
- Keep parts of OS from crashing other parts?
- Protection mechanisms (more details next)
- Address Translation
- Dual Mode Operation
15Address Translation
- Address Space
- A group of memory addresses usable by some
processes - Each program (process) and kernel has different
address spaces. - Address Translation
- Translate from Virtual Addresses (emitted by CPU)
into Physical Addresses (of RAM) - Mapping often performed in Hardware by Memory
Management Unit (MMU)
16Prog 1 Virtual Address Space
Prog 2 Virtual Address Space
Translation Map 1
Translation Map 2
Physical Address Space
17Dual Mode Operation
- Hardware provides at least two operation modes
- Kernel mode ( supervisor or protected mode)
- User mode Normal programs executed
- Some instructions/operations are prohibited in
user mode - E.g., cannot modify page tables in user mode,
user program attempts to modify ? an exception is
generated - Transitions from user mode to kernel mode
- Through system calls, Interrupts, or exceptions
- Kernel takes control back from user process,
verifies the system calls, and handles the
interrupts or exceptions.
18Index (Part I)
- Overview of operating system
- Single-Tasking OS vs. Multitasking OS
- Resources allocation
- Interrupts
19Resources
- Resources passive entities needed by
processes/threads to do their work - CPU time, disk space, memory
- Resources may require exclusive access or may be
sharable - e.g. Read-only files are typically sharable
- Printers are not sharable during time of
printing - One of the major tasks of an operating system is
to manage resources
20Resource Allocation
- Resource Allocation in OS
- Keep detailed records of available resources
know which resources can satisfy which requests - Schedule resources based on specific allocation
policies - Update records to reflect resource commitment and
release by programs and users
21Real Resources vs. Virtual Resources
- Real resources
- Physical devices and associated system software
- e.g. HD, RAM, CPU, printer,
- Virtual resources
- Resources that are apparent to a process or user
- Meet or exceed real resources by
- Rapidly shifting resources unused by one program
to other programs that need them - Q1 Can you give one example?
- Substituting one type of resource for another
- Q2 Can you give one example?
22Issues with Resource Sharing
- Starvation thread waits indefinitely
- e.g., low-priority thread waiting for resources
constantly in use by high-priority threads - Deadlock circular waiting for resources
- e.g., Thread A owns Res 1 and is waiting for Res
2Thread B owns Res 2 and is waiting for Res 1
23Dining Philosophers Problem
- Five chopsticks and five philosophers
- What if all grab at same time?
- ? Deadlock!
- Q. How to fix deadlock after it occurs?
- One solution make one of them give up a
chopstick ? Eventually everyone will get chance
to eat - Any other proposals?
- How to prevent deadlock?
- One solution never let a philosopher take the
last chopstick if no hungry philosopher has two
chopsticks afterwards
24Three Methods for Handling Deadlocks
- Detect and recover allow entering deadlock
state, detect it and then recover - Requires deadlock detection algorithm
- Prevent or avoid deadlock ensure that system
will never enter a deadlock - Ignore deadlock and pretend that deadlocks never
occur in the system - used by most operating systems, including UNIX,
Window - The simplest way to deal with deadlock
- What would happen?
25Index (Part I)
- Overview of operating system
- Single-Tasking OS vs. Multitasking OS
- Resources allocation
- Interrupts
26Interrupt Processing (1) (revisit P227-231)
- Peripheral device sends an interrupt, which is an
electrical signal over control bus - CPU continuously monitors the bus for interrupt
signals, and copy them to interrupt register in
the form of a numeric value -- interrupt code - The control unit checks interrupt register at the
end of each execution cycle (steps on the
next slide) - If an interrupt code is found, CPU suspends the
execution of the current process, reset interrupt
register to zero, and process the interrupt. - When the interrupt has be processed, the CPU
resumes executing the suspended process. - Remark coordinating peripheral device
communication with interrupts allows the CPU do
something useful while its waiting for an
interrupt. - Q. Can you give one example?
27Interrupt Processing (2) (revisit P230)
- Q Why do we need stack in interrupt processing?
- Ans OS needs to be able to restart a suspended
process at exactly the position is was
interrupted. - CPU pushes current register values on stack the
saved register values are called the machine
state. - CPU executes a master interrupt handler
supervisor - Supervisor searches interrupt table based on
interrupt code, and transfers control to a
corresponding interrupt handler - When the interrupt handler finishes, CPU pops the
stack and load them back into the appropriated
registers ? the suspended process resumes from
point of interruption