synchronous c wcrt algebra 101
play

Synchronous C + WCRT Algebra 101 Reinhard von Hanxleden Joint work - PowerPoint PPT Presentation

Synchronous C + WCRT Algebra 101 Reinhard von Hanxleden Joint work with Michael Mendler, Claus Traulsen, . . . Real-Time and Embedded Systems Group (RTSYS) Department of Computer Science Christian-Albrechts-Universit at zu Kiel


  1. Synchronous C + WCRT Algebra 101 Reinhard von Hanxleden Joint work with Michael Mendler, Claus Traulsen, . . . Real-Time and Embedded Systems Group (RTSYS) Department of Computer Science Christian-Albrechts-Universit¨ at zu Kiel www.informatik.uni-kiel.de/rtsys SYNCHRON 2011, Le Bois du Lys

  2. SC Basics Synchronous C An Alternative SC Syntax WCRT Algebra Summary Overview Synchronous C SC Basics An Alternative SC Syntax Summary WCRT Algebra v. Hanxleden, Mendler, Traulsen Synchronous C + WCRT Algebra 101 Slide 2

  3. SC Basics Synchronous C An Alternative SC Syntax WCRT Algebra Summary The SC-Story From Last Time How to get deterministic concurrency? ◮ Deterministic decision on when to perform context switch ◮ Deterministic decision on what thread to switch to Idea: Cooperative thread scheduling at application level ◮ As in co-routines, threads decide when to resume another thread (static) ◮ However, a dispatcher decides what thread to resume (dynamic) ◮ Reactive control flow implemented at application level—are still executing a sequential C program! v. Hanxleden, Mendler, Traulsen Synchronous C + WCRT Algebra 101 Slide 3

  4. Producer Consumer Observer int main() { int main() { int main() { DEAD(28); DEAD(41); DEAD(41); volatile unsigned int * buf = volatile unsigned int * buf = volatile unsigned int * buf = (unsigned int*)(0x3F800200); (unsigned int*)(0x3F800200); (unsigned int*)(0x3F800200); unsigned int i = 0; unsigned int i = 0; volatile unsigned int * fd = for (i = 0; ; i++ ) { int arr[8]; (unsigned int*)(0x80000600); DEAD(26); for (i =0; i<8; i++) unsigned int i = 0; *buf = i; arr[i] = 0; for (i = 0; ; i++ ) { } for (i = 0; ; i++) { DEAD(26); return 0; DEAD(26); *fd = *buf; } register int tmp = *buf; } arr[i%8] = tmp; return 0; } } return 0; } Lickly et al. , Predictable Programming on a Precision Timed Architecture , CASES’08 14 // == TICK FUNCTION == 31 Consumer: 15 int tick () 32 for (j = 0; j < 8; j++) 1 #include ”sc.h” 16 { 33 arr [ j ] = 0; 2 17 static int BUF, fd, i , j , 34 for (j = 0; ; j++) { 3 // == MAIN FUNCTION == 18 k = 0, tmp, arr [8]; 35 PAUSE; 4 int main() 19 36 tmp = BUF; 5 { 20 TICKSTART(1); 37 arr [ j % 8] = tmp; } 6 int notDone; 21 38 7 22 PCO: 39 Observer: 8 do { 23 FORK(Producer, 3); 40 for ( ; ; ) { 9 notDone = tick(); 24 FORK(Consumer, 2); 41 PAUSE; 10 //sleep(1); 25 FORKE(Observer); 42 fd = BUF; 11 } while (notDone); 26 43 k++; } 12 return 0; 27 Producer: 44 13 } 28 for (i = 0; ; i++) { 45 TICKEND; 29 PAUSE; 46 } 30 BUF = i; }

  5. Producer Consumer Observer int main() { int main() { int main() { DEAD(28); DEAD(41); DEAD(41); volatile unsigned int * buf = volatile unsigned int * buf = volatile unsigned int * buf = (unsigned int*)(0x3F800200); (unsigned int*)(0x3F800200); (unsigned int*)(0x3F800200); unsigned int i = 0; unsigned int i = 0; volatile unsigned int * fd = for (i = 0; ; i++ ) { int arr[8]; (unsigned int*)(0x80000600); DEAD(26); for (i =0; i<8; i++) unsigned int i = 0; *buf = i; arr[i] = 0; for (i = 0; ; i++ ) { } for (i = 0; ; i++) { DEAD(26); return 0; DEAD(26); *fd = *buf; } register int tmp = *buf; } arr[i%8] = tmp; return 0; } } return 0; } Lickly et al. , Predictable Programming on a Precision Timed Architecture , CASES’08 14 // == TICK FUNCTION == 31 Consumer: 15 int tick () 32 for (j = 0; j < 8; j++) 1 #include ”sc.h” 16 { 33 arr [ j ] = 0; 2 17 static int BUF, fd, i , j , 34 for (j = 0; ; j++) { 3 // == MAIN FUNCTION == 18 k = 0, tmp, arr [8]; 35 PAUSE; 4 int main() 19 36 tmp = BUF; 5 { 20 TICKSTART(1); 37 arr [ j % 8] = tmp; } 6 int notDone; 21 38 7 22 PCO: 39 Observer: 8 do { 23 FORK(Producer, 3); 40 for ( ; ; ) { 9 notDone = tick(); 24 FORK(Consumer, 2); 41 PAUSE; 10 //sleep(1); 25 FORKE(Observer); 42 fd = BUF; 11 } while (notDone); 26 43 k++; } 12 return 0; 27 Producer: 44 13 } 28 for (i = 0; ; i++) { 45 TICKEND; 29 PAUSE; 46 } 30 BUF = i; }

  6. Producer Consumer Observer int main() { int main() { int main() { DEAD(28); DEAD(41); DEAD(41); volatile unsigned int * buf = volatile unsigned int * buf = volatile unsigned int * buf = (unsigned int*)(0x3F800200); (unsigned int*)(0x3F800200); (unsigned int*)(0x3F800200); unsigned int i = 0; unsigned int i = 0; volatile unsigned int * fd = for (i = 0; ; i++ ) { int arr[8]; (unsigned int*)(0x80000600); DEAD(26); for (i =0; i<8; i++) unsigned int i = 0; *buf = i; arr[i] = 0; for (i = 0; ; i++ ) { } for (i = 0; ; i++) { DEAD(26); return 0; DEAD(26); *fd = *buf; } register int tmp = *buf; } arr[i%8] = tmp; return 0; } } return 0; } Lickly et al. , Predictable Programming on a Precision Timed Architecture , CASES’08 14 // == TICK FUNCTION == 31 Consumer: 15 int tick () 32 for (j = 0; j < 8; j++) 1 #include ”sc.h” 16 { 33 arr [ j ] = 0; 2 17 static int BUF, fd, i , j , 34 for (j = 0; ; j++) { 3 // == MAIN FUNCTION == 18 k = 0, tmp, arr [8]; 35 PAUSE; 4 int main() 19 36 tmp = BUF; 5 { 20 TICKSTART(1); 37 arr [ j % 8] = tmp; } 6 int notDone; 21 38 7 22 PCO: 39 Observer: 8 do { 23 FORK(Producer, 3); 40 for ( ; ; ) { 9 notDone = tick(); 24 FORK(Consumer, 2); 41 PAUSE; 10 //sleep(1); 25 FORKE(Observer); 42 fd = BUF; 11 } while (notDone); 26 43 k++; } 12 return 0; 27 Producer: 44 13 } 28 for (i = 0; ; i++) { 45 TICKEND; 29 PAUSE; 46 } 30 BUF = i; }

  7. Producer-Consumer-Observer in SC 1 int tick () 2 { 3 static int BUF, fd, i , j , 4 k = 0, tmp, arr [8]; 5 6 TICKSTART(1); 7 8 PCO: 9 FORK(Producer, 3); 25 Observer: 10 FORK(Consumer, 2); 26 for ( ; ; ) { 11 FORKE(Observer); 27 PAUSE; 12 28 fd = BUF; 13 Producer: 29 k++; } 14 for (i = 0; ; i++) { 30 15 PAUSE; 31 TICKEND; 16 BUF = i; } 32 } 17 18 Consumer: 19 for (j = 0; j < 8; j++) 20 arr [ j ] = 0; 21 for (j = 0; ; j++) { 22 PAUSE; 23 tmp = BUF; 24 arr [ j % 8] = tmp; }

  8. Producer-Consumer-Observer + Preemptions 1 int tick () 2 { 3 static int BUF, fd, i , j , 4 k = 0, tmp, arr [8]; 5 6 TICKSTART(1); 7 8 PCO: 9 FORK(Producer, 3); 25 Observer: 10 FORK(Consumer, 2); 26 for ( ; ; ) { 11 FORKE(Observer); 27 PAUSE; 12 28 fd = BUF; 13 Producer: 29 k++; } 14 for (i = 0; ; i++) { 30 15 PAUSE; 31 TICKEND; 16 BUF = i; } 32 } 17 18 Consumer: 19 for (j = 0; j < 8; j++) 20 arr [ j ] = 0; 21 for (j = 0; ; j++) { 22 PAUSE; 23 tmp = BUF; 24 arr [ j % 8] = tmp; }

  9. Producer-Consumer-Observer + Preemptions in SC 1 int tick () 2 { 3 static int BUF, fd, i , j , 4 k = 0, tmp, arr [8]; 26 Observer: 5 27 for ( ; ; ) { 6 TICKSTART(1); 28 fd = BUF; 7 29 k++; 8 PCO: 30 PAUSE; } 9 FORK(Producer, 4); 31 10 FORK(Consumer, 3); 32 Parent: 11 FORK(Observer, 2); 33 while (1) { 12 FORKE(Parent); 34 if (k == 20) 13 35 TRANS(Done); 14 Producer: 36 if (BUF == 10) 15 for (i = 0; ; i++) { 37 TRANS(PCO); 16 BUF = i; 38 PAUSE; 17 PAUSE; } 39 } 18 40 19 Consumer: 41 Done: 20 for (j = 0; j < 8; j++) 42 TERM; 21 arr [ j ] = 0; 43 TICKEND; 22 for (j = 0; ; j++) { 44 } 23 tmp = BUF; 24 arr [ j % 8] = tmp; 25 PAUSE; }

  10. Going on the Road . . .

  11. SC Basics Synchronous C An Alternative SC Syntax WCRT Algebra Summary Criticisms of Original SC ◮ Hard to understand what’s going on ◮ Thread structure gets lost ◮ What does FORK/FORKE mean? v. Hanxleden, Mendler, Traulsen Synchronous C + WCRT Algebra 101 Slide 11

  12. SC Basics Synchronous C An Alternative SC Syntax WCRT Algebra Summary Proposed Alternative Syntax ◮ Replace labels by explicit “Thread” and “State” declarations ◮ Add syntactic scopes (braces) ◮ Predefined FORK1/FORK2/. . . operators v. Hanxleden, Mendler, Traulsen Synchronous C + WCRT Algebra 101 Slide 12

  13. Original PCO-Example 1 int tick () 2 { 3 static int BUF, fd, i , j , 4 k = 0, tmp, arr [8]; 26 Observer: 5 27 for ( ; ; ) { 6 TICKSTART(1); 28 fd = BUF; 7 29 k++; 8 PCO: 30 PAUSE; } 9 FORK(Producer, 4); 31 10 FORK(Consumer, 3); 32 Parent: 11 FORK(Observer, 2); 33 while (1) { 12 FORKE(Parent); 34 if (k == 20) 13 35 TRANS(Done); 14 Producer: 36 if (BUF == 10) 15 for (i = 0; ; i++) { 37 TRANS(PCO); 16 BUF = i; 38 PAUSE; 17 PAUSE; } 39 } 18 40 19 Consumer: 41 Done: 20 for (j = 0; j < 8; j++) 42 TERM; 21 arr [ j ] = 0; 43 TICKEND; 22 for (j = 0; ; j++) { 44 } 23 tmp = BUF; 24 arr [ j % 8] = tmp; 25 PAUSE; }

  14. Transforming the PCO-Example (1) 1. Separate threads 1 int tick () 25 Producer: 2 { 26 for (i = 0; ; i++) { 3 static int BUF, fd, i , j , 27 BUF = i; 4 k = 0, tmp, arr [8]; 28 PAUSE; } 5 29 6 TICKSTART(1); 30 Consumer: 7 31 for (j = 0; j < 8; j++) 8 PCO: 32 arr [ j ] = 0; 9 FORK(Producer, 4); 33 for (j = 0; ; j++) { 10 FORK(Consumer, 3); 34 tmp = BUF; 11 FORK(Observer, 2); 35 arr [ j % 8] = tmp; 12 FORKE(Parent); 36 PAUSE; } 13 37 14 Parent: 38 Observer: 15 while (1) { 39 for ( ; ; ) { 16 if (k == 20) 40 fd = BUF; 17 TRANS(Done); 41 k++; 18 if (BUF == 10) 42 PAUSE; } 19 TRANS(PCO); 43 20 PAUSE; 44 TICKEND; 21 } 45 } 22 23 Done: 24 TERM;

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend