“Computers make very fast, very accurate mistakes.”

Slides:



Advertisements
Similar presentations
Chapter 6 Limited Direct Execution
Advertisements

1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
OS Spring’03 Introduction Operating Systems Spring 2003.
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.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
15-410, S’ Hardware Overview Jan. 19, 2004 Dave Eckhardt Bruce Maggs L04_Hardware “Computers make very fast, very accurate mistakes.” --Brandon.
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.
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
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.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
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.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Introduction to Operating Systems Concepts
Chapter Overview General Concepts IA-32 Processor Architecture
Introduction to Operating Systems
Introduction to Operating Systems
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
Processes and threads.
Process concept.
Interrupts and signals
Microprocessor Systems Design I
CS 6560: Operating Systems Design
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
William Stallings Computer Organization and Architecture 8th Edition
Anton Burtsev February, 2017
Mechanism: Limited Direct Execution
CS 3305 System Calls Lecture 7.
Introduction of microprocessor
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Introduction to Operating Systems
CS 143A Quiz 1 Solution.
Computer-System Architecture
Module 2: Computer-System Structures
Processor Fundamentals
Direct Memory Access Disk and Network transfers: awkward timing:
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Today’s agenda Hardware architecture and runtime system
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
Architectural Support for OS
CSCE 313 – Introduction to UNIx process
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Module 2: Computer-System Structures
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Module 2: Computer-System Structures
Chapter 13: I/O Systems.
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 “Computers make very fast, very accurate mistakes.” --Brandon Long Hardware Overview Sep. 16, 2008 Nathaniel Filardo (Stolen with only a slight trace of shame from CMU 15-410) L04_Hardware

Synchronization This lecture Not exactly Chapter 2 or 13 Hey speaking of that, the textbook readings are up on the schedule page. Just checking... People all registered? People all subscribed to the mailing list? Please check; some bounce unsubscription messages flew through my INBOX.

Synchronization Personal Simics licenses Simics machine-simulator software is licensed We have enough “seats” for the class Free site license from Virtutech. (<3) Should work on ACM, Grad CS, and Ugrad CS networks See the course website for usage instructions! Other Options “Personal academic license” for a personal Linux box locked to your personal machine (MAC address) apply at www.simics.net (top right of page)

Synchronization Simics on Windows? Simics simulator itself is available for Windows 15-410 build/debug infrastructure is not Can be hacked up, issues may arise Version skew, partner, ... Options Dual-boot Linux/Windows, run Linux in VMware Usability via X depends on network latency May be too slow – though we are experimenting Port to cygwin (may be non-trivial) There are some JHU machines in the labs...

Outline Computer hardware CPU State Fairy tales about system calls CPU context switch (intro) Interrupt handlers Race conditions Interrupt masking Sample hardware device – countdown timer

Inside The Box - Historical/Logical

Inside The Box - Really (Sorta)

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

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

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

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)

The Story of getpid() User process is computing User process calls getpid() library routine Library routine executes TRAP $314159 In Intel-land, TRAP is called “INT” (because it isn't one) REMEMBER: “INT” is not an interrupt The world changes Some registers dumped into memory somewhere Some registers loaded from memory somewhere The processor has entered kernel mode

User Mode

Entering Kernel Mode

Entering Kernel Mode

The Kernel Runtime Environment Language runtimes differ ML: may be 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/off virtual memory Flushes caches

The Story of getpid() Process runs 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()

Returning to User Mode

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

A Story About read() count = read(7, buf, sizeof (buf)); 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 to user buffer User process “wakes up”

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

Another Story About read() Disk: done! Asserts “interrupt request” signal CPU stops running P2's instructions Interrupts to kernel mode Runs “disk interrupt handler” code Kernel: switch to P1 Return from interrupt - but to P1, not P2! P2 is able to execute instructions, but not doing so P2 is not “blocked” It is “runnable” But it is not “running”

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

Interrupt Dispatch Table lookup Interrupt controller says: this is interrupt source #3 CPU fetches table entry #3 Table base-pointer programmed in OS startup Table-entry size defined by hardware Save old processor state Modify CPU state according to table entry Start running interrupt handler

Interrupt Return “Return from interrupt” operation Load saved processor state back into registers Restoring program counter reactivates “old” code Hardware instruction typically restores some state Kernel code must do the remainder

Example: x86/IA32 CPU saves old processor state Stored on “kernel stack” - picture follows 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” (IRET) instruction Registers loaded from kernel stack Mode switched from “kernel” to “user”

IA32 Single-Task Mode Example From intel-sys.pdf (please consult!) Picture: 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) IRET restores state from EIP, CS, EFLAGS

Race Conditions Two concurrent activities Computer program, disk drive Various execution sequences produce various “answers” Disk interrupt before or after function call? Execution sequence is not controlled So either outcome is possible “randomly” System produces random “answers” One answer or another “wins the race”

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 status Work in queue ⇒ transmit next request to disk Queue empty ⇒ let disk go idle Various execution orders possible Disk interrupt before or after “disk idle” test? System produces random “answers” “Work in queue ⇒ transmit next request” (good) “Work in queue ⇒ let disk go idle” (what??)

Race Conditions – Driver Skeleton dev_start(request) { if (device_idle) send_device(request); else enqueue(request); } dev_intr() { ...finish up previous request... if (new_request = head()) { send_device(new_request); } else device_idle = 1;

Race Conditions – Good Case

Race Conditions – Bad Case

What Went Wrong? “Top half” ran its algorithm Examine state Commit to action Interrupt handler ran its algorithm Various outcomes possible Depends on exactly when interrupt handler runs System produces random “answers” Study & avoid this in your P1!

Interrupt Masking Two approaches Temporarily suspend/mask/defer 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? PC hw makes this an interesting question... Avoid blocking too long Part of Project 1, Project 3 grading criteria

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

Timer – Why? Why interrupt a perfectly good execution? Avoid CPU hogs while (1) continue; 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

Summary Computer hardware CPU State Fairy tales about system calls CPU context switch (intro) Interrupt handlers Race conditions Interrupt masking Sample hardware device – countdown timer