/* * This function displays stats. It uses ANSI terminal codes to clear * screen when called. It is called from a single non-master * thread in the server process, when the process is run with more * than one lcore enabled. */ static void do_stats_display(struct rte_mbuf* pkt) { static uint64_t last_cycles; static uint64_t cur_pkts = 0; static uint64_t last_pkts = 0; const char clr[] = { 27, '[', '2', 'J', '\0' }; const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' }; (void)pkt; uint64_t cur_cycles = rte_get_tsc_cycles(); cur_pkts += print_delay; /* Clear screen and move to top left */ printf("%s%s", clr, topLeft); printf("Total packets: %9"PRIu64" \n", cur_pkts); printf("TX pkts per second: %9"PRIu64" \n", (cur_pkts - last_pkts) * rte_get_timer_hz() / (cur_cycles - last_cycles)); printf("Packets per group: %d\n", NUM_PKTS); last_pkts = cur_pkts; last_cycles = cur_cycles; printf("\n\n"); }
void rte_delay_us_block(unsigned int us) { const uint64_t start = rte_get_timer_cycles(); const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6; while ((rte_get_timer_cycles() - start) < ticks) rte_pause(); }
s32 time_update(void) { #if 0 //int ret = US_RET_OK; //int sec_delta = 0; //struct timeval tv; //cycles = rte_get_hpet_cycles(); cycles = rte_rdtsc(); if( (ret = gettimeofday((struct timeval*)&tv, NULL))< 0){ return ret; } sec_delta = ((tv.tv_sec - Ts.tv_sec)*1000000 + (tv.tv_usec - Ts.tv_nsec/1000))/1000; if (sec_delta > 0 ){ jiffies += sec_delta; Ts.tv_sec = tv.tv_sec; Ts.tv_nsec = tv.tv_usec*1000; } #else u64 sec_1_cnt ; u64 ms_1_cnt ; u64 us_1_cnt ; u64 t_delta; sec_1_cnt = rte_get_timer_hz(); ms_1_cnt = sec_1_cnt/1000; us_1_cnt = ms_1_cnt/1000; cycles = rte_rdtsc(); t_delta = cycles - last_1us_cycle; if(t_delta > us_1_cnt){ tv_usec += t_delta/us_1_cnt; if(Ts.tv_nsec >1000000){ Ts.tv_nsec = 0; Ts.tv_sec++; }else{ Ts.tv_nsec = tv_usec*1000; } last_1us_cycle = cycles; } t_delta = cycles - last_1ms_cycle; if(t_delta > ms_1_cnt){ jiffies += t_delta/ms_1_cnt ; last_1ms_cycle = cycles; } return US_RET_OK; #endif }
void tw_init_timer_vals(void) { one_sec = rte_get_timer_hz(); one_msec = (one_sec / 1000UL); one_usec = (one_msec / 1000UL); one_nsec = (one_usec / 1000UL); #ifdef USE_PERIODIC_TIMERS rte_timer_subsystem_init(); #endif }
static void axgbe_check_link_timeout(struct axgbe_port *pdata) { unsigned long link_timeout; unsigned long ticks; link_timeout = pdata->link_check + (AXGBE_LINK_TIMEOUT * 2 * rte_get_timer_hz()); ticks = rte_get_timer_cycles(); if (time_after(ticks, link_timeout)) axgbe_phy_config_aneg(pdata); }
/* * Updates flow info to be "active" or "expired" */ static int update_status(uint64_t elapsed_cycles, struct flow_info *data) { if (unlikely(data == NULL)) { return -1; } if ((elapsed_cycles - data->last_pkt_cycles) / rte_get_timer_hz() >= lb->expire_time) { data->is_active = 0; } else { data->is_active = 1; } return 0; }
void spdk_shutdown_nvmf_conns(void) { struct spdk_nvmf_conn *conn; int i; pthread_mutex_lock(&g_conns_mutex); for (i = 0; i < g_max_conns; i++) { conn = &g_conns_array[i]; if (!conn->is_valid) continue; SPDK_TRACELOG(SPDK_TRACE_DEBUG, "Set conn %d state to exiting\n", i); conn->state = CONN_STATE_EXITING; } pthread_mutex_unlock(&g_conns_mutex); rte_timer_init(&g_shutdown_timer); rte_timer_reset(&g_shutdown_timer, rte_get_timer_hz() / 1000, PERIODICAL, rte_get_master_lcore(), spdk_nvmf_conn_check_shutdown, NULL); }
err_t iperf_server_init(void) { int i; err_t ret = ERR_OK; sys_init(); lwip_init(); ticks_sec = rte_get_timer_hz(); /////////////////////////////////////////// ip_addr_t ipaddr, netmask, gateway; dpdkif_get_if_params(&ipaddr, &netmask, &gateway, netif.hwaddr); netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, dpdkif_init, ethernet_input)); netif_set_up(&netif); rte_eal_remote_launch (dpdkif_rx_thread_func, NULL,1); //////////////////////////////////////////// for (i = 0; i < sizeof(send_data) / sizeof(*send_data); i++) send_data[i] = i; struct tcp_pcb *pcb; pcb = tcp_new(); if (pcb == NULL) return ERR_MEM; if ((ret = tcp_bind(pcb, IP_ADDR_ANY, IPERF_SERVER_PORT)) != ERR_OK) { tcp_close(pcb); return ret; } pcb = tcp_listen(pcb); tcp_accept(pcb, accept); return ret; }
int app_init(void) { uint32_t i; char ring_name[MAX_NAME_LEN]; char pool_name[MAX_NAME_LEN]; /* init driver(s) */ if (rte_pmd_init_all() < 0) rte_exit(EXIT_FAILURE, "Cannot init PMD\n"); if (rte_eal_pci_probe() < 0) rte_exit(EXIT_FAILURE, "Cannot probe PCI\n"); if (rte_eth_dev_count() == 0) rte_exit(EXIT_FAILURE, "No Ethernet port - bye\n"); /* load configuration profile */ if (app_load_cfg_profile(cfg_profile) != 0) rte_exit(EXIT_FAILURE, "Invalid configuration profile\n"); /* Initialize each active flow */ for(i = 0; i < nb_pfc; i++) { uint32_t socket = rte_lcore_to_socket_id(qos_conf[i].rx_core); struct rte_ring *ring; rte_snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].rx_core); ring = rte_ring_lookup(ring_name); if (ring == NULL) qos_conf[i].rx_ring = rte_ring_create(ring_name, ring_conf.ring_size, socket, RING_F_SP_ENQ | RING_F_SC_DEQ); else qos_conf[i].rx_ring = ring; rte_snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].tx_core); ring = rte_ring_lookup(ring_name); if (ring == NULL) qos_conf[i].tx_ring = rte_ring_create(ring_name, ring_conf.ring_size, socket, RING_F_SP_ENQ | RING_F_SC_DEQ); else qos_conf[i].tx_ring = ring; /* create the mbuf pools for each RX Port */ rte_snprintf(pool_name, MAX_NAME_LEN, "mbuf_pool%u", i); qos_conf[i].mbuf_pool = rte_mempool_create(pool_name, mp_size, MBUF_SIZE, burst_conf.rx_burst * 4, sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, rte_eth_dev_socket_id(qos_conf[i].rx_port), 0); if (qos_conf[i].mbuf_pool == NULL) rte_exit(EXIT_FAILURE, "Cannot init mbuf pool for socket %u\n", i); app_init_port(qos_conf[i].rx_port, qos_conf[i].mbuf_pool); app_init_port(qos_conf[i].tx_port, qos_conf[i].mbuf_pool); qos_conf[i].sched_port = app_init_sched_port(qos_conf[i].tx_port, socket); } RTE_LOG(INFO, APP, "time stamp clock running at %" PRIu64 " Hz\n", rte_get_timer_hz()); RTE_LOG(INFO, APP, "Ring sizes: NIC RX = %u, Mempool = %d SW queue = %u," "NIC TX = %u\n", ring_conf.rx_size, mp_size, ring_conf.ring_size, ring_conf.tx_size); RTE_LOG(INFO, APP, "Burst sizes: RX read = %hu, RX write = %hu,\n" " Worker read/QoS enqueue = %hu,\n" " QoS dequeue = %hu, Worker write = %hu\n", burst_conf.rx_burst, burst_conf.ring_burst, burst_conf.ring_burst, burst_conf.qos_dequeue, burst_conf.tx_burst); RTE_LOG(INFO, APP, "NIC thresholds RX (p = %hhu, h = %hhu, w = %hhu)," "TX (p = %hhu, h = %hhu, w = %hhu)\n", rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh, tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh); return 0; }
uint64_t spdk_get_ticks_hz(void) { return rte_get_timer_hz(); }
int main(int argc, char **argv) { int rc; int i; rc = parse_args(argc, argv); if (rc != 0) { return rc; } rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs); if (rc < 0) { fprintf(stderr, "could not initialize dpdk\n"); return 1; } request_mempool = rte_mempool_create("nvme_request", 8192, spdk_nvme_request_size(), 128, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); if (request_mempool == NULL) { fprintf(stderr, "could not initialize request mempool\n"); return 1; } task_pool = rte_mempool_create("task_pool", 8192, sizeof(struct reset_task), 64, 0, NULL, NULL, task_ctor, NULL, SOCKET_ID_ANY, 0); g_tsc_rate = rte_get_timer_hz(); if (register_workers() != 0) { return 1; } if (register_controllers() != 0) { return 1; } if (associate_workers_with_ns() != 0) { rc = 1; goto cleanup; } printf("Initialization complete. Launching workers.\n"); for (i = 2; i >= 0; i--) { rc = run_nvme_reset_cycle(i); if (rc != 0) { goto cleanup; } } cleanup: unregister_controllers(); if (rc != 0) { fprintf(stderr, "%s: errors occured\n", argv[0]); } return rc; }
/** Clock cycles per nano second */ static uint64_t latencystat_cycles_per_ns(void) { return rte_get_timer_hz() / NS_PER_SEC; }
int perf_launch_lcores(struct evt_test *test, struct evt_options *opt, int (*worker)(void *)) { int ret, lcore_id; struct test_perf *t = evt_test_priv(test); int port_idx = 0; /* launch workers */ RTE_LCORE_FOREACH_SLAVE(lcore_id) { if (!(opt->wlcores[lcore_id])) continue; ret = rte_eal_remote_launch(worker, &t->worker[port_idx], lcore_id); if (ret) { evt_err("failed to launch worker %d", lcore_id); return ret; } port_idx++; } /* launch producers */ RTE_LCORE_FOREACH_SLAVE(lcore_id) { if (!(opt->plcores[lcore_id])) continue; ret = rte_eal_remote_launch(perf_producer_wrapper, &t->prod[port_idx], lcore_id); if (ret) { evt_err("failed to launch perf_producer %d", lcore_id); return ret; } port_idx++; } const uint64_t total_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->plcores); uint64_t dead_lock_cycles = rte_get_timer_cycles(); int64_t dead_lock_remaining = total_pkts; const uint64_t dead_lock_sample = rte_get_timer_hz() * 5; uint64_t perf_cycles = rte_get_timer_cycles(); int64_t perf_remaining = total_pkts; const uint64_t perf_sample = rte_get_timer_hz(); static float total_mpps; static uint64_t samples; const uint64_t freq_mhz = rte_get_timer_hz() / 1000000; int64_t remaining = t->outstand_pkts - processed_pkts(t); while (t->done == false) { const uint64_t new_cycles = rte_get_timer_cycles(); if ((new_cycles - perf_cycles) > perf_sample) { const uint64_t latency = total_latency(t); const uint64_t pkts = processed_pkts(t); remaining = t->outstand_pkts - pkts; float mpps = (float)(perf_remaining-remaining)/1000000; perf_remaining = remaining; perf_cycles = new_cycles; total_mpps += mpps; ++samples; if (opt->fwd_latency && pkts > 0) { printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM, mpps, total_mpps/samples, (float)(latency/pkts)/freq_mhz); } else { printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM, mpps, total_mpps/samples); } fflush(stdout); if (remaining <= 0) { t->result = EVT_TEST_SUCCESS; if (opt->prod_type == EVT_PROD_TYPE_SYNT) { t->done = true; rte_smp_wmb(); break; } } } if (new_cycles - dead_lock_cycles > dead_lock_sample && opt->prod_type == EVT_PROD_TYPE_SYNT) { remaining = t->outstand_pkts - processed_pkts(t); if (dead_lock_remaining == remaining) { rte_event_dev_dump(opt->dev_id, stdout); evt_err("No schedules for seconds, deadlock"); t->done = true; rte_smp_wmb(); break; } dead_lock_remaining = remaining; dead_lock_cycles = new_cycles; } } printf("\n"); return 0; }
static int paxos_rx_process(struct rte_mbuf *pkt, struct proposer* proposer) { int ret = 0; uint8_t l4_proto = 0; uint16_t outer_header_len; union tunnel_offload_info info = { .data = 0 }; struct udp_hdr *udp_hdr; struct paxos_hdr *paxos_hdr; struct ether_hdr *phdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *); parse_ethernet(phdr, &info, &l4_proto); if (l4_proto != IPPROTO_UDP) return -1; udp_hdr = (struct udp_hdr *)((char *)phdr + info.outer_l2_len + info.outer_l3_len); /* if UDP dst port is not either PROPOSER or LEARNER port */ if (!(udp_hdr->dst_port == rte_cpu_to_be_16(PROPOSER_PORT) || udp_hdr->dst_port == rte_cpu_to_be_16(LEARNER_PORT)) && (pkt->packet_type & RTE_PTYPE_TUNNEL_MASK) == 0) return -1; paxos_hdr = (struct paxos_hdr *)((char *)udp_hdr + sizeof(struct udp_hdr)); if (rte_get_log_level() == RTE_LOG_DEBUG) { //rte_hexdump(stdout, "udp", udp_hdr, sizeof(struct udp_hdr)); //rte_hexdump(stdout, "paxos", paxos_hdr, sizeof(struct paxos_hdr)); print_paxos_hdr(paxos_hdr); } int value_len = rte_be_to_cpu_16(paxos_hdr->value_len); struct paxos_value *v = paxos_value_new((char *)paxos_hdr->paxosval, value_len); switch(rte_be_to_cpu_16(paxos_hdr->msgtype)) { case PAXOS_PROMISE: { struct paxos_promise promise = { .iid = rte_be_to_cpu_32(paxos_hdr->inst), .ballot = rte_be_to_cpu_16(paxos_hdr->rnd), .value_ballot = rte_be_to_cpu_16(paxos_hdr->vrnd), .aid = rte_be_to_cpu_16(paxos_hdr->acptid), .value = *v }; proposer_handle_promise(proposer, &promise); break; } case PAXOS_ACCEPT: { if (first_time) { proposer_preexecute(proposer); first_time = false; } struct paxos_accept acpt = { .iid = rte_be_to_cpu_32(paxos_hdr->inst), .ballot = rte_be_to_cpu_16(paxos_hdr->rnd), .value_ballot = rte_be_to_cpu_16(paxos_hdr->vrnd), .aid = rte_be_to_cpu_16(paxos_hdr->acptid), .value = *v }; proposer_handle_accept(proposer, &acpt); break; } case PAXOS_ACCEPTED: { struct paxos_accepted ack = { .iid = rte_be_to_cpu_32(paxos_hdr->inst), .ballot = rte_be_to_cpu_16(paxos_hdr->rnd), .value_ballot = rte_be_to_cpu_16(paxos_hdr->vrnd), .aid = rte_be_to_cpu_16(paxos_hdr->acptid), .value = *v }; proposer_handle_accepted(proposer, &ack); break; } default: break; } outer_header_len = info.outer_l2_len + info.outer_l3_len + sizeof(struct udp_hdr) + sizeof(struct paxos_hdr); rte_pktmbuf_adj(pkt, outer_header_len); return ret; } static uint16_t add_timestamps(uint8_t port __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts, uint16_t nb_pkts, uint16_t max_pkts __rte_unused, void *user_param) { struct proposer* proposer = (struct proposer *)user_param; unsigned i; uint64_t now = rte_rdtsc(); for (i = 0; i < nb_pkts; i++) { pkts[i]->udata64 = now; paxos_rx_process(pkts[i], proposer); } return nb_pkts; } static inline int port_init(uint8_t port, struct rte_mempool *mbuf_pool, struct proposer* proposer) { struct rte_eth_dev_info dev_info; struct rte_eth_txconf *txconf; struct rte_eth_rxconf *rxconf; struct rte_eth_conf port_conf = port_conf_default; const uint16_t rx_rings = 1, tx_rings = 1; int retval; uint16_t q; rte_eth_dev_info_get(port, &dev_info); rxconf = &dev_info.default_rxconf; txconf = &dev_info.default_txconf; txconf->txq_flags &= PKT_TX_IPV4; txconf->txq_flags &= PKT_TX_UDP_CKSUM; if (port >= rte_eth_dev_count()) return -1; retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf); if (retval != 0) return retval; for (q = 0; q < rx_rings; q++) { retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE, rte_eth_dev_socket_id(port), rxconf, mbuf_pool); if (retval < 0) return retval; } for (q = 0; q < tx_rings; q++) { retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE, rte_eth_dev_socket_id(port), txconf); if (retval < 0) return retval; } retval = rte_eth_dev_start(port); if (retval < 0) return retval; struct ether_addr addr; rte_eth_macaddr_get(port, &addr); rte_eth_promiscuous_enable(port); rte_eth_add_rx_callback(port, 0, add_timestamps, proposer); rte_eth_add_tx_callback(port, 0, calc_latency, NULL); return 0; } static void lcore_main(uint8_t port, __rte_unused struct proposer *p) { proposer_preexecute(p); for (;;) { // Check if signal is received if (force_quit) break; struct rte_mbuf *bufs[BURST_SIZE]; const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs, BURST_SIZE); if (unlikely(nb_rx == 0)) continue; uint16_t buf; for (buf = 0; buf < nb_rx; buf++) rte_pktmbuf_free(bufs[buf]); } } static __attribute__((noreturn)) int lcore_mainloop(__attribute__((unused)) void *arg) { uint64_t prev_tsc = 0, cur_tsc, diff_tsc; unsigned lcore_id; lcore_id = rte_lcore_id(); rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_TIMER, "Starting mainloop on core %u\n", lcore_id); while(1) { cur_tsc = rte_rdtsc(); diff_tsc = cur_tsc - prev_tsc; if (diff_tsc > TIMER_RESOLUTION_CYCLES) { rte_timer_manage(); prev_tsc = cur_tsc; } } } static void report_stat(struct rte_timer *tim, __attribute((unused)) void *arg) { /* print stat */ uint32_t count = rte_atomic32_read(&stat); rte_log(RTE_LOG_INFO, RTE_LOGTYPE_USER8, "Throughput = %8u msg/s\n", count); /* reset stat */ rte_atomic32_set(&stat, 0); /* this timer is automatically reloaded until we decide to stop it */ if (force_quit) rte_timer_stop(tim); } static void check_timeout(struct rte_timer *tim, void *arg) { struct proposer* p = (struct proposer *) arg; unsigned lcore_id = rte_lcore_id(); rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_USER8, "%s() on lcore_id %i\n", __func__, lcore_id); struct paxos_message out; out.type = PAXOS_PREPARE; struct timeout_iterator* iter = proposer_timeout_iterator(p); while(timeout_iterator_prepare(iter, &out.u.prepare)) { rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_USER8, "%s Send PREPARE inst %d ballot %d\n", __func__, out.u.prepare.iid, out.u.prepare.ballot); send_paxos_message(&out); } out.type = PAXOS_ACCEPT; while(timeout_iterator_accept(iter, &out.u.accept)) { rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_USER8, "%s: Send ACCEPT inst %d ballot %d\n", __func__, out.u.prepare.iid, out.u.prepare.ballot); send_paxos_message(&out); } timeout_iterator_free(iter); /* this timer is automatically reloaded until we decide to stop it */ if (force_quit) rte_timer_stop(tim); } int main(int argc, char *argv[]) { uint8_t portid = 0; unsigned master_core, lcore_id; signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); force_quit = false; int proposer_id = 0; if (rte_get_log_level() == RTE_LOG_DEBUG) { paxos_config.verbosity = PAXOS_LOG_DEBUG; } struct proposer *proposer = proposer_new(proposer_id, NUM_ACCEPTORS); first_time = true; /* init EAL */ int ret = rte_eal_init(argc, argv); if (ret < 0) rte_exit(EXIT_FAILURE, "Error with EAL initialization\n"); /* init timer structure */ rte_timer_init(&timer); rte_timer_init(&stat_timer); /* load deliver_timer, every 1 s, on a slave lcore, reloaded automatically */ uint64_t hz = rte_get_timer_hz(); /* Call rte_timer_manage every 10ms */ TIMER_RESOLUTION_CYCLES = hz / 100; rte_log(RTE_LOG_INFO, RTE_LOGTYPE_USER1, "Clock: %"PRIu64"\n", hz); /* master core */ master_core = rte_lcore_id(); /* slave core */ lcore_id = rte_get_next_lcore(master_core, 0, 1); rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_USER1, "lcore_id: %d\n", lcore_id); rte_timer_reset(&timer, hz, PERIODICAL, lcore_id, check_timeout, proposer); /* reset timer */ rte_eal_remote_launch(lcore_mainloop, NULL, lcore_id); /* stat core */ lcore_id = rte_get_next_lcore(lcore_id , 0, 1); rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_USER1, "lcore_id: %d\n", lcore_id); rte_timer_reset(&stat_timer, hz, PERIODICAL, lcore_id, report_stat, NULL); /* init RTE timer library */ rte_timer_subsystem_init(); mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS, MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); if (mbuf_pool == NULL) rte_exit(EXIT_FAILURE, "Cannot create mbuf_pool\n"); /* reset timer */ rte_eal_remote_launch(lcore_mainloop, NULL, lcore_id); if (port_init(portid, mbuf_pool, proposer) != 0) rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8"\n", portid); lcore_main(portid, proposer); rte_log(RTE_LOG_DEBUG, RTE_LOGTYPE_USER8, "Free proposer\n"); proposer_free(proposer); return 0; }
/***************************************************************************** * main() ****************************************************************************/ int main(int argc, char **argv) { global_config_t *cfg; int ret; /* * Initialize DPDK infrastructure before we do anything else */ ret = rte_eal_init(argc, argv); if (ret < 0) rte_panic("Cannot init EAL\n"); /* * Initialize RTE timer library */ rte_timer_subsystem_init(); /* * Precalculate the number of cycles per us so we don't do it everytime. */ cycles_per_us = (rte_get_timer_hz() / 1000000); /* * Return value above to be used to scan app specific options */ argc -= ret; argv += ret; /* * General checks */ if (rte_lcore_count() < 3) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n", "WARP17 needs at least three cores!"); /* We only support at most 64 cores right now (to make parsing easier). */ if (rte_lcore_count() > (sizeof(uint64_t) * 8)) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: WARP17 supports at most %"PRIu32" cores!\n", (uint32_t)sizeof(uint64_t) * 8); if (rte_eth_dev_count() > TPG_ETH_DEV_MAX) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: WARP17 works with at most %u ports!\n", TPG_ETH_DEV_MAX); /* * Initialize various submodules */ if (!cli_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the command line interface"); if (!rpc_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the RPC server"); if (!cfg_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n", "Failed initializing default configuration!\n"); if (!cfg_handle_command_line(argc, argv)) exit(EXIT_FAILURE); /* Error reporting is handled by the function itself */ if (!trace_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the tracing module"); if (!trace_filter_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the trace filter module"); if (!mem_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed allocating required mbufs"); /* WARNING: Careful when adding code above this point. Up until ports are * initialized DPDK can't know that there might be ring interfaces that * still need to be created. Therefore any call to rte_eth_dev_count() * doesn't include them. */ if (!port_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the Ethernets ports"); if (!msg_sys_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the message queues"); if (!test_mgmt_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing test mgmt"); if (!test_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing tests"); if (!eth_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the Ethernets pkt handler"); if (!arp_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the ARP pkt handler"); if (!route_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the ROUTE module"); if (!ipv4_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the IPv4 pkt handler"); if (!tcp_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the TCP pkt handler"); if (!udp_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the UDP pkt handler"); if (!tlkp_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the Session lookup engine"); if (!tlkp_tcp_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the TCP lookup engine"); if (!tlkp_udp_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the UDP lookup engine"); if (!tsm_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the TSM module"); if (!timer_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the TCP timers module"); if (!pkt_loop_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the pkt loop"); if (!raw_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the RAW Application module"); if (!http_init()) TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n", "Failed initializing the RAW Application module"); start_cores(); /* * Process startup command file, if any. */ cfg = cfg_get_config(); if (cfg != NULL && cfg->gcfg_cmd_file) { if (!cli_run_input_file(cfg->gcfg_cmd_file)) TPG_ERROR_EXIT(EXIT_FAILURE, "Failed to run command file: %s!\n", cfg->gcfg_cmd_file); } /* * Process CLI commands, and other house keeping tasks... */ cli_interact(); tpg_exit = true; /* * Exit!!! */ rte_eal_mp_wait_lcore(); /* * Destroy the CLI. */ cli_exit(); /* * Destroy the mgmt RPC server. */ rpc_destroy(); return 0; }
int main(int argc, char **argv) { int rc; struct worker_thread *worker; rc = parse_args(argc, argv); if (rc != 0) { return rc; } ealargs[1] = sprintf_alloc("-c %s", g_core_mask ? g_core_mask : "0x1"); if (ealargs[1] == NULL) { perror("ealargs sprintf_alloc"); return 1; } rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs); free(ealargs[1]); if (rc < 0) { fprintf(stderr, "could not initialize dpdk\n"); return 1; } request_mempool = rte_mempool_create("nvme_request", 8192, nvme_request_size(), 128, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); if (request_mempool == NULL) { fprintf(stderr, "could not initialize request mempool\n"); return 1; } task_pool = rte_mempool_create("task_pool", 8192, sizeof(struct perf_task), 64, 0, NULL, NULL, task_ctor, NULL, SOCKET_ID_ANY, 0); g_tsc_rate = rte_get_timer_hz(); if (register_workers() != 0) { return 1; } if (register_aio_files(argc, argv) != 0) { return 1; } if (register_controllers() != 0) { return 1; } if (associate_workers_with_ns() != 0) { return 1; } printf("Initialization complete. Launching workers.\n"); /* Launch all of the slave workers */ worker = g_workers->next; while (worker != NULL) { rte_eal_remote_launch(work_fn, worker, worker->lcore); worker = worker->next; } rc = work_fn(g_workers); worker = g_workers->next; while (worker != NULL) { if (rte_eal_wait_lcore(worker->lcore) < 0) { rc = -1; } worker = worker->next; } print_stats(); unregister_controllers(); if (rc != 0) { fprintf(stderr, "%s: errors occured\n", argv[0]); } return rc; }
int main() { sys_sem_t sem; sys_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); sys_sem_free(&sem); /////////////////////////////////////////////////////////////////////////////////////////////////// struct netconn *conn, *newconn; err_t err; /* Create a new connection identifier. */ conn = netconn_new(NETCONN_TCP); netconn_set_noautorecved(conn, 0); tcp_nagle_disable(conn->pcb.tcp); /* Bind connection to well known port number 7. */ netconn_bind(conn, NULL, 80); /* Tell connection to go into listening mode. */ netconn_listen(conn); while (1) { /* Grab new connection. */ err = netconn_accept(conn, &newconn); printf("accepted new connection %p\n", newconn); /* Process the new connection. */ if (err == ERR_OK) { struct netbuf *buf; void *data; u16_t len; u64_t total_rcvd = 0; u64_t eal_tsc_resolution_hz = rte_get_timer_hz(); u64_t end = rte_get_timer_cycles() + eal_tsc_resolution_hz; while ((err = netconn_recv(newconn, &buf)) == ERR_OK) { netbuf_data(buf, &data, &len); if (len > 0) { total_rcvd += len; } if (rte_get_timer_cycles() >= end) { printf("%llu \n", (unsigned long long)total_rcvd); total_rcvd = 0; end = rte_get_timer_cycles() + eal_tsc_resolution_hz; } #if 0 if (err != ERR_OK) { printf("tcpecho: netconn_write: error \"%s\"\n", lwip_strerr(err)); } #endif //} while (netbuf_next(buf) >= 0); netbuf_delete(buf); } /*printf("Got EOF, looping\n");*/ /* Close connection and discard connection identifier. */ netconn_close(newconn); netconn_delete(newconn); } } while (1); }
static struct rte_ring *r; #define TEST_RING_VERIFY(exp) \ if (!(exp)) { \ printf("error at %s:%d\tcondition " #exp " failed\n", \ __func__, __LINE__); \ rte_ring_dump(r); \ return (-1); \ } #define TEST_RING_FULL_EMTPY_ITER 8 static int check_live_watermark_change(__attribute__((unused)) void *dummy) { uint64_t hz = rte_get_timer_hz(); void *obj_table[MAX_BULK]; unsigned watermark, watermark_old = 16; uint64_t cur_time, end_time; int64_t diff = 0; int i, ret; unsigned count = 4; /* init the object table */ memset(obj_table, 0, sizeof(obj_table)); end_time = rte_get_timer_cycles() + (hz * 2); /* check that bulk and watermark are 4 and 32 (respectively) */ while (diff >= 0) { /* add in ring until we reach watermark */
int main(int argc, char **argv) { uint32_t i; int32_t ret; printf("\n%s %s\n", wr_copyright_msg(), wr_powered_by()); fflush(stdout); wr_scrn_setw(1);/* Reset the window size */ /* call before the rte_eal_init() */ (void)rte_set_application_usage_hook(pktgen_usage); memset(&pktgen, 0, sizeof(pktgen)); pktgen.flags = PRINT_LABELS_FLAG; pktgen.ident = 0x1234; pktgen.nb_rxd = DEFAULT_RX_DESC; pktgen.nb_txd = DEFAULT_TX_DESC; pktgen.nb_ports_per_page = DEFAULT_PORTS_PER_PAGE; if ( (pktgen.l2p = wr_l2p_create()) == NULL) pktgen_log_panic("Unable to create l2p"); pktgen.portdesc_cnt = wr_get_portdesc(pktgen.portlist, pktgen.portdesc, RTE_MAX_ETHPORTS, 0); /* Initialize the screen and logging */ pktgen_init_log(); pktgen_cpu_init(); /* initialize EAL */ ret = rte_eal_init(argc, argv); if (ret < 0) return -1; argc -= ret; argv += ret; pktgen.hz = rte_get_timer_hz(); /* Get the starting HZ value. */ /* parse application arguments (after the EAL ones) */ ret = pktgen_parse_args(argc, argv); if (ret < 0) return -1; pktgen_init_screen((pktgen.flags & ENABLE_THEME_FLAG) ? THEME_ON : THEME_OFF); rte_delay_ms(100); /* Wait a bit for things to settle. */ wr_print_copyright(PKTGEN_APP_NAME, PKTGEN_CREATED_BY); lua_newlib_add(_lua_openlib); /* Open the Lua script handler. */ if ( (pktgen.L = lua_create_instance()) == NULL) { pktgen_log_error("Failed to open Lua pktgen support library"); return -1; } pktgen_log_info(">>> Packet Burst %d, RX Desc %d, TX Desc %d, mbufs/port %d, mbuf cache %d", DEFAULT_PKT_BURST, DEFAULT_RX_DESC, DEFAULT_TX_DESC, MAX_MBUFS_PER_PORT, MBUF_CACHE_SIZE); /* Configure and initialize the ports */ pktgen_config_ports(); pktgen_log_info(""); pktgen_log_info("=== Display processing on lcore %d", rte_lcore_id()); /* launch per-lcore init on every lcore except master and master + 1 lcores */ for (i = 0; i < RTE_MAX_LCORE; i++) { if ( (i == rte_get_master_lcore()) || !rte_lcore_is_enabled(i) ) continue; ret = rte_eal_remote_launch(pktgen_launch_one_lcore, NULL, i); if (ret != 0) pktgen_log_error("Failed to start lcore %d, return %d", i, ret); } rte_delay_ms(1000); /* Wait for the lcores to start up. */ /* Disable printing log messages of level info and below to screen, */ /* erase the screen and start updating the screen again. */ pktgen_log_set_screen_level(LOG_LEVEL_WARNING); wr_scrn_erase(pktgen.scrn->nrows); wr_logo(3, 16, PKTGEN_APP_NAME); wr_splash_screen(3, 16, PKTGEN_APP_NAME, PKTGEN_CREATED_BY); wr_scrn_resume(); pktgen_redisplay(1); rte_timer_setup(); if (pktgen.flags & ENABLE_GUI_FLAG) { if (!wr_scrn_is_paused() ) { wr_scrn_pause(); wr_scrn_cls(); wr_scrn_setw(1); wr_scrn_pos(pktgen.scrn->nrows, 1); } lua_init_socket(pktgen.L, &pktgen.thread, pktgen.hostname, pktgen.socket_port); } pktgen_cmdline_start(); execute_lua_close(pktgen.L); pktgen_stop_running(); wr_scrn_pause(); wr_scrn_setw(1); wr_scrn_printf(100, 1, "\n"); /* Put the cursor on the last row and do a newline. */ /* Wait for all of the cores to stop running and exit. */ rte_eal_mp_wait_lcore(); return 0; }