From patchwork Wed May 24 22:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13254581 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9D84C77B7C for ; Wed, 24 May 2023 22:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uMArlEbf1mqLgHsqc97Tn55hbbnb3ACrOZ8CPC2U0GM=; b=Rb21KujEYFwOqP urO+FK+SwNTUodcSP++BBaPm0op/MNUQ0bCv+4GOVDnPKNyNUAR5Ng4+4YMLeQdMA5HjUrFh4ijRG Xex3/UfCoVbnwODQFHPYLqZHcXkv7xhHYe6yugzMrYKRktqwTqeGjDmzowcZ2PXcv/qtT3fHSZypk zan32/PwM4LhvxXAxiXpQ5EjueZWoPHPb/LHJojkKv1a5vLgvMc+igvnxFgApMFoYmp/9bCvDWr/r EzlSkDSDVEDHWcKLo3saV2C+DTc6WFOOwE9dipljei3PrdXf0mmz/6fiICCNSR5wr5dxD3xCSD+cY 0hL6zXfMEncWEZHyKohg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q1xDi-00EqPh-0o; Wed, 24 May 2023 22:44:38 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1xDf-00EqP0-2r for linux-arm-kernel@bombadil.infradead.org; Wed, 24 May 2023 22:44:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:To:From:Subject:References :Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GMM9vMp4aqYytcqLPDz/iiJMs6KDe9Jl9sq1ptTjl+0=; b=RiMc/21LFxwCqmYfHv0NuMYbrU KFzJxUMiqp/8mBnrYoB43qjVnvw4lfEJ8CREJ+L1wHnGHUBvrgXTH/yaZRykPCtavRsLpbxp2Ws5Q 1JJl2fgGJR5toX8JImjLFw2EtsKoKc9D8xcl/8RD5tyh/1J4mOo0UF6n/cB9KJDSElbuhc6/3zvRB tdLkwThvUVKgjcM1cIOovR/bw3FtD+yraEXdwPiJonmUgXFz8zijAxHfhkU/3O5HokJYYRFoXULeB Mw0fQno0L0rYuq3NXoCcWnEPSeqE32kHfzLpJw5n/7eFwmPdCTxvQqKx4xp92V2+fu0Gn8esCrkG+ SUFntgLA==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1q1wpc-00Basv-QW for linux-arm-kernel@lists.infradead.org; Wed, 24 May 2023 22:19:47 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561bad0999aso35279367b3.0 for ; Wed, 24 May 2023 15:19:43 -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=Z8IG/LHvssd4ek4wsZCf8HjG0zEZTvuReh4wQiW+zxfK2Xrn8ATBEAoFZwIu8ubH3l pW7er8vyeLkppvSs9jrOzIAv1wMKH86l/kKlPbsdj40oCHOlHGXNNgqvCr4FYTlkhWHI RdzyqJBL41iAD/v9e0pLr18iT4WRHALZD7bpAW9jVvPzE6Wkk9f5brXN4SbqpN1gtp2d GFvQVyIW9212sXeO/QwYOrHuAseUGNrTTlQOApqQvn/FWYO+N2NpTRD8IA/iY/veuuu5 bCokVAnAppBNqugINLGE+UkDf7rU7HQHoQWroJRSw7tukfC7r5q5VTw/wxBfDqxscROy iO/w== X-Gm-Message-State: AC+VfDwXKkzQhD7YZThy9HYsEW3YomgqNMrRLjVUxqOwn6EC3oXaAVDe vaDAXAVCQNKvz51wccyPEtntXwEURS3o X-Google-Smtp-Source: ACHHUZ4Hie0jo3VkTqExA880N8d0gJAH1peyWNkf3rk0bbCBNfDD3lXI4p8YwUqyZJmk9SodS9Mg7Lbe60em 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230524_231944_936872_988CEA0B X-CRM114-Status: GOOD ( 16.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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; }