Round Robin Non-Preemptive Scheduler

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Real-Time Library: RTX
Bitwise Operators Pointers Functions Structs Interrupts (in C)
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
CSE Fall Introduction - 1 What is an Embedded Systems  Its not a desktop system  Fixed or semi-fixed functionality (not user programmable)
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
FreeRTOS.
CSS430 CPU Scheduling1 Textbook Ch5 These slides were compiled from the Applied OSC textbook slides (Silberschatz, Galvin, and Gagne) and the instructor’s.
BrickOS Scheduling Solving The Low-Priority Starvation Problem.
Real Time Operating System
Introduction to Embedded Systems
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
Getting Started with the µC/OS-III Real Time Kernel Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Scheduling in µC/OS-III Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Reference: Ian Sommerville, Chap 15  Systems which monitor and control their environment.  Sometimes associated with hardware devices ◦ Sensors: Collect.
Microprocessors 1 MCS-51 Interrupts.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
CS140 Project 1: Threads Slides by Kiyoshi Shikuma.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 More on Thread API.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
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)
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
The 8051 Microcontroller Chapter 6 INTERRUPTS. 2/29 Interrupt is the occurrence of a condition an event that causes a temporary suspension of a program.
1 Round Robin Non-Preemptive Scheduler Lecture 12.
Co-routine YoonMo, Yeon. Co-routine generalize subroutines multiple entry points suspending and resuming of execution at certain locations.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Sharing the Processor: A Survey of Approaches to Supporting Concurrency 16-1.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Introduction In this lab , we will learn
A walk through interrupts on the PPC 823
REAL-TIME OPERATING SYSTEMS
Microprocessor Systems Design I
Timer and Interrupts.
Interrupt and Time Management in µC/OS-III
Interrupts In 8085 and 8086.
Getting Started with the µC/OS-III Real Time Kernel
UNIT 5 TIMRERS/COUNTERS
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Arithmetic using a stack
* * * * * * * 8051 Interrupts Programming.
Process management Information maintained by OS for process management
Interrupt.
Interrupts, Tasks and Timers
An Embedded Software Primer
Swi Scheduling Hwi Swi Tsk Idle
Scheduling in µC/OS-III
Last Week Introduced operating systems Discussed the Kernel
Interrupt Source: under
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
PIC18 Interrupt Programming
CSE 153 Design of Operating Systems Winter 19
February 24, 2015 Jacob Beningo, CSDP
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University
Presentation transcript:

Round Robin Non-Preemptive Scheduler Lecture 17 Embedded Systems

In These Notes . . . What is Scheduling? What is the basis of Round Robin non-preemptive scheduling? Examples of Round Robin Round Robin (cooperative) scheduler Embedded Systems

What is Scheduling? We have seen a “reactive” system – activities are processed based on interrupts. When scheduled activities are needed, you can set up timer interrupts, or you can have the operating system schedule these periodic tasks (perhaps triggered by interrupts…). Scheduling is choosing which task to run and then running it The rules: Define certain functions to be tasks If there is a task ready to run, then run it Finish a task before you start another one If there is more than one task to start, run the highest priority task first (0 is highest priority) Embedded Systems

A Simple Example We will keep track of how long until the task will run (“time”) and if it is scheduled now (“run”) Embedded Systems

Note at the end, things “stack up” (one T3 missed) A More Complex Example Note at the end, things “stack up” (one T3 missed) Embedded Systems

Over-extended Embedded System This is an “overextended” system because some tasks are missed – several times. There is not enough processor time to complete all of the work. This is covered in more detail in a future lecture. Embedded Systems

Review of Scheduler Information Scheduler provided in these slides Details Scheduler uses a software timer per task All software timers are decremented using a timer tick based on the Timer B0 hardware overflow interrupt Each task runs to completion before yielding control of MCU back to Scheduler (non-preemptive) Embedded Systems

Round Robin Scheduler API Init_RR_Scheduler(void) Initialize tick timer B0 and task timers Add Task(task, time period, priority) task: address of task (function name without parentheses) time period: period at which task will be run (in ticks) priority: lower number is higher priority. Also is task number. automatically enables task return value: 1 – loaded successfully, 0 – unable to load Remove Task(task) removes task from scheduler. Run Task(task number) Signals the scheduler that task should run when possible and enables it Run RR Scheduler() Run the scheduler! Never returns There must be at least one task scheduled to run before calling this function. Enable_Task(task_number) and Disable_Task(task_number) Set or clear enabled flag, controlling whether task can run or not Reschedule_Task(task_number, new_period) Changes the period at which the task runs. Also resets timer to that value. Embedded Systems

Set up Timer B0 in Init_RR_Scheduler Set up B0 timer to generate an interrupt every 1 millisecond // default tb0 will be = 65536 (timer tick = 5.4613 ms) // if you load tb0 = 12000, timer tick will = 1.0000ms init_Task_Timers(); // Initialize all tasks tb0 = 12000; // 1 ms timer tick DISABLE_INTS tb0ic = 1; // Timer B0 overflow ENABLE_INTS tb0st = 1; // start timer B0 Embedded Systems

Task List Structure #define USE_ROUND_ROBIN_SCH 1 // Set to 1 if using Round Robin Task Scheduler #define MAX_TASKS 5 // Set maximum number of tasks to be used in system // Will affect performance. typedef struct { int initialTimerValue; // “frequency” of task int timer; // time to next “run” int run; // binary – 1 = “run now” int enabled; void (* task)(void); // address of function } task_t; task_t GBL_task_list[MAX_TASKS]; int GBL_run_scheduler=0; Embedded Systems

Running the Scheduler void Run_RR_Scheduler(void) { // Always running int i; GBL_run_scheduler = 1; while (1) { // Loop forever & Check each task for (i=0 ; i<MAX_TASKS ; i++) { // If this is a scheduled task if (GBL_task_list[i].task != NULL) { if (GBL_task_list[i].enabled == 1) { if (GBL_task_list[i].run == 1) { GBL_task_list[i].run=0; // Reset task timer GBL_task_list[i].task(); // Run the task break; } Embedded Systems

Task List Initialization void init_Task_Timers(void) { // Initialize all tasks int i; for (i=0 ; i<MAX_TASKS ; i++) { GBL_task_list[i].initialTimerValue = 0; GBL_task_list[i].run = 0; GBL_task_list[i].timer = enabled = 0; GBL_task_list[i].task = NULL; } Embedded Systems

Adding a Task int addTask(void (*task)(void), int time, int priority) { unsigned int t_time; /* Check for valid priority */ if (priority >= MAX_TASKS || priority < 0) return 0; /* Check to see if we are overwriting an already scheduled task */ if (GBL_task_list[priority].task != NULL) return 0; /* Schedule the task */ GBL_task_list[priority].task = task; GBL_task_list[priority].run = 0; GBL_task_list[priority].timer = time; GBL_task_list[priority].enabled = 1; GBL_task_list[priority].initialTimerValue = time; return 1; } Embedded Systems

Task Selection // Make sure to load the vector table with this ISR addr #pragma INTERRUPT tick_timer_intr void tick_timer_intr(void) { static char i; for (i=0 ; i<MAX_TASKS ; i++) { // If scheduled task if (GBL_task_list[i].task != NULL) { if (GBL_task_list[i].enabled == 1) { if (GBL_task_list[i].timer) { if (--GBL_task_list[i].timer == 0){ GBL_task_list[i].run = 1; GBL_task_list[i].timer = GBL_task_list[i].initialTimerValue; } Embedded Systems

Removing a Task void removeTask(void (* task)(void)) { int i; for (i=0 ; i<MAX_TASKS ; i++) { if (GBL_task_list[i].task == task) { GBL_task_list[i].task = NULL; GBL_task_list[i].timer = 0; GBL_task_list[i].initialTimerValue = 0; GBL_task_list[i].run = enabled = 0; return; } Embedded Systems

Enabling or Disabling a Task void Enable_Task(int task_number) { GBL_task_list[task_number].enabled = 1; } void Disable_Task(int task_number) GBL_task_list[task_number].enabled = 0; Embedded Systems

Rescheduling a Task Changes period of task and resets counter void Reschedule_Task(int task_number, int new_timer_val) { GBL_task_list[task_number].initialTimerValue = new_timer_val; GBL_task_list[task_number].timer = new_timer_val; } Embedded Systems

Start Round Robin System To run RR scheduler, first add the function (task): addTask(flash_redLED, 25, 3); addTask(sample_ADC, 500, 4); Then, the last thing you do in the main program is: Run_RR_Scheduler(); Embedded Systems