Asynchronous Events on Linux

Similar documents
Kernel Korner AEM: A Scalable and Native Event Mechanism for Linux

Chapter 8: I/O functions & socket options

CISC2200 Threads Spring 2015

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

SMD149 - Operating Systems

Operating Systems 2010/2011

3.1 Introduction. Computers perform operations concurrently

Problem Set: Processes

Threads. CS3026 Operating Systems Lecture 06

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Module 12: I/O Systems

Problem Set: Processes

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Input/Output Systems

The control of I/O devices is a major concern for OS designers

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Operating System Structure

Process Description and Control

Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Lecture 2 Process Management

Process Description and Control. Chapter 3

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Processes. CS3026 Operating Systems Lecture 05

CHAPTER 3 - PROCESS CONCEPT

Processes and Threads

Definition Multithreading Models Threading Issues Pthreads (Unix)

Chapter 13: I/O Systems

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

A Scalable Event Dispatching Library for Linux Network Servers

Concurrent Programming

CS510 Operating System Foundations. Jonathan Walpole

Module 12: I/O Systems

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Chapter 4: Threads. Chapter 4: Threads

Threads Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 3: Processes. Operating System Concepts 9 th Edition

Chapter 3: Process Concept

Chapter 3: Process Concept

1 Multiprocessors. 1.1 Kinds of Processes. COMP 242 Class Notes Section 9: Multiprocessor Operating Systems

Lecture 8: Other IPC Mechanisms. CSC 469H1F Fall 2006 Angela Demke Brown

Chapter 3: Process Concept

Topics. Lecture 8: Other IPC Mechanisms. Socket IPC. Unix Communication

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

CS 322 Operating Systems Practice Midterm Questions

Operating Systems. Figure: Process States. 1 P a g e

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

Processes COMPSCI 386

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Process Scheduling Queues

Chapter 3: Processes. Operating System Concepts 8th Edition

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Computer Systems Assignment 2: Fork and Threads Package

Chapter 13: I/O Systems

Chapter 3 Process Description and Control

Exception-Less System Calls for Event-Driven Servers

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

CS2506 Quick Revision

Lecture 4: Process Management

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

ò mm_struct represents an address space in kernel ò task represents a thread in the kernel ò A task points to 0 or 1 mm_structs

CHAPTER 2: PROCESS MANAGEMENT

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

Chapter 4: Threads. Chapter 4: Threads

Process Description and Control. Chapter 3

Scheduling. Don Porter CSE 306

Virtual Memory COMPSCI 386

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Chapter 8: Virtual Memory. Operating System Concepts

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

(MCQZ-CS604 Operating Systems)

Computer Systems II. First Two Major Computer System Evolution Steps

Multithreaded Programming

238P: Operating Systems. Lecture 14: Process scheduling

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Process Description and Control

Introduction to Asynchronous Programming Fall 2014

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Multiprocessors 2007/2008

Lecture 15: I/O Devices & Drivers

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

IT 540 Operating Systems ECE519 Advanced Operating Systems

!! How is a thread different from a process? !! Why are threads useful? !! How can POSIX threads be useful?

The Kernel Abstraction

CS350: Final Exam Review

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

A process. the stack

Linux Driver and Embedded Developer

Transcription:

Asynchronous Events on Linux Frederic.Rossi@Ericsson.CA Open System Lab Systems Research June 25, 2002 Ericsson Research Canada

Introduction Linux performs well as a general purpose OS but doesn t satisfy most of Telecom requirements. Server platform operating systems must be: Linearly scalable, Have non-stop operations, Have soft real-time responsiveness. Look at standard mechanisms June 25, 2002 2 Ericsson Research Canada

Introduction Problems with the standard mechanisms Scalability: select() and poll() are O(n) interfaces, SIGIO requires de-multiplexing in O(n), Soft real-time responsiveness: Real-time signals have fixed priorities, RT signal priorities cannot be used to increase responsiveness, Reliability: RT signals and signals cannot live in the same world: order is not guaranteed, Signal delivery is guaranteed but not the number of signal delivered, Latency of signal delivery. June 25, 2002 3 Ericsson Research Canada

Introduction Problems with the standard mechanisms Multi-threading Standard mechanisms implies the use of multi-threading to handle multiple simultaneous connections, Requires locking mechanisms for concurrency, Increases scheduling latency, Resources consumer: 1 thread per connection, Difficult to port, to maintain. [threads] Implementation dependant, Many libraries are not thread-safe, Thread implementation is changing. June 25, 2002 4 Ericsson Research Canada

Introduction Alternative mechanism Event-driven mechanisms: One event per resource in input (socket, file, load, number of tasks ), Registration for interests in some events. No specific software architecture is required, Easier to program. Just provide call-backs for event handlers, Used whenever concurrency between data is not needed, Handlers for events are executed asynchronously, June 25, 2002 5 Ericsson Research Canada

Event-driven mechanisms Polling Processes Event Spawned processes User Events Jobs Asynchronous execution Handlers are executed asynchronously, This mechanism consumes no kernel resources, no CPU time. Traditional notification Kernel Asynchronous activation Synchronous vs. Asynchronous Execution June 25, 2002 6 Ericsson Research Canada

Event-driven mechanisms Existing asynchronous mechanisms Microsoft I/O completion port (IOCP): Completion ports are associated with descriptors, Use of threads to wait for completion, Applications are provided functions to get I/O completion packets from the IOCP, Must provide a valid pointer and length to data location. POSIX Asynchronous I/O (AIO): Notify user processes upon completion of some operations, Use of signals to notify users. Can use RT signals to take benefits of their priorities, Works on (file, socket) descriptors, Provides IOCP with RT signals. User processes must provide valid pointers to data location. June 25, 2002 7 Ericsson Research Canada

Event-driven mechanisms Existing asynchronous mechanisms Microsoft I/O completion port (IOCP): Not Linux!! POSIX Asynchronous I/O (AIO): Not yet supported on Linux, not fully supported by other Unix! Problems: Event completion is not transparent, Restricted to stream descriptors, Scalability, Soft real-time responsiveness. Our solution: the asynchronous event mechanism (AEM) June 25, 2002 8 Ericsson Research Canada

Asynchronous Event Mechanism Architecture overview General features It s a Linux kernel enhancement, Provides an event-driven methodology of development Scalability and soft real-time responsiveness! Spawned processes User kernel Events Jobs No multithreading; Executes user land call-backs from kernel space, User processes request interest in some events, and then do something else; Non blocking mechanism, Event loops are per process and handled from the kernel, User call-backs are executed by context-switching the current process. June 25, 2002 9 Ericsson Research Canada

Asynchronous Event Mechanism Architecture overview Technical features A set of new system calls for event registration, An event is an object in the system that is monitored periodically or awaiting for a change of state. Some Jobs run at the level of interrupt handlers attached to some process to monitor events, Example of events: asynchronous read on sockets, timers Unix process main () Job Job Job Event Event Event June 25, 2002 10 Ericsson Research Canada

Jobs Overview Jobs are processing elements executing inside the kernel at (soft) interrupt time, Light mechanism ; provide no execution context as opposed to processes or threads, Fast mechanism; jobs are highfrequency entities, Perfectly serialized ; a job run until completion before another one is executed, Benefit of SMP architecture ; jobs can execute in parallel, Jobs are used for event activation June 25, 2002 11 Ericsson Research Canada

Jobs States Reactive jobs These are jobs used to wait for some event, Explicitly awaken by the underlying implementation, Are not scheduled in order to reduce latency time of handler execution. Periodic jobs These are jobs used to periodically lookup for event, Inserted by the dispatcher into the scheduler queue, Are defined by a frequency and a timeout values, Timers are based on periodic jobs. Ready Job_enable() Job_disable() Running Job_lock() Suspended Block Lock Job_wake_up() Job_suspend_interruptible() Job_unlock() Suspended Unblock Job state automaton June 25, 2002 12 Ericsson Research Canada

Jobs Scheduling DB job I/O job 1 Job Dispatcher Job dispatcher Handle periodic jobs, Jobs are assigned an age spent in the queue, When a job s age reaches 0 then it becomes ready to execute, Insert ready to execute jobs into the scheduler queue. TCP job Job Scheduler Job scheduling I/O job 2 Job scheduler Update jobs state according to the automaton s rule Then execute the job, Jobs execute in parallel on SMP. June 25, 2002 13 Ericsson Research Canada

Events Overview Process Active events Event chain An event defines the execution context for a user land handler and a job, An event defines its relationship with other events (sibling, child, parent), A list of active events is maintained for each process, Active events for scheduled processes are checked during each clock tick. I/O job DB job TCP job List of events per process When an event is activated the corresponding handler is executed, Scalable! no single thread of control and fine grained mechanism. June 25, 2002 14 Ericsson Research Canada

Events Event created Process Child process User level Event chain Process I/O job DB job Event chain TCP job DB job Kernel level Event created processes New processes are created by event activations, Each process implements a resource container to handle event related data (jobs, handler arguments ), When creating a new process the parent can be told to not wait for its child when it exists. Event Handler execution June 25, 2002 15 Ericsson Research Canada

Events Two event handler types Handlers can either be serialized like signals or be forked processes, Process Process Process Process Handler1 Handler2 Event 1 Event 2 Forked event handlers Event 1 Event 2 Serialized event handlers June 25, 2002 16 Ericsson Research Canada

Memory Management Motivation In the POSIX definition for AIO a valid pointer must be provided by the application, In AEM we manage user process memory from inside the kernel. No need to pre-allocate memory from applications. This is handled at the time call-backs are executed, This pool can be used as a resource container for event related data. June 25, 2002 17 Ericsson Research Canada

Memory Management Motivation We implemented a specific buddy allocator in order to: Prevent memory fragmentation, swapping and page faulting caused by successive allocations, Encourage reuse of memory locations, Allocate quickly, No waste of resource. Memory space is requested when event handlers are executed, Provides fine grained blocks of different size for the applications, Provides big blocks to be used as pools, The size of blocks fits with the event requests, Can use mapping of user memory or direct copy to prevent a time consuming copy of data. June 25, 2002 18 Ericsson Research Canada

Scalability Fine grained mechanism No list of port to scan (select() is linear in the number of fd) Event data completion; no need to lookup for information (like for SIGIO) DB job I/O job 1 No single thread of control! TCP job Job Scheduler I/O job 2 June 25, 2002 19 Ericsson Research Canada

Soft real-time responsiveness Soft pre-emption We use event priorities to increase process weights, So that it influences scheduling decision regarding process selection, for a process P: srt_priority (P) = P activated event priorities and weight (P) = srt_base + srt_priority (P) Load control problem June 25, 2002 20 Ericsson Research Canada

Soft real-time responsiveness Load control It is based on the total number of event handlers executed in the system during the last second, The load is the number of estimated events per process per time slice, All processes are influenced equally. global estimation of event load, srt_base = max [0, cste calc_decay (load)], and calc_decay (load) is the proportional increase of the load, cste is the maximum allowed, load = elapsed second Hz now events tasks Thus conservation of order is insured in the same time interval, srt_priority ( P1) < srt_priority ( P 2 ) weight ( P1 ) < weight ( P2 ), June 25, 2002 21 Ericsson Research Canada

Soft real-time responsiveness Process time slice allocation It is computed when selected for the first time, Its allocated quantum of execution is proportional to its number of events, So that it gives a chance to other processes, Small quantum time values are allocated to event handlers to improve responsiveness ( 20 ms). for a process P: time_slice (P) = min [ weight ( P), cste] cste June 25, 2002 22 Ericsson Research Canada

Interface Actual AEM user interface Socket interface, eventdesc_t request (handler_t handler, unsigned long evflags,,,) Timer interface, ret is an event descriptor if the request is successful, Control functions. ret is negative if an error occurred. evflags tells how the handler is going to be executed: EVF_ONESHOT EVF_FORK EVF_NOCLDWAIT void handler (eventdesc_t ed,,,) June 25, 2002 23 Ericsson Research Canada

Interface Socket interface main () { int sfd = socket ( ); bind (sfd, ); listen (sfd, ); id = sockasync_accept (h_accept, 0, sfd); while (1); } void h_accept (jid_t id, int sfd, int nfd) { id = sockasync_read (h_read, EVF_FORK EVF_CLDNOWAIT, nfd);. id = sockasync_close (h_close, EVF_ONESHOT, nfd); } void h_read (jid_t id, int fd, char *data, int len) { } void h_close (jid_t id, int fd) { } June 25, 2002 24 Ericsson Research Canada

Interface Socket interface id = sockasync_sk (h_sk_state, EVF_FORK, sfd, TCP_ESTABLISHED); id = sockasync_sock (h_sock_state, 0, sfd, SS_CONNECTED); void h_sock_state (jid_t id, int fd, int state) { } void h_sk_state (jid_t id, int fd, int state) { } June 25, 2002 25 Ericsson Research Canada

Interface Timer interface Based on the implementation of periodic jobs, Must be provided with an interval and an optional period. main () { struct timespec interv; interv.tv_sec = 1; interv.tv_nsec = 0; evtimer (h_timer,0,&interv, NULL,); void h_timer (int id, struct timespec to) { printf ("Timer event desc. %d: %us: %uns\n", ed, to.tv_sec, to.tv_nsec); } } while (1); June 25, 2002 26 Ericsson Research Canada

Interface Control function Control function: evctl, Somewhat equivalent to ioctl, Controls event properties from the application. int id = sockasync_sk (h_connected, EVF_ONESHOT, sfd, TCP_ESTABLISHED); if (id<0) { perror ("sender sockasync: "); exit (1); } evctl (id, EVJOBPRIO, JOB_HIGH); Event Id Control flag Argument pointer/value June 25, 2002 27 Ericsson Research Canada

Performance Context-switch measurement Purpose is to run the AEM at full speed for the worst case, One opened socket, 50,000 ping-pong messages between two remote processes, Size of messages vary between 2 and 65536 bytes, Client is synchronous in both cases, Server is asynchronous with serialized event handlers. Not forked. June 25, 2002 28 Ericsson Research Canada

Performance Context-switch measurement Same graph for messages between 2 and 256 bytes with a larger scale. June 25, 2002 29 Ericsson Research Canada

Performance Context-switch measurement Same graph for messages between 2 and 65536 bytes with a larger scale. June 25, 2002 30 Ericsson Research Canada

Conclusion New model in the Unix world, Implemented in the Linux kernel 2.4.6, Ensure scalability, Ensure soft real-time responsiveness, Provide a secure event-driven interface to Linux for the development of highly available applications, Flexible: expandable with new system calls, June 25, 2002 31 Ericsson Research Canada

Thank you for your attention! June 25, 2002 32 Ericsson Research Canada