15-410, S’04 - 1 - Hardware Overview Jan. 19, 2004 Dave Eckhardt Bruce Maggs L04_Hardware 15-410 “Computers make very fast, very accurate mistakes.” --Brandon.

Slides:



Advertisements
Similar presentations
Computer-System Structures Er.Harsimran Singh
Advertisements

The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
Chapter 6 Limited Direct Execution
A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Processes 1 CS502 Spring 2006 Processes Week 2 – CS 502.
OS Spring’03 Introduction Operating Systems Spring 2003.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
OS Spring’04 Introduction Operating Systems Spring 2004.
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
System Calls 1.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
2.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 2: Computer-System Structures Computer System Operation I/O Structure.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Chapter 2: Computer-System Structures
Thanks to Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2 Computer-System Structures n Computer System Operation n I/O Structure.
2: Computer-System Structures
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
15-410, S’ Hardware Overview Jan. 19, 2004 Dave Eckhardt Bruce Maggs L04_Hardware “Dude, what were you thinking?”
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 4 Computer Systems Review.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Lecture 26 Virtual Machine Monitors. Virtual Machines Goal: run an guest OS over an host OS Who has done this? Why might it be useful? Examples: Vmware,
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Review of Computer System Organization. Computer Startup For a computer to start running when it is first powered up, it needs to execute an initial program.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
1 Hardware Overview Dave Eckhardt
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
“Computers make very fast, very accurate mistakes.”
Introduction to Operating Systems Concepts
Introduction to Operating Systems
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
Processes and threads.
CS 6560: Operating Systems Design
CS 3305 System Calls Lecture 7.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

15-410, S’ Hardware Overview Jan. 19, 2004 Dave Eckhardt Bruce Maggs L04_Hardware “Computers make very fast, very accurate mistakes.” --Brandon Long

15-410, S’ Synchronization Today's class Not exactly Chapter 2 or 13 Project 0 Due tonight at midnight Consider not using a late day Could be a valuable commodity later Remember, this is a warm-up Reliance on these skills will increase rapidlyUpcoming Project 1 Lecture on “The Process”

15-410, S’ Synchronization Personal Simics licenses Simics machine-simulator software is licensed We have enough “seats” for the class Should work on most CMU-network machines Will not work on most non-CMU-network machines Options CMU “Address extension” service (non- encrypted VPN) “Personal academic license” for a personal Linux box » locked to your personal machine (MAC address) » apply at (top right of page)

15-410, S’ Synchronization Simics on Windows? Simics simulator itself is available for Windows build/debug infrastructure is notOptions Dual-boot, VMware Usability via X depends on network latency Port to cygwin (may be non-trivial) There are those Andrew cluster machines...

15-410, S’ Outline Computer hardware CPU State Fairy tales about system calls CPU context switch (intro) Interrupt handlers Interrupt masking Sample hardware device – countdown timer

15-410, S’ Inside The Box - Historical/Logical

15-410, S’ Inside The Box - Really

15-410, S’ CPU State User registers (on Planet Intel) General purpose - %eax, %ebx, %ecx, %edx Stack Pointer - %esp Frame Pointer - %ebp Mysterious String Registers - %esi, %edi

15-410, S’ CPU State Non-user registers, a.k.a.... Processor status register(s) Currently running: user code / kernel code? Interrupts on / off Virtual memory on / off Memory model small, medium, large, purple, dinosaur

15-410, S’ CPU State Floating Point Number registers Logically part of “User registers” Sometimes another “special” set of registers Some machines don't have floating point Some processes don't use floating point

15-410, S’ Story time! Time for some fairy tales The getpid() story (shortest legal fairy tale) The read() story (toddler version) The read() story (grade-school version)

15-410, S’ The Story of getpid() User process is computing User process calls getpid() library routine Library routine executes TRAP(314159) The world changes Some registers dumped into memory somewhere Some registers loaded from memory somewhere The processor has entered kernel mode

15-410, S’ User Mode

15-410, S’ Entering Kernel Mode

15-410, S’ Entering Kernel Mode

15-410, S’ The Kernel Runtime Environment Language runtimes differ ML: no stack, “nothing but heap” C: stack-based Processor is more-or-less agnostic Some assume/mandate a stack Trap handler builds kernel runtime environment Depending on processor Switches to correct stack Saves registers Turns on virtual memory Flushes caches

15-410, S’ The Story of getpid() Process in kernel mode running->u_reg[R_EAX] = running->u_pid; Return from interrupt Processor state restored to user mode (modulo %eax) User process returns to computing Library routine returns %eax as value of getpid()

15-410, S’ Returning to User Mode

15-410, S’ The Story of getpid() What's the getpid() system call? C function you call to get your process ID “Single instruction” which modifies %eax Privileged code which can access OS internal state

15-410, S’ A Story About read() User process is computing count = read(7, buf, sizeof (buf)); User process “goes to sleep” Operating system issues disk read Time passes Operating system copies data User process “wakes up”

15-410, S’ Another Story About read() P1: read() Trap to kernel mode Kernel: tell disk: “read sector ” Kernel: switch to running P2 Return to user mode - but to P2, not P1! P1 is “blocked in system call” Part-way through driver code Marked “unable to execute more instructions” P2: compute 1/3 of Mandelbrot set

15-410, S’ Another Story About read() Disk: done! Asserts “interrupt request” signal Interrupt to kernel mode Run “disk interrupt handler” code Kernel: switch to P1 Return from interrupt - but to P1, not P2!

15-410, S’ Interrupt Vector Table How should CPU handle this particular interrupt? Disk interrupt  invoke disk driver Mouse interrupt  invoke mouse driver Need to know Where to dump registers often: property of current process, not of interrupt New register values to load into CPU key: new program counter, new status register » These define the new execution environment

15-410, S’ Interrupt Dispatch/Return Table lookup Interrupt controller says: this is interrupt source #3 CPU fetches table entry #3 Pre-programmed table base-pointer Table entry size defined by hardware Save old processor state Modify state according to table entry Start running interrupt handler “Return from interrupt” process Load saved processor state back into registers Restoring program counter reactivates “old” code

15-410, S’ Example: x86/IA32 CPU saves old processor state Stored on “kernel stack” CPU modifies state according to table entry Loads new privilege information, program counter Interrupt handler begins Uses kernel stack for its own purposes Interrupt handler completes Empties stack back to original state Invokes “interrupt return” instruction

15-410, S’ IA32 Single-Task Mode Example Interrupt/Exception while in kernel mode (Project 1) Hardware pushes registers on current stack, NO STACK CHANGE EFLAGS (processor state) CS/EIP (return address) Error code (certain interrupts/faults, not others: see intel-sys.pdf) From intel-sys.pdf

15-410, S’ Race Conditions Two concurrent activities Computer program, disk drive Execution sequences produce various “answers” Disk interrupt before or after function call? Execution orders are not controlled Either outcome is possible “randomly” System produces random “answers” One answer or another “wins the race”

15-410, S’ Race Conditions – Disk Device Driver “Top half” wants to launch disk-I/O requests If disk is idle, send it the request if disk is busy, queue request for later Interrupt handler action depends on queue empty/non Queue empty  let disk go idle Queue non-empty  transmit next request Various outcomes possible Disk interrupt before or after “device idle” test? System produces random “answers” Queue non-empty  transmit next request Queue non-empty  let disk go idle

15-410, S’ Race Conditions – Driver Skeleton dev_start(request) { if (device_idle) start_device(request); else enqueue(request); } dev_intr() {...finish up previous request... if (new_request = head()) { start_device(new_request); }

15-410, S’ Race Conditions – Good Case

15-410, S’ Race Conditions – Bad Case

15-410, S’ What Went Wrong? “Top half” ran its algorithm Examine state Commit to action Interrupt handler ran its algorithm Examine state Commit to action Various outcomes possible Depends on exactly when interrupt handler runs System produces random “answers”

15-410, S’ Interrupt Masking Two approaches Temporarily suspend (“mask”) device interrupt while checking and enqueueing Will cover further before Project 1 Or use a lock-free data structure [left as an exercise for the reader]Considerations Avoid blocking all interrupts [not a big issue for ] Avoid blocking too long Part of Project 3 grading criteria

15-410, S’ Timer – Behavior Simple behavior Count something CPU cycles, bus cycles, microseconds When you hit a limit, signal an interrupt Reload counter to initial value Do it “in background” / “in hardware” (Don't wait for software to do reload)Summary No “requests”, no “results” Steady stream of evenly-distributed interrupts

15-410, S’ Timer – Why? Why interrupt a perfectly good execution? Avoid CPU hogs for (;;) ; Maintain accurate time of day Battery-backed calendar counts only seconds (poorly) Dual-purpose interrupt Timekeeping ++ticks_since_boot; Avoid CPU hogs force process switch

15-410, S’ Summary Computer hardware CPU State Fairy tales about system calls CPU context switch (intro) Interrupt handlers Interrupt masking Sample hardware device – countdown timer