Changes in benchmark/readyQ/churn.cfa [12bb5ab1:75965a6]
- File:
-
- 1 edited
-
benchmark/readyQ/churn.cfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/churn.cfa
r12bb5ab1 r75965a6 1 1 #include "rq_bench.hfa" 2 2 3 #include <locks.hfa>4 5 3 unsigned spot_cnt = 2; 6 semaphore * spots;4 bench_sem * volatile * spots; 7 5 8 6 thread BThrd { 9 7 unsigned long long count; 10 8 unsigned long long blocks; 11 b ool skip;9 bench_sem sem; 12 10 }; 13 11 … … 16 14 this.count = 0; 17 15 this.blocks = 0; 18 this.skip = false;19 16 } 20 17 … … 22 19 23 20 void main( BThrd & this ) with( this ) { 24 park();21 wait( sem ); 25 22 for() { 26 uint32_t r = prng(this); 27 semaphore & sem = spots[r % spot_cnt]; 28 if(!skip) V( sem ); 29 blocks += P( sem ); 30 skip = false; 31 23 uint32_t r = prng(); 24 bench_sem * next = __atomic_exchange_n(&spots[r % spot_cnt], &sem, __ATOMIC_SEQ_CST); 25 if(next) post( *next ); 26 blocks += wait( sem ); 32 27 count ++; 33 28 if( clock_mode && stop) break; … … 44 39 { 's', "spots", "Number of spots in the system", spot_cnt } 45 40 }; 46 BENCH_OPT_PARSE("cforall c hurnbenchmark");41 BENCH_OPT_PARSE("cforall cycle benchmark"); 47 42 48 43 { … … 54 49 spots = aalloc(spot_cnt); 55 50 for(i; spot_cnt) { 56 (spots[i]){ 0 };51 spots[i] = 0p; 57 52 } 58 53 … … 60 55 BThrd * threads[nthreads]; 61 56 for(i; nthreads ) { 62 BThrd & t = *(threads[i] = malloc()); 63 (t){}; 64 t.skip = i < spot_cnt; 57 threads[i] = malloc(); 58 (*threads[i]){}; 65 59 } 66 60 printf("Starting\n"); … … 70 64 71 65 for(i; nthreads) { 72 unpark( *threads[i]);66 post( threads[i]->sem ); 73 67 } 74 68 wait(start, is_tty); … … 78 72 printf("\nDone\n"); 79 73 80 for(i; spot_cnt) {81 for(10000) V( spots[i] );82 }83 84 74 for(i; nthreads) { 75 post( threads[i]->sem ); 85 76 BThrd & thrd = join( *threads[i] ); 86 77 global_counter += thrd.count;
Note:
See TracChangeset
for help on using the changeset viewer.