Processes (Tasks) and operating systems. Why multiple processes? Example: engine control

Similar documents
Reminder. Final exam. Tentative time: December 6th, 4:30pm-5:45pm Location: G26. ECE 1160/2160 Embedded System Design 1

Multitasking Operating Systems

2. Introduction to Software for Embedded Systems

Motivation. Reactive Systems. This Week s Topic. CprE 488 Embedded Systems Design. Lecture 5 Embedded Operating Systems

CprE 488 Embedded Systems Design. Lecture 5 Embedded Operating Systems

SMD149 - Operating Systems

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Multiprocessor and Real- Time Scheduling. Chapter 10

Timers 1 / 46. Jiffies. Potent and Evil Magic

Operating Systems. Scheduling

REAL TIME OPERATING SYSTEM PROGRAMMING-I: VxWorks

Processes and Multitasking

238P: Operating Systems. Lecture 14: Process scheduling

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

Scheduling Algorithm and Analysis

Process Scheduling Part 2

CS-537: Midterm Exam (Spring 2001)

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

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Lecture 2 Process Management

EECS 482 Introduction to Operating Systems

8: Scheduling. Scheduling. Mark Handley

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Outline. Introduction. Survey of Device Driver Management in Real-Time Operating Systems

EECS 571 Principles of Real-Time Embedded Systems. Lecture Note #10: More on Scheduling and Introduction of Real-Time OS


Real-time operating systems and scheduling

1.1 CPU I/O Burst Cycle

Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for s,...).

3.1 Introduction. Computers perform operations concurrently

Asynchronous Events on Linux

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

Commercial Real-time Operating Systems An Introduction. Swaminathan Sivasubramanian Dependable Computing & Networking Laboratory

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Embedded System Design

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

Processes and Threads. From Processes to Threads. The Case for Threads. The Case for Threads. Process abstraction combines two concepts.

Unit 3 : Process Management

CS 153 Design of Operating Systems Winter 2016

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

CS3733: Operating Systems

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Midterm Exam Amy Murphy 19 March 2003

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

NuttX Realtime Programming

Problem Set: Processes

Multimedia-Systems. Operating Systems. Prof. Dr.-Ing. Ralf Steinmetz Prof. Dr. rer. nat. Max Mühlhäuser Prof. Dr.-Ing. Wolfgang Effelsberg

Lab 8 Real-time OS - 1

518 Lecture Notes Week 3

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Predictable Interrupt Management and Scheduling in the Composite Component-based System

Introduction to Embedded Systems

Problem Set: Processes

A Predictable RTOS. Mantis Cheng Department of Computer Science University of Victoria

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

Concurrent activities in daily life. Real world exposed programs. Scheduling of programs. Tasks in engine system. Engine system

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Last class: Today: Thread Background. Thread Systems

CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

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

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

OPERATING SYSTEM CONCEPTS UNDERSTAND!!! IMPLEMENT!!! ANALYZE!!!

CS450/550 Operating Systems

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Lecture 4: Threads; weaving control flow

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

Process Description and Control

Back to RTOS. CSE466 Autumn 00-1

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

CS450/550 Operating Systems

QUESTION BANK UNIT I

THREADS ADMINISTRIVIA RECAP ALTERNATIVE 2 EXERCISES PAPER READING MICHAEL ROITZSCH 2

15: OS Scheduling and Buffering

Administration. Matteo Corti RZ H

MC7204 OPERATING SYSTEMS

Tasks. Task Implementation and management

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Systems software design. Processes, threads and operating system resources

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

NAME: KEY (FIRST NAME FIRST) TOTAL:

POSIX Threads Programming

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Midterm Exam. October 20th, Thursday NSC

Preemptive Scheduling

* What are the different states for a task in an OS?

Introduction Programmer Interface User Interface Process Management Memory Management File System I/O System Interprocess Communication

CHAPTER NO - 1 : Introduction:

ECE 574 Cluster Computing Lecture 8

CS370 Operating Systems

Systemy RT i embedded Wykład 11 Systemy RTOS

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institution of Technology, IIT Delhi

CSE 153 Design of Operating Systems Fall 2018

Scheduling - Overview

Transcription:

Processes (Tasks) and operating systems Motivation for processes. The process abstraction. Context switching. Multitasking. Processes and UML. Operating systems Why multiple processes? Processes help us manage timing complexity: multiple rates multimedia automotive asynchronous input user interfaces communication systems Example: engine control Tasks: spark control crankshaft sensing fuel/air mixture oxygen sensor Kalman filter state machine engine controller 1

Life without processes Code turns into a mess: interruptions of one task for another spaghetti code time A B C A C A_code(); B_code(); if (C) C_code(); A_code(); switch (x) { case C: C(); case D: D();... Co-routine methodology Co-routines are cooperating subroutines where: Unlike a subroutine, the caller determines the return address. Co-routines voluntarily give up control to other co-routines. Pattern of control transfers is embedded in the code. Co-routine Example Co-routine 1 Co-routine 2 ADR r14,co2a co2a co1a ADR r13,co2b ADR r13,co1b MOV r15,r13 MOV r15,r14 co2b co1b ADR r13,co2c ADR r13,co1c MOV r15,r13 MOV r15,r14 co2c co1c... 2

Processes / Tasks A process is a unique execution of a program. Several copies of a program may run simultaneously or at different times. A process has its own state: registers; memory. The operating system manages processes. Processes and CPUs Activation record: copy of process state. Context switch: current CPU context goes out; new CPU context goes in. process 1 process 2... PC registers CPU memory Terms Thread = lightweight process: a process that shares memory space with other processes. Reentrancy: ability of a program to be executed several times with the same results. 3

Processes in POSIX Create a process with fork: parent process keeps executing old program; child process executes new program. process a process a process b POSIX fork() The fork process creates child: childid = fork(); if (childid == 0) { /* child operations */ } else { /* parent operations */ } POSIX execv() Overlays child code: childid = fork(); if (childid == 0) { execv( mychild,childargs); perror( execv ); exit(1); } file with child code 4

Context switching A context switch is the transfer of use of the CPU from one executing process to another. Who controls when the context is switched? How is the context switched? Co-operative multitasking Improvement on co-routines: hides context switching mechanism; still relies on processes to give up CPU. Each process allows a context switch at cswitch() call. Separate scheduler chooses which process runs next. Problems with co-operative multitasking Programming errors can keep other processes out: process never gives up CPU; process waits too long to switch, missing input. 5

Context switching Must copy all registers to activation record, keeping proper return value for PC. Must copy new activation record into CPU state. How does the program that copies the context keep its own context? - stack for fixed number of processes. - task control block for a dynamic or indeterminate number of processes. Preemptive multitasking Most powerful form of multitasking: OS controls when contexts switches; OS determines what process runs next. Use timer to call OS, switch contexts: interrupt CPU timer Flow of control with preemption interrupt interrupt P1 OS P1 OS P2 time 6

Preemptive context switching Timer interrupt gives control to OS, which saves interrupted process s state in an activation record. OS chooses next process to run. OS installs desired activation record as current CPU state. Why not use interrupts? We could change the interrupt vector at every period, but: we would need management code anyway; we would have to know the next period s process at the start of the current process. Operating systems The operating system controls resources: who gets the CPU; when I/O takes place; how much memory is allocated. The most important resource is the CPU itself. CPU access controlled by the scheduler. 7

Process State or Task Control Model A process can be in one of three states: executing on the CPU; ready to run; waiting for data. gets CPU ready executing preempted gets data needs data needs data gets data and CPU waiting Operating system structure OS needs to keep track of: process priorities; scheduling state; process activation record. Processes may be created: statically before system starts; dynamically during execution. Embedded vs. generalpurpose scheduling Workstations try to avoid starving processes of CPU access. Fairness implies that all processes have equal access to CPU. Embedded systems must meet deadlines. Low-priority processes may not run for a long time. 8

Time quanta Quantum: unit of time for scheduling. Priority-driven scheduling Each process has a priority. CPU goes to highest-priority process that is ready. Priorities determine scheduling policy: fixed priority; time-varying priorities. Priority-driven scheduling example Rules: each process has a fixed priority (1 highest); highest-priority ready process gets CPU; process continues until done or wait state. Processes P1: priority 1, execution time 10 P2: priority 2, execution time 30 P3: priority 3, execution time 20 Initially: P2 is ready to run when the system is started. P1 s data arrives at time=15. P3 s data arrives at time=18 9

Priority-driven scheduling example P3 ready t=18 P2 ready t=0 P1 ready t=15 P2 P1 P2 P3 0 10 20 30 40 50 60 time The scheduling problem Can we meet all deadlines? Must be able to meet deadlines in all cases. How much CPU horsepower do we need to meet our deadlines? Process initiation disciplines Periodic process: executes on (almost) every period. Aperiodic process: executes on demand. Analyzing aperiodic process sets is harder- --must consider worst-case combinations of process activations. 10

Timing requirements on processes Execution time: amount of time it takes for a process to run. Period: interval between process activations. Initiation interval: reciprocal of period. Initiation time: time at which process becomes ready. Deadline: time at which process must finish. (generally, period = deadline) Timing violations What happens if a process doesn t finish by its deadline? Hard deadline: system fails if missed. Soft deadline: user may notice, but system doesn t necessarily fail. Example: Space Shuttle software error Space Shuttle s first launch was delayed by a software timing error: Primary control system PASS and backup system BFS. BFS failed to synchronize with PASS. Change to one routine added delay that threw off start time calculation. 1 in 67 chance of timing problem. 11

Interprocess communication Interprocess communication (IPC): OS provides mechanisms so that processes can pass data. Two types of semantics: blocking: sending process waits for response; non-blocking: sending process continues. IPC styles Shared memory: processes have some memory in common; must cooperate to avoid destroying/missing messages. Message passing: processes send messages along a communication channel---no common address space. Shared memory Shared memory on a bus: memory CPU 1 CPU 2 12

Race condition in shared memory Problem when two CPUs try to write the same location: CPU 1 reads flag and sees 0. CPU 2 reads flag and sees 0. CPU 1 sets flag to one and writes location. CPU 2 sets flag to one and overwrites location. Atomic test-and-set Problem can be solved with an atomic (un-interruptable) test-and-set: single bus operation reads memory location, tests it, writes it. ARM test-and-set provided by SWP: ADR r0,semaphore LDR r1,#1 GETFLAG SWP r1,r1,[r0] BNZ GETFLAG Critical regions Critical region: section of code that cannot be interrupted by another process. Examples: writing shared memory; accessing I/O device. 13

Semaphores Semaphore: OS primitive for controlling access to critical regions. Protocol: Get access to semaphore with P(). Perform critical region operations. Release semaphore with V(). Message passing Message passing on a network: CPU 1 CPU 2 message message message Process data dependencies One process may not be able to start until another finishes. Data dependencies defined in a task graph. All processes in one task run at the same rate. P1 P3 P4 P2 14

Other operating system functions Date/time. File system. Networking. Security. 15