3 # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227041
5 # panic: [pmc,2749] (ri21, rc1) waiting too long for pmc to be free
8 # KDB: stack backtrace:
9 # db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe01ab083850
10 # vpanic() at vpanic+0x181/frame 0xfffffe01ab0838a0
11 # panic() at panic+0x43/frame 0xfffffe01ab083900
12 # pmc_wait_for_pmc_idle() at pmc_wait_for_pmc_idle+0xa2/frame 0xfffffe01ab083930
13 # pmc_release_pmc_descriptor() at pmc_release_pmc_descriptor+0x20b/frame 0xfffffe01ab083980
14 # pmc_syscall_handler() at pmc_syscall_handler+0x4bd/frame 0xfffffe01ab083ac0
15 # amd64_syscall() at amd64_syscall+0x762/frame 0xfffffe01ab083bf0
16 # fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe01ab083bf0
17 # --- syscall (0, FreeBSD ELF64, nosys), rip = 0x8009c154a, rsp = 0x7fffffffe4d8, rbp = 0x7fffffffe500 ---
19 # [ thread pid 3123 tid 100454 ]
20 # Stopped at kdb_enter+0x37: movq $0,0x1285d1e(%rip)
22 # version: FreeBSD 14.0-CURRENT #1 ufs-n247476-f77f86ecfea: Mon Jun 21 08:40:40 CEST 2021
23 # pho@t2.osted.lan:/var/tmp/deviant3/sys/amd64/compile/PHO
27 cat > /tmp/pmc-crash.c <<EOF
29 Copyright (c) 2018 Dominic Dwyer <dom@itsallbroken.com>
32 Redistribution and use in source and binary forms, with or without
33 modification, are permitted provided that the following conditions are met:
35 1. Redistributions of source code must retain the above copyright notice,
36 this list of conditions and the following disclaimer.
38 2. Redistributions in binary form must reproduce the above copyright notice,
39 this list of conditions and the following disclaimer in the documentation
40 and/or other materials provided with the distribution.
42 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
46 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52 POSSIBILITY OF SUCH DAMAGE.
54 clang -lpmc pmc-crash.c -o pmc-crash
57 #include <sys/types.h>
69 printf("pmc_init %s", strerror(errno));
74 if (pmc_allocate("inst_retired.any", PMC_MODE_TC, 0, PMC_CPU_ANY,
77 printf("pmc_allocate %s", strerror(errno));
81 printf("attaching to self\n");
82 if (pmc_attach(pmc_id, 0) != 0)
84 printf("pmc_attach %s", strerror(errno));
88 if (pmc_start(pmc_id) != 0)
90 printf("pmc_start %s", strerror(errno));
95 for (int i = 0; i < 100; i++)
101 printf("success, detaching...\n");
102 pmc_detach(pmc_id, 0);
108 mycc -o /tmp/pmc-crash -Wall -Wextra -O0 /tmp/pmc-crash.c -lpmc || exit
109 kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; }
114 rm -f /tmp/pmc-crash /tmp/pmc-crash.core /tmp/pmc-crash.c
115 [ $loaded ] && kldunload hwpmc