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:



Advertisements
Similar presentations
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Advertisements

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Real-Time Library: RTX
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
CSCI 4717/5717 Computer Architecture
HW/SW Interface Operating Systems Design and Implementation.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
Bitwise Operators Pointers Functions Structs Interrupts (in C)
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Implementing interrupt driven IO. Why use interrupt driven IO? Positive points –Allows asynchronous operation of IO events –Good use of resources –Leads.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
MicroC/OS-II Embedded Systems Design and Implementation.
Embedded Systems Interrupts C.-Z. Yang Sept.-Dec
IN2305-II Embedded Programming Lecture 5: Survey of SW Architectures.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
INTERRUPTS PROGRAMMING
FreeRTOS.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Advanced Embedded Systems Design Pre-emptive scheduler BAE 5030 Fall 2004 Roshani Jayasekara Biosystems and Agricultural Engineering Oklahoma State University.
Introduction to Embedded Systems
Real-Time Kernel (Part 1)
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
Nachos Phase 1 Code -Hints and Comments
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
Chapter 4 TIMER OPERATION
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Scheduling in µC/OS-III Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Interrupt.
Microprocessors 1 MCS-51 Interrupts.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
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.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
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.
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
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.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Co-routine YoonMo, Yeon. Co-routine generalize subroutines multiple entry points suspending and resuming of execution at certain locations.
INSTITUTE: INSTITUTE:PARUL INSTITUTE OF TECHNOLOGY BRANCH : BRANCH :B.E. E.C.5 TH SEM. SUBJECT:MICROCONTROLLER & INTERFACING TOPIC:AVR INTTRUPT TOPIC:AVR.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
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.
Interrupt 마이크로 프로세서 (Micro Processor) 2015년 2학기 충북대학교 전자공학과 박 찬식
A walk through interrupts on the PPC 823
Microprocessor Systems Design I
Timer and Interrupts.
Mechanism: Limited Direct Execution
Interrupts In 8085 and 8086.
Round Robin Non-Preemptive Scheduler
UNIT 5 TIMRERS/COUNTERS
* * * * * * * 8051 Interrupts Programming.
An Embedded Software Primer
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
CSE 153 Design of Operating Systems Winter 19
February 24, 2015 Jacob Beningo, CSDP
Presentation transcript:

1 Run-to-Completion Non-Preemptive Scheduler

2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative) scheduler in in rtc.c and rtc.h –Note: if the code examples in the notes differ from the code in rtc.c or rtc.h, follow rtc.c or rtc.h

3 Approaches to Sharing the Processor (Scheduling) We have seen two types of code in a program –Code in main, or a function called by main (possibly indirectly) –Code in interrupt service routines, executing asynchronously This approach makes certain behavior difficult to implement –E.g. run Check_for_Overrun() every 28 milliseconds –Run Update_Display() every 100 milliseconds –Run Signal_Data_Available() 300 milliseconds after UART0 Rx interrupt occurs Solution 1 –Use a timer peripheral. Set it to expire after the desired time delay. –Problem: Need a timer per event, or a function which makes one timer act like many based on a schedule of desired events. Solution 2 –Break the code into tasks which will run periodically –Add a scheduler which runs the tasks at the right times Scheduling: deciding which task to run next and then starting it running

4 Scheduling Rules Define functions which need to run periodically to be tasks If there is a task ready to run, then run it Finish the current task before you start another one –“Run to completion” = non-preemptive –One task can’t preempt another task If there is more than one task to start, run the highest priority task first

5 Implementing Scheduler Behavior Keep a table with information on each task –Where the task starts – so we can run it –The period with which it should run –How long of a delay until it should run again Decrement this timer every so often Reload it with period when it overflows –Whether it is ready to run now –Whether it is enabled – so we can switch it on or off easily Use a periodic timer ISR (e.g. a tick per millisecond) to update delay information in the table Use scheduler to run tasks with ready = 1 Tick Timer ISR ReadyDelayTaskReadyDelayTaskReadyDelayTaskReadyDelayTask Scheduler

6 Task Table Initialization #define MAX_TASKS 5 // Set maximum number of tasks. Affects performance. typedef struct { int period; // period of task in ticks int delay;// time until next run int ready;// binary: 1 = “run now” int enabled;// active task? void (* task)(void);// address of function } task_t; task_t GBL_task_table[MAX_TASKS]; void init_Task_Table(void) { // Initialize all tasks entries to empty state int i; for (i=0 ; i<MAX_TASKS ; i++) { GBL_task_table[i].delay = 0; GBL_task_table[i].ready = 0; GBL_task_table[i].period = 0; GBL_task_table[i].enabled = 0; GBL_task_table[i].task = NULL; }

7 Initialize Tick Timer Set up B0 timer to generate an interrupt every 1 millisecond UPDATE // default tb0 will be = (timer tick = 65536/24MHz ) // load tb0 with 1 ms*24MHz = 24,000 init_Task_Timers(); // Initialize all tasks tb0 = 24000; // 1 ms timer tick DISABLE_INTS tb0ic = 1;// Timer B0 overflow ENABLE_INTS tb0st = 1;// start timer B0

8 Update Task Table With Each Tick On every time tick –Reduce Delay –If Delay becomes 0, mark task Ready to run and reload Delay with Period // 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) && (GBL_task_list[i].enabled == 1) && (GBL_task_list[i].delay != 0) ) { GBL_task_list[i].delay--; if (GBL_task_list[i].delay == 0){ GBL_task_list[i].ready = 1; GBL_task_list[i].delay = GBL_task_list[i].period; } // if delay == 0 } // if && && && } // for

9 A Simple Example We will keep track of how long until the task will run (“delay”) and if it is scheduled to run now (“ready”)

10 Review of Scheduler Information Scheduler provided in rtc.[c|h] 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)

11 Run-to-Completion Scheduler API Init_RTC_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 RTC 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.

12 Running the Scheduler void Run_RTC_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) && (GBL_task_list[i].enabled == 1) && (GBL_task_list[i].ready == 1) ) { GBL_task_list[i].task(); // Run the task GBL_task_list[i].ready = 0; break; } // if && && } // for i } // while 1 }

13 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].ready = 0; GBL_task_list[priority].delay = time; GBL_task_list[priority].period = time; GBL_task_list[priority].enabled = 1; return 1; }

14 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].delay = 0; GBL_task_list[i].period = 0; GBL_task_list[i].run = 0; GBL_task_list[i].enabled = 0; return; }

15 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; }

16 Rescheduling a Task Changes period of task and resets counter void Reschedule_Task(int task_number, int new_period) { GBL_task_list[task_number].period = new_period; GBL_task_list[task_number].delay = new_period; }

17 Start System To run RTC scheduler, first add the function (task): addTask(flash_redLED, 25, 3); addTask(sample_ADC, 500, 4); Then, the last thing to do in the main program is: Run_RTC_Scheduler(); // never returns

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

19 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.