Resource Analysis of Distributed and Concurrent Programs
Elvira Albert
Complutense University of Madrid (Spain) DICE-FOPARA 2017
April 22-23, 2017, Uppsala, Sweden
Elvira Albert, UCM Resource Analysis 1/37
Resource Analysis of Distributed and Concurrent Programs Elvira - - PowerPoint PPT Presentation
Resource Analysis of Distributed and Concurrent Programs Elvira Albert Complutense University of Madrid (Spain) DICE-FOPARA 2017 April 22-23, 2017, Uppsala, Sweden Elvira Albert, UCM Resource Analysis 1/37 what is resource analysis? The
Complutense University of Madrid (Spain) DICE-FOPARA 2017
April 22-23, 2017, Uppsala, Sweden
Elvira Albert, UCM Resource Analysis 1/37
what is resource analysis?
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Upper Bounds (worst case) Lower Bounds (best case)
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Execution steps Visits to p Memory
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Execution steps Visits to p Memory
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Execution steps Visits to p Memory Time? Energy?
Elvira Albert, UCM Resource Analysis 2/37
what is resource analysis?
automatic
Execution steps Visits to p Memory Time? Energy?
Elvira Albert, UCM Resource Analysis 2/37
what is it useful for?
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
U1 U2
Resource Analysis 3/37
what is it useful for?
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
U = 2n2 + 3n Proof:
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
2n + 2m 2n2 + 4m 5n + 3m n log(n) + 4m
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
2n + 2m 2n2 + 4m 5n + 3m n log(n) + 4m 3n+m n+m2 4m n2 ∗ m4 n ∗ m log(n)
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
2n + 2m 2n2 + 4m 5n + 3m n log(n) + 4m 3n+m n+m2 4m n2 ∗ m4 n ∗ m log(n)
Elvira Albert, UCM Resource Analysis 3/37
what is it useful for?
2n + 2m 2n2 + 4m 5n + 3m n log(n) + 4m 3n+m n+m2 4m n2 ∗ m4 n ∗ m log(n)
Elvira Albert, UCM Resource Analysis 3/37
Plan of the talk
Part 1: Cost analysis in sequential programs
Generation of cost relations Inference of upper bounds
Elvira Albert, UCM Resource Analysis 4/37
Plan of the talk
Part 1: Cost analysis in sequential programs
Generation of cost relations Inference of upper bounds
Part 2: Cost analysis in concurrent programs
Loops with concurrent interleavings May-happen-in-parallel analysis Rely-guarantee reasoning
Elvira Albert, UCM Resource Analysis 4/37
Plan of the talk
Part 1: Cost analysis in sequential programs
Generation of cost relations Inference of upper bounds
Part 2: Cost analysis in concurrent programs
Loops with concurrent interleavings May-happen-in-parallel analysis Rely-guarantee reasoning
Part 3: Cost analysis of distributed systems
Dynamic distributed locations Resource analysis with cost centers New performance indicators Parallel and peak cost
Elvira Albert, UCM Resource Analysis 4/37
Part 1: Resource Analysis of Sequential Code
Elvira Albert, UCM Resource Analysis 5/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 3∗size(l)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 3∗size(l)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
while (l != null) { l = l.next; new C(); ⇐ programpoint }
(number of visits to a program point)
1 + 2∗size(l)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
while (l != null) { l = l.next; new C(); ⇐ program point }
(number of visits to a program point)
size(l)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
while (l != null) { l = l.next; new C(); ⇐ program point }
(memory)
size(l)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
while (l != null) { l = l.next; new C(); }
(number of instructions)
1 + 2∗size(l)
while (l != null) { l = l.next; new C(); ⇐ memory }
(memory)
size(l)∗size(C)
Elvira Albert, UCM Resource Analysis 6/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Upper Bound
A Classical approach [Wegbreit’75] to cost analysis consists of:
by means of recurrence relations.
bound (a function of the input data sizes).
Elvira Albert, UCM Resource Analysis 7/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Cost Relations CRs Solver
Upper Bound
A Classical approach [Wegbreit’75] to cost analysis consists of:
by means of recurrence relations.
bound (a function of the input data sizes).
Elvira Albert, UCM Resource Analysis 8/37
Resource Analysis of Sequential Code
Program
(Cost Model) Static Analysis
Cost Relations CRs Solver
Upper Bound
Elvira Albert, UCM Resource Analysis 9/37
Resource Analysis of Sequential Code
Program
(Cost Model) Static Analysis
Cost Relations CRs Solver
Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Static Analysis
while (l != null) l = l.next;
Elvira Albert, UCM Resource Analysis 9/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Static Analysis Cost Relations
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′).
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′).
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′).
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′).
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
while(l) = 1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Recursive Representation Size Analysis
Cost Relations
while (l != null) l = l.next; while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). while(l, l) ← l=null. while(l, l′) ← l=null, l′′=l.next, while(l′′, l′). size1 ← {l=0} size2 ← {l>0, l>l′′}
while(l) = 1 {l=0} while(l) = 2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 10/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Cost Relations CRs Solver
Upper Bound
Elvira Albert, UCM Resource Analysis 11/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Cost Relations CRs Solver
Upper Bound
Resource Analysis 11/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Cost Relations CRs Solver
Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Resource Analysis 11/37
Resource Analysis of Sequential Code
Program
(Cost Model)
Cost Relations CRs Solver
Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 11/37
Resource Analysis of Sequential Code
Cost Relations
CRs Solver Upper Bound
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′} while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l)
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′} while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l) while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′} while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l) while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
Maximization remains the same k1 and k2 are constants
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′} while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l) while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′} while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l) while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l)
Maximization remains the same k1 and k2 are constants
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l∗k2
Elvira Albert, UCM Resource Analysis 12/37
Resource Analysis of Sequential Code
Cost Relations
Ranking function Maximization Upper Bound
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′} while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l) while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
Maximization remains the same k1 and k2 are constants
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
Maximization remains the same k1 and k2 are constants
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l ∗ k2
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l)
Maximization remains the same k1 and k2 are constants
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l∗k2
while(l) = k1 {l=0} while(l) = k2+while(l′′) {l>0, l>l′′}
RF(l) = l
(linear expression on l)
Maximization remains the same k1 and k2 are constants
while+(l) = cost+
bc + RF(l) ∗ cost+ loop
while+(l) = k1 + l∗k2
Elvira Albert, UCM Resource Analysis 12/37
Summary Sequential
The process involves a series of transformations and analyses:
Transformation into recursive form Size analysis Generation of cost relations Ranking functions and maximization
We cover polynomial, exponential, logarithmic complexities From now on: given task m, we assume cost Um Main references: ESOP’07, SAS’08 Handling fields: SAS’10, FM’11
Elvira Albert, UCM Resource Analysis 13/37
Part 2: Concurrent Programs
Elvira Albert, UCM Resource Analysis 14/37
Adding Concurrency
p Different tasks interleave execution in the same processor
Elvira Albert, UCM Resource Analysis 15/37
Adding Concurrency
p m Different tasks interleave execution in the same processor Asynchronous task invocations
m(¯ x)
Elvira Albert, UCM Resource Analysis 15/37
Adding Concurrency
p m
release release
Different tasks interleave execution in the same processor Asynchronous task invocations
m(¯ x)
Non-preemptive concurrency by explicitly releasing the processor
release
Elvira Albert, UCM Resource Analysis 15/37
Adding Concurrency
p m
release release
f x y
Different tasks interleave execution in the same processor Asynchronous task invocations
m(¯ x)
Non-preemptive concurrency by explicitly releasing the processor
release
Shared memory among the different tasks
Elvira Albert, UCM Resource Analysis 15/37
Resource Analysis with interleavings (I)
p
release f=3 f=2 f=1 release f=*
f x y while ( f >0){ . . . f = f −1; r e l e a s e ; }
1st approach: assume that shared memory changes after every release
Elvira Albert, UCM Resource Analysis 16/37
Resource Analysis with interleavings (I)
p
release f=3 f=2 f=1 release f=*
f x y
f=?
while ( f >0){ . . . f = f −1; r e l e a s e ; }
1st approach: assume that shared memory changes after every release Loss of information, poor results → loops based on shared variables cannot be bound.
Elvira Albert, UCM Resource Analysis 16/37
Resource Analysis with interleavings (II)
p m
f=3 f=2 f=1 release release x=3 y=7
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 x = 3 7 y = 7;
p() m() 2nd approach: use a May-Happen-in-Parallel analysis to infer instructions pairs that can interleave: . . . (4, 6), (4, 7) . . .
Elvira Albert, UCM Resource Analysis 17/37
Resource Analysis with interleavings (II)
p m
f=3 f=2 f=1 release release x=3 y=7 f=1
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 x = 3 7 y = 7;
p() m() 2nd approach: use a May-Happen-in-Parallel analysis to infer instructions pairs that can interleave: . . . (4, 6), (4, 7) . . . Shared memory can only change if an update can interleave with
release → improve results
Elvira Albert, UCM Resource Analysis 17/37
Resource Analysis with interleavings (III)
p
f=3 f=2 f=1 release
m
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 while
( x>0){
7
x = x −1;
8
f = 100;
9
r e l e a s e ;
10 }
p() m() 3rd approach: interleavings that modify shared memory are safe if they can only happen a finite number of times
Elvira Albert, UCM Resource Analysis 18/37
Resource Analysis with interleavings (III)
p
f=3 f=2 f=1 release
m
x=1 f=100 release
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 while
( x>0){
7
x = x −1;
8
f = 100;
9
r e l e a s e ;
10 }
p() m() 3rd approach: interleavings that modify shared memory are safe if they can only happen a finite number of times
Elvira Albert, UCM Resource Analysis 18/37
Resource Analysis with interleavings (III)
p
f=3 f=2 f=1 release
m
x=1 f=100 release f=100 f=99 . . . f=1 release
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 while
( x>0){
7
x = x −1;
8
f = 100;
9
r e l e a s e ;
10 }
p() m() 3rd approach: interleavings that modify shared memory are safe if they can only happen a finite number of times
Elvira Albert, UCM Resource Analysis 18/37
Resource Analysis with interleavings (III)
p
f=3 f=2 f=1 release
m
x=1 f=100 release f=100 f=99 . . . f=1 release x=0 f=100 release
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 while
( x>0){
7
x = x −1;
8
f = 100;
9
r e l e a s e ;
10 }
p() m() 3rd approach: interleavings that modify shared memory are safe if they can only happen a finite number of times
Elvira Albert, UCM Resource Analysis 18/37
Resource Analysis with interleavings (III)
p
f=3 f=2 f=1 release
m
x=1 f=100 release f=100 f=99 . . . f=1 release x=0 f=100 release f=100 f=99 . . . f=1 release
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 while
( x>0){
7
x = x −1;
8
f = 100;
9
r e l e a s e ;
10 }
p() m() 3rd approach: interleavings that modify shared memory are safe if they can only happen a finite number of times
Elvira Albert, UCM Resource Analysis 18/37
Resource Analysis with interleavings (III)
p
f=3 f=2 f=1 release
m
x=1 f=100 release f=100 f=99 . . . f=1 release x=0 f=100 release f=100 f=99 . . . f=1 release
f x y
1 while
( f >0){
2
. . .
3
f = f −1;
4
r e l e a s e ;
5 } 6 while
( x>0){
7
x = x −1;
8
f = 100;
9
r e l e a s e ;
10 }
p() m() 3rd approach: interleavings that modify shared memory are safe if they can only happen a finite number of times Rely-guarantee reasoning: max(f ) × (max(x) + 1)
Elvira Albert, UCM Resource Analysis 18/37
Summary Concurrent Programs
Basic resource analysis for sound results APLAS’11 May-happen-in-parallel analysis FORTE’12, LPAR’13, SAS’15 Rely-guarantee reasoning ATVA’13, JAR’17 From now on: given a concurrent task m, we assume cost Um
Elvira Albert, UCM Resource Analysis 19/37
Part 3: Distributed Systems
Elvira Albert, UCM Resource Analysis 20/37
Adding distribution
x
X = newLoc to create a
distributed location
Elvira Albert, UCM Resource Analysis 21/37
Adding distribution
x
p q
X = newLoc to create a
distributed location A location has a queue of pending tasks and one active task
Elvira Albert, UCM Resource Analysis 21/37
Adding distribution
x
p q
y
r p
z
t u
X = newLoc to create a
distributed location A location has a queue of pending tasks and one active task Multiple locations can be created dynamically y=newLoc; z=newLoc
Elvira Albert, UCM Resource Analysis 21/37
Adding distribution
x
p q
y
r p
z
t u
x
p q m
X = newLoc to create a
distributed location A location has a queue of pending tasks and one active task Multiple locations can be created dynamically y=newLoc; z=newLoc Asynchronous tasks can be added among locations: x.m(w) (in z)
Elvira Albert, UCM Resource Analysis 21/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Idea: use cost centers to separate the cost
c(x), c(y), c(z)
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Idea: use cost centers to separate the cost
c(x), c(y), c(z)
When we analyze an instruction i, its cost Ci is added to the cost center of the x component: c(x) · Ci
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Idea: use cost centers to separate the cost
c(x), c(y), c(z)
When we analyze an instruction i, its cost Ci is added to the cost center of the x component: c(x) · Ci Global cost expression:
c(x)·(Up+Uq+Um)+c(y)·(Ur+Up)+c(z)·(Ut+Uu)
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Idea: use cost centers to separate the cost
c(x), c(y), c(z)
When we analyze an instruction i, its cost Ci is added to the cost center of the x component: c(x) · Ci Global cost expression:
c(x)·(Up+Uq+Um)+✭✭✭✭✭
✭
c(y)·(Ur+Up)+✭✭✭✭✭
✭
c(z)·(Ut+Uu)
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Idea: use cost centers to separate the cost
c(x), c(y), c(z)
When we analyze an instruction i, its cost Ci is added to the cost center of the x component: c(x) · Ci Global cost expression: ✭✭✭✭✭✭✭ ✭
c(x)·(Up+Uq+Um) + c(y)·(Ur+Up) +✭✭✭✭✭
✭
c(z)·(Ut+Uu)
Elvira Albert, UCM Resource Analysis 22/37
Resource analysis with cost centers
x
p q m
y
r p
z
t u
Using cost analysis so far:
C = Up + Uq + Um + Ur + Up + · · · + Ut + Uu
We aim at having the cost at the level of distributed components
Cx = Up + Uq + Um Cy = Ur + Up . . .
Idea: use cost centers to separate the cost
c(x), c(y), c(z)
When we analyze an instruction i, its cost Ci is added to the cost center of the x component: c(x) · Ci Global cost expression: ✭✭✭✭✭✭✭ ✭
c(x)·(Up+Uq+Um) +✭✭✭✭✭
✭
c(y)·(Ur+Up) + c(z)·(Ut+Uu)
Elvira Albert, UCM Resource Analysis 22/37
Cost centers of different types
x
p q m
y
r p
z
t u
Cost centers are a general concept that allows us to distinguish within the UB different aspects:
Elvira Albert, UCM Resource Analysis 23/37
Cost centers of different types
x
p q m
y
r p
z
t u
Cost centers are a general concept that allows us to distinguish within the UB different aspects: Component cost centers: c(x), c(y)..
Elvira Albert, UCM Resource Analysis 23/37
Cost centers of different types
x
p q m
y
r p
z
t u
Cost centers are a general concept that allows us to distinguish within the UB different aspects: Component cost centers: c(x), c(y).. Program point cost centers: cost center c(pp) per pp:acquire(e) for (x=0;x<n;x++) pp:acquire(e) c(pp) ∗ n ∗ max(e) +c(pp2) ∗ ...
Elvira Albert, UCM Resource Analysis 23/37
Cost centers of different types
x
p q m
y
r p
z
t u
Cost centers are a general concept that allows us to distinguish within the UB different aspects: Component cost centers: c(x), c(y).. Program point cost centers: cost center c(pp) per pp:acquire(e) for (x=0;x<n;x++) pp:acquire(e) c(pp) ∗ n ∗ max(e) +c(pp2) ∗ ... Task level centers: cost center c(m) per method c(m) ∗ Cm+c(p) ∗ ...
Elvira Albert, UCM Resource Analysis 23/37
Cost centers of different types
x
p q m
y
r p
z
t u
Cost centers are a general concept that allows us to distinguish within the UB different aspects: Component cost centers: c(x), c(y).. Program point cost centers: cost center c(pp) per pp:acquire(e) for (x=0;x<n;x++) pp:acquire(e) c(pp) ∗ n ∗ max(e) +c(pp2) ∗ ... Task level centers: cost center c(m) per method c(m) ∗ Cm+c(p) ∗ ... Multi-component cost centers: cost centers of the form c(z, x), i.e., when we find an instruction x.m(w) in z we do c(z, x) ∗ size(w)
Elvira Albert, UCM Resource Analysis 23/37
Part 3: Distributed Systems
Elvira Albert, UCM Resource Analysis 24/37
Parallel Cost
Serial cost: accumulate costs from different locations Limitation: ignore the parallelism of the distributed execution model. New analysis: infer the parallel cost of distributed systems (maximum cost between parallel tasks) Use: know if an application succeeds in exploiting the parallelism of the distributed locations, overall resource consumption
Elvira Albert, UCM Resource Analysis 25/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
Trace
1
y
m1 m2 m3 p q
P1
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
Trace
1
y
m1 m2 m3 p q
P1
P1 = Um1 + Um2 + Um3
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
P1 = Um1 + Um2 + Um3 Trace
2
y
m1 m2 m3 p q
P2
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
P1 = Um1 + Um2 + Um3 Trace
2
y
m1 m2 m3 p q
P2
P2 = Um1 + Up
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
P1 = Um1 + Um2 + Um3 P2 = Um1 + Up Trace
3
y
m1 m2 m3 p q
P3
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
P1 = Um1 + Um2 + Um3 P2 = Um1 + Up Trace
3
y
m1 m2 m3 p q
P3
P3 = Um1 + Um2 + Uq
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost
void m ( int n) { . . . // m1 x . p(n) ; . . . // m2 y . q(n) ; . . . // m3 }
P1 = Um1 + Um2 + Um3 P2 = Um1 + Up Trace
3
y
m1 m2 m3 p q
P3
P3 = Um1 + Um2 + Uq The parallel cost of the program is the maximum of all possible traces: P = max(P1, P2, P3) < Serial
Elvira Albert, UCM Resource Analysis 26/37
Parallel Cost Analysis
Program Distributed Flow Graph
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 m3
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 m3
N1={m1, m2, m3}
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 p
N1={m1, m2, m3}
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 p
N1={m1, m2, m3} N2={m1, p}
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 q
N1={m1, m2, m3} N2={m1, p}
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 q
N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q}
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q
N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 m3
N1={m1, m2, m3} N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 m3
N1={m1, m2, m3} N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq UB|N1=Um1+Um2+Um3 Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 +✘✘✘ ✘ c(p)·Up +✘✘✘ ✘ c(q)·Uq
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 p
N1={m1, m2, m3} N2={m1, p} N2={m1, p} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq UB|N1=Um1+Um2+Um3
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 p
N1={m1, m2, m3} N2={m1, p} N2={m1, p} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq UB|N1=Um1+Um2+Um3 UBN2=Um1 + Up Serial=c(m1)·Um1 +✘✘✘✘ ✘ c(m2)·Um2 +✘✘✘✘ ✘ c(m3)·Um3 + c(p)·Up +✘✘✘ ✘ c(q)·Uq
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 q
N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq UB|N1=Um1+Um2+Um3 UBN2=Um1 + Up
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q m1 m2 q
N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq UB|N1=Um1+Um2+Um3 UBN2=Um1 + Up UBN3 = Um1 + Um2 + Uq Serial=c(m1)·Um1 + c(m2)·Um2 +✘✘✘✘ ✘ c(m3)·Um3 +✘✘✘ ✘ c(p)·Up + c(q)·Uq
Elvira Albert, UCM Resource Analysis 27/37
Parallel Cost Analysis
Program Distributed Flow Graph
m1 m2 m3 p q
N1={m1, m2, m3} N2={m1, p} N3={m1, m2, q} Serial=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq UB|N1=Um1+Um2+Um3 UBN2=Um1 + Up UBN3 = Um1 + Um2 + Uq
The parallel cost of the program is the maximum of all possible UB’s: UBP = max(UBN1, UBN2, UBN3) < Serial
UB=c(m1)·Um1 + c(m2)·Um2 + c(m3)·Um3 + c(p)·Up + c(q)·Uq
Elvira Albert, UCM Resource Analysis 27/37
Elvira Albert, UCM Resource Analysis 28/37
Part 2: Distributed Systems
Elvira Albert, UCM Resource Analysis 29/37
Motivation
Non-cumulative resources: are acquired and then released New notion of cost: infer the peak cost vs. the total cost Technical difficulty: not enough to reason on the final state
any intermediate step Key feature: framework can be instantiated to measure any type of non-cumulative resource that is acquired and (optionally) freed.
Elvira Albert, UCM Resource Analysis 30/37
Handling resources
Two instructions for handling resources:
y = acquire(e) allocates the amount of resources stated by expression e. release y releases resources referenced by y.
resource leaks when
Reusing a resource variable without releasing previous resources. Reaching the end of a method without releasing a resource variable.
Elvira Albert, UCM Resource Analysis 31/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
x:k1 L2
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
x:k1 L2 r:k2 x:k1 L3
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
Total = k1 + k2 + s + n
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
Total = k1 + k2 + s + n
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
P1 = k1 + k2 + s P1
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
Total = k1 + k2 + s + n
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
P1 = k1 + k2 + s P2 = k1 + k2 + n P2
Elvira Albert, UCM Resource Analysis 32/37
Peak Cost: Motivating Example
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
Total = k1 + k2 + s + n
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
P1 = k1 + k2 + s P2 = k1 + k2 + n The peak cost is the maximum between them: Peak = max(P1, P2) < Total
Elvira Albert, UCM Resource Analysis 32/37
Simultaneous resource analysis
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
A1 = {a2, a3, a4}
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
1 main ( int
s , int n) {
2
x = acquire(k1 ) ;
3
r = acquire(k2 ) ;
4
r = acquire( s ) ;
5
release r ;
6
y = acquire(n) ;
7
release x ;
8 }
A1 = {a2, a3, a4}
A2 = {a2, a3, a6}
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
A1 A2
A1 = {a2, a3, a4} A2 = {a2, a3, a6}
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
A1 = {a2, a3, a4} A2 = {a2, a3, a6}
Total = c(a2) · k1 + c(a3) · k2 + c(a4) · s + c(a6) · n
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
A1
A1 = {a2, a3, a4} A2 = {a2, a3, a6}
Total = c(a2) · k1 + c(a3) · k2 + c(a4) · s + c(a6) · n Total = c(a2) · k1 + c(a3) · k2 + c(a4) · s +✘✘✘
✘
c(a6) · n
UB|A1 = k1 + k2 + s
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
A2
A1 = {a2, a3, a4} A2 = {a2, a3, a6}
Total = c(a2) · k1 + c(a3) · k2 + c(a4) · s + c(a6) · n Total = c(a2) · k1 + c(a3) · k2 +✘✘✘
✘
c(a4) · s + c(a6) · n
UB|A1 = k1 + k2 + s UB|A2 = k1 + n + k2
Elvira Albert, UCM Resource Analysis 33/37
Simultaneous resource analysis
x:k1 L2 r:k2 x:k1 L3 r:s r:k2 x:k1 L4 r:k2 x:k1 L5 y:n r:k2 x:k1 L6 y:n r:k2 L7
A1 = {a2, a3, a4} A2 = {a2, a3, a6}
Total = c(a2) · k1 + c(a3) · k2 + c(a4) · s + c(a6) · n Total = c(a2) · k1 + c(a3) · k2 + c(a4) · n + c(a6) · s
UB|A1 = k1 + k2 + s UB|A2 = k1 + n + k2
The UB on the peak cost of the program is the maximum of all UB’s: UBN = max(UBA1, UBA2) < Total
Elvira Albert, UCM Resource Analysis 33/37
Elvira Albert, UCM Resource Analysis 34/37
Summary Distributed Systems
Cost centers based resource analysis APLAS’11 New performance indicators iFM’13 Parallel cost analysis SAS’15 Peak cost analysis TACAS’15
Elvira Albert, UCM Resource Analysis 35/37
Conclusions
Cost Analysis
research on cost analysis dates back to 1975 generating and solving different forms of recurrence relations
Elvira Albert, UCM Resource Analysis 36/37
Conclusions
Cost Analysis
research on cost analysis dates back to 1975 generating and solving different forms of recurrence relations
From sequential to concurrent systems
Concurrent interleavings May-happen-in-parallel based analysis Rely-guarantee
Elvira Albert, UCM Resource Analysis 36/37
Conclusions
Cost Analysis
research on cost analysis dates back to 1975 generating and solving different forms of recurrence relations
From sequential to concurrent systems
Concurrent interleavings May-happen-in-parallel based analysis Rely-guarantee
From concurrent to distributed systems
New performance indicators New notions of cost
Parallel cost Peak cost
Elvira Albert, UCM Resource Analysis 36/37
Conclusions
Cost Analysis
research on cost analysis dates back to 1975 generating and solving different forms of recurrence relations
From sequential to concurrent systems
Concurrent interleavings May-happen-in-parallel based analysis Rely-guarantee
From concurrent to distributed systems
New performance indicators New notions of cost
Parallel cost Peak cost
Integrated in the SACO system, Static Analyzer for Concurrent Objects
Elvira Albert, UCM Resource Analysis 36/37
Credits
http://costa.ls.fi.upm.es Elvira Albert Puri Arenas Einar Broch Johnsen Jes´ us Correas Jes´ us Domenech Antonio Flores Samir Genaim Miguel G´
Pablo Gordillo Miguel Isabel Enrique Mart´ ın-Mart´ ın Germ´ an Puebla Guillermo Rom´ an Damiano Zanardini
Elvira Albert, UCM Resource Analysis 37/37