From nobody Sun Feb 8 10:49:42 2026 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 5CEDC25743B for ; Mon, 10 Feb 2025 18:38:16 +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=1739212698; cv=none; b=osxV2Plw+0Ypi62C78hF/wb1xOZEPbq4SzpebGPlAYLxenZLhyf7tK+xOeL1rVKZFRc9KcX/YAYP+1kJl5kcYTi8OghjXxpJMoFIieVa3xANZ4/GZxTCJ1fihpbXjm6w6NA4DkeyVGOShAQS/xSaASHZ/yEt/x0hTv+SU4/ACEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212698; c=relaxed/simple; bh=OFakRqNQKHADdpdhmZgfVErGfxtO80Hgq1mtytTW264=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=fUfmmnCoF7iiT5c0DHyYLRdC25pRqaIOhHA0Ij3ssgmARhwmGb8/dX+jaF1Mwaix4dcFxgIxLAz+qs9Y1V2TeRTBxeeHvkHFkglimFMi3qeASP7U2VIe8z3mKnTrn/61MF/OR4asIoJk57ebKAGUCMraeQOMFArllL/B8rN0xdg= 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=qtqYaJwH; 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="qtqYaJwH" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e5b2bf5a317so7255130276.3 for ; Mon, 10 Feb 2025 10:38:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739212695; x=1739817495; 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=vYBVa7z0m4z3JsO7DUulpiX1vMOJnR6DEMUcDKBuhfA=; b=qtqYaJwHcdPbGa6uWIo4NL37DHQxutq+G1HWSKu9sCcmi/Q2xzHRgTy2aml6ep5QG+ Pid4BuVBXLm/ZBkcJoPWYH6JCDO/xiRYvdX2Pnt9OKINUQM2hIhVT/DsXXBhWufr4Khl Bqegvo9SsGH1j249gBHsRvmcaHtCDb+l1kBT2zrh+wbVN8mbLxjbY+XbY7GooIX7aBwg HJXH9dhph+ARkxHgDhzSM9UykfB9d9FcRHYdUhoyXyGhfKWWHoxlee+aIHsicgleplCN iK6qeq3urwPd8dEejrPEFwDXR4h1fGM0C+lvUlLG8f/74WCdB2BUXRaarjUx8xI1W5qL QzQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739212695; x=1739817495; 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=vYBVa7z0m4z3JsO7DUulpiX1vMOJnR6DEMUcDKBuhfA=; b=blS+8Px/U1InGTUXDbuPTdyxk+//affoPLD5l6nBaZZmxPcJ2ibPjVM2KS7zCa4SDB pZv5aHK9y62nc+Cl2bslju+F8bu/j0Mpms9gUnTWL5OHP8/X58qIReuautUcLlDO4xhi lPJdJOTXIQC2OqskDlqkBNMoxlCyAaHYDPaYa/HHZ9sisEmrwWVOwODY+Ej2q5e13d30 ifaTGk7SdeXRzYEFrBxktjAQbL8qhUWOo/7Wjam46ltDZ0ubz8fnX/on0Ni5Y8Gz4wMo XY6XfZCnbTI6Adx9ffK3uqJxqs9UOljffU/AKiTMgWWX/Vsyi/0/0tk36dj+Mw9ec/gF pSOw== X-Forwarded-Encrypted: i=1; AJvYcCVM8p8RRYNHEl0ufsXxhBG5yqorfzS2yv6u9FebCGjvj0SuDqoU4B/WOnHLl9Ji48sPtjitwFScQoiwQ1M=@vger.kernel.org X-Gm-Message-State: AOJu0YwvGNJd+LQoKBQoQuN+PQYpiPpkuXQltAjnfT3BPyE1fzuJqC/s pqFKvUU9Mk+BzWEr96npj5MomiXC9UbGdn0hOtHcECQmItz8cEk7Hj8vbHg9NrUiVOXMEsBGGnL qwMQSag== X-Google-Smtp-Source: AGHT+IHKeCisUol3zDmhjIr5zbOJ7wY6aZEFAXOChmLKaU4l4cT6Voj+AsLIzjf79+Pu4qf2BTOgzii8z1sH X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:c64e:af58:30d4:168d]) (user=irogers job=sendgmr) by 2002:a25:7a44:0:b0:e5b:3445:d33c with SMTP id 3f1490d57ef6-e5b461801d0mr111693276.3.1739212695310; Mon, 10 Feb 2025 10:38:15 -0800 (PST) Date: Mon, 10 Feb 2025 10:38:05 -0800 In-Reply-To: <20250210183808.130522-1-irogers@google.com> Message-Id: <20250210183808.130522-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: <20250210183808.130522-1-irogers@google.com> X-Mailer: git-send-email 2.48.1.502.g6dc24dfdaf-goog Subject: [PATCH v5 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.48.1.502.g6dc24dfdaf-goog From nobody Sun Feb 8 10:49:42 2026 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 6D937257453 for ; Mon, 10 Feb 2025 18:38:18 +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=1739212700; cv=none; b=iayfIID0kLZeyn0ZxfdJDlcpzPwCnNXYN+pbd2Co7nMrYk5r4Jg2UqH1m+ugp7gm0l+ANMN78wXhFSmCRGkS+ESqmZg7T0jL8lP+v7l91vlzOOLrrQos4IvBGuFQ0scyfYE8soCw8r/2f+fTonTQs6J9vOYdxvfWbQV6EG3VDpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212700; c=relaxed/simple; bh=6ixW3uqiFvuVD+HyDPYyEDMckDxt6jrLcM7mLWSWT0Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dvv4GKo74EUKe/c19gmrsTm5wyhCebuDbSzMR6Ere0Qj5kFcR41RE6wK/sLUTYSiiSuY3IcKNhF13suetBVigUjQvlSRYBiDg5YQDJ50Xkn+lF/Kix+uhVJ6uI7hNL64ir3Gl9ug0gOJrNf1hAQyySVbXjmA/6o9IoIP2sxrFmY= 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=rj+Wbo4I; 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="rj+Wbo4I" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e5b3ae2e0d9so5755070276.0 for ; Mon, 10 Feb 2025 10:38:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739212697; x=1739817497; 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=HCljTNPPwHKTDTDfBQ8knfX7jWJi09j9Ne8EmTtzMbc=; b=rj+Wbo4IrdqiKPq7fPxzwq4og/dn5lf5HVF4v9SCGpNciqwQt0mr1MIU8JSqL5hJFE rEpEduaTca1qABu0c1BSc07NnIyfFy1iiscbtDolkts0nb1mtIn+Qwfn3OIsANLeqFt0 nvQlfLUu7/qCudzAg7HCteeUJ7fm1UhY7ct5cnBJ2jnm37do0rERqoYPZcIQalIaskkp eXSv5cPBM4jYygcgT6pghc3X/3sqFYasXd3h7U1mn7qpLLr6fU17BeMYs7100XihQw84 KZMR7n1cKmqKGsnCrQluqIFgvjFpCASJ1OX8hMzB5s9O+r0YWfvzZnsuP/mAYA3Kew0Z 7h7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739212697; x=1739817497; 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=HCljTNPPwHKTDTDfBQ8knfX7jWJi09j9Ne8EmTtzMbc=; b=wus2Y/EOz3HG8Xm9UKc69ExYQHyq+L0zp+ZKmyZnRbr3xY+WHneRbiISyz/bLcoldr IRMCSdkM4E6ncYOlW5dqrY/I74FaJrG+TrflXQDJeCSC/T8kMPDgQq1y+4+b61w4FvLt HWmCFG2tCUihaT4Wp8lGaZTiZlWAHe+yiSFQsVW0tsmLriU7FLUibNnTFc0ViKeHqm8+ 3BYJVb7T5+dHtMm8o4qQtASbFQZ8AiUusWWJfN2ilN0VvHc5My95I5Cv96yIrDO/p779 ZYeYNajvToBGruZUQnHzO10hCW1pJhU/ZST/WA7+OQR0voS7UlAliDVNyq6giLtJM/SJ N0Ow== X-Forwarded-Encrypted: i=1; AJvYcCUbCMqp7zErwHMfRiWpb7VXR/KRv+4myo55B8RL2b+PzC44M8EijKueVT9u8jZHqfmr2li56Va1DJsIkds=@vger.kernel.org X-Gm-Message-State: AOJu0YxM50HD4mc+qByi+UgBVNkEz47uHg4eZY8X8irQusoE9xh3zWMD qTMYrv1q/b3eiiVqDAGohiVxsQOsLD1EJ64zAdJwP7q/O4VbARDKviny7rODXgTGQQlRE2+BNt2 8a4ChOQ== X-Google-Smtp-Source: AGHT+IF/3fXdDMGjHwsubbKV2X/CqJQNFBb0YnBrBMqMQu/nTbASFKI5+C4RdgJWfhkPD5Ov2HtATvcRKtCT X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:c64e:af58:30d4:168d]) (user=irogers job=sendgmr) by 2002:a05:6902:1365:b0:e58:98ba:77a8 with SMTP id 3f1490d57ef6-e5b46261c65mr114792276.6.1739212697325; Mon, 10 Feb 2025 10:38:17 -0800 (PST) Date: Mon, 10 Feb 2025 10:38:06 -0800 In-Reply-To: <20250210183808.130522-1-irogers@google.com> Message-Id: <20250210183808.130522-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: <20250210183808.130522-1-irogers@google.com> X-Mailer: git-send-email 2.48.1.502.g6dc24dfdaf-goog Subject: [PATCH v5 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 e65c7e9f15d1..126fe6cc8893 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1022,8 +1022,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 @@ -1031,15 +1039,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.48.1.502.g6dc24dfdaf-goog From nobody Sun Feb 8 10:49:42 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 7AAB1257ADE for ; Mon, 10 Feb 2025 18:38:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212702; cv=none; b=CmrP6ylE8xd0qZNHi3fbnGHuZ3SUnnzmEGgtrdHA45LohwGrKhZRU775BDHqU+MJANmLTbhS2iX6ulpWhSqlBQeORFHWIPUcJ+fOtBQ7AmJ0HRtcLkCRCNYT6PqxNncCmIq5LI3DVtAO/F7xKJS3DYHwb/843zdRLE9OOtkJdrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212702; c=relaxed/simple; bh=vzR5dnuhJdQwnCFop8Hjt6OgqVnfdAEzGZEHKRU9r3Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=lAN0/Ntz9W+wtiHDKBahHgRByTZabjvjKOsj8m03EWCSzxHrt9X1upaluF6POq5rIGj8dBZwQHTSFVditn+BOG+BlPSUJo5LS+K6Tj3FC8gArcg29I9tYvVsNlBp6iNcOFtocPIbr4+5iBXbSglyx0DZqvsN9Z+1EFd6aSCHtZ4= 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=3WQxRp8g; arc=none smtp.client-ip=209.85.128.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="3WQxRp8g" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6f3ff1ff13aso70226367b3.3 for ; Mon, 10 Feb 2025 10:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739212699; x=1739817499; 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=zE/xALH3ZlNnHvoxZ6fWkHxnSbY7yQ3Nej5cU7cHGVE=; b=3WQxRp8gevlCvYKOymSsVKUYMnndo4BS3U2J40lOvEDTNOJfmBVT/1ErM5jxg0lpSs 7cVBFcdXFTHyMihSMI5FU23NJV/7/oG41xYnUbdQPHjJq0Ycp0berdMJvmsvmHZxW4fw cPpbA5LLhNepDuuv8qNowJawMJ39p6gGeBOBx3t9PUBYrMPrc1jdUlxYH43p8rLnNPK8 LhuDPou8+lBWyWf/MaXd0epO16Hk7rJ7Sh3m06JKVBasn44bj17icfOz3Bw2ykXHqgXi tX+EVK/AOLq9Lnj+N5objzL555aKDbeDcSabcCSguL8xTzOd3Z3WpWyA1oCPs3jPEZiv njDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739212699; x=1739817499; 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=zE/xALH3ZlNnHvoxZ6fWkHxnSbY7yQ3Nej5cU7cHGVE=; b=LdrWsJbj/SPSok8uCuAPgIbhokCG7Y95DrlxsO+ZYtOtfcqlEZwPuM1qQ8o2NRyy4h 5o9TfrcqEXdOm6zrbxKUTMpsUd0O8McpHV935J1DXAkTNfDaOTfHX7dnlbasyAJW8gaN YYzH2UYjnDjtaMM2RG/sPPWdIttuTP/XBaIonS5TnQPWl+19K/p3PZYAD/ZZbZ0bjSvK Le9WdO2JcBRFQk6AqYoXwzs/WFkn2TdoSVi/b370g/CL6g9Xu8BxWy3Uy+mdNac2GY5G ooA3Pct4RI7dVwaWTRKLWtYCCAb+bd+rckkf4cNMNxmysjJd+gepno9aUnzx0bz9Yt/q DirA== X-Forwarded-Encrypted: i=1; AJvYcCUducQRDn1dNh5mhI946rm5gJa0ycvE8brxX/KUEaiHVXmC9E0KUSaLh4YBVskLYyiJGlK5u5vH8srtees=@vger.kernel.org X-Gm-Message-State: AOJu0YwbRtx9H2zk5IxECmerpU33NfxzPkwxhw6JtYTxk1cuu5tb1wo9 lC2t/KApx+9Y58KWGdcakhnJjkW3b/0bvbg+STlfSWQ0NqfpRhaV9SZwyBHirMRtl9Cs5qY4O5w YvbHpWg== X-Google-Smtp-Source: AGHT+IGSXC7oLNGvNYsSKydOfp1VLqOjftKvAPrI7Jeo4bci0el2VhPVUjCWQFgWVbZxKP5hoCQI33JGd5EM X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:c64e:af58:30d4:168d]) (user=irogers job=sendgmr) by 2002:a05:690c:2fc2:b0:6f4:beb3:1d8b with SMTP id 00721157ae682-6f9b2a0e02cmr1182077b3.3.1739212699512; Mon, 10 Feb 2025 10:38:19 -0800 (PST) Date: Mon, 10 Feb 2025 10:38:07 -0800 In-Reply-To: <20250210183808.130522-1-irogers@google.com> Message-Id: <20250210183808.130522-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: <20250210183808.130522-1-irogers@google.com> X-Mailer: git-send-email 2.48.1.502.g6dc24dfdaf-goog Subject: [PATCH v5 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 6c36b98875bc..8cccf1e22cdf 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.48.1.502.g6dc24dfdaf-goog From nobody Sun Feb 8 10:49:42 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 BACC425A2AD for ; Mon, 10 Feb 2025 18:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212705; cv=none; b=iFPhLSjCNkegJrhgSjnWlO6z3oa5J/xOi6BwqmqLkikWk/1auhtRpKqX3KpkACTcwCUtjHQB2rfC8GKr/V06U1DtCTeyPgvLLn7iNSxKEGkf3NpGLEZ+Mh/EGohtOPIjWTaM7DTk+UuSK2DD6XWTw1mmZjoWZJEKCqXDMdixRco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739212705; c=relaxed/simple; bh=5S/OIgcn2deCugxjNMcpYyQFGLB77gbyEPATklDG9+0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=f1t0YzM9xMvBy5ufPX4tLsNqiGTq0knrz7KYlU37MK5n/2SfnSFGOVLuYCQgDv7tyctDr4SzTDC9w2F5mi1reLVl7z/Xe/ykyDdEMZfzsRqV18y6h3NFhHHFuofzqrHrEDjVcTO4OBv0nEl3RUCsJQ8MsDGRJcEsM1Z7RNcQUsM= 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=WiadKpBw; arc=none smtp.client-ip=209.85.128.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="WiadKpBw" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6f97ec73df7so26452837b3.1 for ; Mon, 10 Feb 2025 10:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739212702; x=1739817502; 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=EAybgbAyRjsxbSgnJKOdBfIjhewPK/g36HI/JOok4tU=; b=WiadKpBwWRsau4iiXTAtnXdQ08yUkbHuJlKcmhU4NjCF6T0Ha16NBEGpwvO5IRXFbT X+zYmtp+tJFUft7HT6UyY72jpjlHVwnuD96/PVw9jJMWBr+s4hgjg+M0ZPQVq6ZMyn9F obN0ddFH1JySnDH7rHUPaw+Y0ZOyV2WTKTxwqdQt+pGth6Mh//Aw3xsu2UHUveL6yqVj aGR+SLzjEOJQTFfOLjsVtGNPAA3dXw42mPxxulX0LvnhSxIFQQs6LXOC/GmVBhcpvKMQ LwELTqHNlUOW0EUb1FG1Qp1aKRPPoFa34hlJLyO3MArK0MA13sVSIxE4rItpsi7oroNP 0WHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739212702; x=1739817502; 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=EAybgbAyRjsxbSgnJKOdBfIjhewPK/g36HI/JOok4tU=; b=sggAF0CFA2vpQ1WvZNMdiRCfDXEIPk943w5vfFE+nLhgEjnJ/P1vbRgP0dgqT/H52w 5XWTlUdrXpJp38sm4Ryt5PMlf7dlKIHiIk4ZECQDwggpHXVV2fWZIFEK4ZojGgtroDdO SaF4ygT0sfxUkyLGVvfoNjrTOIQ+PEOQbTkHTDTINhGkJ6wwXWJUlFMlTu7bNuqsiTDv cfQs5uotFPtocJ69JtGb8PlchG5V7pUrOr+DAgovYTMQfx9NOPc0poc25a3zuyF1JC4Z So7Lfg/95U/akPI9+9wQJTpRgJM+y78hl0dVol8L3rB87mclfRLtMbAq3NscJdxqyTI/ 1Gvg== X-Forwarded-Encrypted: i=1; AJvYcCUCYvXcYwBNQYIi7ljFL53zbwH1hCYu7ut0JU7iz6LbdzlqoibxWEPEM7AhIMQLpDGQ2CWFG8zquli94hY=@vger.kernel.org X-Gm-Message-State: AOJu0YwOeOJurk3kJgjxlEQ5sNZi4LBHvuL5hud2vYafkkf9Al9ZCcPC 4oq4gxR4l9TMqeyenL2h0Hg6jy1QuAwfvuiS8ds1CPnlkQj9yEy6YKzRNSf6+a4y0xRGL6RaTuw dHkmxvQ== X-Google-Smtp-Source: AGHT+IGPswsl9mVUms6BzmbQlBMGBLvKfm3Zc2+LBruPfvqRDJ1/0exb9i8KzVaV/jVDKAUKh06GzBJR7xgs X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:c64e:af58:30d4:168d]) (user=irogers job=sendgmr) by 2002:a05:690c:3703:b0:6f3:e216:9dd with SMTP id 00721157ae682-6fb0b5ce97emr68067b3.4.1739212701710; Mon, 10 Feb 2025 10:38:21 -0800 (PST) Date: Mon, 10 Feb 2025 10:38:08 -0800 In-Reply-To: <20250210183808.130522-1-irogers@google.com> Message-Id: <20250210183808.130522-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: <20250210183808.130522-1-irogers@google.com> X-Mailer: git-send-email 2.48.1.502.g6dc24dfdaf-goog Subject: [PATCH v5 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 8cccf1e22cdf..55aa35ffbb4a 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 c2a15b0259cf..f84a9bf810bb 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1433,7 +1433,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: @@ -1808,6 +1808,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.48.1.502.g6dc24dfdaf-goog