Skip to content

Commit

Permalink
example: sysinfo: print timer pool tick information
Browse files Browse the repository at this point in the history
Print timer pool tick info from odp_timer_pool_info().

Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
  • Loading branch information
MatiasElo committed Sep 12, 2023
1 parent 528a2dc commit 73297c1
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions example/sysinfo/odp_sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ typedef struct {
typedef struct {
int num_pktio;
pktio_t pktio[MAX_IFACES];
int num_timer;
odp_timer_capability_t timer[ODP_CLOCK_NUM_SRC];
struct {
odp_timer_capability_t capa[ODP_CLOCK_NUM_SRC];
odp_timer_pool_info_t pool_info[ODP_CLOCK_NUM_SRC];
int num;
} timer;
} appl_args_t;

/* Check that prints can use %u instead of %PRIu32 */
Expand Down Expand Up @@ -538,8 +541,13 @@ static void print_proto_stats_capa(appl_args_t *appl_args)
static int timer_capability(appl_args_t *appl_args)
{
for (int i = 0; i < ODP_CLOCK_NUM_SRC; i++) {
int ret = odp_timer_capability(i, &appl_args->timer[appl_args->num_timer]);
int ret;
odp_timer_pool_t pool;
odp_timer_pool_param_t params;
odp_timer_capability_t *capa = &appl_args->timer.capa[appl_args->timer.num];
odp_timer_pool_info_t *info = &appl_args->timer.pool_info[appl_args->timer.num];

ret = odp_timer_capability(i, capa);
if (ret && i == ODP_CLOCK_DEFAULT) {
ODPH_ERR("odp_timer_capability() failed for default clock source: %d\n",
ret);
Expand All @@ -551,15 +559,38 @@ static int timer_capability(appl_args_t *appl_args)
ODPH_ERR("odp_timer_capability() failed: %d\n", ret);
return -1;
}
appl_args->num_timer++;

odp_timer_pool_param_init(&params);
params.clk_src = i;
params.res_ns = capa->max_res.res_ns;
params.min_tmo = capa->max_res.min_tmo;
params.max_tmo = capa->max_res.max_tmo;
params.num_timers = 1;

pool = odp_timer_pool_create("timer_pool", &params);
if (pool == ODP_TIMER_POOL_INVALID) {
ODPH_ERR("odp_timer_pool_create() failed for clock source: %d\n", i);
return -1;
}

ret = odp_timer_pool_info(pool, info);
if (ret) {
ODPH_ERR("odp_timer_pool_info() failed: %d\n", ret);
return -1;
}

odp_timer_pool_destroy(pool);

appl_args->timer.num++;
}
return 0;
}

static void print_timer_capa(appl_args_t *appl_args)
{
for (int i = 0; i < appl_args->num_timer; i++) {
odp_timer_capability_t *capa = &appl_args->timer[i];
for (int i = 0; i < appl_args->timer.num; i++) {
odp_timer_capability_t *capa = &appl_args->timer.capa[i];
odp_timer_pool_info_t *info = &appl_args->timer.pool_info[i];

printf("\n");
printf(" TIMER (SRC %d)\n", i);
Expand Down Expand Up @@ -591,6 +622,19 @@ static void print_timer_capa(appl_args_t *appl_args)
capa->periodic.max_base_freq_hz.integer,
capa->periodic.max_base_freq_hz.numer,
capa->periodic.max_base_freq_hz.denom);
printf(" timer pool tick info (max_res)\n");
printf(" freq: %" PRIu64 " %" PRIu64 "/%" PRIu64 " Hz\n",
info->tick_info.freq.integer,
info->tick_info.freq.numer,
info->tick_info.freq.denom);
printf(" nsec: %" PRIu64 " %" PRIu64 "/%" PRIu64 " ns\n",
info->tick_info.nsec.integer,
info->tick_info.nsec.numer,
info->tick_info.nsec.denom);
printf(" clk_cycle: %" PRIu64 " %" PRIu64 "/%" PRIu64 " cycles\n",
info->tick_info.clk_cycle.integer,
info->tick_info.clk_cycle.numer,
info->tick_info.clk_cycle.denom);
}
}

Expand Down

0 comments on commit 73297c1

Please sign in to comment.