Commit 75b4ef10 authored by Joanne Hugé's avatar Joanne Hugé

Clean up the code

parent 10a4b9d7
......@@ -25,6 +25,8 @@
// Structs
enum TSNTask { SEND_PACKET_TASK, RTT_TASK };
typedef struct rtt_stat {
int min_rtt;
......@@ -62,24 +64,25 @@ static uint64_t nb_cycles;
static main_param_t main_params;
static thread_param_t thread_params;
static rtt_stat_t rtt_stats;
static egress_stat_t egress_stats;
static egress_param_t egress_params;
static ingress_stat_t ingress_stats;
static ingress_param_t ingress_params;
static rtt_stat_t rtt_stats = {.min_rtt = INT_MAX};
static egress_stat_t egress_stats = {.min_kernel_latency = INT_MAX};
static ingress_stat_t ingress_stats = {.min_kernel_latency = INT_MAX,
.min_interval = INT_MAX};
static int enable_histograms;
static int enable_affinity;
static int enable_etf;
static int enable_timestamps;
enum TSNTask { SEND_PACKET_TASK, RTT_TASK };
static enum TSNTask tsn_task;
struct timespec measures_start;
struct timespec measures_end;
static struct timespec measures_start;
static struct timespec measures_end;
char send_data[MAX_BUFFER_SIZE];
static char send_data[MAX_BUFFER_SIZE];
static void help(char *argv[]) {
printf("Usage: %s -f IF [-abthgv] [-e ETF_OFFSET] [-d BUF_LEN] [-i USEC] [-l N] [-p PRIO] [-q PACKET_PRIO] [-r USEC]\n\n", argv[0]);
......@@ -100,10 +103,11 @@ static void help(char *argv[]) {
printf("\n");
}
// Real-time thread
// Sends packets at a regular intervall
/*
* Real-time thread: Sends packets at a regular intervall
*/
static void *packet_sending_thread(void *p) {
(void) p;
(void)p;
struct timespec next;
uint64_t next_txtime;
struct sched_param priority;
......@@ -133,11 +137,12 @@ static void *packet_sending_thread(void *p) {
clock_gettime(CLOCK_MONOTONIC, &next);
clock_gettime(CLOCK_MONOTONIC, &measures_start);
// Packet sending loop
for (nb_cycles = 0;; nb_cycles++) {
if (thread_params.max_cycles)
if (nb_cycles >= ((unsigned int)thread_params.max_cycles))
break;
if (thread_params.max_cycles &&
nb_cycles >= ((unsigned int)thread_params.max_cycles))
break;
sprintf(send_data, "%d", (int)(nb_cycles % 1000));
do_tsn_task(send_data, next_txtime);
......@@ -153,15 +158,13 @@ static void *packet_sending_thread(void *p) {
return NULL;
}
// Main thread, has non-real time priority
// Handles the IO and creates real time threads
/*
* Main thread, has non-real time priority
* Handles the IO and creates the real time thread
*/
int main(int argc, char *argv[]) {
pthread_t thread;
egress_stats.min_kernel_latency = INT_MAX;
egress_stats.avg_kernel_latency = 0;
egress_stats.max_kernel_latency = 0;
// Default configuration values
thread_params.interval = 100000 * 1000;
thread_params.max_cycles = 0;
......
......@@ -161,7 +161,7 @@ void recv_udp_packet() {
stats->min_kernel_latency = min(kernel_latency, stats->min_kernel_latency);
stats->max_kernel_latency = max(kernel_latency, stats->max_kernel_latency);
stats->avg_kernel_latency = (stats->max_kernel_latency * (stats->packets_received) + kernel_latency) / (stats->packets_received+1);
stats->avg_kernel_latency = (stats->max_kernel_latency * (stats->packets_received) + kernel_latency) / (stats->packets_received + 1);
if (use_histogram) {
if (kernel_latency > MAX_KERNEL_LATENCY)
......
......@@ -22,8 +22,9 @@ typedef struct ingress_stat {
int avg_interval;
int max_interval;
uint64_t high_kernel_latency;
uint64_t packets_received;
uint64_t high_kernel_latency;
uint64_t high_jitter;
int lost_packets;
char data[MAX_BUFFER_SIZE];
......
......@@ -224,7 +224,7 @@ static void process_error_queue() {
stats->min_kernel_latency = min(kernel_latency, stats->min_kernel_latency);
stats->max_kernel_latency = max(kernel_latency, stats->max_kernel_latency);
stats->avg_kernel_latency = (stats->max_kernel_latency * packets_sent + kernel_latency) / (packets_sent+1);
stats->avg_kernel_latency = (stats->max_kernel_latency * packets_sent + kernel_latency) / (packets_sent + 1);
if (use_histogram) {
if (kernel_latency > MAX_KERNEL_LATENCY)
......
......@@ -31,6 +31,8 @@
// Structs
enum TSNTask { RECV_PACKET_TASK, RTT_TASK };
typedef struct thread_param {
int interval;
int priority;
......@@ -53,20 +55,21 @@ static uint64_t jitter_hist[MAX_JITTER];
static main_param_t main_params;
static thread_param_t thread_params;
static ingress_stat_t ingress_stats;
static ingress_param_t ingress_params;
static egress_stat_t egress_stats;
static egress_param_t egress_params;
static egress_stat_t egress_stats = {.min_kernel_latency = INT_MAX};
static ingress_stat_t ingress_stats = {.min_kernel_latency = INT_MAX,
.min_interval = INT_MAX};
static int enable_histograms;
static int enable_affinity;
static int enable_timestamps;
enum TSNTask { RECV_PACKET_TASK, RTT_TASK };
static enum TSNTask tsn_task;
struct timespec measures_start;
struct timespec measures_end;
static struct timespec measures_start;
static struct timespec measures_end;
static void help(char *argv[]) {
printf("Usage: %s [-aghtv] [-b CLIENT_IP] [-d BUF_LEN] [-f IF] [-i USEC] [-p PRIO] [-r USEC]\n\n", argv[0]);
......@@ -87,14 +90,14 @@ static void help(char *argv[]) {
// Real-time thread
// Measures intervals between packet receptions
static void *packet_receiving_thread(void *p) {
(void) p;
(void)p;
struct timespec current, previous;
struct sched_param priority;
cpu_set_t mask;
int prev_packet_id = 0;
// Set thread CPU affinity
if (enable_affinity) {
// Set thread CPU affinity
CPU_ZERO(&mask);
CPU_SET(1, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
......@@ -107,6 +110,7 @@ static void *packet_receiving_thread(void *p) {
error(EXIT_FAILURE, errno, "Couldn't set priority");
clock_gettime(CLOCK_MONOTONIC, &measures_start);
// Packet receiving loop
for (ingress_stats.packets_received = 0;; ingress_stats.packets_received++) {
......@@ -130,7 +134,7 @@ static void *packet_receiving_thread(void *p) {
ingress_stats.min_interval = min(interval_us, ingress_stats.min_interval);
ingress_stats.max_interval = max(interval_us, ingress_stats.max_interval);
ingress_stats.avg_interval = (ingress_stats.avg_interval * ingress_stats.packets_received + interval_us) / (ingress_stats.packets_received+1);
ingress_stats.avg_interval = (ingress_stats.avg_interval * ingress_stats.packets_received + interval_us) / (ingress_stats.packets_received + 1);
// Check if packets were lost
ingress_stats.lost_packets += (current_packet_id - prev_packet_id - 1) % 1000;
......@@ -140,7 +144,7 @@ static void *packet_receiving_thread(void *p) {
dist_to_interval += MAX_JITTER / 2;
if (dist_to_interval > ((int)MAX_JITTER) || dist_to_interval < 0)
fprintf(stderr, "jitter higher than MAX_JITTER: %d\n", dist_to_interval);
ingress_stats.high_jitter++;
else
jitter_hist[dist_to_interval]++;
}
......@@ -169,7 +173,6 @@ int main(int argc, char *argv[]) {
ingress_stats.packets_received = 0;
// Default configuration values
thread_params.interval = 100000 * 1000;
thread_params.priority = 99;
......
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