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

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
Chapter 14 80x86, Large Model Port Porting to real mode and for the large model –Real mode: 1Mb memory space (pointers in this model require 32 bits) –In.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
CSE Fall Introduction - 1 What is an Embedded Systems  Its not a desktop system  Fixed or semi-fixed functionality (not user programmable)
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?
Chapter 6 Real-Time Embedded Multithreading The Thread – The Essential Component.
MicroC/OS-II Embedded Systems Design and Implementation.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Outline Introduction to MQX Initializing and starting MQX
Μ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.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
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.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
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.
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.
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.
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.
Multi-Tasking The Multi-Tasking service is offered by VxWorks with its real- time kernel “WIND”.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
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.
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.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Lab 3 Department of Computer Science and Information Engineering National Taiwan University Lab3 – μC/OS 2015/10/13/ 13 1.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
CHAPTER 7 CONCURRENT SOFTWARE Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
Chapter 3 RTOS Concepts And Definitions Department of Computer Science Hsu Hao Chen Professor Hsung-Pin Chang.
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.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Limited Direct Execution
Process concept.
Chapter 13: Porting μC/OS-II
Topics Covered What is Real Time Operating System (RTOS)
Interrupt and Time Management in µC/OS-III
Round Robin Non-Preemptive Scheduler
Getting Started with the µC/OS-III Real Time Kernel
Computer System Overview
Introduction What is an operating system bootstrap
Scheduling in µC/OS-III
Processor Fundamentals
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.)
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CS333 Intro to Operating Systems
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 2015 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” Empty list: OS Tasks:

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 */ return; } if (OSSchedLockNestingCtr > (OS_NESTING_CTR)0) { /* Scheduler still locked? */ Enable interrupts /* Yes */ return; } 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? */ Enable interrupts /* Yes */ return; } 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) { CPU_CRITICAL_EXIT(); return; } 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 */ CPU_CRITICAL_EXIT(); return; return; }

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