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

Normalize jitter value for the server histogram

parent f30202f7
......@@ -40,6 +40,7 @@ typedef struct thread_stat {
} thread_stat_t;
typedef struct thread_param {
int interval;
int priority;
thread_stat_t stats;
......@@ -82,13 +83,14 @@ struct timespec measures_start;
struct timespec measures_end;
static void help(char *argv[]) {
printf("Usage: %s [-aghtv] [-b CLIENT_IP] [-d BUF_LEN] [-f IF] [-p PRIO] [-r USEC]\n\n", argv[0]);
printf("Usage: %s [-aghtv] [-b CLIENT_IP] [-d BUF_LEN] [-f IF] [-i USEC] [-p PRIO] [-r USEC]\n\n", argv[0]);
printf(" -a Run the real time thread on CPU1\n");
printf(" -b CLIENT_IP Server side RTT\n");
printf(" -d BUF_LEN Set the length of tx buffer\n");
printf(" -f IF Set the network interface to be used\n");
printf(" -g Print histograms to sdtout on exit\n");
printf(" -h Show help\n");
printf(" -i USEC Wake up the real time thread every USEC microseconds (Default: 10ms)\n");
printf(" -p PRIO Run the real time thread at priority PRIO\n");
printf(" -r USEC Refresh the non real time main thread every USEC microseconds\n");
printf(" -t Enable timestamps\n");
......@@ -105,6 +107,7 @@ static void *packet_receiving_thread(void *p) {
thread_stat_t *stats = &param->stats;
uint64_t diff = 0;
cpu_set_t mask;
int64_t dist_to_interval;
stats->min_interval = UINT64_MAX;
stats->max_interval = 0;
......@@ -142,12 +145,16 @@ static void *packet_receiving_thread(void *p) {
stats->min_interval = diff < stats->min_interval ? diff : stats->min_interval;
stats->max_interval = diff > stats->max_interval ? diff : stats->max_interval;
if( diff > MAX_HIST_VAL * 1000 ) {
fprintf(stderr, "jitter higher than MAX_HIST_VAL\n");
exit(EXIT_FAILURE);
}
else {
histograms[2][diff / 1000] = diff / 1000;
if(enable_histograms) {
dist_to_interval = (diff - param->interval) / 1000;
dist_to_interval += MAX_HIST_VAL / 2;
if( dist_to_interval > ((int)MAX_HIST_VAL) || dist_to_interval < 0 ) {
fprintf(stderr, "jitter higher than MAX_HIST_VAL\n");
exit(EXIT_FAILURE);
}
else {
histograms[2][dist_to_interval]++;
}
}
}
......@@ -172,6 +179,7 @@ int main(int argc, char *argv[]) {
stats = &param->stats;
// Default configuration values
param->interval = 100000 * 1000;
param->priority = 99;
enable_affinity = 0;
......@@ -243,7 +251,7 @@ static void print_histograms() {
duration_hour = duration / NSEC_PER_SEC / 3600;
duration_minutes = duration / NSEC_PER_SEC / 60 - duration_hour * 60;
interval = (param->stats.min_interval + param->stats.max_interval) / 2 / 1000;
interval = param->interval / 1000;
printf("{\"measure_sets\": [{"
"\"measure_type\": \"packet_recv_timestamps\","
......@@ -268,21 +276,28 @@ static void print_histograms() {
printf("%s", (i + 1 < 2 ? "], " : "]"));
}
max_hist_val = 0;
for (int j = 0; j < MAX_HIST_VAL && histograms[2][j]; j++)
max_hist_val = j;
min_hist_val = 0;
for (int j = MAX_HIST_VAL - 1; j >= 0 && histograms[2][j]; j--)
min_hist_val = j;
printf( "]}, {"
"\"measure_type\": \"packet_jitter\","
"\"props_names\": [\"jitter\"],"
"\"units\": [\"us\"],"
"\"props_type\": \"histogram\","
"\"middle\": \"%d\","
"\"metadata\": {"
"\"i\": \"%dus\", \"duration\": \"%dh%d\""
"},"
"\"props\": [[", interval, duration_hour, duration_minutes);
"\"props\": [[", interval,
MAX_HIST_VAL / 2 - min_hist_val,
duration_hour,
duration_minutes);
max_hist_val = 0;
for (int j = 0; j < MAX_HIST_VAL && histograms[2][j]; j++)
max_hist_val = j;
for (int j = 0; j < max_hist_val; j++)
for (int j = min_hist_val; j < max_hist_val; j++)
printf("%" PRIi64 "%s", histograms[2][j], (j + 1 < max_hist_val ? ", " : ""));
printf( "]]}]}\n");
......@@ -330,6 +345,9 @@ static void process_options(int argc, char *argv[]) {
help(argv);
exit(EXIT_SUCCESS);
break;
case 'i':
param->interval = atoi(optarg) * 1000;
break;
case 'g':
enable_histograms = 1;
break;
......
......@@ -10,8 +10,8 @@
#define NSEC_PER_SEC UINT64_C(1000000000)
#define SERVER_PORT "50000"
#define SERVER_PORT_INT 50000
#define MAX_HIST_VAL 1000
#define NB_HISTOGRAMS 2
#define MAX_HIST_VAL 2000
#define NB_HISTOGRAMS 3
typedef struct packet_timestamps {
uint64_t enter_user_space;
......
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