From nobody Mon Feb 9 00:54:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD63FC7EE2D for ; Mon, 22 May 2023 06:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231892AbjEVGrI (ORCPT ); Mon, 22 May 2023 02:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbjEVGp4 (ORCPT ); Mon, 22 May 2023 02:45:56 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33892E59 for ; Sun, 21 May 2023 23:44:48 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5308f5d8ac9so3103256a12.0 for ; Sun, 21 May 2023 23:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737863; x=1687329863; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=72TLmH2W4t53itRP03fYxeW8kLc6/TPjYOWxUzORf6s=; b=PkcphY2m0bQMP0ZyOPR2RVtJqOGpihkKEzqjJx2gsfkBHgH0/jhHTds2NEz+jcqEaQ GEZp8iaHj5YbTLwfpGDM1VWbzKUQb3ZwD5qVrIScXOptbBakU1B9WWl6OMzvvDXD/qjr 9NjnR1NwhWK93augXd2wfjyijzsVpZY5zogVBdbivezR++w7GWS2bmikbkuKyJT1fhk9 mvt627X1v5l8MOerB3HVmQIs6QqpC9Lh17LK6CA51uEMojlHr/rXQ01IkLE1linnl4be h5MyEujS5CEJoUhlUJL+G+nb53xhyD5JClPjM/E/b7YApOJagzbyhKTXcDIamxfb15x4 Tznw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737863; x=1687329863; 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=72TLmH2W4t53itRP03fYxeW8kLc6/TPjYOWxUzORf6s=; b=KZfVNvxy942ziEIJmjP1Nm8R8yNcRTV2/RuhPiZvw74t8/e2rjRcs1dEfnNGXSRQad aPaWZ4LD8j+0iy39Ui0FjSSpm/bUQRlx3GR2NW+di4765Yqb4Lg8uRJ7j79R36F5mhX3 FfZFv+cAuXKBvk0b6RdZxd81dURSdjms8dkkzn0ndwfoKQuiH2aAzIn6Qe0ZNqQFdGi5 K8j6jS4GbBU7mX/iFB6zMCyZ6uBtWYGrFXrMT4jVs6FMlJTi9KLsPTSAHSvgGk3YkNTT /a7QXl5RYQTzrrAfit28XAfscpAbln4wW2HsIzZf20PRg6ETqdqZ5HHk3wiYmdCSA8be t86g== X-Gm-Message-State: AC+VfDzSEss+EQpH8hEom53aPNrewJI8fEIqT/cRxw7X/21tnHlHgGD2 kSP/3VH9rAAJ0wmmxbGfhIsqXFPubqL/ X-Google-Smtp-Source: ACHHUZ7jra7VZJT4OEslfuoWrE8z9a03q8ZBonIBgERnfxnhpKhmMegq1vNMXydobj60GaqrAsHWT9h/tiWA X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a63:da02:0:b0:520:4dfb:530a with SMTP id c2-20020a63da02000000b005204dfb530amr2200802pgh.8.1684737863132; Sun, 21 May 2023 23:44:23 -0700 (PDT) Date: Sun, 21 May 2023 23:43:27 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-21-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 20/23] perf pmus: Split pmus list into core and other From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Split the pmus list into core and other. This will later allow for the core and other pmus to be populated separately. Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 2fb28e583366..10f5648073bb 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -12,13 +12,19 @@ #include "pmu.h" #include "print-events.h" =20 -static LIST_HEAD(pmus); +static LIST_HEAD(core_pmus); +static LIST_HEAD(other_pmus); =20 void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; =20 - list_for_each_entry_safe(pmu, tmp, &pmus, list) { + list_for_each_entry_safe(pmu, tmp, &core_pmus, list) { + list_del(&pmu->list); + + perf_pmu__delete(pmu); + } + list_for_each_entry_safe(pmu, tmp, &other_pmus, list) { list_del(&pmu->list); =20 perf_pmu__delete(pmu); @@ -29,7 +35,12 @@ static struct perf_pmu *pmu_find(const char *name) { struct perf_pmu *pmu; =20 - list_for_each_entry(pmu, &pmus, list) { + list_for_each_entry(pmu, &core_pmus, list) { + if (!strcmp(pmu->name, name) || + (pmu->alias_name && !strcmp(pmu->alias_name, name))) + return pmu; + } + list_for_each_entry(pmu, &other_pmus, list) { if (!strcmp(pmu->name, name) || (pmu->alias_name && !strcmp(pmu->alias_name, name))) return pmu; @@ -53,7 +64,7 @@ struct perf_pmu *perf_pmus__find(const char *name) return pmu; =20 dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(&pmus, dirfd, name); + pmu =3D perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, di= rfd, name); close(dirfd); =20 return pmu; @@ -72,7 +83,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const = char *name) if (pmu) return pmu; =20 - return perf_pmu__lookup(&pmus, dirfd, name); + return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dir= fd, name); } =20 /* Add all pmus in sysfs to pmu list: */ @@ -93,7 +104,7 @@ static void pmu_read_sysfs(void) while ((dent =3D readdir(dir))) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; - /* add to static LIST_HEAD(pmus): */ + /* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */ perf_pmu__find2(fd, dent->d_name); } =20 @@ -104,24 +115,37 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int= type) { struct perf_pmu *pmu; =20 - list_for_each_entry(pmu, &pmus, list) + list_for_each_entry(pmu, &core_pmus, list) { if (pmu->type =3D=3D type) return pmu; - + } + list_for_each_entry(pmu, &other_pmus, list) { + if (pmu->type =3D=3D type) + return pmu; + } return NULL; } =20 +/* + * pmu iterator: If pmu is NULL, we start at the begin, otherwise return t= he + * next pmu. Returns NULL on end. + */ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) { - /* - * pmu iterator: If pmu is NULL, we start at the begin, - * otherwise return the next pmu. Returns NULL on end. - */ + bool use_core_pmus =3D !pmu || pmu->is_core; + if (!pmu) { pmu_read_sysfs(); - pmu =3D list_prepare_entry(pmu, &pmus, list); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + pmu =3D NULL; + pmu =3D list_prepare_entry(pmu, &other_pmus, list); } - list_for_each_entry_continue(pmu, &pmus, list) + list_for_each_entry_continue(pmu, &other_pmus, list) return pmu; return NULL; } --=20 2.40.1.698.g37aff9b760-goog