aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDasaratharaman Chandramouli <dasaratharaman.chandramouli@intel.com>2015-04-15 13:09:50 -0400
committerLen Brown <len.brown@intel.com>2015-05-27 17:26:42 -0400
commite275b3885dffd31095984ed2476ed0447fa7309a (patch)
tree10594c6dd193e9bf5ef007648fee4d4a9279ff37 /tools
parentba155e2d21f6bf05de86a78dbe5bfd8757604a65 (diff)
tools/power turbostat: correctly display more than 2 threads/core
Without this update, turbostat displays only 2 threads per core. Some processors, such as Xeon Phi, have more. Signed-off-by: Dasaratharaman Chandramouli <dasaratharaman.chandramouli@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/power/x86/turbostat/turbostat.c71
1 files changed, 51 insertions, 20 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index bac98ca3d4ca..d85adbafbe60 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -1381,12 +1381,41 @@ int parse_int_file(const char *fmt, ...)
1381} 1381}
1382 1382
1383/* 1383/*
1384 * cpu_is_first_sibling_in_core(cpu) 1384 * get_cpu_position_in_core(cpu)
1385 * return 1 if given CPU is 1st HT sibling in the core 1385 * return the position of the CPU among its HT siblings in the core
1386 * return -1 if the sibling is not in list
1386 */ 1387 */
1387int cpu_is_first_sibling_in_core(int cpu) 1388int get_cpu_position_in_core(int cpu)
1388{ 1389{
1389 return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1390 char path[64];
1391 FILE *filep;
1392 int this_cpu;
1393 char character;
1394 int i;
1395
1396 sprintf(path,
1397 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list",
1398 cpu);
1399 filep = fopen(path, "r");
1400 if (filep == NULL) {
1401 perror(path);
1402 exit(1);
1403 }
1404
1405 for (i = 0; i < topo.num_threads_per_core; i++) {
1406 fscanf(filep, "%d", &this_cpu);
1407 if (this_cpu == cpu) {
1408 fclose(filep);
1409 return i;
1410 }
1411
1412 /* Account for no separator after last thread*/
1413 if (i != (topo.num_threads_per_core - 1))
1414 fscanf(filep, "%c", &character);
1415 }
1416
1417 fclose(filep);
1418 return -1;
1390} 1419}
1391 1420
1392/* 1421/*
@@ -1412,25 +1441,31 @@ int get_num_ht_siblings(int cpu)
1412{ 1441{
1413 char path[80]; 1442 char path[80];
1414 FILE *filep; 1443 FILE *filep;
1415 int sib1, sib2; 1444 int sib1;
1416 int matches; 1445 int matches = 0;
1417 char character; 1446 char character;
1447 char str[100];
1448 char *ch;
1418 1449
1419 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1450 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
1420 filep = fopen_or_die(path, "r"); 1451 filep = fopen_or_die(path, "r");
1452
1421 /* 1453 /*
1422 * file format: 1454 * file format:
1423 * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4) 1455 * A ',' separated or '-' separated set of numbers
1424 * otherwinse 1 sibling (self). 1456 * (eg 1-2 or 1,3,4,5)
1425 */ 1457 */
1426 matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2); 1458 fscanf(filep, "%d%c\n", &sib1, &character);
1459 fseek(filep, 0, SEEK_SET);
1460 fgets(str, 100, filep);
1461 ch = strchr(str, character);
1462 while (ch != NULL) {
1463 matches++;
1464 ch = strchr(ch+1, character);
1465 }
1427 1466
1428 fclose(filep); 1467 fclose(filep);
1429 1468 return matches+1;
1430 if (matches == 3)
1431 return 2;
1432 else
1433 return 1;
1434} 1469}
1435 1470
1436/* 1471/*
@@ -2755,13 +2790,9 @@ int initialize_counters(int cpu_id)
2755 2790
2756 my_package_id = get_physical_package_id(cpu_id); 2791 my_package_id = get_physical_package_id(cpu_id);
2757 my_core_id = get_core_id(cpu_id); 2792 my_core_id = get_core_id(cpu_id);
2758 2793 my_thread_id = get_cpu_position_in_core(cpu_id);
2759 if (cpu_is_first_sibling_in_core(cpu_id)) { 2794 if (!my_thread_id)
2760 my_thread_id = 0;
2761 topo.num_cores++; 2795 topo.num_cores++;
2762 } else {
2763 my_thread_id = 1;
2764 }
2765 2796
2766 init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); 2797 init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id);
2767 init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); 2798 init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id);