Chapter 6: Event Control Block (ECB)

Slides:



Advertisements
Similar presentations
The OS kernel: Implementing processes and Threads Kernel Definitions and Objects Queue Structures Threads Implementing Processes and Threads Implementing.
Advertisements

Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Real-Time Library: RTX
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Deadlocks, Message Passing Brief refresh from last week Tore Larsen Oct
Mike Holenderski, Synchronization 2IN60: Real-time Architectures (for automotive systems)
 Wind River Systems, Inc Chapter - 6 Semaphores.
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 6 Review I2C Communication, review fixed point arithmetic,
Embedded System Presentation Nguyễn Trần Quang Nguyễn Công Vũ 1µC/OS-II.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
IN2305-II Embedded Programming Lecture 7: More OS Services.
Final Labs. Labs  Providing the Wakeup-Highest Option in the OSFlagPost()  Providing Non-Destructive-Read Message API for Message Queue Management in.
Embedded Systems More Operating System Services C.-Z. Yang Sept.-Dec
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Multithreaded Web Server.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Kernel structure & Task management © P.J.Fondse April 2010.
The  C/OS-II Real-Time Operating System.  C/OS-II Real-time kernel –Portable, scalable, preemptive RTOS –Ported to over 90 processors Pronounced “microC.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
SYNCHRONIZATION Module-4. scheduling Scheduling is an operating system mechanism that arbitrate CPU resources between running tasks. Different scheduling.
2-1 The critical section –A piece of code which cannot be interrupted during execution Cases of critical sections –Modifying a block of memory shared by.
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic.
Real Time Operating Systems
FreeRTOS.
® 7-2 Semaphores 7.1Overview Binary Semaphores and Synchronization Mutual Exclusion.
2001 Networking Operating Systems (CO32010) 1. Operating Systems 2. Processes and scheduling 4.
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic.
MicroC/OS-II S O T R.  MicroC/OS-II (commonly termed as µC/OS- II or uC/OS-II), is the acronym for Micro-Controller Operating Systems Version 2.  It.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 7: Semaphore Management Seulki Lee 1. Semaphore?  A protocol mechanism offered by most multitasking kernels  Control access to a shared resource.
2-1 Chapter 2 Real-Time Systems Concepts. 2-2 Foreground/Background Systems BackgroundForeground ISR Time Code execution application consists of an infinite.
Chapter 3: Kernel Structure 1. Objectives To understand what a task is. To learn how μ C/OS-II manages tasks. To know how an interrupt service routine.
Synchronization Akos Ledeczi EECE 6354, Fall 2013 Vanderbilt University.
Big Picture Lab 4 Operating Systems C Andras Moritz
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Chapter 3: Kernel Structure 1. Objectives To understand what a task is. To learn how μ C/OS-II manages tasks. To know how an interrupt service routine.
Chapter 1: Getting Started with μC/OS-II 1. kernel Introduction 2 LinuxμC/OS-II Task (process) kernel Device driver User mode (0-3G) (Kernel mode) 3G-4G.
Chapter 5: Time Management 1. Time Management OSTimeDly() OSTimeDlyHMSM() OSTimeDlyResume() OSTimeGet() OSTimeSet() 2.
Outlines  Introduction  Kernel Structure  Porting.
Chapter 5 Time Management use clock tick to provide a periodic interrupt to keep track of time delays and timeouts The frequency of the clock tick depends.
Chapter 3: Kernel Structure
Chapter 1: Getting Started with μC/OS-II
REAL-TIME OPERATING SYSTEMS
Chapter 11: Message Queue Management
Chapter 4: Task Management
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Topics Covered What is Real Time Operating System (RTOS)
CS703 – Advanced Operating Systems
COT 4600 Operating Systems Fall 2009
Chapter 8: Mutual Exclusion Semaphores
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall2014 9/20/2018.
Concurrency: Mutual Exclusion and Synchronization
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall /27/2018.
Introduction to uC/OS-II
Semaphore Originally called P() and V() wait (S) { while S <= 0
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Lecture 2 Part 2 Process Synchronization
Computer Science & Engineering Electrical Engineering
Chapter 6 Synchronization Principles
Monitors and Inter-Process Communication
Chapter 3: Process Management
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Presentation transcript:

Chapter 6: Event Control Block (ECB)

Synchronization & Communication Semaphore (counting semaphore) Mutual Exclusion Semaphore (binary semaphore + PCP) Event Flag Communication Message Mailbox Message Queue

General operations OSXxxCreate OSXxxDel OSXxxPend OSXxxAccept Wait for Xxx OSXxxAccept A non-blocking version of OSXxxPend OSXxxPost Release Xxx OSXxxQuery

Blocking System call TaskA TaskB “Device Not Ready”

Nonblocking System call TaskA return -1 “Device Not Ready”

Asynchronous System call TaskA TaskA return 0 “Device Not Ready”

Semantics of ECB ECB (Event Control Block) An ISR or a task can signal an ECB Only a task can wait for an ECB (error!!!) An optional timeout can be specified in case the ECB is not signaled within the specified time period

Semantics of ECB Multiple tasks can wait for an ECB. Only the highest priority task (HPT) is made ready to run when the ECB is signaled. When a ECB is used as a semaphore, tasks can both wait and signal the ECB.

The use of ECB A building block to implement services such as Semaphore Mutual Exclusion Semaphore Message Mailbox Message Queue All ECB functions only consider how to manipulate data structures. Caller must consider synchronization issues

ECB data structure

Type of event control block Pointer to message or queue structure ECB data structure Type of event control block .OSEventType .OSEventGrp .OSEventCnt .OSEventPtr 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 . 55 54 53 52 51 50 49 48 63 62 61 60 59 58 57 56 ~ OSRdyGrp Semaphore Count… Pointer to message or queue structure ~ OSRdyTbl “red” fields are Initialized by OS_EventWaitListInit ~: is “similar to”

OSEventType OSEventGrp OSEventCnt OSEventPtr OSEventTbl[] OS_EVENT_TYPE_SEM OS_EVENT_TYPE_MUTEX 0x00 0x00 cnt prio OS_MUTEX_AVAILABLE NULL NULL 0x00 … 0x00 0x00 … 0x00 OS_EVENT_TYPE_QM Point to msg 0x00 OS_EVENT_TYPE_MBOX 0x00 … 0x00 0x00 cnt Point to Q 0x00 … 0x00

ECB Functions OS_EventWaitListInit() OS_EventTaskRdy() Initialize an ECB OS_EventTaskRdy() Make a task ready OS_EventTaskWait() Put the task to sleep OS_EventTO()

5 Task A ECB Task B ready queue (waiting queue) 2. OS_XXX_Post 1 ready queue 2. OS_XXX_Post (OS_Event_TaskRdy) 1. OS_XXX_Pend (OS_Event_TaskWait) Task A ECB (waiting queue) Task B 5

5 Task A ECB Task B ready queue (waiting queue) OS_XXX_Post 1 ready queue 2. OS_EventTO 1. OS_XXX_Pend (OS_Event_TaskWait) Task A OS_XXX_Post (OS_Event_TaskRdy) ECB (waiting queue) Task B 5

OS_EventWaitListInit() "loop unrolling"

OS_EventTaskRdy() This function is called by the POST functions for a semaphore, a mutex, a message mailbox or a message queue when the ECB is signaled. OS_EventTaskRdy() removes the highest priority task from the wait list of the ECB and makes this task ready to run.

OS_EventTaskRdy() - 1 EventGrp EventTbl Waiting Queue Ready Queue 1 1 OSRdyGrp EventGrp 1 1 1 EventTbl OSRdyTbl 1 1 1 1 1

OS_EventTaskRdy() - 2 EventGrp EventTbl Waiting Queue Ready Queue 1 1 OSRdyGrp EventGrp 1 EventTbl OSRdyTbl 1 1 1 1 1

OS_EventTaskRdy() - 3 EventGrp EventTbl Waiting Queue Ready Queue 1 1 OSRdyGrp EventGrp 1 1 EventTbl OSRdyTbl 1 1 1 1 1

OS_EventTaskRdy() - 4 Task Control Block (TCB) Event Control Block OSTCBDly=? 1 OSTCBEventPtr OSTCBStat 1 1 Task Control Block (TCB) Event Control Block (ECB)

OS_EventTaskRdy() - 5 Task Control Block (TCB) Event Control Block OSTCBDly=? 1 OSTCBEventPtr OSTCBStat 1 1 Task Control Block (TCB) Event Control Block (ECB)

OS_EventTaskRdy() - 6 Task Control Block (TCB) Event Control Block OSTCBDly=0 1 OSTCBEventPtr OSTCBStat ≒ Rdy 1 1 Task Control Block (TCB) Event Control Block (ECB)

OS_EventTaskRdy() INT8U OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk) { OS_TCB *ptcb; INT8U x, y, bitx, bity, prio; y = OSUnMapTbl[pevent->OSEventGrp]; bity = OSMapTbl[y]; x = OSUnMapTbl[pevent->OSEventTbl[y]]; bitx = OSMapTbl[x]; prio = (INT8U)((y << 3) + x); if ((pevent->OSEventTbl[y] &= ~bitx) == 0x00) pevent->OSEventGrp &= ~bity; ptcb = OSTCBPrioTbl[prio]; ptcb->OSTCBDly = 0; ptcb->OSTCBEventPtr = (OS_EVENT *)0; ptcb->OSTCBMsg = msg; ptcb->OSTCBStat &= ~msk; if (ptcb->OSTCBStat == OS_STAT_RDY) { OSRdyGrp |= bity; OSRdyTbl[y] |= bitx; } return (prio); Find highest priority task waiting for message Remove this task from the waiting list Prevent OSTimeTick() from readying task Unlink ECB from this task Clear bit associated with event type Set the task ready to run if the task is not suspended

OS_EventTaskWait() This function is called by the PEND functions for a semaphore, a mutex, a message mailbox or a message queue when a task must wait on an ECB. It removes the current task from the ready list and places it in the wait list of the ECB.

OS_EventTaskWait() - 1 EventGrp EventTbl Waiting Queue Ready Queue 1 1 OSRdyGrp EventGrp 1 1 EventTbl OSRdyTbl 1 1 1 1 1

OS_EventTaskWait() - 2 EventGrp EventTbl Waiting Queue Ready Queue 1 1 OSRdyGrp EventGrp 1 EventTbl OSRdyTbl 1 1 1 1 1

OS_EventTaskWait() - 3 EventGrp EventTbl Waiting Queue Ready Queue 1 1 OSRdyGrp EventGrp 1 1 1 EventTbl OSRdyTbl 1 1 1 1 1

Put task in waiting list OS_EventTaskWait() void OS_EventTaskWait (OS_EVENT *pevent) { OSTCBCur->OSTCBEventPtr = pevent; if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) { OSRdyGrp &= ~OSTCBCur->OSTCBBitY; } pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX; pevent->OSEventGrp |= OSTCBCur->OSTCBBitY; Task no longer ready Put task in waiting list

OS_EventTO() OS_EventTO = OS-Event-Time-Out This function is called by the PEND functions for a semaphore, a mutex, a message mailbox or a message queue when the ECB is not signaled within the specified timeout period.

Usage: OS_EventTaskRdy() Taski Taskj xxx_post() xxx_pend( 0 ) xxx_post() xxx_pend( 0 )

Usage: OS_EventTO() 1 3 2 Taski Taskj Taskj xxx_post() xxx_pend( 3 ) Waiting queue Ready queue xxx_post() xxx_pend( 3 ) xxx_post() xxx_pend( 0 ) 1 3 2

Remove the task from the waiting list of the ECB OS_EventTO() void OS_EventTO (OS_EVENT *pevent) { if ((pevent->OSEventTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) { pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY; } OSTCBCur->OSTCBStat = OS_STAT_RDY; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; Remove the task from the waiting list of the ECB