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

01 - CS F372 OS Introduction-2

This document provides an overview of an operating systems course, including: 1) The course covers topics like OS architecture, processes, scheduling, synchronization, deadlocks, memory management, file systems, and more over 40 lectures according to the textbook. 2) The objectives are to understand what an OS is, how it evolved, its functions, underlying design concepts, and how it manages and allocates hardware resources for users and applications. 3) An OS acts as an intermediary between the user and computer hardware, controlling devices and allocating resources to programs in a fair manner. It is made up of hardware, OS software, application programs, and users.

Uploaded by

iDubbbz TV
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

01 - CS F372 OS Introduction-2

This document provides an overview of an operating systems course, including: 1) The course covers topics like OS architecture, processes, scheduling, synchronization, deadlocks, memory management, file systems, and more over 40 lectures according to the textbook. 2) The objectives are to understand what an OS is, how it evolved, its functions, underlying design concepts, and how it manages and allocates hardware resources for users and applications. 3) An OS acts as an intermediary between the user and computer hardware, controlling devices and allocating resources to programs in a fair manner. It is made up of hardware, OS software, application programs, and users.

Uploaded by

iDubbbz TV
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 60

CS F372 Operating

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

 CPU, memory, I/O 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, machines, other computers


01/24/2024 8
User’s view of OS
User’s view of the computer varies according to the
interface being used

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

Control program – controls the execution of user


programs and operations of I/O devices

“The one program running at all times on the


computer” is the kernel

01/24/2024 11
Computer System Organization
General purpose computer-system
 One or more CPUs, device controllers connect

through common bus providing access to shared


memory

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

 It can be initiated anytime without reference to the

system clock
What causes an interrupt?
 Hardware or software

Why is interrupt caused?


 Occurrence of an event

01/24/2024 17
Interrupts

01/24/2024 18
Interrupt types

• Hardware Interrupt is caused by hardware device


• Avoid wasting the processor’s valuable time in
polling loops
• Software Interrupt is caused by an instruction in a
program

01/24/2024 19
Interrupt handling
How does a device interrupts the CPU?
 The device issues an interrupt signal to the

processor on the interrupt request line


When does the processor responds to an
interrupt?
 The processor completes the execution of the

current instruction (finishes the current instruction


cycle) and then responds to the interrupt
How does the CPU responds back?
 Its sends an acknowledgement signal back 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

and checks for interrupts


 Stores contents of Program Counter (return

address) and processor state onto stack


 Services the interrupt

 Transfer control to interrupt service routine (ISR)


and execute it
 After the interrupt is serviced

 Restore the processor state


 Load the saved return address into the program counter
 Resume the interrupted computation

01/24/2024 21
Interrupt handling

Main Program Main Program Main Program Main Program

Printer Interrupt Modem Interrupt Modem Interrupt

What is an ISR or interrupt handler?


It is a program that services the interrupting
source

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

How is the mapping between the interrupt source and


ISR done?
 Interrupt vector table (IVT)

 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

identify the address of the ISR


 Generally

 (ISR address location in IVT)H = (Interrupt vector)H *


(No. of locations for one entry in the vector table)H +
starting address of IVT

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 ?”

The Interrupt Vector Table in 8086


 Occupies the address range from 00000H to 003FFH (the first
1024 bytes in the memory map)
 Each entry in the Interrupt Vector Table is 4 bytes long:
 The first two bytes represent the offset address (IP)
 The last two bytes represent the segment address of the
ISR (CS)
The 8086 gets the new values of CS and IP register from four
memory addresses (locations)
8086 supports 256 interrupts

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.,

 Avoids polling the device which wastes valuable

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

 Processors share the computer bus, the clock,

memory, and peripheral devices


Advantages include:
1. Increased throughput

2. Increased reliability

01/24/2024 32
Computer-System Architecture
Two types:
 Asymmetric Multiprocessing – each processor is

assigned a specific task


 Symmetric Multiprocessing – each processor

performs all tasks

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

A dual-core design with two cores on the


same chip

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

A kilobyte, or KB, is 1,024 bytes


a megabyte, or MB, is 1,0242 bytes
a gigabyte, or GB, is 1,0243 bytes
a terabyte, or TB, is 1,0244 bytes
a petabyte, or PB, is 1,0245 bytes
exabyte, zettabyte, yottabyte

01/24/2024 35
Storage Structure
Main memory – the only large storage media that the CPU can
access directly
 Random access; volatile; small size

 Load and store data

Secondary storage – extension of main memory that provides


large nonvolatile storage
 Slower than main memory

Tertiary storage –magnetic tapes, CD, DVD


 Backup

 Very large storage; very slow

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

Cache are smaller (size-wise) than storage being


cached
 Cache management important design problem

 Cache size and replacement policy

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

When does booting occurs ?


 When system is powered-on or rebooted

Who loads the kernel on booting?


 Bootstrap loader or bootstrap program

Where is the bootstrap program kept?


 Typically stored in ROM or EEPROM

 Generally known as firmware

01/24/2024 40
Computer Startup/System Boot
What happens on power-on?
 The PC is loaded with a predefined memory location

 Execution starts at that fixed memory location

 At that location is the initial bootstrap program

Bootstrap loader: Tasks


 Run diagnostics to determine the state of the other

hardware attached to the machine (POST – Power


on self test)
 Initializes all aspects of system (CPU registers,

device controllers and the contents of main


memory)
 Loads operating system kernel

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

successor of BIOS for 64-bit architecture


• Linux & UNIX systems
• GRUB, or GRand Unified Bootloader

• Mobile systems - Android


• vendors provide boot loaders

• most common Android boot loader is LK (for “little

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

 Example: Divide by zero, invalid memory address


 Specific request from a user program that an

operating-system service be performed


 Example: Write a value to an output device
 Executes a special operation called a system call
or monitor call

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

cause problems only for the one program running


 Example

 If a process gets stuck in an infinite loop


 One erroneous program might modify another
program, the data of another program, or even
the operating system itself
A properly designed operating system must ensure
that an incorrect (or malicious) program cannot cause
other programs to execute incorrectly

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

running user code or kernel code


 Mode bit: kernel (0), user (1)
 When the computer system is executing on behalf
of a user application, the system is in user mode
 When the computer system is executing the OS
code, then the system is in kernel mode

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

designated as privileged instructions


 Hardware allows privileged instructions to be

executed in only kernel mode


 If an attempt is made to execute a privileged

instruction in user mode, the hardware does not


execute the instruction but rather treats it as illegal
and traps it to the operating system
 Example: instruction to switch to kernel mode, I/O

control, timer management, and interrupt


management
01/24/2024 49
System Calls
Means for a user program to ask the operating system
to perform tasks reserved for the operating system on
the user program’s behalf
Interface to the services provided by the OS
Written in ALP or in a high-level language (C or C++)

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

 parameters that are passed to each function

 the return values the programmer can expect

 APIs are implemented as libraries

 Example libc (standard C language library) is provided

for programs in C language


 APIs invoke the actual system call

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 system call routine


The system call interface
 Intercepts the function calls in the API

 Invokes the intended system call in OS kernel

 Returns status of the system call and any return values

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

result of the call


01/24/2024 53
API – System Call – OS Relationship

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

 In some cases, may be more parameters than


registers
 Parameters stored in a block , or table, in memory, and

address of block passed as a parameter in a register


 This approach taken by Linux and Solaris
 Parameters placed, or pushed, onto the stack by the

program and popped off the stack by the operating


system

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

You might also like