static void *perf_client(void *arg) { (void) arg; #if ODP_VERSION < 106 if (odp_init_local(ODP_THREAD_CONTROL) != 0) { OFP_ERR("Error: ODP local init failed.\n"); return NULL; } #endif if (ofp_init_local()) { OFP_ERR("Error: OFP local init failed.\n"); return NULL; } ofp_set_stat_flags(OFP_STAT_COMPUTE_PERF); while (1) { struct ofp_perf_stat *ps = ofp_get_perf_statistics(); printf ("Mpps:%4.3f\n", ((float)ps->rx_fp_pps)/1000000); usleep(1000000UL); } return NULL; }
int main(int argc, char **argv) { int ret; odp_shm_t shm; if (odp_init_global(NULL, NULL) != 0) LOG_ABORT("Failed global init.\n"); if (odp_init_local() != 0) LOG_ABORT("Failed local init.\n"); shm = odp_shm_reserve("test_globals", sizeof(test_globals_t), ODP_CACHE_LINE_SIZE, 0); gbl_args = odp_shm_addr(shm); if (gbl_args == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args, 0, sizeof(test_globals_t)); parse_args(argc, argv, &gbl_args->args); ret = test_init(); if (ret == 0) { ret = run_test(); test_term(); } return ret; }
int main(int argc, char **argv) { int ret; odp_shm_t shm; int max_thrs; if (odp_init_global(NULL, NULL) != 0) LOG_ABORT("Failed global init.\n"); if (odp_init_local(ODP_THREAD_CONTROL) != 0) LOG_ABORT("Failed local init.\n"); shm = odp_shm_reserve("test_globals", sizeof(test_globals_t), ODP_CACHE_LINE_SIZE, 0); gbl_args = odp_shm_addr(shm); if (gbl_args == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args, 0, sizeof(test_globals_t)); max_thrs = odp_thread_count_max(); gbl_args->rx_stats_size = max_thrs * sizeof(pkt_rx_stats_t); gbl_args->tx_stats_size = max_thrs * sizeof(pkt_tx_stats_t); shm = odp_shm_reserve("test_globals.rx_stats", gbl_args->rx_stats_size, ODP_CACHE_LINE_SIZE, 0); gbl_args->rx_stats = odp_shm_addr(shm); if (gbl_args->rx_stats == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args->rx_stats, 0, gbl_args->rx_stats_size); shm = odp_shm_reserve("test_globals.tx_stats", gbl_args->tx_stats_size, ODP_CACHE_LINE_SIZE, 0); gbl_args->tx_stats = odp_shm_addr(shm); if (gbl_args->tx_stats == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args->tx_stats, 0, gbl_args->tx_stats_size); parse_args(argc, argv, &gbl_args->args); ret = test_init(); if (ret == 0) { ret = run_test(); test_term(); } return ret; }
int main(int argc, char *argv[]) { struct sigaction signal_action; struct rlimit rlimit; uint32_t pkts_into_tm, pkts_from_tm; odp_instance_t instance; int rc; memset(&signal_action, 0, sizeof(signal_action)); signal_action.sa_handler = signal_handler; sigfillset(&signal_action.sa_mask); sigaction(SIGILL, &signal_action, NULL); sigaction(SIGFPE, &signal_action, NULL); sigaction(SIGSEGV, &signal_action, NULL); sigaction(SIGTERM, &signal_action, NULL); sigaction(SIGBUS, &signal_action, NULL); getrlimit(RLIMIT_CORE, &rlimit); rlimit.rlim_cur = rlimit.rlim_max; setrlimit(RLIMIT_CORE, &rlimit); rc = odp_init_global(&instance, &ODP_INIT_PARAMS, NULL); if (rc != 0) { printf("Error: odp_init_global() failed, rc = %d\n", rc); abort(); } rc = odp_init_local(instance, ODP_THREAD_CONTROL); if (rc != 0) { printf("Error: odp_init_local() failed, rc = %d\n", rc); abort(); } if (process_cmd_line_options(argc, argv) < 0) return -1; create_and_config_tm(); odp_random_data(random_buf, RANDOM_BUF_LEN, 1); next_rand_byte = 0; odp_atomic_init_u32(&atomic_pkts_into_tm, 0); odp_atomic_init_u32(&atomic_pkts_from_tm, 0); traffic_generator(g_num_pkts_to_send); pkts_into_tm = odp_atomic_load_u32(&atomic_pkts_into_tm); pkts_from_tm = odp_atomic_load_u32(&atomic_pkts_from_tm); printf("pkts_into_tm=%u pkts_from_tm=%u\n", pkts_into_tm, pkts_from_tm); odp_tm_stats_print(odp_tm_test); return 0; }
static int tests_global_init(odp_instance_t *inst) { if (0 != odp_init_global(inst, NULL, NULL)) { fprintf(stderr, "error: odp_init_global() failed.\n"); return -1; } if (0 != odp_init_local(*inst, ODP_THREAD_CONTROL)) { fprintf(stderr, "error: odp_init_local() failed.\n"); return -1; } return 0; }
int main(int argc, char **argv) { (void) argc; (void) argv; test_assert_ret(odp_init_global(NULL, NULL) == 0); test_assert_ret(odp_init_local(ODP_THREAD_CONTROL) == 0); test_assert_ret(run_test() == 0); test_assert_ret(odp_term_local() == 0); test_assert_ret(odp_term_global() == 0); return 0; }
static int init_suite(void) { odp_pool_param_t pool_params; ofp_pkt_hook pkt_hook[OFP_HOOK_MAX]; odp_pool_t pool; odph_linux_thr_params_t thr_params; odp_instance_t instance; /* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); return -1; } /* Init this thread */ if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); return -1; } memset(pkt_hook, 0, sizeof(pkt_hook)); pool_params.pkt.seg_len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUFFER_SIZE; pool_params.type = ODP_POOL_PACKET; (void) ofp_init_pre_global(pool_name, &pool_params, pkt_hook, &pool, ARP_AGE_INTERVAL, ARP_ENTRY_TIMEOUT); /* * Start a packet processing thread to service timer events. */ odp_atomic_store_u32(&still_running, 1); odp_cpumask_t cpumask; odp_cpumask_zero(&cpumask); odp_cpumask_set(&cpumask, 0x1); thr_params.start = pp_thread; thr_params.arg = NULL; thr_params.thr_type = ODP_THREAD_WORKER; thr_params.instance = instance; odph_linux_pthread_create(&pp_thread_handle, &cpumask, &thr_params); return 0; }
static void *pkt_io_recv(void *arg) { odp_pktio_t pktio; odp_packet_t pkt, pkt_tbl[OFP_PKT_BURST_SIZE]; int pkt_idx, pkt_cnt; struct pktio_thr_arg *thr_args; ofp_pkt_processing_func pkt_func; thr_args = arg; pkt_func = thr_args->pkt_func; if (odp_init_local(ODP_THREAD_WORKER)) { OFP_ERR("Error: ODP local init failed.\n"); return NULL; } if (ofp_init_local()) { OFP_ERR("Error: OFP local init failed.\n"); return NULL; } pktio = ofp_port_pktio_get(thr_args->port); OFP_DBG("PKT-IO receive starting on port: %d, pktio-id: %"PRIX64"\n", thr_args->port, odp_pktio_to_u64(pktio)); while (1) { pkt_cnt = odp_pktio_recv(pktio, pkt_tbl, OFP_PKT_BURST_SIZE); for (pkt_idx = 0; pkt_idx < pkt_cnt; pkt_idx++) { pkt = pkt_tbl[pkt_idx]; if (odp_unlikely(odp_packet_has_error(pkt))) { OFP_DBG("Packet with error dropped.\n"); odp_packet_free(pkt); continue; } ofp_packet_input(pkt, ODP_QUEUE_INVALID, pkt_func); } #ifdef OFP_SEND_PKT_BURST ofp_send_pending_pkt_burst(); #endif /*OFP_SEND_PKT_BURST*/ } /* Never reached */ return NULL; }
static int init_suite(void) { odp_pool_param_t pool_params; ofp_pkt_hook pkt_hook[OFP_HOOK_MAX]; odp_instance_t instance; /* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); return -1; } /* Init this thread */ if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); return -1; } memset(pkt_hook, 0, sizeof(pkt_hook)); pool_params.pkt.seg_len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUFFER_SIZE; pool_params.type = ODP_POOL_PACKET; (void) ofp_init_pre_global("packet_pool", &pool_params, pkt_hook, &ofp_packet_pool, ARP_AGE_INTERVAL, ARP_ENTRY_TIMEOUT); ofp_arp_init_local(); init_ifnet(); ofp_arp_ipv4_insert(dst_ipaddr, dst_mac, dev); nexthop.gw = dst_ipaddr; nexthop.vlan = vlan; nexthop.port = port; return 0; }
static int init_suite(void) { odp_pool_param_t pool_params; ofp_pkt_hook pkt_hook[OFP_HOOK_MAX]; odp_pool_t pool; odp_instance_t instance; /* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); return -1; } /* Init this thread */ if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); return -1; } memset(pkt_hook, 0, sizeof(pkt_hook)); pkt_hook[OFP_HOOK_OUT_IPv4] = fastpath_hook_out_IPv4; #ifdef INET6 pkt_hook[OFP_HOOK_OUT_IPv6] = fastpath_hook_out_IPv6; #endif /* INET6 */ pool_params.pkt.seg_len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.num = SHM_PKT_POOL_NB_PKTS; pool_params.type = ODP_POOL_PACKET; (void) ofp_init_pre_global(pool_name, &pool_params, pkt_hook, &pool, ARP_AGE_INTERVAL, ARP_ENTRY_TIMEOUT); ofp_arp_init_local(); init_ifnet(); ofp_arp_ipv4_insert(tun_rem_ip, tun_rem_mac, dev); return 0; }
static void *odp_run_start_routine(void *arg) { odp_start_args_t *start_args = arg; /* ODP thread local init */ if (odp_init_local(start_args->thr_type)) { ODPH_ERR("Local init failed\n"); return NULL; } void *ret_ptr = start_args->start_routine(start_args->arg); int ret = odp_term_local(); if (ret < 0) ODPH_ERR("Local term failed\n"); else if (ret == 0 && odp_term_global()) ODPH_ERR("Global term failed\n"); return ret_ptr; }
static int init_suite(void) { odp_pool_param_t pool_params; ofp_pkt_hook pkt_hook[OFP_HOOK_MAX]; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); return -1; } /* Init this thread */ if (odp_init_local(ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); return -1; } memset(pkt_hook, 0, sizeof(pkt_hook)); pkt_hook[OFP_HOOK_LOCAL] = fastpath_local_hook; pkt_hook[OFP_HOOK_LOCAL_IPv4] = fastpath_local_IPv4_hook; pkt_hook[OFP_HOOK_LOCAL_UDPv4] = fastpath_local_UDPv4_hook; pkt_hook[OFP_HOOK_FWD_IPv4] = fastpath_ip4_forward_hook; pkt_hook[OFP_HOOK_FWD_IPv6] = fastpath_ip6_forward_hook; pkt_hook[OFP_HOOK_GRE] = fastpath_gre_hook; pool_params.pkt.seg_len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUFFER_SIZE; pool_params.type = ODP_POOL_PACKET; (void) ofp_init_pre_global("packet_pool", &pool_params, pkt_hook, &ofp_packet_pool, ARP_AGE_INTERVAL, ARP_ENTRY_TIMEOUT); ofp_arp_init_local(); ofp_ip_init(); return 0; }
int main(int argc, char *argv[]){ if(argc<2)return 1; int i,n,cpu; odp_cpumask_t cpumask; odp_init_global(NULL, NULL); odp_init_local(ODP_THREAD_CONTROL); struct iofix fix; odp_pool_t pool = open_pool("pktin_pool",1024); //fix.pktio = open_nic("mytap",pool); fix.pktio = open_nic(argv[1],pool); n = odp_cpumask_default_worker(&cpumask, MAX_WORKERS); odph_linux_pthread_create(thread_tbl, &cpumask, iot_burst,&fix,ODP_THREAD_WORKER); odph_linux_pthread_join(thread_tbl, n); return 0; }
int main(void) { static ofp_init_global_t oig; odp_instance_t instance; if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } if (ofp_init_global(instance, &oig)) { OFP_ERR("Error: OFP global init failed.\n"); exit(EXIT_FAILURE); } OFP_INFO("Init successful.\n"); return 0; }
/* * INIT */ static int init_suite(void) { odp_pool_param_t pool_params; ofp_pkt_hook pkt_hook[OFP_HOOK_MAX]; struct ofp_ifnet *dev; odp_pool_t pool; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); return -1; } /* Init this thread */ if (odp_init_local(ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); return -1; } memset(pkt_hook, 0, sizeof(pkt_hook)); pool_params.pkt.seg_len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.len = SHM_PKT_POOL_BUFFER_SIZE; pool_params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUFFER_SIZE; pool_params.type = ODP_POOL_PACKET; (void) ofp_init_pre_global("packet_pool", &pool_params, pkt_hook, &pool, ARP_AGE_INTERVAL, ARP_ENTRY_TIMEOUT); ofp_arp_init_local(); dev = ofp_get_ifnet(0, 0); dev->if_mtu = ifmtu; memcpy(dev->mac, ifmac, OFP_ETHER_ADDR_LEN); ofp_mac_to_link_local(ifmac, link_local); return 0; }
int main(int argc, char *argv[]) { odp_instance_t instance; odp_platform_init_t plat_idata; int ret; /* Parse and store the application arguments */ parse_args(argc, argv); memset(&plat_idata, 0, sizeof(odp_platform_init_t)); plat_idata.ipc_ns = ipc_name_space; if (odp_init_global(&instance, NULL, &plat_idata)) { EXAMPLE_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } /* Init this thread */ if (odp_init_local(instance, ODP_THREAD_CONTROL)) { EXAMPLE_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } ret = ipc_second_process(); if (odp_term_local()) { EXAMPLE_ERR("Error: odp_term_local() failed.\n"); exit(EXIT_FAILURE); } if (odp_term_global(instance)) { EXAMPLE_ERR("Error: odp_term_global() failed.\n"); exit(EXIT_FAILURE); } return ret; }
static int init_suite(void) { ofp_global_param_t params; odp_instance_t instance; /* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); return -1; } /* Init this thread */ if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); return -1; } ofp_init_global_param(¶ms); params.enable_nl_thread = 0; memset(params.pkt_hook, 0, sizeof(params.pkt_hook)); params.pkt_hook[OFP_HOOK_OUT_IPv4] = fastpath_hook_out_IPv4; #ifdef INET6 params.pkt_hook[OFP_HOOK_OUT_IPv6] = fastpath_hook_out_IPv6; #endif /* INET6 */ (void) ofp_init_global(instance, ¶ms); ofp_init_local(); init_ifnet(); ofp_add_mac(dev, tun_rem_ip, tun_rem_mac); return 0; }
int main(int argc, char **argv) { odph_odpthread_t thread_tbl[MAX_WORKERS]; int i, j; int cpu; int num_workers; odp_shm_t shm; odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; odp_pool_param_t params; int ret; stats_t (*stats)[MAX_PKTIOS]; int if_count; odp_instance_t instance; odph_odpthread_params_t thr_params; /* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { printf("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } /* Init this thread */ if (odp_init_local(instance, ODP_THREAD_CONTROL)) { printf("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } /* Reserve memory for args from shared mem */ shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, 0); gbl_args = odp_shm_addr(shm); if (gbl_args == NULL) { printf("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } gbl_args_init(gbl_args); for (i = 0; (unsigned)i < MAC_TBL_SIZE; i++) odp_atomic_init_u64(&gbl_args->mac_tbl[i], 0); /* Parse and store the application arguments */ parse_args(argc, argv, &gbl_args->appl); /* Print both system and application information */ print_info(NO_PATH(argv[0]), &gbl_args->appl); /* Default to system CPU count unless user specified */ num_workers = MAX_WORKERS; if (gbl_args->appl.cpu_count) num_workers = gbl_args->appl.cpu_count; /* Get default worker cpumask */ num_workers = odp_cpumask_default_worker(&cpumask, num_workers); (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); gbl_args->appl.num_workers = num_workers; if_count = gbl_args->appl.if_count; printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); /* Create packet pool */ odp_pool_param_init(¶ms); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; params.pkt.len = SHM_PKT_POOL_BUF_SIZE; params.pkt.num = SHM_PKT_POOL_SIZE; params.type = ODP_POOL_PACKET; gbl_args->pool = odp_pool_create("packet pool", ¶ms); if (gbl_args->pool == ODP_POOL_INVALID) { printf("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } odp_pool_print(gbl_args->pool); bind_workers(); for (i = 0; i < if_count; ++i) { const char *dev = gbl_args->appl.if_names[i]; int num_rx; /* An RX queue per assigned worker and a private TX queue for * each worker */ num_rx = gbl_args->pktios[i].num_rx_thr; if (create_pktio(dev, i, num_rx, num_workers, gbl_args->pool)) exit(EXIT_FAILURE); ret = odp_pktio_promisc_mode_set(gbl_args->pktios[i].pktio, 1); if (ret != 0) { printf("Error: failed to set port to promiscuous mode.\n"); exit(EXIT_FAILURE); } } gbl_args->pktios[i].pktio = ODP_PKTIO_INVALID; bind_queues(); print_port_mapping(); memset(thread_tbl, 0, sizeof(thread_tbl)); odp_barrier_init(&barrier, num_workers + 1); stats = gbl_args->stats; memset(&thr_params, 0, sizeof(thr_params)); thr_params.thr_type = ODP_THREAD_WORKER; thr_params.instance = instance; thr_params.start = run_worker; /* Create worker threads */ cpu = odp_cpumask_first(&cpumask); for (i = 0; i < num_workers; ++i) { odp_cpumask_t thd_mask; for (j = 0; j < MAX_PKTIOS; j++) gbl_args->thread[i].stats[j] = &stats[i][j]; thr_params.arg = &gbl_args->thread[i]; odp_cpumask_zero(&thd_mask); odp_cpumask_set(&thd_mask, cpu); odph_odpthreads_create(&thread_tbl[i], &thd_mask, &thr_params); cpu = odp_cpumask_next(&cpumask, cpu); } /* Start packet receive and transmit */ for (i = 0; i < if_count; ++i) { odp_pktio_t pktio; pktio = gbl_args->pktios[i].pktio; ret = odp_pktio_start(pktio); if (ret) { printf("Error: unable to start %s\n", gbl_args->appl.if_names[i]); exit(EXIT_FAILURE); } } ret = print_speed_stats(num_workers, gbl_args->stats, gbl_args->appl.time, gbl_args->appl.accuracy); exit_threads = 1; /* Master thread waits for other threads to exit */ for (i = 0; i < num_workers; ++i) odph_odpthreads_join(&thread_tbl[i]); free(gbl_args->appl.if_names); free(gbl_args->appl.if_str); if (odp_pool_destroy(gbl_args->pool)) { printf("Error: pool destroy\n"); exit(EXIT_FAILURE); } if (odp_term_local()) { printf("Error: term local\n"); exit(EXIT_FAILURE); } if (odp_term_global(instance)) { printf("Error: term global\n"); exit(EXIT_FAILURE); } printf("Exit: %d\n\n", ret); return ret; }
/** * ODP L2 forwarding main function */ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_pool_t pool; int i; int cpu; int num_workers; odp_shm_t shm; odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; odp_pool_param_t params; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { LOG_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } /* Init this thread */ if (odp_init_local(ODP_THREAD_CONTROL)) { LOG_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } /* Reserve memory for args from shared mem */ shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, 0); gbl_args = odp_shm_addr(shm); if (gbl_args == NULL) { LOG_ERR("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } memset(gbl_args, 0, sizeof(*gbl_args)); /* Parse and store the application arguments */ parse_args(argc, argv, &gbl_args->appl); /* Print both system and application information */ print_info(NO_PATH(argv[0]), &gbl_args->appl); /* Default to system CPU count unless user specified */ num_workers = MAX_WORKERS; if (gbl_args->appl.cpu_count) num_workers = gbl_args->appl.cpu_count; /* Get default worker cpumask */ num_workers = odp_cpumask_def_worker(&cpumask, num_workers); (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); if (num_workers < gbl_args->appl.if_count) { LOG_ERR("Error: CPU count %d less than interface count\n", num_workers); exit(EXIT_FAILURE); } if (gbl_args->appl.if_count % 2 != 0) { LOG_ERR("Error: interface count %d is odd in fwd appl.\n", gbl_args->appl.if_count); exit(EXIT_FAILURE); } /* Create packet pool */ memset(¶ms, 0, sizeof(params)); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; params.pkt.len = SHM_PKT_POOL_BUF_SIZE; params.pkt.num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; params.type = ODP_POOL_PACKET; pool = odp_pool_create("packet pool", ¶ms); if (pool == ODP_POOL_INVALID) { LOG_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } odp_pool_print(pool); for (i = 0; i < gbl_args->appl.if_count; ++i) { gbl_args->pktios[i] = create_pktio(gbl_args->appl.if_names[i], pool, gbl_args->appl.mode); if (gbl_args->pktios[i] == ODP_PKTIO_INVALID) exit(EXIT_FAILURE); } gbl_args->pktios[i] = ODP_PKTIO_INVALID; memset(thread_tbl, 0, sizeof(thread_tbl)); stats_t **stats = calloc(1, sizeof(stats_t) * num_workers); odp_barrier_init(&barrier, num_workers + 1); /* Create worker threads */ cpu = odp_cpumask_first(&cpumask); for (i = 0; i < num_workers; ++i) { odp_cpumask_t thd_mask; void *(*thr_run_func) (void *); if (gbl_args->appl.mode == APPL_MODE_PKT_BURST) thr_run_func = pktio_ifburst_thread; else /* APPL_MODE_PKT_QUEUE */ thr_run_func = pktio_queue_thread; gbl_args->thread[i].src_idx = i % gbl_args->appl.if_count; gbl_args->thread[i].stats = &stats[i]; odp_cpumask_zero(&thd_mask); odp_cpumask_set(&thd_mask, cpu); odph_linux_pthread_create(&thread_tbl[i], &thd_mask, thr_run_func, &gbl_args->thread[i]); cpu = odp_cpumask_next(&cpumask, cpu); } print_speed_stats(num_workers, stats, gbl_args->appl.time, gbl_args->appl.accuracy); free(stats); exit_threads = 1; /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); free(gbl_args->appl.if_names); free(gbl_args->appl.if_str); printf("Exit\n\n"); return 0; }
int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; appl_args_t params; int core_count, num_workers; odp_cpumask_t cpumask; char cpumaskstr[64]; odph_linux_thr_params_t thr_params; odp_instance_t instance; struct rlimit rlp; getrlimit(RLIMIT_CORE, &rlp); printf("RLIMIT_CORE: %ld/%ld\n", rlp.rlim_cur, rlp.rlim_max); rlp.rlim_cur = 200000000; printf("Setting to max: %d\n", setrlimit(RLIMIT_CORE, &rlp)); /* Parse and store the application arguments */ parse_args(argc, argv, ¶ms); if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } /* Print both system and application information */ print_info(NO_PATH(argv[0]), ¶ms); core_count = odp_cpu_count(); num_workers = core_count; if (params.core_count) num_workers = params.core_count; if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; /* * By default core #0 runs Linux kernel background tasks. * Start mapping thread from core #1 */ memset(&app_init_params, 0, sizeof(app_init_params)); app_init_params.linux_core_id = 0; if (core_count > 1) num_workers--; num_workers = odp_cpumask_default_worker(&cpumask, num_workers); odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("Num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); app_init_params.if_count = params.if_count; app_init_params.if_names = params.if_names; app_init_params.pkt_hook[OFP_HOOK_LOCAL] = fastpath_local_hook; if (ofp_init_global(instance, &app_init_params)) { OFP_ERR("Error: OFP global init failed.\n"); exit(EXIT_FAILURE); } memset(thread_tbl, 0, sizeof(thread_tbl)); /* Start dataplane dispatcher worker threads */ thr_params.start = default_event_dispatcher; thr_params.arg = ofp_eth_vlan_processing; thr_params.thr_type = ODP_THREAD_WORKER; thr_params.instance = instance; odph_linux_pthread_create(thread_tbl, &cpumask, &thr_params); /* other app code here.*/ /* Start CLI */ ofp_start_cli_thread(instance, app_init_params.linux_core_id, params.conf_file); sleep(2); /* webserver */ if (setup_webserver(params.root_dir, params.laddr, params.lport)) { OFP_ERR("Error: Failed to setup webserver.\n"); exit(EXIT_FAILURE); } odph_linux_pthread_join(thread_tbl, num_workers); printf("End Main()\n"); return 0; }
/** * Test main function */ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; int num_workers; odp_queue_t queue; uint64_t cycles, ns; odp_queue_param_t param; odp_pool_param_t params; odp_timer_pool_param_t tparams; odp_timer_pool_info_t tpinfo; odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; odp_shm_t shm; test_globals_t *gbls; printf("\nODP timer example starts\n"); if (odp_init_global(NULL, NULL)) { printf("ODP global init failed.\n"); return -1; } /* Init this thread. */ if (odp_init_local()) { printf("ODP local init failed.\n"); return -1; } printf("\n"); printf("ODP system info\n"); printf("---------------\n"); printf("ODP API version: %s\n", odp_version_api_str()); printf("CPU model: %s\n", odp_sys_cpu_model_str()); printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); printf("Cache line size: %i\n", odp_sys_cache_line_size()); printf("Max CPU count: %i\n", odp_cpu_count()); printf("\n"); /* Reserve memory for test_globals_t from shared mem */ shm = odp_shm_reserve("shm_test_globals", sizeof(test_globals_t), ODP_CACHE_LINE_SIZE, 0); if (ODP_SHM_INVALID == shm) { EXAMPLE_ERR("Error: shared mem reserve failed.\n"); return -1; } gbls = odp_shm_addr(shm); if (NULL == gbls) { EXAMPLE_ERR("Error: shared mem alloc failed.\n"); return -1; } memset(gbls, 0, sizeof(test_globals_t)); parse_args(argc, argv, &gbls->args); memset(thread_tbl, 0, sizeof(thread_tbl)); /* Default to system CPU count unless user specified */ num_workers = MAX_WORKERS; if (gbls->args.cpu_count) num_workers = gbls->args.cpu_count; /* * By default CPU #0 runs Linux kernel background tasks. * Start mapping thread from CPU #1 */ num_workers = odph_linux_cpumask_default(&cpumask, num_workers); (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); printf("resolution: %i usec\n", gbls->args.resolution_us); printf("min timeout: %i usec\n", gbls->args.min_us); printf("max timeout: %i usec\n", gbls->args.max_us); printf("period: %i usec\n", gbls->args.period_us); printf("timeouts: %i\n", gbls->args.tmo_count); /* * Create pool for timeouts */ params.tmo.num = NUM_TMOS; params.type = ODP_POOL_TIMEOUT; gbls->pool = odp_pool_create("msg_pool", ODP_SHM_NULL, ¶ms); if (gbls->pool == ODP_POOL_INVALID) { EXAMPLE_ERR("Pool create failed.\n"); return -1; } tparams.res_ns = gbls->args.resolution_us*ODP_TIME_USEC; tparams.min_tmo = gbls->args.min_us*ODP_TIME_USEC; tparams.max_tmo = gbls->args.max_us*ODP_TIME_USEC; tparams.num_timers = num_workers; /* One timer per worker */ tparams.priv = 0; /* Shared */ tparams.clk_src = ODP_CLOCK_CPU; gbls->tp = odp_timer_pool_create("timer_pool", &tparams); if (gbls->tp == ODP_TIMER_POOL_INVALID) { EXAMPLE_ERR("Timer pool create failed.\n"); return -1; } odp_timer_pool_start(); odp_shm_print_all(); (void)odp_timer_pool_info(gbls->tp, &tpinfo); printf("Timer pool\n"); printf("----------\n"); printf(" name: %s\n", tpinfo.name); printf(" resolution: %"PRIu64" ns\n", tpinfo.param.res_ns); printf(" min tmo: %"PRIu64" ticks\n", tpinfo.param.min_tmo); printf(" max tmo: %"PRIu64" ticks\n", tpinfo.param.max_tmo); printf("\n"); /* * Create a queue for timer test */ memset(¶m, 0, sizeof(param)); param.sched.prio = ODP_SCHED_PRIO_DEFAULT; param.sched.sync = ODP_SCHED_SYNC_NONE; param.sched.group = ODP_SCHED_GROUP_DEFAULT; queue = odp_queue_create("timer_queue", ODP_QUEUE_TYPE_SCHED, ¶m); if (queue == ODP_QUEUE_INVALID) { EXAMPLE_ERR("Timer queue create failed.\n"); return -1; } printf("CPU freq %"PRIu64" Hz\n", odp_sys_cpu_hz()); printf("Cycles vs nanoseconds:\n"); ns = 0; cycles = odp_time_ns_to_cycles(ns); printf(" %12"PRIu64" ns -> %12"PRIu64" cycles\n", ns, cycles); printf(" %12"PRIu64" cycles -> %12"PRIu64" ns\n", cycles, odp_time_cycles_to_ns(cycles)); for (ns = 1; ns <= 100*ODP_TIME_SEC; ns *= 10) { cycles = odp_time_ns_to_cycles(ns); printf(" %12"PRIu64" ns -> %12"PRIu64" cycles\n", ns, cycles); printf(" %12"PRIu64" cycles -> %12"PRIu64" ns\n", cycles, odp_time_cycles_to_ns(cycles)); } printf("\n"); /* Initialize number of timeouts to receive */ odp_atomic_init_u32(&gbls->remain, gbls->args.tmo_count * num_workers); /* Barrier to sync test case execution */ odp_barrier_init(&gbls->test_barrier, num_workers); /* Create and launch worker threads */ odph_linux_pthread_create(thread_tbl, &cpumask, run_thread, gbls); /* Wait for worker threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); printf("ODP timer test complete\n\n"); return 0; }
/** main() Application entry point * * @param argc int * @param argv[] char* * @return int * */ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; appl_args_t params; int core_count, num_workers; odp_cpumask_t cpumask; char cpumaskstr[64]; /* Parse and store the application arguments */ parse_args(argc, argv, ¶ms); /* Print both system and application information */ print_info(NO_PATH(argv[0]), ¶ms); if (odp_init_global(NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } if (odp_init_local(ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } core_count = odp_cpu_count(); num_workers = core_count; if (params.core_count) num_workers = params.core_count; if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; /* * By default core #0 runs Linux kernel background tasks. * Start mapping thread from core #1 */ memset(&app_init_params, 0, sizeof(app_init_params)); app_init_params.linux_core_id = 0; if (core_count > 1) num_workers--; num_workers = odp_cpumask_default_worker(&cpumask, num_workers); odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("Num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); app_init_params.if_count = params.if_count; app_init_params.if_names = params.if_names; app_init_params.pkt_hook[OFP_HOOK_LOCAL] = fastpath_local_hook; if (ofp_init_global(&app_init_params)) { OFP_ERR("Error: OFP global init failed.\n"); exit(EXIT_FAILURE); } memset(thread_tbl, 0, sizeof(thread_tbl)); /* Start dataplane dispatcher worker threads */ ofp_linux_pthread_create(thread_tbl, &cpumask, default_event_dispatcher, ofp_eth_vlan_processing, ODP_THREAD_CONTROL ); /* other app code here.*/ /* Start CLI */ ofp_start_cli_thread(app_init_params.linux_core_id, params.conf_file); /* sysctl test thread */ ofp_start_sysctl_thread(app_init_params.linux_core_id); odph_linux_pthread_join(thread_tbl, num_workers); printf("End Main()\n"); return 0; }
static int ofp_lib_start(void) { ofp_init_global_t app_init_params; odph_linux_pthread_t thread_tbl[32]; int ret_val, num_workers = 1; odp_cpumask_t cpumask; char cpumaskstr[64]; if (ofp_init_global_called) return EXIT_FAILURE; /* * Before any ODP API functions can be called, we must first init the ODP * globals, e.g. availale accelerators or software implementations for * shared memory, threads, pool, qeueus, sheduler, pktio, timer, crypto * and classification. */ if (odp_init_global(NULL, NULL)) { OFP_ERR("ODP global init failed."); return EXIT_FAILURE; } /* * When the gloabel ODP level init has been done, we can now issue a * local init per thread. This must also be done before any other ODP API * calls may be made. Local inits are made here for shared memory, * threads, pktio and scheduler. */ if (odp_init_local(ODP_THREAD_CONTROL) != 0) { OFP_ERR("ODP local init failed."); odp_term_global(); return EXIT_FAILURE; } /* * Initializes cpumask with CPUs available for worker threads. * Sets up to 'num' CPUs and returns the count actually set. * Use zero for all available CPUs. */ num_workers = odp_cpumask_default_worker(&cpumask, num_workers); if (odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)) < 0) { OFP_ERR("Error: Too small buffer provided to " "odp_cpumask_to_str"); odp_term_local(); odp_term_global(); return EXIT_FAILURE; } printf("Num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); /* * Now that ODP has been initalized, we can initialize OFP. This will * open a pktio instance for each interface supplied as argument by the * user. * * General configuration will be to pktio and schedluer queues here in * addition will fast path interface configuration. */ memset(&app_init_params, 0, sizeof(app_init_params)); if (ofp_init_global(&app_init_params) != 0) { OFP_ERR("OFP global init failed."); ofp_term_global(); odp_term_local(); odp_term_global(); return EXIT_FAILURE; } if (ofp_init_local() != 0) { OFP_ERR("Error: OFP local init failed."); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(); return EXIT_FAILURE; } /* * Create and launch dataplane dispatcher worker threads to be placed * according to the cpumask, thread_tbl will be populated with the * created pthread IDs. * * In this case, all threads will run the default_event_dispatcher * function with ofp_eth_vlan_processing as argument. * * If different dispatchers should run, or the same be run with differnt * input arguments, the cpumask is used to control this. */ memset(thread_tbl, 0, sizeof(thread_tbl)); ret_val = ofp_linux_pthread_create(thread_tbl, &cpumask, default_event_dispatcher, ofp_eth_vlan_processing, ODP_THREAD_CONTROL); if (ret_val != num_workers) { OFP_ERR("Error: Failed to create worker threads, " "expected %d, got %d", num_workers, ret_val); ofp_stop_processing(); odph_linux_pthread_join(thread_tbl, num_workers); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(); return EXIT_FAILURE; } ofp_ifconfig(); return EXIT_SUCCESS; }
/** main() Application entry point * * @param argc int * @param argv[] char* * @return int * */ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; appl_args_t params; int core_count, num_workers; odp_cpumask_t cpumask; char cpumaskstr[64]; /* Parse and store the application arguments */ parse_args(argc, argv, ¶ms); /* Print both system and application information */ print_info(NO_PATH(argv[0]), ¶ms); if (odp_init_global(NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } if (odp_init_local(ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } core_count = odp_cpu_count(); num_workers = core_count; if (params.core_count) num_workers = params.core_count; if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; if (core_count > 1) num_workers--; num_workers = odp_cpumask_default_worker(&cpumask, num_workers); odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("Num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); memset(&app_init_params, 0, sizeof(app_init_params)); app_init_params.linux_core_id = 0; app_init_params.if_count = params.if_count; app_init_params.if_names = params.if_names; if (ofp_init_global(&app_init_params)) { OFP_ERR("Error: OFP global init failed.\n"); exit(EXIT_FAILURE); } memset(thread_tbl, 0, sizeof(thread_tbl)); /* Start dataplane dispatcher worker threads */ ofp_linux_pthread_create(thread_tbl, &cpumask, default_event_dispatcher, ofp_eth_vlan_processing, ODP_THREAD_CONTROL ); /* other app code here.*/ /* Start CLI */ ofp_start_cli_thread(app_init_params.linux_core_id, params.conf_file); sleep(5); ofp_loglevel = OFP_LOG_INFO; config_suite_framework(app_init_params.linux_core_id); OFP_INFO("\n\nSuite: IPv4 UDP socket: create and close.\n\n"); if (!init_suite(NULL)) run_suite(create_close_udp, create_close_udp_noproto); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP socket: create and close.\n\n"); if (!init_suite(NULL)) run_suite(create_close_tcp, create_close_tcp_noproto); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP socket: create and close.\n\n"); if (!init_suite(NULL)) run_suite(create_close_udp6, create_close_udp6_noproto); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP socket: create and close.\n\n"); if (!init_suite(NULL)) run_suite(create_close_tcp6, create_close_tcp6_noproto); end_suite(); OFP_INFO("Test ended.\n"); #endif /* INET6 */ OFP_INFO("\n\nSuite: IPv4 UDP socket: bind.\n\n"); if (!init_suite(init_udp_create_socket)) run_suite(bind_ip4_local_ip, bind_ip4_any); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP socket: bind.\n\n"); if (!init_suite(init_tcp_create_socket)) run_suite(bind_ip4_local_ip, bind_ip4_any); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP socket: bind.\n\n"); if (!init_suite(init_udp6_create_socket)) run_suite(bind_ip6_local_ip, bind_ip6_any); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP socket: bind.\n\n"); if (!init_suite(init_tcp6_create_socket)) run_suite(bind_ip6_local_ip, bind_ip6_any); end_suite(); OFP_INFO("Test ended.\n"); #endif /* INET6 */ OFP_INFO("\n\nSuite: IPv4 UDP socket: shutdown.\n\n"); if (!init_suite(init_udp_create_socket)) run_suite(shutdown_socket, shutdown_socket); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP socket: shutdown (no connection).\n\n"); if (!init_suite(init_tcp_create_socket)) run_suite(shutdown_socket, shutdown_socket); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP socket: shutdown.\n\n"); if (!init_suite(init_udp6_create_socket)) run_suite(shutdown_socket, shutdown_socket); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP socket: shutdown (no connection).\n\n"); if (!init_suite(init_tcp6_create_socket)) run_suite(shutdown_socket, shutdown_socket); end_suite(); OFP_INFO("Test ended.\n"); #endif /* INET6 */ OFP_INFO("\n\nSuite: IPv4 UDP socket: connect.\n\n"); if (!init_suite(init_udp_create_socket)) run_suite(connect_udp4, connect_bind_udp4); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 UDP socket: connect + shutdown.\n\n"); if (!init_suite(init_udp_create_socket)) run_suite(connect_shutdown_udp4, connect_shutdown_bind_udp4); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP socket: connect.\n\n"); if (!init_suite(init_udp6_create_socket)) run_suite(connect_udp6, connect_bind_udp6); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP socket: connect + shutdown.\n\n"); if (!init_suite(init_udp6_create_socket)) run_suite(connect_shutdown_udp6, connect_shutdown_bind_udp6); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP socket: connect + shutdown + any.\n\n"); if (!init_suite(init_udp6_create_socket)) run_suite(connect_shutdown_udp6_any, connect_shutdown_bind_udp6_any); end_suite(); OFP_INFO("Test ended.\n"); #endif /* INET6 */ OFP_INFO("\n\nSuite: IPv4 UDP socket BIND local address: send + sendto\n\n"); if (!init_suite(init_udp_bind_local_ip)) run_suite(send_ip4_udp_local_ip, sendto_ip4_udp_local_ip); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 UDP socket bind any address: send + sendto\n\n"); if (!init_suite(init_udp_bind_any)) run_suite(send_ip4_udp_any, sendto_ip4_udp_any); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP socket BIND local address: send + sendto\n\n"); if (!init_suite(init_udp6_bind_local_ip)) run_suite(send_ip6_udp_local_ip, sendto_ip6_udp_local_ip); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP socket bind any address: send + sendto\n\n"); if (!init_suite(init_udp6_bind_any)) run_suite(send_ip6_udp_any, sendto_ip6_udp_any); end_suite(); OFP_INFO("Test ended.\n"); #endif /* INET6 */ OFP_INFO("\n\nSuite: IPv4 UDP bind local IP: sendto + recv.\n\n"); if (!init_suite(init_udp_local_ip)) run_suite(send_udp_local_ip, recv_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 UDP bind local IP: sendto + recvfrom.\n\n"); if (!init_suite(init_udp_bind_local_ip)) run_suite(send_udp_local_ip, recvfrom_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 UDP bind any address: sendto + recv.\n\n"); if (!init_suite(init_udp_any)) run_suite(send_udp_any, recv_udp); end_suite(); OFP_INFO("\n\nSuite: IPv4 UDP bind any address: sendto + recvfrom.\n\n"); if (!init_suite(init_udp_bind_any)) run_suite(send_udp_any, recvfrom_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 UDP bind any address: sendto + recvfrom(NULL addr).\n\n"); if (!init_suite(init_udp_bind_any)) run_suite(send_udp_any, recvfrom_udp_null_addr); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP bind local IP: sendto + recv.\n\n"); if (!init_suite(init_udp6_bind_local_ip)) run_suite(send_udp6_local_ip, recv_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP bind local IP: sendto + recvfrom.\n\n"); if (!init_suite(init_udp6_bind_local_ip)) run_suite(send_udp6_local_ip, recvfrom_udp6); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP bind any IP: sendto + recv.\n\n"); if (!init_suite(init_udp6_bind_any)) run_suite(send_udp6_any, recv_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP bind any IP: sendto + recvfrom.\n\n"); if (!init_suite(init_udp6_bind_any)) run_suite(send_udp6_any, recvfrom_udp6); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 UDP bind any IP: sendto + recvfrom(NULL addr).\n\n"); if (!init_suite(init_udp6_bind_any)) run_suite(send_udp6_any, recvfrom_udp_null_addr); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 TCP socket local IP: listen.\n\n"); if (!init_suite(init_tcp_bind_local_ip)) run_suite(listen_tcp, listen_tcp); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 TCP socket local IP: listen.\n\n"); if (!init_suite(init_tcp6_bind_local_ip)) run_suite(listen_tcp, listen_tcp); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 TCP socket local IP: connect + accept.\n\n"); if (!init_suite(init_tcp_bind_listen_local_ip)) run_suite(connect_tcp4_local_ip, accept_tcp4); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP socket any IP: connect + accept.\n\n"); if (!init_suite(init_tcp_bind_listen_any)) run_suite(connect_tcp4_any, accept_tcp4); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP socket local IP: connect + accept null address.\n\n"); if (!init_suite(init_tcp_bind_listen_local_ip)) run_suite(connect_tcp4_local_ip, accept_tcp4_null_addr); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 TCP socket local IP: connect + accept.\n\n"); if (!init_suite(init_tcp6_bind_listen_local_ip)) run_suite(connect_tcp6_local_ip, accept_tcp6); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP socket any IP: connect + accept.\n\n"); if (!init_suite(init_tcp6_bind_listen_any)) run_suite(connect_tcp6_any, accept_tcp6); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP socket local IP: connect + accept null address.\n\n"); if (!init_suite(init_tcp6_bind_listen_local_ip)) run_suite(connect_tcp6_local_ip, accept_tcp6_null_addr); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 TCP socket local IP: send + recv.\n\n"); if (!init_suite(init_tcp_bind_listen_local_ip)) run_suite(send_tcp4_local_ip, receive_tcp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP socket any IP: send + recv.\n\n"); if (!init_suite(init_tcp_bind_listen_any)) run_suite(send_tcp4_any, receive_tcp); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 TCP socket local IP: send + recv.\n\n"); if (!init_suite(init_tcp6_bind_listen_local_ip)) run_suite(send_tcp6_local_ip, receive_tcp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP socket any IP: send + recv.\n\n"); if (!init_suite(init_tcp6_bind_listen_any)) run_suite(send_tcp6_any, receive_tcp); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 UDP bind local IP: select + recv.\n\n"); if (!init_suite(init_udp_bind_local_ip)) run_suite(send_udp_local_ip, select_recv_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 TCP bind local IP: select + accept + recv.\n\n"); if (!init_suite(init_tcp_bind_listen_local_ip)) run_suite(send_tcp4_local_ip, select_recv_tcp); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP bind local IP: select + recv.\n\n"); if (!init_suite(init_udp6_bind_local_ip)) run_suite(send_udp6_local_ip, select_recv_udp); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv6 TCP bind local IP: select + accept + recv.\n\n"); if (!init_suite(init_tcp6_bind_listen_local_ip)) run_suite(send_tcp6_local_ip, select_recv_tcp); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 UDP bindlocal IP: select + recv x2.\n\n"); if (!init_suite(init_udp_bind_local_ip)) run_suite(send_udp_local_ip, select_recv_udp_2); end_suite(); OFP_INFO("Test ended.\n"); OFP_INFO("\n\nSuite: IPv4 UDP bind local IP: socket_sigevent rcv.\n\n"); if (!init_suite(init_udp_bind_local_ip)) run_suite(recv_send_udp_local_ip, socket_sigevent_udp4); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 UDP bind local IP: socket_sigevent rcv.\n\n"); if (!init_suite(init_udp6_bind_local_ip)) run_suite(recv_send_udp6_local_ip, socket_sigevent_udp6); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 TCP bind local IP: socket_sigevent rcv.\n\n"); if (!init_suite(init_tcp_bind_listen_local_ip)) run_suite(connect_recv_send_tcp_local_ip, socket_sigevent_tcp_rcv); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 TCP bind local IP: socket_sigevent rcv.\n\n"); if (!init_suite(init_tcp6_bind_listen_local_ip)) run_suite(connect_recv_send_tcp6_local_ip, socket_sigevent_tcp_rcv); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ OFP_INFO("\n\nSuite: IPv4 TCP bind local IP: socket_sigevent accept.\n\n"); if (!init_suite(init_tcp_bind_listen_local_ip)) run_suite(connect_tcp_delayed_local_ip, socket_sigevent_tcp_accept); end_suite(); OFP_INFO("Test ended.\n"); #ifdef INET6 OFP_INFO("\n\nSuite: IPv6 TCP bind local IP: socket_sigevent accept.\n\n"); if (!init_suite(init_tcp6_bind_listen_local_ip)) run_suite(connect_tcp6_delayed_local_ip, socket_sigevent_tcp_accept); end_suite(); OFP_INFO("Test ended.\n"); #endif /*INET6*/ odph_linux_pthread_join(thread_tbl, num_workers); printf("End Main()\n"); return 0; }
void *pp_thread(void *arg) { ALLOW_UNUSED_LOCAL(arg); #if ODP_VERSION >= 102 if (odp_init_local(ODP_THREAD_WORKER)) { #else if (odp_init_local()) { #endif OFP_ERR("odp_init_local failed"); return NULL; } if (ofp_init_local()) { OFP_ERR("ofp_init_local failed"); return NULL; } while (odp_atomic_load_u32(&still_running)) { odp_event_t event; odp_queue_t source_queue; event = odp_schedule(&source_queue, ODP_SCHED_WAIT); if (odp_event_type(event) != ODP_EVENT_TIMEOUT) { OFP_ERR("Unexpected event type %d", odp_event_type(event)); continue; } ofp_timer_handle(event); } return NULL; } static void test_arp(void) { struct ofp_ifnet mock_ifnet; struct in_addr ip; uint8_t mac[OFP_ETHER_ADDR_LEN] = { 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, }; /* The buffer passed into ofp_ipv4_lookup_mac() must be 8 bytes since * a 64-bit operation is currently being used to copy a MAC address. */ uint8_t mac_result[OFP_ETHER_ADDR_LEN + 2]; CU_ASSERT(0 == ofp_init_local()); memset(&mock_ifnet, 0, sizeof(mock_ifnet)); CU_ASSERT(0 != inet_aton("1.1.1.1", &ip)); /* Test entry insert, lookup, and remove. */ CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); CU_ASSERT(0 == ofp_arp_ipv4_insert(ip.s_addr, mac, &mock_ifnet)); memset(mac_result, 0xFF, OFP_ETHER_ADDR_LEN); CU_ASSERT(0 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); CU_ASSERT(0 == memcmp(mac, mac_result, OFP_ETHER_ADDR_LEN)); CU_ASSERT(0 == ofp_arp_ipv4_remove(ip.s_addr, &mock_ifnet)); CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); /* Test entry is aged out. */ CU_ASSERT(0 == ofp_arp_ipv4_insert(ip.s_addr, mac, &mock_ifnet)); OFP_INFO("Inserted ARP entry"); sleep(ARP_AGE_INTERVAL + ARP_ENTRY_TIMEOUT); CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); /* Test entry is aged out after a few hits. */ CU_ASSERT(0 == ofp_arp_ipv4_insert(ip.s_addr, mac, &mock_ifnet)); OFP_INFO("Inserted ARP entry"); sleep(ARP_AGE_INTERVAL); CU_ASSERT(0 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); sleep(ARP_AGE_INTERVAL); CU_ASSERT(0 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); sleep(ARP_AGE_INTERVAL + ARP_ENTRY_TIMEOUT); CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet)); } int main(void) { CU_pSuite ptr_suite = NULL; int nr_of_failed_tests = 0; int nr_of_failed_suites = 0; /* Initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); /* add a suite to the registry */ ptr_suite = CU_add_suite("ofp errno", init_suite, end_suite); if (NULL == ptr_suite) { CU_cleanup_registry(); return CU_get_error(); } if (NULL == CU_ADD_TEST(ptr_suite, test_arp)) { CU_cleanup_registry(); return CU_get_error(); } #if defined(OFP_TESTMODE_AUTO) CU_set_output_filename("CUnit-Util"); CU_automated_run_tests(); #else /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); #endif nr_of_failed_tests = CU_get_number_of_tests_failed(); nr_of_failed_suites = CU_get_number_of_suites_failed(); CU_cleanup_registry(); return (nr_of_failed_suites > 0 ? nr_of_failed_suites : nr_of_failed_tests); }
/** * ODP packet example main function */ int main(int argc, char * argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_pool_t pool; int num_workers; int i; odp_shm_t shm; odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; odp_pool_param_t params; odp_timer_pool_param_t tparams; odp_timer_pool_t tp; odp_pool_t tmop; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { EXAMPLE_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } if (odp_init_local(ODP_THREAD_CONTROL)) { EXAMPLE_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } my_sleep(1 + __k1_get_cluster_id() / 4); /* init counters */ odp_atomic_init_u64(&counters.seq, 0); odp_atomic_init_u64(&counters.ip, 0); odp_atomic_init_u64(&counters.udp, 0); odp_atomic_init_u64(&counters.icmp, 0); odp_atomic_init_u64(&counters.cnt, 0); /* Reserve memory for args from shared mem */ shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, 0); args = odp_shm_addr(shm); if (args == NULL) { EXAMPLE_ERR("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } memset(args, 0, sizeof(*args)); /* Parse and store the application arguments */ parse_args(argc, argv, &args->appl); /* Print both system and application information */ print_info(NO_PATH(argv[0]), &args->appl); /* Default to system CPU count unless user specified */ num_workers = MAX_WORKERS; if (args->appl.cpu_count) num_workers = args->appl.cpu_count; num_workers = odp_cpumask_default_worker(&cpumask, num_workers); if (args->appl.mask) { odp_cpumask_from_str(&cpumask, args->appl.mask); num_workers = odp_cpumask_count(&cpumask); } (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); /* ping mode need two workers */ if (args->appl.mode == APPL_MODE_PING) { if (num_workers < 2) { EXAMPLE_ERR("Need at least two worker threads\n"); exit(EXIT_FAILURE); } else { num_workers = 2; } } /* Create packet pool */ odp_pool_param_init(¶ms); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; params.pkt.len = SHM_PKT_POOL_BUF_SIZE; params.pkt.num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; params.type = ODP_POOL_PACKET; pool = odp_pool_create("packet_pool", ¶ms); if (pool == ODP_POOL_INVALID) { EXAMPLE_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } odp_pool_print(pool); /* Create timer pool */ tparams.res_ns = 1 * ODP_TIME_MSEC_IN_NS; tparams.min_tmo = 0; tparams.max_tmo = 10000 * ODP_TIME_SEC_IN_NS; tparams.num_timers = num_workers; /* One timer per worker */ tparams.priv = 0; /* Shared */ tparams.clk_src = ODP_CLOCK_CPU; tp = odp_timer_pool_create("timer_pool", &tparams); if (tp == ODP_TIMER_POOL_INVALID) { EXAMPLE_ERR("Timer pool create failed.\n"); exit(EXIT_FAILURE); } odp_timer_pool_start(); /* Create timeout pool */ memset(¶ms, 0, sizeof(params)); params.tmo.num = tparams.num_timers; /* One timeout per timer */ params.type = ODP_POOL_TIMEOUT; tmop = odp_pool_create("timeout_pool", ¶ms); if (pool == ODP_POOL_INVALID) { EXAMPLE_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } for (i = 0; i < args->appl.if_count; ++i) create_pktio(args->appl.if_names[i], pool); /* Create and init worker threads */ memset(thread_tbl, 0, sizeof(thread_tbl)); if (args->appl.mode == APPL_MODE_PING) { odp_cpumask_t cpu_mask; odp_queue_t tq; int cpu_first, cpu_next; odp_cpumask_zero(&cpu_mask); cpu_first = odp_cpumask_first(&cpumask); odp_cpumask_set(&cpu_mask, cpu_first); tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); if (tq == ODP_QUEUE_INVALID) abort(); args->thread[1].pktio_dev = args->appl.if_names[0]; args->thread[1].pool = pool; args->thread[1].tp = tp; args->thread[1].tq = tq; args->thread[1].tim = odp_timer_alloc(tp, tq, NULL); if (args->thread[1].tim == ODP_TIMER_INVALID) abort(); args->thread[1].tmo_ev = odp_timeout_alloc(tmop); if (args->thread[1].tmo_ev == ODP_TIMEOUT_INVALID) abort(); args->thread[1].mode = args->appl.mode; odph_linux_pthread_create(&thread_tbl[1], &cpu_mask, gen_recv_thread, &args->thread[1], ODP_THREAD_WORKER); tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); if (tq == ODP_QUEUE_INVALID) abort(); args->thread[0].pktio_dev = args->appl.if_names[0]; args->thread[0].pool = pool; args->thread[0].tp = tp; args->thread[0].tq = tq; args->thread[0].tim = odp_timer_alloc(tp, tq, NULL); if (args->thread[0].tim == ODP_TIMER_INVALID) abort(); args->thread[0].tmo_ev = odp_timeout_alloc(tmop); if (args->thread[0].tmo_ev == ODP_TIMEOUT_INVALID) abort(); args->thread[0].mode = args->appl.mode; cpu_next = odp_cpumask_next(&cpumask, cpu_first); odp_cpumask_zero(&cpu_mask); odp_cpumask_set(&cpu_mask, cpu_next); odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, gen_send_thread, &args->thread[0], ODP_THREAD_WORKER); } else { int cpu = odp_cpumask_first(&cpumask); for (i = 0; i < num_workers; ++i) { odp_cpumask_t thd_mask; void *(*thr_run_func) (void *); int if_idx; odp_queue_t tq; if_idx = i % args->appl.if_count; args->thread[i].pktio_dev = args->appl.if_names[if_idx]; tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); if (tq == ODP_QUEUE_INVALID) abort(); args->thread[i].pool = pool; args->thread[i].tp = tp; args->thread[i].tq = tq; args->thread[i].tim = odp_timer_alloc(tp, tq, NULL); if (args->thread[i].tim == ODP_TIMER_INVALID) abort(); args->thread[i].tmo_ev = odp_timeout_alloc(tmop); if (args->thread[i].tmo_ev == ODP_TIMEOUT_INVALID) abort(); args->thread[i].mode = args->appl.mode; if (args->appl.mode == APPL_MODE_UDP) { thr_run_func = gen_send_thread; } else if (args->appl.mode == APPL_MODE_RCV) { thr_run_func = gen_recv_thread; } else { EXAMPLE_ERR("ERR MODE\n"); exit(EXIT_FAILURE); } /* * Create threads one-by-one instead of all-at-once, * because each thread might get different arguments. * Calls odp_thread_create(cpu) for each thread */ odp_cpumask_zero(&thd_mask); odp_cpumask_set(&thd_mask, cpu); odph_linux_pthread_create(&thread_tbl[i], &thd_mask, thr_run_func, &args->thread[i], ODP_THREAD_WORKER); cpu = odp_cpumask_next(&cpumask, cpu); } } print_global_stats(num_workers); /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); free(args->appl.if_names); free(args->appl.if_str); printf("Exit\n\n"); return 0; }
/** * ODP L2 forwarding main function */ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_pool_t pool; int i; int cpu; int num_workers; odp_shm_t shm; odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; odph_ethaddr_t new_addr; odp_pktio_t pktio; odp_pool_param_t params; int ret; stats_t *stats; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { LOG_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } /* Init this thread */ if (odp_init_local(ODP_THREAD_CONTROL)) { LOG_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } /* Reserve memory for args from shared mem */ shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, 0); gbl_args = odp_shm_addr(shm); if (gbl_args == NULL) { LOG_ERR("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } memset(gbl_args, 0, sizeof(*gbl_args)); /* Parse and store the application arguments */ parse_args(argc, argv, &gbl_args->appl); /* Print both system and application information */ print_info(NO_PATH(argv[0]), &gbl_args->appl); /* Default to system CPU count unless user specified */ num_workers = MAX_WORKERS; if (gbl_args->appl.cpu_count) num_workers = gbl_args->appl.cpu_count; /* Get default worker cpumask */ num_workers = odp_cpumask_default_worker(&cpumask, num_workers); (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); if (num_workers < gbl_args->appl.if_count) { LOG_ERR("Error: CPU count %d less than interface count\n", num_workers); exit(EXIT_FAILURE); } /* Create packet pool */ odp_pool_param_init(¶ms); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; params.pkt.len = SHM_PKT_POOL_BUF_SIZE; params.pkt.num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; params.type = ODP_POOL_PACKET; pool = odp_pool_create("packet pool", ¶ms); if (pool == ODP_POOL_INVALID) { LOG_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } odp_pool_print(pool); for (i = 0; i < gbl_args->appl.if_count; ++i) { pktio = create_pktio(gbl_args->appl.if_names[i], pool); if (pktio == ODP_PKTIO_INVALID) exit(EXIT_FAILURE); gbl_args->pktios[i] = pktio; /* Save interface ethernet address */ if (odp_pktio_mac_addr(pktio, gbl_args->port_eth_addr[i].addr, ODPH_ETHADDR_LEN) != ODPH_ETHADDR_LEN) { LOG_ERR("Error: interface ethernet address unknown\n"); exit(EXIT_FAILURE); } /* Save destination eth address */ if (gbl_args->appl.dst_change) { /* 02:00:00:00:00:XX */ memset(&new_addr, 0, sizeof(odph_ethaddr_t)); new_addr.addr[0] = 0x02; new_addr.addr[5] = i; gbl_args->dst_eth_addr[i] = new_addr; } /* Save interface destination port */ gbl_args->dst_port[i] = find_dest_port(i); } gbl_args->pktios[i] = ODP_PKTIO_INVALID; memset(thread_tbl, 0, sizeof(thread_tbl)); stats = gbl_args->stats; odp_barrier_init(&barrier, num_workers + 1); /* Create worker threads */ cpu = odp_cpumask_first(&cpumask); for (i = 0; i < num_workers; ++i) { odp_cpumask_t thd_mask; void *(*thr_run_func) (void *); if (gbl_args->appl.mode == DIRECT_RECV) thr_run_func = pktio_direct_recv_thread; else /* SCHED_NONE / SCHED_ATOMIC / SCHED_ORDERED */ thr_run_func = pktio_queue_thread; gbl_args->thread[i].src_idx = i % gbl_args->appl.if_count; gbl_args->thread[i].stats = &stats[i]; odp_cpumask_zero(&thd_mask); odp_cpumask_set(&thd_mask, cpu); odph_linux_pthread_create(&thread_tbl[i], &thd_mask, thr_run_func, &gbl_args->thread[i], ODP_THREAD_WORKER); cpu = odp_cpumask_next(&cpumask, cpu); } /* Start packet receive and transmit */ for (i = 0; i < gbl_args->appl.if_count; ++i) { pktio = gbl_args->pktios[i]; ret = odp_pktio_start(pktio); if (ret) { LOG_ERR("Error: unable to start %s\n", gbl_args->appl.if_names[i]); exit(EXIT_FAILURE); } } ret = print_speed_stats(num_workers, stats, gbl_args->appl.time, gbl_args->appl.accuracy); exit_threads = 1; /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); free(gbl_args->appl.if_names); free(gbl_args->appl.if_str); printf("Exit\n\n"); return ret; }
/** main() Application entry point * * @param argc int * @param argv[] char* * @return int * */ int main(int argc, char *argv[]) { odph_odpthread_t thread_tbl[MAX_WORKERS]; appl_args_t params; int core_count, num_workers; odp_cpumask_t cpumask; char cpumaskstr[64]; odph_odpthread_params_t thr_params; odp_instance_t instance; /* Parse and store the application arguments */ parse_args(argc, argv, ¶ms); if (params.if_count > OFP_FP_INTERFACE_MAX) { printf("Error: Invalid number of interfaces: maximum %d\n", OFP_FP_INTERFACE_MAX); exit(EXIT_FAILURE); } if (odp_init_global(&instance, NULL, NULL)) { OFP_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } if (odp_init_local(instance, ODP_THREAD_CONTROL)) { OFP_ERR("Error: ODP local init failed.\n"); exit(EXIT_FAILURE); } /* Print both system and application information */ print_info(NO_PATH(argv[0]), ¶ms); core_count = odp_cpu_count(); num_workers = core_count; if (params.core_count && params.core_count < core_count) num_workers = params.core_count; if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; if (core_count > 1) num_workers--; num_workers = odp_cpumask_default_worker(&cpumask, num_workers); odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); printf("Num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); ofp_init_global_param(&app_init_params); app_init_params.if_count = params.if_count; app_init_params.if_names = params.if_names; if (ofp_init_global(instance, &app_init_params)) { OFP_ERR("Error: OFP global init failed.\n"); exit(EXIT_FAILURE); } if (ofp_init_local()) { OFP_ERR("Error: OFP local init failed.\n"); exit(EXIT_FAILURE); } build_classifier(app_init_params.if_count, app_init_params.if_names); /* Start CLI */ ofp_start_cli_thread(instance, app_init_params.linux_core_id, params.cli_file); sleep(1); memset(thread_tbl, 0, sizeof(thread_tbl)); /* Start dataplane dispatcher worker threads */ thr_params.start = default_event_dispatcher; thr_params.arg = ofp_udp4_processing; thr_params.thr_type = ODP_THREAD_WORKER; thr_params.instance = instance; odph_odpthreads_create(thread_tbl, &cpumask, &thr_params); app_processing(); odph_odpthreads_join(thread_tbl); printf("End Main()\n"); return 0; }
/** * ODP packet example main function */ int main(int argc, char *argv[]) { odp_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_buffer_pool_t pool; int thr_id; int num_workers; void *pool_base; int i; int first_core; int core_count; /* Init ODP before calling anything else */ if (odp_init_global()) { ODP_ERR("Error: ODP global init failed.\n"); exit(EXIT_FAILURE); } /* Reserve memory for args from shared mem */ args = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE); if (args == NULL) { ODP_ERR("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } memset(args, 0, sizeof(*args)); /* Parse and store the application arguments */ parse_args(argc, argv, &args->appl); /* Print both system and application information */ print_info(NO_PATH(argv[0]), &args->appl); core_count = odp_sys_core_count(); num_workers = core_count; if (args->appl.core_count) num_workers = args->appl.core_count; if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; printf("Num worker threads: %i\n", num_workers); /* * By default core #0 runs Linux kernel background tasks. * Start mapping thread from core #1 */ first_core = 1; if (core_count == 1) first_core = 0; printf("First core: %i\n\n", first_core); /* Init this thread */ thr_id = odp_thread_create(0); odp_init_local(thr_id); /* Create packet pool */ pool_base = odp_shm_reserve("shm_packet_pool", SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE); if (pool_base == NULL) { ODP_ERR("Error: packet pool mem alloc failed.\n"); exit(EXIT_FAILURE); } pool = odp_buffer_pool_create("packet_pool", pool_base, SHM_PKT_POOL_SIZE, SHM_PKT_POOL_BUF_SIZE, ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_PACKET); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } odp_buffer_pool_print(pool); /* Create and init worker threads */ memset(thread_tbl, 0, sizeof(thread_tbl)); for (i = 0; i < num_workers; ++i) { void *(*thr_run_func) (void *); int core; int if_idx; core = (first_core + i) % core_count; if_idx = i % args->appl.if_count; args->thread[i].pktio_dev = args->appl.if_names[if_idx]; args->thread[i].pool = pool; args->thread[i].mode = args->appl.mode; args->thread[i].type = args->appl.type; args->thread[i].fanout = args->appl.fanout; if (args->appl.mode == APPL_MODE_PKT_BURST) thr_run_func = pktio_ifburst_thread; else /* APPL_MODE_PKT_QUEUE */ thr_run_func = pktio_queue_thread; /* * Create threads one-by-one instead of all-at-once, * because each thread might get different arguments. * Calls odp_thread_create(cpu) for each thread */ odp_linux_pthread_create(thread_tbl, 1, core, thr_run_func, &args->thread[i]); } /* Master thread waits for other threads to exit */ odp_linux_pthread_join(thread_tbl, num_workers); printf("Exit\n\n"); return 0; }
/** * main() Application entry point * * This is the main function of the FPM application, it's a minimalistic * example, see 'usage' function for available arguments and usage. * * Using the number of available cores as input, this example sets up * ODP dispatcher threads executing OFP VLAN processesing and starts * a CLI function on a managment core. * * @param argc int * @param argv[] char* * @return int * */ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; appl_args_t params; int core_count, num_workers, ret_val; odp_cpumask_t cpumask; char cpumaskstr[64]; odph_linux_thr_params_t thr_params; odp_instance_t instance; /* Parse and store the application arguments */ if (parse_args(argc, argv, ¶ms) != EXIT_SUCCESS) return EXIT_FAILURE; if (ofp_sigactions_set(ofp_sig_func_stop)) { printf("Error: failed to set signal actions.\n"); return EXIT_FAILURE; } /* * Before any ODP API functions can be called, we must first init the ODP * globals, e.g. availale accelerators or software implementations for * shared memory, threads, pool, qeueus, sheduler, pktio, timer, crypto * and classification. */ if (odp_init_global(&instance, NULL, NULL)) { printf("Error: ODP global init failed.\n"); return EXIT_FAILURE; } /* * When the gloabel ODP level init has been done, we can now issue a * local init per thread. This must also be done before any other ODP API * calls may be made. Local inits are made here for shared memory, * threads, pktio and scheduler. */ if (odp_init_local(instance, ODP_THREAD_CONTROL) != 0) { printf("Error: ODP local init failed.\n"); odp_term_global(instance); return EXIT_FAILURE; } /* Print both system and application information */ print_info(NO_PATH(argv[0]), ¶ms); /* * Get the number of cores available to ODP, one run-to-completion thread * will be created per core. */ core_count = odp_cpu_count(); num_workers = core_count; if (params.core_count) num_workers = params.core_count; if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; /* * This example assumes that core #0 runs Linux kernel background tasks. * By default, cores #1 and beyond will be populated with a OFP * processing thread each. */ memset(&app_init_params, 0, sizeof(app_init_params)); app_init_params.linux_core_id = 0; if (core_count > 1) num_workers--; /* * Initializes cpumask with CPUs available for worker threads. * Sets up to 'num' CPUs and returns the count actually set. * Use zero for all available CPUs. */ num_workers = odp_cpumask_default_worker(&cpumask, num_workers); if (odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)) < 0) { printf("Error: Too small buffer provided to " "odp_cpumask_to_str\n"); odp_term_local(); odp_term_global(instance); return EXIT_FAILURE; } printf("Num worker threads: %i\n", num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr); app_init_params.if_count = params.if_count; app_init_params.if_names = params.if_names; app_init_params.pkt_hook[OFP_HOOK_LOCAL] = fastpath_local_hook; /* * Now that ODP has been initalized, we can initialize OFP. This will * open a pktio instance for each interface supplied as argument by the * user. * * General configuration will be to pktio and schedluer queues here in * addition will fast path interface configuration. */ if (ofp_init_global(instance, &app_init_params) != 0) { printf("Error: OFP global init failed.\n"); ofp_term_global(); odp_term_local(); odp_term_global(instance); return EXIT_FAILURE; } if (ofp_init_local() != 0) { printf("Error: OFP local init failed.\n"); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(instance); return EXIT_FAILURE; } /* * Create and launch dataplane dispatcher worker threads to be placed * according to the cpumask, thread_tbl will be populated with the * created pthread IDs. * * In this case, all threads will run the default_event_dispatcher * function with ofp_eth_vlan_processing as argument. * * If different dispatchers should run, or the same be run with differnt * input arguments, the cpumask is used to control this. */ memset(thread_tbl, 0, sizeof(thread_tbl)); thr_params.start = default_event_dispatcher; thr_params.arg = ofp_eth_vlan_processing; thr_params.thr_type = ODP_THREAD_WORKER; thr_params.instance = instance; ret_val = odph_linux_pthread_create(thread_tbl, &cpumask, &thr_params); if (ret_val != num_workers) { OFP_ERR("Error: Failed to create worker threads, " "expected %d, got %d", num_workers, ret_val); ofp_stop_processing(); odph_linux_pthread_join(thread_tbl, num_workers); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(instance); return EXIT_FAILURE; } /* * Now when the ODP dispatcher threads are running, further applications * can be launched, in this case, we will start the OFP CLI thread on * the management core, i.e. not competing for cpu cycles with the * worker threads */ if (ofp_start_cli_thread(instance, app_init_params.linux_core_id, params.conf_file) < 0) { OFP_ERR("Error: Failed to init CLI thread"); ofp_stop_processing(); odph_linux_pthread_join(thread_tbl, num_workers); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(instance); return EXIT_FAILURE; } /* * If we choose to check performance, a performance monitoring client * will be started on the management core. Once every second it will * read the statistics from the workers from a shared memory region. * Using this has negligible performance impact (<<0.01%). */ if (params.perf_stat) { if (start_performance(instance, app_init_params.linux_core_id) <= 0) { OFP_ERR("Error: Failed to init performance monitor"); ofp_stop_processing(); odph_linux_pthread_join(thread_tbl, num_workers); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(instance); return EXIT_FAILURE; } } /* * Wait here until all worker threads have terminated, then free up all * resources allocated by odp_init_global(). */ odph_linux_pthread_join(thread_tbl, num_workers); if (ofp_term_local() < 0) printf("Error: ofp_term_local failed\n"); if (ofp_term_global() < 0) printf("Error: ofp_term_global failed\n"); if (odp_term_local() < 0) printf("Error: odp_term_local failed\n"); if (odp_term_global(instance) < 0) printf("Error: odp_term_global failed\n"); printf("FPM End Main()\n"); return EXIT_SUCCESS; }