Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Critical Section - Program Optimization for Multi Core Architectures - Lecture Slides, Slides of Computer Science

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

2012/2013

Uploaded on 03/28/2013

ekanath
ekanath 🇮🇳

3.8

(4)

80 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Objectives_template
file:///D|/...ary,%20Dr.%20Sanjeev%20K%20Aggrwal%20&%20Dr.%20Rajat%20Moona/Multi-core_Architecture/lecture%2041/41_1.htm[6/14/2012 12:15:49 PM]
Module 21: Problem and Solution
Lecture 41: Solution to Critical Section Problem
The Lecture Contains:
Solution to Critical Section Problem
Mutual Exclusion
Progress
Bounded Wait
Solution Issues
Two Process Critical Section Solution
Solution to Critical Section Problem
Synchronization Support in OS/ISA
Support in ISA
Implementing Locks Using Swap
Other Supports From ISA
Support From The OS
Multiprocessor Issues
Semaphores
Mutual Exclusion Using Semaphore
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Critical Section - Program Optimization for Multi Core Architectures - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Module 21: Problem and Solution

Lecture 41: Solution to Critical Section Problem

The Lecture Contains:

Solution to Critical Section Problem

Mutual Exclusion

Progress

Bounded Wait

Solution Issues

Two Process Critical Section Solution

Solution to Critical Section Problem

Synchronization Support in OS/ISA

Support in ISA

Implementing Locks Using Swap

Other Supports From ISA

Support From The OS

Multiprocessor Issues

Semaphores

Mutual Exclusion Using Semaphore

Module 21: Problem and Solution

Lecture 41: Solution to Critical Section Problem

Solution to Critical Section Problem

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

Mutual Exclusion

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.

Module 21: Problem and Solution

Lecture 41: Solution to Critical Section Problem

Solution Issues

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.

Two Process Critical Section Solution

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 }

Module 21: Problem and Solution

Lecture 41: Solution to Critical Section Problem

Solution to Critical Section Problem

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 Support in OS/ISA

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.

Module 21: Problem and Solution

Lecture 41: Solution to Critical Section Problem

Other Supports from ISA

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;

Support From The OS

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.

Module 21: Problem and Solution

Lecture 41: Solution to Critical Section Problem

Synchronization Support in OS/ISA

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

Solutions for Multi-processes

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

Multiprocessor Issues

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