Ejemplo n.º 1
0
void run_B (int use_hw, int num_load_threads, thread_arg_t * arg)
{
    unsigned int i=0;
    hthread_t measure_tidA, measure_tidB;
    hthread_t tids[num_load_threads];
    hthread_mutexattr_t block_attr;
    hthread_mutexattr_t data_attr;

    // Print banner
    show_banner(num_load_threads);

    // 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;

    // Create measurement thread A
    hthread_create(&measure_tidA, NULL, measureThread, (void*)arg);  

    // Create measurement thread B
    hthread_create(&measure_tidB, NULL, testThreadWithMeasurement, (void*)arg);  
    
    // Create all of the load threads
    dbg_printf("Creating load threads...\n");
    for (i = 0; i < num_load_threads; i++)
    {
        // Create load thread
        hthread_create(&tids[i], NULL, testThread, (void*)arg);  
    }

    // Make sure that measurement thread A runs
    hthread_join(measure_tidA,NULL);

    // Make sure that measurement thread B runs
    hthread_join(measure_tidB,NULL);

    // Wait for all load threads to complete
    for (i = 0; i < num_load_threads; i++)
    {
        // Join on load thread
        hthread_join(tids[i],NULL); 
    }

    // Extract turn-around results
    // Turn-around = unlock_start to measure_lock_stop 
    arg->measure_lock_check = calc_timediff_us(arg->unlock_start, arg->measure_lock_stop);

    return;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
int main( int argc, char *argv[] )
{
	hthread_t           tid[ CHILDREN ];
    hthread_mutex_t     mutex;
    hthread_mutexattr_t attr;
    Huint               i;

    hthread_mutexattr_init( &attr );
    hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_FAST_NP );
    hthread_mutexattr_setnum( &attr, 1 );
    hthread_mutex_init( &mutex, &attr );
    
    for( i = 0; i < CHILDREN; i++ )
    {
        hthread_create( &tid[i], NULL, child, &mutex );
    }
    
    for( i = 0; i < CHILDREN; i++ )
    {
   	    hthread_join( tid[i], NULL );
    }

	printf( "--DONE--\n" );
	return 1;
}
Ejemplo n.º 4
0
int main() {
	hthread_t test_thread;
	hthread_mutexattr_t attr;
	hthread_mutex_t mutex;
	struct test_data data;
	int arg, retVal;
	
	//Print the name of the test to the screen
	printf( "Starting test mutexattr_init_1\n" );

	//Set up the arguments for the test
	data.attr = &attr;
	data.mutex = &mutex;
	arg = (int) &data;
	
	//Run the tests
	hthread_create( &test_thread, NULL, testThread, (void *) arg );
	hthread_join( test_thread, (void *) &retVal );

	//Evaluate the results
	if ( retVal == EXPECTED_RESULT ) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("Test FAILED [expecting %d, received%d]\n", EXPECTED_RESULT, retVal );
		return PTS_FAIL;
	}	
}
Ejemplo n.º 5
0
int main() {
	hthread_t test_thread;
	hthread_attr_t test_attr;
	hthread_mutex_t mutex;
	int arg, retVal;
	
	//Print the name of the test to the screen
	printf( "Starting test mutex_init_3\n" );

	//Set up the arguments for the test
	arg = (int) &mutex;
	
	//Initialize RPC
	rpc_setup();
	
	//Run the tests
	hthread_attr_init( &test_attr );
	if ( HARDWARE ) hthread_attr_sethardware( &test_attr, HWTI_ONE_BASEADDR );
	hthread_create( &test_thread, &test_attr, testThread, (void *) arg );
	hthread_join( test_thread, (void *) &retVal );

	if ( HARDWARE ) readHWTStatus( HWTI_ONE_BASEADDR );
	
	//Evaluate the results
	if ( retVal == EXPECTED_RESULT ) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("Test FAILED [expecting %d, received %d]\n", EXPECTED_RESULT, retVal );
		return PTS_FAIL;
	}
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
int main( int argc, char *argv[] )
{
    hthread_t   prod_tid;
    hthread_t   sort_tid;
    hthread_t   cons_tid;
    prod_struct prod;
    sort_struct sort;
    cons_struct cons;

    // Setup the structures for the threads
    DEBUG_PRINTF( "Setting up Structures\n" );
    setup_structs( &prod, &sort, &cons );

    // Create the producing thread
    DEBUG_PRINTF( "Creating Producer\n" );
    hthread_create( &prod_tid, NULL, prod_thread, (void*)&prod );
    
    // Create the sorting thread
    DEBUG_PRINTF( "Creating Sorter\n" );
    hthread_create( &sort_tid, NULL, sort_thread, (void*)&sort );

    // Create the consuming thread
    DEBUG_PRINTF( "Creating Consumer\n" );
    hthread_create( &cons_tid, NULL, cons_thread, (void*)&cons );
    
    // Send the start signal to the producer
    DEBUG_PRINTF( "Starting Producer\n" );
    start_producer( &prod, &sort, &cons );

    // Wait for the sorting thread to finish
    hthread_join( prod_tid, NULL );
    
    // Wait for the sorting thread to finish
    hthread_join( sort_tid, NULL );
    
    // Wait for the sorting thread to finish
    hthread_join( cons_tid, NULL );

    // Clean up the structures
    DEBUG_PRINTF( "Cleaning Structures\n" );
    destroy_structs( &prod, &sort, &cons );

    // Exit the program
    return 0;
}
Ejemplo n.º 9
0
Hint thread_create(hthread_t *t, hthread_attr_t *a, hthread_start_t s, void *g)
{
    Hint status;

    status = hthread_create( t, a, s, g );

	if( status != SUCCESS ) DEBUG_PRINTF( "CREATE ERROR: 0x%8.8x\n", status );
    return status;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
int thread_pool_init(struct threadpool * tp, int num_threads)
{
  int iterator;

  for (iterator = 0; iterator < num_threads; iterator++) {
    tp->thr_id[iterator] = iterator;
    hthread_create(&(tp->p_threads[iterator]), NULL, handle_requests_loop, (void *) tp);
  }
  return 0;
}
Ejemplo n.º 12
0
void * testThread ( void * arg ) {
	int retVal;
	struct test_data * data = (struct test_data *) arg;
	
	hthread_create( &data->thread, NULL, data->function, NULL );
	retVal = hthread_join( data->thread, NULL );
	
	hthread_exit( (void *) retVal );
	return NULL;
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
void * testThread ( void * arg ) {
	int retVal;
	struct testdata * data = (struct testdata *) arg;
	
	hthread_create( &data->thread, data->attr, data->function, NULL );
    hthread_attr_setdetachstate( data->attr, HTHREAD_CREATE_DETACHED );
	retVal = hthread_join( data->thread, NULL );
	
	hthread_exit( (void *) retVal );
	return NULL;
}
Ejemplo n.º 15
0
int main (int argc, char *argv[]) 
{
    unsigned int start      = 0;
    unsigned int stop       = 0;
    hthread_t thread;
    struct simple_test simple;
    Huint i, j, ret;
	
for(j = 0; j < ITERATIONS; j++)
{

#ifdef PRINT	
    printf("\nStarting Simple Test...\n");
#endif	
    simple.val = 110;

    // Xilinx OPB Timer locations as specified in the .mhs file
    volatile int *timer_control = (int*)0x73000000;
    volatile int *timer_value   = (int*)0x73000008;

    // Enable timer and clear interrupt
    *timer_control = 0x00000510;

    // Start the timer
    start = *timer_value;

    for(i = 0; i < j+1; i++)
    {
	hthread_create(&thread, NULL, simple_thread, (void*)&simple); 
        hthread_join(thread, (void*)&ret);

#ifdef PRINT		
        printf( "main: CPUID = %d\n",_get_procid());
        printf( "main: Val =  %d\n", simple.val );
	printf( "..................................\n");
#endif	
    }

    // Stop timer
    stop = *timer_value;
    
    printf("Exec. Time = %d Iteration = %d\n",(stop-start),j);

#ifdef PRINT
    printf("Start Time = %u\n",start);
    printf("Stop Time  = %u\n",stop);
    printf("Exec. Time = %d\n",(stop-start));
    printf( "main: Val =  %d\n", simple.val );
    printf( "- done -\n\n" );
#endif
}
    return 0;
}
Ejemplo n.º 16
0
// The daemon_init function provides an interface to the main thread
// to start the daemon. It should only be called once and will run
// in the main thread.
void daemon_init(DaemonComm *dc)
{
    // Initialize the Daemon Communication Struct.
    // This struct is used to pass information from the
    // main thread to the daemon thread.
    UNSET(dc->new_code);
    UNSET(dc->in_hw);
    dc->new_code_address = NULL;
    dc->new_code_size = 0;

    // Create the daemon thread.
    hthread_create(&dc->tid, NULL, daemon_thread, (void *)dc);
}
Ejemplo n.º 17
0
void * testThread ( void * arg ) {
	int retVal;
	struct test_data * data = (struct test_data *) arg;
	
	hthread_create( &data->thread, NULL, data->function, NULL );
	hthread_join( data->thread, NULL );
	
	//If the thread exited, and we can join on it, its a success
	retVal = SUCCESS;
	
	hthread_exit( (void *) retVal );
	return NULL;
}
Ejemplo n.º 18
0
Hint create_producer( buffer_t *buffer, hthread_t *tid )
{
    Hint sta;

    // Attempt to create the thread
    sta = hthread_create( tid, NULL, producer, (void*)buffer );

    // Check that the creation was successful
    if( sta != 0 )  DEBUG_PRINTF( "ERROR: (OP=CREATE) (STA=0x%8.8x)\n", sta );

    // Return the status back to the user
    return sta;
}
Ejemplo n.º 19
0
void * testThread ( void * arg ) {
	int retVal;
	struct test_data * data = (struct test_data *) arg;

	hthread_mutex_lock( data->mutex );
	hthread_create( &data->thread, NULL, data->function, (void *) data );
	retVal = hthread_cond_wait( data->cond, data->mutex );
	hthread_mutex_unlock( data->mutex );
	
	hthread_join( data->thread, NULL );
	
	hthread_exit( (void *) retVal );
	return NULL;
}
Ejemplo n.º 20
0
hthread_t create_worker( argument *arg )
{
	hthread_t	tid;
    Huint 		status;

    status = hthread_create( &tid, NULL, thread_worker, (void*)arg );
	if( status != 0 )
	{
		printf( "Create Error: (STA=%u) (TID=%u)\n",status,tid );
        while(1);
	}
	
    return tid;
}
Ejemplo n.º 21
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_create_thread( TID* ptid, ATTR* pat,
                                       THREAD_FUNC* pfn, void* arg,
                                       const char* name, const char* location )
{
    int rc;
    void** arg2;
    UNREFERENCED( name );               /* unref'ed on non-Windows   */
    pttthread = 1;                      /* Set a mark on the wall    */
    arg2 = malloc( 2 * sizeof( void* ));
    *(arg2+0) = (void*) pfn;
    *(arg2+1) = (void*) arg;
    rc = hthread_create( ptid, pat, hthread_func, arg2, name );
    PTTRACE( "create", (void*)*ptid, NULL, location, rc );
    return rc;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
int main() {
	hthread_t test_thread;
	hthread_attr_t test_attr;
	int arg, retVal, start_num, waken_num;
	struct testdata data;
	hthread_mutex_t mutex;
	hthread_cond_t cond;
	
	//Print the name of the test to the screen
	printf( "Starting test cond_broadcast_1\n" );

	//Set up the arguments for the test
	hthread_cond_init( &cond, NULL );
	hthread_mutex_init( &mutex, NULL );
	start_num = 0;
	waken_num = 0;
	
	data.mutex = &mutex;
	data.cond = &cond;
	data.start_num = &start_num;
	data.waken_num = &waken_num;
	data.function = a_thread_function;
	
	arg = (int) &data;
	
	//Initialize RPC
	rpc_setup();
	
	//Run the tests
	hthread_attr_init( &test_attr );
	if ( HARDWARE ) hthread_attr_sethardware( &test_attr, HWTI_ONE_BASEADDR );
	hthread_create( &test_thread, &test_attr, testThread, (void *) arg );
	hthread_join( test_thread, (void *) &retVal );

	if ( HARDWARE ) readHWTStatus( HWTI_ONE_BASEADDR );
	
	//Evaluate the results
	if ( retVal == EXPECTED_RESULT ) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("Test FAILED [expecting %d, received %d]\n", EXPECTED_RESULT, retVal );
		return PTS_FAIL;
	}
}
//------------------------------------------//
// Software_Create                          //
// Description: Function used to create     //
// software threads only. Used if creating  //
// a hardware thread fails.                 //
//------------------------------------------//
Huint software_create (
        hthread_t * tid,
        hthread_attr_t * attr,
        Huint func_id,
        void * arg)
{
    
    void * func;

    // ---------------------------------------------
    // Make sure tables are setup
    // ---------------------------------------------
    if (!table_initialized_flag) {
        
        // Assert flag
        table_initialized_flag = 1;

        // Init thread table
        init_thread_table(&global_thread_table);

        // Load entries with app-specific data
        load_my_table();

        // Init function-to-accelerator table
        init_func_2_acc_table();

        #ifdef ICAP
        // Initialize mutexes, ICAP, and bitfiles
        // for Partial Reconfiguration.
        init_PR_data();
        #endif
    }

    #ifdef DEBUG_DISPATCH
    printf("Software thread\n");
    #endif

    // Create a native/software thread on the host processor
    func = lookup_handle(&global_thread_table, func_id, TYPE_HOST);
  
    // Increment thread counter
    thread_counter++; 
        
    return (hthread_create(tid, attr, func, arg));
}
Ejemplo n.º 25
0
void * testThread ( void * arg ) {
	int retVal, i;
	struct testdata * data = (struct testdata *) arg;

	for( i=0; i<THREAD_NUM; i++ )	
		hthread_create( &data->thread[i], NULL, data->function, (void *) data );
	while( *(data->start_num) != THREAD_NUM ) hthread_yield();
	hthread_mutex_lock( data->mutex );
	hthread_cond_broadcast( data->cond );
	hthread_mutex_unlock( data->mutex );
	for( i=0; i<THREAD_NUM; i++ )	
		hthread_join( data->thread[i], NULL );
	
	retVal = *(data->waken_num);
	
	hthread_exit( (void *) retVal );
	return NULL;
}
Ejemplo n.º 26
0
int main (int argc, char *argv[]) {
	hthread_t thread; //I came up with this name myself
	struct fibonacci fib;
//	log_t log;
    Huint fibArray[FIBMAX];
//	Huint *fibArray;
	Huint i;

	hthread_mutex_init( &hwtiMutex, NULL );
	hthread_mutex_init( &mutex2, NULL );
	hthread_mutex_init( &mutex3, NULL );
	hthread_mutex_init( &mutex4, NULL );
	printf( "Mutex number is %d\n", hwtiMutex.num );
	printf( "Mutex number is %d\n", mutex2.num );
	printf( "Mutex number is %d\n", mutex3.num );
	printf( "Mutex number is %d\n", mutex4.num );

//	log_create( &log, 1024 );
//	log_time( &log );

//	fibArray = malloc( FIBMAX * sizeof ( Huint ) );

	for( i=0; i<FIBMAX; i++ ) {
		fib.fibNum = i;
    
		printf( "Creating Thread for Fibonacci %d\n", i );
		hthread_create(&thread, NULL, findFibonacci, (void*)&fib);
		hthread_join(thread, NULL);
		fibArray[i] = fib.fibVal;
	}

//	log_time( &log );
	for( i=0; i<FIBMAX; i++ ) {
		printf( "Fibonacci %d is %d\n", i, fibArray[i] );
	}
//	log_close_ascii( &log );
//	printf( "\nReview the log file to determine the total time\n" );
	printf( " - done -\n\n" );
	return 1 ;
}
Ejemplo n.º 27
0
hthread_t create_new_thread(uint ctr, Hbool detached)
{    
    Huint status;
    hthread_t   thread_id;
	hthread_attr_t  attrs;

	// Setup the attributes for the main thread
	attrs.detached		= detached;
	attrs.stack_size	= HT_STACK_SIZE;
    
    status = hthread_create( &thread_id, &attrs, simpleThread, (void*) ctr);
	if( status != 0 )
	{
        // UNrecoverable error.
		printf( "Create Error: %u,  for %s thread (CTR = %u)\n",
                status,
                ((detached == Htrue)? "detached" : "joinable"),
                ctr);
        while(1);
	}
    return thread_id;
}
Ejemplo n.º 28
0
int main() {
	hthread_t test_thread;
	int arg, retVal;
	
	//Print the name of the test to the screen
	printf( "Starting test yield_1\n" );

	//Set up the arguments for the test
	arg = (int) NULL;
	
	//Run the tests
	hthread_create( &test_thread, NULL, testThread, (void *) arg );
	hthread_join( test_thread, (void *) &retVal );

	//Evaluate the results
	if ( retVal == EXPECTED_RESULT ) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("Test FAILED [expecting %d, received%d]\n", EXPECTED_RESULT, retVal );
		return PTS_FAIL;
	}	
}
Ejemplo n.º 29
0
int main( int argc, char *argv[] )
{
	hthread_t           tid[ CHILDREN ];
    hthread_mutex_t     mutex[ MUTEXES ];
    hthread_mutexattr_t attr;
    Huint               i;
    Huint               j;
    Huint               c;

    hthread_mutexattr_init( &attr );
    hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_FAST_NP );
    
    c = 0;
    for( i = 0; i < MUTEXES; i++ )
    {
        hthread_mutexattr_setnum( &attr, i );
        hthread_mutex_init( &mutex[i], &attr );
        
        for( j = 0; j < CHILDREN_PER_MUTEX; j++ )
        {
            hthread_create( &tid[c], NULL, child, &mutex[i] );
            printf( "Created Child %u\n", tid[c] );

            c++;
        }
    }
    
    for( i = 0; i < CHILDREN; i++ )
    {
        printf( "Join Child %u\n", tid[i] );
   	    hthread_join( tid[i], NULL );
    }
    
	printf( "--DONE--\n" );
	return 1;
}
Ejemplo n.º 30
0
int main() {
    unsigned int i = 0;
	int retVal;
    
    // Allocate NUM_THREADS threads
    hthread_t * tid = (hthread_t *) malloc(sizeof(hthread_t) * NUM_THREADS);
    hthread_attr_t * attr = (hthread_attr_t *) malloc(sizeof(hthread_attr_t) * NUM_AVAILABLE_HETERO_CPUS);

    assert(tid);
    assert(attr);
    
    // Set up attributes for a hardware thread
    for (i = 0; i < NUM_AVAILABLE_HETERO_CPUS; i++)
    { 
        hthread_attr_init(&attr[i]);
        hthread_attr_setdetachstate( &attr[i], HTHREAD_CREATE_JOINABLE);
    }
	
    unsigned int failed = 0;
	
    // Create hardware threads first
    for (i = 0; i < NUM_AVAILABLE_HETERO_CPUS; i++) {
        // Create thread -- Assuming that thread manager will give us
        // a TID = 2 every time since we are creating & joining 1 thread 
        // at a time.
        if (microblaze_create( &tid[i], &attr[i], foo_thread_FUNC_ID, (void *) 2, i) ) {
            failed = 1;
            PRINT_ERROR(THREAD_HARDWARE_CREATE_FAILED);
        }
        if (hthread_join( tid[i], (void *) &retVal ) ) {
            failed = 1;
            PRINT_ERROR(THREAD_HARDWARE_JOIN_FAILED);
        }
        // Make sure the return value is equal to base_array[i]
        if (base_array[i] != ((unsigned int) retVal - HT_CMD_HWTI_COMMAND)) {
            failed = 1;
            PRINT_ERROR(THREAD_HARDWARE_INCORRECT_RETURN);
        }

    }
    
    // Create all threads as software threads
    for (i = 0; i < NUM_THREADS; i++) {
        // Create threads
	    if (hthread_create( &tid[i], NULL, foo_thread, (void *) 2 )) {
            failed = 1;
            PRINT_ERROR(THREAD_SOFTWARE_CREATE_FAILED);
        }
    }
    // Now join on all software threads we just created
    for (i = 0; i < NUM_THREADS; i++) {
        // Join on thread
	    if (hthread_join(tid[i], (void *) &retVal )) {
            failed = 1;
            PRINT_ERROR(THREAD_SOFTWARE_JOIN_FAILED);
        }
    }
    // Create NUM_THREADS threads
	// ----> Create hardware threads first
    for (i = 0; i < NUM_AVAILABLE_HETERO_CPUS; i++) {
        // Create threads
        if (microblaze_create( &tid[i], &attr[i], foo2_thread_FUNC_ID, (void *) i, i) ) {
            failed = 1;
            PRINT_ERROR(THREAD_HARDWARE_CREATE_FAILED);
        }
    }

    // ----> The remaining are software threads
    for (i = NUM_AVAILABLE_HETERO_CPUS; i < NUM_THREADS; i++) {
        // Create threads
	    if (hthread_create( &tid[i], NULL, foo2_thread, (void *) i )) {
            failed = 1;
            PRINT_ERROR(THREAD_SOFTWARE_CREATE_FAILED);
        }
    }

    // Try to create more here --SHOULD FAIL!!!
    for (i = 0; i < NUM_THREADS; i++) {
        // If it does not fail
	    if (hthread_create( &tid[i], NULL, foo2_thread, (void *) i ) == SUCCESS ) {
            failed = 1;
            PRINT_ERROR(THREAD_SOFTWARE_ERROR_FAILED);
        }
    }

    // Clean up- Join on the threads.
    for (i = 0; i < NUM_THREADS; i++) {
        // If it fails
	    if (hthread_join(tid[i], (void *) &retVal )) {
            failed = 1;
            PRINT_ERROR(FINAL_JOIN_ERROR);
        }
    }

    // Test dynamic_create_smart
    

#ifdef SPLIT_BRAM
    // Test microblaze_create_DMA and dyanmic_create_smart_DMA
        
#endif
    
    if (failed) {
        PRINT_ERROR(TEST_FAILED);
    }
    else
        PRINT_ERROR(TEST_PASSED);

    free(tid);
    free(attr);

	return TEST_PASSED;
}