Пример #1
0
int main( int argc, char *argv[] )
{
    Huint           sta;
    void*           retval;
    hthread_t       tid;
    hthread_attr_t  attr;
    int num_ops = 0;
	printf( "\n****Main Thread****... \n" );
   
    for( num_ops = 0; num_ops < 5; num_ops++)
    { 
	    // Initialize the attributes for the hardware thread
	    hthread_attr_init( &attr );
	    hthread_attr_sethardware( &attr, HWTI_BASEADDR );
	
	    // Create the hardware thread
		printf( "Starting Hardware Thread... \r" );
	    sta = hthread_create( &tid, &attr, NULL, (void*)(num_ops) );
		printf( "Started Hardware Thread (TID = %d) (ARG = %d)... 0x%8.8x\n", tid, num_ops, sta );
	
	    // Clean up the attribute structure
	    hthread_attr_destroy( &attr );
	
	    // Wait for the hardware thread to exit
		printf( "Waiting for Hardware Thread... \r" );
	    hthread_join( tid, &retval );
		printf( "Joined on  Hardware Thread... 0x%8.8x\n", (Huint)retval );
    }
    // Return from main
    return 0;
}
Пример #2
0
int main( int argc, char *argv[] ) {
    hthread_t       tid, sw1, sw2;
    hthread_attr_t  hw1Attr, sw1Attr, sw2Attr;
	hthread_mutex_t mutex;
    Huint           retval;
	struct arguments myArgs;

    hthread_attr_init( &hw1Attr );
    hthread_attr_init( &sw1Attr );
    hthread_attr_init( &sw2Attr );
    hthread_attr_sethardware( &hw1Attr, HWTI_BASEADDR );
	hthread_mutex_init( &mutex, NULL );
	myArgs.mutex = &mutex;

	retval = hthread_mutex_lock( myArgs.mutex );
   
    // Set the thread's argument data to some value
    myArgs.value = 1000;
   
   	// Create two software threads
    hthread_create( &tid, &hw1Attr, NULL, (void*)(&myArgs) );
    hthread_create( &sw1, &sw1Attr, thread, (void*)(&myArgs) );
    hthread_create( &sw2, &sw2Attr, thread, (void*)(&myArgs) );
	hthread_yield();

    // HWT should be blocked
    readHWTStatus();
	
	retval = hthread_mutex_unlock( myArgs.mutex );

    hthread_join( tid, (void*)(&retval) );
    hthread_join( sw1, (void*)(&retval) );
    hthread_join( sw2, (void*)(&retval) );
    readHWTStatus();
    
    // Clean up the attribute structure
    hthread_attr_destroy( &hw1Attr );
    hthread_attr_destroy( &sw1Attr );
    hthread_attr_destroy( &sw2Attr );

    // Print out value of arg, and a successful exit message
    printf( "After joins arg = %d\n", myArgs.value);
    printf( "-- QED --\n" );

    // Return from main
    return 1;
}
Пример #3
0
int main(int argc, char *argv[]) {
    hthread_mutexattr_t mutexAttr;
    hthread_mutex_t     mutex;
	hthread_attr_t      threadAttr;
    hthread_t           thread;
	Huint               arg;
	log_t               log;

    //Initialize Log
	log_create( &log, 1024 );

	//Mutex operations
	printf( "Starting mutex operations\n" );
	hthread_mutexattr_init( &mutexAttr );
	hthread_mutexattr_setnum( &mutexAttr, 0 );
	hthread_mutexattr_getnum( &mutexAttr, &arg );
	hthread_mutexattr_destroy( &mutexAttr );

    hthread_mutex_init(&mutex, NULL);
	hthread_mutex_lock( &mutex );
	hthread_mutex_unlock( &mutex );

	hthread_mutex_trylock( &mutex );
	hthread_mutex_unlock( &mutex );
	hthread_mutex_destroy( &mutex );

    //Condition Variable operations
	/*
	printf( "Starting condition variable operations\n" );
	hthread_condattr_init( &condvarAttr );
	hthread_condattr_setnum( &condvarAttr, 0 );
	hthread_condattr_getnum( &condvarAttr, &arg );
	hthread_condattr_destroy( &condvarAttr );

	hthread_cond_init( &condvar, NULL );
	hthread_mutex_lock( &mutex );
	hthread_cond_wait( &condvar, &mutex );
	hthread_mutex_unlock( &mutex );
	hthread_cond_signal( &condvar );
	hthread_cond_broadcast( &condvar );
	hthread_cond_destroy( &condvar );
	*/

    //Thread operations
	printf( "Starting thread operations\n" );
	hthread_attr_init( &threadAttr );
    hthread_create( &thread, &threadAttr, foo, &log );
	hthread_attr_destroy( &threadAttr );

	hthread_join( thread, NULL );

    printf( " -- End of Program --\n" );
	log_close_ascii( &log );

	return 0;
}
Пример #4
0
int main( int argc, char *argv[] )
{
    Huint           sta;
    void*           retval;
    hthread_t       tid;
    hthread_attr_t  attr;
    int num_ops = 0;
	printf( "\n****Main Thread****... \n" );

    XCache_DisableDCache();

// *************************************************************************************    
    unsigned int *fcn_pointer = (unsigned int*)(HWTI_BASEADDR + 6*sizeof(int));

    int code_offset				= 0;
	FuncPointer fp 				= 0;
	unsigned char * prog_ptr	= 0;
	unsigned int * first_instr = 0;

	// Initialize code offset and program pointer
	code_offset = 0x1f0; //0x1d4;//0x1a8;
	prog_ptr = (unsigned char *)&junk_o;
			
	// Initialize function pointer (actual place to jump to)
	fp = (FuncPointer)(prog_ptr + code_offset);

	// Initialize a pointer that allows one to "look" at the 1st instruction
	first_instr = (unsigned int*)(prog_ptr + code_offset);

    *fcn_pointer = (int)fp;
// *************************************************************************************    


    for( num_ops = 0; num_ops < 5; num_ops++)
    { 
	    // Initialize the attributes for the hardware thread
	    hthread_attr_init( &attr );
	    hthread_attr_sethardware( &attr, HWTI_BASEADDR );
	
	    // Create the hardware thread
		printf( "Starting Hardware Thread... \r" );
	    sta = hthread_create( &tid, &attr, (void*)fp, (void*)(num_ops) );
		printf( "Started Hardware Thread (TID = %d) (ARG = %d)... 0x%8.8x\n", tid, num_ops, sta );
	
	    // Clean up the attribute structure
	    hthread_attr_destroy( &attr );
	
	    // Wait for the hardware thread to exit
		printf( "Waiting for Hardware Thread... \r" );
	    hthread_join( tid, &retval );
		printf( "Joined on  Hardware Thread... 0x%8.8x\n", (Huint)retval );
    }
    // Return from main
    return 0;
}
Пример #5
0
void* findFibonacci(void * arg) {
	hthread_attr_t attrBase;
	hthread_t threadBase;
	hthread_t threadOne;
	hthread_t threadTwo;
	struct fibonacci * fib;
	struct fibonacci fibOne;
	struct fibonacci fibTwo;
    
	fib = (struct fibonacci *) arg;
    
	if (fib->fibNum == 0 || fib->fibNum == 1) {
		//Set up the attr for a HW thread
		hthread_attr_init( &attrBase );
		hthread_attr_sethardware( &attrBase, HWTI_BASEADDR );

		//since there is only one HWTI, perform a mutex lock on it.
		//then create the HW thread
		hthread_mutex_lock( &hwtiMutex );
		//hthread_create(&threadBase, NULL, findFibHWTI, (void*)fib);
		//readHWTStatus();
		//resetHWT();
		//printf( "fibVal is %d\n", fib->fibVal );
		printf( "fib address is %x, %x, %x\n", (Huint)fib, (Huint)(&fib->fibNum), (Huint)(&fib->fibVal) );
		hthread_create(&threadBase, &attrBase, NULL, arg);

		//Clean up the attr
		hthread_attr_destroy( &attrBase );

		//Wait for HW thread to finish ... and unlock mutex
		hthread_join(threadBase, NULL);
		//readHWTStatus();
		printf( "fibVal is %d\n", fib->fibVal );
		hthread_mutex_unlock( &hwtiMutex );
	} else {
		fibOne.fibNum = fib->fibNum - 1;
		fibTwo.fibNum = fib->fibNum - 2;

		hthread_create(&threadOne, NULL, findFibonacci, (void*)&fibOne);
		hthread_create(&threadTwo, NULL, findFibonacci, (void*)&fibTwo);

		hthread_join(threadOne, NULL);
		hthread_join(threadTwo, NULL);

		fib->fibVal = fibOne.fibVal + fibTwo.fibVal;
	}
   
	return NULL;
}
Пример #6
0
int main( int argc, char *argv[] ) {
    hthread_t       tid1;
    hthread_attr_t  attr1;
    struct command 	commands;
	Huint           i;
	log_t           log;

    // Create the log file for timing reports
	log_create( &log, 1024 );

    // Initialize the attributes for the threads
    hthread_attr_init( &attr1 );

    // Setup the attributes for the hardware threads
    hthread_attr_sethardware( &attr1, HWT_ZERO_BASEADDR );

	// Initialize matrixData
	commands.count = 060;
	commands.value = 1012;
	commands.operation = 6;
	//commands.ptrData = (int *) malloc( sizeof( int ) * commands.count );
	commands.ptrData = (int *) 0x63000050;

    // Create the hardware thread
	log_time( &log );
	hthread_create( &tid1, &attr1, NULL, (void*)(&commands) );

    // Wait for the threads to exit
    hthread_join( tid1, NULL );
	log_time( &log );

    readHWTStatus( HWT_ZERO_BASEADDR );

	for( i = 0; i < commands.count; i+=16 ) {
		printf( "%i=%i\n", i, commands.ptrData[i] );
	}

    // Clean up the attribute structure
    hthread_attr_destroy( &attr1 );

	printf( "log dump\n" );
	log_close_ascii( &log );
    printf( "-- QED --\n" );

    // Return from main
    return 1;
}
Пример #7
0
int main( int argc, char *argv[] )
{
    if (NUM_THREADS > 2){
        printf("CANNOT USE MORE THAN (2) HETEROGENEOUS THREADS!!!!\r\n");
        return (-1);
    }
    // Timer variables
    xps_timer_t timer;
    int time_create, time_start, time_stop;

    // Mutex
    hthread_mutex_t * mutex          = (hthread_mutex_t*)malloc( sizeof(hthread_mutex_t) );
    hthread_mutex_init( mutex, NULL );

    // Thread attribute structures
    Huint           sta[NUM_THREADS];
    void*           retval[NUM_THREADS];
    hthread_t       tid[NUM_THREADS];
    hthread_attr_t  attr[NUM_THREADS];
    targ_t thread_arg[NUM_THREADS];

    // Setup Cache
    XCache_EnableICache(0xc0000801);

    // Create timer
    xps_timer_create(&timer, (int*)0x20400000);

    // Start timer
    xps_timer_start(&timer);

// *************************************************************************************    
    extern unsigned char intermediate[];

    extern unsigned int blink_handle_offset;
    unsigned int blink_handle = (blink_handle_offset) + (unsigned int)(&intermediate);

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

    int j = 0;
    printf("Code start address = 0x%08x\n", (unsigned int)&intermediate);

    for (j = 0; j < NUM_THREADS; j++)
    {
        // Initialize the attributes for the threads
        hthread_attr_init( &attr[j] );
        hthread_attr_sethardware( &attr[j], (void*)base_array[j] );
    }

    int num_ops = 0;
    for( num_ops = 0; num_ops < 1; num_ops = num_ops + 1)
    { 

        printf("******* Round %d ********\n",num_ops);
#ifdef USE_MB_THREAD
        printf("**** MB-based Threads ****\n");
#else
        printf("**** PPC-based Threads ****\n");
#endif

        // Initialize thread arguments
        for ( j= 0; j < NUM_THREADS; j++)
        {
            thread_arg[j].arg = 1 << ((j + 1));
            thread_arg[j].mutex = mutex;
        }

        time_create = xps_timer_read_counter(&timer);
        // Create threads
        for (j = 0; j < NUM_THREADS; j++)
        {
            // Create the blink thread
#ifdef USE_MB_THREAD
            // Create MB Thread
            sta[j] = hthread_create( &tid[j], &attr[j], (void*)blink_handle, (void*)(&thread_arg[j]) );
            //printf( "Started MB Thread (TID = %d) \n", tid[j]);
#else
            // Create SW Thread
            sta[j] = hthread_create( &tid[j], NULL, blink_thread, (void*)(&thread_arg[j]) );
            //printf( "Started SW Thread (TID = %d) \n", tid[j]);
#endif
        }


        // Allow created threads to begin running and start timer
        time_start = xps_timer_read_counter(&timer);
        printf("Waiting for threads...\n");
        // Join on all threads
        for (j = 0; j < NUM_THREADS; j++)
        {
            hthread_join( tid[j], &retval[j] );
        }

        // Grab stop time
        time_stop = xps_timer_read_counter(&timer);

        // Print out status
        for (j = 0; j < NUM_THREADS; j++)
        {
            printf("TID[%d] = 0x%08x, status = 0x%08x, retval = 0x%08x\n",j,tid[j],sta[j],(unsigned int)retval[j]);
        }

        printf("*********************************\n");
        printf("Create time  = %u\n",time_create);
        printf("Start time   = %u\n",time_start);
        printf("Stop time    = %u\n",time_stop);
        printf("*********************************\n");
        printf("Creation time (|Start - Create|) = %u\n",time_start - time_create);
        printf("Elapsed time  (|Stop - Start|)   = %u\n",time_stop - time_start);


    }


    hthread_mutex_destroy( mutex );
    free( mutex );

    // Clean up the attribute structures
    for (j = 0; j < NUM_THREADS; j++)
    {
        hthread_attr_destroy( &attr[j] );
    }

    printf ("-- Complete --\n");

    // Return from main
    return 0;
}
Пример #8
0
int main()
{
  
   printf("--- Distance benchmark ---\n");
   printf("Number of Points: %d\n", ARR_LENGTH);
#ifdef OPCODE_FLAGGING
   printf("-->Opcode flagging ENABLED\n");
#else
   printf("-->Opcode flagging DISABLED\n");
#endif
   // Initialize various host tables once.
   init_host_tables();


    // Thread attribute structures
    targ_t thread_arg[NUM_THREADS];

    float vals_x0[ARR_LENGTH];
    float vals_x1[ARR_LENGTH];

    float vals_y0[ARR_LENGTH];
    float vals_y1[ARR_LENGTH];

    float vals_ds[ARR_LENGTH];

    int j = 0;

    for (j = 0; j < NUM_THREADS; j++)
    {
        // Initialize the attributes for the threads
        hthread_attr_init( &attr[j] );
    }

    for (j = 0; j < ARR_LENGTH; j++)
    {
        vals_x0[j] = (float) ARR_LENGTH - j;
        vals_y0[j] = (float) ARR_LENGTH - j;

        vals_x1[j] = (float) j + 1;
        vals_y1[j] = (float) ARR_LENGTH - j + 1;
    }



   // Initialize thread arguments
   int num_items = ARR_LENGTH/NUM_THREADS;
   int extra_items = ARR_LENGTH - (num_items*NUM_THREADS);
   for ( j= 0; j < NUM_THREADS; j++)
   {
      thread_arg[j].x0s = &vals_x0[j*(num_items)];
      thread_arg[j].y0s = &vals_y0[j*(num_items)];
      thread_arg[j].x1s = &vals_x1[j*(num_items)];
      thread_arg[j].y1s = &vals_y1[j*(num_items)];
      thread_arg[j].distances = &vals_ds[j*(num_items)];
      thread_arg[j].length = num_items;
   }
   // Add in extra items for the last thread if needed
   thread_arg[j-1].length += extra_items;

   start = hthread_time_get();
   // Create threads
   for (j = 0; j < NUM_THREADS; j++)
   {
      // Create the distance thread
      sta[j] =  thread_create( &tid[j], &attr[j], distance_thread_FUNC_ID, (void *) &thread_arg[j], STATIC_HW0+j, 0);
      //sta[j] =  thread_create( &tid[j], &attr[j], distance_thread_FUNC_ID, (void *) &thread_arg[j], DYNAMIC_HW, 0);
   }

   // Join on all threads
   for (j = 0; j < NUM_THREADS; j++) {
      if (thread_join(tid[j], &ret[j], &exec_time[j]))
         printf("Join error!\n");
   }

   // Grab stop time
   stop = hthread_time_get();

   for (j = 0; j < NUM_THREADS; j++) {
   // Determine which slave ran this thread based on address
   Huint base = attr[j].hardware_addr - HT_HWTI_COMMAND_OFFSET;
   Huint slave_num = (base & 0x00FF0000) >> 16;
   printf("Execution time (TID : %d, Slave : %d)  = %f msec\n", tid[j], slave_num, hthread_time_msec(exec_time[j]));
   }

   // Display OS overhead
   printf("Total OS overhead (thread_create) = %f usec\n", hthread_time_usec(create_overhead));
   printf("Total OS overhead (thread_join) = %f usec\n", hthread_time_usec(join_overhead));
   create_overhead=0;
   join_overhead=0;

   // Display overall time
   hthread_time_t diff; hthread_time_diff(diff, stop, start);
   printf("Total time = %f usec\n", hthread_time_usec(diff));

#ifdef DEBUG_DISPATCH
    for (j = 0; j < ARR_LENGTH; j++)
    {
        printf("D(%d) = %f\n",j,vals_ds[j]);
    }
#endif

    // Clean up the attribute structures
    for (j = 0; j < NUM_THREADS; j++)
    {
        hthread_attr_destroy( &attr[j] );
    }

   printf("--- Done ---\n");

    return 0;
}
Пример #9
0
int run_tests()
{
    if (NUM_THREADS > NUM_CPUS){
        printf("CANNOT USE MORE THAN (%d) HETEROGENEOUS THREADS!!!!\r\n", NUM_CPUS);
        return (-1);
    }
  
    // Timer variables
    xps_timer_t timer;
    int time_create, time_start, time_stop;

    // Thread attribute structures
    Huint           sta[NUM_THREADS];
    void*           retval[NUM_THREADS];
    hthread_t       tid[NUM_THREADS];
    hthread_attr_t  attr[NUM_THREADS];
    targ_t thread_arg[NUM_THREADS];

    // Setup Cache
    XCache_DisableDCache();
    XCache_EnableICache(0xc0000801);

    // Create timer
    xps_timer_create(&timer, (int*)0x20400000);

    // Start timer
    xps_timer_start(&timer);

// *************************************************************************************    
    extern unsigned char intermediate[];

    extern unsigned int distance_handle_offset;
    unsigned int distance_handle = (distance_handle_offset) + (unsigned int)(&intermediate);
    printf("Code start address = 0x%08x\n", (unsigned int)&intermediate);

// *************************************************************************************    
    int vals_x0[ARR_LENGTH];
    int vals_x1[ARR_LENGTH];

    int vals_y0[ARR_LENGTH];
    int vals_y1[ARR_LENGTH];
    int vals_ds[ARR_LENGTH];

    int j = 0;

    for (j = 0; j < NUM_THREADS; j++)
    {
        // Initialize the attributes for the threads
        hthread_attr_init( &attr[j] );
        hthread_attr_sethardware( &attr[j], (void*)base_array[j] );
    }

    for (j = 0; j < ARR_LENGTH; j++)
    {
        vals_x0[j] = ARR_LENGTH - j;
        vals_y0[j] = ARR_LENGTH - j;

        vals_x1[j] = ARR_LENGTH - j + 1;
        vals_y1[j] = ARR_LENGTH - j;
    }


#ifdef MY_DEBUG
#endif

    int num_ops = 0;
    for( num_ops = 0; num_ops < 2; num_ops = num_ops + 1)
    { 

        printf("******* Round %d ********\n",num_ops);
#ifdef USE_MB_THREAD
        printf("**** MB-based Threads ****\n");
#else
        printf("**** PPC-based Threads ****\n");
#endif

        for (j = 0; j < ARR_LENGTH; j++)
        {
            vals_x0[j]  = ARR_LENGTH - j;
        }

        // Initialize thread arguments
        int num_items = ARR_LENGTH/NUM_THREADS;
        int extra_items = ARR_LENGTH - (num_items*NUM_THREADS);
        for ( j= 0; j < NUM_THREADS; j++)
        {
            thread_arg[j].x0s = &vals_x0[j*(num_items)];
            thread_arg[j].y0s = &vals_y0[j*(num_items)];
            thread_arg[j].x1s = &vals_x1[j*(num_items)];
            thread_arg[j].y1s = &vals_y1[j*(num_items)];
            thread_arg[j].distances = &vals_ds[j*(num_items)];
            thread_arg[j].length = num_items;
        }
        // Add in extra items for the last thread if needed
        thread_arg[j-1].length += extra_items;

        time_create = xps_timer_read_counter(&timer);
        // Create threads
        for (j = 0; j < NUM_THREADS; j++)
        {
            // Create the distance thread
#ifdef USE_MB_THREAD
            // Create MB Thread
            sta[j] = hthread_create( &tid[j], &attr[j], (void*)distance_handle, (void*)(&thread_arg[j]) );
            //printf( "Started MB Thread (TID = %d) \n", tid[j]);
#else
            // Create SW Thread
            sta[j] = hthread_create( &tid[j], NULL, distance_thread, (void*)(&thread_arg[j]) );
            //printf( "Started SW Thread (TID = %d) \n", tid[j]);
#endif
        }


        // Allow created threads to begin running and start timer
        time_start = xps_timer_read_counter(&timer);
        // Join on all threads
        for (j = 0; j < NUM_THREADS; j++)
        {
            hthread_join( tid[j], &retval[j] );
        }

        // Grab stop time
        time_stop = xps_timer_read_counter(&timer);

        // Print out status
        for (j = 0; j < NUM_THREADS; j++)
        {
            printf("TID[%d] = 0x%08x, status = 0x%08x, retval = 0x%08x\n",j,tid[j],sta[j],(unsigned int)retval[j]);
        }

        printf("*********************************\n");
        printf("Create time  = %u\n",time_create);
        printf("Start time   = %u\n",time_start);
        printf("Stop time    = %u\n",time_stop);
        printf("*********************************\n");
        printf("Creation time (|Start - Create|) = %u\n",time_start - time_create);
        printf("Elapsed time  (|Stop - Start|)   = %u\n",time_stop - time_start);
        printf("Total time   (|Create - Stop|)   = %u\n",time_stop - time_create);


    }

#ifdef MY_DEBUG
    for (j = 0; j < ARR_LENGTH; j++)
    {
        printf("D(%d) = %d\n",j,vals_ds[j]);
    }
#endif

    // Clean up the attribute structures
    for (j = 0; j < NUM_THREADS; j++)
    {
        hthread_attr_destroy( &attr[j] );
    }

    printf ("-- Complete --\n");

    // Return from main
    return 0;
}
Пример #10
0
//int main( int argc, char *argv[] )
int run_tests()
{
    if (NUM_THREADS > NUM_CPUS){
        printf("CANNOT USE MORE THAN (%d) HETEROGENEOUS THREADS!!!!\r\n",NUM_CPUS);
        return (-1);
    }
    // Timer variables
    xps_timer_t timer;
    int time_create, time_start, time_stop;

    // Thread attribute structures
    Huint           sta[NUM_THREADS];
    void*           retval[NUM_THREADS];
    hthread_t       tid[NUM_THREADS];
    hthread_attr_t  attr[NUM_THREADS];
    targ_t thread_arg[NUM_THREADS];

    // Setup Cache
    XCache_DisableDCache();
    XCache_EnableICache(0xc0000801);

    // Create timer
    xps_timer_create(&timer, (int*)0x20400000);

    // Start timer
    xps_timer_start(&timer);

// *************************************************************************************    
    extern unsigned char intermediate[];

    extern unsigned int sort_handle_offset;
    unsigned int sort_handle = (sort_handle_offset) + (unsigned int)(&intermediate);

// *************************************************************************************    
    float local_data[ARR_LENGTH];

    int j = 0;
    printf("Code start address = 0x%08x\n", (unsigned int)&intermediate);

    for (j = 0; j < NUM_THREADS; j++)
    {
        // Initialize the attributes for the threads
        hthread_attr_init( &attr[j] );
        hthread_attr_sethardware( &attr[j], (void*)base_array[j] );
    }

    for (j = 0; j < ARR_LENGTH; j++)
    {
        local_data[j] = (ARR_LENGTH - j)*1.00;
    }


#ifdef MY_DEBUG
    show_array(&local_data[0], ARR_LENGTH);
#endif
    int num_ops = 0;
    for( num_ops = 0; num_ops < 2; num_ops = num_ops + 1)
    { 

        printf("******* Round %d ********\n",num_ops);
#ifdef USE_MB_THREAD
        printf("**** MB-based Threads ****\n");
#else
        printf("**** PPC-based Threads ****\n");
#endif

        for (j = 0; j < ARR_LENGTH; j++)
        {
            local_data[j]  = ARR_LENGTH - j;
        }


        // Initialize thread arguments
        for ( j= 0; j < NUM_THREADS; j++)
        {
            thread_arg[j].data = &local_data[j*(ARR_LENGTH/NUM_THREADS)];
            thread_arg[j].length = ARR_LENGTH/NUM_THREADS;
        }

        time_create = xps_timer_read_counter(&timer);
        // Create threads
        for (j = 0; j < NUM_THREADS; j++)
        {
            // Create the sort thread
#ifdef USE_MB_THREAD
            // Create MB Thread
            sta[j] = hthread_create( &tid[j], &attr[j], (void*)sort_handle, (void*)(&thread_arg[j]) );
            //printf( "Started MB Thread (TID = %d) \n", tid[j]);
#else
            // Create SW Thread
            sta[j] = hthread_create( &tid[j], NULL, bubblesort_thread, (void*)(&thread_arg[j]) );
            //printf( "Started SW Thread (TID = %d) \n", tid[j]);
#endif
        }


        // Allow created threads to begin running and start timer
        time_start = xps_timer_read_counter(&timer);

        // Join on all threads
        for (j = 0; j < NUM_THREADS; j++)
        {
            hthread_join( tid[j], &retval[j] );
        }

        // Grab stop time
        time_stop = xps_timer_read_counter(&timer);

        // Print out status
        for (j = 0; j < NUM_THREADS; j++)
        {
            printf("TID[%d] = 0x%08x, status = 0x%08x, retval = 0x%08x\n",j,tid[j],sta[j],(unsigned int)retval[j]);
        }

        printf("*********************************\n");
        printf("Create time  = %u\n",time_create);
        printf("Start time   = %u\n",time_start);
        printf("Stop time    = %u\n",time_stop);
        printf("*********************************\n");
        printf("Creation time (|Start - Create|) = %u\n",time_start - time_create);
        printf("Elapsed time  (|Stop - Start|)   = %u\n",time_stop - time_start);
        printf("Total time   (|Create - Stop|)   = %u\n",time_stop - time_create);


    }

#ifdef MY_DEBUG
    show_array(&local_data[0], ARR_LENGTH);
    check_array(&local_data[0], ARR_LENGTH);    // Note there will be errors as the data set is not merged
#endif

    // Clean up the attribute structures
    for (j = 0; j < NUM_THREADS; j++)
    {
        hthread_attr_destroy( &attr[j] );
    }

    printf ("-- Complete --\n");

    // Return from main
    return 0;
}
Пример #11
0
int run_tests()
{
    // Timer variables
    xps_timer_t timer;
    int time_create, time_start, time_unlock, time_stop;

    // Mutex
    hthread_mutex_t * mutex          = (hthread_mutex_t*)malloc( sizeof(hthread_mutex_t) );
    hthread_mutex_init( mutex, NULL );

    float min;

    // Thread attribute structures
    Huint           sta[NUM_THREADS];
    void*           retval[NUM_THREADS];
    hthread_t       tid[NUM_THREADS];
    hthread_attr_t  attr[NUM_THREADS];
    targ_t thread_arg[NUM_THREADS];

    // Setup Cache
    XCache_DisableDCache();
    XCache_EnableICache(0xc0000801);

    // Create timer
    xps_timer_create(&timer, (int*)0x20400000);

    // Start timer
    xps_timer_start(&timer);

// *************************************************************************************    
    extern unsigned char intermediate[];

    extern unsigned int min_handle_offset;
    unsigned int min_handle = (min_handle_offset) + (unsigned int)(&intermediate);


// *************************************************************************************    
    printf("Code start address = 0x%08x\n", (unsigned int)&intermediate);

    int i = 0;
    float main_array[ARRAY_LENGTH];
    printf("Addr of array = 0x%08x\n",(unsigned int)&main_array[0]);
    for (i = 0; i < ARRAY_LENGTH; i++)
    {
        main_array[i] = (i+2)*3.14f;
    }


    int num_items = ARRAY_LENGTH/NUM_THREADS;
    int extra_items = ARRAY_LENGTH - (num_items*NUM_THREADS);
    float * start_addr = &main_array[0];
    for (i = 0; i < NUM_THREADS; i++)
    {
        // Initialize the attributes for the hardware threads
        hthread_attr_init( &attr[i] );
        hthread_attr_sethardware( &attr[i], (void*)base_array[i] );

        // Initialize thread arguments
        thread_arg[i].num_items = num_items;
        thread_arg[i].data_ptr = start_addr;
        thread_arg[i].min_mutex = mutex;
        thread_arg[i].min  = &min;
        start_addr+=num_items;
    }
    // Add in extra items for the last thread if needed
    thread_arg[i-1].num_items += extra_items;

    int num_ops = 0;
    for( num_ops = 0; num_ops < 2; num_ops = num_ops + 1)
    { 

        printf("******* Round %d ********\n",num_ops);
#ifdef USE_MB_THREAD
    printf("**** MB-based Threads ****\n");
#else
    printf("**** PPC-based Threads ****\n");
#endif
        min = 9999999;

        // Lock mutex before hand so that timing will not include thread creation time
        hthread_mutex_lock(mutex);

        // Start timing thread create
        time_create = xps_timer_read_counter(&timer);

        for (i = 0; i < NUM_THREADS; i++)
        {
            // Create the worker threads
#ifdef USE_MB_THREAD

            // Create MB Thread
            sta[i] = hthread_create( &tid[i], &attr[i], (void*)(min_handle), (void*)(&thread_arg[i]) );
#else
            // Create SW Thread
            sta[i] = hthread_create( &tid[i], NULL, min_thread, (void*)(&thread_arg[i]) );
#endif
        }

        // Allow created threads to begin running and start timer
        time_start = xps_timer_read_counter(&timer);
        hthread_mutex_unlock(mutex);
        time_unlock = xps_timer_read_counter(&timer);

        // Wait for the threads to exit
		//printf( "Waiting for thread(s) to complete... \n" );
        for (i = 0; i < NUM_THREADS; i++)
        {
    	    hthread_join( tid[i], &retval[i] );
        }

        time_stop = xps_timer_read_counter(&timer);

        // Display results
        printf("Min = %f\n",min);
        for (i = 0; i < NUM_THREADS; i++)
        {
            printf("TID = 0x%08x, status = 0x%08x, retval = 0x%08x\n",tid[i],sta[i],(Huint)retval[i]);
        }
        printf("*********************************\n");
        printf("Create time  = %u\n",time_create);
        printf("Start time   = %u\n",time_start);
        printf("Unlock time  = %u\n",time_unlock);
        printf("Stop time    = %u\n",time_stop);
        printf("*********************************\n");
        printf("Creation time (|Start - Create|) = %u\n",time_start - time_create);
        printf("Unlock time (|Unlock - Start|)   = %u\n",time_unlock - time_start);
        printf("Elapsed time  (|Stop - Start|)   = %u\n",time_stop - time_start);

    }

    hthread_mutex_destroy( mutex );
    free( mutex );

    // Clean up the attribute structures
    for (i = 0; i < NUM_THREADS; i++)
    {
        hthread_attr_destroy( &attr[i] );
    }
    printf ("-- Complete --\n");

    // Return from main
    return 0;
}