#include <stdio.h>
#include <stdint.h>
#include "main.h"
static volatile int timer_stop;
static uint64_t timer_start;
static void
{
double timer_end = (double)(
cne_rdtsc() - timer_start);
if (hz)
cne_printf(
"Single timer fired in [green]%.2f[] seconds on thread %d\n\n", timer_end / hz,
else
cne_printf(
"Single timer fired in [green]inf[] seconds on thread %d\n\n",
cne_id());
timer_stop = 1;
}
static void
{
int *count = arg;
double timer_end = (double)(
cne_rdtsc() - timer_start);
if (hz)
cne_printf(
"Periodical timer fired in [green]%.2f[] seconds on thread %d\n", timer_end / hz,
else
cne_printf(
"Periodical timer fired in [green]inf[] seconds on thread %d\n",
cne_id());
(*count)++;
if (*count > 10)
timer_stop = 1;
}
static int
timer_cmd(int argc, char **argv)
{
int count;
(void)argc;
(void)argv;
cne_printf(
"\nSet a single use timer for 2 seconds\n");
timer_stop = 0;
while (timer_stop == 0) {
}
count = 0;
cne_printf(
"\nSet a periodical timer for every 1/2 second\n");
timer_stop = 0;
while (timer_stop == 0) {
}
return 0;
}
static int
{
uint64_t count = 0, hz;
uint64_t tsc_start, tsc_end, delta;
tsc_end = tsc_start + hz;
count++;
delta = (tsc_end - tsc_start);
cne_printf(
"TSC start [blue]%lu[] - end [blue]%lu[] = [red]%lu[]\n", tsc_start, tsc_end, delta);
if (count)
cne_printf(
" loop count: [green]%lu[] ([green]%lu[]) cycles\n", count, delta / count);
else
cne_printf(
" loop count: [green]%lu[] ([green]inf[]) cycles\n", count);
count = 0;
tsc_end = tsc_start + hz;
count++;
delta = (tsc_end - tsc_start);
cne_printf(
"Precise TSC start [blue]%lu[] - end [blue]%lu[] = [red]%lu[]\n", tsc_start, tsc_end,
delta);
if (count)
cne_printf(
" loop count: [green]%lu[] ([green]%lu[]) cycles\n", count, delta / count);
else
cne_printf(
" loop count: [green]%lu[] ([green]inf[]) cycles\n", count);
return 0;
}
static struct cli_tree default_tree[] = {
c_cmd("timer", timer_cmd, "Run a timer test"),
c_cmd("perf", rdtsc_cmd, "Run a simple rdtsc performance test"),
c_end()
};
static int
init_tree(void)
{
return -1;
return -1;
return -1;
return 0;
}
static int
{
char buff[256];
int n;
n = snprintf(buff,
sizeof(buff),
"cndp-cli:%s> ",
cli_path_string(NULL, NULL));
return n;
}
static int
setup_cli(void)
{
return -1;
}
return -1;
}
vt_cls();
return 0;
}
int
main(int argc, char *argv[])
{
(void)argc;
(void)argv;
if (setup_cli() < 0)
return -1;
cli_start(
"CNDP Timer Example, use 'ls -rl' or 'chelp -a' to see all commands");
return 0;
}
static struct cli_node * cli_root_node(void)
static char * cli_path_string(struct cli_node *node, char *path)
CNDP_API int cli_default_tree_init(void)
CNDP_API void cli_start(const char *msg)
CNDP_API int cli_setup_with_tree(cli_tree_t tree)
CNDP_API void cli_destroy(void)
CNDP_API int cli_create(struct cli_cfg *cfg)
CNDP_API int cli_add_tree(struct cli_node *dir, struct cli_tree *tree)
CNDP_API int cli_add_bin_path(const char *path)
CNDP_API cli_prompt_t cli_set_prompt(cli_prompt_t prompt)
CNDP_API int cne_id(void)
static uint64_t cne_rdtsc_precise(void)
static uint64_t cne_rdtsc(void)
CNDP_API int cne_printf_pos(int16_t r, int16_t c, const char *fmt,...)
CNDP_API int cne_printf(const char *fmt,...)
CNDP_API int cne_lcore_id(void)
CNDP_API uint64_t cne_get_timer_hz(void)
int cne_timer_reset(struct cne_timer *tim, uint64_t ticks, enum cne_timer_type type, unsigned tim_thread, cne_timer_cb_t fct, void *arg)
int cne_timer_stop(struct cne_timer *tim)
void cne_timer_subsystem_init(void)
void cne_timer_init(struct cne_timer *tim)
void cne_timer_manage(void)
void cne_timer_dump_stats(FILE *f)