





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
These are the Lecture Slides of Program Optimization for Multi Core Architectures which includes Triangular Lower Limits, Multiple Loop Limits, Dependence System Solvers, Single Equation, Simple Test, Extreme Value Test etc.Key important points are: Critical Section, Mutual Exclusion, Progress, Bounded Wait, Solution Issues, Process Critical Section Solution, Synchronization Support
Typology: Slides
1 / 9
This page cannot be seen from the preview
Don't miss anything!
Requirements Mutual Exclusion Progress Bounded Wait We can make no assumptions on Processor speed Relative speeds of processes Time to execute any critical/remainder section Time to execute any entry/exit code
Statement of obvious If a process is in critical section at some point in time, no other process should be permitted to enter its critical section. This is clearly the most basic requirement for the solution.
Preemptive kernel A process may be preempted when in kernel mode Non-preemptive kernel A process may not be preempted when in kernel mode Preemptive kernels are difficult Especially for SMP machines. Threads on multi-processors face independent OS. Preemptive kernels are essential In embedded systems with RT guarantees Windows 2000, XP are non-preemptive Linux kernel became preemptive since Linux 2.
Processes are P0 and P1. Processes share a common variable turn(=0 or 1). If turn= i, Pi is permitted to enter the critical section.
while (1) { While (turn != i); Critical section turn = 1-i; Remainder section }
Consider two processes P0 and P1. Shared variables (for solution to CSP) int turn; boolean flag[2]; flag[ i ] is true when Piis ready to enter its critical section.
while (1) { flag[i] = TRUE; turn = j; while (flag[j] && turn == j); Critical section flag[i] = FALSE; Remainder section }
Synchronization code can be written using locks while (1) { Non critical code Acquire Lock Critical Section Code Release Lock } Implementation of Lock require support from the ISA TestAndSet instruction, Swap instruction.
Some processors support TestAndSet instruction. boolean TestAndSet(boolean *mem) { boolean ret = *mem; *mem = TRUE; return ret; } Acquire Lock: while TestAndSet(&lock) ; Release Lock: lock = false;
If OS is non-preemptive System calls can be provided for Acquire Lock and Release Lock. Process can not be preempted while acquiring and releasing locks. If OS is preemptive. System calls are tricky to support but not impossible.
Synchronization code can be written using locks while (1) { Non critical code Acquire Lock Critical Section Code Release Lock } Implementation of Lock require support from the ISA TestAndSet instruction, Swap instruction OS may provide system calls to Acquire lock or release lock. For preemptive OS kernels, hard to implement these calls
boolean waiting[n], lock; waiting[i] = TRUE; key = TRUE; while (waiting[i] && key) key = TestAndSet(&lock); waiting[i] = FALSE; // Critical Section j = (i+1)%n; while ((j != i) && waiting[j]==FALSE) j = (j+1)%n; if (j==i) lock=FALSE; else waiting[j] = FALSE; // Remainder Section
Multiple processors share a single bus. Arbitration is for bus cycles Atomicity across processors is at the granularity of bus cycle. TestAndSet or Swap instructions require At least one read and one write cycle Bus arbitration logic has to be instructed to give bus for two cycles. Lock instruction prefix in Pentium For example lock xchg %ax, mem Lock instruction causes an arbitration sequence to be done for the entire instruction. Atomic instruction execution across multiple processors