diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-10-10 07:17:09 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2014-01-14 03:44:01 -0500 |
commit | 55cd4e54c67b0886447070a609d11779728b81e6 (patch) | |
tree | 7b1b736207abc60f48236016b656cc62bc5feeae | |
parent | 23624a2fd62515146c0eace874583fb66586de4c (diff) |
Add TSC calibration support to ftcat
Provide the -c option to calibrate the TSC offsets.
Provide the -v option to get output about it.
-rw-r--r-- | include/timestamp.h | 5 | ||||
-rw-r--r-- | src/ftcat.c | 42 |
2 files changed, 42 insertions, 5 deletions
diff --git a/include/timestamp.h b/include/timestamp.h index b3b10ce..1668bcb 100644 --- a/include/timestamp.h +++ b/include/timestamp.h | |||
@@ -32,8 +32,9 @@ int str2event(const char* str, cmd_t *id); | |||
32 | const char* event2str(cmd_t id); | 32 | const char* event2str(cmd_t id); |
33 | const char* task_type2str(int task_type); | 33 | const char* task_type2str(int task_type); |
34 | 34 | ||
35 | #define ENABLE_CMD 0L | 35 | #define ENABLE_CMD 0x0 |
36 | #define DISABLE_CMD 1L | 36 | #define DISABLE_CMD 0x1 |
37 | #define CALIBRATE_CMD 0x1410 | ||
37 | 38 | ||
38 | #define TIMESTAMP(id) id | 39 | #define TIMESTAMP(id) id |
39 | 40 | ||
diff --git a/src/ftcat.c b/src/ftcat.c index b43a3a5..b8c6f0c 100644 --- a/src/ftcat.c +++ b/src/ftcat.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <sys/ioctl.h> | 27 | #include <sys/ioctl.h> |
28 | 28 | ||
29 | #include "migration.h" /* from liblitmus */ | ||
29 | #include "timestamp.h" | 30 | #include "timestamp.h" |
30 | 31 | ||
31 | #define MAX_EVENTS 128 | 32 | #define MAX_EVENTS 128 |
@@ -66,12 +67,35 @@ static int enable_event(int fd, char* str) | |||
66 | err = ioctl(fd, ENABLE_CMD, *id); | 67 | err = ioctl(fd, ENABLE_CMD, *id); |
67 | 68 | ||
68 | if (err < 0) | 69 | if (err < 0) |
69 | printf("ioctl(%d, %d, %d) => %d (errno: %d)\n", fd, (int) ENABLE_CMD, *id, | 70 | fprintf(stderr, "ioctl(%d, %d, %d) => %d (errno: %d)\n", fd, (int) ENABLE_CMD, *id, |
70 | err, errno); | 71 | err, errno); |
71 | 72 | ||
72 | return err == 0; | 73 | return err == 0; |
73 | } | 74 | } |
74 | 75 | ||
76 | static int calibrate_cycle_offsets(int fd) | ||
77 | { | ||
78 | int cpu, err; | ||
79 | int max_cpus = sysconf(_SC_NPROCESSORS_CONF); | ||
80 | |||
81 | for (cpu = 0; cpu < max_cpus; cpu++) { | ||
82 | err = be_migrate_to_cpu(cpu); | ||
83 | if (!err) { | ||
84 | printf("Calibrating CPU %d...", cpu); | ||
85 | err = ioctl(fd, CALIBRATE_CMD, 0); | ||
86 | if (err) { | ||
87 | printf("\n"); | ||
88 | fprintf(stderr, "ioctl(CALIBRATE_CMD) => %d (errno: %d, %m)\n", err, errno); | ||
89 | return 0; | ||
90 | } else | ||
91 | printf(" done.\n"); | ||
92 | } else { | ||
93 | fprintf(stderr, "Could not migrate to CPU %d (%m).\n", cpu); | ||
94 | } | ||
95 | } | ||
96 | return 1; | ||
97 | } | ||
98 | |||
75 | 99 | ||
76 | static void cat2stdout(int fd) | 100 | static void cat2stdout(int fd) |
77 | { | 101 | { |
@@ -91,7 +115,9 @@ static void _usage(void) | |||
91 | fprintf(stderr, | 115 | fprintf(stderr, |
92 | "Usage: ftcat [OPTIONS] <ft device> TS1 TS2 ....\n" | 116 | "Usage: ftcat [OPTIONS] <ft device> TS1 TS2 ....\n" |
93 | "\nOptions:\n" | 117 | "\nOptions:\n" |
94 | " -s SIZE -- stop tracing afer recording SIZE bytes\n"); | 118 | " -s SIZE -- stop tracing afer recording SIZE bytes\n" |
119 | " -c -- calibrate the CPU cycle counter offsets\n" | ||
120 | "\n"); | ||
95 | exit(1); | 121 | exit(1); |
96 | } | 122 | } |
97 | 123 | ||
@@ -105,11 +131,12 @@ static void shutdown(int sig) | |||
105 | fprintf(stderr, "disable_all: %m\n"); | 131 | fprintf(stderr, "disable_all: %m\n"); |
106 | } | 132 | } |
107 | 133 | ||
108 | #define OPTSTR "s:" | 134 | #define OPTSTR "s:c" |
109 | 135 | ||
110 | int main(int argc, char** argv) | 136 | int main(int argc, char** argv) |
111 | { | 137 | { |
112 | int opt; | 138 | int opt; |
139 | int want_calibrate = 0; | ||
113 | 140 | ||
114 | const char* trace_file; | 141 | const char* trace_file; |
115 | 142 | ||
@@ -120,6 +147,9 @@ int main(int argc, char** argv) | |||
120 | if (stop_after_bytes == 0) | 147 | if (stop_after_bytes == 0) |
121 | usage("invalid size (%s)", optarg); | 148 | usage("invalid size (%s)", optarg); |
122 | break; | 149 | break; |
150 | case 'c': | ||
151 | want_calibrate = 1; | ||
152 | break; | ||
123 | case ':': | 153 | case ':': |
124 | usage("Argument missing."); | 154 | usage("Argument missing."); |
125 | break; | 155 | break; |
@@ -142,6 +172,12 @@ int main(int argc, char** argv) | |||
142 | usage("could not open feathertrace device (%s): %m", trace_file); | 172 | usage("could not open feathertrace device (%s): %m", trace_file); |
143 | return 1; | 173 | return 1; |
144 | } | 174 | } |
175 | |||
176 | if (want_calibrate && !calibrate_cycle_offsets(fd)) { | ||
177 | fprintf(stderr, "Calibrating %s failed: %m\n", *argv); | ||
178 | return 3; | ||
179 | } | ||
180 | |||
145 | argc -= 1; | 181 | argc -= 1; |
146 | argv += 1; | 182 | argv += 1; |
147 | signal(SIGINT, shutdown); | 183 | signal(SIGINT, shutdown); |