Unit 1 Os
Unit 1 Os
The CPU is given instructions and data through programs. The CPU then
fetches the program and data from the memory and performs arithmetic
and logic operations as per the given instructions and stores the result back
to memory.
While processing, the CPU stores the data as well as instructions in its local
memory called registers. Registers are part of the CPU chip and they are
limited in size and number. Different registers are used for storing data,
instructions or intermediate results.
Other than the registers, the CPU has two main components — Arithmetic
Logic Unit (ALU) and Control Unit (CU). ALU performs all the arithmetic and
logic operations that need to be done as per the instruction in a program.
CU controls sequential instruction execution interprets instructions and
guides data flow through the computer‘s memory, ALU and input or output
devices. CPU is also popularly known as microprocessor.
Control Unit: It is the circuitry in the control unit, which makes use of
electrical signals to instruct the computer system for executing already
stored instructions. It takes instructions from memory and then decodes
and executes these instructions. So, it controls and coordinates the
functioning of all parts of the computer. The Control Unit's main task is to
maintain and regulate the flow of information across the processor. It does
not take part in processing and storing data.
ALU: It is the arithmetic logic unit, which performs arithmetic and logical
functions. Arithmetic functions include addition, subtraction, multiplication
division, and comparisons. Logical functions mainly include selecting,
comparing, and merging the data.
Software
1) System Software
The system software is the main software that runs the computer. When you
turn on the computer, it activates the hardware and controls and
coordinates their functioning. The application programs are also controlled
by system software. An operating system is an example of system software.
i) Operating System:
2) Application Software:
Computer Memory
The computer memory holds the data and instructions needed to process
raw data and produce output. The computer memory is divided into large
number of small parts known as cells. Each cell has a unique address which
varies from 0 to memory size minus one.
Computer memory is of two types: Volatile (RAM) and Non-volatile (ROM). The
secondary memory (hard disk) is referred as storage not memory.
o Register memory
o Cache memory
o Primary memory
o Secondary memory
Register Memory
Registers hold a small amount of data around 32 bits to 64 bits. The speed
of a CPU depends on the number and size (no. of bits) of registers that are
built into the CPU. Registers can be of different types based on their uses.
Some of the widely used Registers include Accumulator or AC, Data Register
or DR, the Address Register or AR, Program Counter (PC), I/O Address
Register, and more.
Cache Memory
Cache memory can only be accessed by CPU. It can be a reserved part of the
main memory or a storage device outside the CPU. It holds the data and
programs which are frequently used by the CPU. So, it makes sure that the
data is instantly available for CPU whenever the CPU needs this data. In
other words, if the CPU finds the required data or instructions in the cache
memory, it doesn't need to access the primary memory (RAM). Thus, by
acting as a buffer between RAM and CPU, it speeds up the system
performance.
L1: It is the first level of cache memory, which is called Level 1 cache or L1
cache. In this type of cache memory, a small amount of memory is present
inside the CPU itself. If a CPU has four cores (quad core cpu), then each core
will have its own level 1 cache. As this memory is present in the CPU, it can
work at the same speed as of the CPU. The size of this memory ranges from
2KB to 64 KB. The L1 cache further has two types of caches: Instruction
cache, which stores instructions required by the CPU, and the data cache
that stores the data required by the CPU.
L2: This cache is known as Level 2 cache or L2 cache. This level 2 cache
may be inside the CPU or outside the CPU. All the cores of a CPU can have
their own separate level 2 cache, or they can share one L2 cache among
themselves. In case it is outside the CPU, it is connected with the CPU with
a very high-speed bus. The memory size of this cache is in the range of 256
KB to the 512 KB. In terms of speed, they are slower than the L1 cache.
L3: It is known as Level 3 cache or L3 cache. This cache is not present in all
the processors; some high-end processors may have this type of cache. This
cache is used to enhance the performance of Level 1 and Level 2 cache. It is
located outside the CPU and is shared by all the cores of a CPU. Its memory
size ranges from 1 MB to 8 MB. Although it is slower than L1 and L2 cache,
it is faster than Random Access Memory (RAM).
When CPU needs the data, first of all, it looks inside the L1 cache. If it does
not find anything in L1, it looks inside the L2 cache. If again, it does not find
the data in L2 cache, it looks into the L3 cache. If data is found in the cache
memory, then it is known as a cache hit. On the contrary, if data is not
found inside the cache, it is called a cache miss.
If data is not available in any of the cache memories, it looks inside the
Random Access Memory (RAM). If RAM also does not have the data, then it
will get that data from the Hard Disk Drive.
So, when a computer is started for the first time, or an application is opened
for the first time, data is not available in cache memory or in RAM. In this
case, the CPU gets the data directly from the hard disk drive. Thereafter,
when you start your computer or open an application, CPU can get that data
from cache memory or RAM.
Memory Units
Memory units are used to measure and represent data. Some of the
commonly used memory units are:
As the CPU interacts directly with main memory, any data entered from
input device or the data to be accessed from hard disk needs to be placed in
the main memory for further processing. The data is then transferred
between CPU and main memory using bus.
The CPU places on the address bus, the address of the main memory
location from which it wants to read data or to write data. While executing
the instructions, the CPU specifies the read or write control signal through
the control bus.
As the CPU may require to read data from main memory or write data to
main memory, a data bus is bidirectional. But the control bus and address
bus are unidirectional. To write data into memory, the CPU places the data
on the data bus, which is then written to the specific address provided
through the address bus. In case of read operation, the CPU specifies the
address, and the data is placed on the data bus by a dedicated hardware,
called memory controller. The memory controller manages the flow of data
into and out of the computer's main memory.
1) uname command
2) lscpu command
3) lshw command
lshw(list hardware) is a small Linux/Unix tool which is used to generate the
detailed information of the system‘s hardware configuration from various
files in the /proc directory. lshw can also report exact memory configuration,
firmware version, mainboard configuration, CPU version and speed, cache
memory configuration, bus speed, etc on DMI-capable x86 or IA-64(Itanium
family of 64 microprocessors) system and some PowerPC machine.
4) lspci :- lspci stands for list pci. Think of this command as ―ls‖ + ―pci‖.
This will display information about all the PCI bus in your server. Apart
from displaying information about the bus, it will also display information
about all the hardware devices that are connected to your PCI and PCIe bus.
$ hwinfo [options]
[options]
$ hwinfo –help
6) lspci : lspci is a utility for displaying information about all PCI buses in
the system and all devices connected to them.
What is PCI?
PCI, or Peripheral Component Interconnect is an interface to add additional
hardware components to a computer system.
WORKING:
When a device raises an interrupt at the process, the processor first
completes the execution of an instruction. Then it loads the Program
Counter (PC) with the address of the first instruction of the ISR. Before
loading the program counter with the address, the address of the
interrupted instruction is moved to a temporary location. Therefore, after
handling the interrupt, the processor can continue with the process.
While the processor is handling the interrupts, it must inform the device
that its request has been recognized to stop sending the interrupt request
signal. Also, saving the registers so that the interrupted process can be
restored in the future increases the delay between the time an interrupt is
received and the start of the execution of the ISR. This is called Interrupt
Latency.
A single computer can perform only one computer instruction at a time. But,
because it can be interrupted, it can manage how programs or sets of
instructions will be performed. This is known as multitasking. It allows the
user to do many different things simultaneously, and the computer turns to
manage the programs that the user starts. Of course, the computer operates
at speeds that make it seem like all user tasks are being performed
simultaneously.
Types of Interrupt
Hardware interrupts can arrive asynchronously for the processor clock and
at any time during instruction execution. Consequently, all hardware
interrupt signals are conditioned by synchronizing them to the processor
clock and act only at instruction execution boundaries.
On some older systems, all interrupts went to the same location, and the OS
used specialized instruction to determine the highest priority unmasked
interrupt outstanding. On contemporary systems, there is generally a
distinct interrupt routine for each type of interrupt or each interrupts
source, often implemented as one or more interrupt vector tables. Hardware
interrupts are further classified into two types, such as:
2. Software Interrupts
When more than one device raises an interrupt request signal, additional
information is needed to decide which device to consider first. The following
methods are used to decide which device to select first,
1. Polling
In polling, the first device encountered with the IRQ bit set is to be
serviced first, and appropriate ISR is called to service the same. It is
easy to implement, but a lot of time is wasted by interrogating the IRQ
bit of all devices.
2. Vectored Interrupts
In vectored interrupts, a device requesting an interrupt identifies itself
directly by sending a special code to the processor over the bus. This
enables the processor to identify the device that generated the
interrupt. The special code can be the starting address of the ISR or
where the ISR is located in memory and is called the interrupt
vector.
3. Interrupt Nesting
In this method, the I/O device is organized in a priority structure.
Therefore, an interrupt request from a higher priority device is
recognized, whereas a lower priority device is not. The processor
accepts interrupts only from devices/processes having priority more
than it.
Processors priority is encoded in a few bits of PS (Process Status
register), and it can be changed by program instructions that write
into the PS. The processor is in supervised mode only while executing
OS routines, and it switches to user mode before executing application
programs.
Interrupt Handling
We know that the instruction cycle consists of fetch, decode, execute and
read/write functions. After every instruction cycle, the processor will check
for interrupts to be processed. If there is no interrupt in the system, it will
go for the next instruction cycle, given by the instruction register. If there is
an interrupt present, then it will trigger the interrupt handler. The handler
will stop the present instruction that is processing and save its
configuration in a register and load the program counter of the interrupt
from a location given by the interrupt vector table.
After processing the interrupt by the processor, the interrupt handler will
load the instruction and its configuration from the saved register. The
process will start its processing where it's left. This saves the old instruction
processing configuration, and loading the new interrupt configuration is also
called context switching. There are different types of interrupt handlers.
The interrupt handler is also called an interrupt service routine (ISR). The
main features of the ISR are
o Interrupts can occur at any time, and they are asynchronous, and
ISR's can call for asynchronous interrupts.
o An interrupt service mechanism can call the ISR's from multiple
sources.
o ISR's can handle both maskable and non-maskable interrupts. An
instruction in a program can disable or enable an interrupt handler
call.
o ISR at the beginning of execution will disable other devices interrupt
services. After completion of the ISR execution, it will reinitialize the
interrupt services.
o The nested interrupts are allowed in ISR for diversion to other
When an interrupt occurs, the service of the interrupt by executing the ISR
may not start immediately by context switching. The time interval between
the occurrence of interrupt and the start of execution of the ISR is called
interrupt latency.
1. Using the pointer to the current process control block, the state and
all register values are saved for use when the process is later
restarted.
2. The CPU mode bit is switched to supervisory
3. Using the pointer to the interrupt handler table and the interrupt
vector, the location of the kernel code to execute is determined. The
interrupt vector is the IRQ for hardware interrupts and an argument
to the interrupt assembly language instruction for software interrupts.
4. Processing is switched to the appropriate portion of the kernel.
The CPU uses a table and the interrupt vector to find OS the code to execute
in response to interrupts. A software interrupt is shown in the below image.
As the computer runs, processing switches between user processes and the
operating system as hardware and software interrupts are received.
Triggering Methods
1. Level-triggered
The processor samples the interrupt input signal during each instruction
cycle. The processor will recognize the interrupt request if the signal is
asserted when sampling occurs.
2. Edge-triggered
Cache Memory
Cache Memory is a special very high-speed memory. It is used to speed up
and synchronizing with high-speed CPU. Cache memory is costlier than main
memory or disk memory but economical than CPU registers. Cache memory
is an extremely fast memory type that acts as a buffer between RAM
and the CPU. It holds frequently requested data and instructions so that
they are immediately available to the CPU when needed.
Cache memory is used to reduce the average time to access data from the Main
memory. The cache is a smaller and faster memory which stores copies of
the data from frequently used main memory locations. There are various
different independent caches in a CPU, which store instructions and data.
Levels of memory:
Level 1 or Register –
It is a type of memory in which data is stored and accepted that are
immediately stored in CPU. Most commonly used register is
accumulator, Program counter, address register etc.
Level 2 or Cache memory –
It is the fastest memory which has faster access time where data is
temporarily stored for faster access.
Level 3 or Main Memory –
It is memory on which computer works currently. It is small in size and
once power is off data no longer stays in this memory.
Level 4 or Secondary Memory –
It is external memory which is not as fast as main memory but data
stays permanently in this memory.
Types of Cache –
Primary Cache –
A primary cache is always located on the processor chip. This cache is
small and its access time is comparable to that of processor registers.
Secondary Cache –
Secondary cache is placed between the primary cache and the rest of the
memory. It is referred to as the level 2 (L2) cache. Often, the Level 2
cache is also housed on the processor chip.
Locality of reference –
Since size of cache memory is less as compared to main memory. So to
check which part of main memory should be given priority and loaded in
cache is decided based on locality of reference.
Types of Locality of reference
1. Spatial Locality of reference
This says that there is a chance that element will be present in the close
proximity to the reference point and next time if again searched then
more close proximity to the point of reference.
2. Temporal Locality of reference
In this Least recently used algorithm will be used. Whenever there is
page fault occurs within a word will not only load word in main memory
but complete page fault will be loaded because spatial locality of
reference rule says that if you are referring any word next word will be
referred in its register that‘s why we load complete page table so the
complete block will be loaded.
Explanation :
The CPU initializes the DMA by sending the given information through
the data bus.
The starting address of the memory block where the data is available (to
read) or where data are to be stored (to write).
It also sends word count which is the number of words in the memory
block to be read or write.
Control to define the mode of transfer such as read or write.
A control to begin the DMA transfer.
We need a system which can act as an intermediary and manage all the
processes and resources present in the system.
An Operating System can be defined as an interface between user and
hardware. It is responsible for the execution of all the processes, Resource
Allocation, CPU management, File Management and many other tasks.