Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Chapter 1(lecture 1,2) Operating System by Ihap El-galaly

What is an Operating System?


 A program that acts as an intermediary between a user of a
computer and the computer hardware.
 It simply provides an environment within which other programs can
do useful work.
Operating system goals:
 Execute user programs and make solving user problems easier.
 Make the computer system convenient to use.
 Use the computer hardware in an efficient manner.
Computer System Structure
Hardware – provides basic computing resources: Central Processing
Unit (CPU), memory, Input/Output (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:
•Users: People, machines, other computers.

What Operating Systems Do?


User view: The user’s view of the computer varies according to the
interface being used.
Users want convenience, ease of use and good performance.
•Don’t care about resource utilization.
System view: From the computer’s point of view, the operating system
is the program most intimately involved with the hardware.
OS is a resource allocator making efficient use of hardware (HW) .
OS is a control program for managing execution of user programs
and controlling the various I/O devices to prevent errors and improper
use of the computer.
Operating System Definition
No universally accepted definition of what is part of the operating
system.
“The one program running at all times on the computer” is the kernel,
part of the operating system.
Computer System Organization

 One or more CPUs, device controllers connect through common


bus providing access to shared memory.
 A computer system contains many I/O devices and their respective
controllers
 I/O devices and the CPU can execute concurrently.
 Each device controller is in charge of a particular device type.
 Each device controller has a local buffer and a set of special-
purpose registers.
 I/O is from the device to local buffer of controller. The controller
moves the data between its controlled device(s) and its buffer.
 CPU moves data from/to main memory to/from local buffers.
 Each device controller type has an operating system device driver
to manage it.
 The device driver manages I/O and provides uniform interface
between the device controller and kernel.
Interacting with Device Controllers
When interacting with a device controller, the CPU can wait for a
response by polling the status register(s) (i.e. by periodically checking
whether the status of the device has changed).
Problem with polling: The CPU is busy waiting for some event to
happen. CPU utilization will be low.
Solution: Interrupts.
Device controller informs CPU that it has finished its operation by
causing an interrupt (i.e. alert the CPU to events that require attention).
Interrupt transfers control to the interrupt service routine generally,
through the interrupt vector, which contains the addresses of all the
service routines.
Interrupt architecture must save the address of the interrupted
instruction.
Software Interrupts
An operating system is interrupt driven.
Events are almost always signaled by the occurrence of an interrupt.
A trap (or exception) is a software-generated interrupt
A specific request from a user program that an operating-system
service be performed by executing a special operation called a system
call.
The operating system preserves the state of the CPU by storing the
registers and the program counter.
Interrupts are used by devices for asynchronous event notification
(these are hardware interrupts).
Device controller informs CPU that it has finished its operation by
causing an interrupt.
Direct Memory Access (DMA)
CPU utilization can be improved even further by allowing a device
controller to transfer data from/to main memory without any
involvement of the CPU.
This is called direct memory access and is used by all modern hard
drives (but also sound controllers, network cards, etc.).
Device controller transfers blocks of data from buffer storage directly
to main memory without CPU intervention.
Only one interrupt is generated per block, rather than the one interrupt
per byte.

With my Best wishes 2022 Eng Ihap EL-Galaly 01062665758 3


Storage Structure

Primary storage: registers, cache memory, and main memory.


Main memory – only large storage media that the CPU can access
directly.
•Random access and typically volatile.
•Typically random-access memory (RAM) in the form of Dynamic
Random-access Memory (DRAM).
The programs and data cannot reside in main memory permanently on
most systems for two reasons:
•Main memory is usually too small to store all needed programs and
data permanently.
•Main memory is volatile—it loses its contents when power is turned
off.
Secondary storage – extension of main memory that provides large
nonvolatile storage capacity.
•Secondary storage is also much slower than main memory.
Hard Disk Drives (HDD) – rigid metal or glass platters covered with
magnetic recording material:
•Disk surface is logically divided into tracks, which are subdivided into
sectors.
•The disk controller determines the logical interaction between the
device and the computer.
Non-volatile memory (NVM) devices– faster than hard disks,
nonvolatile.
Tertiary storage: magnetic tapes, CD-ROM, etc.
•They are slow enough and large enough that they are used only for
special purposes:
Store backup copies of material stored on other devices.
Storage systems organized in hierarchy:
•Speed access time
•Size storage capacity
•Cost
•Volatility storage systems are either volatile or nonvolatile
Caching – copying information into faster storage system; main
memory can be viewed as a cache for secondary storage.

With my Best wishes 2022 Eng Ihap EL-Galaly 01062665758 5


Chapter 1(lecture 3) Operating System by Ihap El-galaly
Computer System Architecture: according to the number of general-
purpose processors used
 Single-Processor Systems.
 Multiprocessor Systems.
 Clustered Systems.
The core is the component that executes instructions and registers for
storing data locally.
The one main CPU with its core is capable of executing a general-
purpose instruction set, including instructions from processes.
Single-Core CPU Chip
An arithmetic-logic unit (ALU) is the part of a computer processor
(CPU) that carries out arithmetic and logic operations.

•All of these special-purpose processors run a limited instruction set


and do not run processes.

Multiprocessor Systems
Multiprocessor Systems: Have two (or more) processors, each with
a single-core CPU. Example from mobile devices to servers.
Multiprocessors systems growing in use and importance:
•Also known as parallel systems, tightly-coupled systems.
Advantages of Multiprocessor Systems
1.Increased throughput: By increasing the number of processors, we
expect to get more work done in less time (i.e. gets more jobs done).
2.Economy of scale: Multiprocessor systems can cost less than
equivalent multiple single-processor systems, because they can share
peripherals, mass storage, and power supplies.
3.Increased reliability: graceful degradation or fault tolerance (i.e. the
failure of one processor will not halt the whole system).
Two Types of Multiprocessor Systems:
Asymmetric Multiprocessing: each processor is assigned a specific
task.
•A master–slave relationship.
•A master processor controls the system: schedules and allocates work
to the slave processors.
Symmetric Multiprocessing (SMP): each processor performs all tasks
(including OS functions and user processes).
•The most common systems.
•All processors are peers; no master–slave relationship exists between
processors.
Each CPU processor has its own set of registers and a private or local
cache.
All processors share physical memory over the system bus.

Multicore systems: Multiple computing cores reside on a single chip.


•These systems can be more efficient than multiple chips with single
cores
A multicore processor with N cores appears to the operating system as
N standard CPUs.
Dual-Core Design
A dual-core design with two cores on the same processor chip:
•Each core has its own register set, as well as its own local cache, often
known as a level 1, or L1, cache.
•A level 2 (L2) cache is local to the chip but is shared by the two
processing cores.
Non-Uniform Memory Access (NUMA) System
CPUs are connected by a shared system interconnect, so that all CPUs
share one physical address space.
The advantage:
•Fast access of a CPU to its local memory with no contention over the
system interconnect.
•So, NUMA systems can scale more effectively as more processors are
added.
The drawback:
•Increased latency when a CPU accesses remote memory across the
system interconnect (slowing down performance).

Clustered Systems
Like multiprocessor systems, but multiple systems working together:
•A cluster consists of several computer systems (nodes) connected via
a network; each node is typically a multicore system.
•These systems are considered loosely coupled.
•Some clusters are for high-performance computing (HPC)
Usually sharing storage via a storage-area network (SAN).
Some clustered systems have distributed lock manager (DLM) to
avoid conflicting operations.
Advantages of Clustered Systems
Provides a high-availability service which survives failures.
•The service will continue even if one or more systems in the cluster fail.
High availability provides increased reliability, which is crucial in many
applications.
•Asymmetric clustering.
One machine is in hot-standby mode while the other is running the
applications.
•Symmetric clustering.
Two or more hosts (nodes) are running applications and are monitoring
each other.
Computer System Operations
For a computer to start running-for instance, when it is powered up or
rebooted, it needs to have an initial program to run.
This initial program, or bootstrap program. (Very simple program)
•It is stored in read-only memory (ROM) or electrically erasable
programmable read-only memory (EEPROM), the computer hardware.
•It initializes all aspects of the system, from CPU registers to
device controllers to memory contents.
The bootstrap program must know how to load the operating
system and to start executing that system.
•To accomplish this goal, the bootstrap program must locate and load
into memory the operating system kernel.
Kernel is interrupt driven (i.e. hardware and software interrupts):
•Hardware interrupt by one of the devices.
•Software interrupt (exception or trap):
Software error (e.g. division by zero or invalid memory access).
Request for operating system service – system call.

Multiprogramming (Batch system)


In a multiprogramming system, a program in execution is termed a
process.
Multiprogramming organizes jobs (code and data) so CPU always has
one to execute.
•A subset of total jobs in system is kept in memory.
•One job selected and run via job scheduling.
•When job has to wait (for I/O for example), OS switches to another job.
Advantages:
•Increasing CPU utilization as well as keeping users satisfied.
The OS keeps several processes in memory simultaneously.
The OS picks and begins to execute one of these processes.
The process may have to wait for some task, such as an I/O operation,
to complete.
•In a non-multiprogrammed system, the CPU would sit idle.
•In a multiprogrammed system, the operating system simply switches
to, and executes, another process.
When that process needs to wait, the CPU switches to another
process.

With my Best wishes 2022 Eng Ihap EL-Galaly 01062665758 9


Chapter 1(lecture 4) Operating System by Ihap El-galaly
Multitasking (Timesharing)
the CPU switches jobs so frequently that users can interact with each
job while it is running, creating interactive computing.
•Response time should be < 1 second.
•Each user has at least one program executing in memory
process.
•If several jobs ready to run at the same time CPU scheduling.
•If processes don’t fit in memory, swapping moves them in and out to
run.
When a process executes, it typically executes for only a short time
before it either finishes or needs to perform I/O.
I/O may be interactive; that is, output goes to a display for the user,
and input comes from a user keyboard, mouse, or touch screen.
Rather than let the CPU sit idle as this interactive input takes place,
the operating system will rapidly switch the CPU to another process.
Having several processes in memory at the same time requires some
form of memory management.
In a multitasking system, the operating system must ensure
reasonable response time.
Virtual memory allows execution of processes not completely in
memory.
•The main advantage is that it enables users to run programs that are
larger than actual physical memory.

Dual-mode Operation
Dual-mode operation allows OS to protect itself and other system
components: User mode and kernel mode (also called supervisor
mode, system mode, or privileged mode).
Mode bit provided by hardware:
•Provides ability to distinguish when system is running user code or
kernel code.
•When a user code is running mode bit = 1 is “user”.
•When a kernel code is executing mode bit = 0 is “kernel”.
A user application requests a service from the operating system via a
system call.
Some instructions designated as privileged, only executable in kernel
mode.

With my Best wishes 2022 Eng Ihap EL-Galaly 01062665758 10


At system boot time, the hardware starts in kernel mode.
The OS is then loaded and starts user applications in user mode.
Whenever a trap or interrupt occurs, the hardware switches from user
mode to kernel mode (that is, changes the state of the mode bit to 0).
When control is given to a user application, the mode is set to user
mode.
Eventually, control is switched back to the operating system via an
interrupt, a trap, or a system call.

Timer
We must ensure that the operating system maintains control over the
CPU.
To accomplish this goal, we can use a timer.
Before turning over control to the user, the operating system ensures
that the timer is set to interrupt.
If the timer interrupts, control transfers automatically to the operating
system.
Timer to prevent infinite loop (or process hogging resources)
Timer is set to interrupt the computer after some time period.
Keep a counter that is decremented by the physical clock.
When counter zero generate an interrupt.
Review: Different Types of Interrupts
I/O completion interrupt
Timer interrupt
Exception
System call
Process Management
A process is a program in execution. It is a unit of work within the
system.
•Program is a passive entity.
•Process is an active entity.
Process termination requires reclaim of any reusable resources.
Single-threaded process has one program counter specifying location
of next instruction to execute.
Multi-threaded process has one program counter per thread.
Process Management Activities
•Creating and deleting both user and system processes.
•Scheduling processes and threads on the CPUs.
•Suspending and resuming processes.
•Providing mechanisms for process synchronization.
•Providing mechanisms for process communication.
•Providing mechanisms for deadlock handling.
Memory Management
To execute a program:
•All (or part) of the instructions must be in memory.
•All (or part) of the data that is needed by the program must be in
memory.
Memory management determines what is in memory and when.
the program terminates, its memory space is declared available, and
the next program can be loaded and executed.
Memory Management Activities
•Keeping track of which parts of memory are currently being used and
which process is using them.
•Deciding which processes (or parts of processes) and data to move
into and out of memory.
•Allocating and deallocating memory space as needed.
File-system Management
•Abstracts physical properties to logical storage unit - file.
File-System management:
•Files usually organized into directories.
•Access control on most systems to determine who can access what
•OS activities include:
Creating and deleting files and directories.
Primitives to manipulate files and directories.
Mapping files onto secondary storage.
Backup files onto stable (non-volatile) storage media.
With my Best wishes 2022 Eng Ihap EL-Galaly 01062665758 12
Mass-Storage Management
Usually disks used to store data that does not fit in main memory or
data that must be kept for a “long” period of time.
Entire speed of computer operation hinges on disk subsystem and its
algorithms.
OS activities:
•Mounting and unmounting
•Free-space management
•Storage allocation
•Disk scheduling
•Partitioning
•Protection
Mounting a file system is making the file system available for use by
the system and its users.
Cache Management
Caching is an important principle, performed at many levels in a
computer (in hardware, operating system, software).
Information in use copied from slower to faster storage temporarily.
Faster storage (cache) checked first to determine if information
Movement between levels of storage hierarchy can be explicit or
implicit.

 Which of the following instructions should be privileged?


a.Set value of timer.
b.Read the clock.
c.Clear memory.
d.Issue a trap instruction.
e.Turn off interrupts.
f.Modify entries in device-status table.
g.Access I/O device.

True and false : OS is a resource manager(true)

With my Best wishes 2022 Eng Ihap EL-Galaly 01062665758 13

You might also like