int main(int argc, char *argv[]) { //Manipulate cpu set and create a hardwall cpu_set_t set; tmc_cpus_clear(&set); tmc_cpus_add_cpu(&set,0); tmc_cpus_add_cpu(&set,35); tmc_udn_init(&set); //Initialize init(argc,argv); display_state(); //Create threads int count; for(count=0; count<nthreads; count++) pthread_create(&threads[count],NULL,thread_fn,(void*)(&thread_id[count])); void *retval; for(count=0; count<nthreads; count++) pthread_join(threads[count],&retval); finalize(); }
//------------------------------------------------------------------------------ //------------------------------Main function----------------------------------- //------------------------------------------------------------------------------ void main(int argc, char *argv[]) { /*struct timespec resolusion; clock_getres(CLOCK_THREAD_CPUTIME_ID,&resolusion); printf("Clock CLOCK_THREAD_CPUTIME_ID resolution: %d nsec\n",resolusion.tv_nsec);*/ //Manipulate cpu set and create a hardwall cpu_set_t set; tmc_cpus_clear(&set); tmc_cpus_add_cpu(&set,0); tmc_cpus_add_cpu(&set,35); tmc_udn_init(&set); void *retval; init(argc, argv); pthread_create(&master,NULL,thread_fn_master,NULL); pthread_create(&slave ,NULL,thread_fn_slave ,NULL); pthread_join(master,&retval); pthread_join(slave ,&retval); }
void ssmp_init_platf(int num_procs) { ssmp_num_ues_ = num_procs; //initialize shared memory tmc_cmem_init(0); // Reserve the UDN rectangle that surrounds our cpus. if (tmc_udn_init(&cpus) < 0) tmc_task_die("Failure in 'tmc_udn_init(0)'."); ssmp_barrier = (tmc_sync_barrier_t* ) tmc_cmem_calloc(SSMP_NUM_BARRIERS, sizeof (tmc_sync_barrier_t)); if (ssmp_barrier == NULL) { tmc_task_die("Failure in allocating mem for barriers"); } uint32_t b; for (b = 0; b < SSMP_NUM_BARRIERS; b++) { tmc_sync_barrier_init(ssmp_barrier + b, num_procs); } if (tmc_cpus_count(&cpus) < num_procs) { tmc_task_die("Insufficient cpus (%d < %d).", tmc_cpus_count(&cpus), num_procs); } tmc_task_watch_forked_children(1); }
int main(int argc, char *argv[]) { printf("MM_UDN starting benchmark.....\n"); //Manipulate cpu set and create a hardwall printf("Setting CPUs and UDN...\n"); cpu_set_t set; tmc_cpus_clear(&set); tmc_cpus_add_cpu(&set,0); tmc_cpus_add_cpu(&set,35); tmc_udn_init(&set); //Initialize init(argc,argv); #ifdef __DEBUG__ display_state(); #endif //Create threads printf("Creating worker threads....\n"); int count; for(count=0; count<nthreads; count++) pthread_create(&threads[count],NULL,thread_fn,(void*)(&thread_id[count])); //Start the watchdog thread printf("Creating watchdog thread....\n"); pthread_create(&watchdog_th,NULL,watchdog,NULL); //Wait for the worker threads to join printf("Main thread waiting to join...\n"); void *retval; for(count=0; count<nthreads; count++) pthread_join(threads[count],&retval); finalize(); }
int main(int argc, char** argv) { // Process arguments. int i = 1; while (i < argc) { // Allow "-i FILE" to override STDIN. if (i + 2 <= argc && !strcmp(argv[i], "-i")) { const char* file = argv[i+1]; if (dup2(open(file, O_RDONLY), STDIN_FILENO) < 0) { fprintf(stderr, "Could not open '%s'.\n", file); exit(1); } i += 2; } // Allow "-o FILE" to override STDOUT. else if (i + 2 <= argc && !strcmp(argv[i], "-o")) { const char* file = argv[i+1]; int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (dup2(fd, STDOUT_FILENO) < 0) { fprintf(stderr, "Could not open '%s'.\n", file); exit(1); } i += 2; } else { break; } } // Get the UDN coordinates of the BME server tile from our arguments. int server_x, server_y; if (i + 1 != argc || sscanf(argv[i], "%d,%d", &server_x, &server_y) != 2) { fprintf(stderr, "usage: linux_client [-i IN] [-o OUT] <server_x>,<server_y>\n"); exit(1); } // Create a UDN header for the server. DynamicHeader bme_server = { .bits.dest_x = server_x, .bits.dest_y = server_y }; // Bind ourselves to our current CPU, and set up a UDN hardwall // which encompasses the entire chip, so that we can communicate // with the BME server. cpu_set_t cpus; tmc_cpus_clear(&cpus); tmc_cpus_grid_add_all(&cpus); tmc_cpus_set_my_cpu(tmc_cpus_get_my_current_cpu()); if (tmc_udn_init(&cpus) != 0) { perror("UDN hardwall create failed"); exit(1); } if (tmc_udn_activate() != 0) { perror("UDN hardwall activate failed"); exit(1); } // Get one huge page of memory. tmc_alloc_t alloc = TMC_ALLOC_INIT; tmc_alloc_set_huge(&alloc); tmc_alloc_set_home(&alloc, 0); tmc_alloc_set_shared(&alloc); int mlength = 1 << 24; void* maddr = tmc_alloc_map(&alloc, mlength); if (maddr == NULL) { perror("can't mmap"); exit(1); } // Lock down that memory and get its physical address and caching // information, using the bme_mem device driver. struct bme_user_mem_desc_io user_mem_desc; struct bme_phys_mem_desc_io phys_mem_desc; int fd = open("/dev/bme/mem", O_RDWR); if (fd < 0) { perror("couldn't open /dev/bme/mem"); exit(1); } // First we find out how many pages are in the region to be locked down. // (Given our allocation above, we know we must have exactly one large page, // but this is an example of what you would do for large regions.) //user_mem_desc.user.va = maddr; user_mem_desc.user.va = (uintptr_t)maddr; // user_mem_desc.user.va = (__u64)maddr; user_mem_desc.user.len = mlength; if (ioctl(fd, BME_IOC_GET_NUM_PAGES, &user_mem_desc) != 0) { perror("BME_IOC_GET_NUM_PAGES ioctl failed"); exit(1); } // Now that we know how many pages are there, we can request that they be // locked into physical memory, and retrieve their physical address and // cache mapping information. phys_mem_desc.user.va = (uintptr_t)maddr; phys_mem_desc.user.len = mlength; phys_mem_desc.phys = (uintptr_t)malloc(sizeof(struct bme_phys_mem_desc) * user_mem_desc.num_pages); phys_mem_desc.num_pages = user_mem_desc.num_pages; if (ioctl(fd, BME_IOC_LOCK_MEMORY, &phys_mem_desc) != 0) { perror("BME_IOC_LOCK_MEMORY ioctl failed"); exit(1); } // Send the BME application a message telling it about the memory we // just locked down. Since this is an example, we're only sending one // message, for one page. DynamicHeader my_hdr = tmc_udn_header_from_cpu(tmc_cpus_get_my_cpu()); struct bme_phys_mem_desc *phys = (struct bme_phys_mem_desc *)(uintptr_t)phys_mem_desc.phys; tmc_udn_send_6(bme_server, UDN0_DEMUX_TAG, EX_MSG_MAPPING, my_hdr.word, phys->pa, phys->pa >> 32, phys->pte, phys->pte >> 32); uint32_t reply = udn0_receive(); if (reply) { fprintf(stderr, "client: got bad response %d to MAPPING message\n", reply); exit(1); } // Now read our standard input into a buffer in the shared page; send // a request to the BME tile to process that data, putting the output // elsewhere in the shared page; and then write it to standard output. char* inbuf = maddr; char* outbuf = inbuf + PROCESSING_BUFSIZE; int len; while ((len = read(STDIN_FILENO, inbuf, PROCESSING_BUFSIZE)) > 0) { // Note that our message gives the server the offsets of the input and // output buffers, rather than pointers to them. This is because the // server has not mapped in the data at the same set of virtual addresses // we're using. We could arrange this, if desired, although it required // more coordination between the client and server. tmc_udn_send_5(bme_server, UDN0_DEMUX_TAG, EX_MSG_PROCESS, my_hdr.word, 0, len, PROCESSING_BUFSIZE); reply = udn0_receive(); if (reply != len) { fprintf(stderr, "client: got bad response %d to PROCESS " "message (expected %d)\n", reply, len); exit(1); } if (write(STDOUT_FILENO, outbuf, len) != len) { perror("write"); exit(1); } } return 0; }
int main(int argc, char **argv) { /* limits */ int niter = 1; int nscambi = 100000; /* threads */ int cpu_white, cpu_black, cpu_main; int white_rank = 0, black_rank = 61; void * ch[2]; /* statistics */ struct timeval start; struct timeval end; /* 0 current, 1 sum, 2 square sum, 3 max value */ uint64_t result_test[4] = { 0, 0, 0, 0 }; double elapsed_test[4] = { 0, 0, 0, 0 }; double avg_Tscambio[4] = { 0 }; double sdev_Tscambio[4] = { 0 }; double max_Tscambio[4] = { 0 }; /* 0 results, 1 elapsed_test, 2 Tscambio, 3 avg_Tscambio, 4 sdev_Tscambio, 5 max_Tscambio */ double avg[6]; double sdev[6]; /* others */ cpu_set_t dp, udn_hardwall; int i; int retval[2]; int opt; int longopt; struct option options[] = { { "niter", required_argument, &longopt, 'n' }, { "nscambi",required_argument, &longopt, 'm' }, { "white", required_argument, &longopt, 'w' }, { "black", required_argument, &longopt, 'b' }, { NULL, 0, NULL, 0 } }; while (longopt || -1 != (opt = getopt_long(argc, argv, "n:m:w:b:", options, NULL))) { switch (opt) { case 'n': niter = atoi(optarg); break; case 'w': white_rank = atoi(optarg); break; case 'b': black_rank = atoi(optarg); break; case 'm': nscambi = atoi(optarg); break; case 0: opt=longopt; continue; } longopt =0; } signal(SIGALRM, sighand_alrm); /* defines cpus */ ERRHAND(tmc_cpus_get_dataplane_cpus(&dp)); if (tmc_cpus_count(&dp) < 3) fprintf(stderr, "[ERROR] numero di cpu dataplane disponibili non sufficiente\n"); //ERRHAND(cpu_white = tmc_cpus_find_first_cpu(&dp)); //ERRHAND(cpu_black = tmc_cpus_find_last_cpu(&dp)); ERRHAND(cpu_white = tmc_cpus_find_nth_cpu(&dp, white_rank)); ERRHAND(cpu_black = tmc_cpus_find_nth_cpu(&dp, black_rank)); ERRHAND(cpu_main = tmc_cpus_find_nth_cpu(&dp, tmc_cpus_count(&dp)-2)); /* bind this process to a dataplane cpu */ ERRHAND(tmc_cpus_set_my_cpu(cpu_main)); #if TEST_VERBOSE >= 1 printf("[INFO] main: cpu %d niter %d\n", tmc_cpus_get_my_cpu(), niter); #endif printf("main on cpu %d, white on cpu %d, black on cpu %d, " "num of test iteration %d, num of exchanges %d\n", tmc_cpus_get_my_cpu(), cpu_white, cpu_black, niter, nscambi); /* define ansd initialize udn hardwall */ tmc_cpus_clear(&udn_hardwall); ERRHAND(tmc_cpus_add_cpu(&udn_hardwall, cpu_main)); ERRHAND(tmc_cpus_add_cpu(&udn_hardwall, cpu_white)); ERRHAND(tmc_cpus_add_cpu(&udn_hardwall, cpu_black)); ERRHAND(tmc_udn_init(&dp)); /* init synchronization barriers */ ERRHAND_NZ(pthread_barrier_init(&computation_start, NULL, 2)); ERRHAND_NZ(pthread_barrier_init(&computation_end, NULL, 2)); for (i=0; i<niter; i++) { arg_t arg[2]; Tscambio[1] = 0; Tscambio[2] = 0; Tscambio[3] = 0; /* START TEST i-esimo */ ERRHAND(gettimeofday(&start, NULL)); /* set deadlock alarm */ alarm(deadlock_timeout); /* setup environment */ ERRHAND_NN(ch[0] = ch_create(CH0_IMPL)(cpu_white, cpu_black CH0_CREATE_ARGS)); ERRHAND_NN(ch[1] = ch_create(CH1_IMPL)(cpu_black, cpu_white CH1_CREATE_ARGS)); arg[0].cpu = cpu_white; arg[0].ch[0] = ch[0]; arg[0].ch[1] = ch[1]; arg[0].num_scambi = nscambi; arg[1].cpu = cpu_black; arg[1].ch[0] = ch[0]; arg[1].ch[1] = ch[1]; arg[1].num_scambi = nscambi; /* start computation */ ERRHAND_NZ(pthread_create(&thread_white, NULL, task_pingpong_white, (void *)&arg[0])); ERRHAND_NZ(pthread_create(&thread_black, NULL, task_pingpong_black, (void *)&arg[1])); /* wait end of computation */ ERRHAND_NZ(pthread_join(thread_white, (void *)retval)); ERRHAND_NZ(pthread_join(thread_black, (void *)(retval+1))); /* destroy environment */ ch_destroy(CH0_IMPL)(ch); ch_destroy(CH1_IMPL)(ch+1); /* END TEST i-esimo */ ERRHAND(gettimeofday(&end, NULL)); /* statistiche sugli scambi eseguiti nel test corrente */ calcStatistics(avg[2], sdev[2], Tscambio, nscambi); timersub(&end, &start, &start); prepareStatistics(elapsed_test, start.tv_sec*1000+start.tv_usec/(double)1000); prepareStatistics(result_test, retval[0] + retval[1]); prepareStatistics(avg_Tscambio, avg[2]); prepareStatistics(sdev_Tscambio, sdev[2]); prepareStatistics(max_Tscambio, Tscambio[3]); #if TEST_VERBOSE == 0 //fprintf(stderr, "%d:%f:%f:%f:(%f);", i, avg[2]/2, sdev[2], (double)Tscambio[3]/2, avg_Tscambio[2]); #elif TEST_VERBOSE >= 2 fprintf(stderr, printStatistics_format("Tscambio (cycles)", PRIu64) "[STAT] Tsend (cycles):\n[STAT] %f\n", printStatistics_values(avg[2], sdev[2], Tscambio), avg[2]/(double)2 ); #endif /* TEST_VERBOSE == 0 */ deadlock_continue = 0; } /* for (i=0; i<niter; i++) */ calcStatistics(avg[0], sdev[0], result_test, niter); calcStatistics(avg[1], sdev[1], elapsed_test, niter); calcStatistics(avg[3], sdev[3], avg_Tscambio, niter); calcStatistics(avg[4], sdev[4], sdev_Tscambio, niter); calcStatistics(avg[5], sdev[5], max_Tscambio, niter); /* fprintf(stderr, printStatistics_format("Tscambio avg (cycles)", "f") printStatistics_format("Tscambio sdev (cycles)", "f") "[STAT] Tscambio max (cycles):\n[STAT] %f\n", printStatistics_values(avg[3], sdev[3], avg_Tscambio), printStatistics_values(avg[4], sdev[4], sdev_Tscambio), maxmax_Tscambio ); */ /* fprintf(stderr, printStatistics_format2("Tscambio avg (cycles)", "f") printStatistics_format2("Tscambio sdev ", "f") printStatistics_format2("Tscambio max (cycles)", "f"), printStatistics_values2(avg[3], sdev[3], avg_Tscambio), printStatistics_values2(avg[4], sdev[4], sdev_Tscambio), printStatistics_values2(avg[5], sdev[5], max_Tscambio) ); Tscambio avg (cycles): 110.491957 0.258812 111.400840 Tscambio sdev : 118.790573 63.409627 306.372066 Tscambio max (cycles): 34756.240000 18675.977854 80419.000000 */ fprintf(stderr, "%-20s %-20s %-20s\n" "%-20f %-20f %-20f\n", "avg", "sdev", "max", avg[3], avg[4], avg[5]); fprintf(stderr, "\n\n" " %-20s %-20s %-20s\n" "Tscambio-avg: %-20f %-20f %-20f\n" "Tscambio-dev: %-20f %-20f %-20f\n" "Tscambio-max: %-20f %-20f %-20f\n", "avg", "sdev", "max", avg[3], avg[4], avg[5], sdev[3], sdev[4], sdev[5], avg_Tscambio[3], sdev_Tscambio[3], max_Tscambio[3] ); #if TEST_VERBOSE == 0 #else #endif /* TEST_VERBOSE == 0 */ return 0; }