Exemple #1
0
static int
run_test(int nthreads)
{
    struct benchmark_data * bdata = start_benchmark();
    struct thread_pool * threadpool = thread_pool_new(nthreads);
   
    struct arg2 args = {
        .a = 20,
        .b = 22,
    };

    struct future * sum = thread_pool_submit(threadpool, (fork_join_task_t) adder_task, &args);

    uintptr_t ssum = (uintptr_t) future_get(sum);
    future_free(sum);
    thread_pool_shutdown_and_destroy(threadpool);

    stop_benchmark(bdata);

    // consistency check
    if (ssum != 42) {
        fprintf(stderr, "Wrong result, expected 42, got %ld\n", ssum);
        abort();
    }

    report_benchmark_results(bdata);
    printf("Test successful.\n");
    free(bdata);
    return 0;
}

/**********************************************************************************/

static void
usage(char *av0, int exvalue)
{
    fprintf(stderr, "Usage: %s [-n <n>]\n"
                    " -n number of threads in pool, default %d\n"
                    , av0, DEFAULT_THREADS);
    exit(exvalue);
}
Exemple #2
0
int main( int argc, char *argv[] )
{

    unsigned int start, stop;
    int i = 0;
    int test = 0;
    int NUM_LOAD_THREADS = 0;
    thread_arg_t arg;
    hthread_mutexattr_t block_attr;
    hthread_mutexattr_t data_attr;
    benchmark_t my_benchmark[TESTS];

    // Turn on the Xilinx Timer
    enableTimer();

    for (test = 0; test < TESTS; test++)
    {
	    // Set the # of load threads
	    NUM_LOAD_THREADS = test * 10;
	
	    // Init. benchmark structure
	    my_benchmark[test].num_threads_in_test = NUM_LOAD_THREADS;
	    *my_benchmark[test].name = "lock/unlock";
	
	    for (i = 0; i < RUNS; i++)
	    {	
	        // Initialize thread argument fields
		    //  * Setup mutexes
		    //  * Initialize counter
		    block_attr.num = 0;
		    block_attr.type = HTHREAD_MUTEX_DEFAULT;
		    data_attr.num = 1;
		    data_attr.type = HTHREAD_MUTEX_DEFAULT;
		    hthread_mutex_init(&arg.block_mutex, &block_attr);
		    hthread_mutex_init(&arg.data_mutex, &data_attr);
		    arg.counter = 0;
		    arg.num_load_threads = NUM_LOAD_THREADS;
	
	        // Run the test
	        start = readTimer();
	        run_A(0,NUM_LOAD_THREADS,&arg);
	        stop = readTimer();
	
	        // Gather results
	        my_benchmark[test].results1[i] = calc_timediff(arg.lock_start, arg.lock_stop);
	        my_benchmark[test].results2[i] = calc_timediff(arg.unlock_start, arg.unlock_stop);
/*	
	        printf(
	                "*** start      = %u\n"
	                "*** stop       = %u\n"
	                "*** elapsed    = %u\n",
	                start, stop, stop - start
	              );
	
	        // Calculate timing results
	        printf(     "\t*********************************\n"
	                    "\t lock Start Time    = %llu ticks\n"
	                    "\t lock Stop Time     = %llu ticks\n"
	                    "\t diff               = %llu ticks\n"
	                    "\t lock Elapsed Time  = %llu us\n",
	                    arg.lock_start, arg.lock_stop, arg.lock_stop - arg.lock_start, calc_timediff_us(arg.lock_start, arg.lock_stop)
	               );
	        printf(     "\t*********************************\n"
	                    "\t unlock Start Time    = %llu ticks\n"
	                    "\t unlock Stop Time     = %llu ticks\n"
	                    "\t diff                 = %llu ticks\n"
	                    "\t unlock Elapsed Time  = %llu us\n",
	                    arg.unlock_start, arg.unlock_stop, arg.unlock_stop - arg.unlock_start, calc_timediff_us(arg.unlock_start, arg.unlock_stop)
	               ); */
	    }                       
    }
    report_benchmark_results(my_benchmark);

    for (test = 0; test < TESTS; test++)
    {
	    // Set the # of load threads
	    NUM_LOAD_THREADS = test * 10;
	
	    // Init. benchmark structure
	    my_benchmark[test].num_threads_in_test = NUM_LOAD_THREADS;
	    *my_benchmark[test].name = "turn_around";
	
	    for (i = 0; i < RUNS; i++)
	    {	
	        // Initialize thread argument fields
		    //  * Setup mutexes
		    //  * Initialize counter
		    block_attr.num = 0;
		    block_attr.type = HTHREAD_MUTEX_DEFAULT;
		    data_attr.num = 1;
		    data_attr.type = HTHREAD_MUTEX_DEFAULT;
		    hthread_mutex_init(&arg.block_mutex, &block_attr);
		    hthread_mutex_init(&arg.data_mutex, &data_attr);
		    arg.counter = 0;

            // Num loads threads + 1 b/c the 2nd measurement thread is a load thread and needs to increment the counter barrier
            // before the main thread releases the blocking mutex
            arg.num_load_threads = NUM_LOAD_THREADS+1;
	
	        // Run the test
	        start = readTimer();
	        run_B(0,NUM_LOAD_THREADS,&arg);
	        stop = readTimer();
	
	        // Gather results
	        my_benchmark[test].results1[i] = calc_timediff(arg.unlock_start, arg.measure_lock_stop);
	        my_benchmark[test].results2[i] = calc_timediff(arg.unlock_start, arg.measure_lock_stop);
/*	
	        printf(
	                "*** start      = %u\n"
	                "*** stop       = %u\n"
	                "*** elapsed    = %u\n",
	                start, stop, stop - start
	              );	

            // Calculate timing results
	        printf(     "\t*********************************\n"
	                    "\t lock Start Time    = %llu ticks\n"
	                    "\t lock Stop Time     = %llu ticks\n"
	                    "\t diff               = %llu ticks\n"
	                    "\t lock Elapsed Time  = %llu us\n",
	                    arg.lock_start, arg.lock_stop, arg.lock_stop - arg.lock_start, calc_timediff_us(arg.lock_start, arg.lock_stop)
	               );
	        printf(     "\t*********************************\n"
	                    "\t unlock Start Time    = %llu ticks\n"
	                    "\t unlock Stop Time     = %llu ticks\n"
	                    "\t diff                 = %llu ticks\n"
	                    "\t unlock Elapsed Time  = %llu us\n"
	                    "\t m_lock Start Time    = %llu ticks\n"
	                    "\t m_lock Stop Time     = %llu ticks\n"
	                    "\t turn around          = %llu us\n",
	                    arg.unlock_start, arg.unlock_stop, arg.unlock_stop - arg.unlock_start, calc_timediff_us(arg.unlock_start, arg.unlock_stop), arg.measure_lock_start, arg.measure_lock_stop, calc_timediff_us(arg.unlock_start, arg.measure_lock_stop)); */
	    }                       
    }
    report_benchmark_results(my_benchmark);

    return 0;
}