Commit 52742c4d authored by Joanne Hugé's avatar Joanne Hugé

WIP: rewrite and clean up code

parent b4ea36fe
...@@ -62,8 +62,8 @@ static int nb_cycles; ...@@ -62,8 +62,8 @@ static int nb_cycles;
static main_param_t main_params; static main_param_t main_params;
static thread_param_t thread_params; static thread_param_t thread_params;
static rtt_stat_t rtt_stats; static rtt_stat_t rtt_stats;
static egress_stat_t * egress_stats; static egress_stat_t egress_stats;
static egress_param_t * egress_params; static egress_param_t egress_params;
static int enable_histograms; static int enable_histograms;
static int enable_affinity; static int enable_affinity;
...@@ -168,14 +168,14 @@ int main(int argc, char *argv[]) { ...@@ -168,14 +168,14 @@ int main(int argc, char *argv[]) {
enable_histograms = 0; enable_histograms = 0;
tsn_task = SEND_PACKET_TASK; tsn_task = SEND_PACKET_TASK;
egress_params->packet_priority = 3; egress_params.packet_priority = 3;
egress_params->tx_buffer_len = 1024; egress_params.tx_buffer_len = 1024;
// Process bash options // Process bash options
process_options(argc, argv); process_options(argc, argv);
egress_params->use_etf = enable_etf; egress_params.use_etf = enable_etf;
egress_params->use_timestamps = enable_timestamps; egress_params.use_timestamps = enable_timestamps;
if (enable_histograms) { if (enable_histograms) {
// Init histograms // Init histograms
...@@ -187,8 +187,10 @@ int main(int argc, char *argv[]) { ...@@ -187,8 +187,10 @@ int main(int argc, char *argv[]) {
init_signals(sighand, enable_histograms); init_signals(sighand, enable_histograms);
// Initialize the UDP packet sending socket // Initialize the UDP packet sending socket
init_udp_send(egress_params, init_udp_send(&egress_params,
thread_params, &egress_stats,
&thread_params,
enable_histograms,
kernel_latency_hist); kernel_latency_hist);
// Initialize the UDP packet receiving socket if RTT is measured // Initialize the UDP packet receiving socket if RTT is measured
...@@ -213,9 +215,9 @@ int main(int argc, char *argv[]) { ...@@ -213,9 +215,9 @@ int main(int argc, char *argv[]) {
} else if (enable_timestamps) { } else if (enable_timestamps) {
printf("%10d: K: %4d %4d %4d\n", printf("%10d: K: %4d %4d %4d\n",
nb_cycles, egress_stats->min_kernel_latency, nb_cycles, egress_stats.min_kernel_latency,
egress_stats->avg_kernel_latency, egress_stats.avg_kernel_latency,
egress_stats->max_kernel_latency); egress_stats.max_kernel_latency);
printf("\033[%dA", 1); printf("\033[%dA", 1);
} }
} }
...@@ -345,8 +347,8 @@ static void process_options(int argc, char *argv[]) { ...@@ -345,8 +347,8 @@ static void process_options(int argc, char *argv[]) {
tsn_task = RTT_TASK; tsn_task = RTT_TASK;
break; break;
case 'd': case 'd':
egress_params->tx_buffer_len = atoi(optarg); egress_params.tx_buffer_len = atoi(optarg);
if (egress_params->tx_buffer_len < 1) { if (egress_params.tx_buffer_len < 1) {
fprintf(stderr, "BUF_LEN should be greater than 1\n"); fprintf(stderr, "BUF_LEN should be greater than 1\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -357,7 +359,7 @@ static void process_options(int argc, char *argv[]) { ...@@ -357,7 +359,7 @@ static void process_options(int argc, char *argv[]) {
break; break;
case 'f': case 'f':
network_if_specified = 1; network_if_specified = 1;
strcpy(egress_params->network_if, optarg); strcpy(egress_params.network_if, optarg);
break; break;
case 'g': case 'g':
enable_histograms = 1; enable_histograms = 1;
...@@ -376,7 +378,7 @@ static void process_options(int argc, char *argv[]) { ...@@ -376,7 +378,7 @@ static void process_options(int argc, char *argv[]) {
thread_params.priority = atoi(optarg); thread_params.priority = atoi(optarg);
break; break;
case 'q': case 'q':
egress_params->packet_priority = atoi(optarg); egress_params.packet_priority = atoi(optarg);
break; break;
case 'r': case 'r':
main_params.refresh_rate = atoi(optarg); main_params.refresh_rate = atoi(optarg);
...@@ -404,5 +406,5 @@ static void process_options(int argc, char *argv[]) { ...@@ -404,5 +406,5 @@ static void process_options(int argc, char *argv[]) {
help(argv); help(argv);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strcpy(egress_params->ip_address, argv[optind]); strcpy(egress_params.ip_address, argv[optind]);
} }
...@@ -52,7 +52,6 @@ static int set_if() { ...@@ -52,7 +52,6 @@ static int set_if() {
} }
void init_udp_recv(struct ingress_param * _params, void init_udp_recv(struct ingress_param * _params,
struct thread_param * _thread_params,
int use_histogram, int use_histogram,
uint64_t * _kernel_latency_hist) { uint64_t * _kernel_latency_hist) {
int getaddrinfo_err; int getaddrinfo_err;
...@@ -60,7 +59,6 @@ void init_udp_recv(struct ingress_param * _params, ...@@ -60,7 +59,6 @@ void init_udp_recv(struct ingress_param * _params,
struct addrinfo hints, *servinfo, *servinfo_it; struct addrinfo hints, *servinfo, *servinfo_it;
params = _params; params = _params;
thread_params = _thread_params;
use_histogram = _use_histogram; use_histogram = _use_histogram;
kernel_latency_hist = _kernel_latency_hist; kernel_latency_hist = _kernel_latency_hist;
...@@ -110,7 +108,7 @@ void init_udp_recv(struct ingress_param * _params, ...@@ -110,7 +108,7 @@ void init_udp_recv(struct ingress_param * _params,
/* /*
* Receives udp packets * Receives udp packets
*/ */
void recv_udp_packet() { void recv_udp_packet(int nb_cycles) {
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
struct msghdr msg; // Message hardware, sent to the socket struct msghdr msg; // Message hardware, sent to the socket
...@@ -145,30 +143,30 @@ void recv_udp_packet() { ...@@ -145,30 +143,30 @@ void recv_udp_packet() {
if (recvmsgerr < 0) if (recvmsgerr < 0)
error(EXIT_FAILURE, errno, "recvmsg failed, ret value: %d\n", recvmsgerr); error(EXIT_FAILURE, errno, "recvmsg failed, ret value: %d\n", recvmsgerr);
if (use_timestamps) { if (params->use_timestamps) {
clock_gettime(CLOCK_REALTIME, &ts);
packet_info.userspace_enter_ts = ts_to_uint(ts);
}
if (use_timestamps) {
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMPING) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMPING) {
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg); struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
packet_info.kernelspace_ts = ts_to_uint(*stamp);
clock_gettime(CLOCK_REALTIME, &ts); uint64_t kernel_latency = timestamps_buffer[ts_buf_read_index++] - ts_to_uint(*stamp);
packet_info.userspace_exit_ts = ts_to_uint(ts); kernel_latency /= 1000u;
ingress_stats->min_kernel_latency = min(kernel_latency, ingress_stats->min_kernel_latency);
ingress_stats->max_kernel_latency = max(kernel_latency, ingress_stats->max_kernel_latency);
ingress_stats->avg_kernel_latency = (ingress_stats->max_kernel_latency * (nb_cycles-1) + kernel_latency) / nb_cycles;
if (use_histograms) if (use_histogram) {
fill_histograms(&packet_info, histograms); if (kernel_latency > MAX_KERNEL_LATENCY)
stats.high_kernel_latency++;
else
kernel_latency_hist[kernel_latency]++;
}
} }
} }
} }
strcpy(packet_info.data, rx_buffer); strcpy(stats->data, rx_buffer);
return packet_info;
} }
static void fill_histograms(packet_info_t *packet_info, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]) { static void fill_histograms(packet_info_t *packet_info, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]) {
......
...@@ -4,14 +4,12 @@ ...@@ -4,14 +4,12 @@
#include "utilities.h" #include "utilities.h"
void init_udp_recv(struct ingress_param * _params, void init_udp_recv(struct ingress_param * _params,
struct thread_param * _thread_params,
int use_histogram, int use_histogram,
uint64_t * _kernel_latency_hist); uint64_t * _kernel_latency_hist);
packet_info_t recv_udp_packet(int use_timestamps, int use_histograms, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]); void recv_udp_packet(int nb_cycles);
void init_udp_recv(ingress_param_t * params, void init_udp_recv(ingress_param_t * params,
thread_param_t * thread_params,
uint64_t * kernel_latency_hist); uint64_t * kernel_latency_hist);
void recv_udp_packet(int nb_cycles); void recv_udp_packet(int nb_cycles);
......
...@@ -47,7 +47,7 @@ static int so_timestamping_flags = ...@@ -47,7 +47,7 @@ static int so_timestamping_flags =
SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE; SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE;
egress_param_t * params; egress_param_t * params;
struct thread_param * thread_params; egress_stat_t * stats;
uint64_t * kernel_latency_hist; uint64_t * kernel_latency_hist;
int use_histogram; int use_histogram;
...@@ -63,7 +63,7 @@ static int ts_buf_write_index = 0; ...@@ -63,7 +63,7 @@ static int ts_buf_write_index = 0;
* Init UDP socket * Init UDP socket
*/ */
void init_udp_send(egress_param_t * _params, void init_udp_send(egress_param_t * _params,
thread_param_t * _thread_params, egress_stat_t * _stats,
int _use_histogram, int _use_histogram,
uint64_t * _kernel_latency_hist) { uint64_t * _kernel_latency_hist) {
...@@ -71,7 +71,7 @@ void init_udp_send(egress_param_t * _params, ...@@ -71,7 +71,7 @@ void init_udp_send(egress_param_t * _params,
pthread_t thread; pthread_t thread;
params = _params; params = _params;
thread_params = _thread_params; stats = _stats;
kernel_latency_hist = _kernel_latency_hist; kernel_latency_hist = _kernel_latency_hist;
use_histogram = _use_histogram use_histogram = _use_histogram
...@@ -216,13 +216,13 @@ static void process_error_queue(int nb_cycles) { ...@@ -216,13 +216,13 @@ static void process_error_queue(int nb_cycles) {
uint64_t kernel_latency = ts_to_uint(stamp) - timestamps_buffer[ts_buf_read_index++]; uint64_t kernel_latency = ts_to_uint(stamp) - timestamps_buffer[ts_buf_read_index++];
kernel_latency /= 1000u; kernel_latency /= 1000u;
egress_stats->min_kernel_latency = min(kernel_latency, egress_stats->min_kernel_latency); stats->min_kernel_latency = min(kernel_latency, stats->min_kernel_latency);
egress_stats->max_kernel_latency = max(kernel_latency, egress_stats->max_kernel_latency); stats->max_kernel_latency = max(kernel_latency, stats->max_kernel_latency);
egress_stats->avg_kernel_latency = (egress_stats->max_kernel_latency * (nb_cycles-1) + kernel_latency) / nb_cycles; stats->avg_kernel_latency = (stats->max_kernel_latency * (nb_cycles-1) + kernel_latency) / nb_cycles;
if (use_histogram) { if (use_histogram) {
if (kernel_latency > MAX_KERNEL_LATENCY) if (kernel_latency > MAX_KERNEL_LATENCY)
stats.high_kernel_latency++; stats->high_kernel_latency++;
else else
kernel_latency_hist[kernel_latency]++; kernel_latency_hist[kernel_latency]++;
} }
...@@ -238,10 +238,10 @@ static void process_error_queue(int nb_cycles) { ...@@ -238,10 +238,10 @@ static void process_error_queue(int nb_cycles) {
switch (serr->ee_code) { switch (serr->ee_code) {
case SO_EE_CODE_TXTIME_INVALID_PARAM: case SO_EE_CODE_TXTIME_INVALID_PARAM:
stats.invalid_parameter++; stats->invalid_parameter++;
break; break;
case SO_EE_CODE_TXTIME_MISSED: case SO_EE_CODE_TXTIME_MISSED:
stats.missed_deadline++; stats->missed_deadline++;
break; break;
default: default:
fprintf(stderr, "Uknown TxTime error\n"); fprintf(stderr, "Uknown TxTime error\n");
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "common.h" #include "common.h"
void init_udp_send(egress_param_t * _params, void init_udp_send(egress_param_t * _params,
thread_param_t * _thread_params,
int _use_histogram, int _use_histogram,
uint64_t * _kernel_latency_hist); uint64_t * _kernel_latency_hist);
void send_udp_packet(char *data, uint64_t txtime, int nb_cycles); void send_udp_packet(char *data, uint64_t txtime, int nb_cycles);
...@@ -30,7 +29,6 @@ typedef struct egress_stat { ...@@ -30,7 +29,6 @@ typedef struct egress_stat {
int avg_kernel_latency; int avg_kernel_latency;
int max_kernel_latency; int max_kernel_latency;
char data[MAX_BUFFER_SIZE];
} thread_stat_t; } thread_stat_t;
#endif #endif
...@@ -31,8 +31,11 @@ ...@@ -31,8 +31,11 @@
// Structs // Structs
typedef struct thread_stat { typedef struct thread_stat {
uint64_t min_interval; uint64_t min_interval;
uint64_t avg_interval;
uint64_t max_interval; uint64_t max_interval;
int packets_received; int packets_received;
int lost_packets; int lost_packets;
} thread_stat_t; } thread_stat_t;
...@@ -171,6 +174,8 @@ int main(int argc, char *argv[]) { ...@@ -171,6 +174,8 @@ int main(int argc, char *argv[]) {
// Default configuration values // Default configuration values
thread_params.interval = 100000 * 1000; thread_params.interval = 100000 * 1000;
thread_params.priority = 99; thread_params.priority = 99;
main_params.refresh_rate = 50000;
main_params.verbose = 0;
enable_affinity = 0; enable_affinity = 0;
enable_timestamps = 0; enable_timestamps = 0;
...@@ -179,9 +184,6 @@ int main(int argc, char *argv[]) { ...@@ -179,9 +184,6 @@ int main(int argc, char *argv[]) {
network_config.tx_buffer_len = 1024; network_config.tx_buffer_len = 1024;
main_params.refresh_rate = 50000;
main_params.verbose = 0;
// Process bash options // Process bash options
process_options(argc, argv); process_options(argc, argv);
...@@ -194,11 +196,17 @@ int main(int argc, char *argv[]) { ...@@ -194,11 +196,17 @@ int main(int argc, char *argv[]) {
init_signals(sighand, enable_histograms); init_signals(sighand, enable_histograms);
// Initialize the UDP packet receiving socket // Initialize the UDP packet receiving socket
init_udp_recv(enable_timestamps, network_config.network_if); init_udp_recv(&ingress_params,
&ingress_stats,
enable_histograms,
kernel_latency_hist);
// Initialize the UDP packet sending socket if RTT is measured // Initialize the UDP packet sending socket if RTT is measured
if (tsn_task == RTT_TASK) if (tsn_task == RTT_TASK)
init_udp_send(0, 0, 1, network_config.network_if, network_config.tx_buffer_len); init_udp_send(&egress_params,
&egress_stats,
0,
NULL);
// Create the real time thread // Create the real time thread
if (pthread_create(&thread, NULL, packet_receiving_thread, NULL)) if (pthread_create(&thread, NULL, packet_receiving_thread, NULL))
...@@ -212,7 +220,7 @@ int main(int argc, char *argv[]) { ...@@ -212,7 +220,7 @@ int main(int argc, char *argv[]) {
if (tsn_task == RECV_PACKET_TASK) { if (tsn_task == RECV_PACKET_TASK) {
int64_t jitter = ((int64_t)stats->max_interval) - stats->min_interval; uint64_t jitter = ((int64_t)stats->max_interval) - stats->min_interval;
printf("%*d: J: %*" PRIi64, printf("%*d: J: %*" PRIi64,
10, stats->packets_received, 10, stats->packets_received,
......
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