/*-----------------------------------------------------------------------------------*/ static void main_thread(void *arg) { sys_sem_t sem; LWIP_UNUSED_ARG(arg); if(sys_sem_new(&sem, 0) != ERR_OK) { LWIP_ASSERT("Failed to create semaphore", 0); } tcpip_init(tcpip_init_done, &sem); sys_sem_wait(&sem); printf("TCP/IP initialized.\n"); #if LWIP_SOCKET if(ping_flag) { sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); } #endif printf("Applications started.\n"); #ifdef MEM_PERF mem_perf_init("/tmp/memstats.client"); #endif /* MEM_PERF */ #if 0 stats_display(); #endif /* Block forever. */ sys_thread_new("pppos_rx_thread", pppos_rx_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); sys_sem_wait(&sem); }
static inline void do_vswitchd(void) { static uint64_t last_stats_display_tsc = 0; static uint64_t next_tsc = 0; uint64_t curr_tsc_local; /* handle any packets from vswitchd */ handle_request_from_vswitchd(); /* * curr_tsc is accessed by all cores but is updated here for each loop * which causes cacheline contention. By setting a defined update * period for curr_tsc of 1us this contention is removed. */ curr_tsc_local = rte_rdtsc(); if (curr_tsc_local >= next_tsc) { curr_tsc = curr_tsc_local; next_tsc = curr_tsc_local + tsc_update_period; } /* display stats every 'stats' sec */ if ((curr_tsc - last_stats_display_tsc) / cpu_freq >= stats_display_interval && stats_display_interval != 0) { last_stats_display_tsc = curr_tsc; stats_display(); } flush_clients(); flush_ports(); flush_vhost_devs(); }
static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { palClearPad(GPIOG, GPIOG_PIN6); chThdSleepMilliseconds(500); palSetPad(GPIOG, GPIOG_PIN6); chThdSleepMilliseconds(500); stats_display(); } }
static void signal_handler(int signum) { /* USR1 signal, stop testing */ if (signum == SIGUSR1) { printf("Force Stop!\n"); stop = 1; } /* USR2 signal, print stats */ if (signum == SIGUSR2) stats_display(0); }
static inline void do_vswitchd(void) { static uint64_t last_stats_display_tsc = 0; /* handle any packets from vswitchd */ handle_request_from_vswitchd(); /* display stats every 'stats' sec */ curr_tsc = rte_rdtsc(); if ((curr_tsc - last_stats_display_tsc) / cpu_freq >= stats_display_interval && stats_display_interval != 0) { last_stats_display_tsc = curr_tsc; stats_display(); } }
void net_test(void *arg) { test_param_t param = (test_param_t)arg; // int i; if (param == 0) { test_printf("Start Network Characterization - SLAVE\n"); calibrate_load(DESIRED_BACKGROUND_LOAD); } nc_slave(param); #ifdef CYGDBG_NET_TIMING_STATS show_net_times(); #endif #if LWIP_STATS_DISPLAY stats_display(); #endif cyg_test_exit(); }
static int init(void) { int cnt = 0; #ifdef LWIP_STATS int stats_cnt = 0; #endif lock_static_init(&net_lock); /* printc("netlock id %d\n", net_lock.lock_id); */ NET_LOCK_TAKE(); torlib_init(); net_conn_init(); cos_net_create_netif_thd(); init_lwip(); NET_LOCK_RELEASE(); /* Start the tcp timer */ while (1) { /* Sleep for a quarter of seconds as prescribed by lwip */ NET_LOCK_TAKE(); if (++cnt == 4) { #ifdef TEST_TIMING timing_output(); #endif } #ifdef LWIP_STATS if (++stats_cnt == 20) { stats_cnt = 0; stats_display(); } #endif tcp_tmr(); NET_LOCK_RELEASE(); timed_event_block(cos_spd_id(), 25); /* expressed in ticks currently */ /* printc("use timer to tcp debug thread here...\n"); */ cos_mpd_update(); } prints("net: Error -- returning from init!!!"); BUG(); return 0; }
void Network::Diagnostics() { platform->AppendMessage(BOTH_MESSAGE, "Network Diagnostics:\n"); uint8_t numFreeConnections = 0; ConnectionState *freeConn = freeConnections; while (freeConn != NULL) { numFreeConnections++; freeConn = freeConn->next; } platform->AppendMessage(BOTH_MESSAGE, "Free connections: %d of %d\n", numFreeConnections, numConnections); uint8_t numFreeTransactions = 0; NetworkTransaction *freeTrans = freeTransactions; while (freeTrans != NULL) { numFreeTransactions++; freeTrans = freeTrans->next; } platform->AppendMessage(BOTH_MESSAGE, "Free transactions: %d of %d\n", numFreeTransactions, networkTransactionCount); uint16_t numFreeSendBuffs = 0; SendBuffer *freeSendBuff = freeSendBuffers; while (freeSendBuff != NULL) { numFreeSendBuffs++; freeSendBuff = freeSendBuff->next; } platform->AppendMessage(BOTH_MESSAGE, "Free send buffers: %d of %d\n", numFreeSendBuffs, tcpOutputBufferCount); #if LWIP_STATS // Normally we should NOT try to display LWIP stats here, because it uses debugPrintf(), which will hang the system is no USB cable is connected. if (reprap.Debug(moduleNetwork)) { stats_display(); } #endif }
/*-----------------------------------------------------------------------------------*/ static void main_thread(void *arg) { sys_sem_t sem; #if PPP_SUPPORT sio_fd_t ppp_sio; #endif LWIP_UNUSED_ARG(arg); netif_init(); if(sys_sem_new(&sem, 0) != ERR_OK) { LWIP_ASSERT("Failed to create semaphore", 0); } tcpip_init(tcpip_init_done, &sem); sys_sem_wait(&sem); printf("TCP/IP initialized.\n"); #if LWIP_RAW /** @todo remove dependency on RAW PCB support */ if(ping_flag) { sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); } #endif printf("Applications started.\n"); #ifdef MEM_PERF mem_perf_init("/tmp/memstats.client"); #endif /* MEM_PERF */ #if 0 stats_display(); #endif /* Block forever. */ sys_sem_wait(&sem); }
// 1. Extract arguments // 2. Initialize modules // 3. Launch candy-factory threads // 4. Launch kid threads // 5. Wait for requested time // 6. Stop candy-factory threads // 7. Wait until no more candy // 8. Stop kid threads // 9. Print statistics // 10. Cleanup any allocated memory int main(int argc, char* argv[]) { //1. Extract Arguments int factories = 0, kids = 0, seconds = 0; int* array[3] = {&factories, &kids, &seconds}; if(invalid_args(argc, argv)) { printf(INVALID_ARG_ERR); exit(1); } for(int i=1; i<=ARG_COUNT; i++){ sscanf(argv[i], "%d", array[i-1]); } //2. Initialize Modules srand(time(NULL)); bbuff_init(); stats_init(factories); //3. Launch candy-factory threads pthread_t* factory_thread_IDs = malloc(factories *(sizeof(pthread_t))); launch_threads(factories, factory_thread_IDs, (void*)factory_thread); //4. Launch kid threads pthread_t* kid_thread_IDs = malloc(kids *(sizeof(pthread_t))); launch_threads(kids, kid_thread_IDs, (void*)kid_thread); //5. Wait for requested time for(int i=0; i<seconds; i++) { sleep(1); printf("Time: %ds\n", i+1); } //6. Stop candy-factory threads stop_thread = true; for(int i=0; i<factories; i++) { pthread_join(factory_thread_IDs[i], NULL); } //7. Wait until no more candy while(!bbuff_is_empty()) { sleep(1); } //8. Stop kid threads for(int i=0; i<kids; i++) { pthread_cancel(kid_thread_IDs[i]); pthread_join(kid_thread_IDs[i], NULL); } //9. Print statistics stats_display(); //10. Cleanup any allocated memory stats_cleanup(); free(factory_thread_IDs); free(kid_thread_IDs); printf("Exiting program!\n"); return 0; }
term_t cbif_stats0(proc_t *proc, term_t *regs) { stats_display(); return A_OK; }
void cmd_get(int argc, char **argv) { list *gl; int opt=GET_VERBOSE, c; char *logfile = 0; pid_t pid; struct group *grp; char *get_output = 0; int stat_thresh = gvStatsThreshold; #ifdef HAVE_REGEX int ret; char get_rx_errbuf[129]; #endif struct option longopts[] = { {"append", no_argument, 0, 'a'}, {"chmod", required_argument, 0, 'c'}, {"chgrp", required_argument, 0, '2'}, {"no-dereference", no_argument, 0, 'd'}, {"delete-after", no_argument, 0, 'D'}, {"dir-mask", required_argument, 0, '3'}, #ifdef HAVE_REGEX {"dir-rx-mask", required_argument, 0, '4'}, #endif {"interactive", no_argument, 0, 'i'}, {"skip-empty", no_argument, 0, 'e'}, {"force", no_argument, 0, 'f'}, {"force-newer", no_argument, 0, 'F'}, {"logfile", required_argument, 0, 'L'}, {"mask", required_argument, 0, 'm'}, #ifdef HAVE_REGEX {"rx-mask", required_argument, 0, 'M'}, #endif {"newer", no_argument, 0, 'n'}, {"nohup", no_argument, 0, 'H'}, {"verbose", no_argument, 0, 'v'}, {"preserve", no_argument, 0, 'p'}, {"parents", no_argument, 0, 'P'}, {"quiet", no_argument, 0, 'q'}, {"recursive", no_argument, 0, 'r'}, {"resume", no_argument, 0, 'R'}, {"skip-existing", no_argument, 0, 's'}, {"stats", optional_argument, 0, 'S'}, {"tagged", no_argument, 0, 't'}, {"type", required_argument, 0, '1'}, {"unique", no_argument, 0, 'u'}, {"output", required_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}, }; if(cmod) { mode_free(cmod); cmod = 0; } if(get_glob_mask) { free(get_glob_mask); get_glob_mask = 0; } if(get_dir_glob_mask) { free(get_dir_glob_mask); get_dir_glob_mask = 0; } #ifdef HAVE_REGEX if(get_rx_mask_set) { regfree(&get_rx_mask); get_rx_mask_set = 0; } if(get_dir_rx_mask_set) { regfree(&get_dir_rx_mask); get_dir_rx_mask_set = 0; } #endif get_skip_empty = false; optind = 0; /* force getopt() to re-initialize */ while((c=getopt_long(argc, argv, "abHc:dDeio:fFL:tnpPvqrRsuT:m:M:", longopts, 0)) != EOF) { switch(c) { case 'a': opt |= GET_APPEND; break; case 'c': cmod = mode_compile(optarg, MODE_MASK_ALL); if(cmod == NULL) { fprintf(stderr, _("Invalid mode for --chmod: %s\n"), optarg); return; } opt |= GET_CHMOD; break; case '2': /* --chgrp */ grp = getgrnam(optarg); if(grp == 0) { fprintf(stderr, _("%s is not a valid group name\n"), optarg); return; } { int i; for(i=0; grp->gr_mem && grp->gr_mem[i]; i++) { if(strcmp(gvUsername, grp->gr_mem[i]) == 0) break; } if(!grp->gr_mem[i]) { fprintf(stderr, _("you are not a member of group %s\n"), optarg); return; } } group_change = grp->gr_gid; opt |= GET_CHGRP; break; case 'D': opt |= GET_DELETE_AFTER; break; case 'd': opt |= GET_NO_DEREFERENCE; break; case 'e': opt |= GET_SKIP_EMPTY; get_skip_empty = true; break; case '3': /* --dir-mask=GLOB */ free(get_dir_glob_mask); get_dir_glob_mask = xstrdup(optarg); unquote(get_dir_glob_mask); break; #ifdef HAVE_REGEX case '4': /* --dir-rx-mask=REGEXP */ if(get_dir_rx_mask_set) { regfree(&get_dir_rx_mask); get_dir_rx_mask_set = false; } unquote(optarg); ret = regcomp(&get_dir_rx_mask, optarg, REG_EXTENDED); if(ret != 0) { regerror(ret, &get_dir_rx_mask, get_rx_errbuf, sizeof(get_rx_errbuf) - 1); ftp_err(_("Regexp '%s' failed: %s\n"), optarg, get_rx_errbuf); return; } else get_dir_rx_mask_set = true; break; #endif case 'i': opt |= GET_INTERACTIVE; break; case 'f': opt |= GET_FORCE; break; case 'F': opt |= GET_FORCE_NEWER; break; case 'm': /* --mask */ free(get_glob_mask); get_glob_mask = xstrdup(optarg); unquote(get_glob_mask); break; #ifdef HAVE_REGEX case 'M': /* --rx-mask */ if(get_rx_mask_set) { regfree(&get_rx_mask); get_rx_mask_set = false; } unquote(optarg); ret = regcomp(&get_rx_mask, optarg, REG_EXTENDED); if(ret != 0) { regerror(ret, &get_rx_mask, get_rx_errbuf, sizeof(get_rx_errbuf) - 1); ftp_err(_("Regexp '%s' failed: %s\n"), optarg, get_rx_errbuf); return; } else get_rx_mask_set = true; break; #endif case 'o': get_output = tilde_expand_home(optarg, gvLocalHomeDir); /*stripslash(get_output);*/ unquote(get_output); break; case 'v': opt |= GET_VERBOSE; break; case 'p': opt |= GET_PRESERVE; break; case 'P': opt |= GET_PARENTS; break; case 'H': opt |= GET_NOHUP; break; case 'q': opt &= ~GET_VERBOSE; break; case 'r': opt |= GET_RECURSIVE; break; case 's': opt |= GET_SKIP_EXISTING; break; case 'S': stat_thresh = optarg ? atoi(optarg) : 0; break; case 'R': opt |= GET_RESUME; break; case '1': if(strncmp(optarg, "ascii", strlen(optarg)) == 0) opt |= GET_ASCII; else if(strncmp(optarg, "binary", strlen(optarg)) == 0) opt |= GET_BINARY; else { printf(_("Invalid option argument --type=%s\n"), optarg); return; } break; case 'u': opt |= GET_UNIQUE; break; case 'L': free(logfile); logfile = xstrdup(optarg); unquote(logfile); break; case 't': opt |= GET_TAGGED; break; case 'n': opt |= GET_NEWER; break; case 'h': print_get_syntax(); return; case '?': return; } } if(optind>=argc && !test(opt, GET_TAGGED)) { minargs(optind); return; } need_connected(); need_loggedin(); gl = rglob_create(); while(optind < argc) { stripslash(argv[optind]); if(rglob_glob(gl, argv[optind], true, true, get_exclude_func) == -1) fprintf(stderr, _("%s: no matches found\n"), argv[optind]); optind++; } if(list_numitem(gl) == 0 && !test(opt, GET_TAGGED)) { rglob_destroy(gl); return; } if(test(opt, GET_TAGGED) && (!ftp->taglist || list_numitem(ftp->taglist)==0)) { printf(_("no tagged files\n")); if(list_numitem(gl) == 0) { rglob_destroy(gl); return; } } get_quit = false; get_batch = get_owbatch = get_delbatch = test(opt, GET_FORCE); if(test(opt, GET_FORCE)) opt &= ~GET_INTERACTIVE; if(get_output && !test(opt, GET_RECURSIVE) && list_numitem(gl) + (test(opt, GET_TAGGED) ? list_numitem(ftp->taglist) : 0) == 1) { /* if the argument to --output ends with a slash, we assume the * user wants the destination to be a directory */ char *e = strrchr(get_output, 0); if(e && e[-1] != '/') opt |= GET_OUTPUT_FILE; } stats_reset(gvStatsTransfer); gvInTransfer = true; gvInterrupted = false; if(test(opt, GET_NOHUP)) { int r = 0; pid = fork(); if(pid == 0) { r = transfer_init_nohup(logfile); if(r != 0) exit(0); } if(r != 0) return; if(pid == 0) { /* child process */ transfer_begin_nohup(argc, argv); if(!test(opt, GET_FORCE) && !test(opt, GET_RESUME)) opt |= GET_UNIQUE; opt |= GET_FORCE; if(list_numitem(gl)) getfiles(gl, opt, get_output); rglob_destroy(gl); if(ftp->taglist && test(opt, GET_TAGGED)) getfiles(ftp->taglist, opt, get_output); free(get_output); transfer_end_nohup(); } if(pid == -1) { perror("fork()"); return; } /* parent process */ sleep(1); printf("%d\n", pid); input_save_history(); gvars_destroy(); reset_xterm_title(); exit(0); } if(list_numitem(gl)) getfiles(gl, opt, get_output); rglob_destroy(gl); if(ftp->taglist && test(opt, GET_TAGGED)) getfiles(ftp->taglist, opt, get_output); free(get_output); mode_free(cmod); cmod = 0; gvInTransfer = false; stats_display(gvStatsTransfer, stat_thresh); }
int main(int argc, char *argv[]) { bbuff_init(); stats_init(atoi(argv[1])); int factory=0; int kid=0; int sec=0; //-----1. Extract arguments----------------- if (argc == 0){ printf("Error: Invalid input\n"); exit(1); } if (argc > 0 && argc <= 4){ factory = atoi(argv[1]); kid = atoi(argv[2]); sec = atoi(argv[3]); } if (factory <= 0 || kid <= 0 || sec <= 0){ printf("Error: Invalid input\n"); exit(1); } //-----2. Initialize modules------------------- //------3. Launch candy-factory threads----------- pthread_t factory_thread[factory]; //to hold factory threads int factory_num[factory]; //to pass factory number to factoryFunc for (int k=0; k<factory; k++){ factory_num[k] = k; } for (int i = 0; i < factory; i++) { pthread_attr_t attr; pthread_attr_init(&attr); if(pthread_create(&factory_thread[i],&attr, factoryFunc, &factory_num[i])) { printf ("Create pthread error!\n"); exit (1); } } pthread_t kid_thread[kid]; //------4. Launch kid threads------------------- for (int i = 0; i < kid; i++) { pthread_attr_t attr; pthread_attr_init(&attr); if(pthread_create(&kid_thread[i], &attr, kidFunc, NULL)) { printf ("Create pthread error!\n"); exit (1); } } //------5. Wait for requested time------------ for (int p=1; p<sec; p++){ sleep(1); printf("Time %ds\n", p); } //------6. Stop candy-factory threads----------- stop_thread = true; for (int x=0; x<factory; x++){ pthread_join(factory_thread[x], NULL); } //------7. Wait until no more candy-------------- while (bbuff_is_empty() == false){ printf("Waiting for all candy to be consumed\n"); sleep(1); } //------8. Stop kid threads---------------------- for (int i = 0; i < kid; i++) { pthread_cancel(kid_thread[i]); pthread_join(kid_thread[i], NULL); } //------9. Print statistics----------------- stats_display(); //------10. Cleanup any allocated memory--------- stats_cleanup(); return 0; }
/*-----------------------------------------------------------------------------------*/ static void main_thread(void *arg) { struct ip_addr ipaddr, netmask, gw; sys_sem_t sem; #if PPP_SUPPORT sio_fd_t ppp_sio; #endif netif_init(); sem = sys_sem_new(0); tcpip_init(tcpip_init_done, &sem); sys_sem_wait(sem); sys_sem_free(sem); printf("TCP/IP initialized.\n"); #if PPP_SUPPORT pppInit(); #if PPP_PTY_TEST ppp_sio = sio_open(2); #else ppp_sio = sio_open(0); #endif if(!ppp_sio) { perror("Error opening device: "); exit(1); } #ifdef LWIP_PPP_CHAP_TEST pppSetAuth(PPPAUTHTYPE_CHAP, "lwip", "mysecret"); #endif pppOpen(ppp_sio, pppLinkStatusCallback, NULL); #endif /* PPP_SUPPORT */ #if LWIP_DHCP { IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input); netif_set_default(&netif); dhcp_init(); dhcp_start(&netif); } #else IP4_ADDR(&gw, 192,168,0,1); IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); netif_set_default(netif_add(&netif,&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input)); netif_set_up(&netif); #endif /* Only used for testing purposes: */ /* IP4_ADDR(&gw, 193,10,66,1); IP4_ADDR(&ipaddr, 193,10,66,107); IP4_ADDR(&netmask, 255,255,252,0); netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input);*/ #if LWIP_HAVE_LOOPIF IP4_ADDR(&gw, 127,0,0,1); IP4_ADDR(&ipaddr, 127,0,0,1); IP4_ADDR(&netmask, 255,0,0,0); netif_set_default(netif_add(&loopif, &ipaddr, &netmask, &gw, NULL, loopif_init, tcpip_input)); #endif #if LWIP_TCP tcpecho_init(); shell_init(); httpd_init(); #endif #if LWIP_UDP udpecho_init(); #endif #if LWIP_RAW sys_thread_new(ping_thread, NULL, DEFAULT_THREAD_PRIO); #endif printf("Applications started.\n"); /* sys_timeout(5000, tcp_timeout, NULL);*/ #ifdef MEM_PERF mem_perf_init("/tmp/memstats.client"); #endif /* MEM_PERF */ #if 0 stats_display(); #endif /* Block for ever. */ sem = sys_sem_new(0); sys_sem_wait(sem); }