Lecture 3
Lecture 3
Computer Architecture
N. Navet - Computing Infrastructure 1 / Lecture 3
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.2 [edited NN] Silberschatz, Galvin and Gagne ©2013
What is an Operating System?
For how long OSes have been developed ?
A program that acts as an intermediary between users’ programs and the
computer hardware, it “manages” the hardware - bare hardware is not
easy to deal with!
Main purposes of an OS:
How many lines of
1. Execute and control user programs
code in an OS ?
2. Ease and speed-up the development of user programs by providing
high-level services / high-level abstractions, ease portability
3. Use the computer hardware in an efficient manner and allow
hardware resources to be shared among users/processes
Linux (M=Millions)
Small OS for embedded systems
Around 30M loc today
can be as small as 10K lines of code,
like the core of FreeRTOS
Operating System Concepts – 9th Edition 1.3 [edited NN] Silberschatz, Galvin and Gagne ©2013
Processors have become complex
System-on-Chips (SoC)
Operating System Concepts – 9th Edition 1.7 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer System Structure
Operating System Concepts – 9th Edition 1.8 Silberschatz, Galvin and Gagne ©2013
Four Components of a Computer System
Operating System Concepts – 9th Edition 1.9 Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.10 [edited NN] Silberschatz, Galvin and Gagne ©2013
In Linux, the Graphical User Interface (e.g., KDE and Gnome) is clearly
decoupled from the OS: we can run the same kernel with ≠ GUIs. In
Windows / OS X, the distinction is not so clear and the GUI can be
considered to belong to the OS.
Operating System Concepts – 9th Edition 1.11 Silberschatz, Galvin and Gagne ©2013
The OS as an extended machine with a higher-level
interface better suited to applications
3 main OS abstractions
System
calls offer the
services of
the OS (e.g.:
writing into a
file) to the
user programs
via an API
(Application
Programming
Interface)
Ex: SATA disk interface (663 pages spec. in 2009), higher level
concepts: disk driver (read/write blocks) and files/directory
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
1.12 [edited NN]
Operating System Definition
Operating System Concepts – 9th Edition 1.13 [edited NN] Silberschatz, Galvin and Gagne ©2013
Operating System Definition (Cont.)
OS is a resource allocator
Manages all resources: memory, CPU, file-storage space, I/O devices
Decides between conflicting requests for resource use (fair or not, e.g.
CPU time in real-time systems)
OS is a control program
Controls execution of programs to prevent errors and improper use of the
computer → improves security & stability, which may have an impact in
terms of safety
Examples of protection:
Memory protection: a program can only access the memory area it is
allowed to (more generally protection of shared resources)
Service protection: service are properly used (e.g. arguments are
correct)
Execution time protection: an application does not use more than its
CPU budget (other applications do not suffer from “starvation”)
Operating System Concepts – 9th Edition 1.14 [edited NN] Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.15 [edited NN] Silberschatz, Galvin and Gagne ©2013
Transition from User to Kernel Mode
Dual-mode operation allows OS to protect itself and other system components
User mode VS kernel mode (aka system mode, privileged mode,
monitor mode)
Mode bit set in a CPU register provides ability to distinguish when system is
running user code or kernel code
Some instructions designated as privileged, only executable in kernel
mode: all instructions related to I/Os, interrupts, Memory Protection Unit, etc.
A system call changes mode to kernel, return from call resets it to user mode
Operating System Concepts – 9th Edition 1.16 [edited NN] Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.17 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer System Organization (1/3)
Computer-system operation
One or more CPUs & device controllers are connected through a
common bus providing access to shared memory
Concurrent execution of CPUs and devices competing for
memory access
Intel G33 is a
northbridge chip, i.e.
meant for high-speed
transfer
ICHx is a southbridge
chip, i.e. meant for
lower-speed transfer
Operating System Concepts – 9th Edition 1.19 [edited NN] Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.20 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer Startup
Operating System Concepts – 9th Edition 1.21 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer-System Operation
The CPU can load instructions only from memory (not from a disk), so any
programs to run must be stored there
I/O devices and the CPU can execute concurrently
Each device controller is in charge of a particular device type and has a local
buffer - I/O is from the device to local buffer of the device controller
The device controller is controlled through registers by a device driver in the
OS
Device controller informs CPU that it has finished its operation by generating
an interrupt (“something requires immediate attention, e.g. requested data is
ready”)
CPU moves data from main memory to the buffers local to the devices, from
local buffers to main memory (except if the device has Direct Memory Access!)
Operating System Concepts – 9th Edition 1.22 Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.23 [edited NN] Silberschatz, Galvin and Gagne ©2013
Roles of Interrupts
An interrupt is a signal to the processor emitted by hardware or software
indicating an event that needs immediate attention:
Hardware interrupt (limited by # interrupt lines): timer, keyboard, mouse,
completion of an I/O operation, memory parity error, etc
Software interrupt (unlimited): divide-by-zero, exception in a program,
etc, and system calls
An interrupt immediately leads to the execution of the corresponding
interrupt service routine (ISR) generally through the interrupt vector,
which contains the addresses of all the ISRs
A software-generated interrupt caused either by an error in a program or a
system call is referred to as a exception or trap
An OS is interrupt driven and interrupts offer a way for the kernel to
regain control of execution (e.g., through timer’s interrupts)
Concepts:
Unix signals are software interrupts
interrupt
but generated by the kernel to
(HW,SW), ISR,
processes, eg. SIGSEGV, SIGKILL
exception,
signal
Operating System Concepts – 9th Edition 1.24 [edited NN] Silberschatz, Galvin and Gagne ©2013
Interrupt Timeline: signaling completion
of an I/O operation
Operating System Concepts – 9th Edition 1.25 [edited NN] Silberschatz, Galvin and Gagne ©2013
I/O Operations
Read/Write
Start of I/O operation
Completion of I/O
Operating System Concepts – 9th Edition 1.28 Silberschatz, Galvin and Gagne ©2013
Outline
Operating System Concepts – 9th Edition 1.29 [edited NN] Silberschatz, Galvin and Gagne ©2013
Multiprocessors / Multicore
Most systems have a single general-purpose processor, along with special-
purpose processors such as a Graphical Processing Unit (GPU)
In many systems (except PCs), all processors are packaged into a single
chip called a System-On-Chip (SOC)
https://en.wik
ipedia.org/wik
i/Apple_A12
Caching : copying
instructions or data into
faster storage area
Operating System Concepts – 9th Edition 1.31 Silberschatz, Galvin and Gagne ©2013
Example: Intel Core I7 organization
Cache performance depends on
locality and speed – but large
caches takes a lot of space
32KB 32KB
L1: speed + locality but space
on chip limits its size
256KB L2: larger amount of data with
slight location penalty
L3: very large cache as close
>2MB
as it can be from the cores
+L3
Operating System Concepts – 9th Edition 1.33 Silberschatz, Galvin and Gagne ©2013
Multiprocessor speedup =
Time to execute program on a single processor
Time to execute program on N parallel processors
1 CPU
N CPUs
Questions:
What happens when f is small ?
What happens when N grows ?
Operating System Concepts – 9th Edition 1.35 Silberschatz, Galvin and Gagne ©2013
f is the fraction of the program that
can be parallelized
Operating System Concepts – 9th Edition 1.36 Silberschatz, Galvin and Gagne ©2013
On CPU voltage, frequency and consumption (1/2)
Operating System Concepts – 9th Edition 1.37 [NN] Silberschatz, Galvin and Gagne ©2013
On CPU voltage, frequency and consumption (2/2)
Operating System Concepts – 9th Edition 1.38 [edited NN] Silberschatz, Galvin and Gagne ©2013
Storage Units (1/2)
✓ The basic unit of computer storage is the bit. All other storage in a
computer is based on collections of bits.
✓ A byte is 8 bits, and on most computers it is the smallest usable
chunk of storage.
✓ Another common term is word, which is a given computer
architecture’s native unit of data. A word is made up of one or more
bytes. For example, a computer that has 64-bit registers and 64-bit
memory addressing typically has 64-bit (8-byte) words. A computer
executes most operations in its native word size rather than a byte
at a time.
✓ Computer storage is generally measured and manipulated in bytes
and collections of bytes.
✓ BUT, networking measurements (e.g., data rates) are always given in
bits (because networks typically move data a bit at a time).
Operating System Concepts – 9th Edition 1.39 [edited NN] Silberschatz, Galvin and Gagne ©2013
Storage Units (2/2)
[Wikipedia]
Operating System Concepts – 9th Edition 1.40 [edited NN] Silberschatz, Galvin and Gagne ©2013
Main metric units (SI Units)
Operating System Concepts – 9th Edition 1.41 [edited NN] Silberschatz, Galvin and Gagne ©2013
Storage-Device Hierarchy
Storage systems organized in
hierarchy based on 3 factors:
Volatile,
Access speed
fast
Cost
Volatility
Caching – copying information
(temporarily) into faster storage Non-
system volatile,
Device Driver (in OS) for each slower
device controller manages I/O
operations (except for 3 top layers)
Provides uniform interface
between controller and
kernel independently of +cloud
the specific hardware
components
Makes it easier for the OS to do
the same for user-program
Operating System Concepts – 9th Edition 1.42 Silberschatz, Galvin and Gagne ©2013
Caching in more details (1/2)
Operating System Concepts – 9th Edition 1.43 [edited NN] Silberschatz, Galvin and Gagne ©2013
Caching in more details (2/2)
Operating System Concepts – 9th Edition 1.44 [edited NN] Silberschatz, Galvin and Gagne ©2013
Cache architecture of modern desktop CPUs
Operating System Concepts – 9th Edition 1.45 [edited NN] Silberschatz, Galvin and Gagne ©2013
Storage hierarchy: who manages what?
“Managing” here means deciding which data goes where and for how long
it stays there
Compiler
s Hardware (CPU)
Operating System Concepts – 9th Edition 1.46 Silberschatz, Galvin and Gagne ©2013
Two imperatives of caching
Runtime environment must
ensure that the most
recent value is used, no
matter where it is stored in
the storage hierarchy
Cache coherency must be
enforced: all CPUs must
have the most recent value
in their cache before using
a data. This is ensured in
hardware.
Operating System Concepts – 9th Edition 1.47 Silberschatz, Galvin and Gagne ©2013
End of Lecture 3
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013