From nobody Mon Oct 6 15:15:53 2025 Received: from mail-oo1-f74.google.com (mail-oo1-f74.google.com [209.85.161.74]) (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 5F0081E0DD9 for ; Sat, 19 Jul 2025 03:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894334; cv=none; b=cGGLRqZz5+pSG1XXacYeQ+OGsCS/g+UJekIMUzn1hVtY+FsQlcOSKjIUYF5OFvb1YcyVZWEREtXBw88ltf1UBWwkV40DOlMQc09MLPNrVNzx3I8gWqROIT/j1rftfYx8CzNvsAXPc2iHUk5ElYNDbrT3LWE+/c3ElDZ/ElMcKwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894334; c=relaxed/simple; bh=IZ1dP4fsOOPT7GVDaxQeOs0A2G/SQ78gec0XJFeHBGU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=MEGIbOfuBs+yCUCZZr6+jk9jrVWrxZ4QwG6TYI/nsnuFz9V1InU09MAJ88FNBzxJ1vHTcwxnVofaWDPEb5Jmxmb0BdA1ndea6LVO6r6TQaLNy+SYYzGNhkpFuie/gtBI5Wr4rbcvnHOPTb9ZClx3lyloBBAgDoTryWLvrEJJfb8= 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=2EwRZuQe; arc=none smtp.client-ip=209.85.161.74 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="2EwRZuQe" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-615b53266bfso1369991eaf.0 for ; Fri, 18 Jul 2025 20:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894332; x=1753499132; 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=NJyT4HLCqXHRxMmnshYz2066eN/wkiwo71q1NVZg9fs=; b=2EwRZuQeHaiQ4RuK7PONQ8MK168fqqniDkdNsuTkU+QxBjKErd9Utb1A9R9KBpPhcS 3rvA4uAa3qt62X0UkrcqKu+CzqbUfkNS/H7DNTyZcc6qU/RIsJbrcYMbWf5BsEunPknP 0cP2ukJLktQQlizs7+l1LvvA6aaMiIH4dYBqTxOPobmxTYsQaeZtxwSQGrPhoJ5L9mhN Nd830HXeIPyYIGlL/58iVluG3O2ZBpULdRTq4wZdVOLtYuDvA/kvF4r97MZjyGB30ARb eyrgjNU8ncITkyPtL26Prws+R2B6I2HMtuHho41E0ZF21jNJpZfk41DC2Wll19v0GufG t0yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894332; x=1753499132; 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=NJyT4HLCqXHRxMmnshYz2066eN/wkiwo71q1NVZg9fs=; b=xJ/BcJG3VDX5xVYYR5ViCNN9+DFgmbgIny9gmg9HPUYRLU02+miCYBVWbfrJONCcy3 xeUkyG0OxgYH0P2gA0es3dDm/ZluSjofHlgylS1e5JJBFcfUmuZiry5sR60uOWAehFbr njbWiUJ5zQ/vcuzLXq0JFUcFq2L5d3C13g6gOXQq01Hk/O/9OhjKNmryo/0CveKK1qgF ZtJGmFxC9Bv5hh6YlTndZtK1BKOi+OFN9Lk7iPrhpSw2n2gS9O0d2swIJfw6qhz6mIU8 zuwx7ZOsCtsnBy6LfRDBLvbzG7iZs6LKiy2nOcmDM2D6ohrZtaCS0LYXXj/UPXn+h04o xYQg== X-Forwarded-Encrypted: i=1; AJvYcCWbdttWiPVVFukAA5RlAUOfUyFBOxJSTq6oKLkhwJDb15159hrjHM+rZC06uzEsm3JbH/uybqiFGSJfuSQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxs/K2+bd6WYyl9coCAu5EOxqSyYMNvpEFdexlUPSp2ZPAP+FIF Pvos1jcMsIGUHtqWRjXH/xcPwKnbCWeDRJAQupkDMbt09Rd4pz9o/Q7dVe9FQWrlzYOP/O2I07V +SVlJPdwIHg== X-Google-Smtp-Source: AGHT+IGvucAyfOt+rnCRQE+RnfkOqny0fkGZY23GJuXWeAKQUZUS6CyLJ7eDt3lkYe/k8/LtvWQNhcF+RN3h X-Received: from oabsa17.prod.google.com ([2002:a05:6871:2111:b0:2ef:e9aa:27e6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:f603:b0:2ff:94d7:b006 with SMTP id 586e51a60fabf-2ffb2251036mr9833040fac.13.1752894332424; Fri, 18 Jul 2025 20:05:32 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:03 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-2-irogers@google.com> Subject: [PATCH v3 01/15] 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@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 ``` Reviewed-by: Thomas Falcon 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 995ad5f654d0..80d8387e6b97 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2549,20 +2549,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 3896a04d90af..d9b6bf78d67b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -4091,3 +4091,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 b84ee274602d..cefa8e64c0d5 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -574,4 +574,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 a59ae5ca0f89..3fd6cc0c2794 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -252,6 +252,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 @@ -276,7 +277,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, @@ -291,10 +292,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); @@ -326,6 +327,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 From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 F41CA1FF7D7 for ; Sat, 19 Jul 2025 03:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894336; cv=none; b=ql8oMuy48GNzD23GINhcRz5dcDtdt42/bv1YP2cjrSmNtDwEbfCDGyySLu5/JckQ9UwHQO+sIGnF+IGzA+whOuqB/bo4hbdroNbRCifJS71QJjIm3VzhNOyiBQ8VfUK5QcFRsj/K5fPVju9dPk6sAVPBrIAyV9U4n9YYSBj/m8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894336; c=relaxed/simple; bh=zejmlYNwgS/OQpMHacoEnWFRqhftHB8onU2Qvy6vpsU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cKE/MWiLgRw+q1BsmwFE1D+2X2dP+fc9oE39RcFdyrllq3gavGtKKbBFktdzLLoquNpR1Rg4bShQCK2qLhnoDUSWBVEh6EcySNWTUfB41NTsBCqUPdFfmRt0Ta5XE+HfzTl/H7E5T4Kj8Y1c96Jdw85gUFZCLwM+Fpc6cxAGP5w= 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=EDgFirkO; arc=none smtp.client-ip=209.85.216.74 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="EDgFirkO" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31202bbaafaso2493209a91.1 for ; Fri, 18 Jul 2025 20:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894334; x=1753499134; 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=5dVZGHVi7sQRXRzVKkfTNIiUhn/WdB0GHZb62bnQe1c=; b=EDgFirkOGS85qRaiOI/zxkysJ6T1p81hM77lHF0hZuID2SuhzYP/LjkEpcEm8/8Hj5 CTRxaWX6tsnwWTdUf/C1pygvyIniu+TISXGiv99ScBKMQZQlpcnzBxeA0/cwxftUyrPQ 9hAvrpwrtnR3w6McgA5c36kDgSVDfuZOK4Ai1E+i3bXBOs+ThYr/q3LosEGdBnZbkmI6 0/4Dink9VhCPL61DT1TLI4RNX1TihzGfczoRBkQm7xId+NUPfsx9C9Rky+3YdO4iU4qZ O5ibyJ7l9TgxyjEEfk33Qn7TeF2k+Ndk5IOq3z2qoEtIaU9oVQbT5XK7MkprFGnV6Qye VqaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894334; x=1753499134; 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=5dVZGHVi7sQRXRzVKkfTNIiUhn/WdB0GHZb62bnQe1c=; b=WxmGHsFPMsrGfZ0jCnvwNXfoLVV4l8j4G35Rr4kYHb/HYXA6GbeSjDdYETcqABJXAD Bhhk3764GO32ujES3xkoxQSzuBpr42HzQO4cPTW538PeswSvWGLy/3dfHkN2f5uk0s41 SbO8m9LGAAGJtd3kmxVyghHgKEu4QMiyZq1MPNT28kyYiR05lwY/LNWIF8KqyBUiczbb JeHl78EeG5K7KDaiqSFiX6HD5noWGY0QFgKTJbJa93jFL8s0dJoL3TRY0CqMd+guAew/ YZ6+tjnp9/wAUu3JcZtTILcWUnxMfKg0AYpHL3Ub5CgfCqc3b2OewxTe8EvXT5lZTlaL zn6w== X-Forwarded-Encrypted: i=1; AJvYcCXc/huVdGKIXQ/To0sh5+S3Uvzyi3P4ptVk5Cfj8VyZed4lKDbzi4xtj95e9+41iiGG7OR/I5hnynGErcg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz72OZqRm5FyCbhVmN0amJ+Env3++haIQo6JCzdOM4WGANSCF19 RGUaR+KLL5BdOAqQvvEpFOwHZ51stE977IaXalofvmdrLWBX/DVpEZ5VyvQw+I54lrdNvIVVFhL i692P2GI+Qg== X-Google-Smtp-Source: AGHT+IGJY7ZCHAzxXWQwWCYTpvlQGS/fifvam3lq/ygXLcAuJEVe1IKP9gewERPFn8QEFZafxVK2+h8CDi4d X-Received: from pjbsu3.prod.google.com ([2002:a17:90b:5343:b0:312:1eb3:78c9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:55c4:b0:311:9c9a:58c5 with SMTP id 98e67ed59e1d1-31c9f44b9c3mr18437977a91.12.1752894334313; Fri, 18 Jul 2025 20:05:34 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:04 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-3-irogers@google.com> Subject: [PATCH v3 02/15] perf stat: Avoid buffer overflow to the aggregation map 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CPUs may be created and passed to perf_stat__get_aggr (via config->aggr_get_id), such as in the stat display should_skip_zero_counter. There may be no such aggr_id, for example, if running with a thread. Add a missing bound check and just create IDs for these cases. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 77e2248fa7fc..73b4521ab8af 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1365,7 +1365,7 @@ static struct aggr_cpu_id perf_stat__get_aggr(struct = perf_stat_config *config, struct aggr_cpu_id id; =20 /* per-process mode - should use global aggr mode */ - if (cpu.cpu =3D=3D -1) + if (cpu.cpu =3D=3D -1 || cpu.cpu >=3D config->cpus_aggr_map->nr) return get_id(config, cpu); =20 if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (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 3244B2185B1 for ; Sat, 19 Jul 2025 03:05:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894338; cv=none; b=Jl43OSYcZQ3hyL2iAExGe/0AKIJTZX0sU3gmbcT5sDFsjB6pjWGDm2Z3qVdPLQmhl77ppszK7UovH3GOysolfk6Iyj23ZOr6sQ8lm9VEn6MrZXj9vXfa0XPCAOzK32lg8yYOHU0ZbXVyECFEXnUyJlTjEvYKj1ITp5o0IxNmiaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894338; c=relaxed/simple; bh=rxECd/orHJ+FjXD+vxZ9UCxbrPbeZ0Ymr36fQ+vUgvE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=OPaQFtjIWZOUhPTAovegRoy9y+7nmblUievO3cdrSDTBU+oX6Cg7ef/VgrvsMcWo2bntuywKP1vs4YU38DuTJMxWiiUoX+IhQ5CHiN4fQseKyLPbgee+kbvnooJCE7bGfc51AMqEAXzaKYHvy+LWjM9vV+llgy0SOL3jinoAEa8= 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=bULmIHrv; arc=none smtp.client-ip=209.85.160.73 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="bULmIHrv" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2e8e969090aso2688114fac.0 for ; Fri, 18 Jul 2025 20:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894336; x=1753499136; 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=8LzGDRK9pbbZy05/7NVo0qy9CZXcleNoSvz0ippsT70=; b=bULmIHrvuv281+jkDXslrXQLBccxdm9zmDt/3ZkoKnRwEHpz3LhXW+nafuCJ7doU+A Td+EdCisuVrOjkPHFejizvUqk1uf1dWF38F/tg440xzBhvEFgx70R/55ZxYAi/jyZqTA 24tqF0bFX1Y4Rs8cbNSV2zQ7D/z7xNHubr+KTpRvJ1xoY+zarz8zp5kX2pZMkZypR1dV zn218QQ8JolXSVljr5cWXLmox0qFPaGt3ot3EPmCoZChLV9/skD04l7QrUifddM5RpTr 3EHt+3XxwvGUozegZilI4TZOEzYlpU22T2t9jwyGnPnnbJcIYyp9g1Exo+X9nS+NF2ti /n0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894336; x=1753499136; 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=8LzGDRK9pbbZy05/7NVo0qy9CZXcleNoSvz0ippsT70=; b=IdA1PcIvO4XGwoGpG3pVA2TVCG1oO3w0jZN7htbPs/3HRO2TIvCrYocDcAmeHFGsML eR0dmDhRcGrR9LmtBIlAqvA3ztmpuJtgYHMZcO6nEIvwhHHEJDTNir2ubqhP0+n5D4Z7 ZmMF7TpO7Ox8/SyhvZbHB51cs0KqPF8dkejYokBIUC9qYe4aYYjYVFWQLyUXss0c/SUS +j6wh4rvuaqsgoRaIYeMROg7nitLmzTM4poQENrrW8H07t23nMrw6oZxgobdXgU5MdF4 L+d2Z9ohJM2cueEwn5O1QDvKQsm0MjXhwn+o8sCebL41NVf94LE5NwKY1NSP5KeTTv+B 12Tg== X-Forwarded-Encrypted: i=1; AJvYcCWU3tu/F6B7yOf5MfFFZgTfnlHKx5Ma0rC9Uxyg9WsnSPkCNwwxveT8vIoSQjqEWDb75ROlMwsds9QxaE8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyf+Vu4rimMGZJuSxpa9oSzEU4Xrp2lDouHvZSiBUOqYWypwvJu 7AkoR1bAzUgAa3ntTJbcZFUL8Iv2HNbiflYc8QuLPOZZnjxRW2Q5WMljLXRZY63SiEWfZi9uTiV 1xvss4AXCbQ== X-Google-Smtp-Source: AGHT+IFeWvY21rnTa5jdEzRoKSaAvbnA4CvHa+J+RiVrn4VIO2NTPCK3Ajtkev5HdcX/TArTEOy39Ncf8kGY X-Received: from oabdy51.prod.google.com ([2002:a05:6870:c7b3:b0:2ff:f5e9:3348]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:171a:b0:2c1:e9a3:3ab3 with SMTP id 586e51a60fabf-2ffd2aa86e6mr7068513fac.33.1752894336264; Fri, 18 Jul 2025 20:05:36 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:05 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-4-irogers@google.com> Subject: [PATCH v3 03/15] perf stat: Don't size aggregation ids from user_requested_cpus 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As evsels may have additional CPU terms, the user_requested_cpus may not reflect all the CPUs requested. Use evlist->all_cpus to size the array as that reflects all the CPUs potentially needed by the evlist. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 73b4521ab8af..00fce828cd5e 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1513,11 +1513,8 @@ static int perf_stat_init_aggr_mode(void) * taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - if (!perf_cpu_map__is_any_cpu_or_is_empty(evsel_list->core.user_requested= _cpus)) - nr =3D perf_cpu_map__max(evsel_list->core.user_requested_cpus).cpu; - else - nr =3D 0; - stat_config.cpus_aggr_map =3D cpu_aggr_map__empty_new(nr + 1); + nr =3D perf_cpu_map__max(evsel_list->core.all_cpus).cpu + 1; + stat_config.cpus_aggr_map =3D cpu_aggr_map__empty_new(nr); return stat_config.cpus_aggr_map ? 0 : -ENOMEM; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (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 F288621CA13 for ; Sat, 19 Jul 2025 03:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894340; cv=none; b=Yok/W7fu1gxfNkaDbI2nJHP7Lx3PbBs3SxWzG5kezVXuq6BjXlGkHgyP/nHwwy6yy1XR0ffQf+fXeEjQeD2wT9QJwk5VqZcUNRYdzcgahTgwdu8bEpTHrrX/SN/ALatYVllB+/F/Jh6RWApZwhsvGR63t6FonLwnAmlH247MEps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894340; c=relaxed/simple; bh=3iqPS74Vm3U8TVu2LqxzGlONC7F3fEEx0C3HxO9oOX8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kQX/LxOOyzu6qxQR8uehC6ux+CySsBuahIWTFm5ct+boPNs0fiRSt0y1Ppn5CCaDaLSAskRHAeP1jgXCo33xk0IIWqACqMi7tvbISN5gmPId7Bg+8iB98AlDPyV7SkOFi1Kz0y8djsrFp4oF4IG5/gYbRHl23sa41OKBMvdOUPY= 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=06DuwR5X; arc=none smtp.client-ip=209.85.160.74 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="06DuwR5X" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-301ede1998aso851478fac.3 for ; Fri, 18 Jul 2025 20:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894338; x=1753499138; 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=TDJzHa5Jjh3EgodtOKHDgfY+ccZxVF0sXpFhOe3DuRk=; b=06DuwR5XH1SBSbVSYiDmmqGlh1MJODmI/qpFmHuYV68fisCSLyCLHgwQ4g5w3dTxZ6 cBoBvTY7S+EhEcpwS2/memz69kCMNiaHfj4giRVRMt6GAl06EX+gZxnfeSPFUILNWfBw 2HXZV4lbRb/PhiKVsq+/TbNq7kGbFMqR+orxlGw6M/Ng9EZIniGfWbfE8K+gzJTOF3R0 Urt8fEYe+Zb3u9KHEaDQmSikcVUMxAFJOCBT9BKXQEejAjyMudyVXnpS+2kmY2KfsDFh JgLvsGIYfZZJNLoEZz4vgBmN894wRvyCN5xSSdgrePyOUUWcUiMOoqpPnvBch5eHqpkI 1QbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894338; x=1753499138; 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=TDJzHa5Jjh3EgodtOKHDgfY+ccZxVF0sXpFhOe3DuRk=; b=vnGDWl8tPLwyhwcwdNArMQIXQ79fkrXujTqIeqjIKzdqrviw1d7YBBajkmKNLsLyHm hemmYOQxX952scU4bhe1tSmElVQgVEudnqVHb8Ulbxmx26LcEROTeV40kvw3icpTZQRj puO9sDkd2B/Kkq1fB72yPSLU7CGgTaejnZVIkrgu1iaE/ND/kqxx60jBfiPys4oPPd3O ZjbwYtqGBzSs62sgrZXQS1yIh/8/8TJdnMnjxAxxNUVjfjZGn7aHR7xzStzpHKqCrEIk 6rGAeIMvlT5TI4SV1ZG47g2YU2lJNkd9YG6f8SCGn6M9G4SiFiCb/x5qs4K1aGQ3jp66 cffw== X-Forwarded-Encrypted: i=1; AJvYcCUt3om1xvSft5mIf8muZJuu9b1PVes4X35i/AIRt6BdMhR3pTyyQYWHctqUKhcIRKjCW/jqXh9zMqygI4c=@vger.kernel.org X-Gm-Message-State: AOJu0YzKWT81R8vTWEAPeORQ2SqY0O7f1G9oEQTSmJLAkkCz9cOZIBxn TGooCeO7jZbhcRjW9TrFffgc3JvJoGWPPnUCY/KNRzNpoo0tM6YXgYoLGGk8+wZQkxZ2dNTdfVb hVczEGrlo8A== X-Google-Smtp-Source: AGHT+IHtAUqaMjqyTAyw5V9bMWgfhc/EuGmlDpdtDKfXE6b2gJq6gjfWRWQouDvDJvNd/3krYdZnxhu9NN3z X-Received: from oabsa2.prod.google.com ([2002:a05:6871:2102:b0:2bc:65b9:2ace]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:7244:b0:2ff:9224:b1c8 with SMTP id 586e51a60fabf-2ffaf5a4bc4mr10499853fac.36.1752894338080; Fri, 18 Jul 2025 20:05:38 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:06 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-5-irogers@google.com> Subject: [PATCH v3 04/15] perf parse-events: Allow the cpu term to be a PMU or CPU range 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On hybrid systems, events like msr/tsc/ will aggregate counts across all CPUs. Often metrics only want a value like msr/tsc/ for the cores on which the metric is being computed. Listing each CPU with terms cpu=3D0,cpu=3D1.. is laborious and would need to be encoded for all variations of a CPU model. Allow the cpumask from a PMU to be an argument to the cpu term. For example in the following the cpumask of the cstate_pkg PMU selects the CPUs to count msr/tsc/ counter upon: ``` $ cat /sys/bus/event_source/devices/cstate_pkg/cpumask 0 $ perf stat -A -e 'msr/tsc,cpu=3Dcstate_pkg/' -a sleep 0.1 Performance counter stats for 'system wide': CPU0 252,621,253 msr/tsc,cpu=3Dcstate_pkg/ 0.101184092 seconds time elapsed ``` As the cpu term is now also allowed to be a string, allow it to encode a range of CPUs (a list can't be supported as ',' is already a special token). The "event qualifiers" section of the `perf list` man page is updated to detail the additional behavior. The man page formatting is tidied up in this section, as it was incorrectly appearing within the "parameterized events" section. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-list.txt | 25 +++++++++----- tools/perf/util/parse-events.c | 47 +++++++++++++++++++++----- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentat= ion/perf-list.txt index ce0735021473..28215306a78a 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -278,26 +278,33 @@ also be supplied. For example: =20 perf stat -C 0 -e 'hv_gpci/dtbp_ptitc,phys_processor_idx=3D0x2/' ... =20 -EVENT QUALIFIERS: +EVENT QUALIFIERS +---------------- =20 It is also possible to add extra qualifiers to an event: =20 percore: =20 -Sums up the event counts for all hardware threads in a core, e.g.: - - - perf stat -e cpu/event=3D0,umask=3D0x3,percore=3D1/ + Sums up the event counts for all hardware threads in a core, e.g.: + perf stat -e cpu/event=3D0,umask=3D0x3,percore=3D1/ =20 cpu: =20 -Specifies the CPU to open the event upon. The value may be repeated to -specify opening the event on multiple CPUs: + Specifies a CPU or a range of CPUs to open the event upon. It may + also reference a PMU to copy the CPU mask from. The value may be + repeated to specify opening the event on multiple CPUs. =20 + Example 1: to open the instructions event on CPUs 0 and 2, the + cycles event on CPUs 1 and 2: + perf stat -e instructions/cpu=3D0,cpu=3D2/,cycles/cpu=3D1-2/ -a sleep 1 =20 - perf stat -e instructions/cpu=3D0,cpu=3D2/,cycles/cpu=3D1,cpu=3D2/ -a sl= eep 1 - perf stat -e data_read/cpu=3D0/,data_write/cpu=3D1/ -a sleep 1 + Example 2: to open the data_read uncore event on CPU 0 and the + data_write uncore event on CPU 1: + perf stat -e data_read/cpu=3D0/,data_write/cpu=3D1/ -a sleep 1 =20 + Example 3: to open the software msr/tsc/ event only on the CPUs + matching those from the cpu_core PMU: + perf stat -e msr/tsc,cpu=3Dcpu_core/ -a sleep 1 =20 EVENT GROUPS ------------ diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3fd6cc0c2794..a337e4d22ff2 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -187,10 +187,22 @@ static struct perf_cpu_map *get_config_cpu(const stru= ct parse_events_terms *head =20 list_for_each_entry(term, &head_terms->terms, list) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_CPU) { - struct perf_cpu_map *cpu =3D perf_cpu_map__new_int(term->val.num); - - perf_cpu_map__merge(&cpus, cpu); - perf_cpu_map__put(cpu); + struct perf_cpu_map *term_cpus; + + if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM) { + term_cpus =3D perf_cpu_map__new_int(term->val.num); + } else { + struct perf_pmu *pmu =3D perf_pmus__find(term->val.str); + + if (pmu && perf_cpu_map__is_empty(pmu->cpus)) + term_cpus =3D pmu->is_core ? cpu_map__online() : NULL; + else if (pmu) + term_cpus =3D perf_cpu_map__get(pmu->cpus); + else + term_cpus =3D perf_cpu_map__new(term->val.str); + } + perf_cpu_map__merge(&cpus, term_cpus); + perf_cpu_map__put(term_cpus); } } =20 @@ -1048,15 +1060,32 @@ do { \ return -EINVAL; } break; - case PARSE_EVENTS__TERM_TYPE_CPU: - CHECK_TYPE_VAL(NUM); - if (term->val.num >=3D (u64)cpu__max_present_cpu().cpu) { + case PARSE_EVENTS__TERM_TYPE_CPU: { + struct perf_cpu_map *map; + + if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM) { + if (term->val.num >=3D (u64)cpu__max_present_cpu().cpu) { + parse_events_error__handle(err, term->err_val, + strdup("too big"), + /*help=3D*/NULL); + return -EINVAL; + } + break; + } + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR); + if (perf_pmus__find(term->val.str) !=3D NULL) + break; + + map =3D perf_cpu_map__new(term->val.str); + if (!map) { parse_events_error__handle(err, term->err_val, - strdup("too big"), - NULL); + strdup("not a valid PMU or CPU number"), + /*help=3D*/NULL); return -EINVAL; } + perf_cpu_map__put(map); break; + } case PARSE_EVENTS__TERM_TYPE_DRV_CFG: case PARSE_EVENTS__TERM_TYPE_USER: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (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 EFC8521D3E8 for ; Sat, 19 Jul 2025 03:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894343; cv=none; b=SjRlwHc9dcWbc1DYb1kUzQl0DV71E8DwdpT6/YSD87d2sX38GzIOTJeaf2MyEAhdx8QF4YOqI4AiBdvXoPS+yCYuT1ca94JFoRQNDfH0IkIf6t0LOtdXg4VPNKnA73+QtQZU7nF4ee/JxaPnYezv/IuG7cCva3BSg03P/1sNWTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894343; c=relaxed/simple; bh=LV19GYynUUF0CjbElgTqMTM8C4erDLHMoiN6xloIXdY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=d11JSTgRSnUrftxiDeeZVh9TrWAYrFdbQGXzCNYYhsm9nefqWh2n8TEc8sFACzZCt5B3wz4lwsTKaTbWuk40ir2Vl6/SgC3L1PG5lHgiVKokTK8J+abbXjBLx9u0wUkPpSTQVm0ohcj6DsXcSI27OzlggrHe6/1Cq07//Cpm5Y4= 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=y0Jh1Hpx; arc=none smtp.client-ip=209.85.160.73 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="y0Jh1Hpx" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2fff642182fso884462fac.0 for ; Fri, 18 Jul 2025 20:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894340; x=1753499140; 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=/sNed9QLILs+6YAkcENeXJYowIz3bMiJ6NyLJB9+4y0=; b=y0Jh1HpxhemVM2zhp9arx4TCzyJkdo1iD0IEWhHRwwTJaJWTo80N8GaBjSflpWZwHz fo+aQPWAGiLCBULcpRO9/LwDsE6z0K5i1CutNU9XeHV1rxIf++wRRGRZBRGKvcFYFlFO 7Xy+315CeciRzG4O3TcJOwQhDDIrIzSHLJ68SCgRDbKM4A2E4Uigw9Ze8UoyvTnd+YNa lo/nfEk2tb6xrV3NcPRAjtSYz84ljgLa2EKYnm4EF1e0kSRD4MTUyf8E739Qvdbvv2/Q dJx9pvis1Xxhwd95aq9W9lbjj+RIZlVo0+6nnIZCKwu0bfeZNTwqUMeaTYuSPqRJL/+m 0oJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894340; x=1753499140; 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=/sNed9QLILs+6YAkcENeXJYowIz3bMiJ6NyLJB9+4y0=; b=BaBIBMsOoL6u4RhDxlOyK6jfRPDgFMgUqi8j1M7HoxD7RuL6voE0C5mL+hXISBiqTM Kj3a2jKlkBxh6gGjeJmsb0ALVkvmhMgQCWGHQaegcJ2l5R1egZCco84tQUFfvZr9dUH+ 9iRLfoL5xxOvs5qBcPRfij/w1JLiBcClBfYHjvAWeNd4k/ylV8iwPvOZmQg7D3ZQhCUC 6WU523UyXBdiwlPYFYUgStX68g6dHUIi3/E60XSqDj56TkXJHFKIjzslGbIJDv2AMDwB ryjB9yjoLaOepnawlmtmzhCspAMpcCIdLxM6KwtF6Fh2teg7kA/SEi8HcTpxGsRXgGZP 7EIA== X-Forwarded-Encrypted: i=1; AJvYcCX3Gbz8oaqpHPiJiNcw0hWD4wFQZjAtUdmkqFQ9gMTLGVUsqiNU08iCrXv7orkT4yYhclUHXchymrFqb84=@vger.kernel.org X-Gm-Message-State: AOJu0YxjBzsNoHUqo/PUpCTFyXIxRomD0se1z3Roe8gwPiDytUrEYA/e QfYZVuBYkobx25rYIbPeAwQemtste0reWySLUsTW+wU0N22LymmgUiHeuaRlpIyDnPY2+VRjCcA BQTAbvBnSIQ== X-Google-Smtp-Source: AGHT+IElBNEhl4+hLU6pTgfpv+B/sViki2SWBWUEPxWbT4/x8P6vUwOlzLh2rEGGMDsfWXzficMMbkU1ULbD X-Received: from oabxm8.prod.google.com ([2002:a05:6870:9f88:b0:2b8:431f:3a1d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:f6a6:b0:2ff:9ff8:72c7 with SMTP id 586e51a60fabf-2ffb24a53e1mr10854216fac.27.1752894339961; Fri, 18 Jul 2025 20:05:39 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:07 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-6-irogers@google.com> Subject: [PATCH v3 05/15] perf tool_pmu: Allow num_cpus(_online) to be specific to a cpumask 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For hybrid metrics it is useful to know the number of p-core or e-core CPUs. If a cpumask is specified for the num_cpus or num_cpus_online tool events, compute the value relative to the given mask rather than for the full system. ``` $ sudo /tmp/perf/perf stat -e 'tool/num_cpus/,tool/num_cpus,cpu=3Dcpu_core/, tool/num_cpus,cpu=3Dcpu_atom/,tool/num_cpus_online/,tool/num_cpus_online, cpu=3Dcpu_core/,tool/num_cpus_online,cpu=3Dcpu_atom/' true Performance counter stats for 'true': 28 tool/num_cpus/ 16 tool/num_cpus,cpu=3Dcpu_core/ 12 tool/num_cpus,cpu=3Dcpu_atom/ 28 tool/num_cpus_online/ 16 tool/num_cpus_online,cpu=3Dcpu_core/ 12 tool/num_cpus_online,cpu=3Dcpu_atom/ 0.000767205 seconds time elapsed 0.000938000 seconds user 0.000000000 seconds sys ``` Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/util/expr.c | 2 +- tools/perf/util/tool_pmu.c | 56 +++++++++++++++++++++++++++++++++----- tools/perf/util/tool_pmu.h | 2 +- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index ca70a14c7cdf..7fda0ff89c16 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -401,7 +401,7 @@ double expr__get_literal(const char *literal, const str= uct expr_scanner_ctx *ctx if (ev !=3D TOOL_PMU__EVENT_NONE) { u64 count; =20 - if (tool_pmu__read_event(ev, &count)) + if (tool_pmu__read_event(ev, /*evsel=3D*/NULL, &count)) result =3D count; else pr_err("Failure to read '%s'", literal); diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 4630b8cc8e52..7aa4f315b0ac 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -332,7 +332,7 @@ static bool has_pmem(void) return has_pmem; } =20 -bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result) +bool tool_pmu__read_event(enum tool_pmu_event ev, struct evsel *evsel, u64= *result) { const struct cpu_topology *topology; =20 @@ -347,18 +347,60 @@ bool tool_pmu__read_event(enum tool_pmu_event ev, u64= *result) return true; =20 case TOOL_PMU__EVENT_NUM_CPUS: - *result =3D cpu__max_present_cpu().cpu; + if (!evsel || perf_cpu_map__is_empty(evsel->core.cpus)) { + /* No evsel to be specific to. */ + *result =3D cpu__max_present_cpu().cpu; + } else if (!perf_cpu_map__has_any_cpu(evsel->core.cpus)) { + /* Evsel just has specific CPUs. */ + *result =3D perf_cpu_map__nr(evsel->core.cpus); + } else { + /* + * "Any CPU" event that can be scheduled on any CPU in + * the PMU's cpumask. The PMU cpumask should be saved in + * own_cpus. If not present fall back to max. + */ + if (!perf_cpu_map__is_empty(evsel->core.own_cpus)) + *result =3D perf_cpu_map__nr(evsel->core.own_cpus); + else + *result =3D cpu__max_present_cpu().cpu; + } return true; =20 case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: { struct perf_cpu_map *online =3D cpu_map__online(); =20 - if (online) { + if (!online) + return false; + + if (!evsel || perf_cpu_map__is_empty(evsel->core.cpus)) { + /* No evsel to be specific to. */ *result =3D perf_cpu_map__nr(online); - perf_cpu_map__put(online); - return true; + } else if (!perf_cpu_map__has_any_cpu(evsel->core.cpus)) { + /* Evsel just has specific CPUs. */ + struct perf_cpu_map *tmp =3D + perf_cpu_map__intersect(online, evsel->core.cpus); + + *result =3D perf_cpu_map__nr(tmp); + perf_cpu_map__put(tmp); + } else { + /* + * "Any CPU" event that can be scheduled on any CPU in + * the PMU's cpumask. The PMU cpumask should be saved in + * own_cpus, if not present then just the online cpu + * mask. + */ + if (!perf_cpu_map__is_empty(evsel->core.own_cpus)) { + struct perf_cpu_map *tmp =3D + perf_cpu_map__intersect(online, evsel->core.own_cpus); + + *result =3D perf_cpu_map__nr(tmp); + perf_cpu_map__put(tmp); + } else { + *result =3D perf_cpu_map__nr(online); + } } - return false; + perf_cpu_map__put(online); + return true; } case TOOL_PMU__EVENT_NUM_DIES: topology =3D online_topology(); @@ -417,7 +459,7 @@ int evsel__tool_pmu_read(struct evsel *evsel, int cpu_m= ap_idx, int thread) old_count =3D perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); val =3D 0; if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) { - if (!tool_pmu__read_event(ev, &val)) { + if (!tool_pmu__read_event(ev, evsel, &val)) { count->lost++; val =3D 0; } diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index c6ad1dd90a56..d642e7d73910 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -34,7 +34,7 @@ enum tool_pmu_event tool_pmu__str_to_event(const char *st= r); bool tool_pmu__skip_event(const char *name); int tool_pmu__num_skip_events(void); =20 -bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result); +bool tool_pmu__read_event(enum tool_pmu_event ev, struct evsel *evsel, u64= *result); =20 u64 tool_pmu__cpu_slots_per_cycle(void); =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 6EBA621CA1E for ; Sat, 19 Jul 2025 03:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894344; cv=none; b=Mn4cNmUKos02vKvP6C5Uh0cUzjS9lLvCnaPwiy0CEHWyOlWiKTbBpWeyYWymiG0P0sQyy8ZT66fmd3b1JhCghdXGbqvMNJOOG7sAeZ5kM6vj/+4TwUiikz2iwO4LFxFl8VseVMyhgo3okT8IVRdFyxfnKRWZZyHpoq97x55e4NQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894344; c=relaxed/simple; bh=5J3GWGp3X0qKm/PVDdnh3hIcgm2jxUOFfVXtpeT61dk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=gQEgS8en4hxX1HTV4N+gBIdsU2W0JxeBbDBuC1RlFI8ueix+r3mBQ9hAc7SPadf1Xp1jh9NMQRWRKUafk4NYSWFwslRr4P1KGphCjZVcdFBXk2vOXXBc5/KAihmd8mcFlyQejHSxLcL5W3uPDeMEgty+Om5GGOB2LKudg/OBfYE= 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=BSZmeqCc; arc=none smtp.client-ip=209.85.215.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="BSZmeqCc" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b38ec062983so1813456a12.3 for ; Fri, 18 Jul 2025 20:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894342; x=1753499142; 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=3cEtMLLOSHTjrlHrzBNeeaYGWDamKeHqpltFXvpLlqk=; b=BSZmeqCcgzaUgTX+WEV5Ss1R5VSYCTtFYLUHpi/V+Pk/uCupWgbBo9HphjIY2K5bP9 o8gqnubvsI0xw3K6HipW8iAp5n+VLrpOmypw/5OnXAWTdXPc/Ztv3urysbZTAAwBiFCt sFULRw+drfooXV4V1UMfC5PzKkbx89HRI5Vg8p4f47ZjU75o4VUr9CzgW2jS3egx31Uh aDmy0rGX0mEWq+ApUA9saDi/+puxSg/PLIPkSMEh0a14/JzgNW9u+8IqXGmQP+kiltcT zFMgioYfSe9wRPM9R/J+rqHAoP/X/JTwigIqJuGQT+fx/SlaxXhVr0A2cZatFSKWLiRy ywHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894342; x=1753499142; 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=3cEtMLLOSHTjrlHrzBNeeaYGWDamKeHqpltFXvpLlqk=; b=ISLrGenT8EiUi6VQSrHuedrHssOyZkxbHuAWA7w7lrAB6fpkSz18f2aylcXEiKSCOd D5jV0DhsFJj6ApN1t0x2+iR6feerk5E77STbh/a49iFHIb5s0vu/v/9BnQCfEuP4VYvi VtgJZjRcSiHc59I1aVZZMWlS1tCS8Ut5DU+lV12ch7Vynvc7S23vR8E5R6kF1mekx8IK IZeXFH4UGCib/hq14CDiOtXmukHcHJblD4OHewy4NMdL/7D65XNspwxV0MqgcphJoRag mT4rg8NrWx0jwBm8YZ9kDiAtRjqFVmVpiZleiPmWQFatJrMr9MuC1xxHIZJPqtnVtB6u +hSw== X-Forwarded-Encrypted: i=1; AJvYcCWA/PBBX4g9nqGfwfIufxcStw+JHCwihi6ErOCfGWZCm4xJG2L9UI25hyacUC7g37vaEwP72vim8GTqySo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc9oFIWxXZdvbNi9uJJtTUDuvAeOF2CmJLUEhwY2/UCisffes8 wCh100xZ6bykGsOmMh22gF8MN2I8ZvLkh1EGnEFfpIlsbkBsPPUKcogK5SgkK+4H1XLkJxqw+SF 0Xc7BhMjC4w== X-Google-Smtp-Source: AGHT+IG1h57zo4JiDzg/FBsTu/ZB2FkzD5xKCvN1jWhLb8fozoI3BRVnMYDIpY5b3Saf2yGkUfm3u7KE/8+w X-Received: from pjbil4.prod.google.com ([2002:a17:90b:1644:b0:31c:c1a6:4452]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1aa3:b0:235:e76c:4362 with SMTP id d9443c01a7336-23e3b79a5acmr55958335ad.18.1752894341814; Fri, 18 Jul 2025 20:05:41 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:08 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-7-irogers@google.com> Subject: [PATCH v3 06/15] libperf evsel: Rename own_cpus to pmu_cpus 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" own_cpus is generally the cpumask from the PMU. Rename to pmu_cpus to try to make this clearer. Variable rename with no other changes. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 8 ++++---- tools/lib/perf/evsel.c | 2 +- tools/lib/perf/include/internal/evsel.h | 2 +- tools/perf/tests/event_update.c | 4 ++-- tools/perf/util/evsel.c | 6 +++--- tools/perf/util/header.c | 4 ++-- tools/perf/util/parse-events.c | 2 +- tools/perf/util/synthetic-events.c | 4 ++-- tools/perf/util/tool_pmu.c | 12 ++++++------ 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index b1f4c8176b32..9d9dec21f510 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -46,7 +46,7 @@ static void __perf_evlist__propagate_maps(struct perf_evl= ist *evlist, * are valid by intersecting with those of the PMU. */ perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__intersect(evlist->user_requested_cpus, evs= el->own_cpus); + evsel->cpus =3D perf_cpu_map__intersect(evlist->user_requested_cpus, evs= el->pmu_cpus); =20 /* * Empty cpu lists would eventually get opened as "any" so remove @@ -61,7 +61,7 @@ static void __perf_evlist__propagate_maps(struct perf_evl= ist *evlist, list_for_each_entry_from(next, &evlist->entries, node) next->idx--; } - } else if (!evsel->own_cpus || evlist->has_user_cpus || + } else if (!evsel->pmu_cpus || evlist->has_user_cpus || (!evsel->requires_cpu && perf_cpu_map__has_any_cpu(evlist->user_requeste= d_cpus))) { /* * The PMU didn't specify a default cpu map, this isn't a core @@ -72,13 +72,13 @@ static void __perf_evlist__propagate_maps(struct perf_e= vlist *evlist, */ perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); - } else if (evsel->cpus !=3D evsel->own_cpus) { + } else if (evsel->cpus !=3D evsel->pmu_cpus) { /* * No user requested cpu map but the PMU cpu map doesn't match * the evsel's. Reset it back to the PMU cpu map. */ perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__get(evsel->own_cpus); + evsel->cpus =3D perf_cpu_map__get(evsel->pmu_cpus); } =20 if (evsel->system_wide) { diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 2a85e0bfee1e..127abe7df63d 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -46,7 +46,7 @@ void perf_evsel__delete(struct perf_evsel *evsel) assert(evsel->mmap =3D=3D NULL); /* If not munmap wasn't called. */ assert(evsel->sample_id =3D=3D NULL); /* If not free_id wasn't called. */ perf_cpu_map__put(evsel->cpus); - perf_cpu_map__put(evsel->own_cpus); + perf_cpu_map__put(evsel->pmu_cpus); perf_thread_map__put(evsel->threads); free(evsel); } diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/inclu= de/internal/evsel.h index ea78defa77d0..b97dc8c92882 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -99,7 +99,7 @@ struct perf_evsel { * cpu map for opening the event on, for example, the first CPU on a * socket for an uncore event. */ - struct perf_cpu_map *own_cpus; + struct perf_cpu_map *pmu_cpus; struct perf_thread_map *threads; struct xyarray *fd; struct xyarray *mmap; diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_updat= e.c index 9301fde11366..cb9e6de2e033 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -109,8 +109,8 @@ static int test__event_update(struct test_suite *test _= _maybe_unused, int subtes TEST_ASSERT_VAL("failed to synthesize attr update name", !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_eve= nt_name)); =20 - perf_cpu_map__put(evsel->core.own_cpus); - evsel->core.own_cpus =3D perf_cpu_map__new("1,2,3"); + perf_cpu_map__put(evsel->core.pmu_cpus); + evsel->core.pmu_cpus =3D perf_cpu_map__new("1,2,3"); =20 TEST_ASSERT_VAL("failed to synthesize attr update cpus", !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_eve= nt_cpus)); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d9b6bf78d67b..ba0c9799928b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -488,7 +488,7 @@ struct evsel *evsel__clone(struct evsel *dest, struct e= vsel *orig) return NULL; =20 evsel->core.cpus =3D perf_cpu_map__get(orig->core.cpus); - evsel->core.own_cpus =3D perf_cpu_map__get(orig->core.own_cpus); + evsel->core.pmu_cpus =3D perf_cpu_map__get(orig->core.pmu_cpus); evsel->core.threads =3D perf_thread_map__get(orig->core.threads); evsel->core.nr_members =3D orig->core.nr_members; evsel->core.system_wide =3D orig->core.system_wide; @@ -1527,7 +1527,7 @@ void evsel__config(struct evsel *evsel, struct record= _opts *opts, attr->exclude_user =3D 1; } =20 - if (evsel->core.own_cpus || evsel->unit) + if (evsel->core.pmu_cpus || evsel->unit) evsel->core.attr.read_format |=3D PERF_FORMAT_ID; =20 /* @@ -1680,7 +1680,7 @@ void evsel__exit(struct evsel *evsel) evsel__free_config_terms(evsel); cgroup__put(evsel->cgrp); perf_cpu_map__put(evsel->core.cpus); - perf_cpu_map__put(evsel->core.own_cpus); + perf_cpu_map__put(evsel->core.pmu_cpus); perf_thread_map__put(evsel->core.threads); zfree(&evsel->group_name); zfree(&evsel->name); diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 53d54fbda10d..d941d7aa0f49 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -4507,8 +4507,8 @@ int perf_event__process_event_update(const struct per= f_tool *tool __maybe_unused case PERF_EVENT_UPDATE__CPUS: map =3D cpu_map__new_data(&ev->cpus.cpus); if (map) { - perf_cpu_map__put(evsel->core.own_cpus); - evsel->core.own_cpus =3D map; + perf_cpu_map__put(evsel->core.pmu_cpus); + evsel->core.pmu_cpus =3D map; } else pr_err("failed to get event_update cpus\n"); default: diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index a337e4d22ff2..d506f9943506 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -320,7 +320,7 @@ __add_event(struct list_head *list, int *idx, =20 (*idx)++; evsel->core.cpus =3D cpus; - evsel->core.own_cpus =3D perf_cpu_map__get(cpus); + evsel->core.pmu_cpus =3D perf_cpu_map__get(cpus); evsel->core.requires_cpu =3D pmu ? pmu->is_uncore : false; evsel->core.is_pmu_core =3D is_pmu_core; evsel->pmu =3D pmu; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 2fc4d0537840..7c00b09e3a93 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2045,7 +2045,7 @@ int perf_event__synthesize_event_update_name(const st= ruct perf_tool *tool, struc int perf_event__synthesize_event_update_cpus(const struct perf_tool *tool,= struct evsel *evsel, perf_event__handler_t process) { - struct synthesize_cpu_map_data syn_data =3D { .map =3D evsel->core.own_cp= us }; + struct synthesize_cpu_map_data syn_data =3D { .map =3D evsel->core.pmu_cp= us }; struct perf_record_event_update *ev; int err; =20 @@ -2126,7 +2126,7 @@ int perf_event__synthesize_extra_attr(const struct pe= rf_tool *tool, struct evlis } } =20 - if (evsel->core.own_cpus) { + if (evsel->core.pmu_cpus) { err =3D perf_event__synthesize_event_update_cpus(tool, evsel, process); if (err < 0) { pr_err("Couldn't synthesize evsel cpus.\n"); diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 7aa4f315b0ac..d99e699e646d 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -357,10 +357,10 @@ bool tool_pmu__read_event(enum tool_pmu_event ev, str= uct evsel *evsel, u64 *resu /* * "Any CPU" event that can be scheduled on any CPU in * the PMU's cpumask. The PMU cpumask should be saved in - * own_cpus. If not present fall back to max. + * pmu_cpus. If not present fall back to max. */ - if (!perf_cpu_map__is_empty(evsel->core.own_cpus)) - *result =3D perf_cpu_map__nr(evsel->core.own_cpus); + if (!perf_cpu_map__is_empty(evsel->core.pmu_cpus)) + *result =3D perf_cpu_map__nr(evsel->core.pmu_cpus); else *result =3D cpu__max_present_cpu().cpu; } @@ -386,12 +386,12 @@ bool tool_pmu__read_event(enum tool_pmu_event ev, str= uct evsel *evsel, u64 *resu /* * "Any CPU" event that can be scheduled on any CPU in * the PMU's cpumask. The PMU cpumask should be saved in - * own_cpus, if not present then just the online cpu + * pmu_cpus, if not present then just the online cpu * mask. */ - if (!perf_cpu_map__is_empty(evsel->core.own_cpus)) { + if (!perf_cpu_map__is_empty(evsel->core.pmu_cpus)) { struct perf_cpu_map *tmp =3D - perf_cpu_map__intersect(online, evsel->core.own_cpus); + perf_cpu_map__intersect(online, evsel->core.pmu_cpus); =20 *result =3D perf_cpu_map__nr(tmp); perf_cpu_map__put(tmp); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 6D1821FBEB6 for ; Sat, 19 Jul 2025 03:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894345; cv=none; b=EXvZF7pz1KmLFeKJsb6887M0qtZT+M5hfafcOQ6jQABf7MC1ZzsD5rjcVYDdwe4uj60VhyRJag9HFHnTBWxnQMvhE7m/5+VLtuDmZziNHBRArLnTEebMnDIO9QOa11fPEw1ehQN7TYlxqUKPdcltwyBXBeeq6vqsYikMHiq/mRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894345; c=relaxed/simple; bh=q5gclP8enVIDgmFTy0uPjEoUXrIKoG7WxEpD69DREJQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=tCu3g8kPvac0K7mBCrPAwVPzmKuoCxqIZcadXz+JKZbwSByBMwes/WMZrBBTTpcC0dPzIB8vhKWdfrjswSb90h2k8GX34/+pnAabwvWhaSdQWrjMJ0GGfVGlTajXHS+73+RutKSPhV43w9Z9cHpy6BNQvSdEYTq3iqn7IaFn2hM= 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=KBJ4Osvu; arc=none smtp.client-ip=209.85.216.74 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="KBJ4Osvu" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-313f702d37fso2772860a91.3 for ; Fri, 18 Jul 2025 20:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894344; x=1753499144; 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=9k2/D5iQ4L1OZOaKDLGd73SeKK5tMn2kJdyY+h5+RPA=; b=KBJ4OsvuGbbeL6cM9Jw+n5tVBd27xNlh1gdlqfrL7IZ+JPFwnMqqeeqywfMzMkEcim fZLoqSvcZrlu/Hp7+yDQOProUpCJtMi9UydaGKGU/GeccAaRd2dcrVYmjd2VBPQc9LT8 exzBWbkzpZ4pe4eS7BO9FExJqezf2b2um1I/mAIJjJhUH/2+DNaK0DXU9IfKGYxkRDVw izaynF8K2UZEbi9mnuuILDoLPn58p/y09p1BaITtcsOnp01CzLp6F+mGk6K/YOfC/wa/ 9+hSi/t2uxJhj14CLfsXOcnoHvwKcHGpcB9FGuYaGAiBy+Jz6DbWdKJ8labT5VsqVsuM wViw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894344; x=1753499144; 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=9k2/D5iQ4L1OZOaKDLGd73SeKK5tMn2kJdyY+h5+RPA=; b=ZXIncvfo4+EkCOMQJUWDxl5EmwNYsrxP3jlRGEJFzBp/du/r6iFIrUkPD7xBa9KXZX oyOE6Kclmo72bUtOp/C9uUa0xZxLtxsJWTF9wOzxsHw1EwVN5qz8Q/dSuXEbl6Drnb7g 7PNdObeeeKRfMsM3gm30P7mkTk4gZVSkxZP/9Z10/A3I2ZSf5odnMnAU1EM2hfSkndTr FklV95URzoba4csSUmN9mPidqkC/4Z2KXpTcHyT500I3BE/poa77t2EUV0TvU70UoKH6 C5Oh84oUsusamLAK4Y1g9IXmz30uqXZElcP6UMKvWpm2ixEZiWIgjjGhfXivKOONX3Wy suMA== X-Forwarded-Encrypted: i=1; AJvYcCU5vWdGFam92fdOLHDekBn0TCx5mqiFyYoHVMYE4H1aBqVfd9SVEjuhBEs5seWWk6E1CYA+RMiJubqxOMg=@vger.kernel.org X-Gm-Message-State: AOJu0YzIAgO4pNUCVlUqavwMk8kAtZdsWnfhe7mH+WHuQ9gImHvI0r89 bKX8wO+blAPaa7eXezBBTzG3CzmIjhQVgkd0gqpUHOo9JKNRhnyQq0f3+VuWVZrtnendBn9yGQI QQ+xJOvJevQ== X-Google-Smtp-Source: AGHT+IGyCYdok/lnjluDg4zgG85RjuslrrMWd8I4POGHU0w7L3dN6jiZ4H8vv/OkrsxeSOuFVkwMORo0c8W5 X-Received: from pjtu4.prod.google.com ([2002:a17:90a:c884:b0:313:1c10:3595]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3901:b0:311:9c9a:58ca with SMTP id 98e67ed59e1d1-31c9f44a3d5mr19868019a91.8.1752894343705; Fri, 18 Jul 2025 20:05:43 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:09 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-8-irogers@google.com> Subject: [PATCH v3 07/15] libperf evsel: Factor perf_evsel__exit out of perf_evsel__delete 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This allows the perf_evsel__exit to be called when the struct perf_evsel is embedded inside another struct, such as struct evsel in perf. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/lib/perf/evsel.c | 7 ++++++- tools/lib/perf/include/internal/evsel.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 127abe7df63d..13a307fc75ae 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -40,7 +40,7 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr= *attr) return evsel; } =20 -void perf_evsel__delete(struct perf_evsel *evsel) +void perf_evsel__exit(struct perf_evsel *evsel) { assert(evsel->fd =3D=3D NULL); /* If not fds were not closed. */ assert(evsel->mmap =3D=3D NULL); /* If not munmap wasn't called. */ @@ -48,6 +48,11 @@ void perf_evsel__delete(struct perf_evsel *evsel) perf_cpu_map__put(evsel->cpus); perf_cpu_map__put(evsel->pmu_cpus); perf_thread_map__put(evsel->threads); +} + +void perf_evsel__delete(struct perf_evsel *evsel) +{ + perf_evsel__exit(evsel); free(evsel); } =20 diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/inclu= de/internal/evsel.h index b97dc8c92882..fefe64ba5e26 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -133,6 +133,7 @@ struct perf_evsel { =20 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *at= tr, int idx); +void perf_evsel__exit(struct perf_evsel *evsel); int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads= ); void perf_evsel__close_fd(struct perf_evsel *evsel); void perf_evsel__free_fd(struct perf_evsel *evsel); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 DEDC0221F26 for ; Sat, 19 Jul 2025 03:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894347; cv=none; b=GMaS9zIGSnxe8c0kDxknA31ojv/huP7JDbutsgvy7zXZ5N27NH6y41NQbuyfHJ9quvjc6vl9GHUiz4ojXqblFQVJIGwwNnijdsX7q46QXqTHdTlcL0hb2CQqrCWG68UFBs1o4u/e2g7dnI0j9DwUMmUzAH5i6f20PjiOxH0gdMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894347; c=relaxed/simple; bh=wXa1SCmjfrA/iYrTIx3xkr7OdsM/urYyoLsdv3r5x70=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=l4qIYlo7R8JsGkD2Edg00V4anbkY0nTZbMSPf6dV5PjhdMabt+6u55zbw9SpDX9QxKMNSJ6z8fJu1cYwFalTCMYvavSmBb+kl4ofa/Pe4qWETs2lIeKg1bV4q42NmDUBbmWb0pBkUBF8qzbAA/XmK51cFWyYVDJX6dyFetGKzwM= 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=UZvnIwCn; arc=none smtp.client-ip=209.85.216.74 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="UZvnIwCn" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-313d6d671ffso2780064a91.2 for ; Fri, 18 Jul 2025 20:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894345; x=1753499145; 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=/ZM3pCSwYMC0xtzhmcoaS56jTJWwNHuIZbVeellQWzo=; b=UZvnIwCnUH3/BzMe8nsLAV6HUrAE0Rf5+pkhugssOrrDp+/RW/74U0zJRzVV7QYAOz WUITNAveMvC1rn9qf16KaHFdTBbfH037KFqpPGhhq7zyFVUHuNBVx8ZOYphdmVclzF5b DWUPG+wUmstja5KJLcdwQ+odTudma8wYJON9Hq4Ow3Nf6So9Yt/3egy7grO9I3fKxozO 2+Zg4N8+h8J1tZbBJEmy/ePJn9YiqePMSDMhnx9En8GVjkrhi6SLDfoufKmwoCIpKCx0 Iki9/Bz5gJPBgB5Knat3R9GfNAkoaLHwJcQlk8K2rZFGSPb5nRoofskmDYi9WxVeW1HC EPlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894345; x=1753499145; 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=/ZM3pCSwYMC0xtzhmcoaS56jTJWwNHuIZbVeellQWzo=; b=BWnrtGG2xhVE38g+YdLC0kRm7uCNTNsnae0UjOXWxPCatZVjKwfiYbBpepqaLSbe5a Dw2BPqRhpNjqPUh8P4vIn9FoScf9OG2EvYNJSeFjVOWTGf7W04ZW/geQpwymSKxcOeGT 1KCRwesAOhVxgtKxdGFNmHUtJnmIbvcRFVQ//CPp+kfKPf3Btqdcc2A592TrHvh5b8wz HIPcwx0Z4VwFBIpSUiisbzYI5wrvBNdAkrUT6MZBl/Y+beT681ZrDEJ24zhEFEd6XRKR tfe4mtZRNQPU2r/nUPJsXDki4yPin/rQrws5rAMehFicIJ+PLtNWK7V+yrAxf/4TzGuO lsDg== X-Forwarded-Encrypted: i=1; AJvYcCVinFa49HVJoV7cEmP8o0eB+GPhmNb/Ky8WGWx8ykglmO0wBdAjvzd5flDpG5K2jSR+lxgEoCkrwJkHtrY=@vger.kernel.org X-Gm-Message-State: AOJu0YyFgBcIx4Gi92Z9Agb3RCEghF8B+Mcyl5ORHKdlvJ5Vz0epiHaI Gi7jLb4VCzpaI4HuxmgPmt6JxyIf7izMtbqwW1yWKtiZBWGPNJTFv08BmXjdfA1AqcHrBj9EjLp 1tE79cxRFsQ== X-Google-Smtp-Source: AGHT+IGxTK1lulIEjB+dBbyn5f9/P/TVosL0kIfsZoFKCIIF6FSBvW7lRnCfCOa5k4w9eAI/HS2myzqxvBSD X-Received: from pjbqa9.prod.google.com ([2002:a17:90b:4fc9:b0:313:d6cf:4fa0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:fc46:b0:2ee:d371:3227 with SMTP id 98e67ed59e1d1-31c9e7617d1mr21663665a91.17.1752894345374; Fri, 18 Jul 2025 20:05:45 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:10 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-9-irogers@google.com> Subject: [PATCH v3 08/15] perf evsel: Use libperf perf_evsel__exit 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid the duplicated code and better enable perf_evsel to change. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ba0c9799928b..af2b26c6456a 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1679,9 +1679,7 @@ void evsel__exit(struct evsel *evsel) perf_evsel__free_id(&evsel->core); evsel__free_config_terms(evsel); cgroup__put(evsel->cgrp); - perf_cpu_map__put(evsel->core.cpus); - perf_cpu_map__put(evsel->core.pmu_cpus); - perf_thread_map__put(evsel->core.threads); + perf_evsel__exit(&evsel->core); zfree(&evsel->group_name); zfree(&evsel->name); #ifdef HAVE_LIBTRACEEVENT --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 669C5224B14 for ; Sat, 19 Jul 2025 03:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894348; cv=none; b=msS5f1w+dn+VLGYQd9pYCf4xjykAyf9Gc87XojmjbWQ2CjCzBTyITUvnVMfeUL10ZmMflkWMgb7ZwAXnuyVxAcadglfj2EbO1O7efLQlDEFPGnLH0qneOozslHC2OnKlAnpZW+4AwxYM0adSiUvaPiVbRJqIfvVki41q3EtkgYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894348; c=relaxed/simple; bh=9zUQeTccp3718gUxjT/0ylX/P1DJl6kmckROyxaibeY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=RrITZN7j03EfVuel9Aq9nJLZOxn61oiV0Em5RLaC/BK/v2hTif0LEfcZ51pnY4oZFPqAHs5FjrvG9OX0mEF0tIfs6RcucyKJ+mwl+GN/SE2anh/dHf48PEEni3HdRyh3kjGTjd68WfOkhv0adnjf8gIpL0cXnihfD36aiL7vOgQ= 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=bYvdJpiw; arc=none smtp.client-ip=209.85.214.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="bYvdJpiw" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-23536f7c2d7so44687505ad.2 for ; Fri, 18 Jul 2025 20:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894347; x=1753499147; 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=gJ/d8adwiFNGcK/vA7cpk18Ivr6shkjwDMIS9Lqkdas=; b=bYvdJpiw7dxBQpA1GpziKDskaL/G3rB7DxavjGQVgJX3U+LIbFrrg2BaAqxwieWWC/ ggcQ7p9L7/TPYzyzAGjxD7o/uJrmpRrH0hnEiltBgVJV4HmS2mSWMLIQRfD1TomLp1Fj HndaBe1l3i/GFnCWpbVB/Q26h8Onb1NrFLofYnBwzG8h7tSuOrMw1W6ufOw96YExPurD YhSMfKt+crxVNz/fqhDF6n/lfh/24xCXz9eGLBGtJ+eSjgFzu6rqwGz9dpurUymGZvtJ mmH67cJKUrE52zcI/lUhMIdGxtgnhWix6rm9/Ife2lgEDHmdQq4zFpKespoYwZC5nAcg IEaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894347; x=1753499147; 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=gJ/d8adwiFNGcK/vA7cpk18Ivr6shkjwDMIS9Lqkdas=; b=RPfeYdXDqDZhfRj8DM1n2O+ozKmSDmr1VedPq4Ra5Yj30Z1D7nXJKHTOKwVF8pN2bH hpPjJbniGKmMa3YVvTX6OmlGGocJmanq9ZnAUcJ/QC3GNc7oOBAinV0gnI92Y4S3/Dxm 4WBYI3CZwGi3GyhM64yHSzsFVjReVQ1g2DbKClE12GXzNbwGUm8XyBqEEjVCWH8LLs19 6gZTvKOzp6uwkLYRxObxuTwr5H729eL8JjudhMnt0i9QA7COY5aSHfr9+84Y39BbCkaJ XC3vQEqogeHYATd2B52Ii7RojIVT044LwSWyLtM8a5Kv2yK3pwT5aX03yWhQZBTsm6wL 4jIA== X-Forwarded-Encrypted: i=1; AJvYcCVp+6xHT2Yf82/+GjHd4TeOwnbmYqs0aerHZ/dclnNJ8I8U7b7I4k30MDfK8jmskqdEGwD44Y7v7qvGuOY=@vger.kernel.org X-Gm-Message-State: AOJu0YwxeMBJY8rbGAOHc630yWoD4o+sKe6xY4jvNsfr4rFy4B3gQdLb bNcFdQX0OnEJhPUtEjtRtfCN83SfMLJaC3z2ZAGoZ8FrXedjM9TQsGWC6LsroIvUKE6DqxIcsiY AtJmbrGgFnw== X-Google-Smtp-Source: AGHT+IEB+pdxCUFskM3zmnoHCS0R9y7J1DhdQMJx0Yjnf/P70GiRb2Ww+gtayc9A6phNdIH+SPcnHMedriJE X-Received: from plbky6.prod.google.com ([2002:a17:902:f986:b0:236:71ef:2187]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce0a:b0:23a:bc47:381f with SMTP id d9443c01a7336-23e25763d49mr160412775ad.36.1752894346988; Fri, 18 Jul 2025 20:05:46 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:11 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-10-irogers@google.com> Subject: [PATCH v3 09/15] perf pmus: Factor perf_pmus__find_by_attr out of evsel__find_pmu 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow a PMU to be found by a perf_event_attr, useful when creating evsels. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 29 +++++++++++++++++------------ tools/perf/util/pmus.h | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 409b909cfa02..9137bb9036ed 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -814,24 +814,18 @@ bool perf_pmus__supports_extended_type(void) return perf_pmus__do_support_extended_type; } =20 -struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) +struct perf_pmu *perf_pmus__find_by_attr(const struct perf_event_attr *att= r) { - struct perf_pmu *pmu =3D evsel->pmu; - bool legacy_core_type; - - if (pmu) - return pmu; + struct perf_pmu *pmu =3D perf_pmus__find_by_type(attr->type); + u32 type =3D attr->type; + bool legacy_core_type =3D type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D P= ERF_TYPE_HW_CACHE; =20 - pmu =3D perf_pmus__find_by_type(evsel->core.attr.type); - legacy_core_type =3D - evsel->core.attr.type =3D=3D PERF_TYPE_HARDWARE || - evsel->core.attr.type =3D=3D PERF_TYPE_HW_CACHE; if (!pmu && legacy_core_type && perf_pmus__supports_extended_type()) { - u32 type =3D evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; + type =3D attr->config >> PERF_PMU_TYPE_SHIFT; =20 pmu =3D perf_pmus__find_by_type(type); } - if (!pmu && (legacy_core_type || evsel->core.attr.type =3D=3D PERF_TYPE_R= AW)) { + if (!pmu && (legacy_core_type || type =3D=3D PERF_TYPE_RAW)) { /* * For legacy events, if there was no extended type info then * assume the PMU is the first core PMU. @@ -842,6 +836,17 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *e= vsel) */ pmu =3D perf_pmus__find_core_pmu(); } + return pmu; +} + +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) +{ + struct perf_pmu *pmu =3D evsel->pmu; + + if (pmu) + return pmu; + + pmu =3D perf_pmus__find_by_attr(&evsel->core.attr); ((struct evsel *)evsel)->pmu =3D pmu; return pmu; } diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 86842ee5f539..7cb36863711a 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -5,6 +5,7 @@ #include #include =20 +struct perf_event_attr; struct perf_pmu; struct print_callbacks; =20 @@ -16,6 +17,7 @@ void perf_pmus__destroy(void); =20 struct perf_pmu *perf_pmus__find(const char *name); struct perf_pmu *perf_pmus__find_by_type(unsigned int type); +struct perf_pmu *perf_pmus__find_by_attr(const struct perf_event_attr *att= r); =20 struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (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 A991B224B14 for ; Sat, 19 Jul 2025 03:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894354; cv=none; b=YmPXrDjeVhoH3Qw2/M1nlOr0u8PA2CmdAtOf/Lycsym64ZJPiMMKDWpbGUoMv3Rkjd8n7Sf8yqfXJZt9F32kcHA45zlkC5C+3dxE3T9CrHTQwg6CJwgwTuIFkTOfZGGZGzp7xY8B0dlpyYo64v+z23MoUy7xPwGssskTXwtBK90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894354; c=relaxed/simple; bh=jEgvDggwtQddGz/4ZXMmANkYODrHYVg1OL8Si0VZ5M0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kpYv0FFRwjtRqjuyL3cm1driTvIg1qI+hAPO3XjdubFICFgm9bkx/RVeSUoyvrGhf1semqM9TZdaj/zb9DRL6g+xHyhqXCItf97OeD0f0Tco2+HRDZ9OtGzT96We8CRuuqyIrxgcw3XMXmJy8TKayB26gMVZWIA/QG/yd8ZuVNI= 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=Qg/0B+6u; arc=none smtp.client-ip=209.85.160.73 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="Qg/0B+6u" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2ffc9597292so2019454fac.2 for ; Fri, 18 Jul 2025 20:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894352; x=1753499152; 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=FbO2FaLlRAtP3MPRgVDa/ZaeF16Ze9Vrmjj4VaK1jxk=; b=Qg/0B+6u0J2HgxoKg6/74lqLvHYs5P9h4OmbgpTEDkvEzn+t9S4AW+NarHsrhtEL3e upjvxsqyhoLuGxdSmDcg6+ivbJc3qsQh+LHWua6puHcFvelVnT77Y2UJfmDfKO7J5CUt GmMbXZ1SE/8oxkl7rZ6rVaZyjsYden1WKxUFCshPPlAB6EHs3mU7Xps8iTcQzAXIqFT7 lfgXgc1A5yhlDAOH0nVYFOvy5a8STDKhMCGcNQM0rSjoS4oeeyYNvGq6ap0xz5S9qWbv BoLMK6bn2kH8abPJ6eITjGfjHtFbYbcOj5Dxr7+8m5jXlfKnEA1Nnj2YuPLEuGisnq9k Mahg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894352; x=1753499152; 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=FbO2FaLlRAtP3MPRgVDa/ZaeF16Ze9Vrmjj4VaK1jxk=; b=KjAV7jrtaj74xM0YcSPyfIQHU/XT/P8puW6D3zL9Cgnlef8tZDv4jNzbvuvt3JEpnH 81uloGjeXZ0CgvkCYmAXn1fXcgfwkhGjuojmqc0PeUudNn9osonw/jrsDEugtQcHZULF F03bucvVzqnXJdjv5i05UgYcvjsTmZIJDAyuxMWVTbkrl/VVvZzzgDHwN76zIwXMbw7K oVOqaRrXjTHHCp5oVGWeVacZamvHFfACQ6pEEO5c8ceqV08VyDaUoBSxn1oB/1eCmEXm gUwr1VrP1wwp6ctVWzg1+fxrrMlH0j5pbJYhmzwxxTyoHM/b/3D8KIoXzHFlPlPVgPt8 yS+g== X-Forwarded-Encrypted: i=1; AJvYcCU4c1QbG6Fm6QzoezYL4QC21lOrPW2A/8zNh4qwhnkNzGxl3GA+US3xqRycfcIt6E0k0AMFv36XSLJ5tJs=@vger.kernel.org X-Gm-Message-State: AOJu0YwJNUe75+a9S+MW/D4lpe/d/V5jjsvzandewctbXsgA3D++O7Zn m5QoYSnpbhg1FS+W7CnsZeXsgdHwwTYT2PV9nKC5TwUvbCyi5ea1MDqkGiyB+fOaDI0tdgeg/So o+t/73sNixQ== X-Google-Smtp-Source: AGHT+IH9mQssBop1ojQqFEkRCfHDS5fXdwoIedZ8y4RWCt//Bq7XXGqKMaiiV+8DtXnKcOcE+95CnISBh2tw X-Received: from oacpz15.prod.google.com ([2002:a05:6871:e48f:b0:2ff:a540:5c40]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:b0e:b0:28c:8476:dd76 with SMTP id 586e51a60fabf-2ffd256ea33mr7239613fac.29.1752894351636; Fri, 18 Jul 2025 20:05:51 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:12 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-11-irogers@google.com> Subject: [PATCH v3 10/15] perf parse-events: Minor __add_event refactoring 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename cpu_list to user_cpus. If a PMU isn't given, find it early from the perf_event_attr. Make the pmu_cpus more explicitly a copy from the PMU (except when user_cpus are given). Derive the cpus from pmu_cpus and user_cpus as appropriate. Handle strdup errors on name and metric_id. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 69 +++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index d506f9943506..bd2d831d5123 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -259,12 +259,12 @@ __add_event(struct list_head *list, int *idx, bool init_attr, const char *name, const char *metric_id, struct perf_pmu *pmu, struct list_head *config_terms, struct evsel *first_wildcard_match, - struct perf_cpu_map *cpu_list, u64 alternate_hw_config) + struct perf_cpu_map *user_cpus, u64 alternate_hw_config) { struct evsel *evsel; bool is_pmu_core; - struct perf_cpu_map *cpus; - bool has_cpu_list =3D !perf_cpu_map__is_empty(cpu_list); + struct perf_cpu_map *cpus, *pmu_cpus; + bool has_user_cpus =3D !perf_cpu_map__is_empty(user_cpus); =20 /* * Ensure the first_wildcard_match's PMU matches that of the new event @@ -288,8 +288,6 @@ __add_event(struct list_head *list, int *idx, } =20 if (pmu) { - is_pmu_core =3D pmu->is_core; - 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, @@ -301,48 +299,77 @@ __add_event(struct list_head *list, int *idx, perf_pmu__warn_invalid_config(pmu, attr->config3, name, PERF_PMU_FORMAT_VALUE_CONFIG3, "config3"); } + } + /* + * If a PMU wasn't given, such as for legacy events, find now that + * warnings won't be generated. + */ + if (!pmu) + pmu =3D perf_pmus__find_by_attr(attr); + + if (pmu) { + is_pmu_core =3D pmu->is_core; + pmu_cpus =3D perf_cpu_map__get(pmu->cpus); } else { is_pmu_core =3D (attr->type =3D=3D PERF_TYPE_HARDWARE || attr->type =3D=3D PERF_TYPE_HW_CACHE); - if (has_cpu_list) - cpus =3D perf_cpu_map__get(cpu_list); - else - cpus =3D is_pmu_core ? cpu_map__online() : NULL; + pmu_cpus =3D is_pmu_core ? cpu_map__online() : NULL; + } + + if (has_user_cpus) { + cpus =3D perf_cpu_map__get(user_cpus); + /* Existing behavior that pmu_cpus matches the given user ones. */ + perf_cpu_map__put(pmu_cpus); + pmu_cpus =3D perf_cpu_map__get(user_cpus); + } else { + cpus =3D perf_cpu_map__get(pmu_cpus); } + if (init_attr) event_attr_init(attr); =20 evsel =3D evsel__new_idx(attr, *idx); - if (!evsel) { - perf_cpu_map__put(cpus); - return NULL; + if (!evsel) + goto out_err; + + if (name) { + evsel->name =3D strdup(name); + if (!evsel->name) + goto out_err; + } + + if (metric_id) { + evsel->metric_id =3D strdup(metric_id); + if (!evsel->metric_id) + goto out_err; } =20 (*idx)++; evsel->core.cpus =3D cpus; - evsel->core.pmu_cpus =3D perf_cpu_map__get(cpus); + evsel->core.pmu_cpus =3D pmu_cpus; evsel->core.requires_cpu =3D pmu ? pmu->is_uncore : false; evsel->core.is_pmu_core =3D is_pmu_core; evsel->pmu =3D pmu; evsel->alternate_hw_config =3D alternate_hw_config; evsel->first_wildcard_match =3D first_wildcard_match; =20 - if (name) - evsel->name =3D strdup(name); - - if (metric_id) - evsel->metric_id =3D strdup(metric_id); - if (config_terms) list_splice_init(config_terms, &evsel->config_terms); =20 if (list) list_add_tail(&evsel->core.node, list); =20 - if (has_cpu_list) - evsel__warn_user_requested_cpus(evsel, cpu_list); + if (has_user_cpus) + evsel__warn_user_requested_cpus(evsel, user_cpus); =20 return evsel; +out_err: + perf_cpu_map__put(cpus); + perf_cpu_map__put(pmu_cpus); + zfree(&evsel->name); + zfree(&evsel->metric_id); + free(evsel); + return NULL; } =20 struct evsel *parse_events__add_event(int idx, struct perf_event_attr *att= r, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 86A3520ADF8 for ; Sat, 19 Jul 2025 03:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894356; cv=none; b=E/mFwrM3mP++YMWheLHDzt5vw+/rqAhdTveMq6eYrl3X1mIIYE4OkqwWVM/WLdqJUqXWUV1sPAQmuaHSorT/LBv6Dm6geNlDIpuzTZrswSCt+QzDteKCa9W4Ws/wlQRXq4fOBJRefIoQIRtf64hn93D0VAokNnlR1FubARCvkJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894356; c=relaxed/simple; bh=7V57mrxclma+L6i7A+s/RUZqSr9To26yFbxOIRG9Ic8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=n42uMMEv5CjyWxMZDgpmdGg1yCNROuF6x+4gbtR6rjpu//NQ86Ntu4o5YnaqWYtUjU9nHjJEYNyjndOZvKecOBEk++jHQaG49bIfe6yxEYUc6Yo99E0zhQ3s3lqjFAy8kXLniF+hmkJDBrK1ljkkzLgh7CSe5LDT5tZH7pPLNeg= 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=1KmgzzwL; arc=none smtp.client-ip=209.85.216.73 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="1KmgzzwL" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-313fab41f4bso3616194a91.0 for ; Fri, 18 Jul 2025 20:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894354; x=1753499154; 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=lxK32ZV3/TwHJ48GSqnT12vEqhtnY89NH3NlvQCfpOQ=; b=1KmgzzwL/r3AVd9PKK9u2XF3aS85LtaiP/g11RDqe5dzP4+/R01rqzLjZnHTibG0an cSoYHxI14is6CyMgilzEgoksS33p47FYvki+LmmVy6TX0gXJ5n0nA6W94jgs0NgQZlur 5VExYtpGSeK1PG9SrO8JI+FDNeIGTbCKLP+pVrjzOqEZG40LY4M6CEPD1aoZe5hdPS2Y 2/wWg4XLyMVldXIKfJ7+RUu2Bt1ZDoYeCgvBqx0YXRBZ2sj/DGbCbAw0kYoE4atjy5ah wiYYfjarsFnlsYN2yKlGuEO+RqEBHefTI678Jz6FBfEB2StFFK+T+saE16UhbbduqsyH taiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894354; x=1753499154; 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=lxK32ZV3/TwHJ48GSqnT12vEqhtnY89NH3NlvQCfpOQ=; b=QX+8CgNUAeBG7HZ4lGjToSvXsclLquRUmKameb7G3SJ/T10kHbbwouqae/hWf6LQZ0 c4aN4i9gD0uA1aNJUuglfliEY+3TDlprYFUJ5vLXdDvIy3krlS5RBJNm0fRt4GoT7PKV dK5LeA73Jb+zUMXY0Guo0wAeSCSDtfMkPFIWwA/v8Fsz/A9xvOJhvBdLTDT+2tbTVyXT POvcqUUcrH4ixUoWf9zoFg/v4M6NKAhJ7UcJKS3UCboSS1vtN4FoagTc7ZLbeDyUZxb0 Z2tsoJwghexAXm0uYwI4dqrtbl80gjcePH4m7oK/KQqh4i7uZWJ6gJSFRL+Qx+Gr7MCl 6UUQ== X-Forwarded-Encrypted: i=1; AJvYcCUvBQPjJ/g3bLeIB22+4E3F/nV4yEay+NxiqypWnS/KoBjXQhiUL4NDSoQVpOmhGvU70s3aOzQhLgTFbNw=@vger.kernel.org X-Gm-Message-State: AOJu0YwVF4TOY50raWw75lmj0ICKXHtqNGoCLUpnQgrzx116YGs93A48 2VjbxwpN7k9P9LGrvLK2FKJwvnF/brvt9AinO4pRfRSJisAy4zvWCEk9vdLzUpskISVi1F0nK/6 ABV3wZuBF9Q== X-Google-Smtp-Source: AGHT+IGog4H16tvEQwiT1AI891pwhJQ9A4BVEfNjMEJyKJU2RSnd/ONsvz2K6wIehr6NTjys2vAEPGX8XNto X-Received: from pjqq12.prod.google.com ([2002:a17:90b:584c:b0:314:2a3f:89c5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b43:b0:311:e8cc:4253 with SMTP id 98e67ed59e1d1-31caf82168bmr13625383a91.2.1752894353867; Fri, 18 Jul 2025 20:05:53 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:13 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-12-irogers@google.com> Subject: [PATCH v3 11/15] perf evsel: Add evsel__open_per_cpu_and_thread 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add evsel__open_per_cpu_and_thread that combines the operation of evsel__open_per_cpu and evsel__open_per_thread so that an event without the "any" cpumask can be opened with its cpumask and with threads it specifies. Change the implementation of evsel__open_per_cpu and evsel__open_per_thread to use evsel__open_per_cpu_and_thread to make the implementation of those functions clearer. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 23 +++++++++++++++++++---- tools/perf/util/evsel.h | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index af2b26c6456a..ae11df1e7902 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2761,17 +2761,32 @@ void evsel__close(struct evsel *evsel) perf_evsel__free_id(&evsel->core); } =20 -int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu_map_idx) +int evsel__open_per_cpu_and_thread(struct evsel *evsel, + struct perf_cpu_map *cpus, int cpu_map_idx, + struct perf_thread_map *threads) { if (cpu_map_idx =3D=3D -1) - return evsel__open_cpu(evsel, cpus, NULL, 0, perf_cpu_map__nr(cpus)); + return evsel__open_cpu(evsel, cpus, threads, 0, perf_cpu_map__nr(cpus)); =20 - return evsel__open_cpu(evsel, cpus, NULL, cpu_map_idx, cpu_map_idx + 1); + return evsel__open_cpu(evsel, cpus, threads, cpu_map_idx, cpu_map_idx + 1= ); +} + +int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu_map_idx) +{ + struct perf_thread_map *threads =3D thread_map__new_by_tid(-1); + int ret =3D evsel__open_per_cpu_and_thread(evsel, cpus, cpu_map_idx, thre= ads); + + perf_thread_map__put(threads); + return ret; } =20 int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *th= reads) { - return evsel__open(evsel, NULL, threads); + struct perf_cpu_map *cpus =3D perf_cpu_map__new_any_cpu(); + int ret =3D evsel__open_per_cpu_and_thread(evsel, cpus, -1, threads); + + perf_cpu_map__put(cpus); + return ret; } =20 static int perf_evsel__parse_id_sample(const struct evsel *evsel, diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index cefa8e64c0d5..8e79eb6d41b3 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -351,6 +351,9 @@ int evsel__enable(struct evsel *evsel); int evsel__disable(struct evsel *evsel); int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx); =20 +int evsel__open_per_cpu_and_thread(struct evsel *evsel, + struct perf_cpu_map *cpus, int cpu_map_idx, + struct perf_thread_map *threads); int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu_map_idx); int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *th= reads); int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 54CC122E3E9 for ; Sat, 19 Jul 2025 03:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894358; cv=none; b=i296estii6LYhm05tCYy/W0QpxZ8lEDlaaTq2h4PwaWde2sG7mQDNl6Y0Gam4eeWyLrDr+A5yxwZLNYUH4c/af7QsGdEMiwKiDuRj26FNTDRRQD/dpFmD05ls/q47/Vrts0+XeTseSqUoOx2f8pbDkIdxUhclh1w8SeE8f862nM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894358; c=relaxed/simple; bh=KH6S1EVXcp2k9GpaDuxbo9DEpDyEC5StJ9+FpyEM40M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Oa1wQMIdVh0ffbop/fEdpsojTV6yIrCSqp2ZL/6SxAnKS/Z4l6cHudKlbo23JZwZVMwoPAZ9YhgJAgLnOm8cDGCWP6v/cGlj0gN1mesjmCHSTV6zduJtx6/3z39KyEam+JlDqERj8DLGZDo60S/LFQ1KWuH9dZoL2FeRrf2y85s= 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=1KDpJz4d; arc=none smtp.client-ip=209.85.216.74 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="1KDpJz4d" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31332dc2b59so2297100a91.0 for ; Fri, 18 Jul 2025 20:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894356; x=1753499156; 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=EEQY36OrLpdtDDbFz4O1+R1L/HhHBHEcsXBUC9UAOjs=; b=1KDpJz4dk33s5+qeUT8pyPEAPGMJ4Ek+dTnKvK3BUgR9tEjSyguxViTRvCjabQsbCy AP1V/brQAcfTlcSeXcXhW1jOXUg/voacGjZ5sGss+/QRZicVib8dc3TUfG3IYI8JDItZ IkVwex4WbR86U97AfOanqkY4vP8BEiyEYnGd1vprYvl47MFhpf4crKONyNnHyIaSQ4ir 49N3pnad177ED0bvC25iPLNQj8R8bwOhDS1/Td9DvxDeeKTJyzOMzWzZRgJkk7rJBLVh Ci9DI91eq2p6UU1fLUcXnXky7l6WkdQRHFKMcXIDJqcZGhRwaGVOtCljPpyALHaxmf3q VHxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894356; x=1753499156; 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=EEQY36OrLpdtDDbFz4O1+R1L/HhHBHEcsXBUC9UAOjs=; b=t7YLjFNXiai+0AyxEqNMG0LvSGsnGapkNlBGioHnUNzQ2LJsXV2PK8UgxGduUzGPb8 zcUNwYU6rbsnqqbLys1bnfP76MooS2tCeROiTRZgRfq0Vvmxk4rADpeKB2yCdbaB+zQn oNNUQ9M67WQyT+fxHlRfA7h1GcBoSfPCXD24hxpSRmlzWvTRHyiogOkMTalTWDQGueRM R1M0mR2PZhi4P9rBebwFPTB6J3o9ZHkd3x7TIWVorsFZxzCMnJ/JYYwtKxa2LmRMlcUy VzrUWqB46R7aj1xeksRT8S/sLjFEB6s6KjPLtPi2riEYlGW57RkkRl5dEJULZUXrimle Prew== X-Forwarded-Encrypted: i=1; AJvYcCWXEMJZ5gjI+H0hEtUxD6450nlPaN6ohs9mYfC8PIEGa7w4PvLIsUVHz0rLovnhXaqjXSV3OchuLZILuv8=@vger.kernel.org X-Gm-Message-State: AOJu0YzAdhI08EaW8f7ge1RAiAMO0/Uf7ROvf5X4qD00I4K9d+XrrgBR OmGSJ4jLKncsMztceKVk5ynnCAF6ntpplHe1l6R9wo5ptgOuno4BLRohjwS314EZL1qp53Vywej J5UalFiUMJQ== X-Google-Smtp-Source: AGHT+IEjgLpESqb9x5G3AgQikzLLP8Ql1eepMkTRr1oFLDd9jCuc/7CRagtVBm1fNTsvWHcdziXRpggSRHAs X-Received: from pjbsi4.prod.google.com ([2002:a17:90b:5284:b0:311:4aa8:2179]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d8c:b0:316:3972:b9d0 with SMTP id 98e67ed59e1d1-31c9e5fcacfmr20143537a91.0.1752894355693; Fri, 18 Jul 2025 20:05:55 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:14 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-13-irogers@google.com> Subject: [PATCH v3 12/15] perf parse-events: Support user CPUs mixed with threads/processes 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Counting events system-wide with a specified CPU prior to this change worked: ``` $ perf stat -e 'msr/tsc/,msr/tsc,cpu=3Dcpu_core/,msr/tsc,cpu=3Dcpu_atom/' -= a sleep 1 Performance counter stats for 'system wide': 59,393,419,099 msr/tsc/ 33,927,965,927 msr/tsc,cpu=3Dcpu_core/ 25,465,608,044 msr/tsc,cpu=3Dcpu_atom/ ``` However, when counting with process the counts became system wide: ``` $ perf stat -e 'msr/tsc/,msr/tsc,cpu=3Dcpu_core/,msr/tsc,cpu=3Dcpu_atom/' p= erf test -F 10 10.1: Basic parsing test : Ok 10.2: Parsing without PMU name : Ok 10.3: Parsing with PMU name : Ok Performance counter stats for 'perf test -F 10': 59,233,549 msr/tsc/ 59,227,556 msr/tsc,cpu=3Dcpu_core/ 59,224,053 msr/tsc,cpu=3Dcpu_atom/ ``` Make the handling of CPU maps with event parsing clearer. When an event is parsed creating an evsel the cpus should be either the PMU's cpumask or user specified CPUs. Update perf_evlist__propagate_maps so that it doesn't clobber the user specified CPUs. Try to make the behavior clearer, firstly fix up missing cpumasks. Next, perform sanity checks and adjustments from the global evlist CPU requests and for the PMU including simplifying to the "any CPU"(-1) value. Finally remove the event if the cpumask is empty. So that events are opened with a CPU and a thread change stat's create_perf_stat_counter to give both. With the change things are fixed: ``` $ perf stat --no-scale -e 'msr/tsc/,msr/tsc,cpu=3Dcpu_core/,msr/tsc,cpu=3Dc= pu_atom/' perf test -F 10 10.1: Basic parsing test : Ok 10.2: Parsing without PMU name : Ok 10.3: Parsing with PMU name : Ok Performance counter stats for 'perf test -F 10': 63,704,975 msr/tsc/ 47,060,704 msr/tsc,cpu=3Dcpu_core/ (4.6= 2%) 16,640,591 msr/tsc,cpu=3Dcpu_atom/ (2.1= 8%) ``` However, note the "--no-scale" option is used. This is necessary as the running time for the event on the counter isn't the same as the enabled time because the thread doesn't necessarily run on the CPUs specified for the counter. All counter values are scaled with: scaled_value =3D value * time_enabled / time_running and so without --no-scale the scaled_value becomes very large. This problem already exists on hybrid systems for the same reason. Here are 2 runs of the same code with an instructions event that counts the same on both types of core, there is no real multiplexing happening on the event: ``` $ perf stat -e instructions perf test -F 10 ... Performance counter stats for 'perf test -F 10': 87,896,447 cpu_atom/instructions/ (14.37= %) 98,171,964 cpu_core/instructions/ (85.63= %) ... $ perf stat --no-scale -e instructions perf test -F 10 ... Performance counter stats for 'perf test -F 10': 13,069,890 cpu_atom/instructions/ (19.32= %) 83,460,274 cpu_core/instructions/ (80.68= %) ... ``` The scaling has inflated per-PMU instruction counts and the overall count by 2x. To fix this the kernel needs changing when a task+CPU event (or just task event on hybrid) is scheduled out. A fix could be that the state isn't inactive but off for such events, so that time_enabled counts don't accumulate on them. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 119 ++++++++++++++++++++++----------- tools/perf/util/parse-events.c | 10 ++- tools/perf/util/stat.c | 6 +- 3 files changed, 87 insertions(+), 48 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 9d9dec21f510..3ed023f4b190 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -36,49 +36,88 @@ void perf_evlist__init(struct perf_evlist *evlist) static void __perf_evlist__propagate_maps(struct perf_evlist *evlist, struct perf_evsel *evsel) { - if (evsel->system_wide) { - /* System wide: set the cpu map of the evsel to all online CPUs. */ - perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__new_online_cpus(); - } else if (evlist->has_user_cpus && evsel->is_pmu_core) { - /* - * User requested CPUs on a core PMU, ensure the requested CPUs - * are valid by intersecting with those of the PMU. - */ + if (perf_cpu_map__is_empty(evsel->cpus)) { + if (perf_cpu_map__is_empty(evsel->pmu_cpus)) { + /* + * Assume the unset PMU cpus were for a system-wide + * event, like a software or tracepoint. + */ + evsel->pmu_cpus =3D perf_cpu_map__new_online_cpus(); + } + if (evlist->has_user_cpus && !evsel->system_wide) { + /* + * Use the user CPUs unless the evsel is set to be + * system wide, such as the dummy event. + */ + evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); + } else { + /* + * System wide and other modes, assume the cpu map + * should be set to all PMU CPUs. + */ + evsel->cpus =3D perf_cpu_map__get(evsel->pmu_cpus); + } + } + /* + * Avoid "any CPU"(-1) for uncore and PMUs that require a CPU, even if + * requested. + */ + if (evsel->requires_cpu && perf_cpu_map__has_any_cpu(evsel->cpus)) { perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__intersect(evlist->user_requested_cpus, evs= el->pmu_cpus); + evsel->cpus =3D perf_cpu_map__get(evsel->pmu_cpus); + } =20 - /* - * Empty cpu lists would eventually get opened as "any" so remove - * genuinely empty ones before they're opened in the wrong place. - */ - if (perf_cpu_map__is_empty(evsel->cpus)) { - struct perf_evsel *next =3D perf_evlist__next(evlist, evsel); - - perf_evlist__remove(evlist, evsel); - /* Keep idx contiguous */ - if (next) - list_for_each_entry_from(next, &evlist->entries, node) - next->idx--; + /* + * Globally requested CPUs replace user requested unless the evsel is + * set to be system wide. + */ + if (evlist->has_user_cpus && !evsel->system_wide) { + assert(!perf_cpu_map__has_any_cpu(evlist->user_requested_cpus)); + if (!perf_cpu_map__equal(evsel->cpus, evlist->user_requested_cpus)) { + perf_cpu_map__put(evsel->cpus); + evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); } - } else if (!evsel->pmu_cpus || evlist->has_user_cpus || - (!evsel->requires_cpu && perf_cpu_map__has_any_cpu(evlist->user_requeste= d_cpus))) { - /* - * The PMU didn't specify a default cpu map, this isn't a core - * event and the user requested CPUs or the evlist user - * requested CPUs have the "any CPU" (aka dummy) CPU value. In - * which case use the user requested CPUs rather than the PMU - * ones. - */ + } + + /* Ensure cpus only references valid PMU CPUs. */ + if (!perf_cpu_map__has_any_cpu(evsel->cpus) && + !perf_cpu_map__is_subset(evsel->pmu_cpus, evsel->cpus)) { + struct perf_cpu_map *tmp =3D perf_cpu_map__intersect(evsel->pmu_cpus, ev= sel->cpus); + perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); - } else if (evsel->cpus !=3D evsel->pmu_cpus) { - /* - * No user requested cpu map but the PMU cpu map doesn't match - * the evsel's. Reset it back to the PMU cpu map. - */ + evsel->cpus =3D tmp; + } + + /* + * Was event requested on all the PMU's CPUs but the user requested is + * any CPU (-1)? If so switch to using any CPU (-1) to reduce the number + * of events. + */ + if (!evsel->system_wide && + !evsel->requires_cpu && + perf_cpu_map__equal(evsel->cpus, evsel->pmu_cpus) && + perf_cpu_map__has_any_cpu(evlist->user_requested_cpus)) { perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__get(evsel->pmu_cpus); + evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); + } + + /* Sanity check assert before the evsel is potentially removed. */ + assert(!evsel->requires_cpu || !perf_cpu_map__has_any_cpu(evsel->cpus)); + + /* + * Empty cpu lists would eventually get opened as "any" so remove + * genuinely empty ones before they're opened in the wrong place. + */ + if (perf_cpu_map__is_empty(evsel->cpus)) { + struct perf_evsel *next =3D perf_evlist__next(evlist, evsel); + + perf_evlist__remove(evlist, evsel); + /* Keep idx contiguous */ + if (next) + list_for_each_entry_from(next, &evlist->entries, node) + next->idx--; + + return; } =20 if (evsel->system_wide) { @@ -98,6 +137,10 @@ static void perf_evlist__propagate_maps(struct perf_evl= ist *evlist) =20 evlist->needs_map_propagation =3D true; =20 + /* Clear the all_cpus set which will be merged into during propagation. */ + perf_cpu_map__put(evlist->all_cpus); + evlist->all_cpus =3D NULL; + list_for_each_entry_safe(evsel, n, &evlist->entries, node) __perf_evlist__propagate_maps(evlist, evsel); } diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index bd2d831d5123..fe2073c6b549 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -310,20 +310,18 @@ __add_event(struct list_head *list, int *idx, if (pmu) { is_pmu_core =3D pmu->is_core; pmu_cpus =3D perf_cpu_map__get(pmu->cpus); + if (perf_cpu_map__is_empty(pmu_cpus)) + pmu_cpus =3D cpu_map__online(); } else { is_pmu_core =3D (attr->type =3D=3D PERF_TYPE_HARDWARE || attr->type =3D=3D PERF_TYPE_HW_CACHE); pmu_cpus =3D is_pmu_core ? cpu_map__online() : NULL; } =20 - if (has_user_cpus) { + if (has_user_cpus) cpus =3D perf_cpu_map__get(user_cpus); - /* Existing behavior that pmu_cpus matches the given user ones. */ - perf_cpu_map__put(pmu_cpus); - pmu_cpus =3D perf_cpu_map__get(user_cpus); - } else { + else cpus =3D perf_cpu_map__get(pmu_cpus); - } =20 if (init_attr) event_attr_init(attr); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index b0205e99a4c9..50b1a92d16df 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -769,8 +769,6 @@ int create_perf_stat_counter(struct evsel *evsel, attr->enable_on_exec =3D 1; } =20 - if (target__has_cpu(target) && !target__has_per_thread(target)) - return evsel__open_per_cpu(evsel, evsel__cpus(evsel), cpu_map_idx); - - return evsel__open_per_thread(evsel, evsel->core.threads); + return evsel__open_per_cpu_and_thread(evsel, evsel__cpus(evsel), cpu_map_= idx, + evsel->core.threads); } --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 346642139C9 for ; Sat, 19 Jul 2025 03:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894359; cv=none; b=FZ1aaXD366mI84LQIzuJ26GK+rLFSWQnv3RoX0P4gCE0a8V5iSaNlajASlk+sB6uxaC3deCYYGbhBW4/0x2cNt0D5PxpFdzT3vxNO/9Rcl1M4gglxLJxa+XdbVEi8G4pF0p6qUWHfzfpmtiI/laSAd9cMkAcfEI4g/JcKeyZ7o4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894359; c=relaxed/simple; bh=QX1ZFZoy77kXJVY+shs+MAXOEsT89Rxp1CS196e90wA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Yvifo4KbqSfzw9gEi91OD8ZYzFzYnMxe74ZRRxZVjB+gtEX+wpty+xWzCajLUbqB3RN/0tMGI6poLFrtOjOW70a03yl15WUSr0TLPJd3lNFRFOO42gqPPE16rEC8d8CdJX5x/e5MxKUX/jxiwlIaewF1IyP4xPobKk9Ev4ux+20= 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=dVbEUPn8; arc=none smtp.client-ip=209.85.216.74 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="dVbEUPn8" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3122368d82bso3408176a91.0 for ; Fri, 18 Jul 2025 20:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894357; x=1753499157; 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=fsxL8L8W7y9gnvueti74PHIwOUalGfFDynZg+KuuTMM=; b=dVbEUPn8cW1y+B1Zs6pwNL/NrQVdcs2o2+hYDs7zWsprFFrneHZQKnKxI5b5QAc/Ny JwuvV5A1bwo0+TmmKTCrXbYRYuRKbcT8nj6xYiUvCYWpJn6hwUGUeqvC/cMEQpaAq5yi 540Mj66AJSRuxtS2d0Ax+VgpLveTcLOkcNI7WMnlYqu6i/QkNvFqhnGBvYoa4PDBlQKF SIEropqi8LA1tBVAw3jqHPCDqQQALjMMIf8J15wGWonwrYgYqaIDglnyWMgregw9knF5 22XylNN/dAEc0o/C1DdXdKnT/QUepMbG5JA2mymVlRmwFJNNfDme6M/EDI2EVv9Yruhw 8g3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894357; x=1753499157; 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=fsxL8L8W7y9gnvueti74PHIwOUalGfFDynZg+KuuTMM=; b=YgWbicCI2bG0CFZF6quSUVxgbBQhc7N0RngnXLucrykCTVYrdee7R9GL7MYEJTkrk3 wcuCPnw2lIVS3aOhtF2hHar6LwvyOn9pxUKjUfqwAOi5Djlx7sJBE0jCN50+K72CX0mI p8sQPgD+Si9JMAEYCeRfd3qqJIuCOKg8uppMBPn4RVztv+MhZPmg24SbcqcAoMDtpXjJ q6RdTSEltyfp/MhKy18FjalODWhbqsS9SGKx1YdPS02UQkG4aZrxlcxUi6OhroMidjsx aE590TMBshSbeDDFvr1nvttbNVXZOYBCkoWk5c+QxpOATxTE35YVlcD3k8yoNe41RTwY QaFQ== X-Forwarded-Encrypted: i=1; AJvYcCV//N+liQaQCqqHDMw6XmHfzWrWqZWBjY7rhrdUKgCcAh5jKpSTrV6QKLHrh32H7ONQdzXm8lFnBjYZweg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz457Bi4r4H7trQDNhyAbDaasZYuqfv9mnL8blToueLFLMtKQn2 hdxdAiMnAw53NAYahbYWFQ5N08i3ihwCu1dakf/92R/RESuIBiwozTMK7YoAFZdAW1sltuTBMFM vQztzITYLMA== X-Google-Smtp-Source: AGHT+IGb8aCsnBZ7OL/AttuP80279VXoqk9vMo41Oz3GuEun0Q8Ghgt7v5m0wHiqWt+NLJm3ykTL51XIhEVe X-Received: from pjbpm18.prod.google.com ([2002:a17:90b:3c52:b0:314:626:7b97]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:270b:b0:311:ab20:159a with SMTP id 98e67ed59e1d1-31c9f47ce74mr17738254a91.29.1752894357573; Fri, 18 Jul 2025 20:05:57 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:15 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-14-irogers@google.com> Subject: [PATCH v3 13/15] perf topdown: Use attribute to see an event is a topdown metic or slots 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The string comparisons were overly broad and could fire for the incorrect PMU and events. Switch to using the config in the attribute then add a perf test to confirm the attribute config values match those of parsed events of that name and don't match others. This exposed matches for slots events that shouldn't have matched as the slots fixed counter event, such as topdown.slots_p. Fixes: fbc798316bef ("perf x86/topdown: Refine helper arch_is_topdown_metri= cs()") Signed-off-by: Ian Rogers --- v2: In test rename topdown_pmu to p_core_pmu for clarity. --- tools/perf/arch/x86/include/arch-tests.h | 4 ++ tools/perf/arch/x86/tests/Build | 1 + tools/perf/arch/x86/tests/arch-tests.c | 1 + tools/perf/arch/x86/tests/topdown.c | 76 ++++++++++++++++++++++++ tools/perf/arch/x86/util/evsel.c | 46 ++++---------- tools/perf/arch/x86/util/topdown.c | 31 ++++------ tools/perf/arch/x86/util/topdown.h | 4 ++ 7 files changed, 108 insertions(+), 55 deletions(-) create mode 100644 tools/perf/arch/x86/tests/topdown.c diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86= /include/arch-tests.h index 4fd425157d7d..8713e9122d4c 100644 --- a/tools/perf/arch/x86/include/arch-tests.h +++ b/tools/perf/arch/x86/include/arch-tests.h @@ -2,6 +2,8 @@ #ifndef ARCH_TESTS_H #define ARCH_TESTS_H =20 +#include "tests/tests.h" + struct test_suite; =20 /* Tests */ @@ -17,6 +19,8 @@ int test__amd_ibs_via_core_pmu(struct test_suite *test, i= nt subtest); int test__amd_ibs_period(struct test_suite *test, int subtest); int test__hybrid(struct test_suite *test, int subtest); =20 +DECLARE_SUITE(x86_topdown); + extern struct test_suite *arch_tests[]; =20 #endif diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Bu= ild index 01d5527f38c7..311b6b53d3d8 100644 --- a/tools/perf/arch/x86/tests/Build +++ b/tools/perf/arch/x86/tests/Build @@ -11,6 +11,7 @@ endif perf-test-$(CONFIG_X86_64) +=3D bp-modify.o perf-test-y +=3D amd-ibs-via-core-pmu.o perf-test-y +=3D amd-ibs-period.o +perf-test-y +=3D topdown.o =20 ifdef SHELLCHECK SHELL_TESTS :=3D gen-insn-x86-dat.sh diff --git a/tools/perf/arch/x86/tests/arch-tests.c b/tools/perf/arch/x86/t= ests/arch-tests.c index bfee2432515b..29ec1861ccef 100644 --- a/tools/perf/arch/x86/tests/arch-tests.c +++ b/tools/perf/arch/x86/tests/arch-tests.c @@ -53,5 +53,6 @@ struct test_suite *arch_tests[] =3D { &suite__amd_ibs_via_core_pmu, &suite__amd_ibs_period, &suite__hybrid, + &suite__x86_topdown, NULL, }; diff --git a/tools/perf/arch/x86/tests/topdown.c b/tools/perf/arch/x86/test= s/topdown.c new file mode 100644 index 000000000000..8d0ea7a4bbc1 --- /dev/null +++ b/tools/perf/arch/x86/tests/topdown.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "arch-tests.h" +#include "../util/topdown.h" +#include "evlist.h" +#include "parse-events.h" +#include "pmu.h" +#include "pmus.h" + +static int event_cb(void *state, struct pmu_event_info *info) +{ + char buf[256]; + struct parse_events_error parse_err; + int *ret =3D state, err; + struct evlist *evlist =3D evlist__new(); + struct evsel *evsel; + + if (!evlist) + return -ENOMEM; + + parse_events_error__init(&parse_err); + snprintf(buf, sizeof(buf), "%s/%s/", info->pmu->name, info->name); + err =3D parse_events(evlist, buf, &parse_err); + if (err) { + parse_events_error__print(&parse_err, buf); + *ret =3D TEST_FAIL; + } + parse_events_error__exit(&parse_err); + evlist__for_each_entry(evlist, evsel) { + bool fail =3D false; + bool p_core_pmu =3D evsel->pmu->type =3D=3D PERF_TYPE_RAW; + const char *name =3D evsel__name(evsel); + + if (strcasestr(name, "uops_retired.slots") || + strcasestr(name, "topdown.backend_bound_slots") || + strcasestr(name, "topdown.br_mispredict_slots") || + strcasestr(name, "topdown.memory_bound_slots") || + strcasestr(name, "topdown.bad_spec_slots") || + strcasestr(name, "topdown.slots_p")) { + if (arch_is_topdown_slots(evsel) || arch_is_topdown_metrics(evsel)) + fail =3D true; + } else if (strcasestr(name, "slots")) { + if (arch_is_topdown_slots(evsel) !=3D p_core_pmu || + arch_is_topdown_metrics(evsel)) + fail =3D true; + } else if (strcasestr(name, "topdown")) { + if (arch_is_topdown_slots(evsel) || + arch_is_topdown_metrics(evsel) !=3D p_core_pmu) + fail =3D true; + } else if (arch_is_topdown_slots(evsel) || arch_is_topdown_metrics(evsel= )) { + fail =3D true; + } + if (fail) { + pr_debug("Broken topdown information for '%s'\n", evsel__name(evsel)); + *ret =3D TEST_FAIL; + } + } + evlist__delete(evlist); + return 0; +} + +static int test__x86_topdown(struct test_suite *test __maybe_unused, int s= ubtest __maybe_unused) +{ + int ret =3D TEST_OK; + struct perf_pmu *pmu =3D NULL; + + if (!topdown_sys_has_perf_metrics()) + return TEST_OK; + + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + if (perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=3D*/false, &ret,= event_cb)) + break; + } + return ret; +} + +DEFINE_SUITE("x86 topdown", x86_topdown); diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 3dd29ba2c23b..9bc80fff3aa0 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -23,47 +23,25 @@ void arch_evsel__set_sample_weight(struct evsel *evsel) bool evsel__sys_has_perf_metrics(const struct evsel *evsel) { struct perf_pmu *pmu; - u32 type =3D evsel->core.attr.type; =20 - /* - * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU - * on a non-hybrid machine, "cpu_core" PMU on a hybrid machine. - * The slots event is only available for the core PMU, which - * supports the perf metrics feature. - * Checking both the PERF_TYPE_RAW type and the slots event - * should be good enough to detect the perf metrics feature. - */ -again: - switch (type) { - case PERF_TYPE_HARDWARE: - case PERF_TYPE_HW_CACHE: - type =3D evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; - if (type) - goto again; - break; - case PERF_TYPE_RAW: - break; - default: + if (!topdown_sys_has_perf_metrics()) return false; - } - - pmu =3D evsel->pmu; - if (pmu && perf_pmu__is_fake(pmu)) - pmu =3D NULL; =20 - if (!pmu) { - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { - if (pmu->type =3D=3D PERF_TYPE_RAW) - break; - } - } - return pmu && perf_pmu__have_event(pmu, "slots"); + /* + * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU on a + * non-hybrid machine, "cpu_core" PMU on a hybrid machine. The + * topdown_sys_has_perf_metrics checks the slots event is only available + * for the core PMU, which supports the perf metrics feature. Checking + * both the PERF_TYPE_RAW type and the slots event should be good enough + * to detect the perf metrics feature. + */ + pmu =3D evsel__find_pmu(evsel); + return pmu && pmu->type =3D=3D PERF_TYPE_RAW; } =20 bool arch_evsel__must_be_in_group(const struct evsel *evsel) { - if (!evsel__sys_has_perf_metrics(evsel) || !evsel->name || - strcasestr(evsel->name, "uops_retired.slots")) + if (!evsel__sys_has_perf_metrics(evsel)) return false; =20 return arch_is_topdown_metrics(evsel) || arch_is_topdown_slots(evsel); diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/= topdown.c index d1c654839049..66b231fbf52e 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -1,6 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#include "api/fs/fs.h" -#include "util/evsel.h" #include "util/evlist.h" #include "util/pmu.h" #include "util/pmus.h" @@ -8,6 +6,9 @@ #include "topdown.h" #include "evsel.h" =20 +// cmask=3D0, inv=3D0, pc=3D0, edge=3D0, umask=3D4, event=3D0 +#define TOPDOWN_SLOTS 0x0400 + /* Check whether there is a PMU which supports the perf metrics. */ bool topdown_sys_has_perf_metrics(void) { @@ -32,31 +33,19 @@ bool topdown_sys_has_perf_metrics(void) return has_perf_metrics; } =20 -#define TOPDOWN_SLOTS 0x0400 bool arch_is_topdown_slots(const struct evsel *evsel) { - if (evsel->core.attr.config =3D=3D TOPDOWN_SLOTS) - return true; - - return false; + return evsel->core.attr.type =3D=3D PERF_TYPE_RAW && + evsel->core.attr.config =3D=3D TOPDOWN_SLOTS && + evsel->core.attr.config1 =3D=3D 0; } =20 bool arch_is_topdown_metrics(const struct evsel *evsel) { - int config =3D evsel->core.attr.config; - const char *name_from_config; - struct perf_pmu *pmu; - - /* All topdown events have an event code of 0. */ - if ((config & 0xFF) !=3D 0) - return false; - - pmu =3D evsel__find_pmu(evsel); - if (!pmu || !pmu->is_core) - return false; - - name_from_config =3D perf_pmu__name_from_config(pmu, config); - return name_from_config && strcasestr(name_from_config, "topdown"); + // cmask=3D0, inv=3D0, pc=3D0, edge=3D0, umask=3D0x80-0x87, event=3D0 + return evsel->core.attr.type =3D=3D PERF_TYPE_RAW && + (evsel->core.attr.config & 0xFFFFF8FF) =3D=3D 0x8000 && + evsel->core.attr.config1 =3D=3D 0; } =20 /* diff --git a/tools/perf/arch/x86/util/topdown.h b/tools/perf/arch/x86/util/= topdown.h index 1bae9b1822d7..2349536cf882 100644 --- a/tools/perf/arch/x86/util/topdown.h +++ b/tools/perf/arch/x86/util/topdown.h @@ -2,6 +2,10 @@ #ifndef _TOPDOWN_H #define _TOPDOWN_H 1 =20 +#include + +struct evsel; + bool topdown_sys_has_perf_metrics(void); bool arch_is_topdown_slots(const struct evsel *evsel); bool arch_is_topdown_metrics(const struct evsel *evsel); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 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 23EEF230274 for ; Sat, 19 Jul 2025 03:06:00 +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=1752894361; cv=none; b=pnoKvbV4Iwg5E8G6RXsTlk7rGZeh2jhouBe07mmPsJUIl6ZfvKGMhekkRlHnnTXUWQTyDEHFsro5meXNEtfyYL2e2faR81O1XUQtx8y1K1i1V6/dQVTK7L+nkxHfZVqc2qdeTaGkSieGLdZnV7sNIggo32m9GkhNgZQ7t1G8jGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894361; c=relaxed/simple; bh=gnUVsnOcV/XtpgO/L2imjrh4swAc/StdCtllv4r2d8E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Dqxkfy2/FP4MAjkdi8XY4qIL+lupAC6qlM0a2VeH+B1TLyCMkG1VkhrQ8WGQjkCoKrolF5b7Isxd0ygfvA24W6bx9UyiM9kBtBPO933xhYKRq3e0PnKXojAL3g/GoaOPWCrgnnYeQgPjEea89KP3sr+vxZBZ6iAdC7WnppibX9o= 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=NSqgKl1m; 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="NSqgKl1m" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-74b4d2f67d5so2387788b3a.3 for ; Fri, 18 Jul 2025 20:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894359; x=1753499159; 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=nmgRc//yvu8C/2TPTG7gdgWNTTZ5mY9hqNAERparZN8=; b=NSqgKl1mGVNlT2kIuAiTy9OhB3bZq7Sqct8Vnqoq4uiablBFgW99WdrO0deCOcLuLq KML1HC6TGohOSoFfi7hxPmEP+2O4nPMmlxzmQTa0fjLDlSwTtHMmNsWokViK9QQsEjI8 wAXICrEKo1DxL4qbyhTpSgnkcZokeZTzb1wMyX24DANkycRDV9ag9LVVJjXDMTRmhVQl QNnmNHefHFfAv7umNFGkrUcIifUMaGirQ0wh0K8uo9jaGDhweNXmj8GrqpAmBRBWRq2Q D6URjIzFws2fPUROIcSJuxgL9nNeb8LS87yIN3EXXLyJlJpanZYWEwnqpy6/XbILaKgE YuDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894359; x=1753499159; 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=nmgRc//yvu8C/2TPTG7gdgWNTTZ5mY9hqNAERparZN8=; b=CycSwIsyqydidfGcjfZm3xD/Oim0HanPfDzH77ALDlDJZgsxRrhBOK+HGJ6mKHmKho JUGvsBTWjdwEtZupM43gBL0H/2CVHRrG1a61UrgcB/YJOFD6KczytVRQBfNVClpTOJYa IRcNPUli2i66s9f6qKvOdRJAPxGA0DGJSfpfzghf5qdqRyDkyM7k2+5tfX/kKcngJTRc pIprq+3YBDTxl+U+KJ5Ys6XtfvgeHEe8PhJJoyUoTYSNdVazAECUwYWnHvXbDLHmG5WD gUvW3UtmhfIfcdOt9PLiWF8IDwgQ9zz3u2rs1oUfrjRzQslIh6ksAqqmRNm3yCvRtQ27 zaFA== X-Forwarded-Encrypted: i=1; AJvYcCVrJ92JImxP6arINpbqEObjiy0chFMgSjwm9DD03K/2Qmfbv8HYuubJPyI707Xb5CdVcppupcOH4pXrVlQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzAiIB/s2dOzXpwmbN9RFVOkoy3EGO7ZLLFV0+inCUgy8m5cV2X UVmzgZ+hcsTVeGFMzwd19ibyEoo4KOcQruR403HHWTBHPT/l9hmN1fai/MVSFapL4Yu9p+gVf1/ VH5ODpW7d1Q== X-Google-Smtp-Source: AGHT+IG4YDUB4lx+V+i8TajjW6vMqT0pjd6tqiud9nGrVufXkeQRNx06qqxAraYwENxoI7aztNJ+KmaqZCxN X-Received: from pfbdh2.prod.google.com ([2002:a05:6a00:4782:b0:746:fd4c:1fcf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3e23:b0:748:e150:ac5c with SMTP id d2e1a72fcca58-759ae1e7120mr7877546b3a.23.1752894359467; Fri, 18 Jul 2025 20:05:59 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:16 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-15-irogers@google.com> Subject: [PATCH v3 14/15] perf parse-events: Fix missing slots for Intel topdown metric events 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Topdown metric events require grouping with a slots event. In perf metrics this is currently achieved by metrics adding an unnecessary "0 * tma_info_thread_slots". New TMA metrics trigger optimizations of the metric expression that removes the event and breaks the metric due to the missing but required event. Add a pass immediately before sorting and fixing parsed events, that insert a slots event if one is missing. Update test expectations to match this. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/evlist.c | 24 ++++++++++++++++++++++++ tools/perf/arch/x86/util/topdown.c | 28 ++++++++++++++++++++++++++++ tools/perf/arch/x86/util/topdown.h | 2 ++ tools/perf/tests/parse-events.c | 24 ++++++++++++------------ tools/perf/util/evlist.h | 1 + tools/perf/util/parse-events.c | 10 ++++++++++ 6 files changed, 77 insertions(+), 12 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 1969758cc8c1..75e9d00a1494 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -81,3 +81,27 @@ int arch_evlist__cmp(const struct evsel *lhs, const stru= ct evsel *rhs) /* Default ordering by insertion index. */ return lhs->core.idx - rhs->core.idx; } + +int arch_evlist__add_required_events(struct list_head *list) +{ + struct evsel *pos, *metric_event =3D NULL; + int idx =3D 0; + + if (!topdown_sys_has_perf_metrics()) + return 0; + + list_for_each_entry(pos, list, core.node) { + if (arch_is_topdown_slots(pos)) { + /* Slots event already present, nothing to do. */ + return 0; + } + if (metric_event =3D=3D NULL && arch_is_topdown_metrics(pos)) + metric_event =3D pos; + idx++; + } + if (metric_event =3D=3D NULL) { + /* No topdown metric events, nothing to do. */ + return 0; + } + return topdown_insert_slots_event(list, idx + 1, metric_event); +} diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/= topdown.c index 66b231fbf52e..0d01b662627a 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -77,3 +77,31 @@ bool arch_topdown_sample_read(struct evsel *leader) =20 return false; } + +/* + * Make a copy of the topdown metric event metric_event with the given ind= ex but + * change its configuration to be a topdown slots event. Copying from + * metric_event ensures modifiers are the same. + */ +int topdown_insert_slots_event(struct list_head *list, int idx, struct evs= el *metric_event) +{ + struct evsel *evsel =3D evsel__new_idx(&metric_event->core.attr, idx); + + if (!evsel) + return -ENOMEM; + + evsel->core.attr.config =3D TOPDOWN_SLOTS; + evsel->core.cpus =3D perf_cpu_map__get(metric_event->core.cpus); + evsel->core.pmu_cpus =3D perf_cpu_map__get(metric_event->core.pmu_cpus); + evsel->core.is_pmu_core =3D true; + evsel->pmu =3D metric_event->pmu; + evsel->name =3D strdup("slots"); + evsel->precise_max =3D metric_event->precise_max; + evsel->sample_read =3D metric_event->sample_read; + evsel->weak_group =3D metric_event->weak_group; + evsel->bpf_counter =3D metric_event->bpf_counter; + evsel->retire_lat =3D metric_event->retire_lat; + evsel__set_leader(evsel, evsel__leader(metric_event)); + list_add_tail(&evsel->core.node, list); + return 0; +} diff --git a/tools/perf/arch/x86/util/topdown.h b/tools/perf/arch/x86/util/= topdown.h index 2349536cf882..69035565e649 100644 --- a/tools/perf/arch/x86/util/topdown.h +++ b/tools/perf/arch/x86/util/topdown.h @@ -5,9 +5,11 @@ #include =20 struct evsel; +struct list_head; =20 bool topdown_sys_has_perf_metrics(void); bool arch_is_topdown_slots(const struct evsel *evsel); bool arch_is_topdown_metrics(const struct evsel *evsel); +int topdown_insert_slots_event(struct list_head *list, int idx, struct evs= el *metric_event); =20 #endif diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 5ec2e5607987..bb8004397650 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -719,20 +719,20 @@ static int test__checkevent_pmu_partial_time_callgrap= h(struct evlist *evlist) =20 static int test__checkevent_pmu_events(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); + struct evsel *evsel; =20 - TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW =3D=3D evsel->core.attr.type = || - strcmp(evsel->pmu->name, "cpu")); - TEST_ASSERT_VAL("wrong exclude_user", - !evsel->core.attr.exclude_user); - TEST_ASSERT_VAL("wrong exclude_kernel", - evsel->core.attr.exclude_kernel); - TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); - TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); - TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive); + TEST_ASSERT_VAL("wrong number of entries", 1 <=3D evlist->core.nr_entries= ); =20 + evlist__for_each_entry(evlist, evsel) { + TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW =3D=3D evsel->core.attr.type= || + strcmp(evsel->pmu->name, "cpu")); + TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); + TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); + TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); + TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); + TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive); + } return TEST_OK; } =20 diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index fac1a01ba13f..1472d2179be1 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -111,6 +111,7 @@ void evlist__add(struct evlist *evlist, struct evsel *e= ntry); void evlist__remove(struct evlist *evlist, struct evsel *evsel); =20 int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs); +int arch_evlist__add_required_events(struct list_head *list); =20 int evlist__add_dummy(struct evlist *evlist); struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wid= e); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index fe2073c6b549..01fa8c80998b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2190,6 +2190,11 @@ static int evlist__cmp(void *_fg_idx, const struct l= ist_head *l, const struct li return arch_evlist__cmp(lhs, rhs); } =20 +int __weak arch_evlist__add_required_events(struct list_head *list __alway= s_unused) +{ + return 0; +} + static int parse_events__sort_events_and_fix_groups(struct list_head *list) { int idx =3D 0, force_grouped_idx =3D -1; @@ -2201,6 +2206,11 @@ static int parse_events__sort_events_and_fix_groups(= struct list_head *list) struct evsel *force_grouped_leader =3D NULL; bool last_event_was_forced_leader =3D false; =20 + /* On x86 topdown metrics events require a slots event. */ + ret =3D arch_evlist__add_required_events(list); + if (ret) + return ret; + /* * Compute index to insert ungrouped events at. Place them where the * first ungrouped event appears. --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 15:15:53 2025 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (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 1D01023313E for ; Sat, 19 Jul 2025 03:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894364; cv=none; b=X8/LC7/HXjEgs/AyauL6kxlSLOGMVEtoJ6ytUlrU1yH/nCZWIiTiBR6ModS0WJdIrFyCjAOHVwpsc6q6soGySkDeUK2sEFvIZgcDoOyGaG1H+GbfwNvMMUgSzofIS+fKdd9ATlgt2ZDAFh+U62VfBEcwGI6Dw/6kZSzDlaSblAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752894364; c=relaxed/simple; bh=DANcYFjWFog65lA2TzZsCGmS77SSjwfSoaVllkCywbg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZOf+CP0bZazMIrqdSd0E4W0hOJkKm8J2G8RO+5Ta+6o3c7kzs+5buaiYQ9GG1DAUcTieYVpI9owx9CYGPSAgCBaN7ZcrVi9QEMSdNRrHwqHqCZYNJBHPh3s4EGzhnivdyK5emJ7msym47gMFK4FhhJEse6xME9e9P+83bPYEoEk= 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=yYCQ1zNJ; arc=none smtp.client-ip=209.85.160.74 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="yYCQ1zNJ" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2f3b9f042a6so2734765fac.3 for ; Fri, 18 Jul 2025 20:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752894361; x=1753499161; 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=87ygbU8b8rNXhdTHrIi6W+OHuxcL4xxMWjwjqIk1tDg=; b=yYCQ1zNJJn62ZjijvzW0htn1cPOve7/0R39uDMGm4al7JKbcwvWBgs1WeCZWWltWzA qZUQE8f7/jt8YhJ9Vw3CcIdLc9vH7vGGwYf7WNygoGR7pkY7/Se4ABmOyfD07872MzpN /rDuD0DBdrlKXULBA/hLLnt4SZ5qrVPIEcc9tQaM0KK/v1P7iBYHpmRdg04/eA7oz+oG 70j/L/Ebm+bY+TXoSOc8df2hiVeJV8nM2GrVyDgBX/05bEVz0E4QxKYvc8oA8iPYWQJK 6wknfjxuq4WJWxr1SodQV1250fpE5+aZBRpO9qu1QQD+TuvDYckmkX5FFKFm33BRoT+W I8iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752894361; x=1753499161; 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=87ygbU8b8rNXhdTHrIi6W+OHuxcL4xxMWjwjqIk1tDg=; b=tzKDX7Isa98l7OOG5o+dZnymON+TbgK7E0pBIXp5bLsVCViTwyUhjaOHDTXf8kAJpL 7jnjoYaJbLu39QcKvVncVNN6bZktVB7i9HwrxP8902moptTt8qLPZ6cG2EbinHsCVWJN rY7V1u9SJJ9Vx2c5aNJtAjWi3OTWa1+0Vai7jO7V81804WSNfu6epRchuTtblDCqSa2D R3qoynOUm7u3UulPuJuhy+bqMzwb8w0hl2iwwiwPGd2nRVNrfMnJcm59uKIIcjGHIAVJ feKcIHlqr4TUVTjM71na7UPHT2VfvbNWCvFD133jVQtxjjJdXLanFDYYeTu9gA6nzTb5 xfZA== X-Forwarded-Encrypted: i=1; AJvYcCWH+TqAb44zA1LYk66aE1p8RzmKkgjBewnNXul7J1fhsmGWvlH2jRNDVTHxVd1M2kezkblEAqn6y2qKos0=@vger.kernel.org X-Gm-Message-State: AOJu0Yyfz50GAxIQo1lJHlBzB5zYhl/RswUJYUJRNf3Vdkg36clkcR+Z aDoP4pgOVEiq5+UhCkNDew8Lu4t2XN1WRVsVUT2/8JixUB9mCKjE/n3ox8V+e/9WGWX+Y3EiV5H 22xm9AhsPdw== X-Google-Smtp-Source: AGHT+IF1zn1v8hKOs29XSjJpG0BiScmrrZ3QjOazEkYYMiDIpN9PpZyK6FC/Hrsm7Uo2yRHmvvdrcHmf9GW3 X-Received: from oabrc11.prod.google.com ([2002:a05:6871:61cb:b0:2ff:9f42:9536]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:c995:b0:2cc:3523:9cd5 with SMTP id 586e51a60fabf-2ffb22a045amr9659853fac.17.1752894361378; Fri, 18 Jul 2025 20:06:01 -0700 (PDT) Date: Fri, 18 Jul 2025 20:05:17 -0700 In-Reply-To: <20250719030517.1990983-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: <20250719030517.1990983-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250719030517.1990983-16-irogers@google.com> Subject: [PATCH v3 15/15] perf metricgroups: Add NO_THRESHOLD_AND_NMI constraint 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 , "Liang, Kan" , Ravi Bangoria , James Clark , Dapeng Mi , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Thresholds can increase the number of counters a metric needs. The NMI watchdog can take away a counter (hopefully the buddy watchdog will become the default and this will no longer be true). Add a new constraint for the case that a metric and its thresholds would fit in counters but only if the NMI watchdog isn't enabled. Either the threshold or the NMI watchdog should be disabled to make the metric fit. Wire this up into the metric__group_events logic. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 1 + tools/perf/pmu-events/pmu-events.h | 14 ++++++++++---- tools/perf/util/metricgroup.c | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index e821155151ec..0abd3cfb15ea 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -235,6 +235,7 @@ class JsonEvent: 'NO_GROUP_EVENTS_NMI': '2', 'NO_NMI_WATCHDOG': '2', 'NO_GROUP_EVENTS_SMT': '3', + 'NO_THRESHOLD_AND_NMI': '4', } return metric_constraint_to_enum[metric_constraint] =20 diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu= -events.h index a523936846e0..ea022ea55087 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -25,15 +25,21 @@ enum metric_event_groups { */ MetricNoGroupEvents =3D 1, /** - * @MetricNoGroupEventsNmi: Don't group events for the metric if the NMI - * watchdog is enabled. + * @MetricNoGroupEventsNmi: + * Don't group events for the metric if the NMI watchdog is enabled. */ MetricNoGroupEventsNmi =3D 2, /** - * @MetricNoGroupEventsSmt: Don't group events for the metric if SMT is - * enabled. + * @MetricNoGroupEventsSmt: + * Don't group events for the metric if SMT is enabled. */ MetricNoGroupEventsSmt =3D 3, + /** + * @MetricNoGroupEventsThresholdAndNmi: + * Don't group events for the metric thresholds and if the NMI watchdog + * is enabled. + */ + MetricNoGroupEventsThresholdAndNmi =3D 4, }; /* * Describe each PMU event. Each CPU has a table of PMU events. diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 3cc6c47402bd..595b83142d2c 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -179,7 +179,7 @@ static void metric__watchdog_constraint_hint(const char= *name, bool foot) " echo 1 > /proc/sys/kernel/nmi_watchdog\n"); } =20 -static bool metric__group_events(const struct pmu_metric *pm) +static bool metric__group_events(const struct pmu_metric *pm, bool metric_= no_threshold) { switch (pm->event_grouping) { case MetricNoGroupEvents: @@ -191,6 +191,13 @@ static bool metric__group_events(const struct pmu_metr= ic *pm) return false; case MetricNoGroupEventsSmt: return !smt_on(); + case MetricNoGroupEventsThresholdAndNmi: + if (metric_no_threshold) + return true; + if (!sysctl__nmi_watchdog_enabled()) + return true; + metric__watchdog_constraint_hint(pm->metric_name, /*foot=3D*/false); + return false; case MetricGroupEvents: default: return true; @@ -212,6 +219,7 @@ static void metric__free(struct metric *m) static struct metric *metric__new(const struct pmu_metric *pm, const char *modifier, bool metric_no_group, + bool metric_no_threshold, int runtime, const char *user_requested_cpu_list, bool system_wide) @@ -246,7 +254,7 @@ static struct metric *metric__new(const struct pmu_metr= ic *pm, } m->pctx->sctx.runtime =3D runtime; m->pctx->sctx.system_wide =3D system_wide; - m->group_events =3D !metric_no_group && metric__group_events(pm); + m->group_events =3D !metric_no_group && metric__group_events(pm, metric_n= o_threshold); m->metric_refs =3D NULL; m->evlist =3D NULL; =20 @@ -831,8 +839,8 @@ static int __add_metric(struct list_head *metric_list, * This metric is the root of a tree and may reference other * metrics that are added recursively. */ - root_metric =3D metric__new(pm, modifier, metric_no_group, runtime, - user_requested_cpu_list, system_wide); + root_metric =3D metric__new(pm, modifier, metric_no_group, metric_no_thr= eshold, + runtime, user_requested_cpu_list, system_wide); if (!root_metric) return -ENOMEM; =20 --=20 2.50.0.727.gbf7dc18ff4-goog