Changeset cf444b6


Ignore:
Timestamp:
Jul 12, 2021, 1:43:15 PM (5 months ago)
Author:
caparsons <caparson@…>
Branches:
jacob/cs343-translation, master, new-ast-unique-expr
Children:
6ff08d8
Parents:
eba9d27
Message:

added more testing to thread_test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/unified_locking/thread_test.cfa

    reba9d27 rcf444b6  
    88static unsigned int threadCount = 2;
    99static unsigned int lockCount = 1;
    10 static unsigned int num_times = 10000;
     10static unsigned int total_times = 320000;
     11static unsigned int num_times;
    1112static const int workBufferSize = 16;
    1213static unsigned int work_unlocked = 10000;
     
    2526thread worker {
    2627    linear_backoff_then_block_lock * locks;
     28    bool improved;
    2729};
    2830
    29 void ?{}( worker & w, linear_backoff_then_block_lock * locks ) {
     31void ?{}( worker & w, linear_backoff_then_block_lock * locks, bool improved ) {
    3032        w.locks = locks;
     33    w.improved = improved;
    3134}
    3235
    33 linear_backoff_then_block_lock norm_lock;
    3436
    3537void main( worker & this ) with(this) {
     
    3739    for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024;
    3840    unsigned int lck = rand() % lockCount;
    39     linear_backoff_then_block_lock * curr_lock = locks;//[lck];
     41    linear_backoff_then_block_lock * curr_lock = &locks[lck];
    4042    for (unsigned int i = 0; i < num_times; i++) {
    4143        dowork(buffer, work_unlocked);
    42         lock(curr_lock);
    43         //printf("lock: %d %p ENTER\n", i, &curr_lock);
    44         //lock(norm_lock);
     44        if (improved) lock_improved(*curr_lock);
     45        else lock(*curr_lock);
    4546        dowork(buffer, work_locked);
    46         //printf("lock: %d %p LEAVE\n", i, &curr_lock);
    47         unlock(curr_lock);
    48         //unlock(norm_lock);
     47        unlock(*curr_lock);
    4948        lck = rand() % lockCount;
    50         //curr_lock = locks[lck];
     49        curr_lock = &locks[lck];
    5150    }
    5251}
    5352
     53
    5454int main(int argc, char* argv[]) {
    5555    switch (argc) {
     56        case 7:
     57            work_unlocked = atoi(argv[5]);
     58        case 6:
     59            work_locked = atoi(argv[5]);
    5660        case 5:
    5761            num_times = atoi(argv[4]);
     
    6872    }
    6973        processor p[threadCount];
    70     linear_backoff_then_block_lock locks;//[lockCount];
    71     printf("lock allocation address: %p \n", &locks);
     74    linear_backoff_then_block_lock locks[lockCount];
    7275    worker * worker_arr[taskCount];
     76    num_times = total_times  / taskCount;
    7377
    74         printf("Start Test: martin lock simple\n");
     78        //printf("Start Test: martin lock simple\n");
    7579        clock_t begin = clock();
    7680        for (unsigned int i = 0; i < taskCount; i++) {
    77         worker_arr[i] = new( &locks );
     81        worker_arr[i] = new( locks, false );
    7882    }
    7983    for (unsigned int i = 0; i < taskCount; i++) {
    80         free( worker_arr[i] );
     84        delete( worker_arr[i] );
    8185    }
    8286        clock_t end = clock();
    8387        double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    84         printf("Done Test, time: %f\n", time_spent);
     88        printf("norm: %f\n", time_spent);
     89
     90    //printf("Start Test: martin lock improved\n");
     91        begin = clock();
     92        for (unsigned int i = 0; i < taskCount; i++) {
     93        worker_arr[i] = new( locks, true );
     94    }
     95    for (unsigned int i = 0; i < taskCount; i++) {
     96        delete( worker_arr[i] );
     97    }
     98        end = clock();
     99        time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
     100        printf("improved: %f\n", time_spent);
    85101}
Note: See TracChangeset for help on using the changeset viewer.