I/o multiplexing On adding a ‘poll()’ method to our character-mode device-driver for an 82573L network controller.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Another device-driver? Getting ready to program the network interface.
I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations.
Fixing some driver problems Most software is discovered to have some ‘design-flaws’ after it has been put into use for awhile.
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
The ‘system-call’ interface We see how an application program can invoke privileged kernel services.
Controlling concurrency A look at some techniques for process synchronization in the Linux environmemt.
The ‘fasync()’ driver-method Two viewpoints on implementing asynchronous notification: the application’s and the driver’s.
Operating Systems High Level View Chapter 1,2. Who is the User? End Users Application Programmers System Programmers Administrators.
UNIX Chapter 01 Overview of Operating Systems Mr. Mohammad A. Smirat.
Processes CSCI 444/544 Operating Systems Fall 2008.
A ‘ringbuffer’ application Introduction to process ‘blocking’ and the Linux kernel’s support for ‘sleeping’ and ‘waking’
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Standard C Library Application Programming Interface to System-Calls.
The UART alternative Substituting input from our PC’s serial-port for local keystrokes when we do ‘single-stepping’
Our ‘nic.c’ module We create a ‘character-mode’ device-driver for the 82573L NIC to use in future experiments.
The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction.
Kernel timing issues An introduction to the use of kernel timers and work queues.
Adjusting out device-driver Here we complete the job of modifying our ‘nicf.c’ Linux driver to support ‘raw’ packet-transfers.
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
Multiplexing i/o A look at some alternatives under Linux for dealing concurrently with multiple sources of device-input.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
COMP1070/2002/lec3/H.Melikian COMP1070 Lecture #3 v Operating Systems v Describe briefly operating systems service v To describe character and graphical.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
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.
المحاضرة الاولى Operating Systems. The general objectives of this decision explain the concepts and the importance of operating systems and development.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
X-WindowsP.K.K.Thambi The X Window System Module 5.
NETW 3005 Threads and Data Sharing. Reading For this lecture, you should have read Chapter 4 (Sections 1-4). NETW3005 (Operating Systems) Lecture 03 -
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 2.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
I/O Software CS 537 – Introduction to Operating Systems.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Chapter 16 Advanced Bourne Shell Programming. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To discuss numeric data processing.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
CS 6560: Operating Systems Design
Protection of System Resources
Introduction to Operating System (OS)
Threads and Data Sharing
Chapter 2: The Linux System Part 2
More examples How many processes does this piece of code create?
CS703 - Advanced Operating Systems
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Chapter 2: The Linux System Part 3
Threads Chapter 4.
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Lecture 6: Multiprogramming and Context Switching
Computer System Laboratory
Presentation transcript:

i/o multiplexing On adding a ‘poll()’ method to our character-mode device-driver for an 82573L network controller

An application idea We want to create an application program that would allow two users to conduct an on-line chat-session while working from two separate nodes on our ‘anchor’ cluster Whatever either user decides to type will be displayed on the both users’ screens To keep their two input-streams visually separated we want to use two ‘windows’

‘netchat.cpp’ Hello, Susan Hi, Paul _ Hi, Paul Hello, Susan _ anchor01anchor02 Whatever a user types will be displayed in the lower window on that user’s screen -- and in the upper window on the other user’s screen

Multiplexed input-streams In order to implement the foregoing idea, it’s necessary for the ‘netchat’ program to accept input from TWO hardware devices: –the keyboard (i.e., ‘standard input’ device) –the ethernet controller (i.e., ‘/dev/nic’) Such a situation is a fairly common one in UNIX/Linux application programming, and is referred to as ‘i/o multiplexing’

Device-driver’s role Special software support is needed within each of the device-drivers in order for any application-program to do ‘i/o multiplexing’ in a way that avoids wasting of CPU time (For an excellent discussion of the various approaches that can be taken to deal with this basic programming issue, see Richard Stevens: Advanced Programming in the UNIX Environment, Chapter 12)

The basic problem Normally when an application ‘reads’ from a device-file, that process will ‘sleep’ until some data is available from that device So if data becomes available on another device, it will not get processed because the application is ‘blocked’ from being given any CPU time by the OS scheduler This would spoil our ‘netchat’ application

‘read()’ causes ‘blocking’ ‘netchat’ application terminal Ethernet controller Whichever device the application attempts to read from, it will get ‘blocked’ until that device has some data to deliver read write

Do multiprocessing? One idea for getting around this ‘blocking’ problem would be to just use the ‘fork()’ system-call to create a separate process for reading from the different device-files Each process can sleep, and whichever process receives any new data will be awakened and scheduled for execution No changes needed to device-driver code

Different processes do ‘read()’ ‘netchat’ parent- process terminal Ethernet controller ‘netchat’ child-process read write Using multiple processes can overcome the ‘blocking-read’ problem, but complicates the code for program termination

Non-blocking ‘read’ It is possible for the application to request ‘non-blocking’ read-operations – i.e., any ‘read()’ calls will immediately return with 0 as return-value in case no data is available The standard-input device-driver already has support for this non-blocking option, and it can be easily added to the ‘read()’ function in network controller’s driver

Code-modification ssize_t my_read( struct file *file, char *buf, size_t len, loff_t *pos ) { static intrxhead = 0; // in case no new data has been received, then either // return immediately if non-blocking mode is in effect // or else sleep until some new data arrives (or until // the user hits -C to cancel execution) if ( rxhead == ioread32( io + E1000_RDH ) { if ( file->f_flags & O_NONBLOCK ) return 0; if ( wait_event_interruptible( wq_rx, rxring != ioread32( io + E1000_RDH ) ) return –EINTR; } …

Uses ‘busy-waiting’ loop ‘netchat’ application terminal Ethernet controller read write Using the ‘nonblocking-read’ option overcomes the problem of a sleeping task, but it wastefully consumes the CPU time write

The ‘elegant’ solution The ‘select()’ system-call provides a very general scheme for doing i/o-multiplexing in a manner that avoids wasting CPU time or making the program-code complicated But it does require adding an extra driver ‘method’ – the so-called ‘poll()’ function

The ‘select()’ arguments Using ‘select()’ requires an application to setup an ‘fd_set’ object, which defines the set of file-descriptors whose activity needs to be monitored by the Linux kernel (in our ‘netchat’ application this would be just the two device-files: the console keyboard and the gigabit ethernet network controller) This ‘fd_set’ object becomes an argument

Using ‘select()’ in ‘netchat’ intkbd = STDIN_FILENO;// keyboard ID intaux = open( “/dev/nic”, O_RDWR );// device-file ID fd_set permset;// create an ‘fd_set’ object FD_ZERO( &permset );// initialize it to ‘empty’ FD_SET( kbd, &permset );// add keyboard to set FD_SET( aux, &permset );// and add the nic to set while (1){ fd_setreadset = permset; if ( select( 1+aux, &readset, NULL, NULL, NULL ) < 0 ) break; if ( FD_ISSET( kbd, &readset ) ) { /* process keyboard input */ } if ( FD_ISSET( aux, &readset ) ) { /* process network input */ } }

How it works The ‘readset’ argument to the ‘select()’ system-call lets the kernel know which device-drivers should have their ‘poll()’ method invoked Then each device-driver’s ‘poll()’ method will perform a test to determine if any new data is ready to be read from that device So the application calls ‘read()’ only when a device is ready with data immediately

struct file_operations We need to include the function-pointer to our implementation for the ‘poll()’ method: struct file_operations my_fops ={ owner:THIS_MODULE, read:my_read, write:my_write, ioctl:my_ioctl, poll:my_poll, };

Our driver’s ‘poll()’ method Linux provides helper-functions to do most of the supporting work for use of ‘select()’ #include // for the ‘poll_wait()’ helper-function unsigned int my_poll( struct file *file, struct poll_table_struct *wait ) { unsigned intmask = 0; poll_wait( file, &wq_recv, wait ); if ( (ioread32( io + E1000_RDH ) != rxhead ) mask |= POLLIN | POLLRDNORM; returnmask; }

The ‘ncurses’ library Our ‘netchat’ application uses the Linux implementation for the UNIX ‘curses’ API This function-library includes routines that not only can manage the console’s cursor, but also implements ‘raw’ keyboard input (for instantaneous keystroke processing) and allows drawing of window-borders

Compiling ‘netchat’ The ‘g++’ compiler can compile-and-link in a single command: $ g++ netchat.cpp -l ncurses -o netchat The C++ source-file Lowercase letter ‘L’ (for library to link with) Name of the library Name for the compiler’s output-file

Try it out We can try running the ‘netchat’ program on any pair of our anchor-cluster stations Of course, we will first need to install our ‘nicpoll.ko’ device-driver module on each of those ‘anchor’ machines Then a user at either machine can type in any messages, and every character typed will be visible immediately on both screens

But… There is a slight problem with using the present version of our ‘nicpoll.c’ module All of the network packets are ‘broadcast’ to every station on the ‘anchor’ cluster! So any third-party who is simultaneously trying to use our network will be receiving all the packets that are being broadcast

In-class exercise Based on what you have learned from our past lessons, and from your reading of the Intel “Open Source Software Developer’s Manual” for its PCIe GbE Controllers, can you propose any ideas for using the NIC’s hardware capabilities so as to allow a pair of anchor-stations to use ‘netchat’ without any other anchor-stations being involved?