From nobody Wed Oct 8 12:36:06 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA8B820A5EA for ; Fri, 27 Jun 2025 19:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052266; cv=none; b=GYIJHMQmX3q5qweCM+E/H/u1grOh2U6lxqlXF2VkERrt8mgHNCGqs6haXmxAwR2A3fp2i3twNzYHrc3m44JuOr1HHis7Q8vteCp/qGVb1/ei0oNoNgJstMxVvBQUbaTQ4NLos95VxhRFogN6H0RQkaIgh1AzRERzfvkLNm2JZKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052266; c=relaxed/simple; bh=5qnWJjXV1yscRGW3Z8MrgpRa/BOaZk2dYgJaEfH4ujE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lOJE719vKxVL58LSYGnaKCMhVSdusobKfNXOLXE6v1InzoGCQjTFTlAowkf6kaYUPUEbdZufpsKfpM8izCohrNHzqtgcIcXar279jA8Ubxbo/+3t4YOmUxU1CVbAEO9fxyFTGbrhHatcCBOoB4oAyY6LsUam8g5hcv1utq9QzJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2nW5UvM2; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2nW5UvM2" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-748b4d5c045so207591b3a.1 for ; Fri, 27 Jun 2025 12:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052264; x=1751657064; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7d6C2lXVAfC01Fe0gAHfj6nm96vm08japImtMus97hs=; b=2nW5UvM26o2eU7jRUFchcAuPKLYBU1ujpWcb1JbmtIkFkB9HQsCXWG0tyyiAB1mOOC oiRH8JQxQ4OPEmq1au9L9Avf4FJ6+TF5+iL2IB5uaJuZD7jUd8UdG8Q0lZ3pSfL1pXke S/O/WrabZvv26+abCiYPYHotAVslOgxdCnwXGWgJ6uVESIhAaBWVCOTh6lui6A1Jl3m4 hzqGnPygc8EmhGiFhee0Db5FCJViimbupNfjSVMCTKaGmj4NxaNyvqx+U94m4l71uYNt 0sWY8lFtTB1FIK0zTVAbfSQj6Mk/vKn4vI+DGppA2ZUTjxDbC6gdZcjsppS+5CFGkrre meZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052264; x=1751657064; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7d6C2lXVAfC01Fe0gAHfj6nm96vm08japImtMus97hs=; b=HwgX31KP7XGadxnoVG4g2yI/Iom27RUGHPTSHWWX4XFGB7BXMZ1YY5U/P7FKlDWT/b FYsAfVAF1MQR8rvujqARoNGox7ixE4EldQ2Gfl0c15ycqZYSXHZswzCRq9qnMRY1yxFK ooaIdsTg30SsukQWVQC0+TdFlZ7lcRP3l4fsYoDRGZz9LVlmjZC3VG3hEC+Z+IAGDPIw ZBkXdOm1rOcrkx7/0LNNjszl6j+jJdRpewzsFl/gQVZWya/qyd2kzCpIuJe98GqsI1gx FLT5AUSy+F+v2bfmXnWpG5Lvks9OBLyuugDqb3flsuzM+7WlGjyoQ7DSsaUm3cSHY2+9 XBGA== X-Forwarded-Encrypted: i=1; AJvYcCXsYttKbEWTwda+Ts+5KtFhaK2fjuj3PekOPTJ6OP4Nnr2hQyoAjRDdor8egAGT6zdOCrshC7A6t67nH5g=@vger.kernel.org X-Gm-Message-State: AOJu0Yxoa4WEf/mDa66YdAXGhBn5QxhZs4Cy6AWpgqHGlyivsaiG3XsO UQt6+Mdww7FxzX8rRoaxS+QWl9ihzxaLTuQ5C/luyjDsHDuUhcZJ4f0S+hUNtKHCfLNfiMj8Cd4 3KZr5liChvw== X-Google-Smtp-Source: AGHT+IGxVVW6Wl9FoYgf65siOYfc6Hro58qDPxO34loRXfOqL/G1tEZu0nJbZPfRW9z4f1g5SNKUncaydpeZ X-Received: from plez10.prod.google.com ([2002:a17:902:ccca:b0:234:aa6d:999d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3bac:b0:236:7165:6ecf with SMTP id d9443c01a7336-23ac465cb20mr71404775ad.38.1751052264186; Fri, 27 Jun 2025 12:24:24 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:06 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-2-irogers@google.com> Subject: [PATCH v1 01/12] perf parse-events: Warn if a cpu term is unsupported by a CPU From: Ian Rogers To: Thomas Falcon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor requested CPU warning out of evlist and into evsel. At the end of adding an event, perform the warning check. To avoid repeatedly testing if the cpu_list is empty, add a local variable. ``` $ perf stat -e cpu_atom/cycles,cpu=3D1/ -a true WARNING: A requested CPU in '1' is not supported by PMU 'cpu_atom' (CPUs 16= -27) for event 'cpu_atom/cycles/' Performance counter stats for 'system wide': cpu_atom/cycles/ 0.000781511 seconds time elapsed ``` Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- tools/perf/util/evlist.c | 15 +-------------- tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++ tools/perf/util/evsel.h | 2 ++ tools/perf/util/parse-events.c | 12 ++++++++---- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 5664ebf6bbc6..a3c4d8558d29 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2546,20 +2546,7 @@ void evlist__warn_user_requested_cpus(struct evlist = *evlist, const char *cpu_lis return; =20 evlist__for_each_entry(evlist, pos) { - struct perf_cpu_map *intersect, *to_test, *online =3D cpu_map__online(); - const struct perf_pmu *pmu =3D evsel__find_pmu(pos); - - to_test =3D pmu && pmu->is_core ? pmu->cpus : online; - intersect =3D perf_cpu_map__intersect(to_test, user_requested_cpus); - if (!perf_cpu_map__equal(intersect, user_requested_cpus)) { - char buf[128]; - - cpu_map__snprint(to_test, buf, sizeof(buf)); - pr_warning("WARNING: A requested CPU in '%s' is not supported by PMU '%= s' (CPUs %s) for event '%s'\n", - cpu_list, pmu ? pmu->name : "cpu", buf, evsel__name(pos)); - } - perf_cpu_map__put(intersect); - perf_cpu_map__put(online); + evsel__warn_user_requested_cpus(pos, user_requested_cpus); } perf_cpu_map__put(user_requested_cpus); } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d55482f094bf..0208d999da24 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -4071,3 +4071,27 @@ void evsel__uniquify_counter(struct evsel *counter) counter->uniquified_name =3D false; } } + +void evsel__warn_user_requested_cpus(struct evsel *evsel, struct perf_cpu_= map *user_requested_cpus) +{ + struct perf_cpu_map *intersect, *online =3D NULL; + const struct perf_pmu *pmu =3D evsel__find_pmu(evsel); + + if (pmu && pmu->is_core) { + intersect =3D perf_cpu_map__intersect(pmu->cpus, user_requested_cpus); + } else { + online =3D cpu_map__online(); + intersect =3D perf_cpu_map__intersect(online, user_requested_cpus); + } + if (!perf_cpu_map__equal(intersect, user_requested_cpus)) { + char buf1[128]; + char buf2[128]; + + cpu_map__snprint(user_requested_cpus, buf1, sizeof(buf1)); + cpu_map__snprint(online ?: pmu->cpus, buf2, sizeof(buf2)); + pr_warning("WARNING: A requested CPU in '%s' is not supported by PMU '%s= ' (CPUs %s) for event '%s'\n", + buf1, pmu ? pmu->name : "cpu", buf2, evsel__name(evsel)); + } + perf_cpu_map__put(intersect); + perf_cpu_map__put(online); +} diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 6dbc9690e0c9..8b5962a1e814 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -572,4 +572,6 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu, s= truct evsel *evsel, =20 bool evsel__is_offcpu_event(struct evsel *evsel); =20 +void evsel__warn_user_requested_cpus(struct evsel *evsel, struct perf_cpu_= map *user_requested_cpus); + #endif /* __PERF_EVSEL_H */ diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index d1965a7b97ed..7a32d5234a64 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -257,6 +257,7 @@ __add_event(struct list_head *list, int *idx, struct evsel *evsel; bool is_pmu_core; struct perf_cpu_map *cpus; + bool has_cpu_list =3D !perf_cpu_map__is_empty(cpu_list); =20 /* * Ensure the first_wildcard_match's PMU matches that of the new event @@ -281,7 +282,7 @@ __add_event(struct list_head *list, int *idx, =20 if (pmu) { is_pmu_core =3D pmu->is_core; - cpus =3D perf_cpu_map__get(perf_cpu_map__is_empty(cpu_list) ? pmu->cpus = : cpu_list); + cpus =3D perf_cpu_map__get(has_cpu_list ? cpu_list : pmu->cpus); perf_pmu__warn_invalid_formats(pmu); if (attr->type =3D=3D PERF_TYPE_RAW || attr->type >=3D PERF_TYPE_MAX) { perf_pmu__warn_invalid_config(pmu, attr->config, name, @@ -296,10 +297,10 @@ __add_event(struct list_head *list, int *idx, } else { is_pmu_core =3D (attr->type =3D=3D PERF_TYPE_HARDWARE || attr->type =3D=3D PERF_TYPE_HW_CACHE); - if (perf_cpu_map__is_empty(cpu_list)) - cpus =3D is_pmu_core ? perf_cpu_map__new_online_cpus() : NULL; - else + if (has_cpu_list) cpus =3D perf_cpu_map__get(cpu_list); + else + cpus =3D is_pmu_core ? cpu_map__online() : NULL; } if (init_attr) event_attr_init(attr); @@ -331,6 +332,9 @@ __add_event(struct list_head *list, int *idx, if (list) list_add_tail(&evsel->core.node, list); =20 + if (has_cpu_list) + evsel__warn_user_requested_cpus(evsel, cpu_list); + return evsel; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:36:06 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 8CDA420E310 for ; Fri, 27 Jun 2025 19:24:26 +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=1751052267; cv=none; b=W40BVRcwpiHFnTNr5pdRtyllkPg79V++ppFR0Wp/qd92Y/mMiQiAtt/7hNBO92hBh0utb/2Z1A1qIhczFLsEuX8zz/azPUhCD0npr0PvAfpqc/RAYRdWIv+gWZ26mJ39iLvGnPbjtasfgOII82H7DdthoptjyPR94fA2SorCOVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052267; c=relaxed/simple; bh=iY7+1w4ffuJmT53JhOUOvGs8aNHT70CLlG9C1dLwHio=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=aeCllLrCashUje8Zd7lf7XAGu8OWblKvuyLGx+9fQKFyRWOgoIvZUhCrYrtJeuI/O9DV96RBY4c5OQD6+Dj3tCn9QE+1Ds2KPBVBW3iCSBF4x65KQFGZJTcjA2j0KcqOLA+l1pmm0zDXqiz9zRgNXztmB0TFIkyBAYhiN+LJNn0= 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=aZIe0wc7; 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="aZIe0wc7" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b34b810fdcaso236265a12.0 for ; Fri, 27 Jun 2025 12:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052266; x=1751657066; 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=4jlp7VVoQZ0r1uOBhIqm+MKIwWsotQYqLXFEbR3D1pU=; b=aZIe0wc7CPfNpauCDGhvM0uXpw9pgABk+jo3fcPclN3PA0Sh9PNX/PPqKe1hts66MC YFL1UrIJGLi1TjZjDYN45ojEwaPwagLHlIq8zq/nvr5YoC7vuVOXUecyJmWT/Rr9bn+b KD2QePndgp6KSJJr5zsWW/fKK9nBEe2wW/eENwLrHIDhzwNpdxWVtEcv/KlEidPr2qlh wWcSUrXkc82kyyPp/m0uM7xXOCbsr4QxPkGdwmgM7tvgKpfs5DnIthjG+4WajKK16x2u 5Q1tlEPFfd3kEtGEJF2KInwU9XA7BzZvwlV6dwOfgPvYR3miG0ZvmfaoOKaABk3wuctM a9Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052266; x=1751657066; 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=4jlp7VVoQZ0r1uOBhIqm+MKIwWsotQYqLXFEbR3D1pU=; b=BDBAlMHfQXCxZMu5rRIinckW/gr/38i0aAj4lWzIsXv3OMjmBIKllAHn8Kc8feG68Z tRb2I5KRV5PsT6pNokxSWGTcunLZAwfk9On0hkeluoYJbKbhT3w9/XF1t6LvMyXDDdqd y5j8P7eMUqa8rHVuRden0mmvEOUcV16Sg0h9O6H8qjzxFruQ6q9OOAzBTWKn44UYkqst YHkKBJmom+8AqKHjgZ+fdPYP0IASuqXpmYdI2q6a8Ficac/E9m5eYJQrOLcY08gX8Gje 7dzlTR2I19C99r9kwdGGqqoMLrjipVcCayvwO71+9BNVU4aw20jWLU8MBAC5slQb+Xhs llNQ== X-Forwarded-Encrypted: i=1; AJvYcCU5govU+3Ib34vlsxhjulaz0jcORvzcRApINbwMmHxgXqXyHGGUjvOkw/VvokOinWP9WvLktsKz423OjRE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywvsg2+SiQ1KS7fw3iPpLxOgo+0Dii78u+PDkoSEzVwQTOXMIN2 nZdhbN2BlhGGVPA2/oYrVzugLB+KKP2t2kmJJ+SQmPXZKrfKa7HHDs6xui2i4x6/FRkx5qhWf9D tAPs9A5rtqg== X-Google-Smtp-Source: AGHT+IHKqQl/ML2/Sm+hnm9pOg2bqes0L29RyOq2eO+4SeKL4TtFginStwz4h+krXnUL/zlqroi8Xw2mxAXH X-Received: from pjv3.prod.google.com ([2002:a17:90b:5643:b0:313:2213:1f54]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d87:b0:312:e9d:3ff2 with SMTP id 98e67ed59e1d1-318c8ec50bamr6593923a91.7.1751052265996; Fri, 27 Jun 2025 12:24:25 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:07 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-3-irogers@google.com> Subject: [PATCH v1 02/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 50fc53adb7e4..803bdcf89c0d 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 Wed Oct 8 12:36:06 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 79103217659 for ; Fri, 27 Jun 2025 19:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052269; cv=none; b=LD0k5YAmWNKte5zgiRoR1U2x0duoK4A3mC/SrDuvT3yBMuYk3PoSOMTbBGPf7T4b73IRgSDYEckw9rzwkHyD03OwR86PZrFmvTz1nTkCjduKCDqcsJbd3TLbm6SnilVFpf5asNQBej4m0kLGHw+HtOQ7dYxkvzibtcspbMaxGmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052269; c=relaxed/simple; bh=8cwlAfASgjDaBAw+Dh0fOpNhqH2F4FYnFY1DzsrvDBs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=E+ii7qM5VYjOPxVjrk4WlogJ+47y2/nix2naLhfNl3x2EUcqYGz7ZVmVt6MJ087guYjnjJ8TytMyKHC1xRKFdxA5T35u8ZPqG0ycF8yv134ENdEkrzcpYbBPiKfAJcIFtALQGY7NlHuLNxNR6pQRHQhWZ93SCpCVo1s41zgIRjc= 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=SXr3wGkW; arc=none smtp.client-ip=209.85.215.202 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="SXr3wGkW" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b2fb347b3e6so2786492a12.1 for ; Fri, 27 Jun 2025 12:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052268; x=1751657068; 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=bHyTiYq3fNklZMY+gxa5ISx5FFJqebiuY8EWbLD3ebA=; b=SXr3wGkW7Ii+aP8kPhBODPq630KwvzwyksAi+9weSWcuixRVZierLi9sj4SGaawgk9 VkxFUcxOseNf2OUdyUTWUoGLzRP9MCagTAuAXEFkdqMANg/OM8+nt6XEkXFafuvNbrS6 McdaRq9Muqi/2ixK9d1pPe/KlxxSu5yK3Xl5DDOujsPiSyuu7EnAbh/z/PHy/+Ww7pUm lYsxlzh1stWKKQHA0a1D6aXD3IjRlNGSxlhEY8pJ3v9dJbp3AcDj2GK2Luz/d++/I/LZ pMRmoX1AzxbVBOY8qpo+WnSy59AUa2k04qYdTOC5v/0Yr154pgvXCt0MC7rFUylIJScS VaKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052268; x=1751657068; 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=bHyTiYq3fNklZMY+gxa5ISx5FFJqebiuY8EWbLD3ebA=; b=NsgcTSfBmKzoVpSZ4vuvbr4MTsGIxexI5oGaw4SoZJ+cmFlRJtLAJyA63vDRVUTiFN TM2mGxXu29VcRhg8OhEUv50zIzUIoDxCad5g8O8m7asc4l0RBLz9kTTc45k0Lq+OVWb7 LDQQWinZpIUpw5VGfw88yU4z1eCuVhX9Zc3JMZ1TtnUMr4H6tzbl9evdFVygNkQqbFuM EAH+pIoalKh3a20waFwBomqqPYLLMFd0vhop2f/0gNsKczzNQDlEvBBW5Q8fCb2hjDxD K1q+jUGKD6nPOe+E3PYAm/U3ZYIPjhiVFKTaNQYqTlJjmWe16YOGZa1HNnPDqnxyMLof +FcQ== X-Forwarded-Encrypted: i=1; AJvYcCWPLa6YGCE6aWwhyLOV3B/TPf8XSI4CkeY+stMYPHFf8ofWdb73PAZBT0urvVholf8dTZH7SgPFAKgj+QI=@vger.kernel.org X-Gm-Message-State: AOJu0YxZzqkOjuAIT3OnudEIONshRoUsGvfUD/+3WAOsm7qwsmwNsxcL QABUnhrWD4vv08zM+YwlCqghbWS73Vxyeos13WReAYGThBXS0oypdp4vll46FmPB7g9T8gJsozD kgl1mdLS10Q== X-Google-Smtp-Source: AGHT+IGTxwiUsCQVubSoLszlIZQZgfIIbhwFOc4KJ1lT0sZ+++wmkWp+9wQn4qXcOje47blqHHETLOxC8xbg X-Received: from plkb7.prod.google.com ([2002:a17:903:fa7:b0:234:c2e4:1df6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:19e8:b0:238:120:134a with SMTP id d9443c01a7336-23ac45c1d67mr84881305ad.22.1751052267794; Fri, 27 Jun 2025 12:24:27 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:08 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-4-irogers@google.com> Subject: [PATCH v1 03/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 803bdcf89c0d..ff726f3e42ea 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 Wed Oct 8 12:36:06 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 41C2E20A5DD for ; Fri, 27 Jun 2025 19:24:30 +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=1751052271; cv=none; b=RZQY7BS5L5Ea5aKO+1keA6i6YXnPI+Ar21/rkKORMZ1pUp9ys7BnNfAxL15LpdoJfyfnWfB1aFkAbK+bx3r2qnh8Y7oBegV9ZKIkZlgl79wc+V+VK/JY3jQZupL+6XRAdublnum2cCobvUEyZlV+/z0QU/iZGTNLRZueaUkJtpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052271; c=relaxed/simple; bh=dVViqCmusnN5RUFVuc4ZulRAN9goYmkUJllZ6fYirJk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=piWz7MLje+RaHIYxgljn7oX/Gvlm+6FMCO2l0J9RNYlvSakDJmM3BFkdKMSHIx0sm12crYG0x+KwdlTgFr0Ip0lGaM03K7ehD9KBgqZoxHUV/fwm9g+6Gz9nurVRzoEGsF3Vjrbm0i2vEZe8j/hb1pYd/YjQNxTbwnQRy9D7uVA= 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=mgld8tfy; 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="mgld8tfy" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2ef38fe89d9so1530333fac.3 for ; Fri, 27 Jun 2025 12:24:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052269; x=1751657069; 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=9nV5bVvayoyTyNMPh50De+OAEo7DL4+9cdaEzSi+im0=; b=mgld8tfyvOg1uGjED4mzwWuu9eFV7L/ct+qqdg1Ahy8IAD+TumNhHAk/MTYM8eDql6 +zW+0CVWlQljv2putpqjsg1b5X8aX0FAZx9ZvKzXEBvmskc8q/aDG2ca9V9oe9b6wvOB vuAOHepZ0esUAQzOheV+TET45rK2g1c1TrCbJIw8k+EFi9XkynHp4eN0eHyc/qV8jEck 51qw/wjx2ppz9ZXaWfUuT/k8xC3slbkBLRWsuFFRyi/4t165XP+AerTDt5gapvIZFvIQ duZnheKFeTbNzoQIOKQuViv743fDIJXlrFrELeajGn24qiDkKXbXmBUtLi4wR+x+0+dm FCBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052269; x=1751657069; 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=9nV5bVvayoyTyNMPh50De+OAEo7DL4+9cdaEzSi+im0=; b=euqnOrHbY136PYrHitzE3tmiCcPqYl+Ca3SWoQbSLE5nVXkHFQou7GL1T3s9bHVh+t 6cgKmOLzl/Aa6NGJtTkadymNQ7TCPt8TOXDpXq7gnd/6apN8IZ7x7SJtrMulosdheQ+E m7PmiWBo8LqQHJPS0aAcilvXDEevUkahnLmzm4npHy5TS05X5aassOSgsVPwfVOu/InB 2MiVs4bXJmKrzhZwoz7D2a4W+yveEctRJwKyWA+69hU8Ah1HSdTuqFPgsEYDDJGVGlgo yEkBZ6QyQOVC1CXibIGqMb9Hy89tre9NMqq9OCs1MCkMvyfAa4za4NwXs1xGos5WtKq/ wfKg== X-Forwarded-Encrypted: i=1; AJvYcCUQqxFVn5Cj3yRftouVBP3kQNeezsHqBaphJw3X5VWiEvyxOqooDNm4YwSPEUjnju1ndWJGJfBCiR8a4Tw=@vger.kernel.org X-Gm-Message-State: AOJu0YyshZh+TXJessa61C4Ed3759u2szoGznng8Q3hFQwkDwOQexUKW IQsmDmnjhf3arOFhooimToWJP+qHCFwGPFv1OB4wXl+wRSnT0HHHdxw5YrVNLLYfTmXNHXLYO60 zbD6S6JZpbw== X-Google-Smtp-Source: AGHT+IFNCUxEUiyLdVvcT9lNT2EQpgKf5ie5NGJ4wgyjmV1TUh8aP4lQE4E6/WPuYgaTNMQG/UaaM/LTBCSK X-Received: from oabqp4.prod.google.com ([2002:a05:6870:ff84:b0:2b8:4b50:daff]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:4e44:b0:29e:559b:d694 with SMTP id 586e51a60fabf-2efed7297f5mr3001891fac.32.1751052269450; Fri, 27 Jun 2025 12:24:29 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:09 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-5-irogers@google.com> Subject: [PATCH v1 04/12] perf parse-events: Allow the cpu term to be a 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 ``` Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- tools/perf/util/parse-events.c | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 7a32d5234a64..ef38eb082342 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -192,10 +192,20 @@ 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); + struct perf_cpu_map *term_cpus; =20 - perf_cpu_map__merge(&cpus, cpu); - perf_cpu_map__put(cpu); + 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 (perf_cpu_map__is_empty(pmu->cpus)) + term_cpus =3D pmu->is_core ? cpu_map__online() : NULL; + else + term_cpus =3D perf_cpu_map__get(pmu->cpus); + } + perf_cpu_map__merge(&cpus, term_cpus); + perf_cpu_map__put(term_cpus); } } =20 @@ -1054,12 +1064,21 @@ do { \ } break; case PARSE_EVENTS__TERM_TYPE_CPU: - CHECK_TYPE_VAL(NUM); - if (term->val.num >=3D (u64)cpu__max_present_cpu().cpu) { - parse_events_error__handle(err, term->err_val, - strdup("too big"), - NULL); - return -EINVAL; + 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; + } + } else { + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR); + if (perf_pmus__find(term->val.str) =3D=3D NULL) { + parse_events_error__handle(err, term->err_val, + strdup("not a valid PMU"), + /*help=3D*/NULL); + return -EINVAL; + } } break; case PARSE_EVENTS__TERM_TYPE_DRV_CFG: --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:36:07 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 1308B20C000 for ; Fri, 27 Jun 2025 19:24:31 +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=1751052274; cv=none; b=kOO0rievpoJ/z8H/H8L0dGyMlvYzeeydymccbcP4xcsqHzymlF8uBFSJHst0ABEr5Gki+WQiqxOtzmjtPLsd4nOD3RqjHAXfcCxe5N+f5bmI8814CUCtlC/lJwpwTQMQYAFolYuD7E6qI97tRKjbuMRKovcu4ZdnpTkYejuHFQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052274; c=relaxed/simple; bh=K4cbZPYI0JIDUSm80xYGKtxGYlTRrcLLUhCDzn/a6pE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oCEt4fT9tLyJIAf1vUmnJvIZ7MGUo6TvW9xFF5WbNgH4jNnr3eZitzAPnDYJ8wHcyf0dvPp8nUuPuXPOmtb2jDNJzzre2bOu3uwR9+kjWavqfdeRpquyQ5F6vR0EEwAtrlwXyYuIxPruzOIOAfjuxCswbbbXCwcKPUUfWvA6Cps= 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=ruQ8MxTd; 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="ruQ8MxTd" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-74ae13e99d6so2310681b3a.0 for ; Fri, 27 Jun 2025 12:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052271; x=1751657071; 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=7RNo+3aZLvAZ2/IwuDIGfrnV93di4OKI/L8u1uWE4qY=; b=ruQ8MxTdY3T3Ctlei8wkPPiuNLJx8/mbkeHilhU2KXi8Q0Fv4st6LIK/5Ne0iQXDHO exE31q8rHlblCj4r4vuWOhf13jwbbH6WjzaFf2V/Fz++Axs/Et+Dm9eNSvfv6H8bGw6K 9ICthocSc/ID5bqOPB4p2TNLUKNTM+IE1Y5RaaMGYx7zlC9MkwZaYCh6vl7Q/fgqcfAa aKbEMsXxX3WyO26HzOdtSfyA8l9O5GUNyZETXaIwfFLR9W6mdmYWYVeK+0tSMgRPAl94 WHoIoh6kfwG1dHIHE5iZqTCSMkUAlAnjT/9tbK7agPdaLBPIiIgPyYfPfSh/90fgm4sH pIuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052271; x=1751657071; 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=7RNo+3aZLvAZ2/IwuDIGfrnV93di4OKI/L8u1uWE4qY=; b=ilnngMHKAbZ1O362a4SwOY1djHS3+8BcS2LDbh8KFZelW6L3Rw9Xp7kofwwfjCPs5U DvMize9ZEjTL+/amPP/sHedeKJgS0IUbqTnhWl2G/H3Sua3PcfSkLt2LSkc8tISOojCC VLl8FaIszT79EaXa60JZySmNsPxvQeYAd/5kNzjgXV7lBwzYSIAhGnLXED2+w7i9OoQE 9by/NE3yWEOYf4MnjCh0bjVu24f9qckrdKdJsqWPQtMjfmt/EaaEpHVOtdK9X5+fl9ie X/l2+69bgw+L31rsHPgD2n6nUYFVi0BK6kOFk2rNT9YN8JrgM3Ze5pdEAk8SNfEEiA6I 6O5A== X-Forwarded-Encrypted: i=1; AJvYcCXNrsmUBpdhNfx32CCCsL+4d6+ik90qV0e2ocGWd+uNfoGg9MtqZKfxiHabP40RnKPbqQ6ocThA49znuew=@vger.kernel.org X-Gm-Message-State: AOJu0YwSX0UtZiij4c9jTPgRDdPvK5EKEESBZXsxpTfNEMd7SOE18Jzt bZT1x/8sRphVYQz0/g/dka5hzyrB2t12Ljo1PgvNP5lFIiIkHVNUHxF52zRvCeWpyWbdiK54iJY MQlIyOPE5gA== X-Google-Smtp-Source: AGHT+IFXlNHgYdYR42gk1f05pi6MWOw2KfQ1AEVMMAnasDAr5TxaXvAaxf5ou9FqDIGdxDC7lI+WkmTgGfYT X-Received: from plq16.prod.google.com ([2002:a17:903:2f90:b0:223:4c5f:3494]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:280f:b0:221:751f:cfbe with SMTP id d9443c01a7336-23ac5f88835mr46714905ad.19.1751052271292; Fri, 27 Jun 2025 12:24:31 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:10 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-6-irogers@google.com> Subject: [PATCH v1 05/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 ``` Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 6413537442aa..ffd55bc06fa4 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -397,7 +397,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 Wed Oct 8 12:36:07 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 32F6D2EBB90 for ; Fri, 27 Jun 2025 19:24:34 +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=1751052275; cv=none; b=Xi2dfr6Mk6gWgV7wQdsWq7c3WGtQp9ofLTtoGHmMPmZpFkxQ3WlHBqPVxuAh3TLgs+JcwdM4OizsVr3izizHYJIgJTGKtpvMiDOb9MN1WPghxUDpt1oRS254m+lbWS6wzcxJUXt7XrcM/zZMJ+dAp0aS1tzHZOnCQprFY73GwLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052275; c=relaxed/simple; bh=/4CLgBy/fjx97fBfSdwsj+wi3iZIrTBu+PBkAgAbVS0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=AvdUGmOITVMPNJg4BvsbM3bFT9eD9it3NI0GUJP+dFgo/vCHKAy+SImOTWbgxJniTollYENwlDV+U1Uq448CKHpf0YPX1DjXVaijthL4k65jd+JRZJvELt/z0kNubQOBUm5Q2jm4JRuP8pfMlTSqBKHWj38mSDawAlY2wKyeWWg= 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=HWKDWgy2; 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="HWKDWgy2" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2fa1a84566so220995a12.1 for ; Fri, 27 Jun 2025 12:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052273; x=1751657073; 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=RIK/VhL2jt+EzGvDP61su+RxHBQCsqze3SJLxs5udE0=; b=HWKDWgy24EIiZg2aeEYwAGkdGA2M/7F3GP/BkE1TC1AOVnUw5UzGEOYFZBt2BtbyUV mcrV4l7eXn28zSmpxrPfJDMVzyCxfWtY8eVzQfH5+hIASJgUC7M+DdSZwbGrMONT66Uh 2LFSMgoacCGUWK8EgKnqJx5G0XMae5NA0reXlnxPkS2RMjMEIR/cFDqS+WbVXvhfR2aB upPEYwEkxMLqB+3GdqpK7Et0ILp06Aqewejg/Cltgpdxo8L43R525fVzWRrADWi7lIvf qrreyEcZ13cs3TlD61s/eASWc4T5JE6v9XeZ+1p4X8vLWUOYj+uSf8WhmqyBBeN6a3LN Vorw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052273; x=1751657073; 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=RIK/VhL2jt+EzGvDP61su+RxHBQCsqze3SJLxs5udE0=; b=XlLqBCU6FD347nJkLo5mB13SLbTADO8m0rUIdhoPOUt822aIZfsYrFUNH+PKi8TW+Z yCNCCpq+Zlco/p7500fZPj3B5A4O8AprIw+7sC55U+y/KfisSoscfNu42DJBmsv//PVa jnUeKJAuKTnC88AYUrd8FZwGbfazmUeLx8TN6kVYlUn8J2klb+F1nDu4v+gX1wMGoQzN h7BzrhmV0BG6zEpBSbeuTKM9uTPyH3a5knmuung/cMMFPcIvXAQ2PcKPPvw1DDMWUZLr ZmXPaxEAiOFv/OIAWVdBJ9omFPfKKPBOrnmKVJd2vD8Pr/+q1jduR/OuOu0TIFuTvduy 7E3A== X-Forwarded-Encrypted: i=1; AJvYcCU1eYHTf5ZHRlBjJjrfDE4sAfrJT+TSawp/QuAJbg3sKKw0CfVAzHDdHeL/aotG8Z4USRphNhXCmmzujOA=@vger.kernel.org X-Gm-Message-State: AOJu0YyUphjgsIK8p57eGe7bSQ6gIoC6sCAw3yZ0I+jr3Aglaa5IaJsT FOABXxG52yBNsRhqNaOsryUkGiqUn79ElkVJesY1+o1QLF1W8bb0JAC1qGTVvDuZzYdVyU8XGqN pyhmeYCWilw== X-Google-Smtp-Source: AGHT+IFVUwapu1S9IeBoAD0gPx9hrv5lWJugnYAAaSx4EfmTs3M2GJ8ymqEp6hiwdZWAyVlF8uUXIUirzpZU X-Received: from plbkz8.prod.google.com ([2002:a17:902:f9c8:b0:234:a0aa:5b34]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:244d:b0:237:d25b:8f07 with SMTP id d9443c01a7336-23ac46527c1mr85394545ad.44.1751052273573; Fri, 27 Jun 2025 12:24:33 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:11 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-7-irogers@google.com> Subject: [PATCH v1 06/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 0208d999da24..8caee925bd4c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -487,7 +487,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; @@ -1526,7 +1526,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 /* @@ -1670,7 +1670,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 2dea35237e81..234641aa6b13 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -4480,8 +4480,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 ef38eb082342..a78a4bc4e8fe 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -323,7 +323,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 Wed Oct 8 12:36:07 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 C78182ECE8F for ; Fri, 27 Jun 2025 19:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052279; cv=none; b=LS+qfK4HOWenmhYrN6h3dE5QmWmQmYmqPtl8Cx7AP6wG8bzSpjCNk2hNSj0AUl6R6hbosgyW/CSslLb3bsXwa3cFzTmf/3bE+154DCxH0psgqsJLHCuiIOJk5db5yFPahs9+jKCgvWWLpkXh/5J9blmDV1b7Q9Pzpm5iNOIspcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052279; c=relaxed/simple; bh=lgYxdkzJdj0+0t5WyUgo4PCHs3tbjzs842Cp3cxBP/Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=FAWCoKKxlEn064Uo+qr/WtZNXO5pvfhv3sdUKnQpRH13nI9b3uH3FI/jx5oI0uHKdCX/hDMWq7xAgtRbbSL0C2ckNdLlAaQaeKLEUPwLuLYTcW8Yjrk1cThdVMOC8g4uNmPDE5Uf5ZHvGuYjNSbtzqOkBuNQ9u6cvF3uwf7LcwU= 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=gw8m1d2T; arc=none smtp.client-ip=209.85.215.202 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="gw8m1d2T" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b3184712fd8so204940a12.3 for ; Fri, 27 Jun 2025 12:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052275; x=1751657075; 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=AdEvbWob6zhzrdFMiDw/dSDXdj7k9xYWPtf9BpTTpI8=; b=gw8m1d2T5MEz7f/d5Fsjx7e+ygRpE2dOPgjhQoLLOXT2hnC4VwdNeBx8mj7FA+Gj8N E315TGITOjUsv+EYq+yc0NyFxJ8pEOdxKTtaWv1T7zMm0DdZ6fFtJw43bfzXWDKlH0Hc Ue9yiXe9BXvegdzsAJhDQihxxiywa6l1nuuWhYWc4cfWscDHxwQpXlzm7SFi+Gm2FWKc lgRxZqRzyxhrYEyYl0cz9PG6RJTOCWadGnI3BHqu424t3i3+3A2SJhSViBhLLCOsgLp0 AzI9/BT9id/O5BxYTOOTEiCxdVee0lq8yMzwmuajIGv1Yp4e8+YR74D8tO/Zz6E4/sLl 54oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052275; x=1751657075; 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=AdEvbWob6zhzrdFMiDw/dSDXdj7k9xYWPtf9BpTTpI8=; b=pYvji2NFD3eGkjFOGeqaiYNz2byllvem5wCPgmTr7T5QF+6MNKTSVoqnZHbCZN2KT2 phAoRJXRfJd4Xwfc17f24hywKfg+PHIq2X7QnPIimhi7SQmtJfcI9PKQf4PYry9vAFSv Sh07kBA+h5xraS4SAUEefE2WIIrmzdIiTyp8y0yGacsCzgEcx6zi4F9qXXh1dW8pyXxR TmwkiXFFRx6r7fVKEbzKKvd+y6XWbzWol2alP90/1ZMITmD/QNvMqUyNmR3a1h7ufWH/ 6x/xW4JJjkKsc11RCrWutDaARoApNCIQeeK290Ri47qgtrlNhJc8vnGvrurDzGjrChw2 V5WA== X-Forwarded-Encrypted: i=1; AJvYcCUVkRl6lsUKKULb3II0uJs3P2X7lO7x/ONHQncKMv4IwseEVreC/53qmqted4lgmei17VkD7LB5rh2Twoc=@vger.kernel.org X-Gm-Message-State: AOJu0YziAm7g2MHNtkEmGKJPZ+0677Gv2pMyy40tnYFpebrJHQGgLubi wDOmWrt3vnmoEA9x4rCaENe3KpMtBcwzAliDZclIgMd6nCUgfst7VCY+P4PxWl6XVjPMoKTP4UQ 0Pz4iuytVqA== X-Google-Smtp-Source: AGHT+IHaVlcHMhPYb35nHDGk44Oi5XKnOLvZEee26fFWEnJwjvFGPUo6h1rXqkaQAH2aOY6DuQV+FK19EpdO X-Received: from plbjy7.prod.google.com ([2002:a17:903:42c7:b0:234:dbbb:e786]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3bc8:b0:235:91a:2c with SMTP id d9443c01a7336-23ac463e5fcmr68496205ad.42.1751052275409; Fri, 27 Jun 2025 12:24:35 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:12 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-8-irogers@google.com> Subject: [PATCH v1 07/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 Wed Oct 8 12:36:07 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 C78DE2ECE97 for ; Fri, 27 Jun 2025 19:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052279; cv=none; b=G6aLMo/+kimi+DpO0Wiya5D/1bPdgOP9ObRZI8w5vF27IT/yFjJ5pmEA9vS4E63KB61b8GI80iPrB6IcKvoodxZ272YRBwtO/1WuzdqgZVRSo6ZiPI1wJ8Usalt+Gv7MrL4WQQNljjeVgvTX2oaOT3QCJ3e4xT+2Z5YfjZkQ1rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052279; c=relaxed/simple; bh=W/Bgi88P7ofhS46Nff6nKg74LxXfuxahRJerKgQn9dE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=MHMoVzLhAS/qT8swwqLJQl3LgetL9inAgQMNSyZPiivNmKlxlDM4/XddsPalhnFNrIKcj0vMA6Y5SMQaYLac62sXL3mpokeLHTQ2Rj+eGwG5LSHwULqvaKF6ieiLcANa5LfKNHCOsWPIQHTv7LvDjXCdj6mIcpKKCpoW7qPvJWw= 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=1KbZQtfn; arc=none smtp.client-ip=209.85.215.202 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="1KbZQtfn" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b26e33ae9d5so359173a12.1 for ; Fri, 27 Jun 2025 12:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052277; x=1751657077; 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=8wGh4hX39HaAnm9ZkRFU2LxfzpD4g1EXGGa3gXUj2fU=; b=1KbZQtfn53TgxgwD7EYZ/Tq2rUHaR8SHVWvdInGNQXD4ycOwUkjLI5cERb8uRzSe+U JQ8/baFUqQPbhIy69TEcrbC3AXfaIWcZ3qcQSiP1ZJ/RVG3Ts/2TydBCZ5dKQFenzqkn TBQ4NCGxrjzrexYehYBn57Ps5unlNFXB9aMu7DIut0koz2LRjcM7PkM8qdiTUqL8bDPd Pyt/qtNfrc47Juw7f1jfiq7afmRsWV0lsEueVqX5VHzWndxnkmDpnNvNp7S+weWXArtS 7hwyGBN0+wEn9U5sfvRM2ZkGaCyXXbrd0Lov6o5/xbrhu4iiqQtCHPtiJGL/aVebFYMr nrnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052277; x=1751657077; 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=8wGh4hX39HaAnm9ZkRFU2LxfzpD4g1EXGGa3gXUj2fU=; b=tkGHfeDcRVwxXyeqlo1Fhw4TnnOVZomJt9lAQAPc5zA+Slydo0hEmawxCN7ZqY1Fw6 2v2cPRmOfR+g1XpsGsAKrp5taVW7cqMMEhOWcKv426zK41cEd1DJHCXPw8FFPOo8hTaM 0jy6nEgYcEbx9q2BqhicWM+prkulAwCwHAjZqkomwUdlSMWydLdIUNNN740TWdstrJJh yZFQgz+91nA/iwpK3B6xRXhJlkF9KUnarxj9DH6AR9O5uFhLEwFpieNf7UkDoaRIC0ZH fVbSico6+M45+ituEoKPMztP/imlk1QhlFhSDz5+tWJ0jSqsI4fLiEJR2qLETzAG8HKV Plkw== X-Forwarded-Encrypted: i=1; AJvYcCX6IIcWngxZtfP0OoqmUgwp3xqkVCdePs9AiHgKJQJYOpwxqgUrMl+2A0d3bFk/hrKptLCS70D32jDOVtU=@vger.kernel.org X-Gm-Message-State: AOJu0YwEXzYXHkJyX6JDB2AI77MwK9KYRmjlCuk36Y1fMtx70uuoHtmJ 6yGap9lYf+ta0mz5XZi5gJEv10ReHRQGF2Qy9Uu8cz7VODZLPkfMe3kntmgoBLo1VylNv08EjT4 HFXhMTeZNEw== X-Google-Smtp-Source: AGHT+IEZpbwsDnk4xblx0rI3Vgl53NcXt0AkOZrWxv3lkOu/3ULvVG1OsFbztyxBw/CpwMw10ECrUDqJtF6b X-Received: from pjbsg10.prod.google.com ([2002:a17:90b:520a:b0:30a:31eb:ec8e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d0d:b0:311:df4b:4b94 with SMTP id 98e67ed59e1d1-318c8eccfd1mr5463074a91.4.1751052277148; Fri, 27 Jun 2025 12:24:37 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:13 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-9-irogers@google.com> Subject: [PATCH v1 08/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid the duplicated code and better enable perf_evsel to change. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 8caee925bd4c..1169aa60c5fc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1669,9 +1669,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 Wed Oct 8 12:36:07 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 CE5B52ED16B for ; Fri, 27 Jun 2025 19:24:39 +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=1751052281; cv=none; b=o5N/pnM84b0zCb6aJHQVPTy7T+wjTW8iRDPKBwKpRGobwbl1d2mxpk2EJeTFKFEnMWa+DlWMLQni+ZlPYoevV45o7Ks6Mpr4/xXz+FGW3S+YDytUQvv2Vt8DBidF9hFdUzeHiHTfSxx/19iTyUdsZ9fHkaf3UE1tZDbyYUJRgvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052281; c=relaxed/simple; bh=aNMN2DWhRyU+2RMpyUjUFGngTzlUnjuyhGY6JPjW1Eo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=IstC5vOOoHB1S8b71rrv3WXHMhtQ7AdOfLZxG9AwwCKhv4FV22d5AOIBhk/SPXh9ZMmYE25hdR3r4CPAjnkLvrrdE0uQ1NeEO4dvYJNT+MI3yQLfnbKlwT536Bndb3wrMqM4sWIYR8ma/pTlHlPCsIFsj9tngrop4CVGkr5YpbU= 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=2WpF7uTs; 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="2WpF7uTs" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2d9e7fbff93so2514191fac.2 for ; Fri, 27 Jun 2025 12:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052279; x=1751657079; 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=Y648qPWPFyBd60sW81F/WAt0bQS91tJJCKmWVX/1yDk=; b=2WpF7uTsZWSOWHDNmMCdPl3WuQT/JGiF0vETmMnX0TnfxEpajkmrINYeK3q87yu+3q LrebpuUOLdiUrei9UtDv3A9ajnyu8voNNzFbxo6Cm+JoM44whOxbiokJYjkoEO4GRdHz em/H2UOhNcuDF8I7xQKCSmbZYhct8A+XV9RY+5uEck27p24LrKBTY0EYPlzV4EfLmCyb Afyl8v6g0E5yMIXwdsVMpa82Z5F914lNj2RWDO9CEdWy4+aJBIJPVqTCXpV7xk0OoCdq hzH4lxLJNYrbBupdcsaPSiEU+vqKuFuvR6TKi8qhtrla9yXcOR44tGQuQz7A/eDHJ+Lr JTvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052279; x=1751657079; 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=Y648qPWPFyBd60sW81F/WAt0bQS91tJJCKmWVX/1yDk=; b=O4bd5h4bnYgH3avc7PhKS9LutIJ++BbqrM1YeWAXJnDzLd5FXTNGATroTjOJrZ1/HJ 8wNPSzMAyZEbFx/Y57odKWc7tycNYqu5/rCN4jtkZZgt6cUkWQia9HRVfxrEVmfcTC09 Gdv2rnj+IH3Y/g4QfcgxTenLPKOLdqncopZAWVxFvF8iWlatJvFt/DNT2KzTbkxhBiMU WGBoOLBOBGPdxX+oIeewsp2tJNPmABeUoaokJSAIe/NsZ50ykOa7UlfLJuox/fG6HfFR H8acnRcyvpRKswdVylnaFGF2/+08nJ30QVttaI7VCHPKRrr2tK1JBoeftonmM/9slpLe hjUQ== X-Forwarded-Encrypted: i=1; AJvYcCV8M0gHMxSWpVXadYQ6cl7QEkQ9X2Ts7yp/2ho+oal4gpaAyWoxKzUD3NIIee5q1asVc3LfB+E+EnOiP5I=@vger.kernel.org X-Gm-Message-State: AOJu0YxGHZUGoQ+JiPsRnTc0h2xkwA1dIexgJp7ZvpaaDR7vbbgXFMac 9ItY8P5QI1f4FSrKhnOWibGozf3R6Y1PXsc5ZeH+Gsbfm8QwljT56NUvlZBqNMbKxWi3pFaA0L6 4bksto1VnAg== X-Google-Smtp-Source: AGHT+IEl0ZSGGe1ulHNJcLJqY9IP+npGVG5iV/pYKzVba8MHXlliSCOPcJXopnVaaMUpJL7mwG+wscVnaTwb X-Received: from oabvp16.prod.google.com ([2002:a05:6871:a010:b0:2d5:7c74:78d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:f60f:b0:2e9:95cc:b855 with SMTP id 586e51a60fabf-2efed7553a2mr3126222fac.34.1751052279003; Fri, 27 Jun 2025 12:24:39 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:14 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-10-irogers@google.com> Subject: [PATCH v1 09/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow a PMU to be found by a perf_event_attr, useful when creating evsels. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 3bbd26fec78a..8bf698badaa7 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -715,24 +715,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. @@ -743,6 +737,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 8def20e615ad..09590b1057ef 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 Wed Oct 8 12:36:07 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 AB3982ED87B for ; Fri, 27 Jun 2025 19:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052283; cv=none; b=T67guqcjuN4dSfxygV+OBTjmotqqeJnGVaxnJKNng2PvcmPF+u+bKah5xbA0PhSKF+H8YfwD5EyTIm4ledopfhC4L0m9dVVWUKX2pW0g9ih+F0SUULyqz0pjqDXK73suH8MY4z1Y9j60vsd67s6Z8GA8PCjCbmt1Zh48t0jC/CE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052283; c=relaxed/simple; bh=XpwRfCj6BAPEzssrvIpf/rQ6k3usPqUG8SmEvpgxGL8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=GI8dUfJrzVelvAwpn8sx3Rm+9DgP4Zto571NyTGSuIsxTlluObZdnR0VwrUK8hg3/ahijFN0SQ4NDHXpoiMQxO9eyZcglIwxweyBcIsYzm2q3HPWAmXQjQP8KSPJVZO5/fEiFejM8E0KPfl2rw47CAlmMjfq6aOJBrgFb5RN5HE= 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=UKOmN2d7; arc=none smtp.client-ip=209.85.210.202 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="UKOmN2d7" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-748e4637739so1863204b3a.1 for ; Fri, 27 Jun 2025 12:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052281; x=1751657081; 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=+g10moDhyR2co9xzcC7zCBnVEO9NfyRuR76f5YnO/4c=; b=UKOmN2d7BSCfSYaApvOMWkAo03UtTJ/HlgWmlViQxAIIoXfaz/8yGDu9bsPPbsYMQl OEAV1enHa5N3UMtcE5/1tQnC5ggRm95UxU0prqh1aQPc/bOvDh1gsrcQEC/Sa6Zbckpj NbuB0vBgaKMb9Fu6K0qCff9Nk+dGBlCoLzv5Ti6rloQ9m6Bga4co7Vbt74vaSdXA/JIX FeBGTnW0X+WxofGOPpUcA3zrPkaaN+1+JHlNzvlpaYN2fCviLBRd1qQm003JpWbe1+bg S0BwxMFDVtoesbZWS0Qt6fM6MLZ/HP36QaydwLMiDqH7xZqDaQDsA4JkNLG715BEajpl BYgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052281; x=1751657081; 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=+g10moDhyR2co9xzcC7zCBnVEO9NfyRuR76f5YnO/4c=; b=UIdzygEvv2Tds30I2m/M4594r69St2VFOwaI+tDfcNCxPtGzgoMW7t3GIcLVSb7PBo 68taYOdhh3hQrPFoyyXN39YQImyxtgjMgT+FLp856v2ZZNb0zjy3vSIe5IRFjdDYz2jq dlGaumwwoF3c62RD0e+U4mKrlNETNWmswAutkJQ2Qp1GF2wNfkbkEbk5Kt0kmnCF2Cp4 YW7v+g/J9lvR2MhUQKpRnhbCfs+fWf3GLhB5fj+CEkjB55nmCgazgBI79+FSf0i1b7oO nGDj9ezKuC+2Wuq48x8CSceA/ZoHQrOxTMy+b3Ed0XOC0g7SxTVb61EhWmJwaEI0CLwM c/Ug== X-Forwarded-Encrypted: i=1; AJvYcCUUsjMGxwTRKvibPN3onwFSmTvV/k+e0KyzUYUNiLixGwDnWspsJGT8gdAg0mi2GkvkGDtWaQKEJKZki+0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7VVqatX9q7iZepsF60DuZLKK2VXRVYcPutNIhtDhxPU7vzY/h SrfHRM01/bLclDCukgExzT80/2vENGqDzMdqnsXGwSDxtHOi2IuEyD1ulu4hUVRB8DscqpKS68T fwn+ogkKfQg== X-Google-Smtp-Source: AGHT+IEsr2LK+hyGE/leTX2OCfI09N2PU8GenufPYSLZAjAShc5sSuT02AOaq+FZ0iQ809ZM8XhsooVzXDU3 X-Received: from pfbdr2.prod.google.com ([2002:a05:6a00:4a82:b0:746:1857:3be6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:8806:b0:746:195b:bf1c with SMTP id d2e1a72fcca58-74ae410c339mr8029997b3a.10.1751052280804; Fri, 27 Jun 2025 12:24:40 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:15 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-11-irogers@google.com> Subject: [PATCH v1 10/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 a78a4bc4e8fe..4092a43aa84e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -262,12 +262,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 @@ -291,8 +291,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, @@ -304,48 +302,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 Wed Oct 8 12:36:07 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 014A22EE5EB for ; Fri, 27 Jun 2025 19:24:43 +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=1751052285; cv=none; b=l3NWC2801V/W8Gf2I1wTxnY91PMyvRIlr8wBWEa7d4sdAKqWQbSKKKSVBIebNH/wuAGnEnmHxNwgV6IaP7EtnGL0R+cGwmZCWkPJbYVRoZKy6YknmIXJSUg/YOZNr59RwId74wW2/mNn8FnOmxaUVOS/zYcV0cB1qqx9ouMtwuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052285; c=relaxed/simple; bh=TmgYCTTGSJdKq7z8EdzJjt+Yp8LyqX4VI4Ic6NdyBsM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=bN9jOWphJ24dvMG/FOJEevTZRJEaQY4MxcvYjOrY9zRltQy7fvDlUpeFXs6TpVtm9ZO9Vbx4C5RRoZaqddjgdRZqgCZ9UfBJz2IBiz4RQHo0ucevaT6/mDkOypV6gatxU4tZ8i0jFGhSr9x5dCRd40viThMCvE9Z5oO2i2rQVoc= 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=GDgbipIk; 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="GDgbipIk" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2e92a214e2eso874723fac.1 for ; Fri, 27 Jun 2025 12:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052283; x=1751657083; 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=EFyT+8RU83ZXK59fsAUqw8r9gWLHShlARLFnNU9b/6g=; b=GDgbipIkPGQBmCJKE74L9wx/h1wvgkd/33kCLUjpcQFYxTJ/XL/irBKcY1JNF8cZ4X TL7vfoIGi1r/ZZVDlL0ksQpXMT+aBmZCuJ1Doz5FQ5I8s2QVEVmcl8lMNV+dTX6seELk LK9fagpAJPEqRH9srtUk0odlZpFMfgiD7wp6N8sv7Yt900lSHtTsiiMO0pgpbksV5Mrz MIzG9edAe21CzwFyBgdzEg2PnUb8EhESPubTQOjMUq0IZu8H3NVPrLkEkZU4fQZqCpJt pSKCVEhJTvj6ts2xvT+2c1QAunusUvBZfvpV246HrJiIOAL9cHybMqpfC2NRzMtZppFP XSsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052283; x=1751657083; 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=EFyT+8RU83ZXK59fsAUqw8r9gWLHShlARLFnNU9b/6g=; b=OYcvXD/dn8Si9eCcz4sipxgIv4mij7my6sd0RlCU85eBHM4OmJSdbIW9z6IV5DtrSA w3vfD6V48t8fWIlFfNbVoIPjnWEKpHENHZLIhlZlIvUZ6yu7Q18YTugznlorMDFp4D6i T+bQOvtI4Z71qJXaA7jgZYIwx5dvDQD0PHarILtXzYuj4ecHtFYvA0LQezVsYibc32Pi 4IqR7JMX4CxV34QlOR85OjaE6hgmu+8abEQ4GNqmkGU+ciiPshUxH4Kra/QucYyHUYov paHjmBwDAT6PN0y3ElE13y+A5wE9HU7djR/JqKir5696TT1LEkDfb+RMe/1SGIV8UobF HTLg== X-Forwarded-Encrypted: i=1; AJvYcCXMvG2A64+nG+eEmgRf4GzivphWTIC7tIP/l63M+46i1V6dgpuVHkZemDKovaYXqMIuZWu3B4egDtHeUts=@vger.kernel.org X-Gm-Message-State: AOJu0YwKFIfb3t2OBvAVgiYGKV/oazNj0tTQvLCiTrF+Em+09K5rjTEF jaUsrlrmV6x892VHgvr43Xc2+rVXnVt44nwbu8p4O/rq5j18AES7MBqtPoL1dYbR4lfiyGKXE2l QVE9UI+5OtA== X-Google-Smtp-Source: AGHT+IHPcRI4IStwL19Uepy2ZttTWHngKeBVZRUyOc+r75wj7tI5L0IQ5QjZmvYiblT/p1WFOLuKCX16y6tM X-Received: from oabps10.prod.google.com ([2002:a05:6870:9e0a:b0:2c1:fc56:4d62]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:8312:b0:2d4:e96a:580d with SMTP id 586e51a60fabf-2efed4d9bd6mr2974016fac.16.1751052282906; Fri, 27 Jun 2025 12:24:42 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:16 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-12-irogers@google.com> Subject: [PATCH v1 11/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- 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 1169aa60c5fc..9abc62635e76 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2741,17 +2741,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 8b5962a1e814..4099812d9548 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -349,6 +349,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 Wed Oct 8 12:36:07 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 CB1042EE5E4 for ; Fri, 27 Jun 2025 19:24:45 +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=1751052287; cv=none; b=Msue8tdecS/V3L5DjDovvcQ7sRpYqF39FXw5UjUUnL7CNcMmW3QWP3M6X4NclWgzz4G1+MsgubGiyAN3gEA2k5i9Ydjf1GGppQ3HeAMrpM7ghgfojy1Lp8SXfMqngur18mx/f3+WMEqPJG9WCWSZB5e0s8NK8Mc7OUKqArft9zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751052287; c=relaxed/simple; bh=M2yPbJ9yDVEQz3yIkcAcoszaWQfbdh8hZW/S1OuH2Ak=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=NKsoze+qoC3hBg8YOryHN6fIxeUfnWYlxFFbnUisENy89Nlzf3ojKsWO7pFq5YexxAxZeQ6RlSQS78hcgKLdtJwBx7ooRBxzDQF/AYw47ImfEY4zgwmGJTFV5LbcIUvq3K9LPq5ly6b7JOrK4wRr+tA6oSWoYNMAEXSdagWiD+Q= 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=uoIuPbTw; 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="uoIuPbTw" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2d9e7fbfedaso227743fac.3 for ; Fri, 27 Jun 2025 12:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751052285; x=1751657085; 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=F3Q/ULdBEGngG34x3hXr5lFsxJBBvdO44FGsF6UluQg=; b=uoIuPbTwlhMZcDR/BtHXSrA3/2+8qMsB1npCXQvVkbFs/ZBNHojc6N2MZAZqp3VWSv v3nFoxVVUgqGZv/8CpGKdftMn9l5hWEnpJrvqZEuUHWeYSK5iA5cEaplaDId5g7xpXsl nqDvyQPjnc0xix0n8pUh39iUjLyqnYNspuEeicnY0WIU0TIk+3RPZDqM00bU7cppX0hF z9bOlwZK8vL5nQG9VJoVeL8xJiOHxgdVNHD3c1uh+2JHU3Nlu/gRGubdRXTK6HtFl2Sd R62zFe/gbF4jE8KS0EAOJy/BiHwwh/z4MKspIUgPXWQbDCgWJTRQWb+4b86Aeh1JmmhP yLkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751052285; x=1751657085; 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=F3Q/ULdBEGngG34x3hXr5lFsxJBBvdO44FGsF6UluQg=; b=cCJQypyaZvpLwQ6lLOjkyCk0hOlI03u2zOORsZlbCb1Z8geYV1p03xW2db5sPloKAy Snv8jIlSTVDBg6JE9x5LF98dIH56r1Z1yxtuXY9RlEtx8FVXjlTLRfLdP+6c1sK+i+FL ZfkF8ikoUYem7e7Z+RgVlVUQ2TN28qRu3coPMLIhnm0ejrvpwULazmmdyUoseXrpqGgE GIQO88kNUhS1SQ98t4sKERtOXehqLk0aZtn6Ycw7ky4N6SHpYymeLtEVzKxvA7AL5GRG NiZx2SwPv6LvNS1yj095Kla/qSFpFZskDS6vW2/1Qyl7+u/zYJ5au08hbmpgCNM71nhX gqFg== X-Forwarded-Encrypted: i=1; AJvYcCUtX0SoC5RqPdKWQvSGWvGxuPt2a+kOvkKS1F1y79uGhImVt1b/0Ph3UR0KrrdkUQMpYqv7r/TmoNbNq7Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+Ee8JWBCp+yjG0lTLzKvAWwMLIW/D0E4LEfJz4mSMaFKhUOZh /Jrw9yFhuehrN+5Vs3jgApNHRnlo5wRwm1r17emOcxd6ld8bYJ3naIkb6lmyll3xPje9yWEQTXC Kyj2qF9DrMA== X-Google-Smtp-Source: AGHT+IGlOvwlmutKPb3zybhQz7t5hQULCTe0D0fT//oISF2zt1cNPyANEM+Mirilb3j28Yt4HvL8mqjCW+6a X-Received: from oabpc15.prod.google.com ([2002:a05:6870:1ecf:b0:2e9:2323:d48f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:e013:b0:29e:4ba5:4ddc with SMTP id 586e51a60fabf-2efed684156mr2905508fac.24.1751052284907; Fri, 27 Jun 2025 12:24:44 -0700 (PDT) Date: Fri, 27 Jun 2025 12:24:17 -0700 In-Reply-To: <20250627192417.1157736-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250627192417.1157736-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250627192417.1157736-13-irogers@google.com> Subject: [PATCH v1 12/12] 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 , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Counting events system-wide with a specified CPU prior to this change worke= d: ``` $ 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. Signed-off-by: Ian Rogers Reviewed-by: Thomas Falcon Tested-by: James Clark --- tools/lib/perf/evlist.c | 118 ++++++++++++++++++++++----------- tools/perf/util/parse-events.c | 10 ++- tools/perf/util/stat.c | 6 +- 3 files changed, 86 insertions(+), 48 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 9d9dec21f510..2d2236400220 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -36,49 +36,87 @@ 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 && + 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 +136,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 4092a43aa84e..0ff7ae75d8f9 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -313,20 +313,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 355a7d5c8ab8..8d3bcdb69d37 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