Embedded Systems: OS. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Similar documents
Embedded Systems: OS

Int tmytask() { while(1){ .. } }

Micrium µc/os II RTOS Introduction EE J. E. Lumpp

Lab 8 Real-time OS - 1

Introduction to Embedded Systems


Programming in Real-Time OS (uc/os-ii)

Real-time operating systems and scheduling

PROCESS SCHEDULING Operating Systems Design Euiseong Seo

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

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

PROCESS SCHEDULING II. CS124 Operating Systems Fall , Lecture 13

Microkernel/OS and Real-Time Scheduling

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Reference Model and Scheduling Policies for Real-Time Systems

Systemy RT i embedded Wykład 11 Systemy RTOS

Multiprocessor and Real-Time Scheduling. Chapter 10

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

Nios II. uc/os-ii porting with Nios II Altera Corporation

Computer Systems Laboratory Sungkyunkwan University

Announcements/Reminders

Tasks. Task Implementation and management

µc/os-ii for the Philips XA

Multimedia Systems 2011/2012

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Event-Driven Scheduling. (closely following Jane Liu s Book)

Concurrent Programming. Implementation Alternatives. Content. Real-Time Systems, Lecture 2. Historical Implementation Alternatives.

Concurrent Programming

An application-based EDF scheduler for OSEK/VDX

CS4514 Real Time Scheduling

REAL TIME OPERATING SYSTEM PROGRAMMING-I: VxWorks

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

Practice Exercises 305

Multiprocessor and Real- Time Scheduling. Chapter 10

AUTOBEST: A United AUTOSAR-OS And ARINC 653 Kernel. Alexander Züpke, Marc Bommert, Daniel Lohmann

Handout. The ARM Instruction Set. Real Time Systems. Real Time Operating Systems. Real Time System Organization. Classification of Real Time Systems

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

Scheduling Mar. 19, 2018

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

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

LECTURE 3:CPU SCHEDULING

8: Scheduling. Scheduling. Mark Handley

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

Real-Time Architectures 2004/2005

NuttX Realtime Programming

(b) External fragmentation can happen in a virtual memory paging system.

Exam Review TexPoint fonts used in EMF.

SMD149 - Operating Systems

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

CEC 450 Real-Time Systems

Learning Outcomes. Scheduling. Is scheduling important? What is Scheduling? Application Behaviour. Is scheduling important?

Real-Time and Concurrent Programming Lecture 6 (F6): Scheduling and bounded response times

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

6/17/2011. Real-time Operating Systems

Department of Computer Science Institute for System Architecture, Operating Systems Group REAL-TIME MICHAEL ROITZSCH OVERVIEW

Last Class: Processes

CSE 237A Middleware and Operating Systems. Tajana Simunic Rosing Department of Computer Science and Engineering University of California, San Diego.

Advanced Operating Systems (CS 202) Scheduling (1)

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Implementation Alternatives. Lecture 2: Implementation Alternatives & Concurrent Programming. Current Implementation Alternatives

Zilog Real-Time Kernel

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Implementing Scheduling Algorithms. Real-Time and Embedded Systems (M) Lecture 9

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

ZiLOG Real-Time Kernel Version 1.2.0

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

Threads Implementation. Jo, Heeseung

File System Internals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

The Real Time Thing. What the hack is real time and what to do with it. 22C3 30. December Erwin Erkinger e.at

Introduction to Real-Time Systems ECE 397-1

CS370 Operating Systems

NetBurner s uc/os RTOS Library

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Background. Contiguous Memory Allocation

A New Real-time Kernel development on an embedded platform

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

ICS Principles of Operating Systems

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

Lecture 2 Process Management

CHAPTER 2: PROCESS MANAGEMENT

REAL TIME OPERATING SYSTEMS: A COMPLETE OVERVIEW

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

Process Scheduling Part 2

Micriμm. Getting Started with Micriμm s. Matt Gordon, Sr. Applications Engineer. 9L05I Renesas Electronics America Inc.

CPU Scheduling: Objectives

Real-Time & Embedded Operating Systems

Real-Time Systems Hermann Härtig Real-Time Operating Systems Brief Overview

MARUTHI SCHOOL OF BANKING (MSB)

4/6/2011. Informally, scheduling is. Informally, scheduling is. More precisely, Periodic and Aperiodic. Periodic Task. Periodic Task (Contd.

RT extensions/applications of general-purpose OSs

Real-Time Systems. Real-Time Operating Systems

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

Operating Systems, Fall

2. Introduction to Software for Embedded Systems

The University of Missouri - Columbia Electrical & Computer Engineering Department ECE4220 Real-Time Embedded Computing

Lecture 12: An Overview of Scheduling Theory

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

Transcription:

Embedded Systems: OS Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

Standalone Applications Often no OS involved One large loop Microcontroller-based embedded systems 2

Real-Time OS Scheduling of threads (or tasks) Creation and termination of threads Timing of thread activations Synchronization Semaphores and locks Input and output Interrupt handling with predictable latency A small kernel size 3

Full-Fledged OS Applications are huge and complex Multiple processes Virtual memory Requires MMU-enabled CPU File systems with persistent storage Networking: TCP/IP stack Security: User vs. kernel space Windowing & GUI support 4

# of addr spaces: Classification # threads per addr space: One Many One MS/DOS Early Macintosh Many embedded OSes (VxWorks, μclinux, μc/os-ii,...) Many Traditional UNIX Mach, OS/2, Linux, Windows, Mac OS X, Solaris, HP-UX 5

Example: μc/os-ii

What is μc/os-ii? A priority-based preemptive RT kernel Memory footprint: ~20KB Written mainly in C (open but not free) Ported to over 100 processors Manage up to 64 tasks Support 8-bit to 64-bit processors GUI, file system, etc. modules available http://www.micrium.com 7

Task A task is a simple program that thinks it has the CPU all to itself Each task has Its own stack space A priority based on its importance A task contains your application code A task is an infinite loop 8

Task Example void Task (void *p_arg) { Do something with argument p_arg; Task initialization; for (;;) { Processing (your code) Wait for event; /* Time to expire.. */ /* Signal from ISR */ /* Signal from task */ Processing (your code) } } 9

Task Creation/Deletion A task is created by OSTaskCreate() Make the new task ready for multitasking The followings passed to the kernel Starting address Stack Priority Arguments passed to the task, etc. A task is deleted by OSTaskDel() 10

Task States Waits for time to expire, message, or signal Event Occurs or Timeout Waits for Event Context Switch Resides in ROM (non-active) Waits for Execution 11

Task Priority Max 64 priority levels 8 levels reserved for OS, 56 levels for user Low number means high priority Priority changed by OSTaskChangePrio() Suspending a task: OSTaskSuspend() Resuming a task: OSTaskResume() 12

Task Synchronization Semaphore Mailbox Message Queue OSSemPost() OSMboxPost() OSQPost() OSQPostFront() OSSemPend() OSMboxPend() OSQPend() 13

Semaphores OSSemPend() Counter-- If (counter < 0), the task is blocked and moved to the wait list A time-out value can be specified OSSemPost() Counter++ If (counter >= 0), the highest priority task in the wait list is removed from the wait list 14

Mailbox OSMboxPend() The message in the mailbox is retrieved If empty, the task is immediately blocked A time-out value can be specified OSMboxPost() A message is posted in the mailbox If there is already a message, returns an error The task with the highest priority is removed from the wait list and scheduled to run 15

Message Queues OSQPend() A message is removed from queue If empty, the task is moved to the wait list and becomes blocked OSQPost()/OSQPostFront() A message is appended to the queue OSQPost(): FIFO, OSQPostFront(): LIFO The highest-priority pending task receives the message and scheduled to run, if any 16

Memory Management To reduce memory fragmentation Use of memory blocks with fixed size All blocks same size The size of blocks is configurable Creation of a memory partition: OSMemCreate() Requesting a memory block: OSMemGet() Releasing a memory block; OSMemPut() 17

Real-Time Scheduling

Real-Time Systems Perform a computation to conform to external timing constraints Deadline frequency: periodic vs. aperiodic Deadline type: Hard: failure to meet deadline causes system failure Soft: failure to meet deadline causes degraded response (best effort, statistical guarantees) 19

Periodic vs. Aperiodic Tasks Periodic task: executes on (almost) every period Aperiodic task: executes on demand Analyzing aperiodic task sets is harder Must consider worst-case combinations of task activations 20

Real-Time Workload Job (unit of work) A computation, a file read, a message transmission, etc. Attributes Resources required to make progress Timing parameters Released Execution time Absolute deadline Relative deadline 21

Real-Time Task Task: a sequence of similar jobs Periodic task (p, e) Its jobs repeat regularly Period p = inter-release time (0 < p) Execution time e = maximum execution time (0 < e < p) Utilization U = e/p 0 5 10 15 22

Real-Time Scheduling Schedulability Property indicating whether a real-time system (a set of real-time tasks) can meet their deadlines Real-time scheduling Determines the order of real-time task executions Static-priority scheduling: RM Dynamic-priority scheduling: EDF 23

Simple Feasibility Test Assume: No resource conflicts Constant process execution times Require: T i T i Can t use more than 100% of the CPU T 1 T 2 T 3 T 24

RM Rate Monotonic Optimal static-priority scheduling Assigns priority according to period A task with a shorter period has a higher priority T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 25

RM Rate Monotonic Executes a job with the shortest period T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 26

RM Rate Monotonic Executes a job with the shortest period Deadline Miss! T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 27

RM Utilization bound Real-time system is schedulable under RM if 1/ n U i n(2 1) Example: T 1 (4,1), T 2 (5,1), T 3 (10,1) Ui 1/ 4 1/ 5 1/10 0.55 3(2 1/3 1) 0.78 Thus, {T 1, T 2, T 3 } is schedulable under RM. 28

Utilization bound (cont d) RM 1/ n U i n(2 1) Utilization 1.1 1 0.9 0.8 0.7 0.6 0.5 RM Utilization Bounds 1 4 16 64 256 1024 4096 The Number of Tasks ~ 69% 29

RM As the number of tasks approaches infinity, the maximum utilization approaches 69% RM cannot use 100% of CPU, even with zero context switch overhead Must keep idle cycles available to handle worst-case scenario However, RM guarantees all tasks will always meet their deadlines 30

EDF Earliest Deadline First Optimal dynamic priority scheduling Task with a shorter deadline has higher priority Executes a job with the earliest deadline T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 31

EDF Earliest Deadline First Executes a job with the earliest deadline T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 32

EDF Earliest Deadline First Executes a job with the earliest deadline T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 33

EDF Earliest Deadline First Executes a job with the earliest deadline T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 34

EDF Optimal scheduling algorithm If there is a schedule for a set of real-time tasks, EDF can schedule it T 1 T 2 (4,1) (5,2) T 3 (7,2) 5 10 15 35

EDF Utilization bound Real-time system is schedulable under EDF if and only if U i 1 (cf.) Liu & Layland, Scheduling algorithms for multiprogramming in a hard-real-time environment, Journal of ACM, 1973. 36

RM vs. EDF (1) Rate Monotonic Simpler implementation, even in systems without explicit support for timing constraints Predictability for the highest priority tasks EDF Full processor utilization Implementation complexity and runtime overhead due to dynamic priority management Misbehavior during overload conditions 37

RM vs. EDF (2) Assumptions All tasks are periodic and fully preemptible All tasks are released at the beginning of period and have a deadline equal to their period All tasks are independent All tasks have a fixed computation time No task may voluntarily suspend itself All overheads are assumed to be 0 There is just one processor 38