Skip to content

Commit

Permalink
test: update timer accuracy test program
Browse files Browse the repository at this point in the history
Signed-off-by: ywc689 <[email protected]>
  • Loading branch information
ywc689 committed Sep 19, 2023
1 parent af249ea commit d11db88
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <rte_cycles.h>
#include "global_data.h"

char *dpvs_pid_file;
char *dpvs_ipc_file;
char *dpvs_conf_file;

RTE_DEFINE_PER_LCORE(uint32_t, g_dpvs_poll_tick);

unsigned int g_version;
Expand Down
4 changes: 0 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@

#define LCORE_CONF_BUFFER_LEN 4096

char *dpvs_pid_file;
char *dpvs_ipc_file;
char *dpvs_conf_file;

static void inline dpdk_version_check(void)
{
#if RTE_VERSION < RTE_VERSION_NUM(20, 11, 1, 0)
Expand Down
52 changes: 44 additions & 8 deletions test/timer/timer_accuracy_test.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include <stdlib.h>
#include <unistd.h>
#include "dpdk.h"
#include "scheduler.h"
#include "cfgfile.h"
#include "timer.h"

#define RTE_TIMER_INT 500 /* us */
#define MAX_DELAY 16000 /* s, should be less than TIMER_MAX_TICKS/DPVS_TIMER_HZ */
#define RTE_TIMER_INT 500 /* us */
#define MAX_DELAY 16000 /* s, should be less than TIMER_MAX_TICKS/DPVS_TIMER_HZ */

static struct timeval g_start_time;
static int init_delay_sec;

static int lcore_loop(void *arg)
{
Expand All @@ -20,15 +23,22 @@ static int lcore_loop(void *arg)
static int timeup(void *arg)
{
struct timeval tv;
struct timeval now, elapsed;
struct timeval now, elapsed, delta;
struct dpvs_timer *tm = arg;

gettimeofday(&now, NULL);
timersub(&now, &g_start_time, &elapsed);
ticks_to_timeval(tm->delay, &tv);

fprintf(stdout, "timer timeout: %lu.%06lu, elapsed time: %lu.%06lu\n",
tv.tv_sec, tv.tv_usec, elapsed.tv_sec, elapsed.tv_usec);
if (timercmp(&tv, &elapsed, <)) {
timersub(&elapsed, &tv, &delta);
} else {
timersub(&tv, &elapsed, &delta);
}

fprintf(stderr, "[%02d] timer timeout: %lu.%06lu, elapsed time: %lu.%06lu, "
"diff: %lu.%06lu\n", rte_lcore_id(), tv.tv_sec, tv.tv_usec,
elapsed.tv_sec, elapsed.tv_usec, delta.tv_sec, delta.tv_usec);

rte_free(tm);

Expand All @@ -38,9 +48,13 @@ static int timeup(void *arg)
int main(int argc, char *argv[])
{
int i, err;
struct timeval delay;
struct timeval delay, elapsed;
struct dpvs_timer *timer;

gettimeofday(&delay, NULL);
srandom(delay.tv_usec ^ getpid());
init_delay_sec = random() % 53 + 7;

/* init */
err = rte_eal_init(argc, argv);
if (err < 0) {
Expand All @@ -49,6 +63,18 @@ int main(int argc, char *argv[])
}
rte_timer_subsystem_init();

err = dpvs_scheduler_init();
if (err) {
fprintf(stderr, "dpvs_scheduler_init failed\n");
return 1;
}

err = global_data_init();
if (err) {
fprintf(stderr, "global_data_init failed\n");
return 1;
}

err = cfgfile_init();
if (err) {
fprintf(stderr, "cfgfile_init failed\n");
Expand All @@ -61,10 +87,20 @@ int main(int argc, char *argv[])
return 1;
}

rte_eal_mp_remote_launch(lcore_loop, NULL, SKIP_MASTER);
rte_eal_mp_remote_launch(lcore_loop, NULL, SKIP_MAIN);

/* delay for some time before scheduling timers */
fprintf(stderr, "delay %d seconds ..\n", init_delay_sec);
while (1) {
rte_timer_manage();
gettimeofday(&g_start_time, NULL);
timersub(&g_start_time, &delay, &elapsed);
if (elapsed.tv_sec > init_delay_sec)
break;
usleep(RTE_TIMER_INT);
}

/* start timer */
gettimeofday(&g_start_time, NULL);
for (i = 1; i < MAX_DELAY; i++) {
timer = rte_zmalloc("timer", sizeof(struct dpvs_timer), 0);
if (!timer) {
Expand Down

0 comments on commit d11db88

Please sign in to comment.