CS代写 Basic Concepts, Processes, Computer System Organisation

Basic Concepts, Processes, Computer System Organisation

What is an Operating System?

Copyright By PowCoder代写 加微信 powcoder

There is no universally accepted definition for what an operating system is:
• The most fundamental piece of software that acts as an intermediary between a user of a computer and the computer hardware
• A systems program which controls all the computer’s resources and provides a base upon which application programs can be written
Operating systems have two main functions:
1. providing abstractions to user programs (top-down view)
2. managing the computer’s resources (bottom-up view)
The job of the OS is to create good abstractions of hardware resources, then implement and manage those abstractions.

Computer Systems
A computer system can be roughly described as the following four components:
1. Hardware – provides basic computing resources (CPU, memory, I/O devices, chips, etc.).
2. Operating system – controls and coordinates the use of the hardware among the various application programs for the various users.
3. Applicationprograms-definethewaysinwhich the system resources are used to solve the computing problems of the users (compilers, database systems, video games, web browsers, business programs).
4. Users-people,machines,othercomputers.

Computer Systems
Operating System
Computer Hardware
The operating system sits between the bare hardware and all other software that runs on the computer.
Kernel mode

Operating Systems as an Extended Machine
Top‐down view
Modern computer architectures (instruction set, memory, IO, buses) are very awkward to program directly.
A book (Anderson, 2007) describing how to interface with a SATA disk ran over 450 pages.
Putting the burden on the programmers to learn all the nitty-gritty of interfacing with a single type of hard disk is clearly unrealistic. There are so many other devices to write programs for.
Disk controller SATA disk driver (hardware) (device driver)
(hardware)
OS simplifies the task of controlling I/O devices by providing pieces of software called device drivers.
(e.g. a SATA disk driver that deals with the hardware and provides ANDERSON, D.: SATA Storage Technology: Serial ATA, Mindshare, 2007.
an interface to read and write disk blocks).

Operating Systems as an Extended Machine
Top‐down view
Layers of abstraction
Disk controller
abstraction
abstraction
(hardware)
(hardware)
(device driver)
• Even this interface for reading and writing disk blocks is too low-level for most applications, so operating systems provide a high-level abstraction (i.e. files).
disk driver
photo html
• Files: using this abstraction, programs can create, read and write files without having to deal with any of the messy details of how the hardware works and where the files are actually stored on disk.

Operating Systems as a Resource Manager
Bottom‐up view
• Another (bottom-up) view of an operating system is a that of a resource manager that manages all of the pieces of the system.
• The job of the operating system is to allocate the resources (processors, memory, I/O devices, etc) to the different processes that want them.
• Most modern operating systems run multiple programs at once and so access to shared resources must be managed and scheduled.

Operating Systems as a Resource Manager
Bottom‐up view
What happens when there are simultaneous printer access requests?
print print
System bus USB controller
Process Process Process 123
Disk controller Disks
connections are only an abstraction (more complicated in practice).

Operating Systems as a Resource Manager
Bottom‐up view
Essentially every modern computer is actually performing many tasks at once. Operating systems will often start many different processes (unknown to the user).
Some of these processes may run in the background, checking for incoming emails or updating antivirus definitions and other operating system upgrades.
Processes on my computer while making these slides

Operating Systems as a Resource Manager
Bottom‐up view
In a multiprocessing system, the CPU will switch back and forth from one process to another very quickly running each process for tens or hundreds of milliseconds.
On single-core machines this is sometimes called pseudo- parallelism because it gives the illusion that many processes are all executing at once (in reality the CPU only executes one at a time).
On a multi-core/processor machine this is true parallelism as the multiple cores will actually be executing multiple processes at the same time.

What is a process?
connections are only an abstraction (more complicated in practice). • A program by itself is not a process; it is a passive entity, such as a file
containing a list of instructions stored on disk (i.e. executable file).
• A program becomes a process when an executable file is loaded into
• a process is a program in execution; an active entity. The status of the current activity of a process is represented by the value of the program counter and the contents of the processor’s registers.

Each process is allocated a portion of memory (user space) when run.
dynamic size
fixed size
Inside main memory (user space) Layout of a process in memory:
connections are only an abstraction (more complicated in practice).
1. Text section—the executable code (in machine language)
2. Data section—global variables
3. Heap section—memory that is dynamically allocated during program
4. Stack section—temporary data storage when invoking functions (such
as function parameters, return addresses, and local variables)

Process State
As a process executes, it transitions through several different states:
1. New-theprocessisbeingcreated
2. Running-instructionsarebeingexecutedontheCPU
3. Waiting-theprocessiswaitingforanevent(I/Oorsignal)
4. Ready-theprocessisreadyforexecutionandiswaiting
to be assigned to a processor
5. Terminated – the process has completed
Many processes may be ready and waiting, but only one process can be running on any processor core at any instant.

Process State
Sequence of State Transitions
The transitions between the different process states are shown below:
Process state diagram.

The OS uses a special data structure to manage multiple processes in memory

Process Control Block (PCB)
Each process is managed by OS by creating and maintaining a PCB for that process.
When a process is created (initialized or installed), the operating system creates a corresponding Process Control Block (PCB), in an area of memory that is protected from normal process access (kernel space).
The PCB is a data structure that stores all the important information about the process.
It serves as the repository for all the data needed to start, or restart, a process, along with some accounting data.
connections are only an abstraction (more complicated in practice).

Process Control Block (PCB)
Each process is stored in the operating system as a Process Control Block which stores all the important information about the process’s state.
PCB includes:
1. Process state – new, ready, running, waiting, terminated
2. Program counter – the address of the next instruction
to be executed for this process.
3. Registers-thevalueofthegeneralandspecial
registers.
∗ special registers include stack pointers, index registers, accumulators.

Process Control Block (PCB)
4. SchedulingInformation-processpriority,pointersto scheduling queues, and other scheduling parameters
5. MemoryManagementInformation-base&limit registers, page tables, or segment tables (depending on the memory system used by the OS)
6. AccountingInformation-CPUandreal-timeused,time limits, process numbers, etc.
7. I/O Status Information – list of I/O devices allocated to process, list of open files, etc.

Computer System Organisation

Computer System Organisation
Typical Computer System (abstract representation)
Memory controller
connections are only an abstraction (more complicated in practice).
A modern general-purpose computer system is comprised of CPU(s), device controllers, system bus, main memory and I/O devices.
I/O Devices – generally have two parts: Device and Device Controller
System bus – main communications path that connects the CPU, main memory and device controllers

Computer System Organisation
I/O Devices, Device Controller, Device Driver
Local buffer storage
Set of special‐purpose registers
Device controller
e.g. disk controller, USB controller, graphics adapter, etc.
Device controller is in charge of a specific type of device (e.g disk, graphics device) • Maintains some local buffer storage and a set of special-purpose
registers.
• Moves data between peripheral device and its local buffer storage.
Device driver – software in charge of a specific device controller (typically supplied by device controller manufacturers
• Sends commands to the device controller by loading the appropriate registers in the device controller
• provides the OS with a uniform interface to the device.
Memory controller

Control Unit
Computer System Organisation
Typical Computer System
Bus interface
• The CPU and device controllers can execute in parallel, competing for memory cycles.
• A memory controller synchronises the CPU and device controllers’ access to memory
CPU (Central Processing Unit) – brain of the computer
• Each CPU has a specific set of instructions that it can execute. (i.e. an x86
processor cannot execute ARM programs, and vice-versa)
• The basic cycle of a CPU is to fetch an instruction from memory, decode it,
execute it and then continue onto the next instruction.
Memory controller
instruction

Control Unit
Computer System Organisation
CPU (Central Processing Unit)
Bus interface
CPU – brain of the computer
• Accessing memory is slower than executing an instruction; thus, CPUs contain registers to store key variables and results as well as special registers for things such as the program counter and the stack pointer.
o Program counter – contains the memory address of the next instruction to be fetched. o Stack – a section of process memory; it contains one frame for each procedure that
has been entered but not yet exited.
o A procedure’s stack frame holds those input parameters, local variables, and temporary variables that are not kept in registers
o Stack pointer – top of the current stack in memory
Memory controller

Program Status Word (PSW) – is a register that contains control bits such as the CPU priority, mode (user/kernel), etc. User programs can read the PSW but can only write to certain bits. PSW is essential in making system calls and I/O operations.
When time multiplexing the CPU, the operating system will often stop the running program to (re)start another one. Every time it stops a running program, the operating system must save all the registers so they can be restored when the program runs later.
Control Unit
Computer System Organisation
CPU (Central Processing Unit)
Bus interface
Memory controller

Modern CPUs have long abandoned the fetch-decode-execute cycle; they now use pipelines to process the fetch, decode and execute operations simultaneously, allowing for more than one instruction to be executed simultaneously. Long pipelines are now common.
Control Unit
Computer System Organisation
CPU (Central Processing Unit)
Bus interface
e.g. While the CPU is executing instruction n, it could also be decoding instruction n + 1 and fetching instruction n + 2
Memory controller

Components:
Control Unit
Computer System Organisation
CPU (Central Processing Unit)
Bus interface
• MMU (Memory Management Unit) maps logical memory address to physical memory (virtual memory scheme), allowing programs to utilise memory that is bigger than the available physical memory.
• ALU (Arithmetic Logic Unit) performs numerical calculations and comparative logic
• Control Unit – coordinates activities of other CPU components during program
• Registers, Cache – store CPU data, addresses and instructions; fast storage
• Bus interface – supervises data transfers between the CPU and I/O devices
Later in the course, we will study virtual memory in detail.
Memory controller

Multicore CPU
Computer System Organisation
Most CPUs now also have multiple cores which act as independent CPUs.
Most CPUs have 4-8 cores but top end CPUs have 64 cores. In 2023 we expect the release of a 128-core CPU (AMD Bergamo)!

Modern CPUs now have multiple cores which act as independent CPUs. Typically, they are set-up as a system using symmetric multiprocessing (SMP).
Multicore CPU
Computer System Organisation
The CPU core is the component that executes instructions and registers for storing data locally.
Core, processor, or CPU core refers to the same thing.
Symmetric multiprocessing (SMP)
• Each peer CPU processor performs all tasks (i.e. OS functions, user processes)
• Each core has its own register set, as well as its own local cache (L1).
• There is also an L2 cache is local to the chip, but is shared by the two processing cores. L1 is smaller but faster than L2.
• All processors share physical memory over the system bus.
• Limitations: If too many CPUs are added, the contention for the system bus becomes
a bottleneck and performance begins to degrade.

Computer System CPU with Non‐Uniform Memory Access (NUMA)
• Each CPU (or group of CPUs) has its own local memory that is accessed via a small, fast local bus.
• In addition, the CPUs are connected by a shared system interconnect, so that all CPUs share one physical address space.
Advantage: when a CPU accesses its local memory, not only is it fast, but there is also no contention over the system interconnect
Potential drawback: This system will experience increased latency when a CPU must access remote memory across the system interconnect, creating a possible performance penalty.
(e.g. CPU0 has slower access to the local memory of CPU3)
https://www.amd.com/system/files/2018‐03/AMD‐Optimizes‐EPYC‐Memory‐With‐NUMA.pdf

Computer System CPU (with NUMA)
Most CPUs have 4-8 cores but top end CPUs have 64 cores (AMD Ryzen). In 2023 we expect the release of a 128-core CPU (AMD
https://www.anandtech.com/show/17055/amd‐gives‐details‐on‐epyc‐zen4‐genoa‐and‐bergamo‐up‐to‐96‐and‐128‐cores
AMD Multicore CPU with NUMA technology, containing 32 cores

Computer System Organisation
Memory is another major component for any computer. Ideal memory would be fast enough that the CPU is not held up by memory, abundantly large and very cheap.
Unfortunately no such memory exists and a different approach must be taken, usually memory is usually broken down into a set of layers with smaller, higher- speed and more expensive memory areas at the top with larger, slower and cheaper layers at the bottom.

Computer System Organisation
Memory ‐ Registers
Typical memory hierarchy (numbers are very approximate).
• internal to the CPU (as fast as the CPU).
• storage capacity depends on the size of the register (i.e. a 64-bit CPU has 64×64 bits (less than 1 KB)

Computer System Organisation
Memory – Cache
Cache – typically stored inside or very close to the CPU, may have several separate levels of cache (L1, L2, L3).
When a program needs to read a memory word, it checks the cache first, On a cache hit the value is read from the cache, but on a cache miss (value not found in cache) it must be read from main memory (or a lower level of cache).
CPUs with multiple cores have levels of cache that may be shared or unique to different cores.
These cache structures require cache coherence protocols to ensure they are consistent (or coherent).
Word ‐ A unit made up of one or more bytes. For example, a computer that has 64‐bit registers and 64‐bit memory addressing typically has 64‐bit (8‐byte) words.
Cache miss
Memory controller
System bus

Computer System Organisation
Memory – RAM
Main memory, usually called Random Access Memory (RAM)
• workhorse of the memory system
• provides storage in the region of gigabytes of data.
• volatile memory – its contents is lost when the power is switched off.
Computers also have small areas of non-volatile memory that maintain their contents when the power is lost:
1. Read-Only Memory (ROM) – used by some computers to store the bootstrap loader; I/O card use it to store programs for for low-level device control; factory programmed)
2. Electrically Erasable Programmable ROM (EEPROM) – non-volatile but re-writable; writing operation is orders of magnitude slower than RAM; usage is similar as ROM; typically used by microcontrollers for smart cards and remote keyless systems.

Computer System Organisation
Memory – RAM
3. Flash RAM is a type of EEPROM, non-volatile memory. It is typically used for firmware, to store the BIOS of a computer, allowing the OS to perform BIOS updates
4. CMOS (Complementary Metal-Oxide-Semiconductor) is actually volatile memory but uses so little power that a small battery is enough to power it for several years. Typically used in a computer to hold configuration parameters, such as boot sequence, time and date.
Terminologies
Bootstrap loader ‐ a computer program typically stored in ROM that is responsible
for booting a computer; It performs hardware initialisation and loads the kernel.
Kernel ‐ the operating system component running on the computer at all times after system boot.
BIOS (Basic Input Output System) – a program stored in a Flash RAM that contains low‐level I/O software (e.g. procedures for reading the keyboard, writing to the screen, I/O operations, etc).

Computer System Organisation
Memory – Hard Disks
Hard disks
• used as the primary storage system
• disk storage is much cheaper (per byte) than RAM but also comes with much slower access times.
• Slow because hard disks are electro-mechanical devices that store data on magnetic disks.

Computer System Organisation
Memory – Hard Disks
Hard disks (main parts)
• A disk consists of one or more metal platters that rotate.
• An actuator arm pivots over the platters from a corner
• Information is written onto the disk in a series of concentric circles.
• Attached to the arm are read and write heads; each disk platter has its own head
• At any given arm position, heads can read an annular region called a track.
• A sector is a subdivision of a track on a magnetic disk
• All tracks for a given arm position form a cylinder
https://blogs.umass.edu/Techbytes/2017/04/04/hard‐drives‐how‐do‐they‐work/

Computer System Organisation
Memory – Hard Disks
Hard disks
• Modern HDDs have a sector size of 4096 bytes or 32768 bits.
• Each bit’s magnetic charge translates to a binary 1 or 0 of data.
• The sectors are read/written by moving a head to the correct track on the disk (5- 10 msec) and then waiting until the disk rotates to the correct sector (5-10 msec).
https://blogs.umass.edu/Techbytes/2017/04/04/hard‐drives‐how‐do‐they‐work/

Computer System Organisation
Memory – Solid State Drives
Solid state drives – SSDs are not disks, they have no moving parts and do not contain any disks. Instead they store data in flash memory which is not lost when power is lost.
SSDs have the advantage that they do not have seek times like a hard disk but flash memory does suffer from wear and can become unreliable after a certain number of writes.
SSD controllers will attempt to even out the wear of different se

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com