Changeset 4f9636f
- Timestamp:
- May 5, 2017, 11:05:53 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 982ed5b, c10ee66
- Parents:
- 45a4ea7 (diff), bd951f7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 6 added
- 3 deleted
- 10 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r45a4ea7 r4f9636f 246 246 //============================================================================================= 247 247 void ConcurrentSueKeyword::visit(StructDecl * decl) { 248 Visitor::visit(decl); 248 249 if( decl->get_name() == type_name ) { 249 250 assert( !type_decl ); … … 385 386 //============================================================================================= 386 387 void MutexKeyword::visit(FunctionDecl* decl) { 388 Visitor::visit(decl); 389 387 390 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); 388 391 if( mutexArgs.empty() ) return; … … 402 405 403 406 void MutexKeyword::visit(StructDecl* decl) { 407 Visitor::visit(decl); 408 404 409 if( decl->get_name() == "monitor_desc" ) { 405 410 assert( !monitor_decl ); … … 504 509 //============================================================================================= 505 510 void ThreadStarter::visit(FunctionDecl * decl) { 511 Visitor::visit(decl); 512 506 513 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 507 514 -
src/benchmark/CorCtxSwitch.c
r45a4ea7 r4f9636f 3 3 #include <thread> 4 4 5 #include <unistd.h> // sysconf 6 #include <sys/times.h> // times 7 #include <time.h> 8 9 inline unsigned long long int Time() { 10 timespec ts; 11 clock_gettime( 12 #if defined( __linux__ ) 13 CLOCK_THREAD_CPUTIME_ID, 14 #elif defined( __freebsd__ ) 15 CLOCK_PROF, 16 #elif defined( __solaris__ ) 17 CLOCK_HIGHRES, 18 #else 19 #error uC++ : internal error, unsupported architecture 20 #endif 21 &ts ); 22 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 23 } // Time 5 #include "bench.h" 24 6 25 7 coroutine GreatSuspender {}; … … 42 24 } 43 25 44 #ifndef N45 #define N 10000000046 #endif47 48 26 int main() { 49 27 const unsigned int NoOfTimes = N; -
src/benchmark/Makefile.am
r45a4ea7 r4f9636f 44 44 @rm -f ./a.out 45 45 46 sched-int: 47 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 SchedInt.c 48 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 49 ./a.out ; \ 50 done 51 @rm -f ./a.out 52 53 monitor: 54 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 Monitor.c 55 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 56 ./a.out ; \ 57 done 58 @rm -f ./a.out 59 46 60 csv-data: 47 61 @${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -quiet -DN=10000000 csv-data.c -
src/benchmark/Makefile.in
r45a4ea7 r4f9636f 492 492 @rm -f ./a.out 493 493 494 sched-int: 495 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 SchedInt.c 496 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 497 ./a.out ; \ 498 done 499 @rm -f ./a.out 500 501 monitor: 502 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 Monitor.c 503 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 504 ./a.out ; \ 505 done 506 @rm -f ./a.out 507 494 508 csv-data: 495 509 @${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -quiet -DN=10000000 csv-data.c -
src/benchmark/ThrdCtxSwitch.c
r45a4ea7 r4f9636f 3 3 #include <thread> 4 4 5 #include <unistd.h> // sysconf 6 #include <sys/times.h> // times 7 #include <time.h> 8 9 inline unsigned long long int Time() { 10 timespec ts; 11 clock_gettime( 12 #if defined( __linux__ ) 13 CLOCK_THREAD_CPUTIME_ID, 14 #elif defined( __freebsd__ ) 15 CLOCK_PROF, 16 #elif defined( __solaris__ ) 17 CLOCK_HIGHRES, 18 #else 19 #error uC++ : internal error, unsupported architecture 20 #endif 21 &ts ); 22 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 23 } // Time 24 25 #ifndef N 26 #define N 100000000 27 #endif 5 #include "bench.h" 28 6 29 7 int main() { -
src/benchmark/bench.c
r45a4ea7 r4f9636f 4 4 #include <thread> 5 5 6 #include <unistd.h> // sysconf 7 #include <sys/times.h> // times 8 #include <time.h> 9 10 inline unsigned long long int Time() { 11 timespec ts; 12 clock_gettime( 13 #if defined( __linux__ ) 14 CLOCK_THREAD_CPUTIME_ID, 15 #elif defined( __freebsd__ ) 16 CLOCK_PROF, 17 #elif defined( __solaris__ ) 18 CLOCK_HIGHRES, 19 #else 20 #error uC++ : internal error, unsupported architecture 21 #endif 22 &ts ); 23 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 24 } // Time 6 #include "bench.h" 25 7 26 8 //======================================= -
src/benchmark/csv-data.c
r45a4ea7 r4f9636f 1 1 #include <fstream> 2 #include <monitor> 2 3 #include <stdlib> 3 4 #include <thread> 4 5 5 extern "C" { 6 #include <unistd.h> // sysconf 7 #include <sys/times.h> // times 8 #include <time.h> 9 } 10 11 inline unsigned long long int Time() { 12 timespec ts; 13 clock_gettime( 14 #if defined( __linux__ ) 15 CLOCK_THREAD_CPUTIME_ID, 16 #elif defined( __freebsd__ ) 17 CLOCK_PROF, 18 #elif defined( __solaris__ ) 19 CLOCK_HIGHRES, 20 #else 21 #error uC++ : internal error, unsupported architecture 22 #endif 23 &ts ); 24 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 25 } // Time 6 #include "bench.h" 26 7 27 8 coroutine GreatSuspender {}; … … 48 29 #endif 49 30 50 51 31 //----------------------------------------------------------------------------- 32 // coroutine context switch 52 33 long long int measure_coroutine() { 53 34 const unsigned int NoOfTimes = N; … … 67 48 } 68 49 50 //----------------------------------------------------------------------------- 51 // thread context switch 69 52 long long int measure_thread() { 70 53 const unsigned int NoOfTimes = N; … … 80 63 } 81 64 65 //----------------------------------------------------------------------------- 66 // single monitor entry 67 monitor mon_t {}; 68 void dummy( mon_t * mutex m ) {} 69 70 long long int measure_1_monitor_entry() { 71 const unsigned int NoOfTimes = N; 72 long long int StartTime, EndTime; 73 mon_t mon; 74 75 StartTime = Time(); 76 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { 77 dummy( &mon ); 78 } 79 EndTime = Time(); 80 81 return ( EndTime - StartTime ) / NoOfTimes; 82 } 83 84 //----------------------------------------------------------------------------- 85 // multi monitor entry 86 void dummy( mon_t * mutex m1, mon_t * mutex m2 ) {} 87 88 long long int measure_2_monitor_entry() { 89 const unsigned int NoOfTimes = N; 90 long long int StartTime, EndTime; 91 mon_t mon1, mon2; 92 93 StartTime = Time(); 94 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { 95 dummy( &mon1, &mon2 ); 96 } 97 EndTime = Time(); 98 99 return ( EndTime - StartTime ) / NoOfTimes; 100 } 101 82 102 int main() 83 103 { 84 sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl; 104 sout | time(NULL) | ','; 105 sout | measure_coroutine() | ','; 106 sout | measure_thread() | ','; 107 sout | measure_1_monitor_entry() | ','; 108 sout | measure_2_monitor_entry() | endl; 85 109 } -
src/libcfa/concurrency/thread.c
r45a4ea7 r4f9636f 40 40 this->next = NULL; 41 41 42 this->current_monitors = NULL;43 this->current_monitor_count = 0;42 this->current_monitors = &this->mon; 43 this->current_monitor_count = 1; 44 44 } 45 45 -
src/tests/Makefile.am
r45a4ea7 r4f9636f 22 22 concurrent=yes 23 23 quick_test+= coroutine thread monitor 24 concurrent_test=coroutine thread monitor multi-monitor sched-int sched-int-multi sched-int-multi2sched-ext sched-ext-multi preempt24 concurrent_test=coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt 25 25 else 26 26 concurrent=no -
src/tests/Makefile.in
r45a4ea7 r4f9636f 230 230 @BUILD_CONCURRENCY_TRUE@concurrent = yes 231 231 @BUILD_CONCURRENCY_FALSE@concurrent_test = 232 @BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int sched-int-multi sched-int-multi2sched-ext sched-ext-multi preempt232 @BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt 233 233 234 234 # applies to both programs -
src/tests/sched-int-barge.c
r45a4ea7 r4f9636f 2 2 #include <kernel> 3 3 #include <monitor> 4 #include <stdlib> 4 5 #include <thread> 5 6 … … 12 13 int counter; 13 14 state_t state; 15 16 unsigned short do_signal; 17 unsigned short do_wait2; 18 unsigned short do_wait1; 14 19 }; 15 20 … … 18 23 this->counter = 0; 19 24 this->state = BARGE; 25 26 this->do_signal = 6; 27 this->do_wait1 = 1; 28 this->do_wait2 = 3; 20 29 } 21 30 … … 33 42 c->counter++; 34 43 44 if( (c->counter % 1000) == 0 ) sout | c->counter | endl; 45 35 46 int action = c->counter % 10; 36 47 37 if( action == 1 || action == 3 ) { 38 if(c->state != BARGE) { 39 sout | "ERROR Mutual exclusion is inconsistent for wait" | endl; 40 abort(); 41 } 48 if( action == 0 ) { 49 c->do_signal = max( ((unsigned)rand48()) % 10, 1); 50 c->do_wait1 = ((unsigned)rand48()) % (c->do_signal); 51 c->do_wait2 = ((unsigned)rand48()) % (c->do_signal); 42 52 53 // if(c->do_wait1 == c->do_wait2) sout | "Same" | endl; 54 } 55 56 if( action == c->do_wait1 || action == c->do_wait2 ) { 43 57 c->state = WAIT; 44 58 wait( &cond ); 45 59 46 60 if(c->state != SIGNAL) { 47 sout | "ERROR Barging detected" | endl;61 sout | "ERROR Barging detected" | c->counter | endl; 48 62 abort(); 49 63 } 50 64 } 51 else if( action == 6 ) { 52 if(c->state != BARGE) { 53 sout | "ERROR Mutual exclusion is inconsistent for signal" | endl; 54 abort(); 55 } 56 65 else if( action == c->do_signal ) { 57 66 c->state = SIGNAL; 58 67 … … 64 73 } 65 74 66 if( (c->counter % 1000) == 0 ) sout | c->counter | endl; 67 if( c->counter == 100_000 ) c->done = true; 75 if( c->counter >= 100_000 ) c->done = true; 68 76 return !c->done; 69 77 } … … 82 90 83 91 int main(int argc, char* argv[]) { 84 processor p[3]; 92 rand48seed(0); 93 processor p; 85 94 { 86 Threads t[ 20];95 Threads t[17]; 87 96 } 88 97 } -
src/tests/sched-int-wait.c
r45a4ea7 r4f9636f 2 2 #include <kernel> 3 3 #include <monitor> 4 #include <stdlib> 4 5 #include <thread> 5 6 … … 12 13 condition condAB, condAC, condBC, condABC; 13 14 14 thread Signaler {}; 15 thread Signaler { 16 int signals[4]; 17 }; 18 19 void ?{}( Signaler * this ){ 20 this->signals[0] = 0; 21 this->signals[1] = 0; 22 this->signals[2] = 0; 23 this->signals[3] = 0; 24 } 25 15 26 thread WaiterAB {}; 16 27 thread WaiterAC {}; … … 18 29 thread WaiterABC{}; 19 30 20 int state; 21 22 /* 23 multi phase 24 */ 31 volatile bool done; 25 32 26 33 //---------------------------------------------------------------------------------------------------- … … 35 42 36 43 void wait( condition * cond, global_t * mutex a, global_t * mutex b ) { 37 state++;38 sout | "Waiting" | state | endl;39 44 wait( cond ); 40 sout | "Waking" | state | endl;41 state--;42 45 } 43 46 44 47 void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) { 45 state++;46 sout | "Waiting" | state | endl;47 48 wait( cond ); 48 sout | "Waking" | state | endl;49 state--;50 49 } 51 50 52 51 //---------------------------------------------------------------------------------------------------- 53 52 // Signaler 54 // signals respectively AB, AC, BC, ABC 55 void signalerABC( global_t * mutex a, global_t * mutex b, global_t * mutex c ) { 56 sout | "Signaling ABC" | endl; 57 signal( &condABC, a, b, c ); 58 sout | "Signaling AB" | endl; 59 signal( &condAB , a, b ); 60 sout | "Signaling BC" | endl; 61 signal( &condBC , b, c ); 62 sout | "Signaling AC" | endl; 63 signal( &condAC , a, c ); 64 } 53 void main( Signaler* this ) { 65 54 66 void signalerAB( global_t * mutex a, global_t * mutex b, global_t * c) {67 signalerABC(a, b, c);68 } 55 while( true ) { 56 int action = (unsigned)rand48() % 4; 57 bool finished = true; 69 58 70 void signalerA( global_t * mutex a, global_t * b, global_t * c ) { 71 signalerAB (a, b, c); 72 } 59 for(int i = 0; i < 4; i++) { 60 if( this->signals[action] < 10_000 ) { 61 finished = false; 62 break; 63 } 64 else { 65 action = (action + 1) % 4; 66 } 67 } 73 68 74 void main( Signaler* this ) { 75 while( state != 4 ) { yield(); } 76 signalerA( &globalA, &globalB, &globalC ); 69 this->signals[action]++; 70 if( finished ) break; 71 72 //sout | action | this->signals[0] | this->signals[1] | this->signals[2] | this->signals[3] | endl; 73 74 switch( action ) { 75 case 0: 76 signal( &condABC, &globalA, &globalB, &globalC ); 77 break; 78 case 1: 79 signal( &condAB , &globalA, &globalB ); 80 break; 81 case 2: 82 signal( &condBC , &globalB, &globalC ); 83 break; 84 case 3: 85 signal( &condAC , &globalA, &globalC ); 86 break; 87 default: 88 sout | "Something went wrong" | endl; 89 abort(); 90 } 91 } 77 92 } 78 93 … … 80 95 // Waiter ABC 81 96 void main( WaiterABC* this ) { 82 while( state != 0 ) { yield(); } 83 wait( &condABC, &globalA, &globalB, &globalC ); 97 while( !done ) { 98 wait( &condABC, &globalA, &globalB, &globalC ); 99 } 84 100 } 85 101 … … 87 103 // Waiter AB 88 104 void main( WaiterAB* this ) { 89 while( state != 1 ) { yield(); } 90 wait( &condAB , &globalA, &globalB ); 105 while( !done ) { 106 wait( &condAB , &globalA, &globalB ); 107 } 91 108 } 92 109 … … 94 111 // Waiter AC 95 112 void main( WaiterAC* this ) { 96 while( state != 2 ) { yield(); } 97 wait( &condAC , &globalA, &globalC ); 113 while( !done ) { 114 wait( &condAC , &globalA, &globalC ); 115 } 98 116 } 99 117 … … 101 119 // Waiter BC 102 120 void main( WaiterBC* this ) { 103 while( state != 3 ) { yield(); } 104 wait( &condBC , &globalB, &globalC ); 121 while( !done ) { 122 wait( &condBC , &globalB, &globalC ); 123 } 105 124 } 106 125 … … 108 127 // Main 109 128 int main(int argc, char* argv[]) { 110 state = 0;129 done = false; 111 130 processor p; 112 131 { … … 115 134 WaiterBC c; 116 135 WaiterAC d; 117 Signaler e; 136 { 137 Signaler e; 138 } 139 done = true; 140 signal( &condABC, &globalA, &globalB, &globalC ); 141 signal( &condAB , &globalA, &globalB ); 142 signal( &condBC , &globalB, &globalC ); 143 signal( &condAC , &globalA, &globalC ); 118 144 } 119 145 }
Note: See TracChangeset
for help on using the changeset viewer.