Skip to content

Commit

Permalink
sysutils/turbostat: unbreak runtime on FreeBSD >= 13.1
Browse files Browse the repository at this point in the history
$ turbostat
turbostat version 17.06.23 - Len Brown <lenb@kernel.org>
Segmentation fault

* thread #1, name = 'turbostat', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x0000000000216992 turbostat`topology_probe at turbostat.c:4685:7
   4682          * Validate that all cpus in cpu_subset are also in cpu_present_set
   4683          */
   4684         for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) {
-> 4685                 if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset))
   4686                         if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set))
   4687                                 err(1, "cpu%d not present", i);
   4688         }
(lldb) bt
* thread #1, name = 'turbostat', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #0: 0x0000000000216992 turbostat`topology_probe at turbostat.c:4685:7
    frame #1: 0x00000000002111c9 turbostat`setup_all_buffers at turbostat.c:4853:2
    frame #2: 0x0000000000217909 turbostat`turbostat_init at turbostat.c:4888:2
    frame #3: 0x0000000000218f3f turbostat`main(argc=1, argv=0x0000000820444710) at turbostat.c:5447:2
    frame #4: 0x0000000000207160 turbostat`_start(ap=<unavailable>, cleanup=<unavailable>) at crt1_c.c:73:7
(lldb) p cpu_subset
(cpu_set_t *) $0 = NULL

PR:		262866
  • Loading branch information
jbeich committed Feb 19, 2023
1 parent 94c603d commit b27279c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sysutils/turbostat/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PORTNAME= turbostat
PORTVERSION= 4.17 # Turbostat itself has a version, but we don't bother
PORTREVISION= 2
PORTREVISION= 3
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/
Expand Down
11 changes: 10 additions & 1 deletion sysutils/turbostat/files/patch-turbostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
+#define CPU_ALLOC(_ign) ({(cpuset_t*)malloc(sizeof(cpuset_t));})
+#define CPU_ALLOC_SIZE(_ign) sizeof(cpuset_t)
+#define CPU_FREE free
+#define CPU_ISSET_S(cpu, _ign, set) (set && CPU_ISSET(cpu, set))
+#define CPU_ISSET_S(cpu, _ign, set) CPU_ISSET(cpu, set)
+#define CPU_SET_S(cpu, _ign, set) CPU_SET(cpu, set)
+#define CPU_ZERO_S(_ign, set) CPU_ZERO(set)
+#define sched_setaffinity(_x, _y, set) cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset_t), set)
Expand Down Expand Up @@ -445,6 +445,15 @@
/*
* NHM adds support for additional MSRs:
@@ -4343,7 +4682,7 @@ void topology_probe()
* Validate that all cpus in cpu_subset are also in cpu_present_set
*/
for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) {
- if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset))
+ if (cpu_subset && CPU_ISSET_S(i, cpu_subset_size, cpu_subset))
if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set))
err(1, "cpu%d not present", i);
}
@@ -4520,8 +4852,21 @@ void setup_all_buffers(void)
for_all_proc_cpus(initialize_counters);
}
Expand Down

0 comments on commit b27279c

Please sign in to comment.