Commit 52325bb4 authored by Joanne Hugé's avatar Joanne Hugé

Add minimum latency measurement

parent 7c106519
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
typedef struct thread_stat { typedef struct thread_stat {
int nb_cycles; int nb_cycles;
int64_t max_diff; int64_t max_diff;
int64_t min_diff;
} thread_stat_t; } thread_stat_t;
typedef struct thread_param { typedef struct thread_param {
...@@ -41,6 +42,9 @@ static inline int64_t diff_ns(struct timespec t1, struct timespec t2) { ...@@ -41,6 +42,9 @@ static inline int64_t diff_ns(struct timespec t1, struct timespec t2) {
static inline int64_t max(int64_t a, int64_t b) { static inline int64_t max(int64_t a, int64_t b) {
return a > b ? a : b; return a > b ? a : b;
} }
static inline int64_t min(int64_t a, int64_t b) {
return a < b ? a : b;
}
static inline struct timespec add_ns(struct timespec t, int64_t ns) { static inline struct timespec add_ns(struct timespec t, int64_t ns) {
struct timespec ret; struct timespec ret;
...@@ -75,6 +79,7 @@ static void *timerthread(void *p) { ...@@ -75,6 +79,7 @@ static void *timerthread(void *p) {
error(EXIT_FAILURE, errno, "Couldn't set priority"); error(EXIT_FAILURE, errno, "Couldn't set priority");
stat->max_diff = 0; stat->max_diff = 0;
stat->min_diff = 1000000;
clock_gettime(CLOCK_ID, &next); clock_gettime(CLOCK_ID, &next);
next = add_ns(next, param->interval); next = add_ns(next, param->interval);
...@@ -88,7 +93,10 @@ static void *timerthread(void *p) { ...@@ -88,7 +93,10 @@ static void *timerthread(void *p) {
clock_nanosleep(CLOCK_ID, TIMER_ABSTIME, &next, NULL); clock_nanosleep(CLOCK_ID, TIMER_ABSTIME, &next, NULL);
clock_gettime(CLOCK_ID, &current); clock_gettime(CLOCK_ID, &current);
stat->max_diff = max(stat->max_diff, diff_ns(current, next)); int64_t diff = diff_ns(current, next);
stat->max_diff = max(stat->max_diff, diff);
stat->min_diff = min(stat->min_diff, diff);
next = add_ns(current, param->interval); next = add_ns(current, param->interval);
} }
...@@ -144,13 +152,14 @@ int main(int argc, char *argv[]) { ...@@ -144,13 +152,14 @@ int main(int argc, char *argv[]) {
process_options(argc, argv, &param, &main_param); process_options(argc, argv, &param, &main_param);
sleep(3); sleep(1);
pthread_create(&thread, NULL, timerthread, (void *)&param); pthread_create(&thread, NULL, timerthread, (void *)&param);
sleep(10); sleep(10);
printf("Maximum latency: %" PRIi64 "us (%d)\n", (param.stat.max_diff / 1000), param.stat.nb_cycles); printf("Maximum latency: %" PRIi64 "us (%d)\n", (param.stat.max_diff / 1000), param.stat.nb_cycles);
printf("Minimum latency: %" PRIi64 "us (%d)\n", (param.stat.min_diff / 1000), param.stat.nb_cycles);
//if(err) //if(err)
// error(EXIT_FAILURE, errno, "Couldn't create thread"); // error(EXIT_FAILURE, errno, "Couldn't create thread");
......
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