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