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