Presentation is loading. Please wait.

Presentation is loading. Please wait.

L21 – OS and IO 1 Comp 411– Spring 2008 4/24/08 Operating System The OS is JUST A PROGRAM but it runs in SUPERVISOR state access to PHYSICAL addresses.

Similar presentations


Presentation on theme: "L21 – OS and IO 1 Comp 411– Spring 2008 4/24/08 Operating System The OS is JUST A PROGRAM but it runs in SUPERVISOR state access to PHYSICAL addresses."— Presentation transcript:

1 L21 – OS and IO 1 Comp 411– Spring 2008 4/24/08 Operating System The OS is JUST A PROGRAM but it runs in SUPERVISOR state access to PHYSICAL addresses access to special registers (like page table register) all IO devices, etc. whereas ordinary programs run in USER state only access to VIRTUAL addresses through page tables normally no access to IO devices Programs ask the OS for services (syscall) give me more memory read/write data from/to disk put pixel on screen give me the next character from the keyboard The OS may choose to “map” devices such as the screen into USER space

2 L21 – OS and IO 2 Comp 411– Spring 2008 4/24/08 Shell You normally interact with a SHELL It provides the command prompt, or GUI (graphical user interface) It is JUST A PROGRAM It runs in USER state just like your programs It interprets your mouse clicks or typed commands and asks the OS to implement your requests Suppose you “double-click” on a program icon What happens?

3 L21 – OS and IO 3 Comp 411– Spring 2008 4/24/08 Program Startup in SHELL First the SHELL finds the file (using FILE SYSTEM in OS) indicated by the icon It checks some permissions and such Finally it calls the EXEC system call with the file name and possibly some arguments Now the OS takes over

4 L21 – OS and IO 4 Comp 411– Spring 2008 4/24/08 OS Exec The OS keeps a PROCESS TABLE of all running programs disk location of executable memory location of page tables priority current status (running, waiting ready, waiting on an event, etc.) PID (process ID) a number assigned to the process A PROCESS is an independent program running in its own memory space The OS allocates a new entry in the PROCESS TABLE And sets up the PAGE TABLE for the new process

5 L21 – OS and IO 5 Comp 411– Spring 2008 4/24/08 Initial Page Table foo swap 0x00000000 0text segment 0x00001000 0text segment 0x00002000 1data segment 0x00003000 0x00004000 0x00005000 0xffffe000 0xfffff000 1stack memory disk page table

6 L21 – OS and IO 6 Comp 411– Spring 2008 4/24/08 Program Startup Now everything is ready The PROCESS TABLE entry has been set up The PAGE TABLE for the process has been initialized The TEXT SEGMENT is out on disk The DATA SEGMENT is in memory The STACK SEGMENT has been allocated 1 PAGE The OS is ready to take the leap of faith ONLY ONE program runs at a time When your program is running the OS is not To run your program and maintain control the OS must trust that is will eventually get control again when the program asks for a service when the program does something illegal when a timer goes off

7 L21 – OS and IO 7 Comp 411– Spring 2008 4/24/08 Page Fault in the Text When we branch to the beginning of “main” we get a page fault So the OS copies the first page of the TEXT of main to a free page in memory

8 L21 – OS and IO 8 Comp 411– Spring 2008 4/24/08 Page Fault in the Text foo swap 0x00000000 1text segment 0x00001000 0text segment 0x00002000 1data segment 0x00003000 0x00004000 0x00005000 0xffffe000 0xfffff000 1stack memory disk page table

9 L21 – OS and IO 9 Comp 411– Spring 2008 4/24/08 Allocate a block of memory Now suppose the first thing our program needs to do is get 6k of memory for an array The program uses “new” to make an array Down inside “new” it calls “malloc” Down inside “malloc” it uses a system call to ask the OS for memory The OS will have to find 2 pages to hold 6k

10 L21 – OS and IO 10 Comp 411– Spring 2008 4/24/08 Allocate a block of memory foo swap 0x00000000 1text segment 0x00001000 0text segment 0x00002000 1data segment 0x00003000 1heap 0x00004000 1heap 0x00005000 0xffffe000 0xfffff000 1stack disk page table

11 L21 – OS and IO 11 Comp 411– Spring 2008 4/24/08 Fault in the other page of TEXT foo swap 0x00000000 1text segment 0x00001000 1text segment 0x00002000 1data segment 0x00003000 1heap 0x00004000 1heap 0x00005000 0xffffe000 0xfffff000 1stack memory disk page table

12 L21 – OS and IO 12 Comp 411– Spring 2008 4/24/08 Grow the stack Now our program needs more stack space Perhaps it has to call a recursive function to traverse a complex data structure Or perhaps the user declares an “automatic” array like double work[1000]; which needs 8000 bytes of memory

13 L21 – OS and IO 13 Comp 411– Spring 2008 4/24/08 Grow the stack foo swap 0x00000000 1text segment 0x00001000 1text segment 0x00002000 1data segment 0x00003000 1heap 0x00004000 1heap 0x00005000... 0xffffd000 1 0xffffe000 1 0xfffff000 1stack memory disk page table

14 L21 – OS and IO 14 Comp 411– Spring 2008 4/24/08 Get partially paged out Sometime later, some other program running on the system needs more memory It asks the OS The OS realizes that not enough physical memory remains available So the OS chooses to PAGE OUT one page from our program It would choose one that hasn’t been used for a while like possibly one of the heap segments

15 L21 – OS and IO 15 Comp 411– Spring 2008 4/24/08 Partially Paged Out foo swap 0x00000000 1text segment 0x00001000 1text segment 0x00002000 1data segment 0x00003000 0heap 0x00004000 1heap 0x00005000... 0xffffd000 1 0xffffe000 1 0xfffff000 1stack memory disk page table

16 L21 – OS and IO 16 Comp 411– Spring 2008 4/24/08 Later we need that page foo swap 0x00000000 1text segment 0x00001000 1text segment 0x00002000 1data segment 0x00003000 1heap 0x00004000 1heap 0x00005000... 0xffffd000 1 0xffffe000 1 0xfffff000 1stack memory disk page table

17 L21 – OS and IO 17 Comp 411– Spring 2008 4/24/08 Exit Finally our program exits It calls the “exit” system call to notify the OS that it is done The OS puts the memory back on the free list Cleans up the PAGE TABLE and PROCESS TABLE And goes on about its business... What does the OS do when no programs are ready?

18 L21 – OS and IO 18 Comp 411– Spring 2008 4/24/08 Interrupts How does the CPU manage SLOW I/O devices? Programmed I/O Interrupt Driven I/O

19 L21 – OS and IO 19 Comp 411– Spring 2008 4/24/08 Polling Advantages Simple No surprises Processor in full control Disadvantages Polling can waste lots of time

20 L21 – OS and IO 20 Comp 411– Spring 2008 4/24/08 Interrupt Driven I/O Advantage CPU only bothered when actually needed Disadvantage Can occur at surprising or inconvenient times Have to save and restore state

21 L21 – OS and IO 21 Comp 411– Spring 2008 4/24/08 MIPS Exceptions Reset Hardware Errors (Bus Error, Cache Error) External Interrupt (6 inputs) Address Error Reserved Instruction TLB Miss System Call Breakpoint Trap Integer Overflow Floating Point Error Timer And a few more

22 L21 – OS and IO 22 Comp 411– Spring 2008 4/24/08 Exception Processing EPC gets address of faulty instruction or of next instruction depending on type of exception Switch to kernel mode Jump to a new location based on type of exception PC  FFFF FFFF BFC0 0000 for Reset PC  FFFF FFFF BFC0 0300 for Hardware error PC  FFFF FFFF BFC0 0380 for external interrupts PC  FFFF FFFF BFC0 0400 for … Save registers Examine the “cause” register to find out why you came here Branch to code to do the right thing

23 L21 – OS and IO 23 Comp 411– Spring 2008 4/24/08 Magnetic Disk Long term, nonvolatile storage Large, inexpensive, and slow Rotating platter(s) coated with magnetic material Use a movable read/write head to access When magnetized region zips past coils in head, a tiny signal is produced Force current through coils to generate magnetic field to magnetize tiny regions on the disk Use feedback to keep the head in the right place

24 L21 – OS and IO 24 Comp 411– Spring 2008 4/24/08 Outside

25 L21 – OS and IO 25 Comp 411– Spring 2008 4/24/08 Inside

26 L21 – OS and IO 26 Comp 411– Spring 2008 4/24/08 Platters and Heads

27 L21 – OS and IO 27 Comp 411– Spring 2008 4/24/08 Magnetic Disk Organization Cylinder: All tracks under head with arm in a fixed position Read/Write time has 3 components Seek time to move the arm Rotational latency: wait for the desired sector to come by Transfer time: transfer bits

28 L21 – OS and IO 28 Comp 411– Spring 2008 4/24/08 Typical Disk Times Average Seek: 8ms to 12ms Sum of all possible seek / number of possible seeks Locality reduces this to maybe only 25% of average number Rotational Latency: At 5400 RPM  11 ms At 7200 RPM  8 ms At 10000 RPM  6ms Transfer time depends on: Transfer size (typical 512 bytes) Rotation speed Recording density Diameter Typical values: 10 to 40MBytes per second

29 L21 – OS and IO 29 Comp 411– Spring 2008 4/24/08 CD

30 L21 – OS and IO 30 Comp 411– Spring 2008 4/24/08 CRT Display

31 L21 – OS and IO 31 Comp 411– Spring 2008 4/24/08 LCD

32 L21 – OS and IO 32 Comp 411– Spring 2008 4/24/08 Graphics Cards

33 L21 – OS and IO 33 Comp 411– Spring 2008 4/24/08 Polygons to Surfaces Numerical coordinates specify vertex positions in 3D Matrix multiply transforms 3D coordinates to eye coordinates Divide projects 3D to 2D in perspective Pixel processors fill polygons with appropriate colors based on lighting model

34 L21 – OS and IO 34 Comp 411– Spring 2008 4/24/08 Anti-aliasing

35 L21 – OS and IO 35 Comp 411– Spring 2008 4/24/08 Sound Sound is variations in air pressure A microphone converts these into an analog electrical signal An analog-to-digital converter samples this at frequent intervals The resulting numbers are stored in a file (.wav) On playback a digital-to-analog converter changes these numbers into an analog electrical signal And the moving cone of a speaker converts this into varying air pressure

36 L21 – OS and IO 36 Comp 411– Spring 2008 4/24/08 MP3? The sequence of numbers representing typical sounds is VERY redundant The next value is closely related to the previous Values aren’t random cause we don’t like noise Extract this redundancy to get compression Lossy compression: Throw less important info away cause listener won’t notice


Download ppt "L21 – OS and IO 1 Comp 411– Spring 2008 4/24/08 Operating System The OS is JUST A PROGRAM but it runs in SUPERVISOR state access to PHYSICAL addresses."

Similar presentations


Ads by Google