From mboxrd@z Thu Jan 1 00:00:00 1970 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 354A3C77B7F for ; Wed, 17 May 2023 15:00:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232523AbjEQPAz (ORCPT ); Wed, 17 May 2023 11:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232586AbjEQPAE (ORCPT ); Wed, 17 May 2023 11:00:04 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40769D060 for ; Wed, 17 May 2023 07:59:24 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64cb2f2751cso893750b3a.3 for ; Wed, 17 May 2023 07:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335562; x=1686927562; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Gq44kqAcq+8j0vM8i7DmjRKdLm4tW5UxG/1gkdirBgE=; b=VHmYUAkEUWg36YLgV+rwU3ZWcraGECwD3Qzgmq3w1f/i09HEF0I4OdmqXnZIMtAcAZ TvSvGmTuPxv47bkmdlz7rcIiB6aYycNA5lDTm5hsP3zSorkj27QEDFdvSgaK4iOqKkn9 9XpCqNYA/cVkubIXrlxrqsTGvUT7h0IzcmsHniG8pFzgk8wLlYz7klezstwmsqftJrfl VEgEn/IAYzEnaQncmQNmsIF/A3Gv5cOsQLIKe+KCXxJCIhTOXUHgHH2OwTsqsvka2VEA X30hKvxJztGGyA+wowlbf9hU0kqTarsjEV1v3neRN55FTrRdjj1H3sFnQnH6U2n0ukO/ KnIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335562; x=1686927562; 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=Gq44kqAcq+8j0vM8i7DmjRKdLm4tW5UxG/1gkdirBgE=; b=d3Fs3O3IouAGZWRHVW7vu9cAvMTA6tEALp7dZCRdgieN4pJGXnBOnaoPuZXRngBK2A vaHlxgLeUWWrGDKnx+E9oNKKHVBoSyh1ceAVdj9P7RxKh5UYSlDLydVnBTXKIMvxGCdf HDaGc+ZpMyIpyqLOa/UsoVua79/Bwr4G8bZUH+gFeeOITiwPm/0As3SmSB6ccRXG1A8r RRdtp9qhF6Jixe6lzRj8562yo6oVad6Ubo00rTRnVN7g4F0sJknUJ8zDaw5dnTSZGf5o YUYfDLk1FAZs5wQG0Fnbl42Hf+s3DtCRL6XuMcB338AoM5VHQf9QJDHhjo+puvqBpHmR 2P5Q== X-Gm-Message-State: AC+VfDzPfy1gTSQesRk/GFBKZI9dWkRv2/7jR3LlU0H3NXy5F+5WhL8n DrmI4j2xTk16UyfLgxdzCwHfFVHfgjbn X-Google-Smtp-Source: ACHHUZ5VgBZWq+DJkhTCA1fH23jV7JtykoO+x4kMt4aMxIEotHunrFLTjmnINXjqoA/ilJDF4+7T0TWXEtyy X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6a00:22d0:b0:643:78c3:fea3 with SMTP id f16-20020a056a0022d000b0064378c3fea3mr431257pfj.6.1684335562320; Wed, 17 May 2023 07:59:22 -0700 (PDT) Date: Wed, 17 May 2023 07:58:00 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-21-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 20/23] perf pmus: Split pmus list into core and uncore 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 , Raul Silvera , 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" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Split the pmus list into core and uncore. This will later allow for the core and uncore 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..dd029a810147 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(uncore_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, &uncore_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, &uncore_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 : &uncore_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 : &uncore_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(uncore_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, &uncore_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, &uncore_pmus, list); } - list_for_each_entry_continue(pmu, &pmus, list) + list_for_each_entry_continue(pmu, &uncore_pmus, list) return pmu; return NULL; } -- 2.40.1.606.ga4b1b128d6-goog