diff --git a/sysutils/turbostat/Makefile b/sysutils/turbostat/Makefile index 66bfe421d962..b8f038ea127a 100644 --- a/sysutils/turbostat/Makefile +++ b/sysutils/turbostat/Makefile @@ -1,12 +1,22 @@ # $FreeBSD$ PORTNAME= turbostat -PORTVERSION= 4.17 # Turbostat itself has a version, but we don't bother -PORTREVISION= 1 +PORTVERSION= 5.3 # Turbostat itself has a version, but we don't bother CATEGORIES= sysutils -MASTER_SITES= https://raw.githubusercontent.com/torvalds/linux/v${PORTVERSION}/tools/power/x86/turbostat/ \ - https://raw.githubusercontent.com/torvalds/linux/v${PORTVERSION}/arch/x86/include/asm/ -DISTFILES= ${PORTNAME}.c ${PORTNAME}.8 msr-index.h intel-family.h +MASTER_SITES= https://raw.githubusercontent.com/torvalds/linux/v${PORTVERSION}/ + +TURBOSTAT_DIR= tools/power/x86/turbostat/ +ASM_DIR= arch/x86/include/asm/ +X86ASM_DIR= tools/arch/x86/include/uapi/asm/ +GENERICASM_DIR= tools/include/uapi/asm-generic/ +DISTFILES= ${TURBOSTAT_DIR}${PORTNAME}.c \ + ${TURBOSTAT_DIR}${PORTNAME}.8 \ + ${ASM_DIR}intel-family.h \ + ${ASM_DIR}msr-index.h \ + tools/include/linux/bits.h \ + ${X86ASM_DIR}bitsperlong.h \ + ${GENERICASM_DIR}bitsperlong.h + DIST_SUBDIR= ${PORTNAME}-${PORTVERSION} MAINTAINER= d.scott.phillips@intel.com @@ -22,11 +32,15 @@ PLIST_FILES= sbin/turbostat man/man8/turbostat.8.gz post-extract: do-extract: - @${MKDIR} ${WRKSRC} - ${CP} ${_DISTDIR}/${PORTNAME}.c ${WRKSRC} - ${CP} ${_DISTDIR}/${PORTNAME}.8 ${WRKSRC} - ${CP} ${_DISTDIR}/msr-index.h ${WRKSRC} - ${CP} ${_DISTDIR}/intel-family.h ${WRKSRC} + @${MKDIR} ${WRKSRC}/linux/asm/asm-generic + ${CP} ${_DISTDIR}/${TURBOSTAT_DIR}${PORTNAME}.c ${WRKSRC} + ${CP} ${_DISTDIR}/${TURBOSTAT_DIR}${PORTNAME}.8 ${WRKSRC} + ${CP} ${_DISTDIR}/tools/include/linux/bits.h ${WRKSRC}/linux + ${CP} ${_DISTDIR}/${X86ASM_DIR}bitsperlong.h ${WRKSRC}/linux/asm + ${CP} ${_DISTDIR}/${ASM_DIR}intel-family.h ${WRKSRC} + ${CP} ${_DISTDIR}/${ASM_DIR}msr-index.h ${WRKSRC} + ${CP} ${_DISTDIR}/${GENERICASM_DIR}bitsperlong.h ${WRKSRC}/linux/asm/asm-generic + do-build: cd ${WRKSRC} && ${CC} ${CFLAGS} -DMSRHEADER='"msr-index.h"' -DINTEL_FAMILY_HEADER='"intel-family.h"' -o ${PORTNAME} ${PORTNAME}.c -lutil diff --git a/sysutils/turbostat/distinfo b/sysutils/turbostat/distinfo index 7efda87eb84e..8684aab16595 100644 --- a/sysutils/turbostat/distinfo +++ b/sysutils/turbostat/distinfo @@ -1,9 +1,15 @@ -TIMESTAMP = 1531331060 -SHA256 (turbostat-4.17/turbostat.c) = 23bc86ba086b0b18bfb92619eb66e0c482f7d6c20f5a00d9c333ac2a1c212660 -SIZE (turbostat-4.17/turbostat.c) = 135407 -SHA256 (turbostat-4.17/turbostat.8) = b58eddff29a33ada502627a457021dd70191a4e4bb96b17ff44b1623158b3ed4 -SIZE (turbostat-4.17/turbostat.8) = 18201 -SHA256 (turbostat-4.17/msr-index.h) = f984e5737423ed1e5beea2d543f2f263321f43b74abc31d728f306489279e4cf -SIZE (turbostat-4.17/msr-index.h) = 29422 -SHA256 (turbostat-4.17/intel-family.h) = c3b888feb0e1a73c0aa6817908c2e71313b1dc2d6c834700d1f983746cc49258 -SIZE (turbostat-4.17/intel-family.h) = 2629 +TIMESTAMP = 1574260829 +SHA256 (turbostat-5.3/tools/power/x86/turbostat/turbostat.c) = d37950aa03c9fc719b53f416edcf9b361806e11b00be3520acf0b502c27054cb +SIZE (turbostat-5.3/tools/power/x86/turbostat/turbostat.c) = 153590 +SHA256 (turbostat-5.3/tools/power/x86/turbostat/turbostat.8) = fa255211daee4d3a504c9b9e38bdbb9e7c7e739a60a9a2648dbac0edb4cd774f +SIZE (turbostat-5.3/tools/power/x86/turbostat/turbostat.8) = 20239 +SHA256 (turbostat-5.3/arch/x86/include/asm/intel-family.h) = a6354dd96e09d000df29fdcff3adb4bdc595b662ff0894dbc07451f65253efb5 +SIZE (turbostat-5.3/arch/x86/include/asm/intel-family.h) = 3993 +SHA256 (turbostat-5.3/arch/x86/include/asm/msr-index.h) = d21fa6a86adb98a51f68ecc7d9074120291dd435522bbbe25895b6098b236920 +SIZE (turbostat-5.3/arch/x86/include/asm/msr-index.h) = 32543 +SHA256 (turbostat-5.3/tools/include/linux/bits.h) = 8121345ae3a14048a93d016664adf7155c3cd772b1b9536a27e5b91bd862fb07 +SIZE (turbostat-5.3/tools/include/linux/bits.h) = 833 +SHA256 (turbostat-5.3/tools/arch/x86/include/uapi/asm/bitsperlong.h) = 8897a5a9ea04d1f99bc7512542468983ca71808c7cf1d8ddfb23fb91654cad14 +SIZE (turbostat-5.3/tools/arch/x86/include/uapi/asm/bitsperlong.h) = 320 +SHA256 (turbostat-5.3/tools/include/uapi/asm-generic/bitsperlong.h) = 7168fc12586f612d643dc2b1157413a6af8fd5c37f04b2252bbb7668581bd4ab +SIZE (turbostat-5.3/tools/include/uapi/asm-generic/bitsperlong.h) = 516 diff --git a/sysutils/turbostat/files/patch-linux_asm_bitsperlong.h b/sysutils/turbostat/files/patch-linux_asm_bitsperlong.h new file mode 100644 index 000000000000..a4b58a1b1370 --- /dev/null +++ b/sysutils/turbostat/files/patch-linux_asm_bitsperlong.h @@ -0,0 +1,10 @@ +--- linux/asm/bitsperlong.h.orig 2019-11-20 21:11:45 UTC ++++ linux/asm/bitsperlong.h +@@ -8,6 +8,6 @@ + # define __BITS_PER_LONG 32 + #endif + +-#include ++#include "asm-generic/bitsperlong.h" + + #endif /* __ASM_X86_BITSPERLONG_H */ diff --git a/sysutils/turbostat/files/patch-linux_bits.h b/sysutils/turbostat/files/patch-linux_bits.h new file mode 100644 index 000000000000..8dcf6fdcaf06 --- /dev/null +++ b/sysutils/turbostat/files/patch-linux_bits.h @@ -0,0 +1,11 @@ +--- linux/bits.h.orig 2019-11-20 21:11:33 UTC ++++ linux/bits.h +@@ -1,7 +1,7 @@ + /* SPDX-License-Identifier: GPL-2.0 */ + #ifndef __LINUX_BITS_H + #define __LINUX_BITS_H +-#include ++#include "asm/bitsperlong.h" + + #define BIT(nr) (1UL << (nr)) + #define BIT_ULL(nr) (1ULL << (nr)) diff --git a/sysutils/turbostat/files/patch-msr-index.h b/sysutils/turbostat/files/patch-msr-index.h new file mode 100644 index 000000000000..1e4f81cc9277 --- /dev/null +++ b/sysutils/turbostat/files/patch-msr-index.h @@ -0,0 +1,11 @@ +--- msr-index.h.orig 2019-11-20 21:11:54 UTC ++++ msr-index.h +@@ -2,7 +2,7 @@ + #ifndef _ASM_X86_MSR_INDEX_H + #define _ASM_X86_MSR_INDEX_H + +-#include ++#include "linux/bits.h" + + /* + * CPU model specific register (MSR) numbers. diff --git a/sysutils/turbostat/files/patch-turbostat.c b/sysutils/turbostat/files/patch-turbostat.c index 67407110c227..6885519318ec 100644 --- a/sysutils/turbostat/files/patch-turbostat.c +++ b/sysutils/turbostat/files/patch-turbostat.c @@ -1,6 +1,6 @@ ---- turbostat.c.orig 2018-07-31 20:42:12 UTC +--- turbostat.c.orig 2019-12-16 20:14:20 UTC +++ turbostat.c -@@ -41,7 +41,31 @@ +@@ -30,7 +30,31 @@ #include #include #include @@ -30,11 +30,11 @@ #include +#endif #include + #include - char *proc_stat = "/proc/stat"; -@@ -132,7 +156,9 @@ unsigned int has_misc_feature_control; - #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) - #define TJMAX_DEFAULT 100 +@@ -145,7 +169,9 @@ int ignore_stdin; + #define MSR_CORE_ENERGY_STAT 0xc001029a + #define MSR_PKG_ENERGY_STAT 0xc001029b +#ifndef __FreeBSD__ #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -42,7 +42,7 @@ /* * buffer size used by sscanf() for added column names -@@ -309,6 +335,7 @@ int cpu_migrate(int cpu) +@@ -357,6 +383,7 @@ int cpu_migrate(int cpu) else return 0; } @@ -50,7 +50,7 @@ int get_msr_fd(int cpu) { char pathname[32]; -@@ -319,18 +346,39 @@ int get_msr_fd(int cpu) +@@ -367,18 +394,39 @@ int get_msr_fd(int cpu) if (fd) return fd; @@ -91,20 +91,21 @@ ssize_t retval; retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); -@@ -340,6 +388,7 @@ int get_msr(int cpu, off_t offset, unsigned long long +@@ -388,6 +436,7 @@ int get_msr(int cpu, off_t offset, unsigned long long return 0; } +#endif /* - * Each string in this array is compared in --show and --hide cmdline. -@@ -2239,6 +2288,173 @@ int parse_int_file(const char *fmt, ...) - return value; + * This list matches the column headers, except +@@ -2018,7 +2067,308 @@ done: + return 0; } +#ifdef __FreeBSD__ +static int ncpus; ++static int maxcpu; +struct cpuset_list { + cpuset_t *sets; + size_t len; @@ -150,13 +151,16 @@ + +static void read_topology_spec(void) +{ -+ char spec[16384]; -+ size_t sz = sizeof(spec) - 1; -+ char *i; ++ char *spec, *i; ++ size_t sz = 0; + ++ if (sysctlbyname("kern.sched.topology_spec", NULL, &sz, NULL, 0) != ENOMEM) ++ err(1, "sysctl: kern.sched.topology_spec: failed"); ++ spec = malloc(sz + 1); ++ if (spec == NULL) ++ err(1, "malloc: failed"); + if (sysctlbyname("kern.sched.topology_spec", spec, &sz, NULL, 0)) + err(1, "sysctl: kern.sched.topology_spec: failed"); -+ spec[sizeof(spec) - 1] = '\0'; + + /* Skip the entire system entry. */ + i = strstr(spec, "logical_cpu_id; ++ ++ for (i = 0; i <= topo.max_cpu_num; i++) { ++ sprintf(path, "/sys/devices/system/cpu/cpu%d/node%i/cpulist", ++ cpu, i); ++ filep = fopen(path, "r"); ++ if (!filep) ++ continue; ++ fclose(filep); ++ return i; ++ } ++ return -1; ++} ++ ++int get_thread_siblings(struct cpu_topology *thiscpu) ++{ ++ char path[80], character; ++ FILE *filep; ++ unsigned long map; ++ int so, shift, sib_core; ++ int cpu = thiscpu->logical_cpu_id; ++ int offset = topo.max_cpu_num + 1; ++ size_t size; ++ int thread_id = 0; ++ ++ thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); ++ if (thiscpu->thread_id < 0) ++ thiscpu->thread_id = thread_id++; ++ if (!thiscpu->put_ids) ++ return -1; ++ ++ size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); ++ CPU_ZERO_S(size, thiscpu->put_ids); ++ ++ sprintf(path, ++ "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu); ++ filep = fopen_or_die(path, "r"); ++ do { ++ offset -= BITMASK_SIZE; ++ if (fscanf(filep, "%lx%c", &map, &character) != 2) ++ err(1, "%s: failed to parse file", path); ++ for (shift = 0; shift < BITMASK_SIZE; shift++) { ++ if ((map >> shift) & 0x1) { ++ so = shift + offset; ++ sib_core = get_core_id(so); ++ if (sib_core == thiscpu->physical_core_id) { ++ CPU_SET_S(so, size, thiscpu->put_ids); ++ if ((so != cpu) && ++ (cpus[so].thread_id < 0)) ++ cpus[so].thread_id = ++ thread_id++; ++ } ++ } ++ } ++ } while (!strncmp(&character, ",", 1)); ++ fclose(filep); ++ ++ return CPU_COUNT_S(size, thiscpu->put_ids); ++} ++ ++void set_max_cpu_num(void) ++{ ++ FILE *filep; ++ unsigned long dummy; ++ ++ topo.max_cpu_num = 0; ++ filep = fopen_or_die( ++ "/sys/devices/system/cpu/cpu0/topology/thread_siblings", ++ "r"); ++ while (fscanf(filep, "%lx,", &dummy) == 1) ++ topo.max_cpu_num += BITMASK_SIZE; ++ fclose(filep); ++ topo.max_cpu_num--; /* 0 based */ ++} ++ +#endif ++/* + * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: + * If you change the values, note they are used both in comparisons + * (>= PCL__7) and to index pkg_cstate_limit_strings[]. +@@ -2540,30 +2890,7 @@ int parse_int_file(const char *fmt, ...) + return value; + } + +-/* +- * cpu_is_first_core_in_package(cpu) +- * return 1 if given CPU is 1st core in package +- */ +-int cpu_is_first_core_in_package(int cpu) +-{ +- return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); +-} + +-int get_physical_package_id(int cpu) +-{ +- return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); +-} +- +-int get_die_id(int cpu) +-{ +- return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/die_id", cpu); +-} +- +-int get_core_id(int cpu) +-{ +- return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); +-} +- + void set_node_data(void) + { + int pkg, node, lnode, cpu, cpux; +@@ -2605,71 +2932,8 @@ void set_node_data(void) + } + } + +-int get_physical_node_id(struct cpu_topology *thiscpu) +-{ +- char path[80]; +- FILE *filep; +- int i; +- int cpu = thiscpu->logical_cpu_id; + +- for (i = 0; i <= topo.max_cpu_num; i++) { +- sprintf(path, "/sys/devices/system/cpu/cpu%d/node%i/cpulist", +- cpu, i); +- filep = fopen(path, "r"); +- if (!filep) +- continue; +- fclose(filep); +- return i; +- } +- return -1; +-} +-int get_thread_siblings(struct cpu_topology *thiscpu) +-{ +- char path[80], character; +- FILE *filep; +- unsigned long map; +- int so, shift, sib_core; +- int cpu = thiscpu->logical_cpu_id; +- int offset = topo.max_cpu_num + 1; +- size_t size; +- int thread_id = 0; +- +- thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); +- if (thiscpu->thread_id < 0) +- thiscpu->thread_id = thread_id++; +- if (!thiscpu->put_ids) +- return -1; +- +- size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); +- CPU_ZERO_S(size, thiscpu->put_ids); +- +- sprintf(path, +- "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu); +- filep = fopen_or_die(path, "r"); +- do { +- offset -= BITMASK_SIZE; +- if (fscanf(filep, "%lx%c", &map, &character) != 2) +- err(1, "%s: failed to parse file", path); +- for (shift = 0; shift < BITMASK_SIZE; shift++) { +- if ((map >> shift) & 0x1) { +- so = shift + offset; +- sib_core = get_core_id(so); +- if (sib_core == thiscpu->physical_core_id) { +- CPU_SET_S(so, size, thiscpu->put_ids); +- if ((so != cpu) && +- (cpus[so].thread_id < 0)) +- cpus[so].thread_id = +- thread_id++; +- } +- } +- } +- } while (!strncmp(&character, ",", 1)); +- fclose(filep); +- +- return CPU_COUNT_S(size, thiscpu->put_ids); +-} +- /* * run func(thread, core, package) in topology order -@@ -2371,6 +2588,22 @@ int for_all_cpus_2(int (func)(struct thread_data *, st + * skip non-present cpus +@@ -2724,6 +2988,22 @@ int for_all_cpus_2(int (func)(struct thread_data *, st return 0; } @@ -304,7 +534,7 @@ /* * run func(cpu) on every cpu in /proc/stat * return max_cpu number -@@ -2401,6 +2634,7 @@ int for_all_proc_cpus(int (func)(int)) +@@ -2754,6 +3034,7 @@ int for_all_proc_cpus(int (func)(int)) fclose(fp); return 0; } @@ -312,7 +542,29 @@ void re_initialize(void) { -@@ -2428,6 +2662,85 @@ int mark_cpu_present(int cpu) +@@ -2762,21 +3043,7 @@ void re_initialize(void) + printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); + } + +-void set_max_cpu_num(void) +-{ +- FILE *filep; +- unsigned long dummy; + +- topo.max_cpu_num = 0; +- filep = fopen_or_die( +- "/sys/devices/system/cpu/cpu0/topology/thread_siblings", +- "r"); +- while (fscanf(filep, "%lx,", &dummy) == 1) +- topo.max_cpu_num += BITMASK_SIZE; +- fclose(filep); +- topo.max_cpu_num--; /* 0 based */ +-} +- + /* + * count_cpus() + * remember the last one seen, it will be the max +@@ -2798,6 +3065,89 @@ int init_thread_id(int cpu) return 0; } @@ -375,7 +627,7 @@ + } +} + -+static int snapshot_proc_interrupts(void) ++int snapshot_proc_interrupts(void) +{ + if (!intr_map) + init_intr_map(); @@ -394,20 +646,31 @@ + + return 0; +} ++int snapshot_proc_sysfs_files(void) ++{ ++ return 0; ++} +#else /* * snapshot_proc_interrupts() * -@@ -2491,6 +2804,8 @@ int snapshot_proc_interrupts(void) +@@ -2861,6 +3211,7 @@ int snapshot_proc_interrupts(void) } return 0; } -+#endif + /* * snapshot_gfx_rc6_ms() * -@@ -2629,6 +2944,18 @@ restart: +@@ -2989,6 +3340,7 @@ int snapshot_proc_sysfs_files(void) + + return 0; + } ++#endif + + int exit_requested; + +@@ -3140,6 +3492,18 @@ restart: } } @@ -426,7 +689,7 @@ void check_dev_msr() { struct stat sb; -@@ -2677,6 +3004,7 @@ void check_permissions() +@@ -3188,6 +3552,7 @@ void check_permissions() if (do_exit) exit(-6); } @@ -434,7 +697,7 @@ /* * NHM adds support for additional MSRs: -@@ -4520,8 +4848,21 @@ void setup_all_buffers(void) +@@ -5192,8 +5557,21 @@ void setup_all_buffers(void) for_all_proc_cpus(initialize_counters); } @@ -456,7 +719,7 @@ base_cpu = sched_getcpu(); if (base_cpu < 0) err(-ENODEV, "No valid cpus found"); -@@ -4529,6 +4870,7 @@ void set_base_cpu(void) +@@ -5201,6 +5579,7 @@ void set_base_cpu(void) if (debug > 1) fprintf(outf, "base_cpu = %d\n", base_cpu); } @@ -464,3 +727,14 @@ void turbostat_init() { +@@ -5769,7 +6148,9 @@ int main(int argc, char **argv) + if (!quiet) + print_version(); + +- probe_sysfs(); ++ #ifndef __FreeBSD__ ++ probe_sysfs(); ++ #endif + + turbostat_init(); +