Chapter 7. More Operating System Services

Slides:



Advertisements
Similar presentations
Chapter 1.2 Operating Systems. Layered Operating System model Hardware Operating System Application.
Advertisements

Big Picture Lab 4 Operating Systems Csaba Andras Moritz.
IN2305-II Embedded Programming Lecture 7: More OS Services.
Embedded Systems More Operating System Services C.-Z. Yang Sept.-Dec
CS533 Concepts of Operating Systems Class 6 The Duality of Threads and Events.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Embedded Systems Basic Design Using a Real- Time Operating System C.-Z. Yang Sept.-Dec
CS533 Concepts of Operating Systems Class 2 The Duality of Threads and Events.
CS533 Concepts of Operating Systems Class 3 Integrated Task and Stack Management.
Chapter 2 The OS, the Computer, and User Programs Copyright © 2008.
FreeRTOS.
Real Time Operating System
SOC Consortium Course Material SoC Design Laboratory Lab 8 Real-time OS - 2 Speaker: Yung-Chih Chen Advisor: Prof. Chun-Yao Wang November 17, 2003 Department.
1 I-Logix Professional Services Specialist Rhapsody IDF (Interrupt Driven Framework) CPU External Code RTOS OXF Framework Rhapsody Generated.
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.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
1 RTOS Design Some of the content of this set of slides is taken from the documentation existing on the FreeRTOS website
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Real Time Operating Systems
© 2000 Morgan Kaufman Overheads for Computers as Components Processes and operating systems Operating systems. 1.
2001 Networking Operating Systems (CO32010) 1. Operating Systems 2. Processes and scheduling 4.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
IPC Programming. Process Model Processes can be organized into a parent-child hierarchy. Consider the following example code: /* */
NETW 3005 Threads and Data Sharing. Reading For this lecture, you should have read Chapter 4 (Sections 1-4). NETW3005 (Operating Systems) Lecture 03 -
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.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
 Wind River Systems, Inc Chapter - 7 Intertask Communication.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
Lab 4 : Real-Time OS Team #7 P 李彥勳 P 謝嵩淮 R 侯凱文.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
1 J.O. KLEIN Institut Universitaire de Technologie de CACHAN Université PARIS SUD - FRANCE An Introduction to Real Time Operating System.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
1 8. Basic Design Using a Real-Time Operating System Kim jung kil.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 7: Semaphore Management Seulki Lee 1. Semaphore?  A protocol mechanism offered by most multitasking kernels  Control access to a shared resource.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
REAL-TIME OPERATING SYSTEMS
Chapter 3: Process Concept
Topics Covered What is Real Time Operating System (RTOS)
An Embedded Software Primer
CSCI1600: Embedded and Real Time Software
Threads and Data Sharing
Computer System Overview
Processor Fundamentals
Operating System Concepts
Chien-Chung Shen CIS/UD
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
An Embedded Software Primer
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CS703 - Advanced Operating Systems
Intertask Communication
CSCI1600: Embedded and Real Time Software
Embedded System Development Lecture 10 3/21/2007
Embedded System Development Lecture 12 4/4/2007
Module 12: I/O Systems I/O hardwared Application I/O Interface
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:

Chapter 7. More Operating System Services The other features offered by commercial RTOSs.

Contents Message Queues, Mailboxes and Pipes Timer Functions Events Memory Management Interrupt Routines in an RTOS Environment

Message Queues, Mailboxes and Pipes Task must be able to communicate with one another to coordinate their activities or to share data. queues, mailboxes, and pipes

Message Queues, Mailboxes and Pipes void Task1(void) { … if (!!problem arises) vLogError(ERROR_TYPE_X); !! Other things that need to be done soon. } void Task2(void) vLogError(ERROR_TYPE_Y); void vLogError(int iErrorType) { AddToQueue(iErrorType); } static int cErrors; void ErrorTask(void) int iErrorType; while(FOREVER) ReadFromQueue(&iErrorType); ++cErrors; !! Send cErrors and iErrorType out on network task1 과 task2가 각각 실행 , 로그에러를 만나면 vLogError에 에러처리를 부탁하고 각자 자신의 task를 수행 각자가 에러를 받아서 처리하고 다시 돌아와 실행하는 것 줄임 vLogError , errortype 받아서 큐에 넣음 ErrorTask 계속 루프돌면서 큐로부터 ErrorType을 인자로 에러형태 찾음

Details with Message Queues Initialize your queues before using queue. Have as many queues as you want the identity of the queue When queue is full, the RTOS must return an error block 주체는 RTOS임 m q 사용 전에 initialize가 필요 원하는 만큼 q를 사용가능 구별하기 위해 identity ---

Details with Message Queues A function that will read from a queue if there is any data and will return error code and block if not. Write onto a queue the number of bytes taken up by a void pointer void 포인터를 써서 수 바이트를 q에 쓸 수 있는데 다음에 알아봄

Pointer and Queues Casting the data as a void pointer One task can pass data to one other task Put the data into buffer And write a pointer to the buffer onto queue data를 void 포인터로 캐스트해서 수바이트를 큐에 더할 수 있음 한 task가 다른 task에 데이터를 전달하는 방법에 ---

Pointer and Queues Fig. 7.2 More Realistic Use of a Queue void *apvQueue[SIZEOF_QUEUE]; void main(void) { … pOseQueue = OSQCreate(apvQueue, SIZEOF_QUEUE); !!Start Task1 !!Start Task2 } void Task1(void) { void Task2(void) { void vLogError(int iErrorType) { byReturn = OSQPost(pOseQueue, (void*)iErorType); … } void ErrorTask(void) { while(FOREVER) iErrorType = (int) OSQPend(pOseQueue, WAIT_FOREVER, &byErr); OSQCreate()는 큐를 생성 post는 큐에 에러를 추가함 pend는 큐에서 에러타입을 인자로 에러값을 얻음 ErrorType은 int형임 OSQCreate() apvQueue 큐를 배열로 선언, SIZEO_QUEUE는 25 OSQPost(), *OSQCreate()가 포인터 함수이고 함수의 포인터가 pOseQueue iErrorType을 void *형으로 cast해서 전달. OSQPend(). pOseQueue : identify of queue , byErr는 일단 ignore Fig. 7.2 More Realistic Use of a Queue

Pointer and Queues Fig. 7.3 Passing Pointer on Queues void vMainTask(void) { int *pTemperatures; BYTE byErr; while(TRUE) pTemperatures = (int*)OSQPend(pOseQueueTemp, WAIT_FOREVER, &byErr); if (pTemperatures[0] != pTemperatures[1]) !! Set Off howling alarm; } static OS_EVENT *pOseQueueTemp; void vReadTemperaturesTask(void) { int *pTemperatures; While(TRUE) { … pTemperatures = (int*)malloc(2*sizeof*pTemperatures); pTemperatures[0] = pTemperatures[1] = OSQPost(pOseQueueTemp, (void*)pTemperatures); } 앞의 예제는 메시지 큐를 에러를 저장해서 처리하는 것, 이 예제는 vReadTemperatureTask에서 pTemperatures[] 값을 하드웨어에서 읽어옴 큐에 저장 vMainTask()에서 큐로부터 temp값을 읽어와서 비교함 각 sub가 task1, 2등에 의해 실행될 수 있음 Fig. 7.3 Passing Pointer on Queues

Mailboxes Much like queues. RTOS can Create, write ,check and read from mail boxes. The number of messages in a mailbox is limited. User can prioritize mailbox messages. MultiTask! sndmsg, rcvmsg, chkmsg

Pipes Much like queues. RTOS can Byte-oriented. Use fread(), fwrite() Create, write ,check and read from pipes. Byte-oriented. Use fread(), fwrite() 데이터 처리 단위가 바이트임 몇 RTOS는 Pipe를 읽고 쓰는데 fread(), fwrite() 제공하기도 함

Which should I use? Trade-offs among Flexibility, speed, memory space, disabled interrupt time length Refer to documents

Pitfalls Passing Pointers through a queue may create shared data bugs void vReadTemperaturesTask(void) { int *pTemperatures; While(TRUE) { … pTemperatures = (int*)malloc(2*sizeof*pTemperatures); pTemperatures[0] = pTemperatures[1] = OSQPost(pOseQueueTemp, (void*)pTemperatures); } void vReadTemperaturesTask(void) { int iTemperatures[2]; While(TRUE) { … iTemperatures[0] = iTemperatures[1] = OSQPost(pOseQueueTemp, (void*)iTemperatures); } 각 switchin이 화살표에 일어났을때 앞의 것은 매번 pTemperature포인터를 지정받아서 사용함 뒤의 것은 메모리상의 iTemperatures의 위치가 같음 뒤에 값비교시에 뒤의 것은 같은 buffer위치를 가리켜서 shared data bugs가능성이 있음

Timer Functions Must Keep track of the passage of time Offer taskDelay() functions. void vMakePhoneCallTask(void) { … taskDelay(100); vDialingToneOn(*p_chPhoneNumber –’0’); vDialingToneOff(); } 짐작 *p_chPhoneNumber –’0’는 숫자의 거리를 인자로 다른 주파수의 소릴 냄 taskDelay()를 볼 수 있고 100은 system ticks를 말함

Events Procedure More than task can block waiting The events occurs The RTOS will unblock all of tasks Form group of events and any subset of events within the group Need to reset events automatically or manually events의 과정 group구성가능하고 그룹 안의 복수 개 event를 처리가능 예:task가 group안의 복수 개 event를 기다림 reset

Comparison for Intertask Comm. Semaphore : the fastest and simplest not much information Events : more complicated than semapohre can wait several events at the same time take more CPU time Queues : much information CPU-intensive, bugs-opportunity.

Memory Management Avoid malloc and free function Slow and unpredictable Use the functions that allocate and free fixed-size buffers. Predictable At MultiTask! system void *getbuf(PoolID, timeout); void *reqbuf(PoolID); void reluf(PoolID, *p_vBuffer); task block의 가능성 Pool은 buffer들의 집합이고 여러 개의 Pool을 정의가능 memory buffer full 일 때 getbuf는 buffer가 빌때까지 block함 reqbuf는 null pointer return relbuf는 p_vBuffer가 가리키는 해당 pool를 free함

Interrupt Routines in an RTOS Environment Interrupt Routines must not call any RTOS functions that- Might block the caller. Might cause the RTOS to switching tasks without fair warning 큰 원리 : interrupt routine은 항상 수행이 완료되어서 next int.를 기다릴 수 있어야 함 task … int rot RTOS func. block int rot. block task. block – high prioirity task 라도 task가 int rot수행중인 것을 모르고 int rout에서 다른 task로 control 를 옮기면 int rout가 완료되지 않게 되고 low prioriy int 혹 전채 int가 block되는것.

Interrupt Routines in an RTOS Environment 정상적인 int rout과정이고 ISR : int service rout. task low에서 int가 걸림 int가 send msg to mailbox의 func호출 또다른 함수 호출 isr이 완료하면 RTOS가 우선순위 높은 task혹은 낮은 task로 돌아가게 함 Fig. 7.14 How Interrupt Routines Should Work

Interrupt Routines in an RTOS Environment 문제가 있는 int rout과정 이전에 mailbox에 higher-prioirty task가 block되어 있다고 가정 tasklow 에서 int rout가 걸리고 RTOS function이 실행뒤에 higher priority task이 unblock되어서 실행 int rout가 완료되지 못함 전체 block Fig. 7.15 What Would Really Happen

Interrupt Routines in an RTOS Environment The RTOS intercepts all the interrupts and then call your interrupt routine. RTOS가 all int rout를 가로막은뒤에 int rout를 수행 call return구간에는 int 구간임을 앎 도중에 hightask로 빠지지 않음 Fig. 7.16 How Interrupt Routines Do Work

Interrupt Routines in an RTOS Environment Disabling the scheduler for the duration of the interrupt routine. ISR이 int rout가 시작된 것을 RTOS에게 알려주는 function을 실행 func , RTOS가 제공 뒤에 scheduler로 jump or call하는 함수 호출 Fig. 7.17 How Interrupt Routines Do Work:Plan B

Interrupt Routines in an RTOS Environment A separate set of functions for interrupt routines specially OSSemPost OSISRSemPost for interrupt routines int rout도중에 other task로 switch되지 않고 항상 isr로 돌아오는 함수사용

Nested Interrupts The RTOS must know when the lower-priority interrupt routine. low priority int rout도중에 high int rout가 걸리면 역시 RTOS가 low int rout수행중인 것을 알고 다시 low int rout로 돌아와야 함 그렇지 않으면 high int끝내고 taskhigh로 switch가능성 Fig. 7.18 Nested Interrupts and the RTOS