linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tomáš Trnka" <trnka@scm.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: perf top -p broken for multithreaded processes since 5.19
Date: Fri, 02 Sep 2022 16:46:45 +0200	[thread overview]
Message-ID: <10137382.nUPlyArG6x@mintaka.ncbr.muni.cz> (raw)

Hello,

A bug in perf v5.19 and newer completely breaks monitoring multithreaded
processes using "perf top -p". The tool fails to start with "Failed to mmap
with 22 (Invalid argument)". It still seems to work fine on single-threaded
processes. "perf record" is also unaffected.

I have bisected the issue to the following commit:

commit ae4f8ae16a07896403c90305d4b9be27f657c1fc
Author: Adrian Hunter <adrian.hunter@intel.com>
Date:   Tue May 24 10:54:31 2022 +0300

    libperf evlist: Allow mixing per-thread and per-cpu mmaps
    
    mmap_per_evsel() will skip events that do not match the CPU, so all CPUs
    can be iterated in any case.

The issue can be easily reproduced using the following test:

$ python - <<EOF
import time
import threading
th = threading.Thread(target=time.sleep, args=(3600,))
th.start()
th.join()
EOF

stracing "perf top -p $(pgrep python)" yields this:

145184 perf_event_open({type=PERF_TYPE_HARDWARE, size=PERF_ATTR_SIZE_VER7, config=PERF_COUNT_HW_CPU_CYCLES, sample_freq=4000, sample_type=PERF_SAMPLE_IP|PERF_SAMPLE_TID|PERF_SAMPLE_TIME|PERF_SAMPLE_PERIOD, read_format=PERF_FORMAT_ID, disabled=1, exclude_kernel=1, mmap=1, comm=1, freq=1, task=1, precise_ip=0 /* arbitrary skid */, sample_id_all=1, mmap2=1, comm_exec=1, ksymbol=1, ...}, 92061, -1, -1, PERF_FLAG_FD_CLOEXEC) = 3
 > tools/perf/perf(evsel__open_cpu+0x287) [0x4c8ad7]
 > tools/perf/perf(cmd_top+0x1996) [0x439b26]
 > tools/perf/perf(run_builtin+0x68) [0x4a91f8]
 > tools/perf/perf(main+0x645) [0x40cad5]
145184 perf_event_open({type=PERF_TYPE_HARDWARE, size=PERF_ATTR_SIZE_VER7, config=PERF_COUNT_HW_CPU_CYCLES, sample_freq=4000, sample_type=PERF_SAMPLE_IP|PERF_SAMPLE_TID|PERF_SAMPLE_TIME|PERF_SAMPLE_PERIOD, read_format=PERF_FORMAT_ID, disabled=1, exclude_kernel=1, mmap=1, comm=1, freq=1, task=1, precise_ip=0 /* arbitrary skid */, sample_id_all=1, mmap2=1, comm_exec=1, ksymbol=1, ...}, 104619, -1, -1, PERF_FLAG_FD_CLOEXEC) = 5
 > tools/perf/perf(evsel__open_cpu+0x287) [0x4c8ad7]
 > tools/perf/perf(cmd_top+0x1996) [0x439b26]
 > tools/perf/perf(run_builtin+0x68) [0x4a91f8]
 > tools/perf/perf(main+0x645) [0x40cad5]
…(snip)…
145184 ioctl(5, PERF_EVENT_IOC_SET_OUTPUT, 3) = -1 EINVAL (Invalid argument)
 > tools/perf/perf(perf_evlist__mmap_ops+0x2cf) [0x5d497f]
 > tools/perf/perf(evlist__mmap+0xa7) [0x4c09b7]
 > perf/perf(cmd_top+0x1ccd) [0x439e5d]
 > tools/perf/perf(run_builtin+0x68) [0x4a91f8]
 > tools/perf/perf(main+0x645) [0x40cad5]

Best regards,

Tomáš
--
Tomáš Trnka
Software for Chemistry & Materials B.V.




             reply	other threads:[~2022-09-02 15:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02 14:46 Tomáš Trnka [this message]
2022-09-02 14:50 ` perf top -p broken for multithreaded processes since 5.19 Adrian Hunter
2022-09-02 19:17   ` Arnaldo Carvalho de Melo
2022-09-03  7:14     ` Adrian Hunter
2022-09-03 14:08       ` Arnaldo Carvalho de Melo
2022-09-03 17:35         ` Adrian Hunter
     [not found]           ` <CA+JHD91ReRGYNiBuO=1CGNZy1egcMjDo+VFO=kmCFrqE0mnK7w@mail.gmail.com>
2022-09-05 11:46             ` Adrian Hunter
2022-09-05 10:42       ` Jiri Olsa
2022-09-04 10:15 ` perf top -p broken for multithreaded processes since 5.19 #forregzbot Thorsten Leemhuis
2022-09-19 15:18   ` Thorsten Leemhuis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10137382.nUPlyArG6x@mintaka.ncbr.muni.cz \
    --to=trnka@scm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).