From d961a3031865be3daabcb13e639c51303b04202c Mon Sep 17 00:00:00 2001 From: Li Linhang Date: Tue, 15 Apr 2025 14:31:14 +0800 Subject: [PATCH] anolis: perf stat: fix on "enable ignore_missing_thread" ANBZ: #19874 This patch fixes ignore_missing_thread in perf stat, which enabled by commit 448ce0e6ea93ae99e0b36055e5f5a3f723fe3665, when working on multiple-event monitoring case. The commit 448ce0e enables ignore_missing_thread on perf stat, but only enables it on the first evsel in evlist. It works only when thread dies before the first event is opened. When a thread dies when opening the following events while monitoring more than one events, perf still returns a sys_perf_event_open failure with 3(No such process). This patch makes it work on all events, by enable ignore_missing_thread on all evsels, and fix fd using when fd is removed by ignore_missing_thread. Signed-off-by: Li Linhang --- tools/perf/builtin-stat.c | 5 ++++- tools/perf/util/evsel.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 77e327d4a9a7..8c18cb5c8832 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2486,6 +2486,7 @@ int cmd_stat(int argc, const char **argv) unsigned int interval, timeout; const char * const stat_subcommands[] = { "record", "report" }; char errbuf[BUFSIZ]; + struct evsel *evsel; setlocale(LC_ALL, ""); @@ -2832,7 +2833,9 @@ int cmd_stat(int argc, const char **argv) goto out; /* Enable ignoring missing threads when -p option is defined. */ - evlist__first(evsel_list)->ignore_missing_thread = target.pid; + evlist__for_each_entry(evsel_list, evsel) { + evsel->ignore_missing_thread = target.pid; + } status = 0; for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) { if (stat_config.run_count != 1 && verbose > 0) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index bc144388f892..dd0903c4a44a 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1944,9 +1944,11 @@ static int get_group_fd(struct evsel *evsel, int cpu_map_idx, int thread) static void evsel__remove_fd(struct evsel *pos, int nr_cpus, int nr_threads, int thread_idx) { - for (int cpu = 0; cpu < nr_cpus; cpu++) + for (int cpu = 0; cpu < nr_cpus; cpu++) { for (int thread = thread_idx; thread < nr_threads - 1; thread++) FD(pos, cpu, thread) = FD(pos, cpu, thread + 1); + FD(pos, cpu, nr_threads - 1) = -1; + } } static int update_fds(struct evsel *evsel, @@ -3815,6 +3817,8 @@ static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist) for (thread = 0; thread < xyarray__max_y(evsel->core.fd); thread++) { int fd = FD(evsel, cpu_map_idx, thread); + if (fd < 0) + continue; if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, cpu_map_idx, thread, fd) < 0) -- Gitee