From nobody Fri Dec 19 19:16:31 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 E5A361A2398 for ; Wed, 8 Jan 2025 05:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314488; cv=none; b=g1bUzV6E5FygesZ6T6GixDgLLZWO+gWpHQxACzW7aPvcyXuuydaTUL0eFx2qX4Kf1O9oSnGm3NSmuh97CXSBqa6ik2Uumz40R2nAHtlyaSzh2ndWRTi+spxKj/0EA5H0FFhZSp29NiHkvfAheZEKRXHTnLIVoQPp7DBV2hOSVMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314488; c=relaxed/simple; bh=62bBMWr5E1/GDqwNs41D1h//alB35yPbnHV0Oe7uaNE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=je6tTBY3YcTDapROgm41VZOf7k5O3ZNzaCWNvzxMMamkBUovZ5BobSoYeS3d0uYfp6U757sx6kDgs0UqwitIg57Z0ZzFhcxlkEhubmHKiXja7CIvxI7VCOpWVULM4ONTlSGmOrrNtZ4IxWooUBLaa2Nc9wd+RXZZmvAMnVdMoS8= 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=lOzQ/1KH; arc=none smtp.client-ip=209.85.219.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="lOzQ/1KH" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3a0d165daeso35661200276.1 for ; Tue, 07 Jan 2025 21:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736314486; x=1736919286; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5e2WjueStXy5Vxgh10KeE4aI11iOULRJOsRrypPKwec=; b=lOzQ/1KHpQIZEVHM84LBFuvuFyNb0/+96kQv9urnjIlb3DvESX5hRu96z48JRIWgBj tC37Dz1RgE+N5R10dv5In2GL3tlljq8jn80qK7EAsItyqQiU8cxAI1BCeqbOb5u7Gv1Z 9C18YUkWoVTygVUMrh1JG6HTgzCM6uYVTc1EodrRGDXhZegjTdYNNlxJ6Hjloxp0G4oq STe5iWOHWnBgRs5S+kRKHBdNLeVvRwAL9F5zq8XlqkyERN4XObRRGFlXEjJlTuL3JGi7 N2VeTkPxSI0UtI4NcRyyWfesTcO8fbyvX0Mp7YZbcTA078iOlQHxbabYHx3RXNxDGLVg k/Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736314486; x=1736919286; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5e2WjueStXy5Vxgh10KeE4aI11iOULRJOsRrypPKwec=; b=FRDWRg5iDew5eoOBwRuuJLykmPguGM1ov9bnpD/82jFykBm6FNDEBoc7DnHQnidwqw lf7miU/vDw33zPYVMvgcUZlcTwH248/5dKxlOtNoYH/EiYbhnPqsLbkAVeLMngX5LnST xSPpO7yhGt1s91NnhtP/AyfqxGhCK/YrK0OrVkbI2nEqRMuhMh828uyOfHhA+T5fop5q n7p13pOydGNUUKiWABvYI+5+fBhpsm9RRIufIRH212tFBailCnmAl9f/ONIOgXHF0SgU qWlhDTLKz3M6nZv61mHQ3SgstDOlDsZvBJbrFQAv29HPNS/klkVkJUqGm+/4ETtPIV6L 0BqA== X-Forwarded-Encrypted: i=1; AJvYcCVr1olA+i/uN2kNvauwFmgXZefyMtWAhFvh1aAJlo34aFqFkQlXhuQtLXYWn8OBdVulgkwR67WSE1YOnso=@vger.kernel.org X-Gm-Message-State: AOJu0YzLLV+Pp7bCV2lV6DMWoZUCN3CVByxW4AnnX6Uih5AKE0uCxiCF h4P4NvLrMsjtdf90ZlfnzHKpL/GYx0HNMMGIJSUrssDlyxc39hXbBAR0Uo6H9zCCLhPXsUPWyz1 zRbGIAQ== X-Google-Smtp-Source: AGHT+IHm+uUJ/9xKXPDUqe/nY0Pj280rMgkTdS/UL8bb0e8i5dlC6a+cOylCUFPSLeP19en84v4o8la9XeIL X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:7ae:a887:5504:e3ca]) (user=irogers job=sendgmr) by 2002:a81:a982:0:b0:6ef:7d06:1eb7 with SMTP id 00721157ae682-6f5311e4c09mr44177b3.2.1736314485929; Tue, 07 Jan 2025 21:34:45 -0800 (PST) Date: Tue, 7 Jan 2025 21:34:25 -0800 In-Reply-To: <20250108053428.1724490-1-irogers@google.com> Message-Id: <20250108053428.1724490-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108053428.1724490-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 1/4] libperf cpumap: Add ability to create CPU from a single CPU number From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Leo Yan , Yoshihiro Furudera , Weilin Wang , Andi Kleen , James Clark , Dominique Martinet , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add perf_cpu_map__new_int so that a CPU map can be created from a single integer. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 10 ++++++++++ tools/lib/perf/include/perf/cpumap.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index fcc47214062a..f3054894ff0c 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -242,6 +242,16 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu= _list) return cpus; } =20 +struct perf_cpu_map *perf_cpu_map__new_int(int cpu) +{ + struct perf_cpu_map *cpus =3D perf_cpu_map__alloc(1); + + if (cpus) + RC_CHK_ACCESS(cpus)->map[0].cpu =3D cpu; + + return cpus; +} + static int __perf_cpu_map__nr(const struct perf_cpu_map *cpus) { return RC_CHK_ACCESS(cpus)->nr; diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 188a667babc6..077133935bf4 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -36,6 +36,8 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new_online= _cpus(void); * perf_cpu_map__new_online_cpus is returned. */ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); +/** perf_cpu_map__new_int - create a map with the one given cpu. */ +LIBPERF_API struct perf_cpu_map *perf_cpu_map__new_int(int cpu); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *ma= p); LIBPERF_API int perf_cpu_map__merge(struct perf_cpu_map **orig, struct perf_cpu_map *other); --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 19:16:31 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 567A51A304A for ; Wed, 8 Jan 2025 05:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314490; cv=none; b=eI7Z3bI7+8ODvNsaTkafzPlrwwx5wDvjIErKiEf71mTDJ9vr1x1E8iVm2GxG2SXwIOOI5EUdB/wSbVCZU9jO3F4koGMDAhYjLtclRJphtDqwX01MGPu3spYrtnA5DcBN2mh8dhRseupOhAVww+rm8W/iDUI8N59igg0ZT9mqix4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314490; c=relaxed/simple; bh=FH6pJMsaJgeqK7UUNBqCQ6T9Rv/2s4i52g3/jbl+dxU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gvS4Ncc7rmmck0UXQJB57vpHymM24oln9GNXo6XfqVRnraj6JWANi9SuL24r/XXfX5taDbxsCqQOHzGpH/hL/43rA283/zH4K2lSqQjagEjcLDUBu3sHDBD9wqrsR2mGfutIJUXotqSCMU7LJ9ByWM2dHG5GCyWXzymTwf9go7U= 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=aC7P5dJ7; arc=none smtp.client-ip=209.85.219.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="aC7P5dJ7" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e4bed6c9151so34045512276.0 for ; Tue, 07 Jan 2025 21:34:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736314488; x=1736919288; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=t23J7xHrW+6du/GAso1cLjFOTcnn40e4CEJt2KBpcE4=; b=aC7P5dJ7mQKkVoU4wWK3kuu05K+XaulFPBYq0yMG0mM5jAVgeVJ5QZIwW5Ui3Ii+vc 5kKIgyVrCfL9ZzEAFnmaREl2Qd6ua8TLCVUBmcER0hTLy79erAmdILAXspzcXMyWVZ6z Ce8e+nDYT3swEFr0eCp3UiM0eRI2aXHLL6R5kT+WZZnqVBeAdpoCDO3ikQreIjtC2DBL og0aIS27W0ulM9oL4EjwtRkBqXcdIOXtlZl3BYk5PxH6CWpawXuL+Jc9qq6adj4ZATpA dPGHhsL4uODF2MIQSeAzdiQRI8E0jXoXyiSeMFWVsC1Wk05FeTKac2BqOiGzDBUVBPa4 oFKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736314488; x=1736919288; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t23J7xHrW+6du/GAso1cLjFOTcnn40e4CEJt2KBpcE4=; b=RGjYAMd0caMZYhGSotr3EAL5ueCdMu1Cly+0J6Oa1GmF0NLUVTk39nmDyVXoPcM07m GBvSJmNVm2SgnLfqUsG56BPVA4CoiFWDHJLl4Z4cycRoEXqnAOMZ/x64Krt8gu3n6iZy wXtAcrImqSwsrMsO23ibOqHUgl8V9EcJJU/WcFh0VRb/WPhHYyYI6VzyZ96VY0QfYfhr QyQw6cFvTBVgLa60XqbcpPYBUEwPj+3wykFzPesGoshr/T3pgRXy8epoSmxTma/CtIHY kCXaDYXwTFIsPGCqVpnip99GziKI07tD8uAx7Q1txL0MRkbL8hlT12dgLyevs/mUi2b8 oTyA== X-Forwarded-Encrypted: i=1; AJvYcCVOLbjadpy9LL7fN4iK4LuZWyXDsIqn5Y+xPVysssdlWNpkfqlC1clkA4L7I/KtS2wvq8HcSkTXUic0GE8=@vger.kernel.org X-Gm-Message-State: AOJu0Yzrs2dUplF0uucUdDHvevBg3Vkw/ytoo4O/vhew8GWpFYDaX9o7 Hg6flkuIlyxKraojIeYPUdW1LBOZA4+Dfqm0+kj/lFXZdWstGU+guLxabMjTgt4mrh05m34lbCs M6EiXpg== X-Google-Smtp-Source: AGHT+IGfud90+1PaGtUI5JAJlfl3512z8vfPSPhC61W7tJfmD1UNBvEijqmfYY9XQy9B8gM2/qNunvu08Lxp X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:7ae:a887:5504:e3ca]) (user=irogers job=sendgmr) by 2002:a25:2b43:0:b0:e2b:d0e9:130f with SMTP id 3f1490d57ef6-e54efbf428cmr3266276.0.1736314488295; Tue, 07 Jan 2025 21:34:48 -0800 (PST) Date: Tue, 7 Jan 2025 21:34:26 -0800 In-Reply-To: <20250108053428.1724490-1-irogers@google.com> Message-Id: <20250108053428.1724490-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108053428.1724490-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 2/4] perf stat: Use counter cpumask to skip zero values From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Leo Yan , Yoshihiro Furudera , Weilin Wang , Andi Kleen , James Clark , Dominique Martinet , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a counter is 0 it may or may not be skipped. For uncore counters it is common they are only valid on 1 logical CPU and all other CPUs should be skipped. The PMU's cpumask was used for the skip calculation, but that cpumask may not reflect user overrides. Similarly a counter on a core PMU may explicitly not request a CPU be gathered. If the counter on this CPU's value is 0 then the counter should be skipped as it wasn't requested. Switch from using the PMU cpumask to that associated with the evsel to support these cases. Avoid potential crash with --per-thread mode where config->aggr_get_id is NULL. Add some examples for the tool event 0 counter skipping. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ba79f73e1cf5..32badf623267 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1042,8 +1042,16 @@ static bool should_skip_zero_counter(struct perf_sta= t_config *config, return true; =20 /* - * Many tool events are only gathered on the first index, skip other - * zero values. + * In per-thread mode the aggr_map and aggr_get_id functions may be + * NULL, assume all 0 values should be output in that case. + */ + if (!config->aggr_map || !config->aggr_get_id) + return false; + + /* + * Tool events may be gathered on all logical CPUs, for example + * system_time, but for many the first index is the only one used, for + * example num_cores. Don't skip for the first index. */ if (evsel__is_tool(counter)) { struct aggr_cpu_id own_id =3D @@ -1051,15 +1059,12 @@ static bool should_skip_zero_counter(struct perf_st= at_config *config, =20 return !aggr_cpu_id__equal(id, &own_id); } - /* - * Skip value 0 when it's an uncore event and the given aggr id - * does not belong to the PMU cpumask. + * Skip value 0 when the counter's cpumask doesn't match the given aggr + * id. */ - if (!counter->pmu || !counter->pmu->is_uncore) - return false; =20 - perf_cpu_map__for_each_cpu(cpu, idx, counter->pmu->cpus) { + perf_cpu_map__for_each_cpu(cpu, idx, counter->core.cpus) { struct aggr_cpu_id own_id =3D config->aggr_get_id(config, cpu); =20 if (aggr_cpu_id__equal(id, &own_id)) --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 19:16:31 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 929F91A7249 for ; Wed, 8 Jan 2025 05:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314493; cv=none; b=lDp1hhyULy9w3Td/bxll+6P+t4+ghOgFYtlw48Zq9+ai7GQ7BzNOgiLxKUOFBiKZcMh/8BwHFUagxbPAPgZ+EG2ZDaOJ1LR5XzDYFo/HuCTxMASuV0Y01tZt0gJKfgLc8UzXSnkoiM9uFCQkevSvrNIUAcNIEyiBgG4nO2gF/4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314493; c=relaxed/simple; bh=pU3q7gcfHF5YJFJO82z2GpY1D+Ad/Z/0AoIS1WPrJj4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eOXtp7HarLyLomMH8cQNGyExPLcc1ntarZb3O6HbLpagcBU7vSlzjMt6K+wKDDkpiyoorcSyCJiflXVtnFRYuNREl7GpCcg+iLq9/3XHYLjDJedSMB3bvLZ1GPRD2lViEeq1kLFQNN/8V/AY/fiH415r4Tps7avwvUWoV9aAmAg= 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=HOpGT0Ov; arc=none smtp.client-ip=209.85.219.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="HOpGT0Ov" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3a0f608b88so32912022276.0 for ; Tue, 07 Jan 2025 21:34:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736314490; x=1736919290; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=0FF1+dR5Lo7oMmZmNU3Ip/TUs1XkJ0WZAvmFs9ECk2g=; b=HOpGT0OvHQT9L23a61RD+HaqCJ8bwWC4uAb4zQMtLWMWqB9t/ZF8BxufgVg7xsazy5 4A6y65BvOam+yaumHaYrH4WzIgaDh/YQ+pLt3oHzNwLEYRV4s7bFCCBd2MzJL1qZw079 eJVVEKQuyUUl5sHCeisjoECFxfSOcF9BqS3sYKuSEWRaSzEVcXZIHMNcgH0MhQVR/VZD PrHJ2o7xv/6ITxVGqUxzyKVzHPNdT0fKEJyDkYMe6hjlPtAirLXsZtOZtLSVuRi+zKA6 vXYhVhLYrWoefF1IXYoOTLJw+JjC3qc5W2YITyPaemT9ANk2rINvHy01DWhAVyiAQRS+ zI4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736314490; x=1736919290; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0FF1+dR5Lo7oMmZmNU3Ip/TUs1XkJ0WZAvmFs9ECk2g=; b=jW4GyoJ+Rq1rmVbM3TYQuFfoUw4W3Ak4X25F2IWn0khrtwnV12KCWbffpfvtp0xoCc kYKI8dv74fEMJDOr43tqdd+wd/ulDybeVqMDW4UEOXoOIQBowGjI0OSGGfOI3mm/vtp1 BLl4Vg7seTF+ZdiILElr5o4qhvC1XLz+rf1rkjomhV8F70mj71roLVInPrkssmljhRkU CGTsI0tm1NgARBRaNmkcGAL2Elr2ZurtBwztI0S4EWpCGbUZlUUvhSkz7cVKvG+Zv8Me FCI7HeSAtH9A0iuwiLGz+PKuccXpMJy7fL9H/8LXwrpGaF8WJzBEKZtbrrAM7GDQCaR+ 0/jA== X-Forwarded-Encrypted: i=1; AJvYcCWZXK+u2lZQgcvX1eKWgBD1RZdr/SW1gTZzEPPFwzJ7suCXjU383IXh5OdOrmcP9hcV/lZUOHxRtTVkYyc=@vger.kernel.org X-Gm-Message-State: AOJu0YxW2ZhlTCEliTQ8NRXz6RjTilXpjUWR8S3mJj3yqNEYpYROXpqd 1L7HBtMMNmJDw5B3UDqb5X9UYJGjnwfqdt1oitCS/pcPwe9ga92YmizICeEM/qiCzRTidNy13TI U30FvMA== X-Google-Smtp-Source: AGHT+IEUKIlCLJcb4EXajotMSIYDCcsHbs9Nh5LAlws/3NJnHcyVabzgEL04vNJh/CrGAixRszW7Ydk2FO36 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:7ae:a887:5504:e3ca]) (user=irogers job=sendgmr) by 2002:a0d:dc46:0:b0:6ee:3fb4:45b9 with SMTP id 00721157ae682-6f5312b4c37mr41297b3.4.1736314490615; Tue, 07 Jan 2025 21:34:50 -0800 (PST) Date: Tue, 7 Jan 2025 21:34:27 -0800 In-Reply-To: <20250108053428.1724490-1-irogers@google.com> Message-Id: <20250108053428.1724490-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108053428.1724490-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 3/4] perf parse-events: Set is_pmu_core for legacy hardware events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Leo Yan , Yoshihiro Furudera , Weilin Wang , Andi Kleen , James Clark , Dominique Martinet , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Also set the CPU map to all online CPU maps. This is done so the behavior of legacy hardware and hardware cache events better matches that of sysfs and json events during __perf_evlist__propagate_maps. Fix missing cpumap put in "Synthesize attr update" test. Signed-off-by: Ian Rogers --- tools/perf/tests/event_update.c | 1 + tools/perf/util/parse-events.c | 37 ++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_updat= e.c index d6b4ce3ef4ee..9301fde11366 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -109,6 +109,7 @@ 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"); =20 TEST_ASSERT_VAL("failed to synthesize attr update cpus", diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1e23faa364b1..4bda4141e9e7 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -231,21 +231,30 @@ __add_event(struct list_head *list, int *idx, struct perf_cpu_map *cpu_list, u64 alternate_hw_config) { struct evsel *evsel; - struct perf_cpu_map *cpus =3D perf_cpu_map__is_empty(cpu_list) && pmu ? p= mu->cpus : cpu_list; + bool is_pmu_core; + struct perf_cpu_map *cpus; =20 - cpus =3D perf_cpu_map__get(cpus); - if (pmu) + 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); perf_pmu__warn_invalid_formats(pmu); - - if (pmu && (attr->type =3D=3D PERF_TYPE_RAW || attr->type >=3D PERF_TYPE_= MAX)) { - perf_pmu__warn_invalid_config(pmu, attr->config, name, - PERF_PMU_FORMAT_VALUE_CONFIG, "config"); - perf_pmu__warn_invalid_config(pmu, attr->config1, name, - PERF_PMU_FORMAT_VALUE_CONFIG1, "config1"); - perf_pmu__warn_invalid_config(pmu, attr->config2, name, - PERF_PMU_FORMAT_VALUE_CONFIG2, "config2"); - perf_pmu__warn_invalid_config(pmu, attr->config3, name, - PERF_PMU_FORMAT_VALUE_CONFIG3, "config3"); + if (attr->type =3D=3D PERF_TYPE_RAW || attr->type >=3D PERF_TYPE_MAX) { + perf_pmu__warn_invalid_config(pmu, attr->config, name, + PERF_PMU_FORMAT_VALUE_CONFIG, "config"); + perf_pmu__warn_invalid_config(pmu, attr->config1, name, + PERF_PMU_FORMAT_VALUE_CONFIG1, "config1"); + perf_pmu__warn_invalid_config(pmu, attr->config2, name, + PERF_PMU_FORMAT_VALUE_CONFIG2, "config2"); + perf_pmu__warn_invalid_config(pmu, attr->config3, name, + PERF_PMU_FORMAT_VALUE_CONFIG3, "config3"); + } + } 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 + cpus =3D perf_cpu_map__get(cpu_list); } if (init_attr) event_attr_init(attr); @@ -260,7 +269,7 @@ __add_event(struct list_head *list, int *idx, evsel->core.cpus =3D cpus; evsel->core.own_cpus =3D perf_cpu_map__get(cpus); evsel->core.requires_cpu =3D pmu ? pmu->is_uncore : false; - evsel->core.is_pmu_core =3D pmu ? pmu->is_core : false; + evsel->core.is_pmu_core =3D is_pmu_core; evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; evsel->alternate_hw_config =3D alternate_hw_config; --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 19:16:31 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 A87EF1A706F for ; Wed, 8 Jan 2025 05:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314495; cv=none; b=Hm98I+4GUWBLxta/+C6VETFYQnkx+/Aa7MA4/clpt11e9CjKYE8u85uxYTkvURjqvCWQ2h9mZbDJbSjMFH/7kKJqkzaIytW6kWlqfCmyMcFjN3DPozCPpvGr1HXDeRxCoqUDW/oKbMGU+/Kv+Z9kTr/O26Q62QwKUznHkRH2Fsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314495; c=relaxed/simple; bh=ywjvsWJNxLmzM3YIwbYYswpNEHZxKvufAxgc8RsNSbc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jpnQOXWppVYaUKtMopM81y4hFZFTuCQevhIXwC+ENX1LAbxFcJsF7GPz3WsZEXtRL9livlTjA6aeEfT0/6ddgOEvBVagOuMQrXyBQpASC9aEjganBe0RLbM3KeQaAcOi1i4BCkuIc0cVwVddJIy0HMl2yxA5Kw7crkkGuKiisII= 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=gHShGJIV; arc=none smtp.client-ip=209.85.219.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="gHShGJIV" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e544c8dae18so20213390276.1 for ; Tue, 07 Jan 2025 21:34:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736314493; x=1736919293; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=XcjD+oXNLY7oywMEC3LvBmYCeG/3kMVQ1vWw9hGSJM0=; b=gHShGJIVO0PMSPbryqkCyPOs2pWEZizw06AbyAsV02oiZngRSaMVq0XpPi54TjJiUE xDEC2TLIj2h9j3ZF5z3ljBYbp11AGLN4yrpoaNaREfetB4dntcKuVHmmeOufsomR9yeh K+lWCSt12rKR8qUeR82FS6TpBd4RAIBFJr64nbr6clu5vfTGr/B1/BMzvG3R1Tn30gV+ dmFCw+/ntc8xJiw18nSbvys1+Ye9G6SoyctCUVVI+ERZKsrDcMevnCtTEtlGxA0IGC+3 5PvcBi4oBOXJP9zkQ4HZmHi6x0ZnLRoqILqFD92p2WQ03lOVcG5PrRP9Rd6bMJhppfPR F++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736314493; x=1736919293; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XcjD+oXNLY7oywMEC3LvBmYCeG/3kMVQ1vWw9hGSJM0=; b=PzJdsrLFIQvRuVKoImYo2JwmCEV5KoYzzdXqolXBQ57TqrFfKl5jOlnb/+jRDv60pN qXpjPoKpCYyuvhppLja57TpV7wJi6rb6CChlabMadTtb062zJMVO/Iu+RnpVb2V47pF/ SAUHYRyys9iZByv827UvdQiN/epHEd+xR3bph9xfhPzUQioxzNHH/lU6J0fdaCxRPYqC hrgVg+6bvPVqY3E73QluzaxQG80+S3oNKH00xvEG0U/Hpf01e0QxHVV6IAsv5gNL53wL MPnDxCFqIB/OtKu1xEwpmbSscONg97UfwfQmx41DR7UYCHVOKEJAKzJZDe3Qyy0OwFgy Xl5A== X-Forwarded-Encrypted: i=1; AJvYcCUnk3rhLzw48mjdqyBh7404enNsw1824AFuJGiiivwSxVFQdD04VFLB1Npj+KScG5x5oa64n+2YkYhJoOI=@vger.kernel.org X-Gm-Message-State: AOJu0YwCRjTWy+ZxDAHmpybiRRM8M8msBz5HJUmzLH7KSMUd/ZRYWy8J H7PfNxtqOJn525tWehQklAewzz3kBe2uh/jks4HHCt4WezJcy3XOEIxLSZqXElenlxAyp5rhwsz Cwtl5LA== X-Google-Smtp-Source: AGHT+IEW9+WqALHzqTdZt6mmp40Bu6OzzY4Eg/OXgZx1NeC6753KkNiIRxAOLHlol1lIM4PvLR54hHNmI92D X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:7ae:a887:5504:e3ca]) (user=irogers job=sendgmr) by 2002:a5b:642:0:b0:e39:6fdc:5567 with SMTP id 3f1490d57ef6-e54eddd285bmr4357276.0.1736314492910; Tue, 07 Jan 2025 21:34:52 -0800 (PST) Date: Tue, 7 Jan 2025 21:34:28 -0800 In-Reply-To: <20250108053428.1724490-1-irogers@google.com> Message-Id: <20250108053428.1724490-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108053428.1724490-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 4/4] perf parse-events: Add "cpu" term to set the CPU an event is recorded on From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Leo Yan , Yoshihiro Furudera , Weilin Wang , Andi Kleen , James Clark , Dominique Martinet , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The -C option allows the CPUs for a list of events to be specified but its not possible to set the CPU for a single event. Add a term to allow this. The term isn't a general CPU list due to ',' already being a special character in event parsing instead multiple cpu=3D terms may be provided and they will be merged/unioned together. An example of mixing different types of events counted on different CPUs: ``` $ perf stat -A -C 0,4-5,8 -e "instructions/cpu=3D0/,l1d-misses/cpu=3D4,cpu= =3D5/,inst_retired.any/cpu=3D8/,cycles" -a sleep 0.1 Performance counter stats for 'system wide': CPU0 6,979,225 instructions/cpu=3D0/ # 0.89= insn per cycle CPU4 75,138 cpu/l1d-misses/ CPU5 1,418,939 cpu/l1d-misses/ CPU8 797,553 cpu/inst_retired.any,cpu=3D8/ CPU0 7,845,302 cycles CPU4 6,546,859 cycles CPU5 185,915,438 cycles CPU8 2,065,668 cycles 0.112449242 seconds time elapsed ``` Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-list.txt | 9 +++ tools/perf/util/evsel_config.h | 1 + tools/perf/util/parse-events.c | 76 +++++++++++++++++++++----- tools/perf/util/parse-events.h | 3 +- tools/perf/util/parse-events.l | 1 + tools/perf/util/pmu.c | 3 +- 6 files changed, 76 insertions(+), 17 deletions(-) diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentat= ion/perf-list.txt index d0c65fad419a..d98de9adc515 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -289,6 +289,15 @@ Sums up the event counts for all hardware threads in a= core, e.g.: =20 perf stat -e cpu/event=3D0,umask=3D0x3,percore=3D1/ =20 +cpu: + +Specifies the CPU to open the event upon. The value may be repeated to +specify opening the event on multiple CPUs: + + + perf stat -e instructions/cpu=3D0,cpu=3D2/,cycles/cpu=3D1,cpu=3D2/ -a sl= eep 1 + perf stat -e data_read/cpu=3D0/,data_write/cpu=3D1/ -a sleep 1 + =20 EVENT GROUPS ------------ diff --git a/tools/perf/util/evsel_config.h b/tools/perf/util/evsel_config.h index af52a1516d0b..94a1e9cf73d6 100644 --- a/tools/perf/util/evsel_config.h +++ b/tools/perf/util/evsel_config.h @@ -48,6 +48,7 @@ struct evsel_config_term { u32 aux_sample_size; u64 cfg_chg; char *str; + int cpu; } val; bool weak; }; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 4bda4141e9e7..ec8429f0cf6d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -7,6 +7,7 @@ #include #include #include +#include "cpumap.h" #include "term.h" #include "env.h" #include "evlist.h" @@ -178,6 +179,26 @@ static char *get_config_name(const struct parse_events= _terms *head_terms) return get_config_str(head_terms, PARSE_EVENTS__TERM_TYPE_NAME); } =20 +static struct perf_cpu_map *get_config_cpu(const struct parse_events_terms= *head_terms) +{ + struct parse_events_term *term; + struct perf_cpu_map *cpus =3D NULL; + + if (!head_terms) + return NULL; + + list_for_each_entry(term, &head_terms->terms, list) { + if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_CPU) { + struct perf_cpu_map *cpu =3D perf_cpu_map__new_int(term->val.num); + + perf_cpu_map__merge(&cpus, cpu); + perf_cpu_map__put(cpu); + } + } + + return cpus; +} + /** * fix_raw - For each raw term see if there is an event (aka alias) in pmu= that * matches the raw's string value. If the string value matches an @@ -441,11 +462,12 @@ int parse_events_add_cache(struct list_head *list, in= t *idx, const char *name, bool found_supported =3D false; const char *config_name =3D get_config_name(parsed_terms); const char *metric_id =3D get_config_metric_id(parsed_terms); + struct perf_cpu_map *cpus =3D get_config_cpu(parsed_terms); + int ret =3D 0; =20 while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; - int ret; =20 if (parse_events__filter_pmu(parse_state, pmu)) continue; @@ -460,7 +482,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, perf_pmu__auto_merge_stats(pmu), /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); if (ret) - return ret; + goto out_err; continue; } =20 @@ -480,21 +502,27 @@ int parse_events_add_cache(struct list_head *list, in= t *idx, const char *name, =20 if (parsed_terms) { if (config_attr(&attr, parsed_terms, parse_state->error, - config_term_common)) - return -EINVAL; - - if (get_config_terms(parsed_terms, &config_terms)) - return -ENOMEM; + config_term_common)) { + ret =3D -EINVAL; + goto out_err; + } + if (get_config_terms(parsed_terms, &config_terms)) { + ret =3D -ENOMEM; + goto out_err; + } } =20 if (__add_event(list, idx, &attr, /*init_attr*/true, config_name ?: name, metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX) =3D=3D NULL) - return -ENOMEM; + cpus, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX) =3D=3D NULL) + ret =3D -ENOMEM; =20 free_config_terms(&config_terms); + if (ret) + goto out_err; } +out_err: + perf_cpu_map__put(cpus); return found_supported ? 0 : -EINVAL; } =20 @@ -808,6 +836,7 @@ const char *parse_events__term_type_str(enum parse_even= ts__term_type term_type) [PARSE_EVENTS__TERM_TYPE_RAW] =3D "raw", [PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE] =3D "legacy-cache", [PARSE_EVENTS__TERM_TYPE_HARDWARE] =3D "hardware", + [PARSE_EVENTS__TERM_TYPE_CPU] =3D "cpu", }; if ((unsigned int)term_type >=3D __PARSE_EVENTS__TERM_TYPE_NR) return "unknown term"; @@ -837,6 +866,7 @@ config_term_avail(enum parse_events__term_type term_typ= e, struct parse_events_er case PARSE_EVENTS__TERM_TYPE_METRIC_ID: case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: case PARSE_EVENTS__TERM_TYPE_PERCORE: + case PARSE_EVENTS__TERM_TYPE_CPU: return true; case PARSE_EVENTS__TERM_TYPE_USER: case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ: @@ -984,6 +1014,15 @@ do { \ return -EINVAL; } break; + case PARSE_EVENTS__TERM_TYPE_CPU: + CHECK_TYPE_VAL(NUM); + if (term->val.num >=3D (u64)cpu__max_present_cpu().cpu) { + parse_events_error__handle(err, term->err_val, + strdup("too big"), + NULL); + return -EINVAL; + } + break; case PARSE_EVENTS__TERM_TYPE_DRV_CFG: case PARSE_EVENTS__TERM_TYPE_USER: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: @@ -1111,6 +1150,7 @@ static int config_term_tracepoint(struct perf_event_a= ttr *attr, case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: case PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_CPU: default: if (err) { parse_events_error__handle(err, term->err_term, @@ -1245,6 +1285,7 @@ do { \ case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: case PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_CPU: default: break; } @@ -1299,6 +1340,7 @@ static int get_config_chgs(struct perf_pmu *pmu, stru= ct parse_events_terms *head case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: case PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_CPU: default: break; } @@ -1343,6 +1385,7 @@ static int __parse_events_add_numeric(struct parse_ev= ents_state *parse_state, struct perf_event_attr attr; LIST_HEAD(config_terms); const char *name, *metric_id; + struct perf_cpu_map *cpus; int ret; =20 memset(&attr, 0, sizeof(attr)); @@ -1364,10 +1407,11 @@ static int __parse_events_add_numeric(struct parse_= events_state *parse_state, =20 name =3D get_config_name(head_config); metric_id =3D get_config_metric_id(head_config); + cpus =3D get_config_cpu(head_config); ret =3D __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, na= me, - metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX - ) =3D=3D NULL ? -ENOMEM : 0; + metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, + cpus, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX) ? 0 : -ENOMEM; + perf_cpu_map__put(cpus); free_config_terms(&config_terms); return ret; } @@ -1427,6 +1471,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, LIST_HEAD(config_terms); struct parse_events_terms parsed_terms; bool alias_rewrote_terms =3D false; + struct perf_cpu_map *term_cpu =3D NULL; =20 if (verbose > 1) { struct strbuf sb; @@ -1521,11 +1566,12 @@ static int parse_events_add_pmu(struct parse_events= _state *parse_state, return -EINVAL; } =20 + term_cpu =3D get_config_cpu(&parsed_terms); evsel =3D __add_event(list, &parse_state->idx, &attr, /*init_attr=3D*/tru= e, get_config_name(&parsed_terms), get_config_metric_id(&parsed_terms), pmu, - &config_terms, auto_merge_stats, /*cpu_list=3D*/NULL, - alternate_hw_config); + &config_terms, auto_merge_stats, term_cpu, alternate_hw_config); + perf_cpu_map__put(term_cpu); if (!evsel) { parse_events_terms__exit(&parsed_terms); return -ENOMEM; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e176a34ab088..ab242f671031 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -80,7 +80,8 @@ enum parse_events__term_type { PARSE_EVENTS__TERM_TYPE_RAW, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE, PARSE_EVENTS__TERM_TYPE_HARDWARE, -#define __PARSE_EVENTS__TERM_TYPE_NR (PARSE_EVENTS__TERM_TYPE_HARDWARE + 1) + PARSE_EVENTS__TERM_TYPE_CPU, +#define __PARSE_EVENTS__TERM_TYPE_NR (PARSE_EVENTS__TERM_TYPE_CPU + 1) }; =20 struct parse_events_term { diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index bf7f73548605..14bff6f9731c 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -324,6 +324,7 @@ aux-output { return term(yyscanner, PARSE_EVENTS__TERM= _TYPE_AUX_OUTPUT); } aux-action { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_ACTION); } aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMP= LE_SIZE); } metric-id { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } +cpu { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CPU); } cpu-cycles|cycles { return hw_term(yyscanner, PERF_COUNT_HW_CPU_CYCLES)= ; } stalled-cycles-frontend|idle-cycles-frontend { return hw_term(yyscanner, P= ERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } stalled-cycles-backend|idle-cycles-backend { return hw_term(yyscanner, PER= F_COUNT_HW_STALLED_CYCLES_BACKEND); } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 6206c8fe2bf9..cffb4eb2696b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1400,7 +1400,7 @@ static int pmu_config_term(const struct perf_pmu *pmu, break; case PARSE_EVENTS__TERM_TYPE_USER: /* Not hardcoded. */ return -EINVAL; - case PARSE_EVENTS__TERM_TYPE_NAME ... PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_NAME ... PARSE_EVENTS__TERM_TYPE_CPU: /* Skip non-config terms. */ break; default: @@ -1775,6 +1775,7 @@ int perf_pmu__for_each_format(struct perf_pmu *pmu, v= oid *state, pmu_format_call "aux-output", "aux-action=3D(pause|resume|start-paused)", "aux-sample-size=3Dnumber", + "cpu=3Dnumber", }; struct perf_pmu_format *format; int ret; --=20 2.47.1.613.gc27f4b7a9f-goog