Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp154058rwd; Wed, 24 May 2023 15:52:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/vHZ4wpiYWO8cLa6h6K5aN7oze/DIfUhDFIriIU+7haVMvjaRnna6pvWe9oqgao656HgR X-Received: by 2002:a17:902:e808:b0:1a1:cb18:7f99 with SMTP id u8-20020a170902e80800b001a1cb187f99mr816574plg.30.1684968774656; Wed, 24 May 2023 15:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684968774; cv=none; d=google.com; s=arc-20160816; b=BYTxYGAbZse0vbItPEDGtbFlpH9b3V2pcs8+wcdSgvyPluallTdVZtR02gDJl7THMY 4zfE/oPjwbGye8C54l5cb1rElFfycgYq1OcO2Hiva8NcQ+dxnf6YgszBBpOworw64VUh UNIQmmY+8dZNFZNCLhBF2JaaiFPYK4aqqaHuvb3dhizloH3ncY/4X/UFlmy2wwiACKUH XZQuQ1uyAO8W2xr7EPn2lWJnfTpfd3vC2KrRPFwOYRHs2V4jLxPU08sHyedgAzMf2+UV yFXIIY1URxT6OOREdECxaR16LzGOZdwoPoMBxhbqfygh1oV+tsUN6aGLxSVtUN7ZMh/e c3eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=GMM9vMp4aqYytcqLPDz/iiJMs6KDe9Jl9sq1ptTjl+0=; b=SmQh1HejVPNi5hMqeVASzVucZL6FeeSzZ1/++yhlaGxBi50RJln5zaj2BRoz5SqYYi mUIhrlmQVtG16mg/syiqCX1K4UNocNUAThpm00miWYNnSTOpeWbxmCUisCKQkzU+B/hA IMtwwYzzHmxdvTnnMGRPx7rnrvBO0rC2E+6Gk7QJ44majdX9E30ivD2K7X6UwEe7y+It 2K7N570ZnHtLJGZ73mtpCmeP22zIeZsggf/3MxrgHvTp4TmTkGiFsAbQ5W6UU2G4flN6 ZWjwfMGqgC268mooI0le1bYj/KY7ZZjIWc/1i+TIKe4yIvfTLNLYNAZGJjBcabOagB61 UCgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=MvmCy8eC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170902f68f00b001aae90dbcc5si2525397plg.459.2023.05.24.15.52.39; Wed, 24 May 2023 15:52:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=MvmCy8eC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238290AbjEXWV6 (ORCPT + 99 others); Wed, 24 May 2023 18:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235667AbjEXWVY (ORCPT ); Wed, 24 May 2023 18:21:24 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAFEDE59 for ; Wed, 24 May 2023 15:20:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561bad0999aso35279357b3.0 for ; Wed, 24 May 2023 15:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966782; x=1687558782; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=GMM9vMp4aqYytcqLPDz/iiJMs6KDe9Jl9sq1ptTjl+0=; b=MvmCy8eCu3J+48fIwJySu6/NGqr6B+GI7lxSpQxNvyJQhdn/XJGu3tRQms8lXbb/mp fMXKKsCd5rbdAqCF1TmAHC2IcNQb8sG9HQlZs1Bwye+MlJl0dARXIlihtUJ5G9jn35vC n0bqk5RnApfckwFWdRl6CTxgRmShYFpM373VOmvX/4Bec6vOEjlIm8KscNwcB5MXLVXF HVuwl5z7sSqnm6fj2mh90+ZuwckfP6U/pUskAhby3ZSFzYnc4GKipfq/f4l1CpDL2/2Y 7B/6Ln9k5Cy61FE653HTiPUaHr2pBf+pxWhi7I2eKCQzggaAzXPVLm1SNAYK0n9q51Ym /dLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966782; x=1687558782; 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=GMM9vMp4aqYytcqLPDz/iiJMs6KDe9Jl9sq1ptTjl+0=; b=Mg24kBYAkEjAI8ZGuVcTqMeYCNpUQ4he3zH5LT/XZ2AW+r05SZ7MLP6cRW4jhEP7s0 2855jRk5VNyylOUfKYLZVPq9C0PYRQW0JDCOahXO6AgH+NZa7UoxgO+qfA4aQO+KI8Sb P2qdlWBqdeOYmk/xtjypCnjPXe9vbJgWWVi9AzILKjQ+mN7MAbh7Ojs4eiP9WhJ/DaA1 Q+2sPnKw+Z3CwmZBnkPXw2DiqiGAb+J3OxHG9YVK2pUvR2PjQeTqzEeB5EDcG/8U5Y9x Gr3NETy80Xhe50D/PYEAjXc3pD7oC4okawhDW+2pB86KfQkZI3TPt5RXNkgMp2baRBZz pcmQ== X-Gm-Message-State: AC+VfDyzjb6ygpb6w6Sikm4BeuU18Io0pCSh3P7ZxFIkLNgBKiaLF+O6 oKjhZ3OiLxoHdAO0C3fuozIc8MBN//Hq X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ae21:0:b0:54c:7a1:ef50 with SMTP id m33-20020a81ae21000000b0054c07a1ef50mr11781823ywh.6.1684966782088; Wed, 24 May 2023 15:19:42 -0700 (PDT) Date: Wed, 24 May 2023 15:18:25 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-30-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 29/35] 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 58ff7937e9b7..4ef4fecd335f 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -12,13 +12,19 @@ #include "pmu.h" #include "print-events.h" -static LIST_HEAD(pmus); +static LIST_HEAD(core_pmus); +static LIST_HEAD(other_pmus); void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; - 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); perf_pmu__delete(pmu); @@ -29,7 +35,12 @@ static struct perf_pmu *pmu_find(const char *name) { struct perf_pmu *pmu; - 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; dirfd = perf_pmu__event_source_devices_fd(); - pmu = perf_pmu__lookup(&pmus, dirfd, name); + pmu = perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dirfd, name); close(dirfd); return pmu; @@ -72,7 +83,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) if (pmu) return pmu; - return perf_pmu__lookup(&pmus, dirfd, name); + return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dirfd, name); } /* Add all pmus in sysfs to pmu list: */ @@ -93,7 +104,7 @@ static void pmu_read_sysfs(void) while ((dent = 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); } @@ -104,24 +115,37 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int type) { struct perf_pmu *pmu; - list_for_each_entry(pmu, &pmus, list) + list_for_each_entry(pmu, &core_pmus, list) { if (pmu->type == type) return pmu; - + } + list_for_each_entry(pmu, &other_pmus, list) { + if (pmu->type == type) + return pmu; + } return NULL; } +/* + * pmu iterator: If pmu is NULL, we start at the begin, otherwise return the + * 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 = !pmu || pmu->is_core; + if (!pmu) { pmu_read_sysfs(); - pmu = list_prepare_entry(pmu, &pmus, list); + pmu = list_prepare_entry(pmu, &core_pmus, list); + } + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + pmu = NULL; + pmu = 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; } -- 2.40.1.698.g37aff9b760-goog