Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum 2.3.2.

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
1 Homework Reading (linked from my web page) –S and S Extracts –National Semiconductor UART Data Sheet Machine Projects –mp2 due at start of class 12 Labs.
1 Implementations: User-level Kernel-level User-level threads package each u.process defines its own thread policies! flexible mgt, scheduling etc…kernel.
Chapter 2 Processes and Threads
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Mutual Exclusion.
Interprocess Communication
EEE 435 Principles of Operating Systems Interprocess Communication Pt I (Modern Operating Systems 2.3)
1 Homework Reading –Review previous material on “interrupts” Machine Projects –MP4 Due today –Starting on MP5 (Due at start of Class 28) Labs –Continue.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Implementing interrupt driven IO. Why use interrupt driven IO? Positive points –Allows asynchronous operation of IO events –Good use of resources –Leads.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Chapter 2.3 : Interprocess Communication
Homework / Exam Return and Review Exam #1 Reading Machine Projects
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
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.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
Mutual Exclusion. Readings r Silbershatz: Chapter 6.
More on UART Interrupts; System Calls Reference on Interrupt Identification Register(IIR) slide 17 of
Programming the I/O Hardware Reference: –textbook: Tanenbaum ch.5.1 – s.htmlwww.cs.umb.edu/ulab/UsingCforHardwareReg.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
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.
Thread Implementations; MUTEX Reference on thread implementation –text: Tanenbaum ch. 2.2 Reference on mutual exclusion (MUTEX) –text: Tanenbaum ch
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
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.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Discussions on hw1 Objectives –Modify I/O library for serial ports –change from ring buffer to queue –implement interrupts I/O Library TTY0TTYn testio.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Homework Reading Machine Projects
Interprocess Communication Race Conditions
Protection of System Resources
Homework Reading Labs S&S Extracts ,
Homework Reading Machine Projects Labs
Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch Receiver Interrupt Program Example:
More on UART Interrupts; System Calls
Discussions on hw1 Objectives Modify I/O library for serial ports
Operating Systems Chapter 5: Input/Output Management
Thread Implementations; MUTEX
Transmitter Interrupts
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Thread Implementations; MUTEX
CS333 Intro to Operating Systems
COMP3221: Microprocessors and Embedded 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:

Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum 2.3.2

Review of Interrupts Bus Com Port

Review of x86 Receiver Interrupts UART receives a character and signals an interrupt on a bus line. Programmable Interrupt Controller(PIC) detects the signal. If no pending interrupts are pending, it services the interrupt immediately. If another one is in progress or a higher priority one is pending, the device is ignored. It continues to assert the interrupt signal until it is serviced. To handle the interrupt, the controller puts an interrupt vector number (e.g 0x23 for COM2) on the data bus and asserts a signal (INTR) to interrupt the CPU.

x86 Receiver Interrupts (cont’d) CPU stops what it is doing and starts doing something else. CPU uses the interrupt vector number to index the IDT (interrupt descriptor table) and find the interrupt vector (i.e. address of the interrupt service routine) CPU runs the service routine which includes writing a certain value(EOI) to the interrupt controller’s I/O port to ack the interrupt

Example Program for COM2 receiver interrupts Look at RT_Receiver_interrupts.htm –Steps 1-5:initialization steps –Step 6: wait forever loop –Steps 10-13:shut down interrupts –Steps 7-9:interrupt handler, need the envelope routine Routines pic_end_int(), pic_enable_irq(), pic_disable_irq() are functions implemented in the SAPC library in directory $pclibsrc Look at $pcinc for include files

How About Transmitter Interrupts? Details on programming UART registers –slide 14 of Use Programmed I/O Set up a loop for the number of characters in the string check the transmit-ready(THRE) bit of the LSR Register if on, write the char to UART_TX register otherwise, loop Use Interrupt-driven I/O

Transmitter Interrupts Each interrupt signals readiness to output another byte of data The transmitter ISR gives another byte to output Issues to consider: –How to distinguish the Tx from Rx interrupts since they share one interrupt line(e.g. IRQ3 for COM2)? –what to do when data runs out? –How to start/restart the Tx interrupt?

How to Distinguish the Interrupts? One interrupt service routine to perform both Tx and Rx functions Check the UART ’ s LSR to see if Data Ready (DR) bit or the Transmit Holding Register(THRE) bit is set. Then execute the corresponding function. Any one of the 3 situations can happen: –Both Tx and Rx interrupts are ready –Only Tx interrupt is ready –Only Rx interrupt is ready

What to Do when Tx Data Runs Out ? THRE bit set to 1 when the UART hardware is ready to accept a new character for transmission. THRE bit set to 0 after UART_Tx register is loaded with a new character. If there is a Tx interrupt, dequeue a character and output it. Shut down the Tx interrupt when queue is empty. Rx interrupts need to be on continuously. Tx interrupts go on and off depending on output availability.

The Transmitter Strategy Set up interrupt gate in IDT, but leave Tx interrupt off in the UART. To load a string (n chars) into queue: –1. Load the first part of the string into the output buffer (i.e. enqueue the chars until the queue is full (Qmax)). –2. Turn Tx interrupt on in the UART_IER. –3. While the interrupt is ongoing, loop over the enqueuing of the rest of the chars. –4. Return when all chars have been enqueued. To output the chars in the queue: –1. Check if the queue is empty. –2. If there are chars, dequeue one and output it to UART_TX. –3. If there none, shut down Tx interrupt in the UART_IER.

An Example write(TTY1, “ ”, 9) with nchar = 9 and Qmax = 6 –1. “ ” put in queue during the setup in ttywrite –2. “ 123 ” output,one by one, by ISR –3. “ 789 ” get loaded in the queue in ttywrite –4. ttywrite returns after all nchar in queue –5. ttywrite has returned, but 6 chars “ ” are still in the queue. They are outputted one by one by ISR

Timeline Representation Outb: ISR: ttywrite: setup loop of enq ’ s testio: ttywrite rest of testio Note: 1. Still have a busy loop in ttywrite, i.e. loop of enq ’ s 2. OK for hw1. Fix it later using a scheduler 3. Could have a race condition due to concurrent activities on modifying the queues

The Race Condition 2 concurrent activities occur when executing ttywrite –ttywrite looping on enqueues –intermittent ISR executing a dequeue –working with the same queue (tty->tbuf) Interrupt can occur between 2 machine instructions. in ttywrite if (enqueue( &(tty->tbuf), buf[i])) i++; during enqueue function, ISR calling dequeue functioncan mess up the queue data structure

How to Avoid the Race Condition This part of program is called critical region or critical section when it accesses shared memory. Use mutual exclusion to make sure one part of program is using the shared variable while the other part is excluded from doing the same thing. Four conditions to provide mutual exclusion: –No two processes simultaneously in critical region –No assumptions made about speeds or numbers of CPUs –No process running outside its critical region may block another process –No process must wait forever to enter its critical region

Mutual Exclusion Using Critical Regions

Mutual Exclusion with Busy Waiting Disabling Interrupts Locked Variables Strict Alternation Peterson ’ s Solution Test and Set Lock (TSL)

Turning off Interrupts in ttywrite We can turn off interrupts during the execution of enqueue and turn them on when enqueue is done How to do it: cli();/* disable interrupts in CPU by setting IF=0 in EFLAGS*/ enqueue(…);/* critical region code */ sti();/* or set_eflags(save_eflags) to re-enable interrupts */

Important to turn off interrupts before using printf Prevent part of the code to do programmed I/O and another one doing interrupt-driven I/O using the Tx of the UART kprintf(…) is the printf routine that turns off interrupts: int saved_eflags; save_eflags = get_eflags(); cli(); printf(…); /* SAPC-library printf uses programmed I/O */ set_eflags(saved_eflags); Turning off Interrupts in printf

Echoes Characters to be echoed are generated in the input interrupt handler One copy is enqueued in the input queue and another in an output echo queue When the Tx ISR runs, it should look first in the echo queue. The user sees the echo as soon as possible