Commit fb50e73f authored by Test's avatar Test

irq-demo: add MONOTONIC clock mode for stats

MONOTONIC will provide better stats in the short term as we have no NTP adjustment but the internal oscillator of the PC will slowly drift and then the statistics will be worst.
REALTIME as a worst variance, but it will be always in sync. The user should also take into account that WR and host time should be properly syncrhonized to NTP in order to get comprehensive (below 1s) mean/min/max values.
parent acce51e1
......@@ -63,14 +63,32 @@ int disable_log_for_stats_engine(stats_engine engine)
return 0;
}
int add_usr_timestamp_to_stats_engine(stats_engine engine, struct usr_timestamp *ts)
static struct timespec ts_t0 = {0};
static int neg_t0=0;
int add_usr_timestamp_to_stats_engine(stats_engine engine, struct usr_timestamp *ts,clock_type sysclkt)
{
struct timespec system_ts;
if(check_stats_engine(engine))
return -EINVAL;
clock_gettime(CLOCK_REALTIME, &system_ts);
if(sysclkt==CLOCK_REALTIME)
{
clock_gettime(CLOCK_REALTIME, &system_ts);
}
else
{
clock_gettime(CLOCK_MONOTONIC, &system_ts);
if(ts_t0.tv_sec==0) //Set starting point t0 of monotonic time
{
neg_t0=timespec_subtract(&ts_t0, &(ts->t),&system_ts);
printf("ts_0=%ld . %ld\n",ts_t0.tv_sec,ts_t0.tv_nsec);
}
if(neg_t0) timespec_subtract(&(ts->t), &(ts_t0),&(ts->t));
else timespec_subtract(&(ts->t), &(ts->t),&(ts_t0));
}
engine->sys_ts[engine->next_ts] = system_ts;
engine->usr_ts[engine->next_ts] = *ts;
......
......@@ -15,6 +15,11 @@
#include "log-device.h"
#include "usr-timestamp.h"
typedef enum{
REALTIME=0,
MONOTONIC,
} clock_type;
typedef struct _stats_engine *stats_engine;
stats_engine create_stats_engine(void);
......@@ -25,7 +30,7 @@ void attach_log_devices_to_stats_engine(stats_engine engine,
int enable_log_for_stats_engine(stats_engine engine);
int disable_log_for_stats_engine(stats_engine engine);
int add_usr_timestamp_to_stats_engine(stats_engine engine,
struct usr_timestamp *ts);
struct usr_timestamp *ts,clock_type sysclkt);
int run_stats_engine(stats_engine engine, int verbose);
void destroy_stats_engine(stats_engine engine);
......
......@@ -13,6 +13,7 @@
#define __DEMO_IRQ_PRIVATE_H__
#include "usr-timestamp.h"
#include "stats-engine.h"
#define PROG_NAME "irq-demo"
#define TEST_FMC_DIO_CH 5
......@@ -21,11 +22,6 @@
#define STATS_LOG_PATH "./.irq-demo.log"
#define MAX_FMC_DIO_PATH 100
typedef enum{
MONOTONIC,
REALTIME
} clock_type;
struct _user_args {
char fmc_dev_path[MAX_FMC_DIO_PATH];
unsigned int irq_period;
......
......@@ -197,7 +197,7 @@ static void process_timestamps_to_engine(stats_engine engine, struct usr_timesta
for(int i = 0 ; i < nts_to_process ; i++) {
/* Pass a timestamp to stats engine */
add_usr_timestamp_to_stats_engine(engine, &ts_to_process[i]);
add_usr_timestamp_to_stats_engine(engine, &ts_to_process[i], global_user_arguments->clock);
/* Compute stats taking into consideration all the timestamps inside the engine */
run_stats_engine(engine, verbose_mode);
}
......@@ -239,10 +239,10 @@ static int parse_user_arguments(int argc, char *argv[], user_args parsed_args)
parsed_args->verbose = 1;
break;
case 'c':
if(strcmp(optarg,"REALTIME")==0)
parsed_args->clock=REALTIME;
else
if(strcmp(optarg,"MONOTONIC")==0)
parsed_args->clock=MONOTONIC;
else
parsed_args->clock=REALTIME;
break;
case 'h':
default:
......@@ -271,7 +271,7 @@ static void show_help(void)
printf("%s -f <FMC DIO device path> [options]\n", PROG_NAME);
printf("\t -f <path> \tSet FMC DIO device path\n");
printf("\t -p <period> \tSet IRQ period (in nanoseconds)\n");
printf("\t -c <MONOTONIC/REALTIME> \tSet the clock mode\n");
printf("\t -c <REALTIME/MONOTONIC> \tSet the clock mode (REALTIME by default)\n");
printf("\t -v \t\tEnable verbose mode\n");
printf("\t -h \t\tShow this help message\n");
printf("Please, press 'q' key + ENTER or CNTRL+C to exit from the demo tool\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment