0% found this document useful (0 votes)
4 views44 pages

Understanding Computer Architecture Basics

The document provides an overview of operating systems and computer architecture, detailing the functionality of operating systems such as memory management, device management, and process management. It explains key concepts like interrupts, dual-mode operation, system calls, and the booting process, as well as the structure of computer systems including single and multiprocessor systems. Additionally, it discusses the importance of device drivers, storage structures, and the role of caches in enhancing performance.
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)
4 views44 pages

Understanding Computer Architecture Basics

The document provides an overview of operating systems and computer architecture, detailing the functionality of operating systems such as memory management, device management, and process management. It explains key concepts like interrupts, dual-mode operation, system calls, and the booting process, as well as the structure of computer systems including single and multiprocessor systems. Additionally, it discusses the importance of device drivers, storage structures, and the role of caches in enhancing performance.
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

Operating Systems

(CS3201)

Computer Architecture
Agenda
• Basic Architecture
• Computer Architecture and Computer Organization
• Interrupts
• Storage Structure
• Registers and Cache
• I/O Structure
• CPU Architecture
• Computer operation
• Dual-mode operation
• System Calls
• Booting

Operating Systems 2
Functionality of an Operating System
• Memory Management
• Device Management
• Security
• Job Scheduling
• Process Management
• File Management
• …

• How an Operating System provides this functionality depends on the


underlying Computer Organization and Architecture
Operating Systems 3
Computer Architecture and Computer
Organization
• “Computer architecture is a description of the structure of a computer
system made from component parts” – Wikipedia

• Architecture vs. Organization


• Architecture deals with functional behavior
• Organization deals with structural relationships
• 64-bit architecture vs. actual 64-bit registers

• Structure has a say in how function happens


• Example: Components communicate via System Bus
• Some texts loosely use one term to mean another
Operating Systems 4
Computer Organization
• Modern general-purpose computer system consists of one or more CPUs and
several device controllers connected through a common bus that provides access
between components and shared memory

Operating Systems 5
Computer Organization – and nomenclature
you cannot escape
• Each device controller is in charge of a specific type of device (and more than one
device, of same type, can attach to the same controller)
• A device controller maintains some local buffer storage
• The device controller is responsible for moving the data between the peripheral devices that
it controls and its local buffer storage
• Typically, operating systems have a device driver for each device controller
• Device driver understands the device controller and provides the rest of the operating system
with a uniform interface to the device
• CPU and the device controllers can execute in parallel..! (and once they are
running in parallel, it means they can simultaneously request for Memory – called
“competing for memory”)
• Memory controller comes into picture. This entity is responsible for
synchronizing (fancy word for conflict prevention) access to memory
Operating Systems 6
Sorry to interrupt this class but something
urgent is up
• Consider an I/O operation
• Step 1: Device driver loads instructions in the Device Controller’s registers
• Step 2: Suppose the instruction was ‘READ’ from Standard Input
• Step 3: The Device Controller transfers data (keystrokes) from device and saves into
local buffer
• Step 4: Read operation complete, Device Controller informs the same to Device
Driver
• Step 5: How does the Device Controller inform the Device Driver? Via an ‘interrupt’
• Step 6: The device driver raises an ‘interrupt’ to tell the CPU that the data has been
read and is now available

• But why interrupt? So that the CPU can go on performing its task instead of
waiting for I/O to complete. But how can it perform its task? By switching
to another task
Operating Systems 7
Interrupts
• Interrupt (Definition/ layman): “An interrupt is a signal emitted by a
device attached to a computer or from a program within the
computer.” – Techtarget
• Usually, this indicates that some event has occurred (either in hardware or software) that
requires the immediate attention of the CPU
• Perhaps the hardware encountered an error (power loss), user moved the mouse (CPU must save
pointer location), or the software program performed a ‘divide by 0’
• The occurrence of the event is signaled to the CPU for further processing. This signal is
an interrupt
• Types:
• Hardware Interrupt: Hardware triggers an interrupt by sending a signal to the CPU
• Software interrupt: Software triggers interrupt using traps or by executing a special operation called
System Call
Operating Systems 8
I have an interrupt on my hands, now what?
• Attend to it (“service” it)
• When CPU is interrupted, it stops what it is doing and immediately transfers
execution to a fixed location
• Fixed location usually contains starting address of the service routine for the interrupt
• Interrupt Service Routine (ISR) is a piece of code that knows how to deal with the interrupt
• Once ISR executes; on completion, the CPU resumes the interrupted computation
• Two approaches to ISR
• Generic ISR: Have a generic ISR that examines interrupt and calls specific Interrupt Service Handler
• Interrupt Vector: An array of addresses, indexed by interrupt number (type of interrupt), where each
address points to a specific Interrupt Service Handler
• The interrupt architecture must also save the state information of whatever was
interrupted
Operating Systems 9
Some crucial scenarios while handling
interrupts
1. Ability to defer interrupt handling during critical processing

2. An efficient way to dispatch to the proper interrupt handler for a


device (or type of interrupt)

3. Need for multilevel interrupts, so that the operating system can


distinguish between high- and low-priority interrupts and can
respond with the appropriate degree of urgency.

Operating Systems 10
More on interrupt implementation
• Most CPUs have two interrupt request lines
• Non maskable interrupt: Reserved for events such as unrecoverable memory errors that
need to be resolved as soon as they occur, cannot be turned off
• Maskable interrupt: Can be turned off by the CPU before the execution of critical instruction
sequences that must not be interrupted. The maskable interrupt is used by device controllers

Operating Systems 11
Interrupt vector in Intel Processors

Operating Systems 12
Storage Structure
• To execute instructions, CPU needs to load them from main memory (since it can
only access main memory)
• Therefore, any program must first be loaded into main memory (called RAM)
• RAM is volatile
• Computers use other forms of memory as well
• Electrically Erasable Programmable Read-Only Memory (EEPROM): Can hold the bootstrap program
• Secondary Storage devices: HDDs, SSDs, Optical disks (rare)
• All forms of memory provide an array of bytes
• Each byte has its own address (byte-addressable memory)
• Interaction is achieved through a sequence of load or store instructions
• load instruction moves a byte or word from main memory to an internal register of the CPU
• store instruction moves the content of a CPU register to main memory

Operating Systems 13
Storage Structure
• A typical instruction–execution cycle, as executed on a system with a von
Neumann architecture
• Step 1: Fetch an instruction from memory and stores that instruction in the instruction
register
• Step 2: Decode the instruction, this may cause operands to be fetched from memory and
stored in some internal register
• Step 3: After the instruction on the operands has been executed, the result may be stored
back in memory
• Ideally, we want the programs and data to reside in main memory permanently,
however:
1. Main memory is usually too small to store all needed programs and data permanently
2. Main memory, as mentioned, is volatile—it loses its contents when power is turned off or
otherwise lost

Operating Systems 14
Storage Structure hierarchy

Operating Systems 15
Registers and Caches
• Register: A word (one or more bytes) of memory managed by CPU
• Types
• General purpose: “AX”, “BX”, “CX” on x86
• Special purpose:
• “SP” = stack pointer
• “FP” = frame pointer
• “PC” = program counter

Operating Systems 16
Registers and Caches
• Access to main memory is (relatively) slow

• Cache: small, fast, expensive memory


• Hold recently-accessed data (D$) or instructions (I$)
• Different sizes & locations
• Types of Cache:
• Level 1 (L1) – on-chip, small
• Level 2 (L2) – on or next to chip, large (compared to L1)
• Level 3 (L3) – on bus, larger than L2

Operating Systems 17
I/O Structure
• A large portion of operating system code is dedicated to managing I/O
• This is in part because of the varying nature of the devices that connect to a
computer system
• Recall from earlier that a general-purpose computer system consists
of multiple devices, all of which exchange data via a common bus
• Recall also that device controller is responsible for moving the data
between the peripheral devices that it controls and its local buffer
storage
• Recall a typical I/O operation based on interrupts (slide 7)

Operating Systems 18
I/O Structure
• The form of interrupt-driven I/O described in slide 7 is fine for moving
small amounts of data but can produce high overhead when used for
bulk data movement

• Solution: Direct Memory Access (DMA)

• After setting up buffers, pointers, and counters for the I/O device, the
device controller transfers an entire block of data directly to or from
the device and main memory, with no intervention by the CPU

Operating Systems 19
I/O Structure

Unlike Polling and


Interrupts, in DMA, transfer
of data from devices to
memory happens without
the involvement of the CPU

Operating Systems 20
Polling versus Interrupts versus DMA

Polling: CPU asks I/O


device if it needs any
action taken on its
behalf

Operating Systems 21
Polling versus Interrupts versus DMA

Interrupt based: I/O


interrupts CPU, CPU
services the interrupt
(in this case, transfer
data to memory)

Operating Systems 22
Polling versus Interrupts versus DMA

DMA: The idea is to


access memory
directly and avoid
CPU as the middle
man.

Operating Systems 23
Computer System Architecture
• So far, we have seen the general structure of a typical computer

• The system can be organized in a number of ways, depending on the


processor architecture

• Many years ago, most computer systems used a single processor (one
CPU with a single processing core). The core is the component that
executes instructions and contains registers

Operating Systems 24
Multi-processor System
• On modern computers, from mobile devices to servers,
multiprocessor systems dominate the landscape
• Traditionally, such systems have two (or more) processors, each with
a single-core CPU
• Share the computer bus and sometimes the memory
• Increased throughput, but N processors does not necessarily lead to a
gain of N
• Overhead: Contention for shared resources; scheduling common resources

Operating Systems 25
Symmetric Multiprocessing (SMP)
• Most common multiprocessor
• Each CPU an independent entity
• Advantages:
• Independent registers and cache
• N processes can run on N CPUs
• Disadvantages:
• CPUs separate, one might work one idle
• Shared data structures can help
reduce disadvantage
• But shared DS has synchronization
overhead
Operating Systems 26
Multicore Systems

Operating Systems 27
Operating Systems 28
Some definitions

Operating Systems 29
Motherboard on a General Computer

Operating Systems 30
Computer System Operations
• OS provides environment within which programs are executed
• OSes vary, however, there are some commonalities:
• When computer is booted, it needs to have an initial program to run
(bootstrap)
• Bootstrap stored in computer hardware (firmware)
• Initializes system and loads OS (locate the kernel, load and execute it)
• Some services are provided outside of the kernel by system programs that are
loaded into memory at boot time to become system daemons (example:
‘systemd’ in Linux)
• System now ready, wait for events
• Event occurrence signaled by interrupts (or traps – nothing but software
interrupt)
• Event can also be a special request from user program by performing special
operation called System call
Operating Systems 31
Booting a System
• "Booting is the process of loading an operating system. It’s the
process that starts when we turn on the computer (using the power
button or by a software command) and ends when the operating
system is loaded into the memory."
• Steps:
• When we turn on the computer, there is no program inside the computer’s
main memory (RAM), so the CPU looks for another program, called the
BIOS (Basic Input/Output System), and runs it. The BIOS is a firmware that
is located on the motherboard and is run by the CPU to start the booting
sequence
• BIOS starts a process called POST (Power-On Self-Test) which tests all the
hardware devices and makes sure there are no issues

Operating Systems 32
Booting a System
• Steps (continued):
• After POST, the BIOS loads the MBR (Master Boot Record) from the
bootable device into RAM. The MBR consists of 512 or more bytes located
at the very beginning sector of the bootable device (which can be an HDD,
an SSD, or a flash drive)
• BIOS runs the first instruction loaded from the MBR. The first instruction is
typically the bootstrap code, aka the bootloader (see above), which is a
program written in machine code that loads the operating system into RAM
(Each operating system has its own bootloaders. For example, GNU GRUB,
LILO (Linux Loader), and rEFInd are a few popular Linux bootloaders)
• Once the OS is loaded into the memory, the OS starts running. Further, the
OS starts its own initialization (which includes loading device drivers, etc).
Finally, when the OS initialization is finished, the OS starts a shell that
displays a login prompt to the user.
Operating Systems 33
Dual-Mode operation
• Operating System (OS) and users share system resources
• OS should ensure that incorrect program (or user) should not cause
other programs and OS to behave improperly
• This protection is ensured by making sure that certain privileged
instructions (which have greater potential for harm) are performed
only by OS:
• Enabling and disabling interrupts, Using page tables, set TLB, access files
• At the very least, we need two modes of operation: user mode and
kernel mode (system / supervisor / privileged mode)
• A bit, called the mode bit, is added to the hardware of the computer
to indicate the current mode: kernel (0) or user (1)
Operating Systems 34
Dual-Mode operation: Example
• At boot time, the hardware starts in kernel mode. The operating system is then
loaded and starts user applications in user mode
• When user application is executing, the system is in user mode.
• However, when a user application requests a service from the operating system
(via a system call), the system must transition from user to kernel mode

Operating Systems 35
System Calls
• System calls are the interface provided by the OS to execute
privileged instructions (they are the interface to the various services
provided by the OS)

Operating Systems 36
System Calls
• System calls are generally available as functions written in C and C++,
although certain low-level tasks (like accessing hardware directly) are
written in Assembly language
• Consider the following command - cp [Link] [Link]
• This command (program) copies the input file [Link] to the output file [Link]
• The program must open the input file and create and open the output file.
Each of these operations requires system calls
• Possible error conditions for each system call must be handled (example: in
case file not found, output ‘File not found’ error to standard output)
• When both files are set up, we enter a loop that reads from the input file (a
system call) and writes to the output file (another system call)
• Finally, after the entire file is copied, the program may close both files (two
system calls), write a message to the console or window (more system calls),
and finally terminate normally (the final system call).
Operating Systems 37
System Calls

Operating Systems 38
System Call Types

Operating Systems 39
Standard C library and the System Call
interface
• The standard C library provides a portion of
the system-call interface for many versions of
UNIX and Linux
• As an example, let’s assume a C program
invokes the printf() statement. The C library
intercepts this call and invokes the necessary
system call (or calls) in the operating system -
in this case, write()
• Note: C library takes the value returned by
write() and passes it back to the user program
Operating Systems 40
Fork(): A popular System call
• fork() is a special and useful System call in Linux/Unix systems
• It is used by processes to create processes that are copies of
themselves
• With the help of such system calls, the child process can be created
by the parent process
• After a new child process is created, both processes will execute the
next instruction following the fork() system call.
• The new process consists of a copy of the address space of the
original process (makes parent child communication easier)

Operating Systems 41
Fork(): A popular System call
• Upon executing fork(), the different values returned by fork() are:
• Negative Value: The creation of a child process was unsuccessful
• Zero: Returned to the newly created child process
• Positive value: Returned to parent or caller. The value contains the process ID
of the newly created child process
• After a fork() system call, one of the two processes typically uses the
exec() system call to replace the process’s memory space with a new
program

Operating Systems 42
Fork(): A popular System call
• pid_t fork(void): Creates a new “child” process that is identical to the
calling “parent” process, including all state (memory, registers, etc.);
Child gets an identical (but separate) copy of the parent’s virtual
address space
• Fork is unique (and often confusing) because it is called once but
returns “twice”

Operating Systems 43
Questions / Queries / Homework
• Thank you

Operating Systems 44

You might also like