0% found this document useful (0 votes)
7 views

Lecture 3

Uploaded by

ryuu.ducat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lecture 3

Uploaded by

ryuu.ducat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Basics of Operating Systems and

Computer Architecture
N. Navet - Computing Infrastructure 1 / Lecture 3

Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Outline

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

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)

Modern SoCs feature high-performance and energy-


efficient CPU cores, GPUs, system-level memory
caches (SLC, M1: 16MB), core-cluster-level caches
(M1: 12MB) and caches dedicated to a core (M1:
128KB), specialized CPUs for e.g. signal processing
& cryptography, communication buses to
interconnect all these components, etc..
A diversity of OS
• Personal computer OS
• Server OS
• Mobile device OS
• Supercomputer OS / OS for High Performance
Computing (HPC) infrastructure
• Real-time / embedded system OS
• Domain specific OS: Robot OS, Smart Card OS, OS
for cars, OS for aircrafts, etc

Any other example of


a domain-specific OS ?
Design objectives for OS

Depends on the intended usage ! A diversity of objectives


Typically, users want convenience, ease of use and responsiveness
Shared computers such as mainframes/clouds must keep users
happy (i.e., fairness among applications/users, and meeting Service
Level Agreement)
Users of dedicated systems such as workstations have dedicated
resources but frequently use shared resources from servers
Handheld computers are optimized for usability, security and battery
life
Some computers have no user interface, such as in automobiles and
aircrafts. In such “critical systems”, meeting timing and safety
constraints giving the priority to certain tasks (≠ fairness).

An Electronic Control Unit (ECU)


is a computer used in the
automotive domain
(engine, ABS, body, etc)
Operating System Concepts – 9th Edition 1.6 [edited NN] Silberschatz, Galvin and Gagne ©2013
Outline

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

Operating System Concepts – 9th Edition 1.7 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer System Structure

“Computer systems” comprises four components:


Hardware – provides basic computing and storage resources
 CPU, memory, Input/Ouput devices
Operating system
 Controls and coordinates use of hardware among various
applications and users
Application programs – define the ways in which the system
resources are used to solve the computing problems of the
users
 Word processors, compilers, web browsers, database
systems, video games
Users
 People and other computers

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

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

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

No universally accepted definition


“The one program running at all times on the computer” is the kernel.
Everything besides the kernel is either
a system program / library (ships with the operating system), or
an application program.
In theory, by law, OS vendors cannot include too much functionality, as
it may prevent application vendors from competing (Microsoft lawsuits)
Some OS, e.g. mobile OS, include not only a kernel but a middleware:
a set of software frameworks providing additional services to
application developers

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

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

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

System call triggers an interrupt

Operating System Concepts – 9th Edition 1.16 [edited NN] Silberschatz, Galvin and Gagne ©2013
Outline

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

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

Main memory is Shared bus


managed by a
memory controller
Very simplified, for more modern architectures see
https://en.wikipedia.org/wiki/Southbridge_(computing)
Operating System Concepts – 9th Edition 1.18 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer System Organization (2/3)
A typical Slide outside the scope of the course
motherboard
10+ years ago

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

Today, there is a single chipset


(Platform Controller Hub for
Intel) and the CPU (actually
more a SoC) is interconnected
directly to high-speed devices
such as SSD or GPU

Operating System Concepts – 9th Edition 1.19 [edited NN] Silberschatz, Galvin and Gagne ©2013
Outline

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

Operating System Concepts – 9th Edition 1.20 [edited NN] Silberschatz, Galvin and Gagne ©2013
Computer Startup

bootstrap program is loaded at power-up or reboot


Typically stored in non-volatile memory: ROM or EEPROM (e.g.
flash memory), generally known as firmware / BIOS / UEFI
Initializes all aspects of system: CPU registers, device controllers,
etc
Loads operating system kernel into memory and starts execution

Once the kernel is loaded, services (offered by system processes


outside the kernel) are loaded and execute in background:
On Unix, the first system process is “init” (“systemd” in Linux) and it
loads other daemons (i.e., background processes) like:
 “syslogd”: the system logging facility,
 “sshd” serves incoming SSH connections,
 “cron” performs defined tasks at scheduled times.

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

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts and I/O operations
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

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

ISR executing – The process is informed through an interrupt


that the I/O transfer is over.

Operating System Concepts – 9th Edition 1.25 [edited NN] Silberschatz, Galvin and Gagne ©2013
I/O Operations

From the programmer’s perspective, 2 types of I/O operations:


Synchronous I/O: after I/O starts, control returns to user program only upon
I/O completion → the process is blocked until I/O is over
Asynchronous I/O: I/O starts but control returns to user program without
waiting for I/O completion

Synchronous or Asynchronous I/O in previous slide?


Low-level:
1. To start an I/O, the device driver (SW) from the OS writes the appropriate
command in a register of the device controller (HW)
2. The device controller reads the registers and determines the action to be done
(e.g., read/write at a certain location)
3. The controller then transfers the data between (to/from) the device and the
local buffer, and informs the device driver through an interrupt when the
transfer is over
4. If it is a read operation (and without DMA – see next slide), the CPU moves
the data from local buffer to main memory
Operating System Concepts – 9th Edition 1.26 [edited NN] Silberschatz, Galvin and Gagne ©2013
To avoid that the CPU handles
large amounts of data (e.g., disk I/O) : DMA

Read/Write
Start of I/O operation

Completion of I/O

Direct Memory Access (DMA) : the


device controller transfers blocks of
data between its local buffer and
memory without that the CPU
intervenes. DMAs may still delay
CPU if they are using the shared
system bus at the same time as
the CPU
Operating System Concepts – 9th Edition 1.27 [edited NN] Silberschatz, Galvin and Gagne ©2013
Direct Memory Access Structure
Used for high-speed I/O
devices: disks, network
cards, graphic cards
Device controller transfers
blocks of data from buffer
storage directly to main
memory without CPU
intervention
Only one interrupt is
generated per “block” (block
size varies e.g, 256 or 512
bytes), rather than one
interrupt per byte/word

Operating System Concepts – 9th Edition 1.28 Silberschatz, Galvin and Gagne ©2013
Outline

1. What is an Operating System (OS) ?


2. Organization of computer systems
3. Where the OS fits in
4. Users mode and kernel execution mode
5. Computer-System Architecture
6. Computer startup
7. The role of interrupts and I/O operations
8. Multicore and limits of parallelization
9. Memory hierarchy and caching

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

Symmetric Multiprocessing Architecture (SMP): identical cores/CPUs vs


Heterogeneous Multiprocessor System on a Chip (HMPSoC)
Today, multicore CPUs is the norm Hyperthreading: consists of two
virtual processors per core –
the core can execute two
programs and choose which
one to execute on a cycle per
cycle basis. Its efficiency
comes from the fact that
programs spend a lot of time
waiting for data.
Operating System Concepts – 9th Edition 1.30 [edited NN] Silberschatz, Galvin and Gagne ©2013
Location of all memory areas?

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

image from Arstechnica


Operating System Concepts – 9th Edition 1.32 [edited NN] Silberschatz, Galvin and Gagne ©2013
Higher clock rate →
Higher voltage →
Higher consumption +
Heat

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

[edited NN]System Concepts – 9th Edition


Operating 1.34 Silberschatz, Galvin and Gagne ©2013
Let T be the execution time of the program on a single processor. (1 – f) of the
execution time cannot be parallelized and a fraction f is infinitely parallelizable with
no scheduling overhead.

1 CPU

N CPUs
Questions:
What happens when f is small ?
What happens when N grows ?

Amdahl’s law gives the time to execute


a program on a multiprocessor platform

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)

✓ The dominant technology today for processors, memory


chips, and digital circuits at large is CMOS
(“Complementary Metal Oxide Semiconductor”)
✓ In CMOS, the max. frequency of a processor increases
linearly with the voltage, while the energy consumption
varies at least quadratically with the voltage (e.g., 2x the
voltage and thus 2x the frequency → 4x consumption)
✓ Let’s consider below the example of a processor. Here
the energy consumption is expressed in joules (1 joule =
the amount of electricity required to run a 1W device for 1s).

Operating System Concepts – 9th Edition 1.37 [NN] Silberschatz, Galvin and Gagne ©2013
On CPU voltage, frequency and consumption (2/2)

Let’s consider a program requiring 109 CPU cycles to execute:


1. Program execution time at 25MHhz and 50Mhz ?
2. Energy consumption to execute the program at 25MHhz and
50Mhz ?
3. Let’s assume the program can be fully parallelized and needs to
complete in 20s. Solution a) is to use a single core at 50Mhz,
sol. b) is to use two cores at 25Mhz. What will be the gain in
terms of energy of solution b) over solution a) ?

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)

What is a kilobyte ? 2 conventions!


✓ 1000 (103) and 1024 (210) bytes
✓ 1000 (103) is the definition by the International System of Units (SI
units), that is the most common definition, symbol is kB
✓ 1024 (210) has been largely used for RAM capacity, CPU cache size,
…, symbol is KB.
✓ In 1998, a new standard has been established to denote powers of
1024 creating prefixes like kibi, mebi, gibi. Thus, the kibibyte, symbol
Kib, is 210 bytes. This notation is rarely used.

[Wikipedia]

Operating System Concepts – 9th Edition 1.40 [edited NN] Silberschatz, Galvin and Gagne ©2013
Main metric units (SI Units)

[Tanenbaum & Austin]

Time to transmit 1 bit on a 10Gbit/s network link?

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)

Data resides in cache temporarily, while it is used.


Faster storage area (cache) checked first to determine if
information is there
If it is, information used directly from the cache (fast)
If not, data copied to cache and used from there

Cache always smaller than storage area being cached


Cache size and cache management are important design problems
E.g., when should data be removed (“evicted”) from a cache?
A cache miss is a failed attempt to read or write a piece of data in the caches
located in or near the CPU, which results in a main memory access with much
longer latency.

Operating System Concepts – 9th Edition 1.43 [edited NN] Silberschatz, Galvin and Gagne ©2013
Caching in more details (2/2)

Caching – copying information (temporarily) into


faster storage system
When talking about caches, we usually mean
“using the caches that are located in the CPU to
speed up the access to data and instructions
normally stored in main memory”
However caching is a general mechanism used at
many levels, e.g.:
Main memory is used to cache data from disks
Disks are used to cache information from the cloud
Previously computed results of a
program/functions are cached to RAM or disk to
save computing time

Operating System Concepts – 9th Edition 1.44 [edited NN] Silberschatz, Galvin and Gagne ©2013
Cache architecture of modern desktop CPUs

Typical 3-level cache


architecture (AMD, Intel):
AMD Ryzen9 (Zen2) cache architecture
• L1 = Level1 (data +
“12 x” means “for each of the 12 cores”.
instructions)
16MB L3 shared within a Core Complex
• L2 = Level2 (still intra-core)
(CCX, i.e. 3 cores on the 3900x) rather
• L3 = Level 3 (shared among
than enabling access to any L3 from any
several cores)
core.

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)

Software: OS + user programs

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

You might also like