From patchwork Fri Aug 25 02:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13364940 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 B3714C6FA8F for ; Fri, 25 Aug 2023 02:41:12 +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=4Ph2kc8M/u8XGcZajB/i39ZGjKC/WzbFFkkwpPG4KrY=; b=ujgMZMLqZlNyCo NK4eY+U38lz0WlZf9eKsHxyYgMMHwaJSCmkPbRmKe75+7pgsR85bXumBB+V57jwyu8F3irwVCqTvN C97cfQoYAz/7zoV79J1LlDGHV0txkZcYJmN8p+00nRfJgKXcAuQtqRDhhHeAcumU6GW/Lm26Pm2R6 nfW1UDM7Rp5HMfmwogngY9UiOK17udlf8WBVOIxvad54VFM0UBPAX5zV3LJA8izR7Cz92f+yRNDyu XdggcRAUDPCwVJxpdAnZNJKE8SDJYwirwI9hxUgUctcAnpB0PVSL6ZeUV/ZuU8QJUxBhQPPgFefER vzXvnLOJM0DR6Z0nYYuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZMkc-0048NH-1Y; Fri, 25 Aug 2023 02:40:42 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZMkS-0048In-0p for linux-arm-kernel@lists.infradead.org; Fri, 25 Aug 2023 02:40:33 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d782a2ba9f9so1180215276.0 for ; Thu, 24 Aug 2023 19:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692931230; x=1693536030; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=gleOx1R6bSswKzh9EuhLGrWijl71cST/VqhPvXlvs9U=; b=Cqu+Mpf9iSpDeRLvOSI3IVWLQssJ9tYBK0e1ZWdNFAycIwrIj1MxpQ1quvIleMZJB6 Drb5sCcEu+fxJtnG5dfoegKcS4mWhHZ523Dohm1QrgK8uHjNxutRRM2W/taS217gq+oI kHkSwnzlHIvea+nMmyhch28gwXtZtS4Q+i0/r1FVJ8rgPQ3Zgmo3DJUDTHva04iSuZ7j Pwog+gL+Ygwt5ML1nXOfFqaQvFCsUOw036pa3OrChBdWXOmot7F0ZhRNIpy1NkakWboa IV/zDZC3ynvtqUUfHShJiG/JbJzUmp13jVoZAVuTdnxcp6qj4ryVFvEGNKWJatT75FYw 4IyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931230; x=1693536030; 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=gleOx1R6bSswKzh9EuhLGrWijl71cST/VqhPvXlvs9U=; b=PKr4R7t6FVJOjrOyKJc2t7188pXD1ppAOknYCD9pQGDt00ETFdT4Q6l5N6vnL6XsUF JN3mntVjGl+aTSOQdN4KhWs3knD5Om0oA5I5k7RQ9EEencKdPhffLtnkIm+1jTmHUs0P i/+eNVpsfd5wzK4GUaj+FlyQpAux/irC6riO+89PGkezUZ1NpdDztAKUkngD7t7tspIr E4xm+V57m7ARlq5E/SsQ1Lh8c8tfLet/K263aRaJ24u8rqchvgGTWdAHx9GwOOb86fT/ VszVgo9N70a+LOjD/p14z0fSE2PUofTU3/9Zsa7Ixrmm0ku6+5uUs2cvA7md6OyYT2Do BAdw== X-Gm-Message-State: AOJu0YyIBHvXHudFDIoz1uuJSWfaEHcSA42hhBVR6C8WlQkkkUbJYZc2 MfUS74shdA9z0cyQpRM+4OqFg06hya17 X-Google-Smtp-Source: AGHT+IFi5wnjwMO3TOfHdkD/PK6fZ23/bjTAUd5coQ8Pvt3nE13DfLfuhsCiqnLwncG7b5sT0DyY9knVVA03 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:449e:d47b:bc6b:cb6b]) (user=irogers job=sendgmr) by 2002:a05:6902:691:b0:bd5:dc2d:9d7f with SMTP id i17-20020a056902069100b00bd5dc2d9d7fmr410342ybt.4.1692931229945; Thu, 24 Aug 2023 19:40:29 -0700 (PDT) Date: Thu, 24 Aug 2023 19:39:57 -0700 In-Reply-To: <20230825024002.801955-1-irogers@google.com> Message-Id: <20230825024002.801955-2-irogers@google.com> Mime-Version: 1.0 References: <20230825024002.801955-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Subject: [PATCH v2 1/6] perf header: Fix missing PMU caps From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Suzuki Poulouse , Kajol Jain , Athira Rajeev , Ming Wang , Huacai Chen , Sean Christopherson , K Prateek Nayak , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Li X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_194032_295528_23BE1D2D X-CRM114-Status: GOOD ( 16.63 ) 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 PMU caps are written as HEADER_PMU_CAPS or for the special case of the PMU "cpu" as HEADER_CPU_PMU_CAPS. As the PMU "cpu" is special, and not any "core" PMU, the logic had become broken and core PMUs not called "cpu" were not having their caps written. This affects ARM and s390 non-hybrid PMUs. Simplify the PMU caps writing logic to scan one fewer time and to be more explicit in its behavior. Reported-by: Wei Li Fixes: 178ddf3bad98 ("perf header: Avoid hybrid PMU list in write_pmu_caps") Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 52fbf526fe74..13c71d28e0eb 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1605,8 +1605,15 @@ static int write_pmu_caps(struct feat_fd *ff, int ret; while ((pmu = perf_pmus__scan(pmu))) { - if (!pmu->name || !strcmp(pmu->name, "cpu") || - perf_pmu__caps_parse(pmu) <= 0) + if (!strcmp(pmu->name, "cpu")) { + /* + * The "cpu" PMU is special and covered by + * HEADER_CPU_PMU_CAPS. Note, core PMUs are + * counted/written here for ARM, s390 and Intel hybrid. + */ + continue; + } + if (perf_pmu__caps_parse(pmu) <= 0) continue; nr_pmu++; } @@ -1619,23 +1626,17 @@ static int write_pmu_caps(struct feat_fd *ff, return 0; /* - * Write hybrid pmu caps first to maintain compatibility with - * older perf tool. + * Note older perf tools assume core PMUs come first, this is a property + * of perf_pmus__scan. */ - if (perf_pmus__num_core_pmus() > 1) { - pmu = NULL; - while ((pmu = perf_pmus__scan_core(pmu))) { - ret = __write_pmu_caps(ff, pmu, true); - if (ret < 0) - return ret; - } - } - pmu = NULL; while ((pmu = perf_pmus__scan(pmu))) { - if (pmu->is_core || !pmu->nr_caps) + if (!strcmp(pmu->name, "cpu")) { + /* Skip as above. */ + continue; + } + if (perf_pmu__caps_parse(pmu) <= 0) continue; - ret = __write_pmu_caps(ff, pmu, true); if (ret < 0) return ret;