static int clean_suite(void) { ofp_arp_term_local(); ofp_term_local(); ofp_term_global(); odp_term_local(); odp_term_global(); 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 tests_global_term(odp_instance_t inst) { if (0 != odp_term_local()) { fprintf(stderr, "error: odp_term_local() failed.\n"); return -1; } if (0 != odp_term_global(inst)) { fprintf(stderr, "error: odp_term_global() failed.\n"); return -1; } 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; }
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; }
/** * 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; }
int main(int argc, char **argv) { int ret; odp_shm_t shm; int max_thrs; odp_instance_t instance; if (odp_init_global(&instance, NULL, NULL) != 0) LOG_ABORT("Failed global init.\n"); if (odp_init_local(instance, 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->instance = instance; 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(); } odp_term_local(); odp_term_global(instance); return ret; }
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; }
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; }
int main(int argc, char **argv) { int ret; ret = odp_init_global(NULL, NULL); if(ret < 0) { fprintf(stderr, "global init failure!\n"); exit(EXIT_FAILURE); } ret = odp_init_local(ODP_THREAD_CONTROL); if(ret < 0) { fprintf(stderr, "local init failure!\n"); exit(EXIT_FAILURE); } parse_param(argc, argv); packet_classifier_init(glb_param.rule_file, glb_param.fib_file); hash_env_init(); sm_hdl = sm_build(glb_param.pat_file); hs_tbl = create_hash_table(); odp_pool_t pkt_pool; pkt_pool = create_pkt_pool("PACKET_POOL",PACKET_POOL_OBJ_SZ, PACKET_POOL_MAX_ELT_NUM); if(pkt_pool == ODP_POOL_INVALID) { fprintf(stderr, "create packet pool failure!\n"); exit(EXIT_FAILURE); } if(init_all_if(pkt_pool) == -1) { fprintf(stderr, "init nic faliure!\n"); exit(EXIT_FAILURE); } odph_linux_pthread_t thr_tbl[ODP_CONFIG_PKTIO_ENTRIES]; int thr_num; thr_num = odph_linux_pthread_create(thr_tbl, &glb_param.cpu_mask, thread_fwd_routine, NULL); if(thr_num != glb_param.nic.num) { fprintf(stderr, "some nic thread start failure!\n"); exit(EXIT_FAILURE); } odph_linux_pthread_t thr_stat_hdl; odp_cpumask_t thr_stat_mask; odp_cpumask_zero(&thr_stat_mask); odp_cpumask_set(&thr_stat_mask, glb_param.nic.num); if(odph_linux_pthread_create(&thr_stat_hdl, &thr_stat_mask, thread_stat_routine, NULL) != 1) { fprintf(stderr, "stat thread start failure!\n"); exit(EXIT_FAILURE); } odph_linux_pthread_join(thr_tbl, thr_num); odph_linux_pthread_join(&thr_stat_hdl, 1); int nic_id; for(nic_id = 0; nic_id < glb_param.nic.num; nic_id++) { odp_pktio_close(thr_data.nic_hdl[nic_id]); } sm_destroy(sm_hdl); odph_hash_free(hs_tbl); odp_pool_destroy(pkt_pool); odp_term_local(); odp_term_global(); 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 tick, 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 = ODP_SHM_INVALID; test_globals_t *gbls = NULL; int err = 0; printf("\nODP timer example starts\n"); if (odp_init_global(NULL, NULL)) { err = 1; printf("ODP global init failed.\n"); goto err_global; } /* Init this thread. */ if (odp_init_local(ODP_THREAD_CONTROL)) { err = 1; printf("ODP local init failed.\n"); goto err_local; } 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_cpu_model_str()); printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz_max()); 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) { err = 1; EXAMPLE_ERR("Error: shared mem reserve failed.\n"); goto err; } gbls = odp_shm_addr(shm); if (NULL == gbls) { err = 1; EXAMPLE_ERR("Error: shared mem alloc failed.\n"); goto err; } memset(gbls, 0, sizeof(test_globals_t)); gbls->pool = ODP_POOL_INVALID; gbls->tp = ODP_TIMER_POOL_INVALID; 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; /* 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); 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 */ odp_pool_param_init(¶ms); params.tmo.num = NUM_TMOS; params.type = ODP_POOL_TIMEOUT; gbls->pool = odp_pool_create("msg_pool", ¶ms); if (gbls->pool == ODP_POOL_INVALID) { err = 1; EXAMPLE_ERR("Pool create failed.\n"); goto err; } tparams.res_ns = gbls->args.resolution_us * ODP_TIME_USEC_IN_NS; tparams.min_tmo = gbls->args.min_us * ODP_TIME_USEC_IN_NS; tparams.max_tmo = gbls->args.max_us * ODP_TIME_USEC_IN_NS; 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) { err = 1; EXAMPLE_ERR("Timer pool create failed.\n"); goto err; } 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 */ odp_queue_param_init(¶m); param.type = ODP_QUEUE_TYPE_SCHED; param.sched.prio = ODP_SCHED_PRIO_DEFAULT; param.sched.sync = ODP_SCHED_SYNC_PARALLEL; param.sched.group = ODP_SCHED_GROUP_ALL; queue = odp_queue_create("timer_queue", ¶m); if (queue == ODP_QUEUE_INVALID) { err = 1; EXAMPLE_ERR("Timer queue create failed.\n"); goto err; } printf("CPU freq %"PRIu64" Hz\n", odp_cpu_hz_max()); printf("Timer ticks vs nanoseconds:\n"); ns = 0; tick = odp_timer_ns_to_tick(gbls->tp, ns); printf(" %12" PRIu64 " ns -> %12" PRIu64 " ticks\n", ns, tick); printf(" %12" PRIu64 " ticks -> %12" PRIu64 " ns\n", tick, odp_timer_tick_to_ns(gbls->tp, tick)); for (ns = 1; ns <= 100 * ODP_TIME_SEC_IN_NS; ns *= 10) { tick = odp_timer_ns_to_tick(gbls->tp, ns); printf(" %12" PRIu64 " ns -> %12" PRIu64 " ticks\n", ns, tick); printf(" %12" PRIu64 " ticks -> %12" PRIu64 " ns\n", tick, odp_timer_tick_to_ns(gbls->tp, tick)); } printf("\n"); gbls->num_workers = num_workers; /* 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, ODP_THREAD_WORKER); /* Wait for worker threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); /* free resources */ if (odp_queue_destroy(queue)) err = 1; err: if (gbls != NULL && gbls->tp != ODP_TIMER_POOL_INVALID) odp_timer_pool_destroy(gbls->tp); if (gbls != NULL && gbls->pool != ODP_TIMER_POOL_INVALID) if (odp_pool_destroy(gbls->pool)) err = 1; if (shm != ODP_SHM_INVALID) if (odp_shm_free(shm)) err = 1; if (odp_term_local()) err = 1; err_local: if (odp_term_global()) err = 1; err_global: if (err) { printf("Err: ODP timer test failed\n\n"); return -1; } printf("ODP timer test complete\n\n"); return 0; }