API Reference Manual  1.47.0
odp_timer_stress.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2025 Nokia
3  */
4 
13 #ifndef _GNU_SOURCE
14 #define _GNU_SOURCE
15 #endif
16 
17 #include <inttypes.h>
18 #include <signal.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <unistd.h>
22 
23 #include <odp_api.h>
24 #include <odp/helper/odph_api.h>
25 
26 #define PROG_NAME "odp_timer_stress"
27 
28 #define MAX_WORKERS ((uint32_t)(ODP_THREAD_COUNT_MAX - 1))
29 #define MULTIPLIER 50U
30 #define FMT_RES "4"
31 #define MAX_RETRY 10U
32 #define WAIT_MULTIPLIER 100U
33 
34 #define GIGAS 1000000000U
35 #define MEGAS 1000000U
36 #define KILOS 1000U
37 
38 enum {
39  SINGLE_SHOT,
40  PERIODIC,
41  CANCEL
42 };
43 
44 enum {
45  SHARED_TMR,
46  PRIV_TMR
47 };
48 
49 #define DEF_MODE SINGLE_SHOT
50 #define DEF_CLK_SRC ODP_CLOCK_DEFAULT
51 #define DEF_RES 1000000U
52 #define DEF_TIMERS 50U
53 #define DEF_POLICY SHARED_TMR
54 #define DEF_TIME 2U
55 #define DEF_WORKERS 1U
56 
57 typedef enum {
58  PRS_OK,
59  PRS_NOK,
60  PRS_TERM
61 } parse_result_t;
62 
63 typedef struct {
64  uint64_t num_tmo;
65  uint64_t num_retry;
66  uint64_t num_miss;
67  uint64_t tot_tm;
68  uint64_t max_mul;
69 } stats_t;
70 
71 typedef struct prog_config_s prog_config_t;
72 
73 typedef struct {
74  odp_timer_t tmr;
75  odp_timeout_t tmo;
76  odp_bool_t is_running;
77 } tmr_hdls_t;
78 
79 typedef struct ODP_ALIGNED_CACHE {
80  stats_t stats;
81 
82  struct {
84  odp_queue_t q;
85  } scd;
86 
87  struct {
88  tmr_hdls_t *tmrs;
89  } cancel;
90 
91  prog_config_t *prog_config;
92  uint32_t num_boot_tmr;
93 } worker_config_t;
94 
95 typedef struct {
96  uint32_t mode;
97  odp_timer_clk_src_t clk_src;
98  uint64_t res_ns;
99  uint32_t num_tmr;
100  uint32_t policy;
101  uint32_t time_sec;
102  uint32_t num_workers;
103 } opts_t;
104 
105 typedef struct prog_config_s {
106  odph_thread_t thread_tbl[MAX_WORKERS];
107  worker_config_t worker_config[MAX_WORKERS];
109  odp_cpumask_t worker_mask;
110  odp_barrier_t init_barrier;
111  odp_barrier_t term_barrier;
112  odp_atomic_u32_t is_running;
113  opts_t def_opts;
114  opts_t opts;
117  odp_pool_t tmo_pool;
118  odp_timer_pool_t tmr_pool;
119  odp_spinlock_t lock;
120  odp_shm_t cancel_shm;
121 } prog_config_t;
122 
123 static prog_config_t *prog_conf;
124 
125 static void terminate(int signal ODP_UNUSED)
126 {
127  odp_atomic_store_u32(&prog_conf->is_running, 0U);
128 }
129 
130 static void init_config(prog_config_t *config)
131 {
132  opts_t opts;
134  worker_config_t *worker;
135 
136  opts.mode = DEF_MODE;
137  opts.clk_src = DEF_CLK_SRC;
138  opts.res_ns = DEF_RES;
139  opts.num_tmr = DEF_TIMERS;
140  opts.policy = DEF_POLICY;
141  opts.time_sec = DEF_TIME;
142  opts.num_workers = DEF_WORKERS;
143 
144  if (odp_timer_capability(opts.clk_src, &capa) == 0) {
145  if (opts.res_ns < capa.highest_res_ns)
146  opts.res_ns = capa.highest_res_ns;
147 
148  if (opts.mode == SINGLE_SHOT || opts.mode == CANCEL) {
149  if (capa.max_timers > 0U && opts.num_tmr > capa.max_timers)
150  opts.num_tmr = capa.max_timers;
151  } else if (capa.max_pools > 0U && opts.num_tmr > capa.periodic.max_timers) {
152  opts.num_tmr = capa.periodic.max_timers;
153  }
154  }
155 
156  for (uint32_t i = 0U; i < MAX_WORKERS; ++i) {
157  worker = &config->worker_config[i];
158  worker->scd.grp = ODP_SCHED_GROUP_INVALID;
159  worker->scd.q = ODP_QUEUE_INVALID;
160  }
161 
162  config->def_opts = opts;
163  config->opts = config->def_opts;
164  config->tmo_pool = ODP_POOL_INVALID;
165  config->tmr_pool = ODP_TIMER_POOL_INVALID;
166  odp_spinlock_init(&config->lock);
167  config->cancel_shm = ODP_SHM_INVALID;
168 }
169 
170 static void print_usage(const opts_t *opts)
171 {
172  printf("\n"
173  "Stress test for benchmarking timer related handling performance in different\n"
174  "scenarios.\n"
175  "\n"
176  "Usage: " PROG_NAME " [OPTIONS]\n");
177  printf("\n"
178  " E.g. " PROG_NAME " -m 0 -n 20\n"
179  " " PROG_NAME " -m 2 -p 1 -t 5 -c 4\n");
180  printf("\n"
181  "Optional OPTIONS:\n"
182  "\n"
183  " -m, --mode Timer mode. %u by default. Modes:\n"
184  " 0: single shot\n"
185  " 1: periodic\n"
186  " 2: single shot with cancel\n"
187  " -s, --clock_source Clock source. Use 'odp_timer_clk_src_t' enumeration values.\n"
188  " %u by default.\n"
189  " -r, --resolution Timer resolution in nanoseconds. %" PRIu64 " by default.\n"
190  " -n, --num_timer Number of timers. %u by default.\n"
191  " -p, --policy Timer sharing policy. %u by default. Policies:\n"
192  " 0: Timers shared by workers\n"
193  " 1: Private timers per worker\n"
194  " -t, --time_sec Time in seconds to run. 0 means infinite. %u by default.\n"
195  " -c, --worker_count Number of workers. %u by default.\n"
196  " -h, --help This help.\n"
197  "\n", opts->mode, opts->clk_src, opts->res_ns, opts->num_tmr, opts->policy,
198  opts->time_sec, opts->num_workers);
199 }
200 
201 static odp_fract_u64_t calc_req_hz(uint64_t res_ns)
202 {
203  odp_fract_u64_t fract;
204  const double hz = (double)ODP_TIME_SEC_IN_NS / (res_ns * MULTIPLIER);
205  double leftover;
206 
207  fract.integer = (uint64_t)hz;
208  leftover = hz - fract.integer;
209  fract.numer = (uint64_t)(leftover * DEF_RES);
210  fract.denom = fract.numer == 0U ? 0U : DEF_RES;
211 
212  return fract;
213 }
214 
215 static parse_result_t check_options(prog_config_t *config)
216 {
217  opts_t *opts = &config->opts;
218  odp_timer_capability_t tmr_capa;
219  int ret;
220  uint32_t req_tmr, max_workers, req_shm;
221  odp_fract_u64_t hz;
222  double hz_d, min_hz_d, max_hz_d;
223  odp_pool_capability_t pool_capa;
224  odp_shm_capability_t shm_capa;
225  uint64_t req_shm_sz;
226 
227  if (opts->mode != SINGLE_SHOT && opts->mode != PERIODIC && opts->mode != CANCEL) {
228  ODPH_ERR("Invalid timer mode: %u\n", opts->mode);
229  return PRS_NOK;
230  }
231 
232  if (opts->policy != SHARED_TMR && opts->policy != PRIV_TMR) {
233  ODPH_ERR("Invalid pool policy: %d\n", opts->policy);
234  return PRS_NOK;
235  }
236 
237  if (opts->mode == CANCEL && opts->policy != PRIV_TMR) {
238  ODPH_ERR("Single shot with cancel mode supported only with worker-private "
239  "timers\n");
240  return PRS_NOK;
241  }
242 
243  ret = odp_timer_capability(opts->clk_src, &tmr_capa);
244 
245  if (ret < -1) {
246  ODPH_ERR("Error querying timer capabilities\n");
247  return PRS_NOK;
248  }
249 
250  if (ret == -1) {
251  ODPH_ERR("Invalid clock source: %d\n", opts->clk_src);
252  return PRS_NOK;
253  }
254 
255  if (!tmr_capa.queue_type_sched) {
256  ODPH_ERR("Invalid queue support, scheduled completion queues not supported\n");
257  return PRS_NOK;
258  }
259 
260  if (opts->res_ns < tmr_capa.highest_res_ns) {
261  ODPH_ERR("Invalid resolution: %" PRIu64 " ns (max: %" PRIu64 " ns)\n",
262  opts->res_ns, tmr_capa.highest_res_ns);
263  return PRS_NOK;
264  }
265 
266  if (opts->num_tmr == 0U) {
267  ODPH_ERR("Invalid number of timers: %u\n", opts->num_tmr);
268  return PRS_NOK;
269  }
270 
271  max_workers = ODPH_MIN(MAX_WORKERS, (uint32_t)odp_cpumask_default_worker(NULL, 0));
272 
273  if (opts->num_workers == 0U || opts->num_workers > max_workers) {
274  ODPH_ERR("Invalid worker count: %u (min: 1, max: %u)\n", opts->num_workers,
275  max_workers);
276  return PRS_NOK;
277  }
278 
279  (void)odp_cpumask_default_worker(&config->worker_mask, opts->num_workers);
280 
281  req_tmr = opts->num_tmr * (opts->policy == PRIV_TMR ? opts->num_workers : 1U);
282 
283  if (opts->mode == SINGLE_SHOT || opts->mode == CANCEL) {
284  if (tmr_capa.max_pools == 0U) {
285  ODPH_ERR("Single shot timers not supported\n");
286  return PRS_NOK;
287  }
288 
289  if (tmr_capa.max_timers > 0U && req_tmr > tmr_capa.max_timers) {
290  ODPH_ERR("Invalid number of timers: %u (max: %u)\n", req_tmr,
291  tmr_capa.max_timers);
292  return PRS_NOK;
293  }
294 
295  config->res_capa.res_ns = opts->res_ns;
296 
297  if (odp_timer_res_capability(opts->clk_src, &config->res_capa) < 0) {
298  ODPH_ERR("Error querying timer resolution capabilities\n");
299  return PRS_NOK;
300  }
301 
302  if (opts->mode == CANCEL) {
303  if (odp_shm_capability(&shm_capa) < 0) {
304  ODPH_ERR("Error querying SHM capabilities");
305  return PRS_NOK;
306  }
307 
308  /* One block for program configuration, one block divided between
309  * workers. */
310  req_shm = 2U;
311 
312  if (req_shm > shm_capa.max_blocks) {
313  ODPH_ERR("Invalid SHM block count support: %u (max: %u)\n",
314  req_shm, shm_capa.max_blocks);
315  return PRS_NOK;
316  }
317 
318  /* Dimensioned so that each structure will always start at a cache line
319  * boundary. */
320  req_shm_sz = ODP_CACHE_LINE_ROUNDUP(sizeof(tmr_hdls_t)) *
321  opts->num_tmr * opts->num_workers;
322 
323  if (shm_capa.max_size != 0U && req_shm_sz > shm_capa.max_size) {
324  ODPH_ERR("Invalid total SHM block size: %" PRIu64 ""
325  " (max: %" PRIu64 ")\n", req_shm_sz, shm_capa.max_size);
326  return PRS_NOK;
327  }
328  }
329  } else {
330  if (tmr_capa.periodic.max_pools == 0U) {
331  ODPH_ERR("Periodic timers not supported\n");
332  return PRS_NOK;
333  }
334 
335  if (req_tmr > tmr_capa.periodic.max_timers) {
336  ODPH_ERR("Invalid number of timers: %u (max: %u)\n", req_tmr,
337  tmr_capa.periodic.max_timers);
338  return PRS_NOK;
339  }
340 
341  hz = calc_req_hz(opts->res_ns);
342  hz_d = odp_fract_u64_to_dbl(&hz);
343  min_hz_d = odp_fract_u64_to_dbl(&tmr_capa.periodic.min_base_freq_hz);
344  max_hz_d = odp_fract_u64_to_dbl(&tmr_capa.periodic.max_base_freq_hz);
345 
346  if (hz_d < min_hz_d || hz_d > max_hz_d) {
347  ODPH_ERR("Invalid requested resolution: %." FMT_RES "f hz "
348  "(min: %." FMT_RES "f hz, max: %." FMT_RES "f hz)\n", hz_d,
349  min_hz_d, max_hz_d);
350  return PRS_NOK;
351  }
352 
353  config->per_capa.base_freq_hz = hz;
354  config->per_capa.max_multiplier = MULTIPLIER;
355  config->per_capa.res_ns = opts->res_ns;
356 
357  if (odp_timer_periodic_capability(opts->clk_src, &config->per_capa) < 0) {
358  ODPH_ERR("Error querying periodic timer capabilities\n");
359  return PRS_NOK;
360  }
361 
362  if (config->per_capa.max_multiplier > MULTIPLIER)
363  config->per_capa.max_multiplier = MULTIPLIER;
364  }
365 
366  if (odp_pool_capability(&pool_capa) < 0) {
367  ODPH_ERR("Error querying pool capabilities\n");
368  return PRS_NOK;
369  }
370 
371  if (pool_capa.tmo.max_num > 0U && req_tmr > pool_capa.tmo.max_num) {
372  ODPH_ERR("Invalid timeout event count: %u (max: %u)\n", req_tmr,
373  pool_capa.tmo.max_num);
374  return PRS_NOK;
375  }
376 
377  return PRS_OK;
378 }
379 
380 static parse_result_t parse_options(int argc, char **argv, prog_config_t *config)
381 {
382  int opt;
383  opts_t *opts = &config->opts;
384 
385  static const struct option longopts[] = {
386  { "mode", required_argument, NULL, 'm' },
387  { "clock_source", required_argument, NULL, 's' },
388  { "resolution", required_argument, NULL, 'r' },
389  { "num_timer", required_argument, NULL, 'n' },
390  { "policy", required_argument, NULL, 'p' },
391  { "time_sec", required_argument, NULL, 't' },
392  { "worker_count", required_argument, NULL, 'c' },
393  { "help", no_argument, NULL, 'h' },
394  { NULL, 0, NULL, 0 }
395  };
396 
397  static const char *shortopts = "m:s:r:n:p:t:c:h";
398 
399  init_config(config);
400 
401  while (true) {
402  opt = getopt_long(argc, argv, shortopts, longopts, NULL);
403 
404  if (opt == -1)
405  break;
406 
407  switch (opt) {
408  case 'm':
409  opts->mode = atoi(optarg);
410  break;
411  case 's':
412  opts->clk_src = atoi(optarg);
413  break;
414  case 'r':
415  opts->res_ns = atoll(optarg);
416  break;
417  case 'n':
418  opts->num_tmr = atoi(optarg);
419  break;
420  case 'p':
421  opts->policy = atoi(optarg);
422  break;
423  case 't':
424  opts->time_sec = atoi(optarg);
425  break;
426  case 'c':
427  opts->num_workers = atoi(optarg);
428  break;
429  case 'h':
430  print_usage(&config->def_opts);
431  return PRS_TERM;
432  case '?':
433  default:
434  print_usage(&config->def_opts);
435  return PRS_NOK;
436  }
437  }
438 
439  return check_options(config);
440 }
441 
442 static parse_result_t setup_program(int argc, char **argv, prog_config_t *config)
443 {
444  struct sigaction action = { .sa_handler = terminate };
445 
446  odp_atomic_init_u32(&config->is_running, 1U);
447 
448  if (sigemptyset(&action.sa_mask) == -1 || sigaddset(&action.sa_mask, SIGINT) == -1 ||
449  sigaddset(&action.sa_mask, SIGTERM) == -1 ||
450  sigaddset(&action.sa_mask, SIGHUP) == -1 || sigaction(SIGINT, &action, NULL) == -1 ||
451  sigaction(SIGTERM, &action, NULL) == -1 || sigaction(SIGHUP, &action, NULL) == -1) {
452  ODPH_ERR("Error installing signal handler\n");
453  return PRS_NOK;
454  }
455 
456  return parse_options(argc, argv, config);
457 }
458 
459 static odp_timer_pool_t create_timer_pool(odp_timer_pool_param_t *param)
460 {
461  odp_timer_pool_t pool;
462 
463  pool = odp_timer_pool_create(PROG_NAME, param);
464 
465  if (pool == ODP_TIMER_POOL_INVALID) {
466  ODPH_ERR("Error creating timer pool\n");
467  return ODP_TIMER_POOL_INVALID;
468  }
469 
470  if (odp_timer_pool_start_multi(&pool, 1) != 1) {
471  ODPH_ERR("Error starting timer pool\n");
472  return ODP_TIMER_POOL_INVALID;
473  }
474 
475  return pool;
476 }
477 
478 static odp_bool_t setup_config(prog_config_t *config)
479 {
480  opts_t *opts = &config->opts;
481  odp_bool_t is_priv = opts->policy == PRIV_TMR;
482  const uint32_t num_barrier = opts->num_workers + 1,
483  max_tmr = opts->num_tmr * (is_priv ? opts->num_workers : 1U),
484  tmr_size = ODP_CACHE_LINE_ROUNDUP(sizeof(tmr_hdls_t));
485  odp_pool_param_t tmo_param;
486  odp_timer_pool_param_t tmr_param;
487  odp_queue_param_t q_param;
488  odp_thrmask_t zero;
489  void *cancel_addr = NULL;
490  uint32_t num_tmr_p_w = ODPH_DIV_ROUNDUP(opts->num_tmr, opts->num_workers),
491  num_tmr = opts->num_tmr;
492  worker_config_t *worker;
493 
494  if (odp_schedule_config(NULL) < 0) {
495  ODPH_ERR("Error initializing scheduler\n");
496  return false;
497  }
498 
499  odp_barrier_init(&config->init_barrier, num_barrier);
500  odp_barrier_init(&config->term_barrier, num_barrier);
501  odp_pool_param_init(&tmo_param);
502  tmo_param.type = ODP_POOL_TIMEOUT;
503  tmo_param.tmo.num = max_tmr;
504  tmo_param.tmo.cache_size = 0U;
505  config->tmo_pool = odp_pool_create(PROG_NAME, &tmo_param);
506 
507  if (config->tmo_pool == ODP_POOL_INVALID) {
508  ODPH_ERR("Error creating timeout pool\n");
509  return false;
510  }
511 
512  odp_timer_pool_param_init(&tmr_param);
513  tmr_param.clk_src = opts->clk_src;
514  tmr_param.res_ns = opts->res_ns;
515  tmr_param.num_timers = max_tmr;
516 
517  if (opts->mode == SINGLE_SHOT || opts->mode == CANCEL) {
518  tmr_param.timer_type = ODP_TIMER_TYPE_SINGLE;
519  tmr_param.min_tmo = config->res_capa.min_tmo;
520  tmr_param.max_tmo = config->res_capa.max_tmo;
521  } else {
523  tmr_param.periodic.base_freq_hz = config->per_capa.base_freq_hz;
524  tmr_param.periodic.max_multiplier = config->per_capa.max_multiplier;
525  }
526 
527  config->tmr_pool = create_timer_pool(&tmr_param);
528 
529  if (config->tmr_pool == ODP_TIMER_POOL_INVALID)
530  return false;
531 
532  odp_queue_param_init(&q_param);
533  q_param.type = ODP_QUEUE_TYPE_SCHED;
535  odp_thrmask_zero(&zero);
536 
537  if (is_priv && opts->mode == CANCEL) {
538  config->cancel_shm = odp_shm_reserve(PROG_NAME, tmr_size * max_tmr,
539  ODP_CACHE_LINE_SIZE, 0U);
540 
541  if (config->cancel_shm == ODP_SHM_INVALID) {
542  ODPH_ERR("Error reserving SHM for cancel mode\n");
543  return false;
544  }
545 
546  cancel_addr = odp_shm_addr(config->cancel_shm);
547 
548  if (cancel_addr == NULL) {
549  ODPH_ERR("Error resolving SHM address for cancel mode\n");
550  return false;
551  }
552  }
553 
554  for (uint32_t i = 0U; i < opts->num_workers; ++i) {
555  worker = &config->worker_config[i];
556  worker->num_boot_tmr = num_tmr_p_w;
557  num_tmr -= num_tmr_p_w;
558 
559  if (num_tmr < num_tmr_p_w)
560  num_tmr_p_w = num_tmr;
561 
562  if (is_priv) {
563  worker->num_boot_tmr = opts->num_tmr;
564 
565  if (opts->mode == CANCEL)
566  worker->cancel.tmrs =
567  (tmr_hdls_t *)(uintptr_t)((uint8_t *)(uintptr_t)cancel_addr + i *
568  worker->num_boot_tmr * tmr_size);
569 
570  worker->scd.grp = odp_schedule_group_create(PROG_NAME, &zero);
571 
572  if (worker->scd.grp == ODP_SCHED_GROUP_INVALID) {
573  ODPH_ERR("Error creating schedule group for worker %u\n", i);
574  return false;
575  }
576 
577  q_param.sched.group = worker->scd.grp;
578  }
579 
580  worker->scd.q = odp_queue_create(PROG_NAME, &q_param);
581 
582  if (worker->scd.q == ODP_QUEUE_INVALID) {
583  ODPH_ERR("Error creating completion queue for worker %u\n", i);
584  return false;
585  }
586 
587  worker->prog_config = config;
588  }
589 
590  return true;
591 }
592 
593 static tmr_hdls_t get_time_handles(odp_timer_pool_t tmr_pool, odp_pool_t tmo_pool, odp_queue_t q)
594 {
595  tmr_hdls_t time;
596 
597  time.tmr = odp_timer_alloc(tmr_pool, q, NULL);
598 
599  if (time.tmr == ODP_TIMER_INVALID)
600  /* We should have enough timers available, if still somehow there is a failure,
601  * abort. */
602  ODPH_ABORT("Error allocating timers, aborting (tmr: %" PRIx64 ", "
603  "tmr pool: %" PRIx64 ")\n", odp_timer_to_u64(time.tmr),
604  odp_timer_pool_to_u64(tmr_pool));
605 
606  time.tmo = odp_timeout_alloc(tmo_pool);
607 
608  if (time.tmo == ODP_TIMEOUT_INVALID)
609  /* We should have enough timeouts available, if still somehow there is a failure,
610  * abort. */
611  ODPH_ABORT("Error allocating timeouts, aborting (tmo: %" PRIx64 ", "
612  "tmo pool: %" PRIx64 ")\n", odp_timeout_to_u64(time.tmo),
613  odp_pool_to_u64(tmo_pool));
614 
615  time.is_running = true;
616 
617  return time;
618 }
619 
620 static inline void start_single_shot(odp_timer_pool_t tmr_pool, odp_timer_t tmr, odp_event_t tmo,
621  uint64_t res_ns, stats_t *stats)
622 {
623  odp_timer_start_t start = { .tick_type = ODP_TIMER_TICK_REL, .tmo_ev = tmo };
624  uint32_t retry = MAX_RETRY, mul = 1U;
625  int ret;
626 
627  while (retry) {
628  start.tick = odp_timer_ns_to_tick(tmr_pool, mul * res_ns);
629  ret = odp_timer_start(tmr, &start);
630 
631  if (ret == ODP_TIMER_SUCCESS)
632  break;
633 
634  --retry;
635 
636  if (retry > 0U && ret == ODP_TIMER_TOO_NEAR) {
637  ++mul;
638  ++stats->num_retry;
639  continue;
640  }
641 
642  /* Arming the timer apparently not possible, abort. */
643  ODPH_ABORT("Error starting timers, aborting (tmr: %" PRIx64 ", tmr pool: "
644  "%" PRIx64 ")\n", odp_timer_to_u64(tmr),
645  odp_timer_pool_to_u64(tmr_pool));
646  }
647 
648  stats->max_mul = mul > stats->max_mul ? mul : stats->max_mul;
649 }
650 
651 static void boot_single_shot(worker_config_t *worker, odp_timer_pool_t tmr_pool,
652  odp_pool_t tmo_pool, uint64_t res_ns)
653 {
654  tmr_hdls_t time;
655 
656  for (uint32_t i = 0U; i < worker->num_boot_tmr; ++i) {
657  time = get_time_handles(tmr_pool, tmo_pool, worker->scd.q);
658  start_single_shot(tmr_pool, time.tmr, odp_timeout_to_event(time.tmo), res_ns,
659  &worker->stats);
660  }
661 }
662 
663 static int process_single_shot(void *args)
664 {
665  worker_config_t *worker = args;
666  odp_thrmask_t mask;
667  prog_config_t *config = worker->prog_config;
668  odp_timer_pool_t tmr_pool = config->tmr_pool;
669  const uint64_t res_ns = prog_conf->opts.res_ns;
670  odp_time_t tm;
671  odp_atomic_u32_t *is_running = &config->is_running;
672  odp_event_t ev;
673  odp_timer_t tmr;
674  stats_t *stats = &worker->stats;
675 
676  if (worker->scd.grp != ODP_SCHED_GROUP_INVALID) {
677  odp_thrmask_zero(&mask);
678  odp_thrmask_set(&mask, odp_thread_id());
679 
680  if (odp_schedule_group_join(worker->scd.grp, &mask) < 0)
681  ODPH_ABORT("Error joining scheduler group, aborting (group: %" PRIu64 ")"
682  "\n", odp_schedule_group_to_u64(worker->scd.grp));
683  }
684 
685  boot_single_shot(worker, tmr_pool, config->tmo_pool, res_ns);
686  odp_barrier_wait(&config->init_barrier);
687  tm = odp_time_local_strict();
688 
689  while (odp_atomic_load_u32(is_running)) {
690  ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT);
691 
692  if (ev == ODP_EVENT_INVALID)
693  continue;
694 
696  start_single_shot(tmr_pool, tmr, ev, res_ns, stats);
697  ++stats->num_tmo;
698  }
699 
700  stats->tot_tm = odp_time_diff_ns(odp_time_local_strict(), tm);
701  odp_barrier_wait(&config->term_barrier);
702 
703  while (true) {
704  ev = odp_schedule(NULL, odp_schedule_wait_time(stats->max_mul * res_ns *
705  WAIT_MULTIPLIER));
706 
707  if (ev == ODP_EVENT_INVALID)
708  break;
709 
711  odp_event_free(ev);
712  (void)odp_timer_free(tmr);
713  }
714 
715  return 0;
716 }
717 
718 static void start_periodic(odp_timer_pool_t tmr_pool, odp_timer_t tmr, odp_event_t tmo,
719  uint64_t mul)
720 {
721  const odp_timer_periodic_start_t start = { .first_tick = 0U, .freq_multiplier = mul,
722  .tmo_ev = tmo };
723  const int ret = odp_timer_periodic_start(tmr, &start);
724 
725  if (ret != ODP_TIMER_SUCCESS)
726  /* Even with implementation-set first tick, arming not possible, abort. */
727  ODPH_ABORT("Error starting timer, aborting (tmr: %" PRIx64 ", tmr pool: "
728  "%" PRIx64 ")\n", odp_timer_to_u64(tmr),
729  odp_timer_pool_to_u64(tmr_pool));
730 }
731 
732 static void boot_periodic(worker_config_t *worker, odp_timer_pool_t tmr_pool, odp_pool_t tmo_pool,
733  uint64_t mul)
734 {
735  tmr_hdls_t time;
736 
737  for (uint32_t i = 0U; i < worker->num_boot_tmr; ++i) {
738  time = get_time_handles(tmr_pool, tmo_pool, worker->scd.q);
739  start_periodic(tmr_pool, time.tmr, odp_timeout_to_event(time.tmo), mul);
740  }
741 }
742 
743 static int process_periodic(void *args)
744 {
745  worker_config_t *worker = args;
746  odp_thrmask_t mask;
747  prog_config_t *config = worker->prog_config;
748  odp_time_t tm;
749  odp_atomic_u32_t *is_running = &config->is_running;
750  odp_event_t ev;
751  odp_timer_t tmr;
752  stats_t *stats = &worker->stats;
753  const uint64_t res_ns = prog_conf->opts.res_ns;
754  int ret;
755 
756  if (worker->scd.grp != ODP_SCHED_GROUP_INVALID) {
757  odp_thrmask_zero(&mask);
758  odp_thrmask_set(&mask, odp_thread_id());
759 
760  if (odp_schedule_group_join(worker->scd.grp, &mask) < 0)
761  ODPH_ABORT("Error joining scheduler group, aborting (group: %" PRIu64 ")"
762  "\n", odp_schedule_group_to_u64(worker->scd.grp));
763  }
764 
765  boot_periodic(worker, config->tmr_pool, config->tmo_pool, config->per_capa.max_multiplier);
766  odp_barrier_wait(&config->init_barrier);
767  tm = odp_time_local_strict();
768 
769  while (odp_atomic_load_u32(is_running)) {
770  ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT);
771 
772  if (ev == ODP_EVENT_INVALID)
773  continue;
774 
776 
777  if (odp_unlikely(odp_timer_periodic_ack(tmr, ev) < 0))
778  ODPH_ABORT("Error acking periodic timer, aborting (tmr: %" PRIx64 ")\n",
779  odp_timer_to_u64(tmr));
780 
781  ++stats->num_tmo;
782  }
783 
784  stats->tot_tm = odp_time_diff_ns(odp_time_local_strict(), tm);
785  odp_barrier_wait(&config->term_barrier);
786 
787  while (true) {
788  ev = odp_schedule(NULL, odp_schedule_wait_time(res_ns *
789  config->per_capa.max_multiplier *
790  WAIT_MULTIPLIER));
791 
792  if (ev == ODP_EVENT_INVALID)
793  break;
794 
795  /* Many workers might be trying to cancel the timer, do it exclusively. */
796  odp_spinlock_lock(&config->lock);
798  ret = odp_timer_periodic_ack(tmr, ev);
799 
800  if (ret < 0)
801  ODPH_ABORT("Error acking periodic timer, aborting (tmr: %" PRIx64 ")\n",
802  odp_timer_to_u64(tmr));
803 
804  if (ret == 1) {
805  odp_spinlock_unlock(&config->lock);
806  continue;
807  }
808 
809  if (ret == 2) {
810  odp_event_free(ev);
811  (void)odp_timer_free(tmr);
812  odp_spinlock_unlock(&config->lock);
813  continue;
814  }
815 
816  if (odp_timer_periodic_cancel(tmr) < 0)
817  ODPH_ABORT("Error cancelling periodic timer, aborting "
818  "(tmr: %" PRIx64 ")\n", odp_timer_to_u64(tmr));
819 
820  odp_spinlock_unlock(&config->lock);
821  }
822 
823  return 0;
824 }
825 
826 static void boot_cancel(worker_config_t *worker, odp_timer_pool_t tmr_pool, odp_pool_t tmo_pool,
827  uint64_t res_ns)
828 {
829  tmr_hdls_t time;
830 
831  for (uint32_t i = 0U; i < worker->num_boot_tmr; ++i) {
832  time = get_time_handles(tmr_pool, tmo_pool, worker->scd.q);
833  start_single_shot(tmr_pool, time.tmr, odp_timeout_to_event(time.tmo), res_ns,
834  &worker->stats);
835  worker->cancel.tmrs[i] = time;
836  }
837 }
838 
839 static int process_cancel(void *args)
840 {
841  worker_config_t *worker = args;
842  odp_thrmask_t mask;
843  prog_config_t *config = worker->prog_config;
844  odp_timer_pool_t tmr_pool = config->tmr_pool;
845  const uint64_t res_ns = prog_conf->opts.res_ns;
846  odp_time_t tm;
847  odp_atomic_u32_t *is_running = &config->is_running;
848  odp_event_t ev;
849  stats_t *stats = &worker->stats;
850  const uint32_t num_boot_tmr = worker->num_boot_tmr;
851  tmr_hdls_t *time;
852  int ret;
853  odp_timer_t tmr;
854 
855  odp_thrmask_zero(&mask);
856  odp_thrmask_set(&mask, odp_thread_id());
857 
858  if (odp_schedule_group_join(worker->scd.grp, &mask) < 0)
859  ODPH_ABORT("Error joining scheduler group, aborting (group: %" PRIu64 ")\n",
860  odp_schedule_group_to_u64(worker->scd.grp));
861 
862  boot_cancel(worker, tmr_pool, config->tmo_pool, res_ns);
863  odp_barrier_wait(&config->init_barrier);
864  tm = odp_time_local_strict();
865 
866  while (odp_atomic_load_u32(is_running)) {
867  ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT);
868 
869  if (odp_unlikely(ev != ODP_EVENT_INVALID)) {
870  start_single_shot(tmr_pool, odp_timeout_timer(odp_timeout_from_event(ev)),
871  ev, res_ns, stats);
872  ++stats->num_miss;
873  continue;
874  }
875 
876  for (uint32_t i = 0U; i < num_boot_tmr; ++i) {
877  time = &worker->cancel.tmrs[i];
878  ret = odp_timer_cancel(time->tmr, &ev);
879 
880  if (odp_unlikely(ret == ODP_TIMER_TOO_NEAR))
881  continue;
882 
883  if (odp_unlikely(ret == ODP_TIMER_FAIL))
884  ODPH_ABORT("Error cancelling timer, aborting (tmr: %" PRIx64 ")\n",
885  odp_timer_to_u64(time->tmr));
886 
887  time->is_running = false;
888  ++stats->num_tmo;
889  }
890 
891  for (uint32_t i = 0U; i < num_boot_tmr; ++i) {
892  time = &worker->cancel.tmrs[i];
893 
894  if (time->is_running)
895  continue;
896 
897  start_single_shot(tmr_pool, time->tmr, odp_timeout_to_event(time->tmo),
898  res_ns, stats);
899  time->is_running = true;
900  }
901  }
902 
903  stats->tot_tm = odp_time_diff_ns(odp_time_local_strict(), tm);
904  odp_barrier_wait(&config->term_barrier);
905 
906  while (true) {
907  ev = odp_schedule(NULL, odp_schedule_wait_time(stats->max_mul * res_ns *
908  WAIT_MULTIPLIER));
909 
910  if (ev == ODP_EVENT_INVALID)
911  break;
912 
914  odp_event_free(ev);
915  (void)odp_timer_free(tmr);
916  }
917 
918  return 0;
919 }
920 
921 static odp_bool_t setup_workers(prog_config_t *config)
922 {
923  odph_thread_common_param_t thr_common;
924  odph_thread_param_t thr_params[config->opts.num_workers], *thr_param;
925  worker_config_t *worker;
926  const uint32_t mode = config->opts.mode;
927  int (*start_fn)(void *) = mode == SINGLE_SHOT ? process_single_shot :
928  mode == PERIODIC ? process_periodic : process_cancel;
929 
930  odph_thread_common_param_init(&thr_common);
931  thr_common.instance = config->odp_instance;
932  thr_common.cpumask = &config->worker_mask;
933 
934  for (uint32_t i = 0; i < config->opts.num_workers; ++i) {
935  thr_param = &thr_params[i];
936  worker = &config->worker_config[i];
937  odph_thread_param_init(thr_param);
938  thr_param->start = start_fn;
939  thr_param->thr_type = ODP_THREAD_WORKER;
940  thr_param->arg = worker;
941  }
942 
943  if ((uint32_t)odph_thread_create(config->thread_tbl, &thr_common, thr_params,
944  config->opts.num_workers) != config->opts.num_workers) {
945  ODPH_ERR("Error configuring worker threads\n");
946  return false;
947  }
948 
949  return true;
950 }
951 
952 static odp_bool_t setup_test(prog_config_t *config)
953 {
954  return setup_config(config) && setup_workers(config);
955 }
956 
957 static void run_control(prog_config_t *config)
958 {
959  const uint32_t time_sec = config->opts.time_sec;
960  odp_atomic_u32_t *is_running = &config->is_running;
961 
962  odp_barrier_wait(&config->init_barrier);
963 
964  if (time_sec > 0U) {
965  sleep(time_sec);
966  odp_atomic_store_u32(is_running, 0U);
967  } else {
968  while (odp_atomic_load_u32(is_running))
969  sleep(1U);
970  }
971 
972  odp_barrier_wait(&config->term_barrier);
973  (void)odph_thread_join(config->thread_tbl, config->opts.num_workers);
974 }
975 
976 static void print_humanised(uint64_t value)
977 {
978  if (value > GIGAS)
979  printf("%.2f GOPS\n", (double)value / GIGAS);
980  else if (value > MEGAS)
981  printf("%.2f MOPS\n", (double)value / MEGAS);
982  else if (value > KILOS)
983  printf("%.2f kOPS\n", (double)value / KILOS);
984  else
985  printf("%" PRIu64 " OPS\n", value);
986 }
987 
988 static void print_stats(const prog_config_t *config)
989 {
990  const stats_t *stats;
991  const opts_t *opts = &config->opts;
992  uint64_t tot_tmo = 0U, tot_miss = 0U, tot_retry = 0U, max_mul = 0U, rate, tot_rate = 0U;
993 
994  printf("=====================\n\n"
995  "" PROG_NAME " done\n\n"
996  " mode: %s\n"
997  " clock source: %d\n"
998  " resolution: %" PRIu64 " ns\n"
999  " number of timers: %u (%s)\n\n", opts->mode == SINGLE_SHOT ? "single shot" :
1000  opts->mode == PERIODIC ?
1001  "periodic" : "single shot with cancel",
1002  opts->clk_src, opts->res_ns, opts->num_tmr,
1003  opts->policy == SHARED_TMR ? "shared" : "private");
1004 
1005  for (uint32_t i = 0U; i < config->opts.num_workers; ++i) {
1006  stats = &config->worker_config[i].stats;
1007  tot_tmo += stats->num_tmo;
1008  tot_miss += stats->num_miss;
1009  tot_retry += stats->num_retry;
1010  max_mul = ODPH_MAX(max_mul, stats->max_mul);
1011  rate = stats->num_tmo / ((double)stats->tot_tm / ODP_TIME_SEC_IN_NS);
1012  tot_rate += rate;
1013 
1014  printf(" worker %u:\n"
1015  " %s%" PRIu64 "\n", i,
1016  opts->mode == SINGLE_SHOT || opts->mode == PERIODIC ?
1017  "number of timeouts: " : "number of cancels: ",
1018  stats->num_tmo);
1019 
1020  if (opts->mode == SINGLE_SHOT || opts->mode == CANCEL) {
1021  if (opts->mode == CANCEL)
1022  printf(" number of misses: %" PRIu64 "\n", stats->num_miss);
1023 
1024  printf(" number of retries: %" PRIu64 "\n"
1025  " max start mul: %" PRIu64 "\n", stats->num_retry,
1026  stats->max_mul);
1027  }
1028 
1029  printf(" runtime: %" PRIu64 " ns\n"
1030  " rate: ", stats->tot_tm);
1031  print_humanised(rate);
1032  printf("\n");
1033  }
1034 
1035  printf(" total:\n"
1036  " %s%" PRIu64 "\n", opts->mode == SINGLE_SHOT || opts->mode == PERIODIC ?
1037  "number of timeouts: " : "number of cancels: ",
1038  tot_tmo);
1039 
1040  if (opts->mode == SINGLE_SHOT || opts->mode == CANCEL) {
1041  if (opts->mode == CANCEL)
1042  printf(" number of misses: %" PRIu64 "\n", tot_miss);
1043 
1044  printf(" number of retries: %" PRIu64 "\n"
1045  " max start mul: %" PRIu64 "\n", tot_retry, max_mul);
1046  }
1047 
1048  printf(" rate: ");
1049  print_humanised(tot_rate);
1050  printf("\n=====================\n");
1051 }
1052 
1053 static void teardown(const prog_config_t *config)
1054 {
1055  const opts_t *opts = &config->opts;
1056  const worker_config_t *worker;
1057 
1058  for (uint32_t i = 0U; i < opts->num_workers; ++i) {
1059  worker = &config->worker_config[i];
1060 
1061  if (worker->scd.q != ODP_QUEUE_INVALID)
1062  (void)odp_queue_destroy(worker->scd.q);
1063 
1064  if (worker->scd.grp != ODP_SCHED_GROUP_INVALID)
1065  (void)odp_schedule_group_destroy(worker->scd.grp);
1066  }
1067 
1068  if (config->cancel_shm != ODP_SHM_INVALID)
1069  (void)odp_shm_free(config->cancel_shm);
1070 
1071  if (config->tmr_pool != ODP_TIMER_POOL_INVALID)
1072  (void)odp_timer_pool_destroy(config->tmr_pool);
1073 
1074  if (config->tmo_pool != ODP_POOL_INVALID)
1075  (void)odp_pool_destroy(config->tmo_pool);
1076 }
1077 
1078 int main(int argc, char **argv)
1079 {
1080  odph_helper_options_t odph_opts;
1081  odp_init_t init_param;
1083  odp_shm_t shm_cfg = ODP_SHM_INVALID;
1084  int ret = EXIT_SUCCESS;
1085  parse_result_t parse_res;
1086 
1087  argc = odph_parse_options(argc, argv);
1088 
1089  if (odph_options(&odph_opts) == -1)
1090  ODPH_ABORT("Error while reading ODP helper options, aborting\n");
1091 
1092  odp_init_param_init(&init_param);
1093  init_param.mem_model = odph_opts.mem_model;
1094 
1095  if (odp_init_global(&odp_instance, &init_param, NULL))
1096  ODPH_ABORT("ODP global init failed, aborting\n");
1097 
1099  ODPH_ABORT("ODP local init failed, aborting\n");
1100 
1101  shm_cfg = odp_shm_reserve(PROG_NAME "_cfg", sizeof(prog_config_t), ODP_CACHE_LINE_SIZE,
1102  0U);
1103 
1104  if (shm_cfg == ODP_SHM_INVALID) {
1105  ODPH_ERR("Error reserving shared memory\n");
1106  ret = EXIT_FAILURE;
1107  goto out;
1108  }
1109 
1110  prog_conf = odp_shm_addr(shm_cfg);
1111 
1112  if (prog_conf == NULL) {
1113  ODPH_ERR("Error resolving shared memory address\n");
1114  ret = EXIT_FAILURE;
1115  goto out;
1116  }
1117 
1118  memset(prog_conf, 0, sizeof(*prog_conf));
1119  prog_conf->odp_instance = odp_instance;
1120  parse_res = setup_program(argc, argv, prog_conf);
1121 
1122  if (parse_res == PRS_NOK) {
1123  ret = EXIT_FAILURE;
1124  goto out;
1125  }
1126 
1127  if (parse_res == PRS_TERM) {
1128  ret = EXIT_SUCCESS;
1129  goto out;
1130  }
1131 
1132  if (!setup_test(prog_conf)) {
1133  ret = EXIT_FAILURE;
1134  goto out;
1135  }
1136 
1137  run_control(prog_conf);
1138  print_stats(prog_conf);
1139 
1140 out:
1141  teardown(prog_conf);
1142 
1143  if (shm_cfg != ODP_SHM_INVALID)
1144  (void)odp_shm_free(shm_cfg);
1145 
1146  if (odp_term_local())
1147  ODPH_ABORT("ODP local terminate failed, aborting\n");
1148 
1150  ODPH_ABORT("ODP global terminate failed, aborting\n");
1151 
1152  return ret;
1153 }
void odp_atomic_init_u32(odp_atomic_u32_t *atom, uint32_t val)
Initialize atomic uint32 variable.
uint32_t odp_atomic_load_u32(odp_atomic_u32_t *atom)
Load value of atomic uint32 variable.
void odp_atomic_store_u32(odp_atomic_u32_t *atom, uint32_t val)
Store value to atomic uint32 variable.
void odp_barrier_init(odp_barrier_t *barr, int count)
Initialize barrier with thread count.
void odp_barrier_wait(odp_barrier_t *barr)
Synchronize thread execution on barrier.
#define ODP_ALIGNED_CACHE
Defines type/struct/variable to be cache line size aligned.
#define odp_unlikely(x)
Branch unlikely taken.
Definition: spec/hints.h:64
#define ODP_UNUSED
Intentionally unused variables of functions.
Definition: spec/hints.h:54
#define ODP_CACHE_LINE_ROUNDUP(x)
Round up to cache line size.
int odp_cpumask_default_worker(odp_cpumask_t *mask, int num)
Default CPU mask for worker threads.
void odp_event_free(odp_event_t event)
Free event.
#define ODP_EVENT_INVALID
Invalid event.
int odp_instance(odp_instance_t *instance)
Get instance handle.
void odp_init_param_init(odp_init_t *param)
Initialize the odp_init_t to default values for all fields.
int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type)
Thread local ODP initialization.
int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params)
Global ODP initialization.
int odp_term_local(void)
Thread local ODP termination.
int odp_term_global(odp_instance_t instance)
Global ODP termination.
uint64_t odp_instance_t
ODP instance ID.
void odp_spinlock_lock(odp_spinlock_t *splock)
Acquire spin lock.
void odp_spinlock_init(odp_spinlock_t *splock)
Initialize spin lock.
void odp_spinlock_unlock(odp_spinlock_t *splock)
Release spin lock.
uint64_t odp_pool_to_u64(odp_pool_t hdl)
Get printable value for an odp_pool_t.
odp_pool_t odp_pool_create(const char *name, const odp_pool_param_t *param)
Create a pool.
int odp_pool_capability(odp_pool_capability_t *capa)
Query pool capabilities.
void odp_pool_param_init(odp_pool_param_t *param)
Initialize pool params.
int odp_pool_destroy(odp_pool_t pool)
Destroy a pool previously created by odp_pool_create()
#define ODP_POOL_INVALID
Invalid pool.
@ ODP_POOL_TIMEOUT
Timeout pool.
void odp_queue_param_init(odp_queue_param_t *param)
Initialize queue params.
#define ODP_QUEUE_INVALID
Invalid queue.
odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param)
Queue create.
int odp_queue_destroy(odp_queue_t queue)
Destroy ODP queue.
@ ODP_QUEUE_TYPE_SCHED
Scheduled queue.
int odp_schedule_group_t
Scheduler thread group.
int odp_schedule_group_join(odp_schedule_group_t group, const odp_thrmask_t *mask)
Join a schedule group.
int odp_schedule_group_destroy(odp_schedule_group_t group)
Schedule group destroy.
#define ODP_SCHED_GROUP_INVALID
Invalid scheduler group.
#define ODP_SCHED_NO_WAIT
Do not wait.
int odp_schedule_default_prio(void)
Default scheduling priority level.
int odp_schedule_config(const odp_schedule_config_t *config)
Global schedule configuration.
uint64_t odp_schedule_group_to_u64(odp_schedule_group_t group)
Get printable value for schedule group handle.
uint64_t odp_schedule_wait_time(uint64_t ns)
Schedule wait time.
odp_schedule_group_t odp_schedule_group_create(const char *name, const odp_thrmask_t *mask)
Schedule group create.
odp_event_t odp_schedule(odp_queue_t *from, uint64_t wait)
Schedule an event.
int odp_shm_free(odp_shm_t shm)
Free a contiguous block of shared memory.
#define ODP_SHM_INVALID
Invalid shared memory block.
int odp_shm_capability(odp_shm_capability_t *capa)
Query shared memory capabilities.
void * odp_shm_addr(odp_shm_t shm)
Shared memory block address.
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags)
Reserve a contiguous block of shared memory.
bool odp_bool_t
Boolean type.
double odp_fract_u64_to_dbl(const odp_fract_u64_t *fract)
Convert fractional number (u64) to double.
void odp_thrmask_set(odp_thrmask_t *mask, int thr)
Add thread to mask.
int odp_thread_id(void)
Get thread identifier.
void odp_thrmask_zero(odp_thrmask_t *mask)
Clear entire thread mask.
@ ODP_THREAD_WORKER
Worker thread.
@ ODP_THREAD_CONTROL
Control thread.
#define ODP_TIME_SEC_IN_NS
A second in nanoseconds.
odp_time_t odp_time_local_strict(void)
Current local time (strict)
uint64_t odp_time_diff_ns(odp_time_t t2, odp_time_t t1)
Time difference in nanoseconds.
int odp_timer_pool_start_multi(odp_timer_pool_t timer_pool[], int num)
Start timer pools.
odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
Timeout alloc.
int odp_timer_free(odp_timer_t timer)
Free a timer.
int odp_timer_periodic_start(odp_timer_t timer, const odp_timer_periodic_start_t *start_param)
Start a periodic timer.
odp_timeout_t odp_timeout_from_event(odp_event_t ev)
Get timeout handle from a ODP_EVENT_TIMEOUT type event.
#define ODP_TIMER_POOL_INVALID
Invalid timer pool handle.
int odp_timer_periodic_capability(odp_timer_clk_src_t clk_src, odp_timer_periodic_capability_t *capa)
Periodic timer capability.
odp_timer_pool_t odp_timer_pool_create(const char *name, const odp_timer_pool_param_t *params)
Create a timer pool.
odp_timer_t odp_timeout_timer(odp_timeout_t tmo)
Return timer handle for the timeout.
int odp_timer_cancel(odp_timer_t timer, odp_event_t *tmo_ev)
Cancel a timer.
int odp_timer_capability(odp_timer_clk_src_t clk_src, odp_timer_capability_t *capa)
Query timer capabilities per clock source.
uint64_t odp_timer_ns_to_tick(odp_timer_pool_t timer_pool, uint64_t ns)
Convert nanoseconds to timer ticks.
int odp_timer_periodic_ack(odp_timer_t timer, odp_event_t tmo_ev)
Acknowledge timeout from a periodic timer.
uint64_t odp_timeout_to_u64(odp_timeout_t tmo)
Get printable value for an odp_timeout_t.
odp_timer_clk_src_t
Clock sources for timer pools.
int odp_timer_start(odp_timer_t timer, const odp_timer_start_t *start_param)
Start a timer.
int odp_timer_res_capability(odp_timer_clk_src_t clk_src, odp_timer_res_capability_t *res_capa)
Timer resolution capability.
int odp_timer_periodic_cancel(odp_timer_t timer)
Cancel a periodic timer.
odp_event_t odp_timeout_to_event(odp_timeout_t tmo)
Convert timeout handle to event handle.
#define ODP_TIMEOUT_INVALID
Invalid timeout handle.
odp_timer_t odp_timer_alloc(odp_timer_pool_t timer_pool, odp_queue_t queue, const void *user_ptr)
Allocate a timer.
uint64_t odp_timer_pool_to_u64(odp_timer_pool_t timer_pool)
Get printable value for an odp_timer_pool_t.
#define ODP_TIMER_INVALID
Invalid timer handle.
uint64_t odp_timer_to_u64(odp_timer_t timer)
Get printable value for an odp_timer_t.
void odp_timer_pool_param_init(odp_timer_pool_param_t *param)
Initialize timer pool parameters.
void odp_timer_pool_destroy(odp_timer_pool_t timer_pool)
Destroy a timer pool.
@ ODP_TIMER_SUCCESS
Timer operation succeeded.
@ ODP_TIMER_TOO_NEAR
Timer operation failed, too near to the current time.
@ ODP_TIMER_FAIL
Timer operation failed.
@ ODP_TIMER_TYPE_PERIODIC
Periodic timer.
@ ODP_TIMER_TYPE_SINGLE
Single shot timer.
@ ODP_TIMER_TICK_REL
Relative ticks.
The OpenDataPlane API.
Unsigned 64 bit fractional number.
uint64_t integer
Integer part.
uint64_t denom
Denominator of the fraction part.
uint64_t numer
Numerator of the fraction part.
Global initialization parameters.
odp_mem_model_t mem_model
Application memory model.
uint32_t max_num
Maximum number of buffers of any size.
struct odp_pool_capability_t::@132 tmo
Timeout pool capabilities
Pool parameters.
uint32_t num
Number of buffers in the pool.
uint32_t cache_size
Maximum number of buffers cached locally per thread.
odp_pool_type_t type
Pool type.
struct odp_pool_param_t::@137 tmo
Parameters for timeout pools.
ODP Queue parameters.
odp_schedule_param_t sched
Scheduler parameters.
odp_queue_type_t type
Queue type.
odp_schedule_group_t group
Thread group.
odp_schedule_prio_t prio
Priority level.
Shared memory capabilities.
uint32_t max_blocks
Maximum number of shared memory blocks.
uint64_t max_size
Maximum memory block size in bytes.
odp_fract_u64_t min_base_freq_hz
Minimum supported base frequency value.
uint32_t max_timers
Maximum number of single shot timers in a pool.
uint32_t max_pools
Maximum number of timer pools for single shot timers (per clock source)
odp_fract_u64_t max_base_freq_hz
Maximum supported base frequency value.
uint64_t highest_res_ns
Highest timer resolution in nanoseconds.
odp_bool_t queue_type_sched
Scheduled queue destination support.
struct odp_timer_capability_t::@176 periodic
Periodic timer capabilities.
Periodic timer capability.
Periodic timer start parameters.
Timer pool parameters.
uint64_t res_ns
Timeout resolution in nanoseconds.
struct odp_timer_pool_param_t::@177 periodic
Periodic timer parameters.
odp_timer_type_t timer_type
Timer type.
uint64_t max_multiplier
Maximum base frequency multiplier.
odp_fract_u64_t base_freq_hz
Timer pool base frequency in hertz.
uint64_t min_tmo
Minimum relative timeout in nanoseconds.
uint32_t num_timers
Number of timers in the pool.
odp_timer_clk_src_t clk_src
Clock source for timers.
uint64_t max_tmo
Maximum relative timeout in nanoseconds.
Timer resolution capability.
Timer start parameters.
uint64_t tick
Expiration time in ticks.
odp_event_t tmo_ev
Timeout event.
odp_timer_tick_type_t tick_type
Tick type.