Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/churn.cfa

    r12bb5ab1 r75965a6  
    11#include "rq_bench.hfa"
    22
    3 #include <locks.hfa>
    4 
    53unsigned spot_cnt = 2;
    6 semaphore * spots;
     4bench_sem * volatile * spots;
    75
    86thread BThrd {
    97        unsigned long long count;
    108        unsigned long long blocks;
    11         bool skip;
     9        bench_sem sem;
    1210};
    1311
     
    1614        this.count  = 0;
    1715        this.blocks = 0;
    18         this.skip = false;
    1916}
    2017
     
    2219
    2320void main( BThrd & this ) with( this ) {
    24         park();
     21        wait( sem );
    2522        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 );
    3227                count ++;
    3328                if( clock_mode && stop) break;
     
    4439                { 's', "spots", "Number of spots in the system", spot_cnt }
    4540        };
    46         BENCH_OPT_PARSE("cforall churn benchmark");
     41        BENCH_OPT_PARSE("cforall cycle benchmark");
    4742
    4843        {
     
    5449                        spots = aalloc(spot_cnt);
    5550                        for(i; spot_cnt) {
    56                                 (spots[i]){ 0 };
     51                                spots[i] = 0p;
    5752                        }
    5853
     
    6055                        BThrd * threads[nthreads];
    6156                        for(i; nthreads ) {
    62                                 BThrd & t = *(threads[i] = malloc());
    63                                 (t){};
    64                                 t.skip = i < spot_cnt;
     57                                threads[i] = malloc();
     58                                (*threads[i]){};
    6559                        }
    6660                        printf("Starting\n");
     
    7064
    7165                        for(i; nthreads) {
    72                                 unpark( *threads[i] );
     66                                post( threads[i]->sem );
    7367                        }
    7468                        wait(start, is_tty);
     
    7872                        printf("\nDone\n");
    7973
    80                         for(i; spot_cnt) {
    81                                 for(10000) V( spots[i] );
    82                         }
    83 
    8474                        for(i; nthreads) {
     75                                post( threads[i]->sem );
    8576                                BThrd & thrd = join( *threads[i] );
    8677                                global_counter += thrd.count;
Note: See TracChangeset for help on using the changeset viewer.