From nobody Fri Nov 29 14:43:25 2024 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 C76481CA6B9 for ; Wed, 18 Sep 2024 22:01:51 +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=1726696913; cv=none; b=qlWfw2xA7yZ84AwBEKBmlw+7u0XW20orRotFLpSp+DLz60XvCl9leGR4XNlvubVFN1YMF5+W7TPzmeDYxbWlD1Kp9oY1xHhzx+9Mih6OCb4UHNCKYRHw5sGJKm6oaOPQKOCNhjjXYWcMCaw5WUOdYIYiTvIlXUDlxdEX+eIgzhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726696913; c=relaxed/simple; bh=uHynIhO2a6wMIH0GHztIOVR6Gu4I55/nbVHOrmgwumg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XrmMoE9uDUSZD9PhJl5jqH2tjF1Biq89h5+NoGn1/5IkywdAsfFV0B4CczQB8aXJ0PeTHQJfZ/3DfMVShjxTKJNXjkRPY4B60/Mrj0+b85Cdp5jOofThWxwT/86SJLS72O5rq/WjL9iONR7vNwjkntGMYnTMHk1LxtMFb5oZRRA= 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=BoL8Rvfq; 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="BoL8Rvfq" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6db7a8c6831so3696087b3.3 for ; Wed, 18 Sep 2024 15:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726696911; x=1727301711; 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=tA+ca2CfCA+dPHers/lEUgLS4RmANjgCVGUaPchRg24=; b=BoL8Rvfq6IWFL88D7Zfmyj4clzJQwrqW+vXxwN1dSbHqvKZvJq8Y6EpqAEFW7EsG3X oU0H+V7+Coe0/UIqC0uWW6bLv9Nvr63vLWJ2qTOz+rAAyaF0esn7TC1oqfpqrZx7mJjp rCY4C/5eOrSkzqDe4L6G7o/FuUWH61LUhhJ2DPXzBJJWHOamPWtpLlcC0AR/SJuQjPqL eVK1d4/8ovgsfnUywQIC1bRw4d6R80V9HDWsyeW31MSa4W7w7D8e8zeZ0fKQ+jYdodt6 Vam43+qlvb7Lmhiko7nTTjD+ubHES0AadXJDKRUXO1KMH1q2M6XPOQPs5nQ0wYoKyTDw xGdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726696911; x=1727301711; 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=tA+ca2CfCA+dPHers/lEUgLS4RmANjgCVGUaPchRg24=; b=vywkfi8vCJcHEkq1QcsVA8lycPv3f+2TJpTYcilpnixntR8M0y5dL+D2y+7sMfAuDd nphbzWiU6P8y3aOoy0n3ARK38u8xrDCc/YjNuWxFaj6/vIPXFdy/FPDQJf5wpVNHhW5M ZUQX7vuF3LvEqLOEqkozwrdJNNorZcHqw4ARvGJCTB5bYXEDGD3MSctFX08yKU/ds7FF Wza8ng4tZwZJh6p6SLB6WmGSeE6BwRARYbGaPDnZfIJBllMIknCRa3W9W9/Jw+8qFX1C EwfZVMFfEOkevGRYOn3xSyjCNT4ksnVvJObdxhIa7wLhX+6AinnibJgTKG55L0J9EWYC T/sA== X-Forwarded-Encrypted: i=1; AJvYcCXQT0aL3efgsTPDBjhyR05R4M3i6P2Zl7gq6LJsZy2mEKdUKpCqFFWSoAbSOvMPNjliaM6O1KEdEBNhI/0=@vger.kernel.org X-Gm-Message-State: AOJu0Yykr8gREPD3qyjYDlP1UllExKouYZPCItE6CEpKLYVL87KKedLG GFphbiIRYvNMiARLb0TCL8KWd/IA5y+hVBNW9umM6hp8GM7D85VjVkJ+3cmSPxa0bAFiuNDKZbN KmmOqAg== X-Google-Smtp-Source: AGHT+IE8oGOkMGpijeUr13v+FWv/cSJFJ+UhD8kBwfC+Eau1PSptnJGHpI0SerfYTZ1mBE3UCoiS9RJhehTr X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cb6b:1e62:cfd8:bd50]) (user=irogers job=sendgmr) by 2002:a05:690c:338e:b0:64b:5cc7:bcb7 with SMTP id 00721157ae682-6dbb6acf2ebmr12290067b3.1.1726696910799; Wed, 18 Sep 2024 15:01:50 -0700 (PDT) Date: Thu, 19 Sep 2024 00:01:31 +0200 In-Reply-To: <20240918220133.102964-1-irogers@google.com> Message-Id: <20240918220133.102964-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: <20240918220133.102964-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v3 1/3] 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 , James Clark , Ravi Bangoria , Weilin Wang , Dominique Martinet , Jing Zhang , 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 cae799ad44e1..2c8e36d0efaa 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -293,6 +293,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 90457d17fb2f..79ed3449d288 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -37,6 +37,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__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *ma= p); LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *= orig, --=20 2.46.0.662.g92d0881bb0-goog From nobody Fri Nov 29 14:43:25 2024 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 579751CB521 for ; Wed, 18 Sep 2024 22:01:54 +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=1726696916; cv=none; b=g6RiWPJuk5DZIsss9Zqg0DlhPKH37EjlkyRbqjd6PB7P/v4NU9EwKt+f/O6EsPRRfg1TvMAPYKm3MSOy1YOqB8sUR/zF05t1uYLQuGROt/PLhonpSL+V7Og5iKpUjPzItcqWbaYO72X6eOs3Ff9BzSOglBF+2yObmHQ8TbaCQ+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726696916; c=relaxed/simple; bh=KNZCg/KlHW2pgZahTxSnWyKwaWdBPj34Ow4kysaSe4U=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=i+b5DSWbPt7LoYtxnvtpw0l0MDWC8+Toyri2eONudmDb5jDe+pZalOo9eYz6LvpCmUvatjmNQpt2g2vLDgymTHTzZUy0LqtErtNZbwyDjs50mocv/KygwbsrJ1j0bADRB/nF+2xGmHNyqusEWhlPujE/EjVlemge949f1FOZihQ= 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=irs3qReJ; 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="irs3qReJ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e201a37e5a4so486126276.0 for ; Wed, 18 Sep 2024 15:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726696913; x=1727301713; 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=PpZWSRVuPXgrYeZb3Xyko33SKJqhRbiuBYTdMDSjW/c=; b=irs3qReJlakVJZqOFZn4bQ9adoM4/CwQo1J+ODdP3rB2ax61OlFX2RMcO/L8BlI7oL RhuL/M4Hj3R82DNM3kv0GbaRqV0YbjIXt38KgQARUwe1eRGrt2960MjI9bochITYzNjw 51PBwwmpbXLPq9nPXNIIQGXWEA3y6QMQ38F4rhfl5gYC1OaGKs4nWMiwOope6ZKqloi0 dFmMuC+cZjbiNOyfj19FQjSsGV3QL372+QXI0AwCaL+UCi6YBvhkQDWKGpNj7zGJFOjK anf7MZH6C8VK67d2OPMm9EG+Y0p7pxzoapoBtgayVbY85krZ2l0xscRon2irSBFx+pMx em0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726696913; x=1727301713; 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=PpZWSRVuPXgrYeZb3Xyko33SKJqhRbiuBYTdMDSjW/c=; b=QsAPBI/a4KnBcApDlRtEA2N2L3j+1UE6Cot1E3G++D18jRQeYTnB/TxMahlanzSn/e bK7je5tXbpS+5TmPYCDQWgFcuPl6b8LiColXSTzq8j/lRZO0wBhn7eaOY2qhIbmAeO50 KRAF4+Z0D1V5PSBg52fwE3iJ/YWlNj58x8CGT3JYTQoctc1Rth7nJlmSBfNyXnVnGnVd 4S82qp0ITHrmquliTr4Y0EGdlcqxiKQdDIiiXUEqMbywukp2lKl6sagQ/J/9H+PR3BLO rXuKKrOQVB4np99WcT9KXG8uKRjcvl1AEwXnClUnUVo9spVF1qY9Yo4waeLotFwC8XCt GV7A== X-Forwarded-Encrypted: i=1; AJvYcCXrxzPncldH8jNWGgJbgLXLXIDmh8wV+RYlyyhA0SIXwR95Gj4/EYH58HIBvFcV7Q5e29yi/O7aDnUu3G0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+QMm84OVIW2gJ3LAUygrHU7IESwkfqJ58Ufwgarfrdk1p3jz5 5XEAu4lUUyq8AZnC6cYEeTRuUIfwwSFog4+fK0Hdxz+LLeYWURMy4NKIWuxHpowNv63Osk1/zFk TdfEwcw== X-Google-Smtp-Source: AGHT+IGFByyzSTA635/zzy6jqvvjlAYTqDNhOlOJ0fPDLGWE+Yg314bw8BggsXdq+zi3PxvZwZaXMc8KK3os X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cb6b:1e62:cfd8:bd50]) (user=irogers job=sendgmr) by 2002:a25:ce46:0:b0:e1c:f1a4:8447 with SMTP id 3f1490d57ef6-e1daff6d4c2mr23764276.4.1726696913317; Wed, 18 Sep 2024 15:01:53 -0700 (PDT) Date: Thu, 19 Sep 2024 00:01:32 +0200 In-Reply-To: <20240918220133.102964-1-irogers@google.com> Message-Id: <20240918220133.102964-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: <20240918220133.102964-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v3 2/3] 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 , James Clark , Ravi Bangoria , Weilin Wang , Dominique Martinet , Jing Zhang , 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 9a8be1e46d67..017d31d51ea4 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) { 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->pmu_name =3D pmu ? strdup(pmu->name) : NULL; --=20 2.46.0.662.g92d0881bb0-goog From nobody Fri Nov 29 14:43:25 2024 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 EBE1C1CB53E for ; Wed, 18 Sep 2024 22:01:56 +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=1726696919; cv=none; b=CVwIRC16wl/PrcZX5bx7bwO4L8oGh5tslEcLcm51aEWPV6rXtuOtMOLUpK4e4FTGq7k73o3k74xAqJ4Ah/IhsDdcl1JkiRvNHB3wX75tMtL1bSTNRyyTB43eeGSBs5c3PYBObAMN//R+sFFXYar9kXczF6JSdIpjaWoUW4tJHtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726696919; c=relaxed/simple; bh=0HmX3+oDarBi9YsEUyCZhTasjdJ8E7Vq2wgPDApLjP8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qmUaW6Xj+TmGWfQ7q7CZsSeUdrtliwEMQd2KS/I8kadhujIZu5h3SM6LLnrUqeXYVZS0uuJbSb49XOIY9HHY8hymCzFqnUppBypVjZkU+XE38f4JYQuTHAdw9bQoyImFfHDb7skvJifIftYBiAwqg/jLDbqww84Si0SuuuHTt0U= 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=mk7ahGZZ; 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="mk7ahGZZ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d9e31e66eeso3801537b3.1 for ; Wed, 18 Sep 2024 15:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726696916; x=1727301716; 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=NcM+VU+CnvqLlwnAxi53/iARGP0HqFfg/cKQ7ZCX6g4=; b=mk7ahGZZUqh2tK4Ie+OcZx47JFujrBSP+fnUI0Ks/0wm3D05K0ckcVBCbYgHcEkf2B 9KxxM4ds9kFUGcjzB+9AeXcoJxZJeGPF900R/l00UnM1Hjlgnl9vFVi1OR6+WTke3FGv 91Sznm/zyj/VtZ+oOMzds/DdStgSumpnOgTwfq2LEMCfJaaUENRkb3l54ulLZqoH3f/3 Gsi50m3A9ctar0bp6M4uS7rs7u60SalEYb13+Ov3k96/bLo1mzvahqD/2avXUru+df+e MM0R3Due0HLr/JAaBMCVFAH+hTvs8b2BYZcfG9bI7uoTesdaQ98H7Ri8VSoxxqxR2XMw sU1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726696916; x=1727301716; 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=NcM+VU+CnvqLlwnAxi53/iARGP0HqFfg/cKQ7ZCX6g4=; b=fE5OIKW9qTz54AI2wSkmDXJEjD2j9YyQ9GfaWpm0xC/gMwBR/hnNIRl3Wy3PYxayNx LiadnXX1tuz6f8h01sNx23CGQW6tUybLw27JnllehoTb+YcZg6Miv6SNAjyIIQv3sXag 8u5j12RNqgR43lFRYENL0v43mTmgO3sFkhT8l+/73HFEZpLy3jVzNZ/HdOQ9aPc/GUbu BgIxRrEnix+UYqY6z/+yHxcUmKMVVG6S7WD5MgxTPMEoI9uEi3F/5BjzkpmFgZ236UPY WiUXC4VfckLgomcc/JATIJtgWcvu6L8FMfgApJ9UpECcESmtzmNdZcq/jTXke+fLWS+n /8sg== X-Forwarded-Encrypted: i=1; AJvYcCXMXyv/z24y8QH5Q4XNZqZjzPvHs+2THgl6jri20QVTgVZ95X65aZt8/fR1oYvDXWLfyHsJDV+IdEmDpEM=@vger.kernel.org X-Gm-Message-State: AOJu0YzHIC6NE7T/ltNF2aPiHPGpzYw4Bn0omuh8svlIpdgj6x8hFgS3 4oiogoIPxfZZDlgRIR5Ai5/J6jpauF0Ff2NFvdxg44ImxKXCnxggbZc2Pc2EWi/7aTBadFp+aqL GQwSIfA== X-Google-Smtp-Source: AGHT+IHmgM+Bh5rGiZ5/+XTrkIvNyuS76NKjY1Cy+4xkAJ6JRB0yVCQnlNFZ0Erd2sOSpjTf0arogTVX/3Gh X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cb6b:1e62:cfd8:bd50]) (user=irogers job=sendgmr) by 2002:a25:ab8e:0:b0:e11:5b8c:f9c with SMTP id 3f1490d57ef6-e1dafd96ef0mr48042276.0.1726696915876; Wed, 18 Sep 2024 15:01:55 -0700 (PDT) Date: Thu, 19 Sep 2024 00:01:33 +0200 In-Reply-To: <20240918220133.102964-1-irogers@google.com> Message-Id: <20240918220133.102964-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: <20240918220133.102964-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v3 3/3] 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 , James Clark , Ravi Bangoria , Weilin Wang , Dominique Martinet , Jing Zhang , 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 368,647 instructions/cpu=3D0/ # 0.26= insn per cycle CPU4 instructions/cpu=3D0/ CPU5 instructions/cpu=3D0/ CPU8 instructions/cpu=3D0/ CPU0 l1d-misses [cpu] CPU4 203,377 l1d-misses [cpu] CPU5 138,231 l1d-misses [cpu] CPU8 l1d-misses [cpu] CPU0 cpu/cpu=3D8/ CPU4 cpu/cpu=3D8/ CPU5 cpu/cpu=3D8/ CPU8 943,861 cpu/cpu=3D8/ CPU0 1,412,071 cycles CPU4 20,362,900 cycles CPU5 10,172,725 cycles CPU8 2,406,081 cycles 0.102925309 seconds time elapsed ``` Note, the event name of inst_retired.any is missing, reported as cpu/cpu=3D8/, as there are unmerged uniquify fixes: https://lore.kernel.org/lkml/20240510053705.2462258-3-irogers@google.com/ 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 | 71 ++++++++++++++++++++++---- tools/perf/util/parse-events.h | 3 +- tools/perf/util/parse-events.l | 1 + tools/perf/util/pmu.c | 1 + 6 files changed, 74 insertions(+), 12 deletions(-) diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentat= ion/perf-list.txt index dea005410ec0..e0cd9bb8283e 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -274,6 +274,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 aee6f808b512..9630c4a24721 100644 --- a/tools/perf/util/evsel_config.h +++ b/tools/perf/util/evsel_config.h @@ -47,6 +47,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 017d31d51ea4..63c31cfdd79b 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); + + cpus =3D 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 @@ -469,11 +490,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; @@ -487,7 +509,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, parsed_terms, perf_pmu__auto_merge_stats(pmu)); if (ret) - return ret; + goto out_err; continue; } =20 @@ -507,20 +529,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) =3D=3D NULL) - return -ENOMEM; + cpus) =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 @@ -835,6 +864,7 @@ static const char *config_term_name(enum parse_events__= 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"; @@ -864,6 +894,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: @@ -1007,6 +1038,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: @@ -1133,6 +1173,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, @@ -1264,6 +1305,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; } @@ -1317,6 +1359,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; } @@ -1371,6 +1414,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)); @@ -1392,9 +1436,11 @@ static int __parse_events_add_numeric(struct parse_e= vents_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) ? 0 : -ENOMEM; + cpus) ? 0 : -ENOMEM; + perf_cpu_map__put(cpus); free_config_terms(&config_terms); return ret; } @@ -1461,6 +1507,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; @@ -1552,10 +1599,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); + &config_terms, auto_merge_stats, term_cpu); + 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 10cc9c433116..2532c81d4f9a 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -79,7 +79,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 5a0bcd7f166a..635d216632d7 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -331,6 +331,7 @@ percore { return term(yyscanner, PARSE_EVENTS__TERM_T= YPE_PERCORE); } aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); } 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 61bdda01a05a..4f68026a97bb 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1738,6 +1738,7 @@ int perf_pmu__for_each_format(struct perf_pmu *pmu, v= oid *state, pmu_format_call "percore", "aux-output", "aux-sample-size=3Dnumber", + "cpu=3Dnumber", }; struct perf_pmu_format *format; int ret; --=20 2.46.0.662.g92d0881bb0-goog