Ch3-2

433 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
433
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ch3-2

  1. 1. Priority InversionWhen a low-priority task blocks a higher-priority one, a priorityinversion is said to occurAssume that priorities: p1>p2>p3, and tasks 1 and 3 share the samecritical resource 1
  2. 2. Priority Inheritance ProtocolIn the PIP the priorities of tasks are dynamically changed so that thepriority of any task in a critical section gets the priority of the highesttask pending on that same critical resource. 2
  3. 3. Priority Inheritance Protocol 3
  4. 4. Priority Inheritance Protocol 4
  5. 5. Priority Ceiling ProtocolEach resource is assigned a priority ceiling equal to the priority ofthe highest priority task that can use it 5
  6. 6. Priority Ceiling Protocol 6
  7. 7. Priority Ceiling Protocol 7
  8. 8. ORIGINAL CEILING PRIORITY PROTOCOL (OCPP)•Each process has a static default priority assigned (for example,by deadline monotonic scheme: less deadline – greater priority, orby rate monotonic scheme: less period – greater priority).•Each resource has a static ceiling value defined, this is themaximum priority of the processes that use it (assume that greaterpriority is represented by greater value).•A process has a dynamic priority which is the maximum of its ownstatic priority and any it inherits due to it blocking higher-priorityprocesses (when process blocks higher-priority task it getstemporarily this higher priority).•A process can only lock a resource if its dynamic priority is higherthan the ceiling of any currently locked resource (excluding any thatit has already locked). 8
  9. 9. Original Ceiling Priority ProtocolD E E b b Q V EC E b P P b b P P P V V EB P b P P b b P P P P P P E EA E Q P Q P P Q Q P P P P P P P P E 9
  10. 10. 10
  11. 11. Memory ManagementStack management:Ideally, provision of at least one more task than anticipated should beallocated to the stack to allow for spurious interrupts and timeoverloading 11
  12. 12. Memory Management 12
  13. 13. SwappingA process is saved to an external device when its timeexpires. The next process is loaded instead OverlaysMain(){a(); b(); c()}This program can be represented as a root segmentalways resident in memory, and three overlay segmentsa, b, cMemory required in this case ismax(mem_a,mem_b,mem_c)instead ofmem_a+mem_b+mem_c 13
  14. 14. PartitionsStatic partitions with absolute addressesNumber of partitions and the sizes are fixed. Tasks arecompiled for the particular partition. There may be a skew inpartitions loadingStatic partitions with relative addressesNumber of partitions and the sizes are fixed. Tasks arecompiled for any partition, need adjustment.Happens internal fragmentationDynamic partitionsNumber of partitions vary, tasks get partition of the necessarysize. External fragmentation can occur => garbage collection(de-fragmentation) 14
  15. 15. De-fragmentation 15
  16. 16. Virtual MemorySegmented: virtual address = (segment, offset)Address=start(segment)+offsetPaged: (page, offset)Address=start(page)+offsetSegmented-paged: (segment, page, offset)Address=start(segment)+start(page)+offset Replacement algorithmsFIFO, LRU (Least recently used)If we have 4 page memory and2 4 6 8 is a a page reference string (page 2 is the least andpage 8 is the most recently used) then2 4 6 8 9 2 4 6 8 9 2 4 6 8 9 will lead to page thrashingMemory locking, Working sets 16
  17. 17. I/O Problems Disk fragmentation Contiguous file allocation: place parts of a file in adjacent sectors Elevator algorithm: reorder queries so that they will be served with minimal magnetic head replacement Criteria for RTOS1. Interrupt latency2. Number of processes system can maintain3. Memory for OS4. Scheduling mechanisms set (round-robin, preemptive, etc)5. Available communication methods (mutexes, semaphores, etc)6. After sale support 17
  18. 18. RTOS Criteria7. Software development kits available8. Hardware platforms support9. Source code availability10. Task context switch time11. RTOS cost12. Compatibility with other RTOS13. Networks and network protocols supported by RTOSA fitness metric can be 13 M   i  1  i m i 18
  19. 19. 19
  20. 20. 20
  21. 21. POSIX (Portable Operating System Interfacefor Computer Environments, IEEE Standard) http://www.unix.org/single_unix_specification/1. Threads – each process can contain several threads2. Mutexes and Condition variables -It is essential to associate a mutex with a condition variable. A threadlocks the mutex for some shared data and then checks whether dataare in the proper state. If no, the thread waits on the appropriatecondition variable. Waiting on the condition variable automaticallyunlocks the mutex. When some thread puts the data in the properstate, it wake a waiting thread by signaling. One thread comes out ofits wait state with the mutex locked 21
  22. 22. POSIX SemaphoresBinary and counting 22
  23. 23. POSIX Messages 23
  24. 24. Real-Time POSIX SignalsSignals are software representation of interrupts or exceptionoccurrences. No routine should be called from a signal handlerthat might cause the handler to block.Signals are used for•Exception handling•Process notification of asynchronous event occurrence•Process termination in an abnormal situation•Interprocess communication 24
  25. 25. Real-Time POSIX Signals 25
  26. 26. Real-Time POSIX Signals 26
  27. 27. System POSIX Signals 27
  28. 28. Clocks and TimersTypically the system time is represented by a 32 bit unsigned integer,while tick value (time resolution) is represented by a float-point value If k denotes system tick, and n is the value stored in sys_clock, then the actual time elapsed is kn 28
  29. 29. POSIX Clocks POSIX allows many clocks to be used by an application. Each clock has its own identifier of type clockid_t. Commonly supported and used identifier is CLOCK_REALTIME that is systemwide clock visible for all processes.Data structure timespec has two fields of the long integer typerepresenting the value in number of seconds since the Epoch(tv_sec) and in nano-seconds (tv_nsec). Epoch started 00:00:001.1.1970 29
  30. 30. POSIX Clocks 30
  31. 31. POSIX Timers 31
  32. 32. POSIX Timers 32
  33. 33. POSIX Asynchronous Input/OutputAIO operations use AIO Control Block aiocb: 33
  34. 34. POSIX Memory Locking 34

×