1 / 13

Operating Systems TSL & Priority Inversion

Operating Systems TSL & Priority Inversion. Hardware Solutions. No Interrupt Checking No Context Switching. Disabling/Enabling Interrupts. Check for Interrupt: Process Interrupt. Decode Instruction. Fetch Next Instruction. Execute Instruction. Start. Halt. This solution is dangerous

malana
Download Presentation

Operating Systems TSL & Priority Inversion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating SystemsTSL & Priority Inversion

  2. Hardware Solutions No Interrupt Checking No Context Switching • Disabling/Enabling Interrupts Check for Interrupt: Process Interrupt Decode Instruction Fetch Next Instruction Execute Instruction Start Halt • This solution is dangerous • It will not work if we have multiple CPUs • Since, the Disable Interrupt instruction will execute on only one CPU • Rest of the CPUs, will continue checking the interrupts

  3. Software Lock FLAG = TRUE FLAG = FALSE FLAG = TRUE FLAG = FALSE FLAG = FALSE The solution will work, if Testing and Setting the Flag are atomic Process 1 1.while (FLAG == FALSE); 2.FLAG = FALSE; Process 2 1.while (FLAG == FALSE); 1.while (FLAG == FALSE); 2. 2.FLAG = FALSE; 3.critical_section(); 3.critical_section(); 4.FLAG = TRUE; 5.noncritical_section(); Timeout No two processes may be simultaneously inside their critical sections

  4. Hardware Lock • Some instruction sets assist us in implementing mutual exclusion on multiple processors • Test and Set Lock (TSL) • TSL Rx, LOCK_VARIABLE • Reads the contents of the memory variable LOCK_VARIABLE • Stores it in the Rx register • Stores back the value 1 at the address of LOCK_VARIABLE. Guaranteed to be Atomic

  5. TSL is “Atomic” • Atomic => Uninterruptible • No other process can access the memory until TSL is complete • The CPU executing the TSL instruction locks the memory bus • Thus, prohibits others CPUs from accessing the memory

  6. Mutual Exclusion Using TSL 1.TSL Rx, LOCK; //copy LOCK to register //and LOCK = 1 2.cmp Rx,0 //Check if Old value of //LOCK was 0. (Rx == 0) 3.jne Line1 //Jump if not equal to //Line 1 4.Critical_Section(); 5.mov LOCK,0 //Lock == 0;

  7. Busy Waiting and Priority Inversion • Peterson’s Solution and TSL both solve the mutual exclusion problem • However, both of these solutions sit in a tight loop waiting for a condition to be met (busy waiting). • Wasteful of CPU resources

  8. Busy Waiting and Priority Inversion • Suppose we have two processes • One of high priority H • One of low priority L • The scheduling algorithm runs Hwhenever it is in ready state • Suppose • L is in its critical section • H becomes ready • L will be placed in a ready state • H will be in the run state

  9. Busy Waiting and Priority Inversion • But, the H will not be able to run • Even L cannot run again to release H • This is sometimes known as the • Priority inversion problem.

  10. Sleep and Wakeup • The solution is that if a process Pi cannot enter the critical section • Pi should not waste CPU’s time by executing the Idle loop. • Pi’s status should be changed from Run to Block • Pi should be removed from the ready list • Entered in a block list • Since, Pi is not in the ready list, no context switch will bring Pi in the run state • Thus, Pi will not waste CPU’s cycle.

  11. Sleep and Wakeup • Later on, when Pi can enter the critical section, Pi’s status should be changed from block to ready • It should be entered in the ready list. Dispatch Ready Running No CPU time wastage Can Enter the Critical Section Cannot Enter the Critical Section Blocked

  12. Sleep and Wakeup: Implementation • Sleep() and Wakeup() can be two system calls. • When a process Pi determines that it can not enter the critical section it calls sleep() • Pi Entered in the block list • When the other process finishes with the critical section, it wakesup Pi, Wakeup(Pi) • Pi Entered in the ready list • Wakeup takes a single input parameter, which is the ID of the process to be unblocked

  13. Summary of the Synchronization Solutions discussed so far • 1. Hardware solution • Disable Interrupts on Uniprocessor System • Limitation: Dangerous in user space + No Time slicing • TSL (or something like TSL) on Multiprocessor system • Limitation: Busy Waiting + Priority Inversion • 2. Software solution • Peterson’s solution for two processes • Limitation: Busy Waiting + Priority Inversion • Bakery algorithm for multiple processes • Limitation: Busy Waiting + Priority Inversion

More Related