From patchwork Fri May 26 21:54:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13257412 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 8D96BC7EE23 for ; Fri, 26 May 2023 22:41:34 +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=wUivAvyymkh0Gc5hWBH4CGQWiLZlsMErmyY3WmfRl9o=; b=FQwrp766CwZC4t kdYf0oxMCyAc0+XcISDWudIqP8U1xTn0E6yQkVgCmkQYpaaRG/dEXpQvz6NH4AIIQT7/GpEOtsJ90 wC+WFXHP4TP/4cRw5qrrBisJmywmDmSdQJHfrp4GvPjIaLidauNUEqpPBtJBz2kbLrDaD6kEcqQA7 2L0ijRZMd6AH3LUMRDrHVm1H3LcDAf/cPQKCq8ocw6Prl+8q4zJ6FZ66Th/SOTRbql7qKWg8qtjIT qQPgm7+ewIHMVNH2pYRk97eB4KcnC+tfzIqkzZTDGsLig474HLybwn7lQB8S0MB5w5rHbKuzLGRC8 L87nKBORwEAtQT5faNrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2g7J-004ADL-2S; Fri, 26 May 2023 22:41:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2g6z-0049zm-27 for linux-arm-kernel@bombadil.infradead.org; Fri, 26 May 2023 22:40:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=kWjpW1u76sBxbsm1hYEhA0qZQ3555o3L2cIJC7DUwoI=; b=EyUxsfPQK6fQP0C73i9bOQzNIs vC4fwpXmH/Adei8NYtkPiWcx072UD837ZYpvl/NdslDCzOL2wbuTga/OEHL98gnJ8FCjzuadbGBdk nBA+3LOCU78fHGeDizDGdAMq68867958UM7ahXBpuyDOWEd28nCQmY4jq3TVgzh/KeXUm7nZHy4Yd jcDYX7j/ZTYFefh7PaaxfYN4v6iTZ1wf7AkWw+H8e4e9bfAVpoxGEvVFxkoRBVhI7hl+tCRzXykrq 9w+IEnnc7qN0pEovFqw8+j6pdv53+W9fEJ0yNTP4Ge7ecMyuPnC3vqdJ5OOkvmfw8M5EVGXi1a39a C6+xs0yg==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fP7-007iw9-03 for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:55:24 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8c9e9e164so2632153276.2 for ; Fri, 26 May 2023 14:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138119; x=1687730119; 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=Pqi2RY0gp1d4rWnKg5tMvNvJV+6YQ4Iv3/YfBY/0/ZxAHBiPmz7i8PVDcEFHsDKIpC 1eXIrPALzIVeM6SgkajaJS3WDDYiDWK0igrzGok4XkRP9+KymLXeB4cx3VwfAeGTw/T0 oizkz4/zJpAdYaXkVRPoDiGwExRFSz/PbVS6XErYXS6IOu31JtQXuJNmjtKp5Fm26Fxw HzgGexdvvdnHnhSywNOm0LXnY6L/EddF1ohOrGZzYypOf2NdjxbFfGOhO7ujZLZrnVip xPprjYgr/dR7EhPPVfYG+MqYZcIQXUE9djG6v9Dz63UYwEj8EESwaeWPukk/vYO4BCot 0Dfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138119; x=1687730119; 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=c4D1I+AK6lb6JiIw9auaO2M82l+sXKU0Vq5nVsOd2I9dCHdozio8CewG0PiymU7DMb 9rtFs/tURl5g/rsQFcO4FPcUuvIG8rAWtIGowiy5UbG0ubKrRmWduarmMya+iEKsOFOX w1O+2d2zoMwev2zxJ4XPqr8p1HLljUoah8EOA9wkVk20gphC9ElGhG/e9rEUA+LL56eB nvcLacRGUQN7AMPR/nAvkJILiyv7hWT861gR5RQmoNAeTm2DzLyarLxkXYK9bVP4LAyX OUp5pYWvmf3ByZbel0fG8SiELlZExxSXsYDXLl8yIUezeO3vz4DTd5oBE1hIUA+pGXDF a06w== X-Gm-Message-State: AC+VfDyJE3X4t/ytqauhw5bhU7HwrqywGJbr2PXigGg3SVvDtrk5UCe/ Swf+mOZ67orQuISkj4i84vbtL3ynpLhL X-Google-Smtp-Source: ACHHUZ4C3ngzT52VBFoUiSc1f/YidlmtHxZJbZ+IMGAvn52S50DrIorMenlPZjXaVLl1md5/rMj/AzEtanjq X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a05:6902:1206:b0:bac:f387:735b with SMTP id s6-20020a056902120600b00bacf387735bmr1234872ybu.13.1685138118999; Fri, 26 May 2023 14:55:18 -0700 (PDT) Date: Fri, 26 May 2023 14:54:04 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-30-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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-20230526_225521_149503_0D684BE4 X-CRM114-Status: GOOD ( 18.52 ) 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 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; }