01 - CS F372 OS Introduction-2
01 - CS F372 OS Introduction-2
Systems
01 – Introduction
Chapter: 1
Sections: 1.1, 1.2, 1.5, 2.3, 2.10
Outline
Text Book
Course plan
Evaluation Components
Course Objectives
What is OS? and OS goals
Components of computer system
OS – what it can do?
Computer systems, OS and Interrupts
01/24/2024 2
Text Book
Silberschatz, A, Galvin P.B. and Gange G
“Operating System Concepts” 9th edition,
Wiley.
01/24/2024 3
Course plan
Lecture Section(s) of the
Topic(s)
Number Text Book
1 Introduction to OS 1.1 to 1.3
2, 3 OS architecture and its components 1.4 to 1.10
4 Special purpose systems 1.11 to 1.12
5-6 Operating system structures Ch 2
Process Concept, scheduling, operations on processes, Interprocess
7-9 Ch 3
communication
10-14 CPU scheduling algorithms Ch 6
15-16 Process Synchronization, Critical section problem, Peterson’s solution 5.1 to 5.3
17-19 Semaphores, Monitors, Synchronization Hardware 5.4 to 5.8
20-21 Deadlock concept, Characterization and methods of handling 7.1 to 7.3
22-24 Deadlock detection, Prevention, Avoidance 7.4 to 7.6
25 Recovery from deadlocks 7.7
26-27 Memory management, Swapping, Allocation 8.1 to 8.3
28-30 Concept of segmentation 8.4, 8.7(Class notes)
31-33 Concept of Paging 8.5 to 8.6
34 Virtual Memory management, Demand paging, Copy-on-write 9.1 to 9.3
35-36 Page replacement algorithms 9.4
37 Frame allocation and Thrashing 9.5 to 9.6
38-39 Secondary storage structure & Management Ch 10
40-42 File systems Ch 11 (Class notes)
01/24/2024 4
Course objectives
Understand what an operating system is
Learn how OS evolved
Study the functions of operating systems
Study the concepts underlying the design
and implementation of OS
01/24/2024 5
What is an Operating System?
Software
A program that acts as an intermediary between a user
of a computer and the computer hardware
Manages and controls computer’s hardware resources
for users and applications
Allocates hardware resources to computer programs in
a fair and efficient manner
It is a control program that manages the execution of
user programs to avoid errors and improper use of
computers
01/24/2024 6
Components of a Computer System
01/24/2024 7
Components of a Computer System
Computer system - four components:
Hardware – provides basic computing resources
01/24/2024 9
User’s view of OS
Personal Computers
Users want convenience - ease of use and good performance
Don’t care about resource utilization
Handheld computers
Resource poor, optimized for usability and battery life
Hence OS for these systems must take these issues into
consideration
Embedded computers
Have little or no user interface (such as in devices and
automobiles and home appliances)
May have numeric keypads and indicator lights (on/off) to show
status
Runs specific programs
01/24/2024 10
Operating system definitions
Resource allocator – manages and allocates
resources
01/24/2024 11
Computer System Organization
General purpose computer-system
One or more CPUs, device controllers connect
01/24/2024 12
Computer System Organization
I/O device controllers and the CPU can execute
concurrently
Each device controller is in charge of a particular
device type
Each device controller has a local buffer
Data is moved between the peripheral devices and
local buffers by the device controller
Device controller informs CPU that it has finished its
operation by causing an interrupt
01/24/2024 13
Computer System Organization
Device driver:
Operating systems have a device driver for each
device controller
This device driver understands the device controller
and provides the operating system with a uniform
interface to the device.
01/24/2024 14
Interrupts
Consider a program performing I/O.
To start an I/O operation, the device driver loads the
appropriate registers in the device controller.
The device controller, in turn, examines the contents of
these registers to determine what action to take (such
as “read a character from the keyboard”).
The controller starts the transfer of data from the device
to its local buffer.
Once the transfer of data is complete, the device
controller informs the device driver that it has finished
its operation.
01/24/2024 15
Interrupts
The device driver then gives control to other parts of the
operating system, possibly returning the data or a
pointer to the data if the operation was a read.
For other operations, the device driver returns status
information such as “write completed successfully” or
“device busy”.
How does the controller inform the device driver that it
has finished its operation?
This is accomplished via an interrupt.
01/24/2024 16
Interrupts
What is interrupt?
It is an asynchronous request to the CPU
system clock
What causes an interrupt?
Hardware or software
01/24/2024 17
Interrupts
01/24/2024 18
Interrupt types
01/24/2024 19
Interrupt handling
How does a device interrupts the CPU?
The device issues an interrupt signal to the
device
Hence the device removes the interrupt signal
01/24/2024 20
Interrupt handling
What happens when interrupt occurs?
CPU finishes the execution of the current instruction
01/24/2024 21
Interrupt handling
01/24/2024 22
OS should guarantee that the interrupt latency is less than a
specified value
01/24/2024 23
Interrupt Vector Table
Where are the ISRs placed?
Placed in a fixed location in memory
Vectored interrupts
Interrupt vector table (IVT)
Acts as a pointer to the ISRs
Table contains the addresses of the ISRs
01/24/2024 24
Interrupt Vector Table
What is an interrupt vector
An interrupt request specifies a code/type of the
interrupt
It is used as an index/pointer into the IVT to
01/24/2024 25
Case Study: 8086 interrupt
handling
At the end of each instruction cycle 8086 processor checks to
see if there is any interrupt request. If so, 8086 responds to
the interrupt by performing series of actions
1. It pushes the flag register on the stack
2. It pushes the current code segment (CS) register contents
on the stack
3. It pushes the current instruction pointer (IP) contents on the
stack
4. It jumps to the start of the ISR by loading the new CS and
IP values for the start of the interrupt service routine (ISR)
• An IRET instruction at the end of the interrupt service
procedure returns execution to the interrupted program
01/24/2024 26
Case Study: 8086 interrupt
handling
“How to get the values of CS and IP register ?”
01/24/2024 27
Case Study: 8086 interrupt
handling
Using the Interrupt Vector Table (of an 8086 processor
operating in real mode) shown below, determine the
address of the ISR of a device with interrupt vector 42H.
0 1 2 3 4 5 6 7 8 9 A B C D E F
00000 3C 22 10 38 6F 13 2C 2A 33 22 21 67 EE F1 32 25
00010 11 3C 32 88 90 16 44 32 14 30 42 58 30 36 34 66
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
00100 4A 33 3C 4A AA 1A 1B A2 2A 33 3C 4A AA 1A 3E 77
00110 C1 58 4E C1 4F 11 66 F4 C5 58 4E 20 4F 11 F0 F4
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
00250 00 10 10 20 3F 26 33 3C 20 26 20 C1 3F 10 28 32
00260 20 4E 00 10 50 88 22 38 10 5A 38 10 4C 55 14 54
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
003E0 3A 10 45 2F 4E 33 6F 90 3A 44 37 43 3A 54 54 7F
003F0 22 3C 80 01 3C 4F 4E 88 22 3C 50 21 49 3F F4 65
01/24/2024 28
Case Study: 8086 interrupt
handling
Answer:
Address in table = 4 X 42H = 108H = 00108H
(Multiply by 4 since each entry is 4 bytes)
Offset (IP) Low = [00108] = 2A
Offset (IP)High = [00109] = 33
Segment (CS) Low = [0010A] = 3C
Segment (CS) High = [0010B] = 4A
Address = 4A3C:332A = 4A3C0 + 332A = 4D6EA H
01/24/2024 29
Hardware (external) interrupts
Generated by hardware
Useful when interfacing I/O devices with low data-
transfer rates with the processor
Example: Keyboard, mouse, printer, etc.,
processing time
The peripheral interrupts the normal application
execution of the processor, requesting to send or
receive data
01/24/2024 30
Computer-System Architecture
According to the number of general-purpose
processors used
Single-Processor Systems
Multiprocessor Systems
Single-Processor Systems
Used by most computer systems many years ago
1 processor (physical chip) with 1 core
(computation unit)
01/24/2024 31
Computer-System Architecture
Multiprocessors systems
Present in: modern computers, mobile devices,
servers
Traditionally 2 or more processors each with 1 core
2. Increased reliability
01/24/2024 32
Computer-System Architecture
Two types:
Asymmetric Multiprocessing – each processor is
Traditional
multiprocessing architecture
01/24/2024 33
Computer-System Architecture
Modern day multiprocessors are multicore systems
multiple computing cores reside on a single chip
Advantages
on-chip communication is faster than between-chip
communication
Lesser power consumption
01/24/2024 34
Storage Definition
The basic unit of computer storage is the bit
A bit can contain one of two values, 0 and 1
Byte is 8 bits
Word
A computer architecture’s native unit of data
made up of one or more bytes
01/24/2024 35
Storage Structure
Main memory – the only large storage media that the CPU can
access directly
Random access; volatile; small size
01/24/2024 36
Storage-device hierarchy
01/24/2024 37
Cache memory
Information in use is copied from slower to faster
storage temporarily
Faster storage (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 there
01/24/2024 38
Performance of Various Levels
of Storage
01/24/2024 39
Computer Startup/System Boot
Booting:
Loading of the OS into the primary memory
01/24/2024 40
Computer Startup/System Boot
What happens on power-on?
The PC is loaded with a predefined memory location
01/24/2024 41
Computer Startup/System Boot
• IA–32 (Intel Architecture, 32-bit)
•BIOS (Basic Input/Output System) which comprises
the bootloader
• Unified Extensible Firmware Interface, or UEFI
kernel”)
01/24/2024 42
Computer Startup/System Boot
Some services are provided outside of the kernel by
system programs that are loaded into memory at boot
time to become system daemons, which run the entire
time the kernel is running.
On Linux, the first system program is “systemd,” and it
starts many other daemons.
Once this phase is complete, the system is fully
booted, and the system waits for some event to occur.
01/24/2024 43
Software interrupts
Also called as trap or exception
Triggered by software
Causes of software interrupt
Exception: error conditions
01/24/2024 44
Dual-Mode Operation
OS and users share the hardware and software
resources of the computer system
Ensure that an error in a user program could
01/24/2024 45
Dual-Mode Operation
Solution: Dual-mode operation
User mode and kernel mode (supervisor mode,
system mode, or privileged mode)
Mode bit is added to the hardware
Provides ability to distinguish when system is
01/24/2024 46
Dual-Mode Operation
At system boot time, the hardware starts in kernel
mode (mode bit = 0)
The operating system is then loaded and starts user
applications in user mode (mode bit changes from 0 to
1)
Whenever a trap or interrupt occurs, the hardware
switches from user mode to kernel mode (mode bit
changes from 1 to 0)
Thus, whenever the operating system gains control of
the computer, it is in kernel mode
01/24/2024 47
Dual-Mode Operation
01/24/2024 48
Dual-Mode Operation
How dual mode protects OS and other user
programs from errant users?
Some instructions that might cause harm are
01/24/2024 50
Example of System Calls
System call sequence to copy the contents of one file
to another file
01/24/2024 51
System Calls
Application developers (or) users use Application
Programming Interface (API) which invokes the
actual system calls
The API specifies
a set of functions
01/24/2024 52
System Call Implementation
The run time support system of programming languages provides a
system-call interface
Typically, a number is associated with each system call
System-call interface maintains a table indexed according to
these numbers
The table contains the starting address of the implementation of
The caller need know anything about how the system call is
implemented
Just needs to obey API and understand what OS will do as a
01/24/2024 54
Standard C Library Example
01/24/2024 55
01/24/2024 56
System Call Parameter Passing
Three general methods used to pass parameters to the
OS
Simplest: pass the parameters in registers
01/24/2024 57
Parameter Passing via Table
01/24/2024 58
Example of Standard API
01/24/2024 59
System call for file read in C
int main(int argc, char *argv[])
{ int fd;
char content[100]="\0";
fd = open(argv[1], O_RDONLY);
if(fd < 0)
{ printf("File could not be opened.\n");
perror("open");
return; }
else
{ read(fd, content, sizeof(content)-1);
write(1, content, sizeof(content)-1);
}
return;}
01/24/2024 60