Operating Systems Chenyang Lu
Example: Linux Ø A Brief History: https://youtu.be/aurdhyl7bta Chenyang Lu 2
Android Source: h*p:// en.wikipedia.org/wiki/ File:Android-System- Architecture.svg Chenyang Lu 3
Killer App for Real-Time? Ø In 2001, about a year after I joined IBM, I got involved with the Sony-Toshiba-IBM initiative that's leading up to the Sony PlayStation 3. Of course, game systems have extremely severe real-time requirements. All the gaming systems I have seen recently offer sub-reflex response (and, yes, I do have three teenagers, so I have seen a few video games). Gamers will not put up with jerky response, so one-second response times just will not cut it; milliseconds rather than seconds are required. Ø So we are in the very interesting state where gaming and entertainment are major factors driving the technology. When was the last time you heard someone say, "Hey, I bought a new PC and Excel really runs a lot faster"? I used to hear that, back in the early '90s. Paul McKenney, IBM Linux Technology Center Shrinking slices: Looking at real time for Linux, PowerPC, and Cell Chenyang Lu 4
Basic Func=ons Ø 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 5
Example: Engine Control Concurrent tasks Ø spark control Ø crankshaft sensing Ø fuel/air mixture Ø oxygen sensor engine controller Chenyang Lu 6
POSIX (Portable Opera=ng System Interface) Ø 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: Linux, MacOS, AIX, HP-UX, Solaris q Many commercial RTOS Chenyang Lu 7
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 in a same process. Ø OS manages processes and threads. Chenyang Lu 8
Context Switch process 1 process 2... PC registers CPU memory Chenyang Lu 9
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 10
Process Management Ø OS keeps track of: q process priorities; q scheduling state; q process control block. Ø Processes may be created: q statically before system starts; q dynamically during execution. Ø OS controls context switches and what process runs. Chenyang Lu 11
Priority Scheduling Ø Every process has a priority. Ø CPU goes to the ready process with the highest priority. q Fixed vs. dynamic priority q Preemptive vs. non-preemptive Chenyang Lu 12
Preemp=ve Priority Scheduling Ø Each process has a fixed priority (1 highest); Ø P 1 : priority 1; P 2 : priority 2; P 3 : priority 3. P 3 released P 2 released P 1 released P2 P1 P2 P3 0 10 20 30 40 50 60 time Chenyang Lu 13
Preemp=ve Priority Scheduling Ø Most common real-time scheduling approach q Real-time POSIX q Real-time priorities in Linux q Most RTOS Ø Not the only possible way q Non-preemptive q Clock-driven scheduling q Reservation-based scheduling Chenyang Lu 14
Semaphores Ø OS primitive for controlling access to critical regions. q Get access to semaphore S with sem_wait(s). q Perform critical region operations. q Release semaphore with sem_post(s). Ø Mutex: only one process can hold a mutex at a time. Chenyang Lu 15
Supervisor Mode Ø The mode in which the OS usually runs. Ø Provide protective barriers between applications and OS. q Prevent applications from corrupting OS data. Ø Can do the following only in the supervisor mode q Access the kernel address space q Execute privileged instructions Example: Set real-time priority q Access special hardware Ø Careful with memory access when q programs run in supervisor mode q processor has no supervisor mode Chenyang Lu 16
Trap (SoNware Interrupt) Ø Enter supervisor mode. Ø Make system calls. q Open file, read from network Ø Example: ARM q Use SWI instruction to enter supervisor mode: SWI CODE_1 q Sets PC to 0x08. q Argument to SWI is passed to supervisor mode code. Chenyang Lu 17