CS代写 COMP 2432 2021/2022 – cscodehelp代写

Operating Systems
Lecture 2 Interrupts and System Calls

 I/O processing

Copyright By cscodehelp代写 加微信 cscodehelp

 Interrupt processing
 OS operation
 System calls and system programs  OS types and structures
COMP 2432 2021/2022

Operating System Mechanism
CPU and make decision and arrangement to control the system. COMP 2432 2021/2022
 Operating system is the manager of a computer system.
 Remember that OS is itself a program and that a process is a
program in execution.
 So OS will present itself as one or more processes in the computer
 When there are multiple processes executing, how can the OS control and manage them?
 What will you do when you have multiple assignments due tomorrow, or there are several dishes to cook for dinner?
 You could do one after the other. When you face problem with one, you may post a discussion note to BlackBoard and switch to another.
 You need a mechanism to be notified of special events, e.g. a new note on BlackBoard, or a phone call for a discussion on a project.
 The OS relies on a special alarm system, called the interrupt processing mechanism.
 When an interrupt occurs, there is a chance for OS to grasp the

I/O Processing
 One can perform I/O when CPU is doing useful work .
 When I/O is completed, OS needs to put aside its current work and looks at I/O device for next I/O.
 The event that I/O is completed causes an interrupt.
 The suspension (interruption) of current work to handle the event is called interrupt processing.
time COMP 2432 2021/2022

I/O Processing
 Two methods for I/O processing  Synchronous
 Asynchronous
Synchronous Asynchronous
COMP 2432 2021/

I/O Processing
 Synchronous I/O
 After I/O starts, user program will wait until I/O completes.
 The program waits and do nothing until the I/O completion interrupt is received.
 At most one I/O request is outstanding at a time, no simultaneous I/O processing.
 Asynchronous I/O
 After I/O starts, user program continues to execute without
waiting for I/O to complete.
 When I/O is completed, program will receive an interrupt.
 There could be several I/O requests working together.
 Use a device-status table to store the status for each I/O device, with its type and state. COMP 2432 2021/2022

Device-Status Table
COMP 2432 2021/2022

Interrupt Processing
 An interrupt is a signal to the CPU to tell it about the occurrence of a major event.
 An error in calculation (illegal instruction, division by zero).  Completion of an I/O.
 Hardware alarm.
 User-generated event (often called a trap or signal).
 Interrupt is the mechanism the OS uses so that it could turn attention to other activities and to manage resources, because interrupt will seize the CPU.
 Non-maskable interrupt: interrupt that cannot be ignored. The CPU must handle this interrupt immediately. A non- maskable interrupt may be “over”-interrupted by another non-maskable higher priority one. COMP 2432 2021/2022
 Two types of interrupts:
 Maskable interrupt: interrupt that may be ignored or
handled later. A lower priority interrupt is maskable.

Interrupt Processing
 Depending on the cause of interrupts, we could classify them into 3 categories.
 Program interrupt:
Caused by conditions within CPU that requires attention, e.g. illegal instruction, overflow, division by zero, memory access violation, special instruction.
 Sometimes also called traps (or signals in Unix/Linux).  I/O interrupt:
Caused by I/O related events, e.g. I/O completion or device errors.
 Timer interrupt:
Caused by the hardware timer of the system to handle time-related activities.
COMP 2432 2021/2022

Interrupt Handling
 Aninterruptmeansanemergency.
 After an (non-maskable) interrupt occurs, CPU will put aside the process it is executing, by saving the program counter and register values (on a stack).
 It looks up an interrupt table, using the interrupt number as an index, for a procedure for execution.
 This procedure is called the interrupt handler, or interrupt service routine (ISR). It is executed in response to the interrupt to serve the interrupt.
Interrupt table
 CPU then jumps to interrupt handler and executes it.
 After the interrupt is serviced, the CPU resumes the suspended program and returns to the next instruction pointed to by the saved PC.
Question: why do we need a stack to store the PC and register?
Lecture 2 COMP 2432 2021/2022

Interrupt Handling
User program
It is possible that when an interrupt is being serviced, another interrupt may arrive.
If the incoming new interrupt Y has a lower priority, it will wait till the first one X completes.
If the new interrupt Y has a higher priority, it will seize the CPU from the current interrupt handler X.
Interrupt handler X
User program Interrupt handler Y
Interrupt handler X
Interrupt handler Y
COMP 2432 2021/2022

Operating System Operation
 Almost all OS are interrupt-driven.
 Without interrupt, there is no way the OS can get back the CPU from a program falling into infinite loop.
 In PC, you could break a program with and kill the task under task manager, but why?
 Upon , there is a hardware interrupt generated. The program in infinite loop will be interrupted. CPU is given to the interrupt handler (the task manager).
 You can therefore kill the task.
 In Unix, you could break a program with .
 There will be a signal (user trap) sent to the program. If there is no interrupt handler (called signal handler) in the program for this signal, the program will be terminated.
 If there is a special handler, some interesting behavior could be resulted. This is called signal processing (system programming).
when necessary (there is a special event).
COMP 2432 2021/2022
 Interrupts allow the OS to gain control of the system

Operating System Operation
 Basic interrupts are driven by hardware (often I/O devices or special interrupt pin) to the microprocessor.
 A trap is a software-generated interrupt caused either by an error or a user request.
 Software errors or software requests generate exception or trap, e.g. division by zero, request for operating system service.
 A system may want to respond to a division by zero error (e.g. Java exception) by doing something.
 Interesting things with signal programming (e.g. signal).
 In Excel 97, you can play the flight simulator game!
 Open a new blank document in Excel 97.
 Press F5. In the reference box, type in X97:L97 and press Enter.
 Press Tab. This will take you to cell M97.
 Click on the Chart wizard button while holding down Ctrl and Shift.
 In Word 97, you can play the pinball game!
 Open a new document in Word 97.
 Type “Blue” and select Word.
 Go to Format  Font and Choose Font Style Bold, Color Blue.
 Type ” ” (space) after word “Blue” and go to Help  About.
 Click on the Word icon/banner while holding down Ctrl and Shift.
COMP 2432 2021/2022

Operating System Operation
 The timer mechanism
 A simple way to prevent infinite loop and resources hogging
by processes.
 Set up interrupt to occur after specific time period (alarm).
 Operating system decrements counter upon timer interrupt.
 When counter reaches zero, something wrong happens.
 Kill the process or take back resources (e.g. unlock a file).
 Sometimes, this is called the watchdog timer.
 Provided by the timer interrupt mechanism.
 In Unix, a special timer interrupt handler, called the clock routine, plays a central role in process scheduling and resource management.
 It is triggered by the hardware clock every 1/60 second in
the original Unix design. COMP 2432 2021/2022

Operating System Operation
 Since interrupt processing is important, special care must be taken in writing interrupt handlers.
 Allowing or disabling interrupts is very important.  Recall that interrupt is the mechanism for an OS to take
 If a user program can disable interrupts, there is no way for the OS to get back the CPU and do some remedial action. The result is system hang-up (e.g. Windows blue screen).
 The hardware should thus provide help to guard against an ordinary user from executing special interrupt related-commands.
 In terms of computer architecture, these commands are called privileged commands, including I/O commands.
 Common solution is to provide dual operation mode in CPU hardware.
COMP 2432 2021/2022
back the CPU when necessary.

User and Kernel Mode
 Dual-mode operation allows the OS to protect itself and other system components.
 Two modes: user mode and kernel mode.
User mode: a user mode process can only execute normal instructions, but not privileged instructions.
Kernel mode: a kernel mode process can execute all instructions. Only OS processes should be executing in kernel mode. It is also called system, privileged or supervisor mode.
 Hardware provides a mode bit.
 Provide ability to distinguish when the system is running user program or system (OS) program.
A process running with user mode bit on is a user process.
 A process running with user mode bit off is a kernel or system process. COMP 2432 2021/2022

User and Kernel Mode
 If a user process executes in user mode, how can it do I/O that needs to execute privileged instructions?
 Achieved through System Calls.
 A system call is an entry port to the OS.
 A system call is actually a trap that changes from user mode to kernel mode, executes the privileged I/O command, returns from system call and reverts back to user mode to continue execution.
COMP 2432 2021/2022

System Calls
 A system call is a programming interface to the services provided by the OS.
 The nature of a system call is similar to a procedure call (a very special procedure call).
 Often written in a high-level language like C/C++.
 User programs could not execute privileged instructions,
except through the OS.
 System call provides the interface to execute these system functions by user programs.
 To facilitate programmers, a high-level Application Program Interface (API) is often provided (e.g. Java API).
 An API hides the details about system calls from programmers. COMP 2432 2021/2022

System Calls
 Example system call sequence to copy the contents of a file to another file.
2 2021/2022

System Calls
Inside the OS, a number would be associated with each system call.
 System-call interface maintains a table indexed according to these numbers.
 Such a table looks like a table of interrupt handlers.
When the user process executes the system call, the system call interface generates a software trap.
System call table
The CPU switches to kernel mode and the system call routine is executed (like interrupt).
Status of the system call is returned to the caller, together with any return values.
The caller needs to know nothing about how the system call is implemented. COMP 2432 2021/2022

System Calls
open a file
COMP 2432 2021/2022

System Calls
 Example of printf() I/O library routine, which calls the write() system call in Unix or Linux.
COMP 2432 2021/2022

Types of System Calls
COMP 2432 2021/2022
 Process control
 Load, execute, create, terminate, abort, get/set attributes,
memory allocation.  File management
 Create, delete, open, close, read, write, reposition, get/set attributes.
 Device management
 Request, release, read, write, reposition, get/set attributes,
attach/detach device.
 Information maintenance
 Get/set time/date, get/set system data, get/set various attributes.
 Communications
 Create connection, delete connection, send message, receive message, transfer status.

System Call Parameter Passing
 System call is like a procedure call, so there is a need to pass in parameters (or arguments).
 Common procedure call parameter passing mechanisms.  Pass-by-value (C, C++ and Pascal)
 Pass-by-reference (Java objects, C++ & and Pascal var)
 Pass-by-value/result (Fortran)
 To pass parameters to OS via system call, we face more limitations.
 System calls are of lower level than normal procedures.
 Hard to use complicated mechanism.
 Three general methods used to pass parameters to OS.  Register
 Table  Stack
COMP 2432 2021/2022

System Call Parameter Passing
 Register
 Put parameters in registers and system call routine reads
 Simple and fast, but it fails if the number of parameters is more than number of registers.
 Put parameters in a block or a table in memory.
 Pass the address of the block as a parameter in a register.
 System call routine reads the parameter using the address found at register.
 Push parameters onto the stack of the program.
 System call routine pops parameters off the stack for use.
COMP 2432 2021/2022
them from registers.

System Call Parameter Passing
 Table approach example
 Effectively a pass-by-reference mechanism.
COMP 2432 2021/2022

System Programs
 System programs provide a convenient environment for program development and execution.
 Some of them are just user interfaces to system calls.  Some others are much more complex.
 File manipulation
 Status information
 File modification
 Programming language support  Program loading and execution  Communications
 Utilities
 Unless we are programmers, we would not see system calls, but we see system programs.
 System programs give us the perception about the OS.
COMP 2432 2021/2022

System Programs
 File management
 Create, delete, copy, rename, print, dump, list and
COMP 2432 2021/2022
files/directory manipulation.
 Status information
 Some ask the system for information: date, time, amount of
available memory, disk space, number of users.
 Others provide detailed information for performance, logging and debugging.
 These programs format and print the output.
 Some systems implement a registry to store and retrieve
 File modification
 Text editors to create and modify files.
 Special commands to search contents of files or perform transformations of the text.
configuration information.

System Programs
 Programming-language support
 Compilers, assemblers, debuggers and interpreters.
compilers. COMP 2432 2021/2022
 Program loading and execution
 Absolute loaders (.com), relocatable loaders (.exe), linkage
editors and overlay-loaders (system programming stuffs).  Debugging systems for programs.
 Communications
 Provide the mechanism for creating virtual connections
among processes, users and computer systems.
 Allow users to send messages to one another’s screens, browse web pages, send email messages, remote log in, file transfer from one machine to another.
 Utilities
 Additional useful programs.
 Database system, word processor, spreadsheet, additional

Types of Operating Systems
each process must get CPU without waiting for too long.
COMP 2432 2021/2022
 Batch processing
 A job is a sequence of programs represented by an input
data sets (often a deck of cards).
 One job is executed one at a time and programs within each
job are executed sequentially.
 Common systems in 60’s like IBM JCL-related (job control
language) systems.
 Multiprogramming
 Programs are executed in interleaved manner by the CPU.
 CPU is given to another program when the current program is waiting for I/O.
 Common systems in 70’s.
 Time-sharing
 Processes are executed in interleaved manner by the CPU.
 Same as multiprogramming, but system is interactive, so

Types of Operating Systems
 Real-time
 A time-sharing system where processes have completion
 Hard real-time systems have firm deadlines.
 Missing a deadline makes a process useless, e.g. examination.
 Soft real-time systems have soft deadlines.
 Missing a deadline reduces value of a process, e.g. assignment.
 Important in high-valued and mission critical applications.
 Banking transactions, airline reservation, space shuttle control.
 Distributed
 Operated upon a collection of computers scattered across
the network.
 Advanced from network operating systems.
 Need to coordinate the share of resource and execution of processes to achieve a common goal.
 Examples:
 Client/server system, internet computing systems.
COMP 2432 2021/2022
deadlines that must be met.

Operating System Structure
 Simple OS
 Example: MS-DOS
 Written to provide most functionality in least space.
 Not divided into modules (non-modular design).
 Interfaces and levels of functionality are not well separated.
COMP 2432 2021/2022

Operating System Structure
 Layered OS
 OS is divided into several
 Each layer is built on top of lower layers.
 Bottom layer (layer 0) is the hardware.
 Highest (layer N) is the user interface.
 Each layer is a module. It is selected such that each layer only uses functions and services of lower-level layers.
 This is similar to OSI 7 layers for network.
COMP 2432 2021/2022
layers (levels).

*nix Operating Systems
 UnixandLinuxarebasedonmanycommonconcepts.
 Only the look and feel and minor aspects could vary.
 They are often referred to as the *nix family.
 There are many common commands on any Unix/Linux system.  You can go to any system and can work reasonably well.
 Advantages of Unix and Linux:
 Reliability: seldom crash, ported to many systems and tested by
many people.
 Security: better security, with simpler kernel design.
 Speed: programs run faster with lower OS overhead.
 Cost: Linux is free and many Unix systems are free.
 Open source: source codes available; you could verify that they are correct; you could modify them to specific need.
 The fastest supercomputers in the world are also running on Linux!
 Top three computers all use Red Hat Enterprise Linux: Fujitsu Fugaku, IBM Summit, IBM Sierra. COMP 2432 2021/2022

*nix Operating Systems
 *nix are the most influential operating systems and form the largest installation base behind Windows.
 ThefirstusefulUnixwasdevelopedin1973atAT&TBellLab, written in assembly and C language.
 C language was invented because of a need to develop Unix.  Two major flavors for Unix:
 BSDUnixdevelopedbyUCBerkeleyforacademicuse.
 Solaris is developed from BSD and is major Unix installation.
 FreeBSD is also a very common Unix installation.
 Mac OS X is designed to be POSIX-compliant.
 PortableOperatingSystemInterface,astandardforUnix-likeOS.
 System V by AT&T, which had led to IBM AIX (running DB2).  Each flavor is packaged by different distributions into Linux.
 BSD Unix is packaged under RedHat (e.g. Fedora, CentOS), Novell (e.g. OpenSUSE), Ubuntu derived from Debian.
 Linux forms the basis of LAMP development platform for many commercial applications.
COMP 2432 2021/2022

Unix Structure
 Unix is not structured in a complex way, but follows a bit of the layered approach.
 Unix consists of two layers:  Kernel (key Unix core)
Consist of everything below the system-call interface and above the physical hardware.
Provide file system, CPU scheduling, memory management and other OS functions.
 Not a good design, with many functions within one level.
 System programs
Programs that supplement the functions provided by kernel.
Shell (command line interpreter), compiler, editor. Examples:
 SSH, cc, gcc, pico , nano. COMP 2432 2021/2022

Unix Structure
COMP 2432 2021/2022

Linux Structure
 Similar 2-layered structure as Unix.
COMP 2432 2021/2022

Mac OS X Structure
 Mac OS X is based on the Darwi

程序代写 CS代考 加微信: cscodehelp QQ: 2235208643 Email: kyit630461@163.com

Leave a Reply

Your email address will not be published. Required fields are marked *