Lines 1-11
Link Here
|
1 |
--- turbostat.c.orig 2018-07-23 18:26:58 UTC |
1 |
--- turbostat.c.orig 2018-07-31 20:42:12 UTC |
2 |
+++ turbostat.c |
2 |
+++ turbostat.c |
3 |
@@ -41,7 +41,30 @@ |
3 |
@@ -41,7 +41,31 @@ |
4 |
#include <sched.h> |
4 |
#include <sched.h> |
5 |
#include <time.h> |
5 |
#include <time.h> |
6 |
#include <cpuid.h> |
6 |
#include <cpuid.h> |
7 |
+#ifdef __FreeBSD__ |
7 |
+#ifdef __FreeBSD__ |
8 |
+#include <sys/types.h> |
8 |
+#include <sys/types.h> |
|
|
9 |
+#include <sys/param.h> |
9 |
+#include <sys/cpuctl.h> |
10 |
+#include <sys/cpuctl.h> |
10 |
+#include <sys/cpuset.h> |
11 |
+#include <sys/cpuset.h> |
11 |
+#include <sys/ioctl.h> |
12 |
+#include <sys/ioctl.h> |
Lines 31-37
Link Here
|
31 |
#include <errno.h> |
32 |
#include <errno.h> |
32 |
|
33 |
|
33 |
char *proc_stat = "/proc/stat"; |
34 |
char *proc_stat = "/proc/stat"; |
34 |
@@ -132,7 +155,9 @@ unsigned int has_misc_feature_control; |
35 |
@@ -132,7 +156,9 @@ unsigned int has_misc_feature_control; |
35 |
#define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
36 |
#define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
36 |
#define TJMAX_DEFAULT 100 |
37 |
#define TJMAX_DEFAULT 100 |
37 |
|
38 |
|
Lines 41-47
Link Here
|
41 |
|
42 |
|
42 |
/* |
43 |
/* |
43 |
* buffer size used by sscanf() for added column names |
44 |
* buffer size used by sscanf() for added column names |
44 |
@@ -309,6 +334,7 @@ int cpu_migrate(int cpu) |
45 |
@@ -309,6 +335,7 @@ int cpu_migrate(int cpu) |
45 |
else |
46 |
else |
46 |
return 0; |
47 |
return 0; |
47 |
} |
48 |
} |
Lines 49-55
Link Here
|
49 |
int get_msr_fd(int cpu) |
50 |
int get_msr_fd(int cpu) |
50 |
{ |
51 |
{ |
51 |
char pathname[32]; |
52 |
char pathname[32]; |
52 |
@@ -319,18 +345,39 @@ int get_msr_fd(int cpu) |
53 |
@@ -319,18 +346,39 @@ int get_msr_fd(int cpu) |
53 |
if (fd) |
54 |
if (fd) |
54 |
return fd; |
55 |
return fd; |
55 |
|
56 |
|
Lines 90-96
Link Here
|
90 |
ssize_t retval; |
91 |
ssize_t retval; |
91 |
|
92 |
|
92 |
retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
93 |
retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
93 |
@@ -340,6 +387,7 @@ int get_msr(int cpu, off_t offset, unsigned long long |
94 |
@@ -340,6 +388,7 @@ int get_msr(int cpu, off_t offset, unsigned long long |
94 |
|
95 |
|
95 |
return 0; |
96 |
return 0; |
96 |
} |
97 |
} |
Lines 98-104
Link Here
|
98 |
|
99 |
|
99 |
/* |
100 |
/* |
100 |
* Each string in this array is compared in --show and --hide cmdline. |
101 |
* Each string in this array is compared in --show and --hide cmdline. |
101 |
@@ -2239,6 +2287,158 @@ int parse_int_file(const char *fmt, ...) |
102 |
@@ -2239,6 +2288,173 @@ int parse_int_file(const char *fmt, ...) |
102 |
return value; |
103 |
return value; |
103 |
} |
104 |
} |
104 |
|
105 |
|
Lines 121-127
Link Here
|
121 |
+ else |
122 |
+ else |
122 |
+ list->cap = 2; |
123 |
+ list->cap = 2; |
123 |
+ |
124 |
+ |
124 |
+ list->sets = reallocarray(list->sets, list->cap, sizeof(cpuset_t)); |
125 |
+ list->sets = realloc(list->sets, list->cap * sizeof(cpuset_t)); |
125 |
+} |
126 |
+} |
126 |
+ |
127 |
+ |
127 |
+static cpuset_t parse_cpu_mask(const char *i) { |
128 |
+static cpuset_t parse_cpu_mask(const char *i) { |
Lines 195-204
Link Here
|
195 |
+ ncpus += CPU_COUNT(packages.sets + i); |
196 |
+ ncpus += CPU_COUNT(packages.sets + i); |
196 |
+} |
197 |
+} |
197 |
+ |
198 |
+ |
198 |
+static int get_core_id(int cpu) |
199 |
+static int get_physical_package_id(int cpu) |
199 |
+{ |
200 |
+{ |
200 |
+ for (int i = 0; i < cores.len; i++) { |
201 |
+ for (int i = 0; i < packages.len; i++) { |
201 |
+ if (!CPU_ISSET(cpu, cores.sets + i)) |
202 |
+ if (!CPU_ISSET(cpu, packages.sets + i)) |
202 |
+ continue; |
203 |
+ continue; |
203 |
+ |
204 |
+ |
204 |
+ return i; |
205 |
+ return i; |
Lines 206-247
Link Here
|
206 |
+ return -1; |
207 |
+ return -1; |
207 |
+} |
208 |
+} |
208 |
+ |
209 |
+ |
209 |
+static int get_cpu_position_in_core(int cpu) |
210 |
+static int get_core_id(int cpu) |
210 |
+{ |
211 |
+{ |
211 |
+ int core = get_core_id(cpu); |
212 |
+ int package_id = get_physical_package_id(cpu); |
212 |
+ if (core < 0) |
213 |
+ if (package_id < 0) |
213 |
+ return -1; |
214 |
+ return -1; |
214 |
+ |
215 |
+ |
215 |
+ cpuset_t s; |
216 |
+ const cpuset_t *package = packages.sets + package_id; |
216 |
+ CPU_COPY(cores.sets + core, &s); |
217 |
+ |
217 |
+ for (int i = 0; !CPU_EMPTY(&s); i++) { |
218 |
+ for (int i = 0, j = -1; i < cores.len; i++) { |
218 |
+ int ffs = CPU_FFS(&s) - 1; |
219 |
+ if (CPU_OVERLAP(package, cores.sets + i)) |
219 |
+ if (ffs == cpu) |
220 |
+ j++; |
220 |
+ return i; |
|
|
221 |
+ CPU_CLR(ffs, &s); |
222 |
+ } |
223 |
+ |
221 |
+ |
|
|
222 |
+ if (!CPU_ISSET(cpu, cores.sets + i)) |
223 |
+ continue; |
224 |
+ |
225 |
+ return j; |
226 |
+ } |
224 |
+ return -1; |
227 |
+ return -1; |
225 |
+} |
228 |
+} |
226 |
+ |
229 |
+ |
227 |
+static int get_num_ht_siblings(int cpu) |
230 |
+static int get_cpu_position_in_core(int cpu) |
228 |
+{ |
231 |
+{ |
229 |
+ int core = get_core_id(cpu); |
232 |
+ for (int i = 0; i < cores.len; i++) { |
230 |
+ if (core < 0) |
233 |
+ if (!CPU_ISSET(cpu, cores.sets + i)) |
231 |
+ return 1; |
234 |
+ continue; |
232 |
+ |
235 |
+ |
233 |
+ return CPU_COUNT(cores.sets + core); |
236 |
+ cpuset_t s; |
|
|
237 |
+ CPU_COPY(cores.sets + i, &s); |
238 |
+ for (int j = 0; !CPU_EMPTY(&s); j++) { |
239 |
+ int ffs = CPU_FFS(&s) - 1; |
240 |
+ if (ffs == cpu) |
241 |
+ return j; |
242 |
+ CPU_CLR(ffs, &s); |
243 |
+ } |
244 |
+ |
245 |
+ return -1; |
246 |
+ } |
247 |
+ |
248 |
+ return -1; |
234 |
+} |
249 |
+} |
235 |
+ |
250 |
+ |
236 |
+static int get_physical_package_id(int cpu) |
251 |
+static int get_num_ht_siblings(int cpu) |
237 |
+{ |
252 |
+{ |
238 |
+ for (int i = 0; i < packages.len; i++) { |
253 |
+ for (int i = 0; i < cores.len; i++) { |
239 |
+ if (!CPU_ISSET(cpu, packages.sets + i)) |
254 |
+ if (!CPU_ISSET(cpu, cores.sets + i)) |
240 |
+ continue; |
255 |
+ continue; |
241 |
+ |
256 |
+ |
242 |
+ return i; |
257 |
+ return CPU_COUNT(cores.sets + i); |
243 |
+ } |
258 |
+ } |
244 |
+ return -1; |
259 |
+ |
|
|
260 |
+ return 1; |
245 |
+} |
261 |
+} |
246 |
+ |
262 |
+ |
247 |
+static int cpu_is_first_core_in_package(int cpu) |
263 |
+static int cpu_is_first_core_in_package(int cpu) |
Lines 257-263
Link Here
|
257 |
/* |
273 |
/* |
258 |
* get_cpu_position_in_core(cpu) |
274 |
* get_cpu_position_in_core(cpu) |
259 |
* return the position of the CPU among its HT siblings in the core |
275 |
* return the position of the CPU among its HT siblings in the core |
260 |
@@ -2326,6 +2526,7 @@ int get_num_ht_siblings(int cpu) |
276 |
@@ -2326,6 +2542,7 @@ int get_num_ht_siblings(int cpu) |
261 |
fclose(filep); |
277 |
fclose(filep); |
262 |
return matches+1; |
278 |
return matches+1; |
263 |
} |
279 |
} |
Lines 265-271
Link Here
|
265 |
|
281 |
|
266 |
/* |
282 |
/* |
267 |
* run func(thread, core, package) in topology order |
283 |
* run func(thread, core, package) in topology order |
268 |
@@ -2371,6 +2572,22 @@ int for_all_cpus_2(int (func)(struct thread_data *, st |
284 |
@@ -2371,6 +2588,22 @@ int for_all_cpus_2(int (func)(struct thread_data *, st |
269 |
return 0; |
285 |
return 0; |
270 |
} |
286 |
} |
271 |
|
287 |
|
Lines 288-294
Link Here
|
288 |
/* |
304 |
/* |
289 |
* run func(cpu) on every cpu in /proc/stat |
305 |
* run func(cpu) on every cpu in /proc/stat |
290 |
* return max_cpu number |
306 |
* return max_cpu number |
291 |
@@ -2401,6 +2618,7 @@ int for_all_proc_cpus(int (func)(int)) |
307 |
@@ -2401,6 +2634,7 @@ int for_all_proc_cpus(int (func)(int)) |
292 |
fclose(fp); |
308 |
fclose(fp); |
293 |
return 0; |
309 |
return 0; |
294 |
} |
310 |
} |
Lines 296-302
Link Here
|
296 |
|
312 |
|
297 |
void re_initialize(void) |
313 |
void re_initialize(void) |
298 |
{ |
314 |
{ |
299 |
@@ -2428,6 +2646,81 @@ int mark_cpu_present(int cpu) |
315 |
@@ -2428,6 +2662,85 @@ int mark_cpu_present(int cpu) |
300 |
return 0; |
316 |
return 0; |
301 |
} |
317 |
} |
302 |
|
318 |
|
Lines 318-334
Link Here
|
318 |
+ else |
334 |
+ else |
319 |
+ intr_map_cap = 2; |
335 |
+ intr_map_cap = 2; |
320 |
+ |
336 |
+ |
321 |
+ intr_map = reallocarray(intr_map, intr_map_cap, sizeof(*intr_map)); |
337 |
+ intr_map = realloc(intr_map, intr_map_cap * sizeof(*intr_map)); |
322 |
+} |
338 |
+} |
323 |
+ |
339 |
+ |
324 |
+static void init_intr_map(void) |
340 |
+static void init_intr_map(void) |
325 |
+{ |
341 |
+{ |
326 |
+ size_t sz = 0; |
342 |
+ size_t sz = 0; |
327 |
+ if (sysctlbyname("hw.intrs", NULL, &sz, NULL, 0)) |
343 |
+ if (sysctlbyname("hw.intrs", NULL, &sz, NULL, 0)) { |
328 |
+ err(1, "sysctl: hw.intrs: failed"); |
344 |
+ warn("sysctl: hw.intrs: per-cpu interrupt data will be unavailable"); |
|
|
345 |
+ return; |
346 |
+ } |
329 |
+ char *intrs = alloca(sz); |
347 |
+ char *intrs = alloca(sz); |
330 |
+ if (sysctlbyname("hw.intrs", intrs, &sz, NULL, 0)) |
348 |
+ if (sysctlbyname("hw.intrs", intrs, &sz, NULL, 0)) { |
331 |
+ err(1, "sysctl: hw.intrs: failed"); |
349 |
+ warn("sysctl: hw.intrs: per-cpu interrupt data will be unavailable"); |
|
|
350 |
+ return; |
351 |
+ } |
332 |
+ |
352 |
+ |
333 |
+ char *i = intrs; |
353 |
+ char *i = intrs; |
334 |
+ char *j; |
354 |
+ char *j; |
Lines 378-384
Link Here
|
378 |
/* |
398 |
/* |
379 |
* snapshot_proc_interrupts() |
399 |
* snapshot_proc_interrupts() |
380 |
* |
400 |
* |
381 |
@@ -2491,6 +2784,8 @@ int snapshot_proc_interrupts(void) |
401 |
@@ -2491,6 +2804,8 @@ int snapshot_proc_interrupts(void) |
382 |
} |
402 |
} |
383 |
return 0; |
403 |
return 0; |
384 |
} |
404 |
} |
Lines 387-393
Link Here
|
387 |
/* |
407 |
/* |
388 |
* snapshot_gfx_rc6_ms() |
408 |
* snapshot_gfx_rc6_ms() |
389 |
* |
409 |
* |
390 |
@@ -2629,6 +2924,18 @@ restart: |
410 |
@@ -2629,6 +2944,18 @@ restart: |
391 |
} |
411 |
} |
392 |
} |
412 |
} |
393 |
|
413 |
|
Lines 406-412
Link Here
|
406 |
void check_dev_msr() |
426 |
void check_dev_msr() |
407 |
{ |
427 |
{ |
408 |
struct stat sb; |
428 |
struct stat sb; |
409 |
@@ -2677,6 +2984,7 @@ void check_permissions() |
429 |
@@ -2677,6 +3004,7 @@ void check_permissions() |
410 |
if (do_exit) |
430 |
if (do_exit) |
411 |
exit(-6); |
431 |
exit(-6); |
412 |
} |
432 |
} |
Lines 414-420
Link Here
|
414 |
|
434 |
|
415 |
/* |
435 |
/* |
416 |
* NHM adds support for additional MSRs: |
436 |
* NHM adds support for additional MSRs: |
417 |
@@ -4520,8 +4828,21 @@ void setup_all_buffers(void) |
437 |
@@ -4520,8 +4848,21 @@ void setup_all_buffers(void) |
418 |
for_all_proc_cpus(initialize_counters); |
438 |
for_all_proc_cpus(initialize_counters); |
419 |
} |
439 |
} |
420 |
|
440 |
|
Lines 436-442
Link Here
|
436 |
base_cpu = sched_getcpu(); |
456 |
base_cpu = sched_getcpu(); |
437 |
if (base_cpu < 0) |
457 |
if (base_cpu < 0) |
438 |
err(-ENODEV, "No valid cpus found"); |
458 |
err(-ENODEV, "No valid cpus found"); |
439 |
@@ -4529,6 +4850,7 @@ void set_base_cpu(void) |
459 |
@@ -4529,6 +4870,7 @@ void set_base_cpu(void) |
440 |
if (debug > 1) |
460 |
if (debug > 1) |
441 |
fprintf(outf, "base_cpu = %d\n", base_cpu); |
461 |
fprintf(outf, "base_cpu = %d\n", base_cpu); |
442 |
} |
462 |
} |
443 |
- |
|
|