// sort thread shall behave the same as hw thread: // - get pointer to data buffer // - if valid address: sort data and post answer // - if exit command: issue thread exit os call void *sort_thread(void* data) { unsigned int ret; unsigned int dummy = 23; struct reconos_resource *res = (struct reconos_resource*) data; struct mbox *mb_start = res[0].ptr; struct mbox *mb_stop = res[1].ptr; //pthread_t self = pthread_self(); //printf("SW Thread %lu: Started with mailbox addresses %p and %p ...\n", self, mb_start, mb_stop); while ( 1 ) { ret = mbox_get(mb_start); //printf("SW Thread %lu: Got address %p from mailbox %p.\n", self, (void*)ret, mb_start); if (ret == UINT_MAX) { // printf("SW Thread %lu: Got exit command from mailbox %p.\n", self, mb_start); pthread_exit((void*)0); } else { bubblesort( (unsigned int*) ret, N); } mbox_put(mb_stop, dummy); } return (void*)0; }
int main(int argc, char ** argv) { uint32 ret = 0; assert(argc == 1); res[0].type = RECONOS_TYPE_MBOX; res[0].ptr = &mb_1; mbox_init(&mb_1,3); reconos_init_autodetect(); reconos_hwt_setresources(&hwt,res,2); reconos_hwt_setinitdata(&hwt,(void *) init_data); reconos_hwt_create(&hwt,0,NULL); ret = mbox_get(&mb_1); if (ret==init_data) printf("get_init_data: success (%X=%X)\n", init_data,ret); else printf("get_init_data: failure (%X!=%X)\n",init_data,ret); pthread_join(hwt.delegate,NULL); return 0; }
uint32_t hwt_delegate_mbox_get(struct reconos_hwt *hwt) { uint32_t handle = reconos_osif_read(hwt->osif); //printf("RECONOS DELEGATE THREAD %d: RES %d: MBOX_GET\n", hwt->slot, handle); resource_check_type(hwt, handle, RECONOS_RESOURCE_TYPE_MBOX); //printf("RECONOS DELEGATE THREAD %d: RES %d: MBOX_GET DONE: %x\n", hwt->slot, handle, data); return mbox_get(hwt->cfg->resource[handle].ptr); }
void mbox_get_data(struct mbox *mb, void* p, size_t size) { int i; uint32_t* parts = (uint32_t*)p; assert((size%sizeof(uint32_t)) == 0); for (i=0; i<size/sizeof(uint32_t); i++) { parts[i] = mbox_get(mb); } }
void SawtoothSoundComponent_HW::process(){ if (this->m_active) { m_HWTParams[2] = (uint32_t) (m_PhaseIncr * SOUNDGATES_FIXED_PT_SCALE); //(uint32_t) (m_PhaseIncr * SOUNDGATES_FIXED_PT_SCALE); mbox_put(&m_CtrlStart, SINUS_HWT_START); mbox_get(&m_CtrlStop); /* Blocks until thread ready */ memcpy(m_SoundOut_1_Port->getWriteBuffer(), &m_LocalBuffer[0], Synthesizer::config::bytesPerBlock); } else { m_SoundOut_1_Port->clearWriteBuffer(); } }
ssize_t rq_receive(rqueue *rq, uint32_t *msg, size_t size) { uint32_t *clone; ssize_t __size; clone = (uint32_t *) mbox_get((struct mbox *) rq); __size = clone[0]; if (__size == 0 || __size > size) return -ENOMEM; __builtin_memcpy(msg, &clone[1], __size); free(clone); return __size; }
void *ctrl_mmul_thread(void *data) { int i; int m; for (i = 0; i < NUM_HWT; i++) { printf("putting into mmul mbox: %x\n", (unsigned int)&matrix_ptr[3 * i]); mbox_put(&mbox_mmul_recv, (unsigned int)&matrix_ptr[3 * i]); } while (1) { m = mbox_get(&mbox_mmul_send); matrix_done_count++; m = (m - (int)&matrix_data[0][0][0]) / (4 * MATRIX_SIZE * MATRIX_SIZE); //printf("putting into mmul mbox: %x\n", (unsigned int)&matrix_ptr[m % 2]); mbox_put(&mbox_mmul_recv, (unsigned int)&matrix_ptr[m % 2]); } }
void *ctrl_sort_thread(void *data) { int i; int m; for (i = 0; i < NUM_HWT; i++) { printf("putting into sort mbox: %x\n", (unsigned int)&sort_data[i][0]); mbox_put(&mbox_sort_recv, (unsigned int)&sort_data[i][0]); } while (1) { m = mbox_get(&mbox_sort_send); sort_request_count_active--; sort_done_count++; m = (m - (int)&sort_data) / (4 * SORT_SIZE); //printf("putting into sort mbox: %x\n", (unsigned int)&sort_data[m][0]); mbox_put(&mbox_sort_recv, (unsigned int)&sort_data[m][0]); } }
// sort thread shall behave the same as hw thread: // - get pointer to data buffer // - if valid address: sort data and post answer // - if exit command: issue thread exit os call void *sort_thread(void* data) { unsigned int ret; unsigned int dummy = 23; struct reconos_resource *res = (struct reconos_resource*) data; struct mbox *mb_start = res[0].ptr; struct mbox *mb_stop = res[1].ptr; while ( 1 ) { ret = mbox_get(mb_start); if(ret == UINT_MAX){ pthread_exit((void*)0); } else { bubblesort( (unsigned int*) ret, BLOCK_WORDS); } mbox_put(mb_stop, dummy); } return NULL; }
static int __init init_reconos_test_module(void) { uint32_t ret = 0; mbox_init(&mb, 3); reconos_init_autodetect(); reconos_hwt_setresources(&hwt, &res, 1); reconos_hwt_setinitdata(&hwt, (void *) init_data); reconos_hwt_create(&hwt, 0, NULL); ret = mbox_get(&mb); if (ret == init_data) printk(KERN_INFO "[reconos-test] get_init_data: " "success (%X=%X)\n", init_data, ret); else printk(KERN_INFO "[reconos-test] get_init_data: " "failure (%X!=%X)\n", init_data, ret); printk("[reconos-test] loaded, test done\n"); return 0; }
int main(int argc, char ** argv) { int i; int ret; int hw_threads; int sw_threads; int running_threads; int buffer_size; int slice_size; unsigned int *data, *copy; timing_t t_start, t_stop; ms_t t_generate; ms_t t_sort; ms_t t_merge; ms_t t_check; if ((argc < 4) || (argc > 4)) { print_help(); exit(1); } // we have exactly 3 arguments now... hw_threads = atoi(argv[1]); sw_threads = atoi(argv[2]); // Base unit is bytes. Use macros TO_WORDS, TO_PAGES and TO_BLOCKS for conversion. buffer_size = atoi(argv[3])*PAGE_SIZE*PAGES_PER_THREAD; slice_size = PAGE_SIZE*PAGES_PER_THREAD; running_threads = hw_threads + sw_threads; //int gettimeofday(struct timeval *tv, struct timezone *tz); // init mailboxes mbox_init(&mb_start,TO_BLOCKS(buffer_size)); mbox_init(&mb_stop ,TO_BLOCKS(buffer_size)); // init reconos and communication resources reconos_init(14,15); res[0].type = RECONOS_TYPE_MBOX; res[0].ptr = &mb_start; res[1].type = RECONOS_TYPE_MBOX; res[1].ptr = &mb_stop; printf("Creating %i hw-threads: ", hw_threads); fflush(stdout); for (i = 0; i < hw_threads; i++) { printf(" %i",i); fflush(stdout); reconos_hwt_setresources(&(hwt[i]),res,2); reconos_hwt_create(&(hwt[i]),i,NULL); } printf("\n"); // init software threads printf("Creating %i sw-threads: ",sw_threads); fflush(stdout); for (i = 0; i < sw_threads; i++) { printf(" %i",i); fflush(stdout); pthread_attr_init(&swt_attr[i]); pthread_create(&swt[i], &swt_attr[i], sort_thread, (void*)res); } printf("\n"); //print_mmu_stats(); // create pages and generate data t_start = gettime(); printf("malloc page aligned ...\n"); data = malloc_page_aligned(TO_PAGES(buffer_size)); copy = malloc_page_aligned(TO_PAGES(buffer_size)); printf("generate data ...\n"); generate_data( data, TO_WORDS(buffer_size)); memcpy(copy,data,TO_WORDS(buffer_size)*4); t_stop = gettime(); t_generate = calc_timediff_ms(t_start,t_stop); // print data of first page printf("Printing of generated data skipped. \n"); //print_data(data, TO_WORDS(buffer_size)); // Start sort threads t_start = gettime(); printf("Putting %i blocks into job queue: ", TO_BLOCKS(buffer_size)); fflush(stdout); for (i=0; i<TO_BLOCKS(buffer_size); i++) { printf(" %i",i); fflush(stdout); mbox_put(&mb_start,(unsigned int)data+(i*BLOCK_SIZE)); } printf("\n"); // Wait for results printf("Waiting for %i acknowledgements: ", TO_BLOCKS(buffer_size)); fflush(stdout); for (i=0; i<TO_BLOCKS(buffer_size); i++) { printf(" %i",i); fflush(stdout); ret = mbox_get(&mb_stop); } printf("\n"); t_stop = gettime(); t_sort = calc_timediff_ms(t_start,t_stop); // merge data t_start = gettime(); printf("Merging sorted data slices...\n"); unsigned int * temp = malloc_page_aligned(TO_PAGES(buffer_size)); //printf("Data buffer at address %p \n", (void*)data); //printf("Address of temporary merge buffer: %p\n", (void*)temp); //printf("Total size of data in bytes: %i\n",buffer_size); //printf("Size of a sorting block in bytes: %i\n",BLOCK_SIZE); data = recursive_merge( data, temp, TO_WORDS(buffer_size), TO_WORDS(BLOCK_SIZE), simple_merge ); t_stop = gettime(); t_merge = calc_timediff_ms(t_start,t_stop); // check data //data[0] = 6666; // manual fault t_start = gettime(); printf("Checking sorted data: ... "); fflush(stdout); ret = check_data( data, copy, TO_WORDS(buffer_size)); if (ret >= 0) { printf("failure at word index %i\n", -ret); printf("expected 0x%08X found 0x%08X\n",copy[ret],data[ret]); printf("dumping the first 2048 words:\n"); for(i = 0; i < 2048; i++) { printf("%08X ",data[i]); if((i % 8) == 7) printf("\n"); } } else { printf("success\n"); //print_data(data, TO_WORDS(buffer_size)); } t_stop = gettime(); t_check = calc_timediff_ms(t_start,t_stop); // terminate all threads printf("Sending terminate message to %i threads:", running_threads); fflush(stdout); for (i=0; i<running_threads; i++) { printf(" %i",i); fflush(stdout); mbox_put(&mb_start,UINT_MAX); } printf("\n"); printf("Waiting for termination...\n"); for (i=0; i<hw_threads; i++) { pthread_join(hwt[i].delegate,NULL); } for (i=0; i<sw_threads; i++) { pthread_join(swt[i],NULL); } printf("\n"); print_mmu_stats(); printf( "Running times (size: %d words, %d hw-threads, %d sw-threads):\n" "\tGenerate data: %lu ms\n" "\tSort data : %lu ms\n" "\tMerge data : %lu ms\n" "\tCheck data : %lu ms\n" "Total computation time (sort & merge): %lu ms\n", TO_WORDS(buffer_size), hw_threads, sw_threads, t_generate, t_sort, t_merge, t_check, t_sort + t_merge ); //free(data); // Memory Leak on variable data!!! return 0; }
static int __init init_reconos_test_module(void) { char * shared_mem_h2s; char * shared_mem_s2h; int i, j; long unsigned jiffies_before; long unsigned jiffies_after; int len_array[13] = {64, 128, 256, 512, 1024, 1280, 1500, 3000, 6000, 9000, 15000, 30000, 50000}; printk(KERN_INFO "[reconos-interface] Init.\n"); mbox_init(&e_mb_put, 2); mbox_init(&e_mb_get, 2); mbox_init(&a_mb_put, 2); mbox_init(&a_mb_get, 2); mbox_init(&b_mb_put, 2); mbox_init(&b_mb_get, 2); mbox_init(&c_mb_put, 2); mbox_init(&c_mb_get, 2); printk(KERN_INFO "[reconos-interface] mbox_init done, starting autodetect.\n"); reconos_init_autodetect(); printk(KERN_INFO "[reconos-interface] Creating hw-thread.\n"); e_res[0].type = RECONOS_TYPE_MBOX; e_res[0].ptr = &e_mb_put; e_res[1].type = RECONOS_TYPE_MBOX; e_res[1].ptr = &e_mb_get; a_res[0].type = RECONOS_TYPE_MBOX; a_res[0].ptr = &a_mb_put; a_res[1].type = RECONOS_TYPE_MBOX; a_res[1].ptr = &a_mb_get; s_res[0].type = RECONOS_TYPE_MBOX; s_res[0].ptr = &s_mb_put; s_res[1].type = RECONOS_TYPE_MBOX; s_res[1].ptr = &s_mb_get; b_res[0].type = RECONOS_TYPE_MBOX; b_res[0].ptr = &b_mb_put; b_res[1].type = RECONOS_TYPE_MBOX; b_res[1].ptr = &b_mb_get; c_res[0].type = RECONOS_TYPE_MBOX; c_res[0].ptr = &c_mb_put; c_res[1].type = RECONOS_TYPE_MBOX; c_res[1].ptr = &c_mb_get; reconos_hwt_setresources(&e_hwt,e_res,2); reconos_hwt_create(&e_hwt,E_HWT_SLOT_NR,NULL); reconos_hwt_setresources(&a_hwt,a_res,2); reconos_hwt_create(&a_hwt,A_HWT_SLOT_NR,NULL); reconos_hwt_setresources(&b_hwt,b_res,2); reconos_hwt_create(&b_hwt,B_HWT_SLOT_NR,NULL); reconos_hwt_setresources(&c_hwt,c_res,2); reconos_hwt_create(&c_hwt,C_HWT_SLOT_NR,NULL); //setup the hw -> sw thread printk(KERN_INFO "[reconos-interface] Allocate memory\n"); shared_mem_h2s = __get_free_pages(GFP_KERNEL | __GFP_NOWARN, 4); //allocate 2² pages get_zeroed_page(GFP_KERNEL); printk(KERN_INFO "[reconos-interface] h2s memory %p\n", shared_mem_h2s); mbox_put(&b_mb_put, shared_mem_h2s); //setup the sw -> hw thread shared_mem_s2h = __get_free_pages(GFP_KERNEL | __GFP_NOWARN, 4); //allocate 2² pages get_zeroed_page(GFP_KERNEL); printk(KERN_INFO "[reconos-interface] s2h memory %p\n", shared_mem_s2h); mbox_put(&c_mb_put, shared_mem_s2h); printk(KERN_INFO "[reconos-interface] HZ= %d\n", HZ); jiffies_before = jiffies; printk(KERN_INFO "[reconos-interface] Setting up AES slot \n"); u32 config_data_start=1; u32 config_rcv=0; u32 config_data_mode=0; //"....1100"=12=mode128, mode192=13, mode256=14,15 u32 config_data_key0=0x16157e2b; // 50462976; //X"03020100" u32 config_data_key1=0xa6d2ae28; //117835012; //X"07060504" u32 config_data_key2=0x8815f7ab; //185207048; //X"0b0a0908" u32 config_data_key3=0x3c4fcf09; //252579084; //X"0f0e0d0c" u32 config_data_key4=319951120; //X"13121110" u32 config_data_key5=387323156; //X"17161514" u32 config_data_key6=454695192; //X"1b1a1918" u32 config_data_key7=522067228; //X"1f1e1d1c" u32 exit_sig=4294967295; // config_data_mode=16; //key length 128 bit, send everything to eth config_data_mode=20; //key length 128 bit, send everything to sw mbox_put(&e_mb_put, config_data_start); mbox_put(&e_mb_put, config_data_mode); mbox_put(&e_mb_put, config_data_key0); mbox_put(&e_mb_put, config_data_key1); mbox_put(&e_mb_put, config_data_key2); mbox_put(&e_mb_put, config_data_key3); mbox_put(&e_mb_put, config_data_key4); mbox_put(&e_mb_put, config_data_key5); mbox_put(&e_mb_put, config_data_key6); mbox_put(&e_mb_put, config_data_key7); config_rcv=mbox_get(&e_mb_get); printk(KERN_INFO "[reconos-interface] AES Setup done\n"); while(1){ printk(KERN_INFO "waiting for hw packets \n"); int ret = mbox_get(&b_mb_get); int i; for (i = 0; i < 100; i+=4) printk(KERN_INFO "%x %x %x %x\n", shared_mem_h2s[i], shared_mem_h2s[i+1], shared_mem_h2s[i+2], shared_mem_h2s[i+3]); printk(KERN_INFO "received packet of len %u\n", ret); mbox_put(&b_mb_put, shared_mem_h2s ); printk(KERN_INFO "setting up hash table \n"); //config eth u32 config_eth_hash_1 = 0xabababab; u32 config_eth_hash_2 = 0xabababab; u32 config_eth_idp = 0x12341234; u32 config_eth_address = 1; //global 0, local 1 -> aes mbox_put(&a_mb_put, config_eth_hash_1 ); mbox_put(&a_mb_put, config_eth_hash_2); mbox_put(&a_mb_put, config_eth_idp); mbox_put(&a_mb_put, config_eth_address); ret = mbox_get(&a_mb_get); printk(KERN_INFO "hwt_ethernet configured - 1\n"); config_eth_hash_1 = 0xabababab; config_eth_hash_2 = 0xababab01; config_eth_idp = 0x56785678; config_eth_address = 5; //global 1, local 1 -> h2s mbox_put(&a_mb_put, config_eth_hash_1 ); mbox_put(&a_mb_put, config_eth_hash_2); mbox_put(&a_mb_put, config_eth_idp); mbox_put(&a_mb_put, config_eth_address); ret = mbox_get(&a_mb_get); printk(KERN_INFO "hwt_ethernet configured - 2\n"); ret = mbox_get(&b_mb_get); for (i = 0; i < 100; i+=4) printk(KERN_INFO "%x %x %x %x\n", shared_mem_h2s[i], shared_mem_h2s[i+1], shared_mem_h2s[i+2], shared_mem_h2s[i+3]); printk(KERN_INFO "received packet of len %u\n", ret); mbox_put(&b_mb_put, shared_mem_h2s ); //config eth config_eth_hash_1 = 0xabababab; config_eth_hash_2 = 0xabababab; config_eth_idp = 0x12341234; config_eth_address = 5; //global 1, local 1 -> h2s mbox_put(&a_mb_put, config_eth_hash_1 ); mbox_put(&a_mb_put, config_eth_hash_2); mbox_put(&a_mb_put, config_eth_idp); mbox_put(&a_mb_put, config_eth_address); ret = mbox_get(&a_mb_get); printk(KERN_INFO "hwt_ethernet configured - 3\n"); } #ifdef ADD //get interrupt time mbox_put(&e_mb_put, shared_mem_s2h); /************************************** * only interrupts **************************************/ u32 data = 2147483648; int iterations = 1; jiffies_before = jiffies; for(i= data; i < data + iterations; i++){ mbox_put(&e_mb_put, i); int ret = mbox_get(&e_mb_get); jiffies_after = jiffies; // printk(KERN_INFO "put %d, ret %d\n", i, ret); } jiffies_after = jiffies; printk(KERN_INFO "[reconos-interface] only interrupts: delta (in jiffies) = %lu for %d iterations", jiffies_after - jiffies_before, iterations); /*********************************************************************** * len = 64, 128, 512, 1024, 1280, 1518, 3000, 6000, 9000, 12000, 15000 **********************************************************************/ for (j = 11; j < 13; j++){ int len = len_array[j]; printk(KERN_INFO "len = %d %p\n", len, shared_mem_s2h); memset(shared_mem_s2h, 0, 2*len); printk(KERN_INFO "len = %d\n", len); iterations = 1000000; jiffies_before = jiffies; for(i=0; i < iterations; i++){ mbox_put(&e_mb_put, len); mbox_get(&e_mb_get); } jiffies_after = jiffies; int ret = memcmp(shared_mem_s2h, shared_mem_s2h+len, len); if (ret == 0) printk(KERN_INFO "copy success\n"); else printk(KERN_INFO " copy failed\n"); printk(KERN_INFO "[reconos-interface] len = %d: delta = %lu", len, jiffies_after - jiffies_before); } //#endif /**************************************** * Reconfigure ETH to send data to dummy ****************************************/ u32 config_data = 1; //global=0, local=1 mbox_put(&a_mb_put, config_data); #endif #ifdef SW_APP // for(i = 0; i < 10000; i++) { for (j = 0; j < 7; j++){ int packet_len = len_array[j]; int iterations = 100000; int j = 0; int result = 0; memset(shared_mem_s2h, 0, 2 * packet_len); /************************************ * send packet to hardware ************************************/ copy_packet(packet_len, 1, shared_mem_s2h, 1, 0); jiffies_before = jiffies; for(i = 0; i < iterations; i++){ mbox_put(&c_mb_put, packet_len + 12); result = mbox_get(&c_mb_get); } jiffies_after = jiffies; printk(KERN_INFO "[reconos-interface] iterations = %d len = %d: delta = %lu", iterations, packet_len, jiffies_after - jiffies_before); } } #endif #ifdef old /************************************ * send packet to hardware ************************************/ copy_packet(packet_len, 2, shared_mem_s2h, 1, 1); struct noc_pkt * snd_pkt = (struct noc_pkt *)shared_mem_s2h; mbox_put(&c_mb_put, packet_len); //printk(KERN_INFO "[reconos-interface] packet sent to hw\n"); result = mbox_get(&c_mb_get); printk(KERN_INFO "[reconos-interface] packet sent received ack from hw, total packet len %d \n", result); /************************************ * receive packet from hardware ************************************/ //printk(KERN_INFO "[reconos-interface] wait for packet from hw\n"); result = mbox_get(&b_mb_get); struct noc_pkt * rcv_pkt = (struct noc_pkt *)shared_mem_h2s; // packet_len = *(int *)shared_mem_h2s; printk(KERN_INFO "[reconos-interface] packet received with len from mbox %d, from memory %d\n", result, rcv_pkt->payload_len); printk(KERN_INFO "packet sent\n"); print_packet(snd_pkt); printk(KERN_INFO "packet received\n"); print_packet(rcv_pkt); for (j = 0; j < packet_len + 12; j++){ unsigned char written_val = shared_mem_s2h[j]; unsigned char read_val = shared_mem_h2s[j]; printk(KERN_INFO "%x %x", written_val, read_val); if ((j + 1) % 8 == 0){ printk(KERN_INFO " "); } if ((j + 1) % 16 == 0){ printk(KERN_INFO "\n"); } } printk(KERN_INFO "\n"); mbox_put(&b_mb_put, shared_mem_h2s); //dummy_value. it will be the amount of data read in a ring buffer scenario /********************************************** * send packet to hardware (s2h -> ADD -> eth) **********************************************/ copy_packet(packet_len, 3, shared_mem_s2h, 0, 1); mbox_put(&c_mb_put, packet_len); //printk(KERN_INFO "[reconos-interface] packet sent to hw\n"); result = mbox_get(&c_mb_get); printk(KERN_INFO "[reconos-interface] packet sent received ack from hw, total packet len %d \n", result); /*************************************** * reconfigure ADD to send packet to SW ***************************************/ u32 config_data = 5; //global=1, local=1 mbox_put(&e_mb_put, config_data); config_data = mbox_get(&e_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); config_data = mbox_get(&e_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); config_data = mbox_get(&e_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); config_data = mbox_get(&e_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); config_data = mbox_get(&e_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); /********************************************** * send packet to hardware (s2h -> ADD -> h2s) **********************************************/ copy_packet(packet_len, 4, shared_mem_s2h, 0, 1); mbox_put(&c_mb_put, packet_len); //printk(KERN_INFO "[reconos-interface] packet sent to hw\n"); result = mbox_get(&c_mb_get); printk(KERN_INFO "[reconos-interface] packet sent received ack from hw, total packet len %d \n", result); /************************************ * receive packet from hardware (ADD) ************************************/ //printk(KERN_INFO "[reconos-interface] wait for packet from hw\n"); result = mbox_get(&b_mb_get); rcv_pkt = (struct noc_pkt *)shared_mem_h2s; // packet_len = *(int *)shared_mem_h2s; printk(KERN_INFO "[reconos-interface] packet received with len from mbox %d, from memory %d\n", result, rcv_pkt->payload_len); printk(KERN_INFO "packet sent\n"); print_packet(snd_pkt); printk(KERN_INFO "packet received\n"); print_packet(rcv_pkt); for (j = 0; j < packet_len + 12; j++){ unsigned char written_val = shared_mem_s2h[j]; unsigned char read_val = shared_mem_h2s[j]; printk(KERN_INFO "%x %x", written_val, read_val); if ((j + 1) % 8 == 0){ printk(KERN_INFO " "); } if ((j + 1) % 16 == 0){ printk(KERN_INFO "\n"); } } printk(KERN_INFO "\n"); mbox_put(&b_mb_put, shared_mem_h2s); //dummy_value. it will be the amount of data read in a ring buffer scenario /************************************ * receive packet from hardware (ETH -> h2s) ************************************/ //printk(KERN_INFO "[reconos-interface] wait for packet from hw\n"); result = mbox_get(&b_mb_get); rcv_pkt = (struct noc_pkt *)shared_mem_h2s; // packet_len = *(int *)shared_mem_h2s; printk(KERN_INFO "[reconos-interface] packet received with len from mbox %d, from memory %d\n", result, rcv_pkt->payload_len); printk(KERN_INFO "packet sent\n"); print_packet(snd_pkt); printk(KERN_INFO "packet received\n"); print_packet(rcv_pkt); for (j = 0; j < packet_len + 12; j++){ unsigned char written_val = shared_mem_s2h[j]; unsigned char read_val = shared_mem_h2s[j]; printk(KERN_INFO "%x %x", written_val, read_val); if ((j + 1) % 8 == 0){ printk(KERN_INFO " "); } if ((j + 1) % 16 == 0){ printk(KERN_INFO "\n"); } } printk(KERN_INFO "\n"); mbox_put(&b_mb_put, shared_mem_h2s); //dummy_value. it will be the amount of data read in a ring buffer scenario /***************************************** * Reconfigure ETH to send packets to ADD *****************************************/ struct config_data config; config.dst_idp = 170; config.src_idp = 187; config.latency_critical = 1; config.direction = 0; //0 = ingress config.priority = 1; config.global_addr = 0; config.local_addr = 1; mbox_put(&a_mb_put, config_data); config_data = mbox_get(&a_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); config_data = mbox_get(&a_mb_get); printk(KERN_INFO "ADD replies : %d\n", config_data); /************************************ * receive packet from hardware (ETH -> ADD -> h2s) ************************************/ //printk(KERN_INFO "[reconos-interface] wait for packet from hw\n"); result = mbox_get(&b_mb_get); rcv_pkt = (struct noc_pkt *)shared_mem_h2s; // packet_len = *(int *)shared_mem_h2s; printk(KERN_INFO "[reconos-interface] packet received with len from mbox %d, from memory %d\n", result, rcv_pkt->payload_len); printk(KERN_INFO "packet sent\n"); print_packet(snd_pkt); printk(KERN_INFO "packet received\n"); print_packet(rcv_pkt); for (j = 0; j < packet_len + 12; j++){ unsigned char written_val = shared_mem_s2h[j]; unsigned char read_val = shared_mem_h2s[j]; printk(KERN_INFO "%x %x", written_val, read_val); if ((j + 1) % 8 == 0){ printk(KERN_INFO " "); } if ((j + 1) % 16 == 0){ printk(KERN_INFO "\n"); } } printk(KERN_INFO "\n"); mbox_put(&b_mb_put, shared_mem_h2s); //dummy_value. it will be the amount of data read in a ring buffer scenario }
void* sort_main(void * arg) { int i; int hw_threads; int sw_threads; unsigned int *data, *copy; logging_init(); unsigned int generate_ms; unsigned int sort_ms; unsigned int merge_ms; unsigned int check_ms; hw_threads = NUM_HWTS; sw_threads = NUM_SWTS; // init mailboxes mbox_init(&mb_start,NUM_BLOCKS); mbox_init(&mb_stop ,NUM_BLOCKS); // init reconos and communication resources reconos_init(); res[0].type = RECONOS_TYPE_MBOX; res[0].ptr = &mb_start; res[1].type = RECONOS_TYPE_MBOX; res[1].ptr = &mb_stop; INFO("Creating %i hw-threads: ", hw_threads); for (i = 0; i < hw_threads; i++) { INFO(" %i",i); reconos_hwt_setresources(&(hwt[i]),res,2); reconos_hwt_create(&(hwt[i]),i,NULL); } INFO("\n"); // init software threads INFO("Creating %i sw-threads: ",sw_threads); for (i = 0; i < sw_threads; i++) { INFO(" %i",i); pthread_attr_init(&swt_attr[i]); pthread_create(&swt[i], &swt_attr[i], sort_thread, (void*)res); } INFO("\n"); // create pages and generate data generate_ms = time_ms(); INFO("malloc page aligned ...\n"); data = malloc(NUM_BLOCKS*BLOCK_WORDS*sizeof*data); copy = malloc(NUM_BLOCKS*BLOCK_WORDS*sizeof*data);; INFO("generate data ...\n"); generate_data(data,NUM_BLOCKS*BLOCK_WORDS); memcpy(copy,data,NUM_BLOCKS*BLOCK_WORDS*sizeof*data); generate_ms = time_ms() - generate_ms; // Start sort threads sort_ms = time_ms(); INFO("Putting %i blocks into job queue: ", NUM_BLOCKS); for (i = 0; i < NUM_BLOCKS; i++) { INFO(" %i",i); mbox_put(&mb_start,(unsigned int)data+(i*BLOCK_WORDS)); } // Wait for results INFO("\nWaiting for %i acknowledgements: ", NUM_BLOCKS); for (i = 0; i < NUM_BLOCKS; i++) { INFO(" %i",i); mbox_get(&mb_stop); } INFO("\n"); sort_ms = time_ms() - sort_ms; // merge data merge_ms = time_ms(); INFO("Merging sorted data slices...\n"); unsigned int * temp = malloc(NUM_BLOCKS*BLOCK_WORDS*sizeof*temp); mergesort(data,temp,BLOCK_WORDS,NUM_BLOCKS); data = temp; /* data = recursive_merge( data, temp, NUM_BLOCKS*BLOCK_WORDS, BLOCK_WORDS, simple_merge ); */ merge_ms = time_ms() - merge_ms; // check data check_ms = time_ms(); INFO("Quick check sorted data (checksum = %d): ... ",generate_checksum(copy,NUM_BLOCKS*BLOCK_WORDS)); if(quick_check_data(data,NUM_BLOCKS*BLOCK_WORDS,generate_checksum(copy,NUM_BLOCKS*BLOCK_WORDS)) != 0){ INFO("FAILURE\r\n"); } else { INFO("success\n"); } /* INFO("Checking sorted data: ... "); ret = check_data( data, copy, TO_WORDS(buffer_size)); if (ret >= 0) { INFO("failure at word index %i\n", -ret); INFO("expected 0x%08X found 0x%08X\n",copy[ret],data[ret]); INFO("dumping the first 2048 words:\n"); for(i = 0; i < 2048; i++){ INFO("%08X ",data[i]); if((i % 8) == 7) INFO("\n"); } } else { INFO("success\n"); //print_data(data, TO_WORDS(buffer_size)); } */ check_ms = time_ms() - check_ms; // terminate all threads INFO("Sending terminate message to %i threads:", hw_threads + sw_threads); for (i = 0; i < hw_threads + sw_threads; i++) { INFO(" %i",i); mbox_put(&mb_start,UINT_MAX); } INFO("\n"); INFO("Waiting for termination...\n"); for (i=0; i<hw_threads; i++) { pthread_join(hwt[i].delegate,NULL); } for (i=0; i<sw_threads; i++) { pthread_join(swt[i],NULL); } INFO("done\n"); INFO("Running times (size: %d words, %d hw-threads, %d sw-threads):\n", NUM_BLOCKS*BLOCK_WORDS, hw_threads, sw_threads); INFO("\tGenerate data: %lu ms\n",generate_ms); INFO("\tSort data : %lu ms\n",sort_ms); INFO("\tMerge data : %lu ms\n",merge_ms); INFO("\tCheck data : %lu ms\n",check_ms); INFO("Total computation time (sort & merge): %lu ms\n",sort_ms + merge_ms); //free(data); // Memory Leak on variable data!!! while(1); return NULL; }
int main(int argc, char ** argv) { int i; int hw_threads; // we have exactly 3 arguments now... hw_threads = 4; // init mailboxes mbox_init(&mb_start,MBOX_SIZE); mbox_init(&mb_stop ,MBOX_SIZE); // init reconos and communication resources reconos_init_autodetect(); res[0].type = RECONOS_TYPE_MBOX; res[0].ptr = &mb_start; res[1].type = RECONOS_TYPE_MBOX; res[1].ptr = &mb_stop; printf("Creating %i hw-threads: ", hw_threads); fflush(stdout); for (i = 0; i < hw_threads; i++) { printf(" %i",i);fflush(stdout); reconos_hwt_setresources(&(hwt[i]),res,2); reconos_hwt_create(&(hwt[i]),i,NULL); } printf("\n"); int addresses[4]; addresses[0] = 0; addresses[1] = 1; addresses[2] = 16; addresses[3] = 17; i = 0; while(1) { i = (i+1) % 4; printf("Waiting"); fflush(stdout); int j; for(j=0; j<5; j++) { printf("."); fflush(stdout); sleep(1); } printf("\n"); printf("Sending command\n"); fflush(stdout); mbox_put(&mb_start,addresses[i]); printf("Waiting for answer\n"); fflush(stdout); mbox_get(&mb_stop); printf("Answer received\n"); printf("Waiting for answer\n"); fflush(stdout); mbox_get(&mb_stop); printf("Answer received\n"); } return 0; }