Scheduling in µC/OS-III

Slides:



Advertisements
Similar presentations
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Advertisements

Real-Time Library: RTX
CSCI 4717/5717 Computer Architecture
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
MicroC/OS-II Embedded Systems Design and Implementation.
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Nachos Phase 1 Code -Hints and Comments
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.
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Getting Started with the µC/OS-III Real Time Kernel Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
Scheduling in µC/OS-III Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CS140 Project 1: Threads Slides by Kiyoshi Shikuma.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Multi-Tasking The Multi-Tasking service is offered by VxWorks with its real- time kernel “WIND”.
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.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
1 Round Robin Non-Preemptive Scheduler Lecture 12.
Synchronization Akos Ledeczi EECE 6354, Fall 2013 Vanderbilt University.
Chapter 13: Porting μC/OS-II 1. Outline Requirements Hardware Software Tasks of Porting µC/OS-II OS_CPU_C.H OS_CPU_C.C OS_CPU_A.ASM Testing a port 2.
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.
Outlines  Introduction  Kernel Structure  Porting.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
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.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
REAL TIME OPERATING SYSTEM
REAL-TIME OPERATING SYSTEMS
Limited Direct Execution
Chapter 13: Porting μC/OS-II
PROCESS MANAGEMENT IN MACH
Topics Covered What is Real Time Operating System (RTOS)
CS703 – Advanced Operating Systems
Mechanism: Limited Direct Execution
Interrupt and Time Management in µC/OS-III
Round Robin Non-Preemptive Scheduler
Getting Started with the µC/OS-III Real Time Kernel
Chapter 10 And, Finally... The Stack
Computer System Overview
Introduction What is an operating system bootstrap
Processor Fundamentals
BIC 10503: COMPUTER ARCHITECTURE
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Processes David Ferry CSCI 3500 – Operating Systems
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CS333 Intro to Operating Systems
Processes and Process Table
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
Computer System Laboratory
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:

Scheduling in µC/OS-III Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University

Ready “List” Not a simple linked list of tasks ordered by priority Priority bitmap: Helps quickly identify the highest priority level that has at least one task ready to run Count Leading Zeros (CLZ) instruction in many CPUs Actual list is an array of ready lists: one for each priority level

Ready “List” OS Tasks: Empty list:

Ready “List” Adding a task always puts it at the end of the list

Preemptive Scheduling: Direct Post

Preemptive Scheduling: Deferred Post

Scheduling Points Post (unless call made with OS_OPT_POST_NO_SCHED) Call delay Pend (unless event has already occurred) Abort pend (only by another task of course) Task creation Task deletion Kernel object deletion (tasks pending on these become ready) Priority change Suspend Resume (only by another task of course) End of all nested ISRs (OSIntExit() instead of OSSched()) Scheduler unlock (only final unlock as locking the scheduler can be nested) Yield in round robin scheduling Explicitly calling the scheduler

Round Robin Scheduling Time Slicing Must call OSSchedRoundRobinCfg() to enable round robin scheduling Yield Time quanta can be set on a per task basis Time quanta can be changed at run-time

Scheduling from Task Level void OSSched (void) { Disable interrupts if (OSIntNestingCtr > (OS_NESTING_CTR)0) { /* ISRs still nested? */ return; /* only schedule when no nested ISRs */ } if (OSSchedLockNestingCtr > (OS_NESTING_CTR)0) { /* Scheduler locked? */ return; /* Yes */ OSPrioHighRdy = OS_PrioGetHighest(); /* Find the highest priority ready */ OSTCBHighRdyPtr = OSRdyList[OSPrioHighRdy].HeadPtr; if (OSTCBHighRdyPtr == OSTCBCurPtr) { /* Current is still highest priority task? */ Enable interrupts /* Yes ... no need to context switch */ return; OSTaskCtxSwCtr++; /* Increment context switch counter */ OS_TASK_SW(); /* Perform a task level context switch */ Enable interrupts

Scheduling from Interrupt Level void OSIntExit (void) { Disable interrupts if (OSIntNestingCtr == (OS_NESTING_CTR)0) { /* Prevent OSIntNestingCtr from wrapping */ return; } OSIntNestingCtr--; if (OSIntNestingCtr > (OS_NESTING_CTR)0) { /* ISRs still nested? */ Enable interrupts /* Yes */ if (OSSchedLockNestingCtr > (OS_NESTING_CTR)0) { /* Scheduler still locked? */ OSPrioHighRdy = OS_PrioGetHighest(); /* Find highest priority */ OSTCBHighRdyPtr = OSRdyList[OSPrioHighRdy].HeadPtr; /* Get highest priority task ready-to-run */ if (OSTCBHighRdyPtr == OSTCBCurPtr) { /* Current task still the highest priority? */ OSTaskCtxSwCtr++; /* Keep track of the total number of ctx switches */ OSIntCtxSw(); /* Perform interrupt level ctx switch */ Enable interrupts

Round Robin Scheduling #if OS_CFG_SCHED_ROUND_ROBIN_EN > 0u void OS_SchedRoundRobin (OS_RDY_LIST *p_rdy_list) { OS_TCB *p_tcb; if (OSSchedRoundRobinEn != DEF_TRUE) { /* Make sure round-robin has been enabled */ return; } CPU_CRITICAL_ENTER(); p_tcb = p_rdy_list->HeadPtr; if (p_tcb == (OS_TCB *)0) { CPU_CRITICAL_EXIT(); return; if (p_tcb == &OSIdleTaskTCB) { if (p_tcb->TimeQuantaCtr > (OS_TICK)0) { p_tcb->TimeQuantaCtr--; /* Decrement time quanta counter */ if (p_tcb->TimeQuantaCtr > (OS_TICK)0) { /* Task not done with its time quanta */ CPU_CRITICAL_EXIT(); return; if (p_rdy_list->NbrEntries < (OS_OBJ_QTY)2) { /* slice only if multiple tasks at same priority */

Round Robin Scheduling cont’d. if (OSSchedLockNestingCtr > (OS_NESTING_CTR)0) { /* Can't round-robin if the scheduler is locked */ CPU_CRITICAL_EXIT(); return; } OS_RdyListMoveHeadToTail(p_rdy_list); /* Move current OS_TCB to the end of the list */ p_tcb = p_rdy_list->HeadPtr; /* Point to new OS_TCB at head of the list */ if (p_tcb->TimeQuanta == (OS_TICK)0) { /* See if we need to use the default time slice */ p_tcb->TimeQuantaCtr = OSSchedRoundRobinDfltTimeQuanta; } else { p_tcb->TimeQuantaCtr = p_tcb->TimeQuanta; /* Load time slice counter with new time */ CPU_CRITICAL_EXIT(); #endif

Task Level Context Switch: Before Must prepare stack as if an interrupt occurred

Task Level Context Switch: After Registers are restored from the new task’s stack It is a “simulated” return from interrupt

ISR Level Context Switch: Before Interrupt has already caused registers to be saved on the stack

ISR Level Context Switch: After