Commit 46b1a368 authored by Miguel Jimenez Lopez's avatar Miguel Jimenez Lopez

sw: Create usr-timestamp structure and use new fields for leap-seconds

FMC DIO device supports leap seconds fields for the timestamps. A new
usr-timestamp type has been created to deal with differences between timespec
and new FMC DIO timestamps.
- New fields for leap-seconds in fmc-dio-device driver
- Create usr-timestamp type for irq-demo
- Conversion mechanism from fmc-dio timestamp to usr-timestamp
parent 42f4584e
......@@ -12,6 +12,7 @@
#ifndef __FMC_DIO_DEVICE_PRIVATE_H__
#define __FMC_DIO_DEVICE_PRIVATE_H__
#include "usr-timestamp.h"
#include "../../kernel/fmc-dio.h"
#define MAX_TMP_BUF 1024
......@@ -43,7 +44,7 @@ static int setup_fmc_dio_device_hw_irq(fmc_dio_device dev,
long count);
static int get_hw_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
struct timespec **ts, unsigned int *nts);
struct usr_timestamp **ts, unsigned int *nts);
static int get_kernel_leaps_info(fmc_dio_device dev);
static void log_msg(fmc_dio_device dev, const char *msg);
......
......@@ -215,7 +215,7 @@ static int setup_fmc_dio_device_hw_irq(fmc_dio_device dev,
}
int get_tai_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
struct timespec **ts, unsigned int *nts)
struct usr_timestamp **ts, unsigned int *nts)
{
if(check_fmc_dio_device(dev))
return -EINVAL;
......@@ -224,10 +224,11 @@ int get_tai_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
}
int get_utc_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
struct timespec **ts, unsigned int *nts)
struct usr_timestamp **ts, unsigned int *nts)
{
int ret;
int tai;
struct timespec *t;
ret = get_tai_ts_from_fmc_dio_device(dev, ch, ts, nts);
if(ret)
......@@ -235,14 +236,16 @@ int get_utc_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
tai = get_kernel_leaps_info(dev);
for(int i = 0 ; i < *nts ; i++)
(*ts)[i].tv_sec -= tai;
for(int i = 0 ; i < *nts ; i++) {
t = &((*ts)[i].t);
t->tv_sec -= tai;
}
return ret;
}
static int get_hw_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
struct timespec **ts, unsigned int *nts)
struct usr_timestamp **ts, unsigned int *nts)
{
struct wr_dio_cmd *c = &dev->cmd;
int ret;
......@@ -261,12 +264,16 @@ static int get_hw_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
}
*nts = c->nstamp;
*ts = calloc(c->nstamp, sizeof(struct timespec));
*ts = calloc(c->nstamp, sizeof(struct usr_timestamp));
if(!*ts)
return -ENOMEM;
for(int i = 0 ; i < c->nstamp ; i++) {
(*ts)[i] = c->t[i];
(*ts)[i].t = (c->t[i]);
(*ts)[i].leap_second = (c->wr_ts_info_buf[i]).leap_second;
(*ts)[i].leap_second_valid = (c->wr_ts_info_buf[i]).leap_second_valid;
(*ts)[i].flag59 = (c->wr_ts_info_buf[i]).flag59;
(*ts)[i].flag61 = (c->wr_ts_info_buf[i]).flag61;
}
dev->total_n_ts += c->nstamp;
......
......@@ -12,9 +12,8 @@
#ifndef __FMC_DIO_DEVICE_H__
#define __FMC_DIO_DEVICE_H__
#include <time.h>
#include "log-device.h"
#include "usr-timestamp.h"
typedef struct fmc_dio_dev * fmc_dio_device;
......@@ -37,9 +36,9 @@ int setup_fmc_dio_device_irq(fmc_dio_device dev,
long count);
int get_tai_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
struct timespec **ts, unsigned int *nts);
struct usr_timestamp **ts, unsigned int *nts);
int get_utc_ts_from_fmc_dio_device(fmc_dio_device dev, int ch,
struct timespec **ts, unsigned int *nts);
struct usr_timestamp **ts, unsigned int *nts);
unsigned int get_total_n_timestamps(fmc_dio_device dev);
unsigned int get_partial_n_timestamps(fmc_dio_device dev);
......
......@@ -12,6 +12,8 @@
#ifndef __STATS_ENGINE_PRIVATE_H__
#define __STATS_ENGINE_PRIVATE_H__
#include "usr-timestamp.h"
#define MAX_TS 1000
#define NS_IN_A_SEC 1000000000
#define MAX_TMP_BUF 1024
......@@ -24,7 +26,7 @@ struct ts_stats {
};
struct _stats_engine {
struct timespec usr_ts[MAX_TS];
struct usr_timestamp usr_ts[MAX_TS];
struct timespec sys_ts[MAX_TS];
double diff_ts[MAX_TS];
struct ts_stats stats;
......@@ -58,7 +60,7 @@ static double compute_stdev(const double *values,
const unsigned int n_values,
const double mean);
static int compute_ts_per_second(const int sec,
const struct timespec *ts,
const struct usr_timestamp *ts,
const unsigned int n_ts);
#endif
......@@ -63,7 +63,7 @@ int disable_log_for_stats_engine(stats_engine engine)
return 0;
}
int add_usr_timestamp_to_stats_engine(stats_engine engine, struct timespec *ts)
int add_usr_timestamp_to_stats_engine(stats_engine engine, struct usr_timestamp *ts)
{
struct timespec system_ts;
......@@ -90,11 +90,11 @@ int run_stats_engine(stats_engine engine, int verbose)
return -EINVAL;
neg = timespec_subtract(&ts, &engine->sys_ts[engine->current_ts],
&engine->usr_ts[engine->current_ts]);
&(engine->usr_ts[engine->current_ts].t));
engine->diff_ts[engine->current_ts] = ((neg) ? -1.0 : 1.0)*(ts.tv_sec + ((double) ts.tv_nsec / NS_IN_A_SEC));
engine->stats.mean = compute_mean(engine->diff_ts, engine->n_ts);
engine->stats.std = compute_stdev(engine->diff_ts, engine->n_ts, engine->stats.mean);
count_ts = compute_ts_per_second(engine->usr_ts[engine->current_ts].tv_sec,
count_ts = compute_ts_per_second(engine->usr_ts[engine->current_ts].t.tv_sec,
engine->usr_ts, engine->n_ts);
if(count_ts != -1)
engine->stats.ts_per_second = count_ts;
......@@ -141,9 +141,13 @@ static void log_stats_engine(stats_engine engine, int verbose)
LOG(engine, "\tsys_ts[%d]: sec %ld, nsec %ld",
i, engine->sys_ts[i].tv_sec,
engine->sys_ts[i].tv_nsec);
LOG(engine, "\twr_ts[%d]: sec %ld, nsec %ld",
i, engine->usr_ts[i].tv_sec,
engine->usr_ts[i].tv_nsec);
LOG(engine, "\twr_ts[%d]: sec %ld, nsec %ld [ls_valid: %d, ls: %d, l59: %d, l61: %d]",
i, engine->usr_ts[i].t.tv_sec,
engine->usr_ts[i].t.tv_nsec,
engine->usr_ts[i].leap_second_valid,
engine->usr_ts[i].leap_second,
engine->usr_ts[i].flag59,
engine->usr_ts[i].flag61);
LOG(engine, "\tdiff[%d]: diff %f",
i, engine->diff_ts[i]);
}
......@@ -264,7 +268,7 @@ static double compute_stdev(const double *values,
}
static int compute_ts_per_second(const int sec,
const struct timespec *ts,
const struct usr_timestamp *ts,
const unsigned int n_ts)
{
static int prev_sec = -1;
......@@ -277,7 +281,7 @@ static int compute_ts_per_second(const int sec,
if(prev_sec != sec) {
count = 0;
for(int i = 0 ; i < n_ts ; i++) {
if(ts[i].tv_sec == prev_sec)
if(ts[i].t.tv_sec == prev_sec)
count++;
}
prev_sec = sec;
......
......@@ -12,9 +12,8 @@
#ifndef __STATS_ENGINE_H__
#define __STATS_ENGINE_H__
#include <time.h>
#include "log-device.h"
#include "usr-timestamp.h"
typedef struct _stats_engine *stats_engine;
......@@ -26,7 +25,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 timespec *ts);
struct usr_timestamp *ts);
int run_stats_engine(stats_engine engine, int verbose);
void destroy_stats_engine(stats_engine engine);
......
......@@ -12,6 +12,8 @@
#ifndef __DEMO_IRQ_PRIVATE_H__
#define __DEMO_IRQ_PRIVATE_H__
#include "usr-timestamp.h"
#define PROG_NAME "irq-demo"
#define TEST_FMC_DIO_CH 5
#define TEST_FMC_DIO_COUNT -1
......@@ -27,7 +29,7 @@ struct _user_args {
typedef struct _user_args * user_args;
static void demo_irq_process_loop(fmc_dio_device fmc_dev, stats_engine engine);
static void process_timestamps_to_engine(stats_engine engine, struct timespec *ts,
static void process_timestamps_to_engine(stats_engine engine, struct usr_timestamp *ts,
unsigned int nts);
static user_args create_user_arguments(void);
......
......@@ -159,7 +159,7 @@ out_log:
static void demo_irq_process_loop(fmc_dio_device fmc_dev, stats_engine engine)
{
struct timespec *ts;
struct usr_timestamp *ts;
unsigned int nts;
/* Process loop:
......@@ -173,7 +173,7 @@ static void demo_irq_process_loop(fmc_dio_device fmc_dev, stats_engine engine)
}
}
static void process_timestamps_to_engine(stats_engine engine, struct timespec *ts,
static void process_timestamps_to_engine(stats_engine engine, struct usr_timestamp *ts,
unsigned int nts)
{
for(int i = 0 ; i < nts ; i++) {
......
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