Task Management 김백규. Task states(1/2)  Running  currently utilising the processor.  Ready  tasks are those that are able to execute.  they are not.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Real-Time Library: RTX
FreeRTOS.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Ulster.ac.uk Embedded Systems Introduction to FreeRTOS >> Ian McCrum School of Engineering.
EECS 373 An Introduction to Real Time OSes. Things Should be working on your project at this point – Your group should have something to work on as of.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
P ORTING F REE RTOS TO MCB2140 BOARD Ashwini Athalye Sravya Kusam Shruti Ponkshe.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Chapter 6 Real-Time Embedded Multithreading The Thread – The Essential Component.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
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.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
EECS 373 An Introduction to Real Time OSes. Outline Quick review of real-time systems Overview of RTOSes – Goals of an RTOS – Features you might want.
FreeRTOS.
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Introduction to Processes CS Intoduction to Operating Systems.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Lecture 24: Introduction to FreeRTOS
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.
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
FreeRTOS.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
EECS 498 Advanced Embedded Systems Lecture 7: An Introduction to Real Time OSes.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
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.
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.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
EECS 473 Advanced Embedded Systems An introduction to real time systems and scheduling Chunks adapted from work by Dr. Fred Kuhns of Washington University.
Threads A thread is an alternative model of program execution
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
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)
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Where Testing Fails …. Problem Areas Stack Overflow Race Conditions Deadlock Timing Reentrancy.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Co-routine YoonMo, Yeon. Co-routine generalize subroutines multiple entry points suspending and resuming of execution at certain locations.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
LPC2148's RTOS Bruce Chhuon 4/10/07. What is a Real Time Operating System? ● A Real Time Operating System (RTOS) manages hardware and software resources.
Introduction In this lab , we will learn
Processes and threads.
Process concept.
PROCESS MANAGEMENT IN MACH
CS4101 嵌入式系統概論 Real-Time Operating System
Topics Covered What is Real Time Operating System (RTOS)
Operating Systems (CS 340 D)
Getting Started with the µC/OS-III Real Time Kernel
CS4101 嵌入式系統概論 Tasks and Scheduling
Processes A process is a running program.
Intro to Processes CSSE 332 Operating Systems
Operating Systems (CS 340 D)
Pointers and Linked Lists
An very brief introduction to Real-time systems Real-time OSes
An Introduction to Real Time OSes
Process Description and Control
Introduction to FreeRTOS
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Task Management 김백규

Task states(1/2)  Running  currently utilising the processor.  Ready  tasks are those that are able to execute.  they are not blocked or suspended.  Blocked  it is currently waiting for either a temporal or external event.  Suspended  state are also not available for scheduling.  vTaskSuspend() and xTaskResume() API calls

Task states (2/2)

Task Control Block(1/2)  *pxTopOfStack(volatile portSTACK_TYPE)  Points to the location of the last item placed on the tasks stack.  xGenericListItem(xListItem)  List item used to place the TCB in ready and blocked queues.  xEventListItem(xListItem)  List item used to place the TCB in event lists.  uxPriority(unsigned portBASE_TYPE)  The priority of the task  *pxStack(portSTACK_TYPE)  Points to the start of the stack  uxTCBNumber(unsigned portBASE_TYPE)  used for tracing the scheduler and making debugging easier only  pcTaskName[ configMAX_TASK_NAME_LEN ](signed portCHAR)  Descriptive name given to the task when created. Facilitates debugging only  usStackDepth(unsigned portSHORT)  Total depth of the stack (when empty)

Task Control Block(2/2) pxTopofStack (portSTACK_TYPE*) xGenericListItem (xListItem) xEventListItem (xListItem) uxPriority (portBASE_TYPE) pxStack (portSTACK_TYPE) uxTCBNumber (portBASE_TYPE) pcTaskName [ configMAX_TASK_NAME_LEN ] (portCHAR) usStackDepth (portSHORT)

Implementing a Task  All task functions should be of this type.  Task functions should never return  typically implemented as a continuous loop. void vATaskFunction( void *pvParameters ) { for( ;; ) { -- Task application code here. -- }

The Idle Task  created automatically when the scheduler is started.  is responsible for freeing memory allocated by the RTOS  Be careful of using vTaskDelete()  to ensure the idle task is not starved of processing time.

The Idle Task Hook  What is the Idle Task Hook?  a function that is called during each cycle of the idle task.  Implement Idle Task Hook (2 options)  1) Implement the functionality in an idle task hook.  2) Create an idle priority task to implement the functionality.

Creating Idle Task Hook(2 nd option)  1. Set configUSE_IDLE_HOOK to 1 within FreeRTOSConfig.h.  2. Define a function that has the following prototype:  void vApplicationIdleHook( void );

APIs in FreeRTOS

API - xTaskCreate  Create a new task and add it to the list of tasks that are ready to run.  Returns:  pdPASS : task was successfully created and added to a ready list  error code : defined in the file projdefs. h portBASE_TYPE xTaskCreate ( pdTASK_CODE pvTaskCode, //pointer to a task function const portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, //parameters for task unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask //handle for task. );

Stack creation for task Set information of Task

Critical section start Add a task to Ready Queue Critical section end

If success, Save handle Macro for forcing a context switch. asm volatile ( "SWI" );

Usage of xTaskCreate // Task to be created. void vTaskCode( void * pvParameters ) { for( ;; ) { // Task code goes here. } // Function that creates a task. void vOtherFunction( void ) { unsigned char ucParameterToPass; xTaskHandle xHandle; // Create the task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle ); // Use the handle to delete the task. vTaskDelete( xHandle ); }

API - vTaskDelete  INCLUDE_vTaskDelete must be defined as 1  Remove a task from the kernel  removed from all ready, blocked, suspended and event lists.  Parameter : pxTask  The handle of the task to be deleted. void vTaskDelete( xTaskHandle pxTask );

Handle to task to be deleted Check this is a current TCB or not 1) Get a handle for the task 2) Remove the task from the ready list 3) Remove the task from the event list 4) Add the TCB to xTasksWaitingTermination to deallocate in the future

Usage of vTaskDelete void vOtherFunction( void ) { xTaskHandle xHandle; // Create the task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); // Use the handle to delete the task. vTaskDelete( xHandle ); }

API - vTaskDelay  INCLUDE_vTaskDelay must be defined as 1  Delay a task for a given number of ticks.  Parameters : xTicksToDelay  The amount of time, in tick periods, that the calling task should block. void vTaskDelay( portTickType xTicksToDelay );

Usage of vTaskDelay // Perform an action every 10 ticks. // NOTE: // This is for demonstration only and would be better achieved // using vTaskDelayUntil(). void vTaskFunction( void * pvParameters ) { portTickType xDelay, xNextTime; // Calc the time at which we want to perform the action // next. xNextTime = xTaskGetTickCount () + ( portTickType ) 10; for( ;; ) { xDelay = xNextTime - xTaskGetTickCount (); xNextTime += ( portTickType ) 10; // Guard against overflow if( xDelay <= ( portTickType ) 10 ) { vTaskDelay( xDelay ); } // Perform action here. }

API - vTaskDelayUntil  Delay a task until a specified time.  can be used by cyclical tasks to ensure a constant execution frequency.  Parameters: pxPreviousWakeTime  Pointer to a variable that holds the time at which the task was last unblocked.  The variable must be initialised with the current time prior to its first use  Following this, the variable is automatically updated within vTaskDelayUntil().  Parameters: xTimeIncrement  The cycle time period. void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );

Usage of vTaskDelayUntil Example usage: // Perform an action every 10 ticks. void vTaskFunction( void * pvParameters ) { portTickType xLastWakeTime; const portTickType xFrequency = 10; // Initialise the xLastWakeTime variable with the current time. xLastWakeTime = xTaskGetTickCount(); for( ;; ) { // Wait for the next cycle. vTaskDelayUntil( &xLastWakeTime, xFrequency ); // Perform action here. }

API - vTaskSuspend  INCLUDE_vTaskSuspend must be defined as 1  Suspend any task.  Parameters: pxTaskToSuspend  Handle to the task being suspended.  NULL handle will cause the calling task to be suspended.  Calls to vTaskSuspend are not accumulative  calling vTaskSuspend () twice requires  one call to vTaskResume () to ready void vTaskSuspend( xTaskHandle pxTaskToSuspend );

Usage of vTaskSuspend void vAFunction( void ) { xTaskHandle xHandle; // Create a task, storing the handle. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); //... // Use the handle to suspend the created task. vTaskSuspend( xHandle ); //... // The created task will not run during this period, unless // another task calls vTaskResume( xHandle ). //... // Suspend ourselves. vTaskSuspend( NULL ); // We cannot get here unless another task calls vTaskResume // with our handle as the parameter. }

Other APIs  vTaskResume  TaskPrioritySet  uxTaskPriorityGet  vTaskPrioritySet  vTaskResumeFromISR

Context Switch Process

Call TaskYield() PortYield() vPortYieldProcessor() portSAVE_CONTEXT() vTaskSwitchContext() portRESTORE_CONTEXT() Generate Interrupt asm volatile ( "SWI" );

SWI interrupt causes …

vPortYieldProcessor()

vTaskSwitchContext

List Structures

xList  Used in ready, blocked, event queue for scheduling

Various Queue in FreeRTOS TCB Priority 0 TCB Priority 1 TCB Priority 2 TCB Priority 3 TCB