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

WIP: rewrite and clean up code

parent 67101268
......@@ -22,12 +22,17 @@
#include "send_packet.h"
#include "utilities.h"
#define MAX_KERNEL_LATENCY 1000
#define MAX_RTT_LATENCY 1000
// Structs
typedef struct thread_stat {
typedef struct egress_stat {
int nb_cycles;
uint64_t rtt;
packet_info_t packet_info;
uint64_t high_kernel_latency;
uint64_t invalid_parameter;
uint64_t missed_deadline;
char data[MAX_BUFFER_SIZE];
} thread_stat_t;
typedef struct thread_param {
......@@ -36,7 +41,6 @@ typedef struct thread_param {
int priority;
int etf_offset;
thread_stat_t stats;
} thread_param_t;
typedef struct main_param {
......@@ -44,13 +48,6 @@ typedef struct main_param {
int verbose;
} main_param_t;
typedef struct network_config {
size_t tx_buffer_len;
char ip_address[256];
char network_if[256];
int packet_priority;
} network_config_t;
// Static functions
static void process_options(int argc, char *argv[]);
......@@ -60,19 +57,21 @@ static void sighand(int sig_num);
// Static variables
static int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL];
static int64_t kernel_latencies[MAX_KERNEL_LATENCY]++;
static int64_t rtt_latencies[MAX_RTT_LATENCY]++;
static main_param_t main_param;
static thread_param_t *param;
static network_config_t network_config;
static main_param_t main_params;
static thread_param_t thread_params;
static egress_stat * egress_stats;
static egress_param * egress_params;
static int enable_histograms;
static int enable_affinity;
static int enable_etf;
static int enable_timestamps;
enum TSNTask { SEND_PACKET_TASK,
RTT_TASK };
enum TSNTask { SEND_PACKET_TASK, RTT_TASK };
static enum TSNTask tsn_task;
struct timespec measures_start;
......@@ -105,8 +104,6 @@ static void *packet_sending_thread(void *p) {
struct timespec next;
uint64_t next_txtime;
struct sched_param priority;
thread_param_t *param = (thread_param_t *)p;
thread_stat_t *stats = &param->stats;
cpu_set_t mask;
// Set thread CPU affinity
......@@ -134,18 +131,18 @@ static void *packet_sending_thread(void *p) {
clock_gettime(CLOCK_MONOTONIC, &next);
clock_gettime(CLOCK_MONOTONIC, &measures_start);
// Packet sending loop
for (stats->nb_cycles = 0;; stats->nb_cycles++) {
if (param->max_cycles)
if (stats->nb_cycles >= param->max_cycles)
for (egress_stats->nb_cycles = 0;; egress_stats->nb_cycles++) {
if (thread_params.max_cycles)
if (egress_stats->nb_cycles >= thread_params.max_cycles)
break;
sprintf(send_data, "%d", stats->nb_cycles % 1000);
do_tsn_task(param, send_data, next_txtime);
sprintf(send_data, "%d", egress_stats->nb_cycles % 1000);
do_tsn_task(send_data, next_txtime);
add_ns(&next, param->interval);
add_ns(&next, thread_params.interval);
if (enable_etf)
next_txtime += param->interval;
next_txtime += thread_params.interval;
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL);
}
......@@ -157,15 +154,14 @@ static void *packet_sending_thread(void *p) {
// Handles the IO and creates real time threads
int main(int argc, char *argv[]) {
pthread_t thread;
thread_stat_t *stats;
param = malloc(sizeof(thread_param_t));
stats = &param->stats;
// Default configuration values
param->interval = 100000 * 1000;
param->max_cycles = 0;
param->priority = 99;
thread_params.interval = 100000 * 1000;
thread_params.max_cycles = 0;
thread_params.priority = 99;
main_params.refresh_rate = 50000;
main_params.verbose = 0;
enable_affinity = 0;
enable_etf = 0;
......@@ -173,18 +169,19 @@ int main(int argc, char *argv[]) {
enable_histograms = 0;
tsn_task = SEND_PACKET_TASK;
network_config.packet_priority = 3;
network_config.tx_buffer_len = 1024;
main_param.refresh_rate = 50000;
main_param.verbose = 0;
egress_params->packet_priority = 3;
egress_params->tx_buffer_len = 1024;
// Process bash options
process_options(argc, argv);
egress_params->use_etf = enable_etf;
egress_params->use_timestamps = enable_timestamps;
if (enable_histograms) {
// Init histograms
memset((int64_t *)histograms, 0, NB_HISTOGRAMS * MAX_HIST_VAL);
memset(kernel_latency, 0, MAX_KERNEL_LATENCY);
memset(rtt_latency, 0, MAX_RTT_LATENCY);
}
// Catch breaks with sighand to print the histograms
......
This diff is collapsed.
......@@ -3,7 +3,23 @@
#include "utilities.h"
void init_udp_send(int use_etf, int use_timestamps, int so_priority, char *network_if, size_t tx_buffer_len);
packet_info_t send_udp_packet(int use_etf, int use_timestamps, char *data, uint64_t txtime, const char *server_ip, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]);
init_udp_send(struct egress_param * _params,
struct thread_param * _thread_params,
uint64_t kernel_latency[MAX_KERNEL_LATENCY]);
void send_udp_packet(char *data, uint64_t txtime);
struct egress_param {
int packet_priority;
size_t tx_buffer_len;
char server_ip[45];
char network_if[16];
int use_etf;
int use_timestamps;
int min_kernel_latency;
int avg_kernel_latency;
int max_kernel_latency;
};
#endif
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