




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















-^ What^ if^ we^ simply^ did^
the^ most^ straightforward^ thing?
-^ What^ might^ be^ sub‐optimal
about^ this?
-^ contention for^ the^ (centralized)
run^ queue
-^ migrating^ threads^ away
from^ their^ data^ (disrupting
data^ locality)
-^ data^ in^ caches,^ data^ in^ nearby
NUMA^ memories
-^ disrupting^ communication
locality between^ groups^ of
threads
-^ de‐scheduling^ a^ thread
holding^ a^ lock that^ other^ threads^ are^ waiting^ for
-^ Not^ just^ a^ question^ of^
when something^ runs,^ but
also^ where^ it^ runs
-^ need^ to^ optimize^ for^ space CPUCPUCPU^ as^ well^ as^ time Runnable^ Queue
CPU^0 CPU^0 CPU^0 CPU^1 CPU^1 CPU^1 Runnable Queue… CPU^ NCPU^ NCPU^ N Uniprocessor^
Multiprocessor
-^ Advantages^ of^ Distributed
Queues? – easy to maintain affinity,^ since^ a^ blocked^ process
stays^ in^ local^ queue
-^ minimal^ locking^ contention to
access^ queue
-^ But^ what^ about^ load^ balancing?^ –^ need^ to^ steal^ work
from^ other^ queues sometimes Centralized^ Queue CPU^0 CPU^0 CPU^0 CPU^1 CPU^1 CPU^1 Runnable^ Queue… CPU^ NCPU^ NCPU^ N Distributed^ Queues RunnableCPU^0 CPU^0 CPU^0 Queue^0 RunnableCPU^ Queue^1 …
(^1) CPU (^1) CPU (^1) RunnableCPU^ NCPU^ NCPU^ N Queue N
-^ Pull^ model:^ –^ CPU^ notices^ its^ queue
is^ empty^ (or^ below^ threshold),
and^ steals^ work
-^ Push^ model:^ –^ kernel^ daemon^ periodically
checks^ queue^ lengths,^ moves
work^ to^ balance
-^ Many^ systems^ use^ both
!!! RunnableRunnableCPU (^0) CPU (^0) CPU (^0) Queue 0 Queue Steal work RunnableCPU^1 CPU^1 CPU^1 Queue 1 … RunnableCPU^ NCPU^ NCPU^ N Queue N push^ and^ pull
CPU^0 CPU^0 CPU^0 0 RunnableCPU^1 CPU^1 CPU^1 Queue 1 … RunnableCPU Queue N NCPU NCPU N docsity.com
-^ Affinity^ Scheduling^ –^ attempts^ to^ preserve
cache^ locality,^ typically^ using
distributed^ queues
-^ implemented^ in^ the^ Linux
O(1)^ (2.6‐2.6.22)^ and^ CFS (2.6.3‐now)^ schedulers
-^ Space^ Sharing^ –^ divide^ processors^
into^ groups;^ jobs^ wait^ until
required^ #^ of^ CPUs^ are^ available
-^ Time^ Sharing:^ “Gang^ Scheduling”
and^ “Co‐Scheduling”
-^ time^ slice^ such^ that^ all^
threads^ in^ a^ job^ always^ run
at^ the^ same^ time
-^ Knowing^ about^ Spinlocks^ –^ kernel^ delays^ de‐scheduling
a^ thread^ if^ it^ is^ holding^ a^ lock
-^ acquiring/releasing^ lock^ sets/clears
a^ kernel‐visible^ flag
-^ Process^ control/scheduler
activations: – application adjusts its^ number^ of^ active^ threads
to^ match^ #^ of^ CPUs^ given^
to^ it by^ the^ OS
1.^ “Cache^ Coherence”^ –^ do^ all^ loads^ and^ stores
to^ a^ given^ cache^ block^ behave
correctly?
2.^ “Memory^ Consistency
Model”^ (sometimes^ called
“Memory^ Ordering”)
-^ do^ all^ loads^ and^ stores,
even^ to^ separate^ cache^ blocks,
behave^ correctly? Recall:^ our^ intuitionCPU^0
CPU^1
CPU^2 Single^ port^ to^ memory Memory
-^ Memory^ model^ specifies
ordering^ constraints^ among
accesses
-^ Uniprocessor model:^ memory
accesses^ atomic and^ in^ program
order
-^ Not^ necessary^ to^ maintain
sequential^ order^ for^ correctness – hardware: buffering, pipelining – compiler: register allocation,^ code^ motion
-^ Simple for^ programmers •^ Allows^ for^ high^ performance
write Awrite Bread Aread B
ProcessorWRITESREADS^ write Reads check for buffer matching addresses in write buffer Cache docsity.com
-^ Order^ between^ accesses
to^ different^ locations becomes
important
-^ Multiple^ copies^ of^ the same^ location A = 1; wait^ ( A^ ==^ 1);^ B =^1 ;^ A^ Interconnection^ Network
B =^ 1; = 1; ProcessorCache^ A:0 Memory
ProcessorCache^ A:0B:0 Memory
wait^ ( B^ ==^ 1); … =^ A ;^ ProcessorCache^ A:0B:0 Memory ^1 ^1^ ^1 A^ = 1;
Oops! 1 docsity.com
-^ Formalized^ by^ Lamport (1979)^ –^ accesses^ of^ each^ processor
in^ program^ order
-^ all^ accesses^ appear^ in^ sequential
order
-^ Any^ order^ implicitly^ assumed
……P1 P2 Pn Memory by programmer^ is^ maintained
Stripped‐down^ version^ of^
a^2 ‐process^ mutex (minus the^ turn‐taking): P^
A = 1^ (a)^
B = 1^ (c) x = B^ (b)^
y = A^ (d)
-^ all^ locations^ are^ initialized
to^0
-^ possible^ outcomes^ for
(x,y): – (0,1), (1,0), (1,1)
-^ (x,y)^ =^ (0,0) is^ not^ a^ possible
outcome:
-^ a‐>b^ and^ c‐>d^ implied^ by
program^ order
-^ x^ =^0 implies^ b‐>c^ which
implies^ a‐>d
-^ a‐>d^ says^ y^ =^1 which^ leads
to^ a^ contradiction
-^ similarly,^ y^ =^0 implies^ x
=^1 which^ is^ also^ a^ contradiction
-^ Sufficient Conditions^ for
SC^ (Dubois^ et^ al.,^ 1987): – assumes general cache^ coherence^ (if^ we^ have caches):
-^ writes^ to^ the^ same^ location are
observed^ in^ same^ order^ by^ all
P’s
-^ for^ each^ processor,^ delay
issue^ of^ access^ until^ previous
completes
-^ a^ read^ completes^ when^ the
return^ value^ is^ back
-^ a^ write^ completes when^ new
value^ is^ visible^ to^ all^ processors – for simplicity, we assume^ writes^ are^ atomic
-^ Important^ to^ note^ that
these^ are^ not^ necessary^ conditions
for^ maintaining^ SC docsity.com
-^ Processor^ issues^ accesses
one‐at‐a‐time and^ stalls^ for
completion
-^ Low^ processor^ utilization
From^ Gupta^ et^ al,^ “Comparative evaluation^ of^ latency^ reducing^ and tolerating^ techniques.”^ In^ Proceedings^ of the^ 18th^ annual^ International^ Symposium on^ Computer^ Architecture^ (ISCA^ '91) docsity.com
-^ Relax^ constraints^ on^ memory
Total^ Store^ Ordering^ (TSO)
(Similar^ to^ Intel)
See^ Section^ 8.2^ of^ “Intel®^64 and^ IA‐^32 Architectures
Software^ Developer’s^ Manual,^ Volume^ 3A:^ System
Programming^ Guide,^ Part^ 1”, http://www.intel.com/content/dam/www/public/us/en/documents/manuals/
‐ia‐^32 ‐architectures‐software‐developer‐vol‐3a
‐part‐^1 ‐manual.pdf docsity.com