Final Review Chenyang Lu CSE 467S Embedded Compu5ng Systems
OS: Basic Func2ons Ø OS controls resources: q who gets the CPU; q when I/O takes place; q how much memory is allocated; q power management. Ø Application programs run on top of OS services Ø Challenge: manage multiple, concurrent tasks. Chenyang Lu CSE 467S
POSIX Ø IEEE standards for application portability between Unix variants. q IEEE 1003.1 defines a Unix-like OS interface. q IEEE 1003.2 defines the shell and utilities q IEEE 1003.4 defines real-time extensions. Ø Supported by many operating systems q Variants of UNIX: AIX, HP-UX, Solaris, Linux q Many commercial RTOS Chenyang Lu CSE 467S
Process Ø A process is a unique execution of a program. q Several copies of a program may run simultaneously. Ø A process has its own context. q Data in registers, PC, status. q Stored in Process Control Block (PCB). Ø Thread: lightweight process q Threads share memory space (not registers) in a same process. Ø OS manages processes and threads. Chenyang Lu CSE 467S
Process States Ø A process can be in one of three states: q executing on the CPU; q ready to run; q waiting for data. executing gets CPU preempted needs data Scheduler ready gets data waiting Chenyang Lu 5
Priority- based Scheduling Ø Every job has a priority. Ø CPU goes to the highest-priority job that is ready. Ø Fixed vs. dynamic priority q Fixed priority: all jobs of a same task have a same priority Ø Preemptive vs. non-preemptive 6
Semaphores Ø OS primitive for controlling access to critical regions. q Get access to semaphore S with wait(s). q Perform critical region operations. q Release semaphore with signal(s). Ø Mutex: only one process can hold a mutex at a time. Chenyang Lu CSE 467S
The Differences Ø Interrupt: generated by external devices Ø Exception: generated by CPU due to software errors Ø Trap: enter supervisor mode Chenyang Lu CSE 467S
OS Support for Real- Time Ø Real-Time OS Ø Real-time extensions to general-purpose OS Chenyang Lu CSE 467S
RTOS: Features for Efficiency Ø Small, with minimal set of functionality Ø Fast context switch Ø Fast and time bounded response to interrupts Ø Fixed or variable partitions of memory q May not support paging or virtual memory q May support locking code and data in memory Ø Sequential file that can accumulate data at fast rate q May be memory-based Chenyang Lu CSE 467S
Real- Time Extensions to General OS Ø Generally slower and less predictable than RTOS Ø More functionality and development support Ø Standard interfaces Ø Suitable for soft real-time applications Chenyang Lu CSE 467S
Embedded vs. General- Purpose Ø General-purpose systems q Fairness to all tasks q Optimize throughput q Optimize average performance Ø Embedded systems q Meet all deadlines. q Fairness or throughput is not important q Worry about worst case performance 12
RT- Preempt Patch Ø Officially called CONFIG_PREEMPT_RT patch. Ø Convert Linux into a fully preemptible kernel. Ø Locks q Making in-kernel locking-primitives preemptible through rtmutexes. q Critical sections protected by spinlock_t and rwlock_t are preemptible. q Priority inheritance for in-kernel spinlocks and semaphores. Ø Converting interrupt handlers into preemptible kernel threads. Ø Converting the timer API into separate infrastructures for high resolution kernel timers plus one for timeouts, leading to user space POSIX timers with high resolution. Source: h*ps://rt.wiki.kernel.org/ Chenyang Lu 13
Metrics for Scheduling Algorithms Ø Ability to meet all deadlines. q A task set is schedulable if all jobs meet deadlines. Ø Run-time overhead. q Time required to make scheduling decision. q Number of context switches. 14
Real- Time Schedulability Analysis Ø Task characteristics q Periodic/Aperiodic q Deadline vs. Period q Blocking Ø Important q Understand the assumptions of each analysis. q Know which analysis to apply based on task characteristics. 15
Op2mal Scheduling Algorithms Static Priority D = P RM Utilization bound Response time D < P DM Response time Dynamic Priority EDF Utilization bound EDF Processor demand Assump5ons: periodic, single- processor, no blocking Chenyang Lu 16
Race Condi2ons Ø Critical region: section of code that cannot be interrupted. q Access to shared state (variable) q Access to hardware resource (I/O devices) Ø Prevent race conditions q Semaphores (POSIX) q Disable interrupts (TinyOS) 17
Priority Inversion Ø A low-priority task blocks a high-priority task from running. Ø Problem: Unbounded priority inversion. 18
Unbounded Priority Inversion cri5cal sec5on 1 P(1) blocked by 4,2,3! 1 1 3 2 4 4 4 4 4 0 2 4 6 8 10 12 14 16 18 20 22 19
Priority Inheritance Protocol Ø Fully understand how it works. Ø Schedulability analysis for RM/PIP. q Compute blocking time for each process q Extension to utilization bound and response time analysis Ø Note the assumptions of PIP and analysis! 20
Scheduling Aperiodic Requests Ø Hybrid task set: periodic tasks + aperiodic tasks q Aperiodic tasks: Arrival time is unknown Ø Sporadic task with a hard deadline q Inter-arrival time must be lower bounded q Schedulability analysis: treat as a periodic task with period = minimum inter-arrival time Ø Aperiodic task with a soft deadline q Possibly unbounded inter-arrival time q Maintain hard guarantees on periodic tasks q Reduce response time of aperiodic tasks 21
Aperiodic Servers Ø Background processing q No impact on periodic tasks q Long delay for aperiodic tasks Ø Polling server q Impact on periodic tasks is equivalent to a periodic task q Long delay for aperiodic tasks that miss the server Ø Deferrable server q Changes the utilization bound q Short delay for aperiodic requests 22
Good Luck! J 23