IO Devices n Controller physically controls the devices

  • Slides: 20
Download presentation
I/O Devices n Controller: physically controls the devices n Devices are diverse and complicated

I/O Devices n Controller: physically controls the devices n Devices are diverse and complicated n Present simpler interface to OS n n n E. g, convert a linear sector number to number of cylinder, sector and head. Operating Device driver: software talks to a controller Installation of drivers n Re-link kernel with new driver, reboot n Register driver in system file, reboot n Install on-the-fly, PNP, NO reboot system driver controller device 1

Handle I/O: Busy Waiting User program Kernel Driver I/O device Issue a system call

Handle I/O: Busy Waiting User program Kernel Driver I/O device Issue a system call (TRAP) Call driver T I M E CPU Wasted Start I/O Polling Do I/O Put data Return control to caller Continue 2

An Example // p is the buffer for (i=0; i<count; i++){ while (*printer_status_reg!=READY); *printer_data_register=p[i];

An Example // p is the buffer for (i=0; i<count; i++){ while (*printer_status_reg!=READY); *printer_data_register=p[i]; } return_to_user(); // loop on every character // loop until ready // output one character 3

I/O by Interrupt n n Driver tells controller what to do by writing its

I/O by Interrupt n n Driver tells controller what to do by writing its device registers. Then the controller starts the device. Controller finishes reading/writing, and then signals the interrupt controller If interrupt controller can accept the interrupt, it informs CPU Interrupt controller puts the number of device on the bus, CPU read it Disk drive CPU 3 Interrupt controller 4 Disk controller 2 1 4

Interrupt-Driven I/O Print system call enable_interrupts(); *printer_data_register=p[0]; scheduler(); Interrupt service procedure Interrupt occurs on

Interrupt-Driven I/O Print system call enable_interrupts(); *printer_data_register=p[0]; scheduler(); Interrupt service procedure Interrupt occurs on every character! if (count==0){ unblock_user(); } else { *printer_data_register=p[I]; count--; i++; } acknowledge_interrupt(); return_from_interrupt(); 5

Direct Memory Access (DMA) User program Kernel I/O device & memory Issue a system

Direct Memory Access (DMA) User program Kernel I/O device & memory Issue a system call Set up DMA chip Suspended Run other programs I/O directly Issue interrupt when finish Set the program status as “ready” Ready to continue 6

I/O Using DMA n n Too many interrupts in interrupt-driven I/O DMA reduces #

I/O Using DMA n n Too many interrupts in interrupt-driven I/O DMA reduces # of interrupts from 1/char to 1/buffer printed Print system call copy_from_user(buffer, p, count); set_up_DMA_controller(); scheduler(); Interrupt service procedure acknowledge_interrupt(); unblock_user(); return_from_interrupt(); 7

Advanced Computer With Multiple Buses Cache bus Local bus Level 2 cache CPU Memory

Advanced Computer With Multiple Buses Cache bus Local bus Level 2 cache CPU Memory bus PCI bridge Main memory PCI bus SCSI USB bus ISA USB bridge SCSI bus Mouse Modem Keyboard Sound card IDE bus IDE disk Graphics adaptor Available PCI slot ISA bus Monitor Printer Available ISA slot 8

Chapter 2 Processes and Threads

Chapter 2 Processes and Threads

Outline n n n Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling 10

Outline n n n Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling 10

Process n A program in execution n n a single instance of an executable

Process n A program in execution n n a single instance of an executable program User enters a command, invokes a program, while this program is executing it is called a process E. g, when a user types the command “ls” , the UNIX system creates a process for this command. Different processes running different programs: Word, Excel Different processes running same programs: multiple web-browsers in a PC 11

Much More Than A Program n Address space n n contain the executable program,

Much More Than A Program n Address space n n contain the executable program, program’s data, and its stack. the I/O devices associated Files opened Execution State: n Registers, e. g. , PC, PSW, SP, … 12

Process Vs. Programs: An Analogue A baker (CPU) uses a recipe (program) to transform

Process Vs. Programs: An Analogue A baker (CPU) uses a recipe (program) to transform the baking ingredients (input data), with the aid of cooking utensils and appliances (resources), into a cake (output). We recognize this entire activity as the process - an abstraction of an executing recipe. 13

Process Vs. Program n Program is a script, while process is an activity (execution)

Process Vs. Program n Program is a script, while process is an activity (execution) based on this script. n n Cake recipe program, baking cake based on the recipe process Different processes may share the same program n n One copy of script, but multiple executions Process is more than a script n Script, input, output, state, etc. 14

Information About Process n Process table in operating systems n n n Core image:

Information About Process n Process table in operating systems n n n Core image: process address space n n One entry for each process in existence Process ID, program counter, working directory, registers, etc. Instruction codes and data Process information = Process table entry + core image 15

Interleaving Execution of Processes n n More than one process exist. CPU switches from

Interleaving Execution of Processes n n More than one process exist. CPU switches from process to process. Process Process A B A C B C Time Process switching Which process to run next? 16

Pseudo-parallelism n n At any instant, the CPU is running only one process. In

Pseudo-parallelism n n At any instant, the CPU is running only one process. In the course of 1 second, it may work on several different processes. n n n The illusion of parallelism The true hardware parallelism: multi-processor Multi-programming n CPU switches back and forth between processes. 17

Different Points of View From Running independently of each other. Each process has its

Different Points of View From Running independently of each other. Each process has its own logical program counter (PC). But only one physical PC in CPU. User A OS Process From B C D D C B A t 1 Time E 18

Process Creation – When? n n System initialization Created by another process User request

Process Creation – When? n n System initialization Created by another process User request Initialization of a batch job 19

Process Creation in System Initialization n Foreground processes n n n Interact with users

Process Creation in System Initialization n Foreground processes n n n Interact with users E. g. , UNIX shell Background processes n n Not associated with particular user Daemons: have some specific functions n E. g. , Accepting emails, accepting web page request 20