Commit 7a42d58b authored by Joanne Hugé's avatar Joanne Hugé

Add interactive interval for client

parent 16f5c761
......@@ -60,6 +60,11 @@ typedef struct main_param {
int verbose;
int enable_tracing;
int enable_graph;
int interval_input;
int transition_time;
uint64_t target_interval;
} main_param_t;
// Static functions
......@@ -113,10 +118,28 @@ static void help(char *argv[]) {
" -v Verbose\n"
" -T Enable tracing until deadline is missed\n"
" -S Enable tracing until threshold is reached\n"
" -U Interactive interval change\n"
"\n",
argv[0]);
}
static void *print_thread(void *p) {
(void)p;
for (;;) {
if (thread_params.max_cycles &&
nb_cycles >= ((unsigned int)thread_params.max_cycles))
break;
printf("Interval: %10" PRIu64 " Target: %10" PRIu64 "\n", thread_params.interval / 1000, main_params.target_interval);
printf("\033[%dA", 1);
usleep(100000);
}
pthread_exit(NULL);
}
/*
* Real-time thread:
* - Sends packets at a regular intervall
......@@ -128,6 +151,13 @@ static void *packet_sending_thread(void *p) {
int ret;
cpu_set_t mask;
uint64_t next_increment = 0;
uint64_t end_t = 0;
uint64_t cur_t = 0;
uint64_t i_t = 0;
uint64_t i_s = thread_params.interval / 1000;
uint64_t i_c = thread_params.interval / 1000;
// Set thread CPU affinity
if (thread_params.affinity_cpu != -1) {
CPU_ZERO(&mask);
......@@ -225,6 +255,65 @@ static void *packet_sending_thread(void *p) {
}
}
if(main_params.interval_input && (thread_params.interval != (main_params.target_interval * 1000))) {
i_c = thread_params.interval / 1000;
// If target interval changed
if(i_t != main_params.target_interval) {
i_t = main_params.target_interval;
i_s = i_c;
cur_t = 0;
next_increment = 0;
if(i_t < i_s)
end_t = (main_params.transition_time * USEC_PER_SEC * USEC_PER_SEC * (i_c - i_t)) / (MOTOR_STEPS * i_t * i_c);
else
end_t = (main_params.transition_time * USEC_PER_SEC * USEC_PER_SEC * (i_t - i_c)) / (MOTOR_STEPS * i_t * i_c);
}
if(next_increment) {
if(cur_t > next_increment) {
i_c += i_t < i_s ? -1 : 1;
next_increment = 0;
}
} else {
uint64_t next_i = i_t < i_s ? i_c - 1 : i_c + 1;
// Compute time at which we will need to increment / decrement the interval
if(i_t < i_s)
next_increment = (end_t * i_t * (i_s - next_i)) / ((i_s - i_t) * next_i);
else
next_increment = (end_t * i_t * (next_i - i_s)) / ((i_t - i_s) * next_i);
// If next increment time is before next interval
if(next_increment < cur_t + i_c) {
if(i_t < i_s) {
i_c = (i_t * i_s * end_t) / ((i_s - i_t) * (cur_t + i_c) + end_t * i_t);
i_c = i_c < i_t ? i_t : i_c;
}
else {
i_c = (i_t * i_s * end_t) / (end_t * i_t - (i_t - i_s) * (cur_t + i_c));
i_c = i_c > i_t ? i_t : i_c;
}
next_increment = 0;
}
}
cur_t += i_c;
if(i_c < 50) {
fprintf(stderr, "Interval too small, exiting..\n");
exit(EXIT_FAILURE);
}
if(i_c > USEC_PER_SEC) {
fprintf(stderr, "Interval too big, exiting..\n");
exit(EXIT_FAILURE);
}
thread_params.interval = i_c * 1000;
}
previous = current;
}
......@@ -243,7 +332,7 @@ invalid_ts:
* - Handles the IO and creates the real time thread
*/
int main(int argc, char *argv[]) {
pthread_t thread;
pthread_t thread, print_pthread;
struct sched_param param;
pthread_attr_t attr;
......@@ -261,6 +350,7 @@ int main(int argc, char *argv[]) {
main_params.verbose = 0;
main_params.enable_tracing = 0;
main_params.enable_graph = 0;
main_params.interval_input = 0;
egress_params.packet_priority = 3;
egress_params.tx_buffer_len = 1024;
enable_etf = 0;
......@@ -336,11 +426,23 @@ int main(int argc, char *argv[]) {
if (pthread_create(&thread, &attr, packet_sending_thread, NULL))
error(EXIT_FAILURE, errno, "Couldn't create packet sending thread");
if(main_params.interval_input) {
// Create the print thread
if (pthread_create(&print_pthread, NULL, print_thread, NULL))
error(EXIT_FAILURE, errno, "Couldn't create print thread");
}
// Verbose loop
for (;;) {
usleep(main_params.refresh_rate);
if (main_params.verbose) {
if (main_params.interval_input) {
uint64_t user_input;
scanf("%" PRIu64, &user_input);
if(user_input)
main_params.target_interval = user_input;
}
else if (main_params.verbose) {
// RTT stats printing
if (tsn_task == RTT_TASK) {
// N_CYCLES, RTT min / avg / max
......@@ -459,7 +561,7 @@ static void sighand(int sig_num) {
*/
static void process_options(int argc, char *argv[]) {
for (;;) {
int c = getopt(argc, argv, "a:bc:d:e:ghi:l:p:q:r:s:tvTS:");
int c = getopt(argc, argv, "a:bc:d:e:ghi:l:p:q:r:s:tvTS:U:");
if (c == -1) break;
......@@ -525,6 +627,10 @@ static void process_options(int argc, char *argv[]) {
thread_params.enable_threshold_tracing = 1;
thread_params.threshold = atoi(optarg);
break;
case 'U':
main_params.interval_input = 1;
main_params.transition_time = atoi(optarg);
break;
}
}
......
......@@ -19,7 +19,10 @@
#include <linux/udp.h>
#endif
#define MOTOR_STEPS 20000
#define NSEC_PER_SEC UINT64_C(1000000000)
#define USEC_PER_SEC UINT64_C(1000000)
#define SERVER_PORT "50000"
#define SERVER_PORT_INT 50000
......
......@@ -186,9 +186,6 @@ static void *tsn_thread(void *p) {
cpu_set_t mask;
char tracemark_message[128];
uint64_t time_elapsed;
uint64_t next_interval;
// Set thread CPU affinity
if (thread_params.affinity_cpu) {
CPU_ZERO(&mask);
......
......@@ -307,9 +307,11 @@ int main(int argc, char *argv[]) {
if (pthread_create(&thread, &attr, pulse_thread, NULL))
error(EXIT_FAILURE, errno, "Couldn't create pulse thread");
if(main_params.interval_input) {
// Create the print thread
if (pthread_create(&print_pthread, NULL, print_thread, NULL))
error(EXIT_FAILURE, errno, "Couldn't create print thread");
}
// Verbose loop
for (;;) {
......
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