Real-Time Operating Systems With Example PICOS18

1y ago
8 Views
3 Downloads
652.24 KB
23 Pages
Last View : 30d ago
Last Download : 3m ago
Upload by : Halle Mcleod
Transcription

Real-Time Operating SystemsWith Example PICOS18Sebastian Fischmeister1What is an Operating System? A program that acts as an intermediary between a userof a computer and the computer hardware Operating system goals:o Execute user programs and make solving user problemseasier.o Make the computer system convenient to use Use the computer hardware in an efficient mannerCSE480/CIS700S. Fischmeister21

Computer System Components1. Hardware – provides basic computing resources (CPU,memory, I/O devices)2. Operating system – controls and coordinates the use ofthe hardware among the various application programsfor the various users3. Applications programs – define the ways in which thesystem resources are used to solve the computingproblems of the users (compilers, database systems,video games, business programs)4. Users (people, machines, other computers)CSE480/CIS700S. Fischmeister3Abstract View of System ComponentsCSE480/CIS700S. Fischmeister42

What is an RTOS? Often used as a control device in a dedicated applicationsuch as controlling scientific experiments, medicalimaging systems, industrial control systems, and somedisplay systems Well-defined fixed-time constraintsCSE480/CIS700S. Fischmeister5More Precisely? The system allows access to sensitive resources withdefined response times.o Maximum response times are good for hard real-timeo Average response times are ok for soft real-time Any system that provides the above can be classified asa real-time systemo 10us for a context switch, ok?o 10s for a context switch, ok?CSE480/CIS700S. Fischmeister63

Taxonomy of RTOSs Small, fast, proprietary kernelsRT extensions to commercial timesharing systemsComponent-based kernelsUniversity-based kernelsCSE480/CIS700S. Fischmeister7Small, Fast, Proprietary Kernels They come in two varieties:o Homegrowno Commercial offerings Usually used for small embedded systems Typically specialized for one particular application Typically stripped down and optimized versions:ooooFast context switchSmall size, limited functionalityLow interrupt latencyFixed or variable sized partitions for memory management PICOS18, pSOS, MicroC, CSE480/CIS700S. Fischmeister84

RT Extensions A common approach is to extend Unixo Linux: RT-Linux, RTLinuxPro, RTAI,o Posix: RT-Posixo MACH: RT-MACH Also done for Windows based on virtualization. Generally slower and less predictable. Richer environment, more functionality. These systems use familiar interfaces, even standards. Problems when converting an OS to an RTOS:o Interface problems (nice and setpriority in Linux)o Timers too coarseo Memory management has no bounded execution timeo Intolerable overhead, excessive latencyCSE480/CIS700S. Fischmeister9How to do an RT Extension? Compliant kernelso Takes an existing RTOS and make it execute other UNIXbinaries (see LynxOS).o Interfaces need to be reprogrammed.o Behavior needs to be correctly reimplemented.CSE480/CIS700S. Fischmeister105

How to do an RT Extension? Dual kernelso Puts an RTOS kernel between the hardware and the OS.o Hard tasks run in the RTOS kernel, the OS runs whenCPU is available.o Native applications can run without any changes.o Hard tasks get real-time properties.o See RTLinuxPro Problems: A single failing hard task can kill the whole system. The RTOS kernel requires its own IO drivers.CSE480/CIS700S. Fischmeister11How to do an RT Extension? Core kernel modificationso Takes the non-RT operating systems and modifies it tobecome an RTOS. Problem: (need to do all this)oooooImplement high-resolution timersMake the kernel preemptiveImplement priority inheritanceReplace FIFOs with priority queuesFind and change long kernel execution pathsCSE480/CIS700S. Fischmeister126

Component-based Kernels The source consists of a number of components that can beselectively included to compose the RTOS. See OS-Kit, Coyote, PURE, 2k, MMLite, Pebble, Chaos, eCos. eCoso Hardware Abstraction Layer (HAL)o Real-time kernel CSE480/CIS700Interrupt handlingException handlingChoice of schedulersThread supportRich set of synchronization primitivesTimers, counters and alarmsChoice of memory allocatorsDebug and instrumentation supportCounters -- Count event occurrencesClocks -- Provide system clocksAlarms -- Run an alarm functionMutexes -- Synchronization primitiveCondition Variables -- Synchronization primitiveSemaphores -- Synchronization primitiveMail boxes -- Synchronization primitiveEvent Flags -- Synchronization primitiveSpinlocks -- Low-level Synchronization PrimitiveScheduler Control -- Control the state of the schedulerInterrupt Handling -- Manage interrupt handlersS. Fischmeister13Component-based Kernels eCosoooooooµITRON 3.0 compatible APIPOSIX compatible APIISO C and math librariesSerial, ethernet, wallclock and watchdog device driversUSB slave supportTCP/IP networking stacksGDB debug support All components can be added through a configurationfile that includes and excludes parts of the source code.CSE480/CIS700S. Fischmeister147

Research Kernels Many researchers built a new kernel for one of thesereasons:oooooooooChallenge basic assumptions made in timesharing OSDeveloping real-time process modelsDeveloping real-time synchronization primitivesDeveloping solutions facilitating timing analysisStrong emphasis on predictabilityStrong emphasis on fault toleranceInvestigate the object-oriented approachReal-time multiprocessor supportInvestigating QoSCSE480/CIS700S. Fischmeister15What Typically Differs168

Requirements RTOS must be predictableo We have to validate the systemo We have to validate the OS calls/services We must know upper bounds too Execution time of system callso Memory usage We must have static bounds ono Memory layouto Size of data structures (e.g. queues) Fine grain interrupt controlCSE480/CIS700S. Fischmeister17RTOS Predictability All components of the RTOS must be predictableo System calls, device drivers, kernel internal management Memory accesso Page faults, lookup time, caches Disk accesso Bound for head movement while reading/writing data Net accesso Bound for time for transmission, switchingo Dropped packets? Scheduling must be deterministicCSE480/CIS700S. Fischmeister189

Admission Control Admission control is a function that decides if new workentering the system should be admitted or not. To perform this it requires:ooooA model of the state of system resourcesKnowledge about incoming requestsAn algorithm to make the admission decisionPolicies for actions to take upon admission and rejection Statically scheduled systems require no admissioncontrol.S. FischmeisterCSE480/CIS70019Admission Control The admission algorithm requires preanalyzed tasks Shared dataExecution timePrecedence informationImportance levelDeadlines Positive decision assigns time slices to the taskNegative decision has options:o Run a simpler version of the tasko Run on a different machineo Reject the task Admission algorithms can be complex as they have to consider multipleresources (e.g., networked video streaming).CSE480/CIS700S. Fischmeister2010

Resource Reservation Resource reservation is the act of actually assigningresources to a task.o Initially no resource reservation, only allocation as the taskruns.o Valuable for hard real-time systems.o Introduces an overhead as resources might be unused introduction of resource reclaiming strategies Closely linked to resource kernels that offer interfacesfor resource reservation, donation, and reflection.CSE480/CIS700S. Fischmeister21Task Declaration RTOSs tailored to microprocessors often require a staticdeclaration of tasks. Advantages are:ooooSimple check that the system has sufficient resources.No admission control necessary.No overhead introduced by the admission test.No thread spawning problems but quite staticCSE480/CIS700S. Fischmeister2211

Boot from ROM The RTOS typically boots from the ROM when used onmicroprocessors. Requires the application program to actually start up theRTOS:void main (void) {/* Perform Initializations */.OSInit();./* Create at least one task by callingOSTaskCreate() */OSStart();}CSE480/CIS700S. Fischmeister23Configurability As mentioned with component-based RTOS, the systemmust be configurable. Include only components needed for the present system Components must be removableo Inter-module dependencies limit configurability Configuration tailors OS to systemo Different configuration possibilities Example RoboVM (PICDEM and modular robot).CSE480/CIS700S. Fischmeister2412

Configurability Remove unused functionso May be done via linker automatically Replace functionalityo Motor placement comes in three functions: Calculated Lookup table (program memory) Lookup table (EEPROM) Conditional compilationo Use #if, #ifdef constructso Needs configuration editoro Example: Linux make config .CSE480/CIS700S. Fischmeister25Problem with Configurability Per (boolean) configuration option, we obtain two newOS versions. Embedded systems require extensive testing. The application must be tested with each configurationseparately:oooo100 configuration options we get around 2 100Require hardware setupRequire software setupRequire reporting for automated testingCSE480/CIS700S. Fischmeister2613

Embedded RTOS I/O I/O normally only through kernel via an system call.o Expensive but provides control In an RTOS for embedded systems, tasks are allowed todo I/O operations directlyo Direct fast accesso Direct task to task communication between chips Problem: Can cause troubles if tasks interfere Solution: Programmer must do synchronization tooCSE480/CIS700S. Fischmeister27Embedded RTOS: Interrupts Normal OS: Interrupts are kernel onlyo Must be reliable (dropped disk interrupts )o Costly: Notification via context switch/syscalls Embedded OS: tasks can use interruptsooooAgain: only trusted/tested programsSpeed importantFast task control possibleBut: modularity decreases, as tasks may have to shareinterrupts correctlyCSE480/CIS700S. Fischmeister2814

PICOS1829Terminology Critical section, or critical region, is code that needs tobe treated indivisibly.o No interruptso No context switch Resource is an entity used by a task.o Printer, keyboard, CAN bus, serial port Shared resource is a resource that can be used by morethan one task.o mutual exclusion Multitasking is the process of scheduling and switchingthe CPU between several tasks.CSE480/CIS700S. Fischmeister3015

Task Task, also called thread, is a user application.o Shares the CPU and resources with other taskso Follows a defined life cycleCSE480/CIS700S. Fischmeister31Context Switches A context switch occurs whenever the multitaskingkernel decides to run a different task.o Save the current task’s context in the storage area.o Restores the new task’s context from the storage area.o Resumes the new task Context switching adds overhead. The more registers a processor has, the higher theoverhead irrelevant for RTOS as long as its known.CSE480/CIS700S. Fischmeister3216

Kernels The kernel is responsible for managing the tasks. Most fundamental service is the context switch. Non-preemtive kernels, also cooperative multitaskingo The task needs to explicitly give up control of the CPU.o Allows low interrupt latency, because they may be neverdisabled.o Allows non-reentrant functions at the task level.o Response time is determined by the longest task.o No overhead for protecting shared data.o Responsiveness may be low, because of low priority taskrequiring a lot of time until it releases the CPU.CSE480/CIS700S. Fischmeister33Kernels Preemptive kernelo Responsiveness is good, because tasks get preempted.o A higher-priority task can preempt a lower priority task thatstill requires more time to compute.o Response time becomes deterministic, because at thenext tick, the OS switches to the other new task.o Non-reentrant functions require careful programming.o Periodic execution of the ‘tick’ adds to the overhead.CSE480/CIS700S. Fischmeister3417

Introduction PICOS18 is a preemptive RTOS for the PIC18 series.Bases on OSEK/VDX, an open industry standard.Developed by Pragmatec.GPL www.picos18.com www.picos18.com/forumCSE480/CIS700S. Fischmeister35Services PICOS18 providesooooooCore services: initialization, schedulingAlarm and counter managerHook routinesTask managerEvent managerInterrupt managerCSE480/CIS700S. Fischmeister3618

PICOS18 Interrupt Routine Part of the user application. One for the high priority interrupts and one for lowpriority interrupts. Most important part: AddOneTick() Let’s have a look.CSE480/CIS700S. Fischmeister37PICOS18 Context Switch The active task gets suspended and its context getspushed onto its stack. The preempted task gets resumed and its context getsrestored. Let’s have look at the save task ctx routine.CSE480/CIS700S. Fischmeister3819

Static Declarations PICOS18 requires you to statically declareo Alarmso Resourceso Tasks Let’s have a look.CSE480/CIS700S. Fischmeister39Task API StatusType ActivateTask (TaskType TaskID)o Change the state of a task from SUSPENDED to READY. StatusType TerminateTask (void)o Changes the state of a task from READY to SUSPENDED. StatusType ChainTask (TaskType TaskID)o Terminates the current task, activates a follow up task. StatusType Schedule(void)o Invoke the scheduler to find a new active task.o Not necessary, because PICOS18 is a preemptive OS. StatusType GetTaskID (TaskRefType TaskID) StatusType GetTaskState (TaskType TaskID,TaskStateRefType State)CSE480/CIS700S. Fischmeister4020

Tasks Implementation At most 16 events. The task state is encoded in the following variables:o tsk X state ID Bits 0-3: task identifier Bit 4: unused Bit 5-7: task stateo tsk X active prio Bits 0-3: task priority Bit 5-7: activation countero Let’s look at some of the functions in pro man.cCSE480/CIS700S. Fischmeister41Event Management StatusType SetEvent (TaskType TaskID,EventMaskType Mask)o Posts an event to another task. Causes a schedulingoperation. StatusType ClearEvent (EventMaskType Mask)o Clears the event, otherwise an infinite loop. StatusType GetEvent (TaskType TaskID,EventMaskRefType Event)o Receives the event value for a specific task. StatusType WaitEvent (EventMaskType Mask)o Blocks the current task until the event occurs.CSE480/CIS700S. Fischmeister4221

Event Implementation At most 16 events. The event status is encoded in these two variables:o EventMaskType event X For each task 16 possible events.o EventMaskType wait X Each task can listen for 16 possible events. Let’s have a look at the code.CSE480/CIS700S. Fischmeister43Alarm Management StatusType GetAlarm (AlarmType AlarmID,TickRefType Tick)o Returns the number of ticks until the alarm goes off. StatusType SetRelAlarm (AlarmType AlarmID,TickType increment, TickType cycle)o Registers an alarm relative to the current kernel counter. StatusType SetAbsAlarm (AlarmType AlarmID,TickType start, TickType cycle)o Registers an alarm as absolute kernel counter tick value. StatusType CancelAlarm (AlarmType AlarmID)o Deactivate an alarm.CSE480/CIS700S. Fischmeister4422

Alarm Implementation Each tick the alarm counters get incremented by one. If the alarm value equals the counter value, then thealarm will cause an event. Let’s look at the code.CSE480/CIS700S. Fischmeister45Sample Application Let’s look at the sample application that comes withPICOS18.CSE480/CIS700S. Fischmeister4623

Well-defined fixed-time constraints CSE480/CIS700 S. Fischmeister 6 More Precisely? The system allows access to sensitive resources with defined response times. oMaximum response times are good for hard real-time oAverage response times are ok for soft real-time Any system that provides the above can be classified as a real-time system

Related Documents:

1.1 Hard Real Time vs. Soft Real Time Hard real time systems and soft real time systems are both used in industry for different tasks [15]. The primary difference between hard real time systems and soft real time systems is that their consequences of missing a deadline dif-fer from each other. For instance, performance (e.g. stability) of a hard real time system such as an avionic control .

Introduction to Real-Time Systems Real-Time Systems, Lecture 1 Martina Maggio and Karl-Erik Arze n 21 January 2020 Lund University, Department of Automatic Control Content [Real-Time Control System: Chapter 1, 2] 1. Real-Time Systems: De nitions 2. Real-Time Systems: Characteristics 3. Real-Time Systems: Paradigms

Operating Systems, Embedded Systems, and Real-Time Systems Janez Puhan Ljubljana, 2015. CIP-CatalogingInPublication NationalandUniversityLibrary,Ljubljana 004.451(078.5)(0.034.2) PUHAN,Janez,1969-Operating Systems, Embedded Systems, and Real-Time Systems [Electronic

computing operating systems and real-time operating systems is the need for " deterministic " timing behavior in the real-time operating systems. Formally, "deterministic" timing means that operating system services consume only known and expected amounts of time. In theory, these service times could be expressed as mathematical formulas.

Key words and phrases: operating system design, real time operating system, layered operating system, software architecture, and process communication. CR Categories: 3.80, 3.83, 4.35. i. INTRODUCTION The Modular Operating System for SUMC (MOSS) is a general purpose real time operating

asics of real-time PCR 1 1.1 Introduction 2 1.2 Overview of real-time PCR 3 1.3 Overview of real-time PCR components 4 1.4 Real-time PCR analysis technology 6 1.5 Real-time PCR fluorescence detection systems 10 1.6 Melting curve analysis 14 1.7 Passive reference dyes 15 1.8 Contamination prevention 16 1.9 Multiplex real-time PCR 16 1.10 Internal controls and reference genes 18

CPSC-663: Real-Time Systems Deterministic Cache Analysis 1 Introduction to Cache Analysis for Real-Time Systems [C. Ferdinand and R. Wilhelm, "Efficient and Precise Cache Behavior Prediction for Real-Time Systems", Real-Time Systems, 17, 131-181, (1999)] (memory performance) Ignoring cache leads to significant resource under-utilization.

10.2 The Real-Time Operating System (RTOS) Real-time operating systems are built around a multi-tasking kernel which controls the allocation of time slices to tasks. A time slice is the period of time a given task has for execution before it is stopped and replaced by another task. This process, also known as context