Commit 44a513e1 authored by Joanne Hugé's avatar Joanne Hugé

Add more comments, make graph tracer and affinity optionnal

parent 5c96fd63
......@@ -25,6 +25,7 @@ typedef struct thread_param {
int priority;
int max_cycles;
int enable_tracing;
int enable_affinity;
uint64_t interval;
uint64_t latency_threshold;
thread_stat_t stat;
......@@ -33,6 +34,7 @@ typedef struct thread_param {
typedef struct main_param {
int refresh_rate;
int enable_tracing;
int enable_graph;
} main_param_t;
static void process_options(int argc, char *argv[], thread_param_t *param,
......@@ -53,11 +55,13 @@ static void *timerthread(void *p) {
thread_param_t *param = (thread_param_t *)p;
thread_stat_t *stat = &param->stat;
// Set thread CPU affinity
CPU_ZERO(&mask);
CPU_SET(1, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
printf("Could not set CPU affinity to CPU #1\n");
if(param->enable_affinity) {
// Set thread CPU affinity
CPU_ZERO(&mask);
CPU_SET(1, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
printf("Could not set CPU affinity to CPU #1\n");
}
// Set thread priority
priority.sched_priority = param->priority;
......@@ -67,16 +71,20 @@ static void *timerthread(void *p) {
stat->max_res = 0;
stat->min_res = UINT64_MAX;
// Start tracing
if (param->enable_tracing) tracing(1);
// Measurement loop
for (stat->nb_cycles = 0;; stat->nb_cycles++) {
if (param->max_cycles && (stat->nb_cycles >= param->max_cycles)) break;
// Two successive clock measurement to determine clock_gettime latency
clock_gettime(CLOCK_ID, &previous);
clock_gettime(CLOCK_ID, &current);
diff = calcdiff_ns(current, previous);
// If the latency hits the tracing threshold, stop tracing
if (param->enable_tracing && (diff > param->latency_threshold)) {
sprintf(time_measured_string, "Diff measured: %" PRIu64 "\n", diff);
tracemark(time_measured_string);
......@@ -88,6 +96,8 @@ static void *timerthread(void *p) {
break;
}
// Update the thread statistics, so that the non real-time
// thread can print it
stat->max_res = max(stat->max_res, diff);
stat->min_res = min(stat->min_res, diff);
......@@ -111,14 +121,19 @@ int main(int argc, char *argv[]) {
param.max_cycles = 100000;
param.priority = 99;
param.enable_tracing = 0;
param.enable_affinity = 0;
main_param.enable_tracing = 0;
main_param.enable_graph = 0;
main_param.refresh_rate = 10000;
// Process bash options
process_options(argc, argv, &param, &main_param);
// Enable ftrace
if (main_param.enable_tracing) {
param.enable_tracing = 1;
setup_tracer();
setup_tracer(main_param.enable_graph);
}
usleep(10000);
......@@ -149,7 +164,7 @@ int main(int argc, char *argv[]) {
static void process_options(int argc, char *argv[], thread_param_t *param,
main_param_t *main_param) {
for (;;) {
int c = getopt(argc, argv, "l:p:i:r:b:f");
int c = getopt(argc, argv, "l:p:i:r:f:ag");
if (c == -1) break;
......@@ -163,14 +178,18 @@ static void process_options(int argc, char *argv[], thread_param_t *param,
case 'i':
param->interval = atoi(optarg);
break;
case 'b':
param->latency_threshold = atoi(optarg);
break;
case 'r':
main_param->refresh_rate = atoi(optarg);
break;
case 'f':
main_param->enable_tracing = 1;
param->latency_threshold = atoi(optarg);
break;
case 'a':
param->enable_affinity = 1;
break;
case 'g':
main_param->enable_graph = 1;
break;
default:
exit(EXIT_FAILURE);
......
......@@ -74,7 +74,7 @@ static void setkernvar(const char *name, char *value) {
fprintf(stderr, "could not set %s to %s\n", name, value);
}
void setup_tracer(void) {
void setup_tracer(int enable_graph) {
char trace_path[MAX_PATH];
char tracemark_path[MAX_PATH];
......@@ -85,7 +85,10 @@ void setup_tracer(void) {
fileprefix = debugfileprefix;
// Clear old traces by setting tracer to nop first
setkernvar("current_tracer", "nop");
setkernvar("current_tracer", "function");
if(enable_graph)
setkernvar("current_tracer", "function_graph");
else
setkernvar("current_tracer", "function");
// Open tracing_on file
strcpy(trace_path, fileprefix);
......
#ifndef TRACER_H
#define TRACER_H
void setup_tracer(void);
void setup_tracer(int enable_graph);
void tracing(int on);
void tracemark(char * s);
......
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