test_intel_pt.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. #!/bin/bash
  2. # Miscellaneous Intel PT testing (exclusive)
  3. # SPDX-License-Identifier: GPL-2.0
  4. set -e
  5. # Skip if no Intel PT
  6. perf list pmu | grep -q 'intel_pt//' || exit 2
  7. shelldir=$(dirname "$0")
  8. # shellcheck source=lib/waiting.sh
  9. . "${shelldir}"/lib/waiting.sh
  10. skip_cnt=0
  11. ok_cnt=0
  12. err_cnt=0
  13. temp_dir=$(mktemp -d /tmp/perf-test-intel-pt-sh.XXXXXXXXXX)
  14. tmpfile="${temp_dir}/tmp-perf.data"
  15. perfdatafile="${temp_dir}/test-perf.data"
  16. outfile="${temp_dir}/test-out.txt"
  17. errfile="${temp_dir}/test-err.txt"
  18. workload="${temp_dir}/workload"
  19. awkscript="${temp_dir}/awkscript"
  20. jitdump_workload="${temp_dir}/jitdump_workload"
  21. maxbrstack="${temp_dir}/maxbrstack.py"
  22. cleanup()
  23. {
  24. trap - EXIT TERM INT
  25. sane=$(echo "${temp_dir}" | cut -b 1-26)
  26. if [ "${sane}" = "/tmp/perf-test-intel-pt-sh" ] ; then
  27. echo "--- Cleaning up ---"
  28. rm -f "${temp_dir}/"*
  29. rmdir "${temp_dir}"
  30. fi
  31. }
  32. trap_cleanup()
  33. {
  34. cleanup
  35. exit 1
  36. }
  37. trap trap_cleanup EXIT TERM INT
  38. # perf record for testing without decoding
  39. perf_record_no_decode()
  40. {
  41. # Options to speed up recording: no post-processing, no build-id cache update,
  42. # and no BPF events.
  43. perf record -B -N --no-bpf-event "$@"
  44. }
  45. # perf record for testing should not need BPF events
  46. perf_record_no_bpf()
  47. {
  48. # Options for no BPF events
  49. perf record --no-bpf-event "$@"
  50. }
  51. have_workload=false
  52. cat << _end_of_file_ | /usr/bin/cc -o "${workload}" -xc - -pthread && have_workload=true
  53. #include <time.h>
  54. #include <pthread.h>
  55. void work(void) {
  56. struct timespec tm = {
  57. .tv_nsec = 1000000,
  58. };
  59. int i;
  60. /* Run for about 30 seconds */
  61. for (i = 0; i < 30000; i++)
  62. nanosleep(&tm, NULL);
  63. }
  64. void *threadfunc(void *arg) {
  65. work();
  66. return NULL;
  67. }
  68. int main(void) {
  69. pthread_t th;
  70. pthread_create(&th, NULL, threadfunc, NULL);
  71. work();
  72. pthread_join(th, NULL);
  73. return 0;
  74. }
  75. _end_of_file_
  76. can_cpu_wide()
  77. {
  78. echo "Checking for CPU-wide recording on CPU $1"
  79. if ! perf_record_no_decode -o "${tmpfile}" -e dummy:u -C "$1" true >/dev/null 2>&1 ; then
  80. echo "No so skipping"
  81. return 2
  82. fi
  83. echo OK
  84. return 0
  85. }
  86. test_system_wide_side_band()
  87. {
  88. echo "--- Test system-wide sideband ---"
  89. # Need CPU 0 and CPU 1
  90. can_cpu_wide 0 || return $?
  91. can_cpu_wide 1 || return $?
  92. # Record on CPU 0 a task running on CPU 1
  93. perf_record_no_decode -o "${perfdatafile}" -e intel_pt//u -C 0 -- taskset --cpu-list 1 uname
  94. # Should get MMAP events from CPU 1 because they can be needed to decode
  95. mmap_cnt=$(perf script -i "${perfdatafile}" --no-itrace --show-mmap-events -C 1 2>/dev/null | grep -c MMAP)
  96. if [ "${mmap_cnt}" -gt 0 ] ; then
  97. echo OK
  98. return 0
  99. fi
  100. echo "Failed to record MMAP events on CPU 1 when tracing CPU 0"
  101. return 1
  102. }
  103. can_kernel()
  104. {
  105. if [ -z "${can_kernel_trace}" ] ; then
  106. can_kernel_trace=0
  107. perf_record_no_decode -o "${tmpfile}" -e dummy:k true >/dev/null 2>&1 && can_kernel_trace=1
  108. fi
  109. if [ ${can_kernel_trace} -eq 0 ] ; then
  110. echo "SKIP: no kernel tracing"
  111. return 2
  112. fi
  113. return 0
  114. }
  115. test_per_thread()
  116. {
  117. k="$1"
  118. desc="$2"
  119. echo "--- Test per-thread ${desc}recording ---"
  120. if ! $have_workload ; then
  121. echo "No workload, so skipping"
  122. return 2
  123. fi
  124. if [ "${k}" = "k" ] ; then
  125. can_kernel || return 2
  126. fi
  127. cat <<- "_end_of_file_" > "${awkscript}"
  128. BEGIN {
  129. s = "[ ]*"
  130. u = s"[0-9]+"s
  131. d = s"[0-9-]+"s
  132. x = s"[0-9a-fA-FxX]+"s
  133. mmapping = "idx"u": mmapping fd"u
  134. set_output = "idx"u": set output fd"u"->"u
  135. perf_event_open = "sys_perf_event_open: pid"d"cpu"d"group_fd"d"flags"x"="u
  136. }
  137. /perf record opening and mmapping events/ {
  138. if (!done)
  139. active = 1
  140. }
  141. /perf record done opening and mmapping events/ {
  142. active = 0
  143. done = 1
  144. }
  145. $0 ~ perf_event_open && active {
  146. match($0, perf_event_open)
  147. $0 = substr($0, RSTART, RLENGTH)
  148. pid = $3
  149. cpu = $5
  150. fd = $11
  151. print "pid " pid " cpu " cpu " fd " fd " : " $0
  152. fd_array[fd] = fd
  153. pid_array[fd] = pid
  154. cpu_array[fd] = cpu
  155. }
  156. $0 ~ mmapping && active {
  157. match($0, mmapping)
  158. $0 = substr($0, RSTART, RLENGTH)
  159. fd = $5
  160. print "fd " fd " : " $0
  161. if (fd in fd_array) {
  162. mmap_array[fd] = 1
  163. } else {
  164. print "Unknown fd " fd
  165. exit 1
  166. }
  167. }
  168. $0 ~ set_output && active {
  169. match($0, set_output)
  170. $0 = substr($0, RSTART, RLENGTH)
  171. fd = $6
  172. fd_to = $8
  173. print "fd " fd " fd_to " fd_to " : " $0
  174. if (fd in fd_array) {
  175. if (fd_to in fd_array) {
  176. set_output_array[fd] = fd_to
  177. } else {
  178. print "Unknown fd " fd_to
  179. exit 1
  180. }
  181. } else {
  182. print "Unknown fd " fd
  183. exit 1
  184. }
  185. }
  186. END {
  187. print "Checking " length(fd_array) " fds"
  188. for (fd in fd_array) {
  189. if (fd in mmap_array) {
  190. pid = pid_array[fd]
  191. if (pid != -1) {
  192. if (pid in pids) {
  193. print "More than 1 mmap for PID " pid
  194. exit 1
  195. }
  196. pids[pid] = 1
  197. }
  198. cpu = cpu_array[fd]
  199. if (cpu != -1) {
  200. if (cpu in cpus) {
  201. print "More than 1 mmap for CPU " cpu
  202. exit 1
  203. }
  204. cpus[cpu] = 1
  205. }
  206. } else if (!(fd in set_output_array)) {
  207. print "No mmap for fd " fd
  208. exit 1
  209. }
  210. }
  211. n = length(pids)
  212. if (n != thread_cnt) {
  213. print "Expected " thread_cnt " per-thread mmaps - found " n
  214. exit 1
  215. }
  216. }
  217. _end_of_file_
  218. $workload &
  219. w1=$!
  220. $workload &
  221. w2=$!
  222. echo "Workload PIDs are $w1 and $w2"
  223. wait_for_threads ${w1} 2
  224. wait_for_threads ${w2} 2
  225. perf_record_no_decode -o "${perfdatafile}" -e intel_pt//u"${k}" -vvv --per-thread -p "${w1},${w2}" 2>"${errfile}" >"${outfile}" &
  226. ppid=$!
  227. echo "perf PID is $ppid"
  228. wait_for_perf_to_start ${ppid} "${errfile}" || return 1
  229. kill ${w1}
  230. wait_for_process_to_exit ${w1} || return 1
  231. is_running ${ppid} || return 1
  232. kill ${w2}
  233. wait_for_process_to_exit ${w2} || return 1
  234. wait_for_process_to_exit ${ppid} || return 1
  235. awk -v thread_cnt=4 -f "${awkscript}" "${errfile}" || return 1
  236. echo OK
  237. return 0
  238. }
  239. test_jitdump()
  240. {
  241. echo "--- Test tracing self-modifying code that uses jitdump ---"
  242. script_path=$(realpath "$0")
  243. script_dir=$(dirname "$script_path")
  244. jitdump_incl_dir="${script_dir}/../../util"
  245. jitdump_h="${jitdump_incl_dir}/jitdump.h"
  246. if ! perf check feature -q libelf ; then
  247. echo "SKIP: libelf is needed for jitdump"
  248. return 2
  249. fi
  250. if [ ! -e "${jitdump_h}" ] ; then
  251. echo "SKIP: Include file jitdump.h not found"
  252. return 2
  253. fi
  254. if [ -z "${have_jitdump_workload}" ] ; then
  255. have_jitdump_workload=false
  256. # Create a workload that uses self-modifying code and generates its own jitdump file
  257. cat <<- "_end_of_file_" | /usr/bin/cc -o "${jitdump_workload}" -I "${jitdump_incl_dir}" -xc - -pthread && have_jitdump_workload=true
  258. #define _GNU_SOURCE
  259. #include <sys/mman.h>
  260. #include <sys/types.h>
  261. #include <stddef.h>
  262. #include <stdio.h>
  263. #include <stdint.h>
  264. #include <unistd.h>
  265. #include <string.h>
  266. #include "jitdump.h"
  267. #define CHK_BYTE 0x5a
  268. static inline uint64_t rdtsc(void)
  269. {
  270. unsigned int low, high;
  271. asm volatile("rdtsc" : "=a" (low), "=d" (high));
  272. return low | ((uint64_t)high) << 32;
  273. }
  274. static FILE *open_jitdump(void)
  275. {
  276. struct jitheader header = {
  277. .magic = JITHEADER_MAGIC,
  278. .version = JITHEADER_VERSION,
  279. .total_size = sizeof(header),
  280. .pid = getpid(),
  281. .timestamp = rdtsc(),
  282. .flags = JITDUMP_FLAGS_ARCH_TIMESTAMP,
  283. };
  284. char filename[256];
  285. FILE *f;
  286. void *m;
  287. snprintf(filename, sizeof(filename), "jit-%d.dump", getpid());
  288. f = fopen(filename, "w+");
  289. if (!f)
  290. goto err;
  291. /* Create an MMAP event for the jitdump file. That is how perf tool finds it. */
  292. m = mmap(0, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE, fileno(f), 0);
  293. if (m == MAP_FAILED)
  294. goto err_close;
  295. munmap(m, 4096);
  296. if (fwrite(&header,sizeof(header),1,f) != 1)
  297. goto err_close;
  298. return f;
  299. err_close:
  300. fclose(f);
  301. err:
  302. return NULL;
  303. }
  304. static int write_jitdump(FILE *f, void *addr, const uint8_t *dat, size_t sz, uint64_t *idx)
  305. {
  306. struct jr_code_load rec = {
  307. .p.id = JIT_CODE_LOAD,
  308. .p.total_size = sizeof(rec) + sz,
  309. .p.timestamp = rdtsc(),
  310. .pid = getpid(),
  311. .tid = gettid(),
  312. .vma = (unsigned long)addr,
  313. .code_addr = (unsigned long)addr,
  314. .code_size = sz,
  315. .code_index = ++*idx,
  316. };
  317. if (fwrite(&rec,sizeof(rec),1,f) != 1 ||
  318. fwrite(dat, sz, 1, f) != 1)
  319. return -1;
  320. return 0;
  321. }
  322. static void close_jitdump(FILE *f)
  323. {
  324. fclose(f);
  325. }
  326. int main()
  327. {
  328. /* Get a memory page to store executable code */
  329. void *addr = mmap(0, 4096, PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  330. /* Code to execute: mov CHK_BYTE, %eax ; ret */
  331. uint8_t dat[] = {0xb8, CHK_BYTE, 0x00, 0x00, 0x00, 0xc3};
  332. FILE *f = open_jitdump();
  333. uint64_t idx = 0;
  334. int ret = 1;
  335. if (!f)
  336. return 1;
  337. /* Copy executable code to executable memory page */
  338. memcpy(addr, dat, sizeof(dat));
  339. /* Record it in the jitdump file */
  340. if (write_jitdump(f, addr, dat, sizeof(dat), &idx))
  341. goto out_close;
  342. /* Call it */
  343. ret = ((int (*)(void))addr)() - CHK_BYTE;
  344. out_close:
  345. close_jitdump(f);
  346. return ret;
  347. }
  348. _end_of_file_
  349. fi
  350. if ! $have_jitdump_workload ; then
  351. echo "SKIP: No jitdump workload"
  352. return 2
  353. fi
  354. # Change to temp_dir so jitdump collateral files go there
  355. cd "${temp_dir}"
  356. perf_record_no_bpf -o "${tmpfile}" -e intel_pt//u "${jitdump_workload}"
  357. perf inject -i "${tmpfile}" -o "${perfdatafile}" --jit
  358. decode_br_cnt=$(perf script -i "${perfdatafile}" --itrace=b | wc -l)
  359. # Note that overflow and lost errors are suppressed for the error count
  360. decode_err_cnt=$(perf script -i "${perfdatafile}" --itrace=e-o-l | grep -ci error)
  361. cd -
  362. # Should be thousands of branches
  363. if [ "${decode_br_cnt}" -lt 1000 ] ; then
  364. echo "Decode failed, only ${decode_br_cnt} branches"
  365. return 1
  366. fi
  367. # Should be no errors
  368. if [ "${decode_err_cnt}" -ne 0 ] ; then
  369. echo "Decode failed, ${decode_err_cnt} errors"
  370. perf script -i "${perfdatafile}" --itrace=e-o-l --show-mmap-events | cat
  371. return 1
  372. fi
  373. echo OK
  374. return 0
  375. }
  376. test_packet_filter()
  377. {
  378. echo "--- Test with MTC and TSC disabled ---"
  379. # Disable MTC and TSC
  380. perf_record_no_decode -o "${perfdatafile}" -e intel_pt/mtc=0,tsc=0/u uname
  381. # Should not get MTC packet
  382. mtc_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "MTC 0x")
  383. if [ "${mtc_cnt}" -ne 0 ] ; then
  384. echo "Failed to filter with mtc=0"
  385. return 1
  386. fi
  387. # Should not get TSC package
  388. tsc_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "TSC 0x")
  389. if [ "${tsc_cnt}" -ne 0 ] ; then
  390. echo "Failed to filter with tsc=0"
  391. return 1
  392. fi
  393. echo OK
  394. return 0
  395. }
  396. test_disable_branch()
  397. {
  398. echo "--- Test with branches disabled ---"
  399. # Disable branch
  400. perf_record_no_decode -o "${perfdatafile}" -e intel_pt/branch=0/u uname
  401. # Should not get branch related packets
  402. tnt_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "TNT 0x")
  403. tip_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "TIP 0x")
  404. fup_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "FUP 0x")
  405. if [ "${tnt_cnt}" -ne 0 ] || [ "${tip_cnt}" -ne 0 ] || [ "${fup_cnt}" -ne 0 ] ; then
  406. echo "Failed to disable branches"
  407. return 1
  408. fi
  409. echo OK
  410. return 0
  411. }
  412. test_time_cyc()
  413. {
  414. echo "--- Test with/without CYC ---"
  415. # Check if CYC is supported
  416. cyc=$(cat /sys/bus/event_source/devices/intel_pt/caps/psb_cyc)
  417. if [ "${cyc}" != "1" ] ; then
  418. echo "SKIP: CYC is not supported"
  419. return 2
  420. fi
  421. # Enable CYC
  422. perf_record_no_decode -o "${perfdatafile}" -e intel_pt/cyc/u uname
  423. # should get CYC packets
  424. cyc_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "CYC 0x")
  425. if [ "${cyc_cnt}" = "0" ] ; then
  426. echo "Failed to get CYC packet"
  427. return 1
  428. fi
  429. # Without CYC
  430. perf_record_no_decode -o "${perfdatafile}" -e intel_pt//u uname
  431. # Should not get CYC packets
  432. cyc_cnt=$(perf script -i "${perfdatafile}" -D 2>/dev/null | grep -c "CYC 0x")
  433. if [ "${cyc_cnt}" -gt 0 ] ; then
  434. echo "Still get CYC packet without cyc"
  435. return 1
  436. fi
  437. echo OK
  438. return 0
  439. }
  440. test_sample()
  441. {
  442. echo "--- Test recording with sample mode ---"
  443. # Check if recording with sample mode is working
  444. if ! perf_record_no_decode -o "${perfdatafile}" --aux-sample=8192 -e '{intel_pt//u,branch-misses:u}' uname ; then
  445. echo "perf record failed with --aux-sample"
  446. return 1
  447. fi
  448. # Check with event with PMU name
  449. if perf_record_no_decode -o "${perfdatafile}" -e br_misp_retired.all_branches:u uname ; then
  450. if ! perf_record_no_decode -o "${perfdatafile}" -e '{intel_pt//,br_misp_retired.all_branches/aux-sample-size=8192/}:u' uname ; then
  451. echo "perf record failed with --aux-sample-size"
  452. return 1
  453. fi
  454. fi
  455. echo OK
  456. return 0
  457. }
  458. test_kernel_trace()
  459. {
  460. echo "--- Test with kernel trace ---"
  461. # Check if recording with kernel trace is working
  462. can_kernel || return 2
  463. if ! perf_record_no_decode -o "${perfdatafile}" -e intel_pt//k -m1,128 uname ; then
  464. echo "perf record failed with intel_pt//k"
  465. return 1
  466. fi
  467. echo OK
  468. return 0
  469. }
  470. test_virtual_lbr()
  471. {
  472. echo "--- Test virtual LBR ---"
  473. # Check if python script is supported
  474. libpython=$(perf version --build-options | grep python | grep -cv OFF)
  475. if [ "${libpython}" != "1" ] ; then
  476. echo "SKIP: python scripting is not supported"
  477. return 2
  478. fi
  479. # Python script to determine the maximum size of branch stacks
  480. cat << "_end_of_file_" > "${maxbrstack}"
  481. from __future__ import print_function
  482. bmax = 0
  483. def process_event(param_dict):
  484. if "brstack" in param_dict:
  485. brstack = param_dict["brstack"]
  486. n = len(brstack)
  487. global bmax
  488. if n > bmax:
  489. bmax = n
  490. def trace_end():
  491. print("max brstack", bmax)
  492. _end_of_file_
  493. # Check if virtual lbr is working
  494. perf_record_no_bpf -o "${perfdatafile}" --aux-sample -e '{intel_pt//,cycles}:u' uname
  495. times_val=$(perf script -i "${perfdatafile}" --itrace=L -s "${maxbrstack}" 2>/dev/null | grep "max brstack " | cut -d " " -f 3)
  496. case "${times_val}" in
  497. [0-9]*) ;;
  498. *) times_val=0;;
  499. esac
  500. if [ "${times_val}" -lt 2 ] ; then
  501. echo "Failed with virtual lbr"
  502. return 1
  503. fi
  504. echo OK
  505. return 0
  506. }
  507. test_power_event()
  508. {
  509. echo "--- Test power events ---"
  510. # Check if power events are supported
  511. power_event=$(cat /sys/bus/event_source/devices/intel_pt/caps/power_event_trace)
  512. if [ "${power_event}" != "1" ] ; then
  513. echo "SKIP: power_event_trace is not supported"
  514. return 2
  515. fi
  516. if ! perf_record_no_decode -o "${perfdatafile}" -a -e intel_pt/pwr_evt/u uname ; then
  517. echo "perf record failed with pwr_evt"
  518. return 1
  519. fi
  520. echo OK
  521. return 0
  522. }
  523. test_no_tnt()
  524. {
  525. echo "--- Test with TNT packets disabled ---"
  526. # Check if TNT disable is supported
  527. notnt=$(cat /sys/bus/event_source/devices/intel_pt/caps/tnt_disable)
  528. if [ "${notnt}" != "1" ] ; then
  529. echo "SKIP: tnt_disable is not supported"
  530. return 2
  531. fi
  532. perf_record_no_decode -o "${perfdatafile}" -e intel_pt/notnt/u uname
  533. # Should be no TNT packets
  534. tnt_cnt=$(perf script -i "${perfdatafile}" -D | grep -c TNT)
  535. if [ "${tnt_cnt}" -ne 0 ] ; then
  536. echo "TNT packets still there after notnt"
  537. return 1
  538. fi
  539. echo OK
  540. return 0
  541. }
  542. test_event_trace()
  543. {
  544. echo "--- Test with event_trace ---"
  545. # Check if event_trace is supported
  546. event_trace=$(cat /sys/bus/event_source/devices/intel_pt/caps/event_trace)
  547. if [ "${event_trace}" != 1 ] ; then
  548. echo "SKIP: event_trace is not supported"
  549. return 2
  550. fi
  551. if ! perf_record_no_decode -o "${perfdatafile}" -e intel_pt/event/u uname ; then
  552. echo "perf record failed with event trace"
  553. return 1
  554. fi
  555. echo OK
  556. return 0
  557. }
  558. test_pipe()
  559. {
  560. echo "--- Test with pipe mode ---"
  561. # Check if it works with pipe
  562. if ! perf_record_no_bpf -o- -e intel_pt//u uname | perf report -q -i- --itrace=i10000 ; then
  563. echo "perf record + report failed with pipe mode"
  564. return 1
  565. fi
  566. if ! perf_record_no_bpf -o- -e intel_pt//u uname | perf inject -b > /dev/null ; then
  567. echo "perf record + inject failed with pipe mode"
  568. return 1
  569. fi
  570. echo OK
  571. return 0
  572. }
  573. test_pause_resume()
  574. {
  575. echo "--- Test with pause / resume ---"
  576. if ! perf_record_no_decode -o "${perfdatafile}" -e intel_pt/aux-action=start-paused/u uname ; then
  577. echo "SKIP: pause / resume is not supported"
  578. return 2
  579. fi
  580. if ! perf_record_no_bpf -o "${perfdatafile}" \
  581. -e intel_pt/aux-action=start-paused/u \
  582. -e instructions/period=50000,aux-action=resume,name=Resume/u \
  583. -e instructions/period=100000,aux-action=pause,name=Pause/u uname ; then
  584. echo "perf record with pause / resume failed"
  585. return 1
  586. fi
  587. if ! perf script -i "${perfdatafile}" --itrace=b -Fperiod,event | \
  588. awk 'BEGIN {paused=1;branches=0}
  589. /Resume/ {paused=0}
  590. /branches/ {if (paused) exit 1;branches=1}
  591. /Pause/ {paused=1}
  592. END {if (!branches) exit 1}' ; then
  593. echo "perf record with pause / resume failed"
  594. return 1
  595. fi
  596. echo OK
  597. return 0
  598. }
  599. count_result()
  600. {
  601. if [ "$1" -eq 2 ] ; then
  602. skip_cnt=$((skip_cnt + 1))
  603. return
  604. fi
  605. if [ "$1" -eq 0 ] ; then
  606. ok_cnt=$((ok_cnt + 1))
  607. return
  608. fi
  609. err_cnt=$((err_cnt + 1))
  610. }
  611. ret=0
  612. test_system_wide_side_band || ret=$? ; count_result $ret ; ret=0
  613. test_per_thread "" "" || ret=$? ; count_result $ret ; ret=0
  614. test_per_thread "k" "(incl. kernel) " || ret=$? ; count_result $ret ; ret=0
  615. test_jitdump || ret=$? ; count_result $ret ; ret=0
  616. test_packet_filter || ret=$? ; count_result $ret ; ret=0
  617. test_disable_branch || ret=$? ; count_result $ret ; ret=0
  618. test_time_cyc || ret=$? ; count_result $ret ; ret=0
  619. test_sample || ret=$? ; count_result $ret ; ret=0
  620. test_kernel_trace || ret=$? ; count_result $ret ; ret=0
  621. test_virtual_lbr || ret=$? ; count_result $ret ; ret=0
  622. test_power_event || ret=$? ; count_result $ret ; ret=0
  623. test_no_tnt || ret=$? ; count_result $ret ; ret=0
  624. test_event_trace || ret=$? ; count_result $ret ; ret=0
  625. test_pipe || ret=$? ; count_result $ret ; ret=0
  626. test_pause_resume || ret=$? ; count_result $ret ; ret=0
  627. cleanup
  628. echo "--- Done ---"
  629. if [ ${err_cnt} -gt 0 ] ; then
  630. exit 1
  631. fi
  632. if [ ${ok_cnt} -gt 0 ] ; then
  633. exit 0
  634. fi
  635. exit 2