Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp478453rwd; Sat, 27 May 2023 00:43:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5buQefhTeS7g/3+TyhpnGTkN36PmNm7RkBIzvLXi8q54L5maTHeDlJb7YWx6FLB71KUJTc X-Received: by 2002:a17:902:ea95:b0:1ac:93ba:a5ec with SMTP id x21-20020a170902ea9500b001ac93baa5ecmr4024258plb.52.1685173433000; Sat, 27 May 2023 00:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685173432; cv=none; d=google.com; s=arc-20160816; b=0vsQXMFOrqgHoNiIZfsPev6H+P7RCK/XL7xaCL7hoLblvBC9mMvrEJ/oyIjTr/zsxB qOPx6v/PAO7i0NwgQWb+Yes9WHSp7TiZbXEmmj5yiWgRmOUEZ5E2j4y/fn5UVtkh107i V0Uwz3brL/5DCaWyubSZS/1oWtjfLn4+4hJc9snbDz5GnrM4z7XKQBJwONtziwpC+Uwg XVx+cFXz4dDhC6kRE5zC7UmxhG5tt00kNPVvikuhR63ZckEGuFEn4IFyuE43vOjGjeKH 76LhIzsDytF63vC65sQiX3BaWRx8an3ZPqZv2gHC0C6VopRTNRgk6oWdzgwaulSESWX3 OChw== 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=kWjpW1u76sBxbsm1hYEhA0qZQ3555o3L2cIJC7DUwoI=; b=CYb9l8Rdo3OPhZC2AFns3OfLZkkod8FpMgfz8BNpQUGAIU3JuN5fGSXEJDLq/X81Jo TA7QMFpl8ksdz1pf42lFz687DOBZbkLKF8fMEp23DNxF5Jo9HWDl4FSZiAXAdBMyLMaG OaHHXcjnf+9/gRANdjsDLIhSv/4sW0QbSBD4b5Oz5yHe0E0/c8jVrg9nriT8KBeGYx6n MhOT3TQmyXmcWUEC5QszOO+HreJ0WfMC2surXJ1b4oELsGGjPT+34B3k+qKgS+Gf3gaD MQhCRZuyl6Sdi49mqDkTBCpnxHqE2SBBDipQD/J4rMh4UY5irSZ7lSfrXkixIhrRSBhZ LAhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=wBi4n8uF; 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 jj10-20020a170903048a00b001ac53744492si5313621plb.2.2023.05.27.00.43.39; Sat, 27 May 2023 00:43:52 -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=wBi4n8uF; 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 S232259AbjE0H1F (ORCPT + 99 others); Sat, 27 May 2023 03:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238068AbjE0HZR (ORCPT ); Sat, 27 May 2023 03:25:17 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 836AC1A2 for ; Sat, 27 May 2023 00:24:38 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-564f6099813so30316237b3.2 for ; Sat, 27 May 2023 00:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685172219; x=1687764219; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=kWjpW1u76sBxbsm1hYEhA0qZQ3555o3L2cIJC7DUwoI=; b=wBi4n8uFTdA3TszUXpCO8GKYB2uqcL4Vn0FqZlNbP1LOQK1BVmm7fF3l2JaCleCDC6 33wxtblEfCpqmbkyharFERKKEItaJEJAgPnDVWqK5Nq/2j4d1CWYZPudPXsTbuOzIyKZ wQdtuDG0uOcF6RR5xCksRwyUT4pEuoHvB4brApBxYHVzaQb5uc7udU5MiNWxh3PNYk2B Wh18NBKanrun3bGONgRozrXoYFsw2jb20t7Xk/3BS1x1UAQC+L1GcjdXGHejgYRM+93T Sf58Fu/qAZ/kAEAa8d6AovzKAWeoflzGzliHn239rljOJ6T5rGHSIeUsvNFEtU79wFeD k+yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685172219; x=1687764219; 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=kWjpW1u76sBxbsm1hYEhA0qZQ3555o3L2cIJC7DUwoI=; b=aR8K01xRR8qOvyTLV9yWJ7S4plaLPl40VxiHLzQ5b0ymo7KXQ0DpjoyL2/CnFFJ6/q GK8iX2MV1EoEyqgV2DMHRznuJunqsHNFAgPUuLv3pi1PwTKv8YJwNXu9Aa1X85jv3Va2 jlgLx6vTw17YuPRnQvwCik5dr8uOBPdAFh8+G3MVKlnaKwqXbD8CwKC2LiKgEMeA02dt gv4b7lFx41JlZYQx5wt/C37fqkOD5g4Q0IusH7Ptg/F4WEwbjPUf5DmZc6aR7FjPsBKX RonSCCO61yx5AWVZpd0I2XEHHoVg7gXorG2lYzKoQto8ybmgwr/2ZcLeisqeW8wVBQrD Fh5A== X-Gm-Message-State: AC+VfDyNJVWEK125qV4zKVdKbh/UpqH3rxc2dS+BiJNwdrOKQyYT/2aT pFFZocIx2qw8DhBDTyvhTsl6byTNSW8i X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:8d44:0:b0:561:81b:7369 with SMTP id w4-20020a818d44000000b00561081b7369mr2447926ywj.8.1685172218828; Sat, 27 May 2023 00:23:38 -0700 (PDT) Date: Sat, 27 May 2023 00:22:04 -0700 In-Reply-To: <20230527072210.2900565-1-irogers@google.com> Message-Id: <20230527072210.2900565-29-irogers@google.com> Mime-Version: 1.0 References: <20230527072210.2900565-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v5 28/34] 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 Reviewed-by: Kan Liang --- 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.41.0.rc0.172.g3f132b7071-goog