From nobody Wed Oct 8 14:20:57 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA8B820A5EA for ; Fri, 27 Jun 2025 19:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052266; cv=none; b=GYIJHMQmX3q5qweCM+E/H/u1grOh2U6lxqlXF2VkERrt8mgHNCGqs6haXmxAwR2A3fp2i3twNzYHrc3m44JuOr1HHis7Q8vteCp/qGVb1/ei0oNoNgJstMxVvBQUbaTQ4NLos95VxhRFogN6H0RQkaIgh1AzRERzfvkLNm2JZKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052266; c=relaxed/simple; bh=5qnWJjXV1yscRGW3Z8MrgpRa/BOaZk2dYgJaEfH4ujE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lOJE719vKxVL58LSYGnaKCMhVSdusobKfNXOLXE6v1InzoGCQjTFTlAowkf6kaYUPUEbdZufpsKfpM8izCohrNHzqtgcIcXar279jA8Ubxbo/+3t4YOmUxU1CVbAEO9fxyFTGbrhHatcCBOoB4oAyY6LsUam8g5hcv1utq9QzJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2nW5UvM2; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2nW5UvM2" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-748b4d5c045so207591b3a.1 for ; Fri, 27 Jun 2025 12:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052264; x=1751657064; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7d6C2lXVAfC01Fe0gAHfj6nm96vm08japImtMus97hs=; b=2nW5UvM26o2eU7jRUFchcAuPKLYBU1ujpWcb1JbmtIkFkB9HQsCXWG0tyyiAB1mOOC oiRH8JQxQ4OPEmq1au9L9Avf4FJ6+TF5+iL2IB5uaJuZD7jUd8UdG8Q0lZ3pSfL1pXke S/O/WrabZvv26+abCiYPYHotAVslOgxdCnwXGWgJ6uVESIhAaBWVCOTh6lui6A1Jl3m4 hzqGnPygc8EmhGiFhee0Db5FCJViimbupNfjSVMCTKaGmj4NxaNyvqx+U94m4l71uYNt 0sWY8lFtTB1FIK0zTVAbfSQj6Mk/vKn4vI+DGppA2ZUTjxDbC6gdZcjsppS+5CFGkrre meZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052264; x=1751657064; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7d6C2lXVAfC01Fe0gAHfj6nm96vm08japImtMus97hs=; b=HwgX31KP7XGadxnoVG4g2yI/Iom27RUGHPTSHWWX4XFGB7BXMZ1YY5U/P7FKlDWT/b FYsAfVAF1MQR8rvujqARoNGox7ixE4EldQ2Gfl0c15ycqZYSXHZswzCRq9qnMRY1yxFK ooaIdsTg30SsukQWVQC0+TdFlZ7lcRP3l4fsYoDRGZz9LVlmjZC3VG3hEC+Z+IAGDPIw ZBkXdOm1rOcrkx7/0LNNjszl6j+jJdRpewzsFl/gQVZWya/qyd2kzCpIuJe98GqsI1gx FLT5AUSy+F+v2bfmXnWpG5Lvks9OBLyuugDqb3flsuzM+7WlGjyoQ7DSsaUm3cSHY2+9 XBGA== X-Forwarded-Encrypted: i=1; AJvYcCXsYttKbEWTwda+Ts+5KtFhaK2fjuj3PekOPTJ6OP4Nnr2hQyoAjRDdor8egAGT6zdOCrshC7A6t67nH5g=@vger.kernel.org X-Gm-Message-State: AOJu0Yxoa4WEf/mDa66YdAXGhBn5QxhZs4Cy6AWpgqHGlyivsaiG3XsO UQt6+Mdww7FxzX8rRoaxS+QWl9ihzxaLTuQ5C/luyjDsHDuUhcZJ4f0S+hUNtKHCfLNfiMj8Cd4 3KZr5liChvw== X-Google-Smtp-Source: AGHT+IGxVVW6Wl9FoYgf65siOYfc6Hro58qDPxO34loRXfOqL/G1tEZu0nJbZPfRW9z4f1g5SNKUncaydpeZ X-Received: from plez10.prod.google.com ([2002:a17:902:ccca:b0:234:aa6d:999d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3bac:b0:236:7165:6ecf with SMTP id d9443c01a7336-23ac465cb20mr71404775ad.38.1751052264186; Fri, 27 Jun 2025 12:24:24 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:06 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-2-irogers@google.com> Subject: [PATCH v1 01/12] perf parse-events: Warn if a cpu term is unsupported by a CPU From: Ian Rogers To: Thomas Falcon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor requested CPU warning out of evlist and into evsel. At the end of adding an event, perform the warning check. To avoid repeatedly testing if the cpu_list is empty, add a local variable. ``` $ perf stat -e cpu_atom/cycles,cpu=3D1/ -a true WARNING: A requested CPU in '1' is not supported by PMU 'cpu_atom' (CPUs 16= -27) for event 'cpu_atom/cycles/' Performance counter stats for 'system wide': cpu_atom/cycles/ 0.000781511 seconds time elapsed ``` Signed-off-by: Ian Rogers --- tools/perf/util/evlist.c | 15 +-------------- tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++ tools/perf/util/evsel.h | 2 ++ tools/perf/util/parse-events.c | 12 ++++++++---- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 5664ebf6bbc6..a3c4d8558d29 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2546,20 +2546,7 @@ void evlist__warn_user_requested_cpus(struct evlist = *evlist, const char *cpu_lis return; =20 evlist__for_each_entry(evlist, pos) { - struct perf_cpu_map *intersect, *to_test, *online =3D cpu_map__online(); - const struct perf_pmu *pmu =3D evsel__find_pmu(pos); - - to_test =3D pmu && pmu->is_core ? pmu->cpus : online; - intersect =3D perf_cpu_map__intersect(to_test, user_requested_cpus); - if (!perf_cpu_map__equal(intersect, user_requested_cpus)) { - char buf[128]; - - cpu_map__snprint(to_test, buf, sizeof(buf)); - pr_warning("WARNING: A requested CPU in '%s' is not supported by PMU '%= s' (CPUs %s) for event '%s'\n", - cpu_list, pmu ? pmu->name : "cpu", buf, evsel__name(pos)); - } - perf_cpu_map__put(intersect); - perf_cpu_map__put(online); + evsel__warn_user_requested_cpus(pos, user_requested_cpus); } perf_cpu_map__put(user_requested_cpus); } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d55482f094bf..0208d999da24 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -4071,3 +4071,27 @@ void evsel__uniquify_counter(struct evsel *counter) counter->uniquified_name =3D false; } } + +void evsel__warn_user_requested_cpus(struct evsel *evsel, struct perf_cpu_= map *user_requested_cpus) +{ + struct perf_cpu_map *intersect, *online =3D NULL; + const struct perf_pmu *pmu =3D evsel__find_pmu(evsel); + + if (pmu && pmu->is_core) { + intersect =3D perf_cpu_map__intersect(pmu->cpus, user_requested_cpus); + } else { + online =3D cpu_map__online(); + intersect =3D perf_cpu_map__intersect(online, user_requested_cpus); + } + if (!perf_cpu_map__equal(intersect, user_requested_cpus)) { + char buf1[128]; + char buf2[128]; + + cpu_map__snprint(user_requested_cpus, buf1, sizeof(buf1)); + cpu_map__snprint(online ?: pmu->cpus, buf2, sizeof(buf2)); + pr_warning("WARNING: A requested CPU in '%s' is not supported by PMU '%s= ' (CPUs %s) for event '%s'\n", + buf1, pmu ? pmu->name : "cpu", buf2, evsel__name(evsel)); + } + perf_cpu_map__put(intersect); + perf_cpu_map__put(online); +} diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 6dbc9690e0c9..8b5962a1e814 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -572,4 +572,6 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu, s= truct evsel *evsel, =20 bool evsel__is_offcpu_event(struct evsel *evsel); =20 +void evsel__warn_user_requested_cpus(struct evsel *evsel, struct perf_cpu_= map *user_requested_cpus); + #endif /* __PERF_EVSEL_H */ diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index d1965a7b97ed..7a32d5234a64 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -257,6 +257,7 @@ __add_event(struct list_head *list, int *idx, struct evsel *evsel; bool is_pmu_core; struct perf_cpu_map *cpus; + bool has_cpu_list =3D !perf_cpu_map__is_empty(cpu_list); =20 /* * Ensure the first_wildcard_match's PMU matches that of the new event @@ -281,7 +282,7 @@ __add_event(struct list_head *list, int *idx, =20 if (pmu) { is_pmu_core =3D pmu->is_core; - cpus =3D perf_cpu_map__get(perf_cpu_map__is_empty(cpu_list) ? pmu->cpus = : cpu_list); + cpus =3D perf_cpu_map__get(has_cpu_list ? cpu_list : pmu->cpus); perf_pmu__warn_invalid_formats(pmu); if (attr->type =3D=3D PERF_TYPE_RAW || attr->type >=3D PERF_TYPE_MAX) { perf_pmu__warn_invalid_config(pmu, attr->config, name, @@ -296,10 +297,10 @@ __add_event(struct list_head *list, int *idx, } else { is_pmu_core =3D (attr->type =3D=3D PERF_TYPE_HARDWARE || attr->type =3D=3D PERF_TYPE_HW_CACHE); - if (perf_cpu_map__is_empty(cpu_list)) - cpus =3D is_pmu_core ? perf_cpu_map__new_online_cpus() : NULL; - else + if (has_cpu_list) cpus =3D perf_cpu_map__get(cpu_list); + else + cpus =3D is_pmu_core ? cpu_map__online() : NULL; } if (init_attr) event_attr_init(attr); @@ -331,6 +332,9 @@ __add_event(struct list_head *list, int *idx, if (list) list_add_tail(&evsel->core.node, list); =20 + if (has_cpu_list) + evsel__warn_user_requested_cpus(evsel, cpu_list); + return evsel; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog