aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-06-26 19:42:28 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-06-26 19:42:28 -0400
commita8a13bfd5ac1a5ba63a722ae173cb2619db89c5c (patch)
treecf5e8a92cb702a42d5b72e7e6a5e37c535b45529 /tools
parent3c2993b8c6143d8a5793746a54eba8f86f95240f (diff)
parentf7d44a8f3fd7f13770470a306a233acbaad5e96d (diff)
Merge branch 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
Pull turbostat fixes from Len Brown. * 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux: tools/power turbostat: update version number tools/power turbostat: decode MSR_IA32_MISC_ENABLE only on Intel tools/power turbostat: stop migrating, unless '-m' tools/power turbostat: if --debug, print sampling overhead tools/power turbostat: hide SKL counters, when not requested
Diffstat (limited to 'tools')
-rw-r--r--tools/power/x86/turbostat/turbostat.c94
1 files changed, 77 insertions, 17 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index b11294730771..0dafba2c1e7d 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -57,7 +57,6 @@ unsigned int list_header_only;
57unsigned int dump_only; 57unsigned int dump_only;
58unsigned int do_snb_cstates; 58unsigned int do_snb_cstates;
59unsigned int do_knl_cstates; 59unsigned int do_knl_cstates;
60unsigned int do_skl_residency;
61unsigned int do_slm_cstates; 60unsigned int do_slm_cstates;
62unsigned int use_c1_residency_msr; 61unsigned int use_c1_residency_msr;
63unsigned int has_aperf; 62unsigned int has_aperf;
@@ -93,6 +92,7 @@ unsigned int do_ring_perf_limit_reasons;
93unsigned int crystal_hz; 92unsigned int crystal_hz;
94unsigned long long tsc_hz; 93unsigned long long tsc_hz;
95int base_cpu; 94int base_cpu;
95int do_migrate;
96double discover_bclk(unsigned int family, unsigned int model); 96double discover_bclk(unsigned int family, unsigned int model);
97unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ 97unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */
98 /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ 98 /* IA32_HWP_REQUEST, IA32_HWP_STATUS */
@@ -151,6 +151,8 @@ size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size;
151#define MAX_ADDED_COUNTERS 16 151#define MAX_ADDED_COUNTERS 16
152 152
153struct thread_data { 153struct thread_data {
154 struct timeval tv_begin;
155 struct timeval tv_end;
154 unsigned long long tsc; 156 unsigned long long tsc;
155 unsigned long long aperf; 157 unsigned long long aperf;
156 unsigned long long mperf; 158 unsigned long long mperf;
@@ -301,6 +303,9 @@ int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg
301 303
302int cpu_migrate(int cpu) 304int cpu_migrate(int cpu)
303{ 305{
306 if (!do_migrate)
307 return 0;
308
304 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); 309 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set);
305 CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); 310 CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set);
306 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) 311 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1)
@@ -384,8 +389,14 @@ struct msr_counter bic[] = {
384 { 0x0, "CPU" }, 389 { 0x0, "CPU" },
385 { 0x0, "Mod%c6" }, 390 { 0x0, "Mod%c6" },
386 { 0x0, "sysfs" }, 391 { 0x0, "sysfs" },
392 { 0x0, "Totl%C0" },
393 { 0x0, "Any%C0" },
394 { 0x0, "GFX%C0" },
395 { 0x0, "CPUGFX%" },
387}; 396};
388 397
398
399
389#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) 400#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
390#define BIC_Package (1ULL << 0) 401#define BIC_Package (1ULL << 0)
391#define BIC_Avg_MHz (1ULL << 1) 402#define BIC_Avg_MHz (1ULL << 1)
@@ -426,6 +437,10 @@ struct msr_counter bic[] = {
426#define BIC_CPU (1ULL << 36) 437#define BIC_CPU (1ULL << 36)
427#define BIC_Mod_c6 (1ULL << 37) 438#define BIC_Mod_c6 (1ULL << 37)
428#define BIC_sysfs (1ULL << 38) 439#define BIC_sysfs (1ULL << 38)
440#define BIC_Totl_c0 (1ULL << 39)
441#define BIC_Any_c0 (1ULL << 40)
442#define BIC_GFX_c0 (1ULL << 41)
443#define BIC_CPUGFX (1ULL << 42)
429 444
430unsigned long long bic_enabled = 0xFFFFFFFFFFFFFFFFULL; 445unsigned long long bic_enabled = 0xFFFFFFFFFFFFFFFFULL;
431unsigned long long bic_present = BIC_sysfs; 446unsigned long long bic_present = BIC_sysfs;
@@ -521,6 +536,8 @@ void print_header(char *delim)
521 struct msr_counter *mp; 536 struct msr_counter *mp;
522 int printed = 0; 537 int printed = 0;
523 538
539 if (debug)
540 outp += sprintf(outp, "usec %s", delim);
524 if (DO_BIC(BIC_Package)) 541 if (DO_BIC(BIC_Package))
525 outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); 542 outp += sprintf(outp, "%sPackage", (printed++ ? delim : ""));
526 if (DO_BIC(BIC_Core)) 543 if (DO_BIC(BIC_Core))
@@ -599,12 +616,14 @@ void print_header(char *delim)
599 if (DO_BIC(BIC_GFXMHz)) 616 if (DO_BIC(BIC_GFXMHz))
600 outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : "")); 617 outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : ""));
601 618
602 if (do_skl_residency) { 619 if (DO_BIC(BIC_Totl_c0))
603 outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : "")); 620 outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : ""));
621 if (DO_BIC(BIC_Any_c0))
604 outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : "")); 622 outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : ""));
623 if (DO_BIC(BIC_GFX_c0))
605 outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : "")); 624 outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : ""));
625 if (DO_BIC(BIC_CPUGFX))
606 outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : "")); 626 outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : ""));
607 }
608 627
609 if (DO_BIC(BIC_Pkgpc2)) 628 if (DO_BIC(BIC_Pkgpc2))
610 outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : "")); 629 outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : ""));
@@ -771,6 +790,14 @@ int format_counters(struct thread_data *t, struct core_data *c,
771 (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) 790 (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset)))
772 return 0; 791 return 0;
773 792
793 if (debug) {
794 /* on each row, print how many usec each timestamp took to gather */
795 struct timeval tv;
796
797 timersub(&t->tv_end, &t->tv_begin, &tv);
798 outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec);
799 }
800
774 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; 801 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
775 802
776 tsc = t->tsc * tsc_tweak; 803 tsc = t->tsc * tsc_tweak;
@@ -912,12 +939,14 @@ int format_counters(struct thread_data *t, struct core_data *c,
912 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); 939 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz);
913 940
914 /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ 941 /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */
915 if (do_skl_residency) { 942 if (DO_BIC(BIC_Totl_c0))
916 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc); 943 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc);
944 if (DO_BIC(BIC_Any_c0))
917 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0/tsc); 945 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0/tsc);
946 if (DO_BIC(BIC_GFX_c0))
918 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0/tsc); 947 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0/tsc);
948 if (DO_BIC(BIC_CPUGFX))
919 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0/tsc); 949 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0/tsc);
920 }
921 950
922 if (DO_BIC(BIC_Pkgpc2)) 951 if (DO_BIC(BIC_Pkgpc2))
923 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc); 952 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc);
@@ -1038,12 +1067,16 @@ delta_package(struct pkg_data *new, struct pkg_data *old)
1038 int i; 1067 int i;
1039 struct msr_counter *mp; 1068 struct msr_counter *mp;
1040 1069
1041 if (do_skl_residency) { 1070
1071 if (DO_BIC(BIC_Totl_c0))
1042 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; 1072 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0;
1073 if (DO_BIC(BIC_Any_c0))
1043 old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; 1074 old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0;
1075 if (DO_BIC(BIC_GFX_c0))
1044 old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; 1076 old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0;
1077 if (DO_BIC(BIC_CPUGFX))
1045 old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; 1078 old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0;
1046 } 1079
1047 old->pc2 = new->pc2 - old->pc2; 1080 old->pc2 = new->pc2 - old->pc2;
1048 if (DO_BIC(BIC_Pkgpc3)) 1081 if (DO_BIC(BIC_Pkgpc3))
1049 old->pc3 = new->pc3 - old->pc3; 1082 old->pc3 = new->pc3 - old->pc3;
@@ -1292,12 +1325,14 @@ int sum_counters(struct thread_data *t, struct core_data *c,
1292 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) 1325 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
1293 return 0; 1326 return 0;
1294 1327
1295 if (do_skl_residency) { 1328 if (DO_BIC(BIC_Totl_c0))
1296 average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; 1329 average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0;
1330 if (DO_BIC(BIC_Any_c0))
1297 average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; 1331 average.packages.pkg_any_core_c0 += p->pkg_any_core_c0;
1332 if (DO_BIC(BIC_GFX_c0))
1298 average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; 1333 average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0;
1334 if (DO_BIC(BIC_CPUGFX))
1299 average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; 1335 average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0;
1300 }
1301 1336
1302 average.packages.pc2 += p->pc2; 1337 average.packages.pc2 += p->pc2;
1303 if (DO_BIC(BIC_Pkgpc3)) 1338 if (DO_BIC(BIC_Pkgpc3))
@@ -1357,12 +1392,14 @@ void compute_average(struct thread_data *t, struct core_data *c,
1357 average.cores.c7 /= topo.num_cores; 1392 average.cores.c7 /= topo.num_cores;
1358 average.cores.mc6_us /= topo.num_cores; 1393 average.cores.mc6_us /= topo.num_cores;
1359 1394
1360 if (do_skl_residency) { 1395 if (DO_BIC(BIC_Totl_c0))
1361 average.packages.pkg_wtd_core_c0 /= topo.num_packages; 1396 average.packages.pkg_wtd_core_c0 /= topo.num_packages;
1397 if (DO_BIC(BIC_Any_c0))
1362 average.packages.pkg_any_core_c0 /= topo.num_packages; 1398 average.packages.pkg_any_core_c0 /= topo.num_packages;
1399 if (DO_BIC(BIC_GFX_c0))
1363 average.packages.pkg_any_gfxe_c0 /= topo.num_packages; 1400 average.packages.pkg_any_gfxe_c0 /= topo.num_packages;
1401 if (DO_BIC(BIC_CPUGFX))
1364 average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; 1402 average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages;
1365 }
1366 1403
1367 average.packages.pc2 /= topo.num_packages; 1404 average.packages.pc2 /= topo.num_packages;
1368 if (DO_BIC(BIC_Pkgpc3)) 1405 if (DO_BIC(BIC_Pkgpc3))
@@ -1482,6 +1519,9 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
1482 struct msr_counter *mp; 1519 struct msr_counter *mp;
1483 int i; 1520 int i;
1484 1521
1522
1523 gettimeofday(&t->tv_begin, (struct timezone *)NULL);
1524
1485 if (cpu_migrate(cpu)) { 1525 if (cpu_migrate(cpu)) {
1486 fprintf(outf, "Could not migrate to CPU %d\n", cpu); 1526 fprintf(outf, "Could not migrate to CPU %d\n", cpu);
1487 return -1; 1527 return -1;
@@ -1565,7 +1605,7 @@ retry:
1565 1605
1566 /* collect core counters only for 1st thread in core */ 1606 /* collect core counters only for 1st thread in core */
1567 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 1607 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
1568 return 0; 1608 goto done;
1569 1609
1570 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) { 1610 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) {
1571 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) 1611 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3))
@@ -1601,15 +1641,21 @@ retry:
1601 1641
1602 /* collect package counters only for 1st core in package */ 1642 /* collect package counters only for 1st core in package */
1603 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) 1643 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
1604 return 0; 1644 goto done;
1605 1645
1606 if (do_skl_residency) { 1646 if (DO_BIC(BIC_Totl_c0)) {
1607 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) 1647 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0))
1608 return -10; 1648 return -10;
1649 }
1650 if (DO_BIC(BIC_Any_c0)) {
1609 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) 1651 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0))
1610 return -11; 1652 return -11;
1653 }
1654 if (DO_BIC(BIC_GFX_c0)) {
1611 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) 1655 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0))
1612 return -12; 1656 return -12;
1657 }
1658 if (DO_BIC(BIC_CPUGFX)) {
1613 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) 1659 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0))
1614 return -13; 1660 return -13;
1615 } 1661 }
@@ -1688,6 +1734,8 @@ retry:
1688 if (get_mp(cpu, mp, &p->counter[i])) 1734 if (get_mp(cpu, mp, &p->counter[i]))
1689 return -10; 1735 return -10;
1690 } 1736 }
1737done:
1738 gettimeofday(&t->tv_end, (struct timezone *)NULL);
1691 1739
1692 return 0; 1740 return 0;
1693} 1741}
@@ -3895,6 +3943,9 @@ void decode_misc_enable_msr(void)
3895{ 3943{
3896 unsigned long long msr; 3944 unsigned long long msr;
3897 3945
3946 if (!genuine_intel)
3947 return;
3948
3898 if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) 3949 if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr))
3899 fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n", 3950 fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n",
3900 base_cpu, msr, 3951 base_cpu, msr,
@@ -4198,7 +4249,12 @@ void process_cpuid()
4198 BIC_PRESENT(BIC_Pkgpc10); 4249 BIC_PRESENT(BIC_Pkgpc10);
4199 } 4250 }
4200 do_irtl_hsw = has_hsw_msrs(family, model); 4251 do_irtl_hsw = has_hsw_msrs(family, model);
4201 do_skl_residency = has_skl_msrs(family, model); 4252 if (has_skl_msrs(family, model)) {
4253 BIC_PRESENT(BIC_Totl_c0);
4254 BIC_PRESENT(BIC_Any_c0);
4255 BIC_PRESENT(BIC_GFX_c0);
4256 BIC_PRESENT(BIC_CPUGFX);
4257 }
4202 do_slm_cstates = is_slm(family, model); 4258 do_slm_cstates = is_slm(family, model);
4203 do_knl_cstates = is_knl(family, model); 4259 do_knl_cstates = is_knl(family, model);
4204 4260
@@ -4578,7 +4634,7 @@ int get_and_dump_counters(void)
4578} 4634}
4579 4635
4580void print_version() { 4636void print_version() {
4581 fprintf(outf, "turbostat version 17.04.12" 4637 fprintf(outf, "turbostat version 17.06.23"
4582 " - Len Brown <lenb@kernel.org>\n"); 4638 " - Len Brown <lenb@kernel.org>\n");
4583} 4639}
4584 4640
@@ -4951,6 +5007,7 @@ void cmdline(int argc, char **argv)
4951 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help 5007 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help
4952 {"Joules", no_argument, 0, 'J'}, 5008 {"Joules", no_argument, 0, 'J'},
4953 {"list", no_argument, 0, 'l'}, 5009 {"list", no_argument, 0, 'l'},
5010 {"migrate", no_argument, 0, 'm'},
4954 {"out", required_argument, 0, 'o'}, 5011 {"out", required_argument, 0, 'o'},
4955 {"quiet", no_argument, 0, 'q'}, 5012 {"quiet", no_argument, 0, 'q'},
4956 {"show", required_argument, 0, 's'}, 5013 {"show", required_argument, 0, 's'},
@@ -4962,7 +5019,7 @@ void cmdline(int argc, char **argv)
4962 5019
4963 progname = argv[0]; 5020 progname = argv[0];
4964 5021
4965 while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v", 5022 while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:Jmo:qST:v",
4966 long_options, &option_index)) != -1) { 5023 long_options, &option_index)) != -1) {
4967 switch (opt) { 5024 switch (opt) {
4968 case 'a': 5025 case 'a':
@@ -5005,6 +5062,9 @@ void cmdline(int argc, char **argv)
5005 list_header_only++; 5062 list_header_only++;
5006 quiet++; 5063 quiet++;
5007 break; 5064 break;
5065 case 'm':
5066 do_migrate = 1;
5067 break;
5008 case 'o': 5068 case 'o':
5009 outf = fopen_or_die(optarg, "w"); 5069 outf = fopen_or_die(optarg, "w");
5010 break; 5070 break;