Outline Announcements Computer Architecture continued Signal handling in

  • Slides: 52
Download presentation
Outline • • Announcements Computer Architecture – continued Signal handling in Unix Device Management

Outline • • Announcements Computer Architecture – continued Signal handling in Unix Device Management – Device Drivers – I/O Strategies – Polling vs. interrupt-driven I/O 9/17/2020 COP 4610 1

Announcements • We are going to have a quiz at the end of the

Announcements • We are going to have a quiz at the end of the class on Sept. 18, 2003 – Which is a week from today – It will be a closed book and closed notes quiz – It will cover • System calls and how to use them • Lecture notes up to next Tuesday (Sept. 16) • Related materials in the book 9/17/2020 COP 4610 2

Announcements – cont. • Next week’s recitation session (Sep. 17) will be optional –

Announcements – cont. • Next week’s recitation session (Sep. 17) will be optional – I will use that mainly to answer questions related to the first programming assignment • By today we should have covered everything you need to know in order to implement the assignment – You are not required to attend as I will not cover new materials – I will be in LOV 301 as we normally meet for recitation 9/17/2020 COP 4610 3

Announcements – cont. • Comments regarding the first programming assignment – You can use

Announcements – cont. • Comments regarding the first programming assignment – You can use simple-shell. cc as a starting point or the code in the textbook • You can use the code segments from examples I distributed • Please note that you are not allowed to copy other’s work • Comments on Homework #1 9/17/2020 COP 4610 4

Device Drivers • The part of OS that implements device management is called collectively

Device Drivers • The part of OS that implements device management is called collectively as device manager, which includes device drivers and device driver infrastructure – Device drivers can be complex – However, the drivers for different devices implement a similar interface so that a higherlevel component has a uniform interface for different devices 9/17/2020 COP 4610 5

Device Driver Interface … write(…); … Device Interface 9/17/2020 Terminal Driver Printer Driver Disk

Device Driver Interface … write(…); … Device Interface 9/17/2020 Terminal Driver Printer Driver Disk Driver Terminal Controller Printer Controller Disk Controller COP 4610 6

Device Management Organization Application Process System Interface File Manager Device-Independent Device-Dependent Hardware Interface Command

Device Management Organization Application Process System Interface File Manager Device-Independent Device-Dependent Hardware Interface Command Status Data Device Controller 9/17/2020 COP 4610 7

I/O Strategies • Direct I/O – The CPU is responsible for determining when the

I/O Strategies • Direct I/O – The CPU is responsible for determining when the I/O operation has completed and then for transferring the data between the primary memory and the device controller data registers • Polling or interrupt-driven I/O – This seems not effective for devices with large transfers, such as a disk drive • Direct Memory Access (DMA) 9/17/2020 COP 4610 8

Direct-Memory Access • Direct memory access controllers – Can read/write data directly from/to primary

Direct-Memory Access • Direct memory access controllers – Can read/write data directly from/to primary memory addresses with no CPU intervention after the driver has started the I/O operation 9/17/2020 COP 4610 9

Direct-Memory Access – cont. 9/17/2020 COP 4610 10

Direct-Memory Access – cont. 9/17/2020 COP 4610 10

Direct-Memory Access – cont. 9/17/2020 COP 4610 11

Direct-Memory Access – cont. 9/17/2020 COP 4610 11

I/O Strategies – cont. • Direct I/O or DMA for data transferring • Polling

I/O Strategies – cont. • Direct I/O or DMA for data transferring • Polling or interrupt-driven • I/O strategies – Direct I/O with polling – DMA I/O with polling • Not supported in general – Direct I/O with interrupts – DMA I/O with interrupts 9/17/2020 COP 4610 12

Direct I/O with Polling read(device, …); 1 System Interface Data read function 5 write

Direct I/O with Polling read(device, …); 1 System Interface Data read function 5 write function 2 3 4 Hardware Interface Command Status Data Device Controller 9/17/2020 COP 4610 13

Device Controllers – cont. . busy Command done Error code Status . . .

Device Controllers – cont. . busy Command done Error code Status . . . busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined) Data 0 Data 1 Logic Data n-1 9/17/2020 COP 4610 14

Hardware Software Polling I/O … // Start the device … While(busy == 1) wait();

Hardware Software Polling I/O … // Start the device … While(busy == 1) wait(); // Device I/O complete … done = 0; busy done … while((busy == 0) && (done == 1)) wait(); // Do the I/O operation busy = 1; … 9/17/2020 COP 4610 15

Interrupt-Driven I/O read(device, …); 1 9 8 b Data System Interface Device Status Table

Interrupt-Driven I/O read(device, …); 1 9 8 b Data System Interface Device Status Table read driver 2 4 7 Device Handler write driver 6 3 Interrupt Handler 8 a 5 Hardware Interface Command Status Data Device Controller 9/17/2020 COP 4610 16

Interrupt-Driven Versus Polling • In general, an interrupt-driven system will have a higher CPU

Interrupt-Driven Versus Polling • In general, an interrupt-driven system will have a higher CPU utilization than a pollingbased system – The CPU time on polling by one process may be utilized by another process to perform computation 9/17/2020 COP 4610 17

Comparison of Polling and Interrupt-Driven I/O Performance • Polling is normally superior from the

Comparison of Polling and Interrupt-Driven I/O Performance • Polling is normally superior from the viewpoint of a single process – Because overhand of polling is less • Interrupt-driven I/O approach gives better overall system performance 9/17/2020 COP 4610 18

I/O-CPU Overlap Through interrupt-driven I/O 9/17/2020 COP 4610 19

I/O-CPU Overlap Through interrupt-driven I/O 9/17/2020 COP 4610 19

I/O-CPU Overlap – cont. • Sequential operation and overlapped operation 9/17/2020 COP 4610 20

I/O-CPU Overlap – cont. • Sequential operation and overlapped operation 9/17/2020 COP 4610 20

I/O-CPU Overlap – cont. - I/O-CPU overlap through overlapped operation and polling 9/17/2020 COP

I/O-CPU Overlap – cont. - I/O-CPU overlap through overlapped operation and polling 9/17/2020 COP 4610 21

I/O-bound and Compute-bound Processes • I/O-bound process – A process’s overall execution time is

I/O-bound and Compute-bound Processes • I/O-bound process – A process’s overall execution time is dominated by the time to perform I/O operations • Compute-bound process – A process’s time on I/O is small compared to the amount of time spent using the CPU • Many processes have I/O-bound and compute -bound phases 9/17/2020 COP 4610 22

Phases of a Process Compute-bound Time I/O-bound 9/17/2020 COP 4610 23

Phases of a Process Compute-bound Time I/O-bound 9/17/2020 COP 4610 23

Device Manager Design • Device drivers – Application programming interface – Coordination among application

Device Manager Design • Device drivers – Application programming interface – Coordination among application processes, drivers, and device controllers – Performance optimization 9/17/2020 COP 4610 24

BSD UNIX Driver Functions 9/17/2020 COP 4610 25

BSD UNIX Driver Functions 9/17/2020 COP 4610 25

The Kernel Interface 9/17/2020 COP 4610 26

The Kernel Interface 9/17/2020 COP 4610 26

Device-Independent Function Call funci(…) Trap Table 9/17/2020 dev_func_i(dev. ID, …) { // Processing common

Device-Independent Function Call funci(…) Trap Table 9/17/2020 dev_func_i(dev. ID, …) { // Processing common to all devices … switch(dev. ID) { case dev 0: dev 0_func_i(…); break; case dev 1: dev 1_func_i(…); break; … case dev. M: dev. M_func_i(…); break; }; // Processing common to all devices … } COP 4610 27

Re-configurable Device Drivers System call interface open(){…} read(){…} Entry Points for Device j etc.

Re-configurable Device Drivers System call interface open(){…} read(){…} Entry Points for Device j etc. Other Kernel services Driver for Device j 9/17/2020 COP 4610 28

Handling Interrupts Device driver J int read(…) { // Prepare for I/O save_state(J); out

Handling Interrupts Device driver J int read(…) { // Prepare for I/O save_state(J); out dev# // Done (no return) } Device status table J Device interrupt handler J void dev_handler(…) { get_state(J); //Cleanup after op signal(dev[j]); return_from_sys_call(); } Interrupt Handler Device Controller 9/17/2020 COP 4610 29

Handling Interrupts – cont. Device driver J Device interrupt handler J int read(…) {

Handling Interrupts – cont. Device driver J Device interrupt handler J int read(…) { … out dev# // Return after interrupt wait(dev[J}); return_from_sys_call(); } void dev_handler(…) { //Cleanup after op signal(dev[j]); } Interrupt Handler Device Controller 9/17/2020 COP 4610 30

CPU-device Interactions 9/17/2020 COP 4610 31

CPU-device Interactions 9/17/2020 COP 4610 31

Device Management in Linux • While it builds on the same basic principles, it

Device Management in Linux • While it builds on the same basic principles, it is more complex and with more details – There a lot of device drivers included and you can also develop your own device drivers for specific purpose devices • Linux divides into char-oriented devices and block oriented devices – fs/blk_dev. c – fs/char_dev. c 9/17/2020 COP 4610 32

Buffering • Buffering – A technique to keep slower I/O devices busy during times

Buffering • Buffering – A technique to keep slower I/O devices busy during times when a process is not requiring I/O operations 9/17/2020 COP 4610 33

The Pure Cycle Water Company Customer Office Water Company Returning the Empties Water Producer

The Pure Cycle Water Company Customer Office Water Company Returning the Empties Water Producer Water Consumers Delivering Water 9/17/2020 COP 4610 34

Buffering – cont. 9/17/2020 COP 4610 35

Buffering – cont. 9/17/2020 COP 4610 35

Double Buffering 9/17/2020 COP 4610 36

Double Buffering 9/17/2020 COP 4610 36

Multiple Buffers - Producer-consumer problem 9/17/2020 COP 4610 37

Multiple Buffers - Producer-consumer problem 9/17/2020 COP 4610 37

Spooling • A spool is a buffer that holds output for a device that

Spooling • A spool is a buffer that holds output for a device that cannot accept interleaved data streams – Printer is an example 9/17/2020 COP 4610 38

Communication Devices Bus Generic Controller Communications Controller Local Device Cabling connecting the controller to

Communication Devices Bus Generic Controller Communications Controller Local Device Cabling connecting the controller to the device Device • Printer • Modem • Network 9/17/2020 COP 4610 39

Randomly Accessed Devices 9/17/2020 COP 4610 40

Randomly Accessed Devices 9/17/2020 COP 4610 40

Optimizing Access to Rotating Devices • Access time has three major components – Seek

Optimizing Access to Rotating Devices • Access time has three major components – Seek time – the time for the disk arm to move the heads to the cylinder containing the desired sector – Rotational latency – the additional time waiting for the disk to rotate the desired sector to the disk head – Transfer Time - time to copy bits from disk surface to memory 9/17/2020 COP 4610 41

Optimizing Seek Time • Multiprogramming on I/O-bound programs => set of processes waiting for

Optimizing Seek Time • Multiprogramming on I/O-bound programs => set of processes waiting for disk • Seek time dominates access time => minimize seek time across the set • Tracks 0: 99; Head at track 75, requests for 23, 87, 36, 93, 66 9/17/2020 COP 4610 42

Optimizing Access to Rotating Devices -First-Come-First-Served (75), 66, 87, 93, 36, 23 52+ 64

Optimizing Access to Rotating Devices -First-Come-First-Served (75), 66, 87, 93, 36, 23 52+ 64 + 51 + 57 + 27 = 251 steps 9/17/2020 COP 4610 43

Optimizing Access to Rotating Devices – cont. -Shortest-Seek-First - SSTF: (75), 66, 87, 93,

Optimizing Access to Rotating Devices – cont. -Shortest-Seek-First - SSTF: (75), 66, 87, 93, 36, 23 – 11 + 21 + 6 + 57 + 13 = 107 steps 9/17/2020 COP 4610 44

Optimizing Access to Rotating Devices – cont. -Scan/Look - Scan: (75), 87, 93, 99,

Optimizing Access to Rotating Devices – cont. -Scan/Look - Scan: (75), 87, 93, 99, 66, 36, 23 – 12 + 6 + 33 + 30 + 13 = 100 steps - Look: (75), 87, 93, 66, 36, 23 – 12 + 6 + 27 + 30 + 13 = 87 steps 9/17/2020 COP 4610 45

Optimizing Access to Rotating Devices – cont. - Circular Scan/ Circular Look • Circular

Optimizing Access to Rotating Devices – cont. - Circular Scan/ Circular Look • Circular Scan: (75), 87, 93, 99, 23, 36, 66 – 12 + 6 + home + 23 + 13 + 30 = 90 + home • Circular Look: (75), 87, 93, 23, 36, 66 – 12 + 6 + home + 23 + 13 + 30 = 84 + home 9/17/2020 COP 4610 46

Serial Port CPU Memory Serial Device • Printer • Terminal • Modem • Mouse

Serial Port CPU Memory Serial Device • Printer • Terminal • Modem • Mouse • etc. 9/17/2020 COP 4610 47

Serial Port Device Driver API Device Driver Software on the CPU • Set UART

Serial Port Device Driver API Device Driver Software on the CPU • Set UART parms • read/write ops • Interrupt hander Bus Interface UART API Serial Device • parity (UART) • bits per byte • etc. 9/17/2020 COP 4610 RS-232 Interface • 9 -pin connector • 4 -wires • bit transmit/receive • . . . 48

Adding a Modem CPU Memory Serial Device Modem • Dialing & connecting • Convert

Adding a Modem CPU Memory Serial Device Modem • Dialing & connecting • Convert analog voice to/from digital • Convert bytes to/from bit streams • Transmit/receive protocol Phone Switched Telephone Network 9/17/2020 COP 4610 49

Serial Communication Device Driver • Set UART parms • read/write ops • Interrupt hander

Serial Communication Device Driver • Set UART parms • read/write ops • Interrupt hander Driver-Modem Protocol • Dialing & connecting • Convert analog voice to/from digital • Convert bytes to/from bit streams • Transmit/receive protocol 9/17/2020 COP 4610 Serial Device RS-232 Modem 50

Exploiting the Phone Network Logical Communication CPU Memory CPU Comm Device Modem Phone Memory

Exploiting the Phone Network Logical Communication CPU Memory CPU Comm Device Modem Phone Memory Switched Telephone Network 9/17/2020 COP 4610 51

Summary • Device Management Organization • I/O Strategies • Device is the bottleneck for

Summary • Device Management Organization • I/O Strategies • Device is the bottleneck for I/O-bound processes – Overlap between I/O and CPU will increase the system’s throughput rate 9/17/2020 COP 4610 52