Commit d9ef8c97 authored by Joanne Hugé's avatar Joanne Hugé

Store max latency only and add a refresh option

parent 70739230
......@@ -2,3 +2,4 @@
*.d
simple-server/build/main
simple-client/build/main
latency-measure/build/main
......@@ -15,7 +15,7 @@
typedef struct thread_stat {
int nb_cycles;
int64_t diff;
int64_t max_diff;
} thread_stat_t;
typedef struct thread_param {
......@@ -25,6 +25,10 @@ typedef struct thread_param {
thread_stat_t stat;
} thread_param_t;
typedef struct main_param {
int refresh_rate;
} main_param_t;
static inline int64_t diff_ns(struct timespec t1, struct timespec t2) {
int64_t diff;
......@@ -34,6 +38,10 @@ static inline int64_t diff_ns(struct timespec t1, struct timespec t2) {
return diff;
}
static inline int64_t max(int64_t a, int64_t b) {
return a > b ? a : b;
}
static inline struct timespec add_ns(struct timespec t, int64_t ns) {
struct timespec ret;
......@@ -66,6 +74,8 @@ static void *timerthread(void *p) {
if (err)
error(EXIT_FAILURE, errno, "Couldn't set priority");
stat->max_diff = 0;
clock_gettime(CLOCK_ID, &next);
next = add_ns(next, param->interval);
......@@ -78,7 +88,7 @@ static void *timerthread(void *p) {
clock_nanosleep(CLOCK_ID, TIMER_ABSTIME, &next, NULL);
clock_gettime(CLOCK_ID, &current);
stat->diff = diff_ns(current, next);
stat->max_diff = max(stat->max_diff, diff_ns(current, next));
next = add_ns(current, param->interval);
}
......@@ -86,11 +96,11 @@ static void *timerthread(void *p) {
return NULL;
}
static void process_options(int argc, char *argv[], thread_param_t * param) {
static void process_options(int argc, char *argv[], thread_param_t * param, main_param_t * main_param) {
for(;;) {
int c = getopt(argc, argv, "l:p:i:");
int c = getopt(argc, argv, "l:p:i:r:");
if(c == -1)
break;
......@@ -103,7 +113,10 @@ static void process_options(int argc, char *argv[], thread_param_t * param) {
param->max_cycles = atoi(optarg);
break;
case 'i':
param->interval = atoi(optarg);
param->interval = (atoi(optarg) * 1000);
break;
case 'r':
main_param->refresh_rate = atoi(optarg);
break;
default:
exit(EXIT_FAILURE);
......@@ -118,13 +131,16 @@ int main(int argc, char *argv[]) {
pthread_t thread;
thread_param_t param;
main_param_t main_param;
// Default values
param.interval = NSECS_PER_SECOND;
param.max_cycles = 100;
param.priority = 80;
process_options(argc, argv, &param);
main_param.refresh_rate = 10000;
process_options(argc, argv, &param, &main_param);
int err =
pthread_create(&thread, NULL, timerthread, (void *)&param);
......@@ -134,9 +150,9 @@ int main(int argc, char *argv[]) {
for (;;) {
usleep(100000);
usleep(main_param.refresh_rate);
printf("Diff: %" PRIi64 "us (%d)\n", (param.stat.diff / 1000), param.stat.nb_cycles);
printf("Maximum latency: %" PRIi64 "us (%d)\n", (param.stat.max_diff / 1000), param.stat.nb_cycles);
if( param.max_cycles == param.stat.nb_cycles )
break;
......
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