turbostat.c (139dd0e07c1c116949aed75c2c067873c6f91e50) | turbostat.c (70a9c6e8ed28d974f10251920ccc0ce22f69afa2) |
---|---|
1/* 2 * turbostat -- show CPU frequency and C-state residency 3 * on modern Intel turbo-capable processors. 4 * 5 * Copyright (c) 2013 Intel Corporation. 6 * Len Brown <len.brown@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 203 unchanged lines hidden (view full) --- 212 unsigned int pkg_temp_c; 213 unsigned long long counter[MAX_ADDED_COUNTERS]; 214} *package_even, *package_odd; 215 216#define ODD_COUNTERS thread_odd, core_odd, package_odd 217#define EVEN_COUNTERS thread_even, core_even, package_even 218 219#define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ | 1/* 2 * turbostat -- show CPU frequency and C-state residency 3 * on modern Intel turbo-capable processors. 4 * 5 * Copyright (c) 2013 Intel Corporation. 6 * Len Brown <len.brown@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 203 unchanged lines hidden (view full) --- 212 unsigned int pkg_temp_c; 213 unsigned long long counter[MAX_ADDED_COUNTERS]; 214} *package_even, *package_odd; 215 216#define ODD_COUNTERS thread_odd, core_odd, package_odd 217#define EVEN_COUNTERS thread_even, core_even, package_even 218 219#define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
220 (thread_base + (pkg_no) * topo.num_cores_per_node * \ 221 topo.num_threads_per_core + \ 222 (core_no) * topo.num_threads_per_core + (thread_no)) | 220 (thread_base + (pkg_no) * topo.cores_per_node * \ 221 topo.threads_per_core + \ 222 (core_no) * topo.threads_per_core + (thread_no)) |
223#define GET_CORE(core_base, core_no, pkg_no) \ | 223#define GET_CORE(core_base, core_no, pkg_no) \ |
224 (core_base + (pkg_no) * topo.num_cores_per_node + (core_no)) | 224 (core_base + (pkg_no) * topo.cores_per_node + (core_no)) |
225#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) 226 227enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; 228enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; 229enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; 230 231struct msr_counter { 232 unsigned int msr_num; --- 35 unchanged lines hidden (view full) --- 268} *cpus; 269 270struct topo_params { 271 int num_packages; 272 int num_cpus; 273 int num_cores; 274 int max_cpu_num; 275 int max_node_num; | 225#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) 226 227enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; 228enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; 229enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; 230 231struct msr_counter { 232 unsigned int msr_num; --- 35 unchanged lines hidden (view full) --- 268} *cpus; 269 270struct topo_params { 271 int num_packages; 272 int num_cpus; 273 int num_cores; 274 int max_cpu_num; 275 int max_node_num; |
276 int num_nodes_per_pkg; 277 int num_cores_per_node; 278 int num_threads_per_core; | 276 int nodes_per_pkg; 277 int cores_per_node; 278 int threads_per_core; |
279} topo; 280 281struct timeval tv_even, tv_odd, tv_delta; 282 283int *irq_column_2_cpu; /* /proc/interrupts column numbers */ 284int *irqs_per_cpu; /* indexed by cpu_num */ 285 286void setup_all_buffers(void); --- 8 unchanged lines hidden (view full) --- 295 */ 296 297int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), 298 struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) 299{ 300 int retval, pkg_no, core_no, thread_no; 301 302 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { | 279} topo; 280 281struct timeval tv_even, tv_odd, tv_delta; 282 283int *irq_column_2_cpu; /* /proc/interrupts column numbers */ 284int *irqs_per_cpu; /* indexed by cpu_num */ 285 286void setup_all_buffers(void); --- 8 unchanged lines hidden (view full) --- 295 */ 296 297int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), 298 struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) 299{ 300 int retval, pkg_no, core_no, thread_no; 301 302 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
303 for (core_no = 0; core_no < topo.num_cores_per_node; 304 ++core_no) { | 303 for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { |
305 for (thread_no = 0; thread_no < | 304 for (thread_no = 0; thread_no < |
306 topo.num_threads_per_core; ++thread_no) { | 305 topo.threads_per_core; ++thread_no) { |
307 struct thread_data *t; 308 struct core_data *c; 309 struct pkg_data *p; 310 311 t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); 312 313 if (cpu_is_not_present(t->cpu_id)) 314 continue; --- 2081 unchanged lines hidden (view full) --- 2396 pkg = cpus[cpu].physical_package_id; 2397 pni[pkg].count++; 2398 2399 if (node < pni[pkg].min) 2400 pni[pkg].min = node; 2401 } 2402 2403 for (pkg = 0; pkg < topo.num_packages; pkg++) | 306 struct thread_data *t; 307 struct core_data *c; 308 struct pkg_data *p; 309 310 t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); 311 312 if (cpu_is_not_present(t->cpu_id)) 313 continue; --- 2081 unchanged lines hidden (view full) --- 2395 pkg = cpus[cpu].physical_package_id; 2396 pni[pkg].count++; 2397 2398 if (node < pni[pkg].min) 2399 pni[pkg].min = node; 2400 } 2401 2402 for (pkg = 0; pkg < topo.num_packages; pkg++) |
2404 if (pni[pkg].count > topo.num_nodes_per_pkg) 2405 topo.num_nodes_per_pkg = pni[0].count; | 2403 if (pni[pkg].count > topo.nodes_per_pkg) 2404 topo.nodes_per_pkg = pni[0].count; |
2406 2407 for (cpu = 0; cpu < topo.num_cpus; cpu++) { 2408 pkg = cpus[cpu].physical_package_id; 2409 node = cpus[cpu].physical_node_id; 2410 cpus[cpu].logical_node_id = node - pni[pkg].min; 2411 } 2412 free(pni); 2413 --- 73 unchanged lines hidden (view full) --- 2487 struct pkg_data *), struct thread_data *thread_base, 2488 struct core_data *core_base, struct pkg_data *pkg_base, 2489 struct thread_data *thread_base2, struct core_data *core_base2, 2490 struct pkg_data *pkg_base2) 2491{ 2492 int retval, pkg_no, core_no, thread_no; 2493 2494 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { | 2405 2406 for (cpu = 0; cpu < topo.num_cpus; cpu++) { 2407 pkg = cpus[cpu].physical_package_id; 2408 node = cpus[cpu].physical_node_id; 2409 cpus[cpu].logical_node_id = node - pni[pkg].min; 2410 } 2411 free(pni); 2412 --- 73 unchanged lines hidden (view full) --- 2486 struct pkg_data *), struct thread_data *thread_base, 2487 struct core_data *core_base, struct pkg_data *pkg_base, 2488 struct thread_data *thread_base2, struct core_data *core_base2, 2489 struct pkg_data *pkg_base2) 2490{ 2491 int retval, pkg_no, core_no, thread_no; 2492 2493 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
2495 for (core_no = 0; core_no < topo.num_cores_per_node; 2496 ++core_no) { | 2494 for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { |
2497 for (thread_no = 0; thread_no < | 2495 for (thread_no = 0; thread_no < |
2498 topo.num_threads_per_core; ++thread_no) { | 2496 topo.threads_per_core; ++thread_no) { |
2499 struct thread_data *t, *t2; 2500 struct core_data *c, *c2; 2501 struct pkg_data *p, *p2; 2502 2503 t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); 2504 2505 if (cpu_is_not_present(t->cpu_id)) 2506 continue; --- 2218 unchanged lines hidden (view full) --- 4725 fprintf(outf, 4726 "cpu %d pkg %d node %d core %d thread %d\n", 4727 i, cpus[i].physical_package_id, 4728 cpus[i].physical_node_id, 4729 cpus[i].physical_core_id, 4730 cpus[i].thread_id); 4731 } 4732 | 2497 struct thread_data *t, *t2; 2498 struct core_data *c, *c2; 2499 struct pkg_data *p, *p2; 2500 2501 t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); 2502 2503 if (cpu_is_not_present(t->cpu_id)) 2504 continue; --- 2218 unchanged lines hidden (view full) --- 4723 fprintf(outf, 4724 "cpu %d pkg %d node %d core %d thread %d\n", 4725 i, cpus[i].physical_package_id, 4726 cpus[i].physical_node_id, 4727 cpus[i].physical_core_id, 4728 cpus[i].thread_id); 4729 } 4730 |
4733 topo.num_cores_per_node = max_core_id + 1; | 4731 topo.cores_per_node = max_core_id + 1; |
4734 if (debug > 1) 4735 fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", | 4732 if (debug > 1) 4733 fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", |
4736 max_core_id, topo.num_cores_per_node); 4737 if (!summary_only && topo.num_cores_per_node > 1) | 4734 max_core_id, topo.cores_per_node); 4735 if (!summary_only && topo.cores_per_node > 1) |
4738 BIC_PRESENT(BIC_Core); 4739 4740 topo.num_packages = max_package_id + 1; 4741 if (debug > 1) 4742 fprintf(outf, "max_package_id %d, sizing for %d packages\n", 4743 max_package_id, topo.num_packages); 4744 if (!summary_only && topo.num_packages > 1) 4745 BIC_PRESENT(BIC_Package); 4746 4747 set_node_data(); 4748 if (debug > 1) | 4736 BIC_PRESENT(BIC_Core); 4737 4738 topo.num_packages = max_package_id + 1; 4739 if (debug > 1) 4740 fprintf(outf, "max_package_id %d, sizing for %d packages\n", 4741 max_package_id, topo.num_packages); 4742 if (!summary_only && topo.num_packages > 1) 4743 BIC_PRESENT(BIC_Package); 4744 4745 set_node_data(); 4746 if (debug > 1) |
4749 fprintf(outf, "num_nodes_per_pkg %d\n", topo.num_nodes_per_pkg); | 4747 fprintf(outf, "nodes_per_pkg %d\n", topo.nodes_per_pkg); |
4750 | 4748 |
4751 topo.num_threads_per_core = max_siblings; | 4749 topo.threads_per_core = max_siblings; |
4752 if (debug > 1) 4753 fprintf(outf, "max_siblings %d\n", max_siblings); 4754} 4755 4756void 4757allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) 4758{ 4759 int i; 4760 | 4750 if (debug > 1) 4751 fprintf(outf, "max_siblings %d\n", max_siblings); 4752} 4753 4754void 4755allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) 4756{ 4757 int i; 4758 |
4761 *t = calloc(topo.num_threads_per_core * topo.num_cores_per_node * | 4759 *t = calloc(topo.threads_per_core * topo.cores_per_node * |
4762 topo.num_packages, sizeof(struct thread_data)); 4763 if (*t == NULL) 4764 goto error; 4765 | 4760 topo.num_packages, sizeof(struct thread_data)); 4761 if (*t == NULL) 4762 goto error; 4763 |
4766 for (i = 0; i < topo.num_threads_per_core * 4767 topo.num_cores_per_node * topo.num_packages; i++) | 4764 for (i = 0; i < topo.threads_per_core * 4765 topo.cores_per_node * topo.num_packages; i++) |
4768 (*t)[i].cpu_id = -1; 4769 | 4766 (*t)[i].cpu_id = -1; 4767 |
4770 *c = calloc(topo.num_cores_per_node * topo.num_packages, | 4768 *c = calloc(topo.cores_per_node * topo.num_packages, |
4771 sizeof(struct core_data)); 4772 if (*c == NULL) 4773 goto error; 4774 | 4769 sizeof(struct core_data)); 4770 if (*c == NULL) 4771 goto error; 4772 |
4775 for (i = 0; i < topo.num_cores_per_node * topo.num_packages; i++) | 4773 for (i = 0; i < topo.cores_per_node * topo.num_packages; i++) |
4776 (*c)[i].core_id = -1; 4777 4778 *p = calloc(topo.num_packages, sizeof(struct pkg_data)); 4779 if (*p == NULL) 4780 goto error; 4781 4782 for (i = 0; i < topo.num_packages; i++) 4783 (*p)[i].package_id = i; --- 674 unchanged lines hidden --- | 4774 (*c)[i].core_id = -1; 4775 4776 *p = calloc(topo.num_packages, sizeof(struct pkg_data)); 4777 if (*p == NULL) 4778 goto error; 4779 4780 for (i = 0; i < topo.num_packages; i++) 4781 (*p)[i].package_id = i; --- 674 unchanged lines hidden --- |