int main(){ struct rthread_t newthread; struct rthread_t newthread2; int ret=rthread_create(&newthread,testfunc,NULL); int ret2=rthread_create(&newthread2,test2func,NULL); while(1){}; return 0; }
static void build_histogram_thread_create(void) { int error; pthread_attr_init(&build_histogram_attr); pthread_attr_setstacksize(&build_histogram_attr, STACK_SIZE); #ifdef HW_HISTOGRAM printf("building histogram in hardware...\n"); rthread_attr_init(&build_histogram_rattr); rthread_attr_setslotnum(&build_histogram_rattr, 0); rthread_attr_setresources(&build_histogram_rattr, build_histogram_resources, 2); error = rthread_create( &build_histogram_thread, &build_histogram_attr, &build_histogram_rattr, NULL); #else printf("building histogram in software...\n"); error = pthread_create( &build_histogram_thread, &build_histogram_attr, build_histogram_entry, NULL); #endif if(error){ perror("pthread_create: build_histogram"); exit(1); } }
static inline int posix_hwt_create(int nslot, void * init_data, reconos_res_t * res, int nres) { rthread_attr_init(&rattr[nslot]); rthread_attr_setslotnum(&rattr[nslot], nslot); rthread_attr_setresources(&rattr[nslot], res, nres); //pthread_attr_init(&posix_attr); return rthread_create(&posix_thread[nslot], &rattr[nslot], init_data); }
/** creates sample HW threads (dynamic) @param number_of_threads: number of threads for sampling step @param hw_circuit: hardware circuit of the thread @param parameter: pointer to a array filled with parameter (size <= 128 byte) @param number_of_parameter: number of parameter in parameter array */ void set_sample_hw_dynamic (unsigned int number_of_threads, reconos_circuit_t * hw_circuit, int * parameter, unsigned int number_of_parameter){ int i; // terminate old sw threads if needed if (number_of_threads < 0 || number_of_threads == hw_number_of_threads_s_dynamic) { return; } else { if (number_of_threads < hw_number_of_threads_s_dynamic) { // remove slots, which are not needed sample_hw_delete_dynamic(hw_number_of_threads_s_dynamic - number_of_threads); hw_number_of_threads_s_dynamic = number_of_threads; return; } } if (information_s_dynamic == NULL) { // set information information_s_dynamic = (information_struct_s *) malloc (sizeof(information_struct_s)); information_s_dynamic[0].particles = particles; information_s_dynamic[0].number_of_particles = N; information_s_dynamic[0].particle_size = sizeof(particle); information_s_dynamic[0].max_number_of_particles = 8096 / sizeof(particle); information_s_dynamic[0].block_size = block_size; information_s_dynamic[0].parameter = parameter; information_s_dynamic[0].number_of_parameter = number_of_parameter; } if (res_s_dynamic == NULL) { // set ressources res_s_dynamic = (reconos_res_t *) malloc (4 * sizeof(reconos_res_t)); res_s_dynamic[0].ptr = mb_sampling_handle; res_s_dynamic[0].type = CYG_MBOX_HANDLE_T ; res_s_dynamic[1].ptr = mb_sampling_done_handle; res_s_dynamic[1].type = CYG_MBOX_HANDLE_T ; res_s_dynamic[2].ptr = hw_mb_sampling_measurement_handle; res_s_dynamic[2].type = CYG_MBOX_HANDLE_T ; res_s_dynamic[3].ptr = hw_mb_sampling_exit_handle; res_s_dynamic[3].type = CYG_MBOX_HANDLE_T ; } // create and resume hw sampling threads in eCos for (i = 0; i < (number_of_threads - hw_number_of_threads_s_dynamic); i++) { hw_thread_node * new_node = malloc (sizeof(hw_thread_node)); new_node->sw_attr = (pthread_attr_t *) malloc (sizeof(pthread_attr_t)); new_node->hw_attr = (rthread_attr_t *) malloc (sizeof(rthread_attr_t)); int ret = pthread_attr_init(new_node->sw_attr); //diag_printf("\nS: p_thread_attr_init = %d", ret); ret = pthread_attr_setstacksize(new_node->sw_attr, STACK_SIZE); //diag_printf("\nS: p_thread_attr_set_stacksize = %d", ret); ret = rthread_attr_init(new_node->hw_attr); //diag_printf("\nS: r_thread_attr_init = %d", ret); ret = rthread_attr_setcircuit(new_node->hw_attr, hw_circuit); //diag_printf("\nS: r_thread_set_circuit = %d", ret); //rthread_attr_setstatesize(new_node->hw_attr, 16384); ret = rthread_attr_setresources(new_node->hw_attr, res_s_dynamic, 4); //diag_printf("\nS: r_thread_attr_setresources = %d", ret); ret = rthread_create(&(new_node->hw_thread), new_node->sw_attr, new_node->hw_attr, (void*)information_s_dynamic); //diag_printf("\nS: r_thread_create = %d", ret); // insert node to list new_node->next = hw_threads_s_dynamic; hw_threads_s_dynamic = new_node; } // set number of hw threads hw_number_of_threads_s_dynamic = number_of_threads; }
int main( int argc, char *argv[] ) { unsigned int i, start_count = 0, done_count = 0; timing_t t_start = 0, t_stop = 0, t_gen = 0, t_sort = 0, t_merge = 0, t_check = 0; unsigned int *addr; unsigned int dummy; int retval; printf( "-------------------------------------------------------\n" "ReconOS hardware multithreading case study (sort)\n" "(c) Computer Engineering Group, University of Paderborn\n\n" "eCos/POSIX, multi-threaded hardware version (" __FILE__ ")\n" "Compiled on " __DATE__ ", " __TIME__ ".\n" "-------------------------------------------------------\n\n" ); #ifdef USE_CACHE printf( "enabling data cache for external ram\n" ); XCache_EnableDCache( 0x80000000 ); #else printf( "data cache disabled\n" ); XCache_DisableDCache( ); #endif data = buf_a; //---------------------------------- //-- GENERATE DATA //---------------------------------- printf( "Generating data..." ); t_start = gettime( ); generate_data( data, SIZE ); t_stop = gettime( ); t_gen = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); #ifdef USE_CACHE // flush cache contents - the hardware can only read from main memory // TODO: storing could be more efficient printf( "Flushing cache..." ); XCache_EnableDCache( 0x80000000 ); printf( "done\n" ); #endif //---------------------------------- //-- SORT DATA //---------------------------------- // create mail boxes for 'start' and 'complete' messages mb_start_attr.mq_flags = mb_done_attr.mq_flags = 0; mb_start_attr.mq_maxmsg = mb_done_attr.mq_maxmsg = 10; mb_start_attr.mq_msgsize = mb_done_attr.mq_msgsize = 4; mb_start_attr.mq_curmsgs = mb_done_attr.mq_curmsgs = 0; // unlink mailboxes, if they exist retval = mq_unlink("/mb_start"); if (retval != 0 && errno != ENOENT) { // we don't care if it doesn't exist diag_printf("unable to unlink mb_start"); } retval = mq_unlink("/mb_done"); if (retval != 0 && errno != ENOENT) { // we don't care if it doesn't exist diag_printf("unable to unlink mb_done"); } // open/create mailboxes mb_start = mq_open("/mb_start", O_RDWR | O_CREAT, S_IRWXU | S_IRWXG, &mb_start_attr); if (mb_start == (mqd_t)-1) { diag_printf("unable to create mb_start"); } mb_done = mq_open("/mb_done", O_RDWR | O_CREAT, S_IRWXU | S_IRWXG, &mb_done_attr); if (mb_done == (mqd_t)-1) { diag_printf("unable to create mb_done"); } // create sorting sowftware threads for ( i = 0; i < MT_HW_NUM_SW_THREADS; i++ ) { pthread_attr_init(&thread_sorter_attr[i]); pthread_create(&thread_sorter[i], &thread_sorter_attr[i], sort8k_entry_posix, (void*)i); } // create sorting hardware thread pthread_attr_init(&hwthread_sorter_attr); pthread_attr_setstacksize(&hwthread_sorter_attr, STACK_SIZE); rthread_attr_init(&hwthread_sorter_hwattr); rthread_attr_setslotnum(&hwthread_sorter_hwattr, 0); rthread_attr_setresources(&hwthread_sorter_hwattr, hwthread_sorter_resources, 2); rthread_create(&hwthread_sorter, &hwthread_sorter_attr, &hwthread_sorter_hwattr, (void*)0); printf( "Sorting data..." ); i = 0; t_start = gettime( ); // put 9 messages into mb_start while ( start_count < 9 ) { addr = &data[i]; if ( mq_send( mb_start, ( void * ) &addr, sizeof(addr), 0 ) == 0 ) { start_count++; i += N; } else { perror("while sending to mq_send"); break; } } t_stop = gettime( ); t_sort += calc_timediff_ms( t_start, t_stop ); while ( done_count < SIZE / N ) { t_start = gettime( ); // if we have something to distribute, // put one into the start mailbox if ( start_count < SIZE / N ) { addr = &data[i]; if ( mq_send( mb_start, ( void * ) &addr, sizeof(addr), 0 ) == 0 ) { start_count++; i += N; } else { perror("while sending to mq_send"); break; } } // see whether anybody's done if ( mq_receive( mb_done, (void*)&dummy, sizeof(dummy), 0 ) == sizeof(dummy) ) { done_count++; } else { perror( "while receiving from mq_done" ); break; } t_stop = gettime( ); t_sort += calc_timediff_ms( t_start, t_stop ); } printf( "done\n" ); #ifdef USE_CACHE // flush cache contents // TODO: invalidating would suffice printf( "Flushing cache..." ); XCache_EnableDCache( 0x80000000 ); printf( "done\n" ); #endif //---------------------------------- //-- MERGE DATA //---------------------------------- printf( "Merging data..." ); t_start = gettime( ); data = recursive_merge( data, buf_b, SIZE, N, simple_merge ); t_stop = gettime( ); t_merge = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); //---------------------------------- //-- CHECK DATA //---------------------------------- printf( "Checking sorted data..." ); t_start = gettime( ); if ( check_data( data, SIZE ) != 0 ) printf( "CHECK FAILED!\n" ); else printf( "check successful.\n" ); t_stop = gettime( ); t_check = calc_timediff_ms( t_start, t_stop ); printf( "\nRunning times (size: %d words):\n" "\tGenerate data: %d ms\n" "\tSort data : %d ms\n" "\tMerge data : %d ms\n" "\tCheck data : %d ms\n" "\nTotal computation time (sort & merge): %d ms\n", SIZE, t_gen, t_sort, t_merge, t_check, t_sort + t_merge ); return 0; }
int main() { // send message queue char *send_buf; char *recv_buf; size_t len = 4; unsigned int prio = 1; int n = 0; struct mq_attr hw_sw_attr; struct mq_attr sw_hw_attr; mqd_t mqd_hw_sw; mqd_t mqd_sw_hw; hw_sw_attr.mq_flags = 0; hw_sw_attr.mq_maxmsg = 10; hw_sw_attr.mq_msgsize = len; hw_sw_attr.mq_curmsgs = 0; sw_hw_attr.mq_flags = 0; sw_hw_attr.mq_maxmsg = 10; sw_hw_attr.mq_msgsize = len; sw_hw_attr.mq_curmsgs = 0; if ((mqd_hw_sw = mq_open("/hw_sw", O_RDWR|O_CREAT, 777, &hw_sw_attr)) < 0) perror("open hw_sw"); if ((mqd_sw_hw = mq_open("/sw_hw", O_RDWR|O_CREAT, 777, &sw_hw_attr)) < 0) perror("open sw_hw"); send_buf = malloc(1024); recv_buf = malloc(1024); memset(send_buf, 0, 1024); memset(recv_buf, 0, 1024); rthread_attr_t rcv_attr; rthread_attr_init(&rcv_attr); reconos_res_t res[2] = {{&mqd_sw_hw,PTHREAD_MQD_T }, {&mqd_hw_sw,PTHREAD_MQD_T }}; rthread_attr_init(&rcv_attr); rthread_attr_setslotnum(&rcv_attr, 0); rthread_attr_setresources(&rcv_attr, res, 2); rthread_t mythread; rthread_create( &mythread, &rcv_attr, NULL); if (mq_send(mqd_sw_hw, &send_buf, len, prio) < 0) perror("mq_send"); fprintf(stderr, "--------------->message sent, ptr = %i\n", send_buf); if (mq_send(mqd_sw_hw, &recv_buf, len, prio) < 0) perror("mq_send"); fprintf(stderr, "--------------->message sent, ptr = %i\n", recv_buf); int msglen = 12; memcpy(send_buf, "hello world", msglen); if (mq_send(mqd_sw_hw, &msglen, len, prio) < 0) perror("mq_send"); fprintf(stderr, "--------------->message sent, ptr = %i\n", recv_buf); if ((n = mq_receive(mqd_hw_sw, &msglen, len, &prio)) < 0) perror("my_receive"); fprintf(stderr, "--------------->message received \n"); fprintf(stderr, "------------------> new message is %d bytes long \n", msglen); fprintf(stderr, "memory at location \"recv_buf\" %s\n", recv_buf); fprintf(stderr, "memory at location \"recv_buf + 16\" %s\n", recv_buf + 16); sleep(10); return 1; }