Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3897474ioa; Tue, 26 Apr 2022 11:55:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD6/wFxRhkcKE2O7ft1l1POIf9L4WibRInhcuIUH4k3xof1lKS0aHZbN8sDZmr/6VdbK07 X-Received: by 2002:a17:902:8644:b0:153:9f01:2090 with SMTP id y4-20020a170902864400b001539f012090mr24147095plt.101.1650999337405; Tue, 26 Apr 2022 11:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650999337; cv=none; d=google.com; s=arc-20160816; b=WMKeD2IdLQMVRDtM7JSbGomGVlPiQpfgwfrboPFeCcnQ6og4Kn6zwxqIvDaPGZzK8H ocGZ8Hs6ei98DOUXrpaYUrXhdNOE1yIzhOhYC/PrkbpmUdoOzH/P6BgHh655G5IX4arx 18aF56pAX7Mk0JKdM6DD/ioIlzHNfYtEd5bplDNsdXieIBDjNlWy7F2nxCOOUMInNpcs T/Wy8jc5kUSSHHDAIYKmXXknVMKHTkshUx2J53LFKmo33U0OYZ5UllToJDq5hYAALbP+ KSbMbp6cIAdmjk7EDgX/UWm21NudzVfqYEGgxMin0KGONFxSCjva2teI604h4XamZthB nnBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VMuj3lJfTnP2d8k+xD1P0KHhX1q5fTxcWHm7zp1SY4A=; b=I+Ml51ohPT13iTnUSmXigzi4fEBxgXMJ4a1de/YVUXCyrau3VuWONac9TVnzKGJJzm 0ive9lWEkiasOcSHTUvByIN5mNgp4gvgUai5m1nKVObO8jjQRBIj+8uumubj/Gy6+13u oYkgTZC8/9Y03KQEyl6hLMYd9IzFKBPYnOosw2R1fArs6xkYCYfqdqruK8vyEN2GkVnA LJJ2eSdrrHL43HuHNn5X/zwfsO4IdDxcNb3nsStj0VPvr3VI2npl8MgzGgJe4qjh1cg9 bG6uoIWofWbmLhfmvy1xnWmSRhN73xb7cnxPfpX5aBRW6B2HRJZbp6obzMWkC9OjS4oh SVWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LOaLTrsh; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k34-20020a17090a14a500b001d97cb4fb82si3246491pja.43.2022.04.26.11.55.21; Tue, 26 Apr 2022 11:55:37 -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=@linuxfoundation.org header.s=korg header.b=LOaLTrsh; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347016AbiDZJNi (ORCPT + 99 others); Tue, 26 Apr 2022 05:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347531AbiDZIvm (ORCPT ); Tue, 26 Apr 2022 04:51:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196C71402C; Tue, 26 Apr 2022 01:40:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7A6C4B81D1A; Tue, 26 Apr 2022 08:40:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD4B8C385A0; Tue, 26 Apr 2022 08:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962431; bh=6BWfZPAJuPEtXnQFvxAC3x0F9LeiCMCnFIwNDSglij4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LOaLTrshbapj2/Fx+dyyayWIoT7GQigcn8R//ttdklq4XThZFjbhom509Vi6Q92Gw D/2ovNugStBY2UtBL/Lkh4C0IE+/Wwi6hoDataRNB+0SmBQ7y/b0LViJXrfIAbTMAE DKneEAKEju+DQr1BqWeEmElsgsD9LFMCBelCCxU8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Athira Rajeev , Madhavan Srinivasan , Michael Ellerman , Sasha Levin Subject: [PATCH 5.15 095/124] powerpc/perf: Fix power9 event alternatives Date: Tue, 26 Apr 2022 10:21:36 +0200 Message-Id: <20220426081749.999848649@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Athira Rajeev [ Upstream commit 0dcad700bb2776e3886fe0a645a4bf13b1e747cd ] When scheduling a group of events, there are constraint checks done to make sure all events can go in a group. Example, one of the criteria is that events in a group cannot use the same PMC. But platform specific PMU supports alternative event for some of the event codes. During perf_event_open(), if any event group doesn't match constraint check criteria, further lookup is done to find alternative event. By current design, the array of alternatives events in PMU code is expected to be sorted by column 0. This is because in find_alternative() the return criteria is based on event code comparison. ie. "event < ev_alt[i][0])". This optimisation is there since find_alternative() can be called multiple times. In power9 PMU code, the alternative event array is not sorted properly and hence there is breakage in finding alternative events. To work with existing logic, fix the alternative event array to be sorted by column 0 for power9-pmu.c Results: With alternative events, multiplexing can be avoided. That is, for example, in power9 PM_LD_MISS_L1 (0x3e054) has alternative event, PM_LD_MISS_L1_ALT (0x400f0). This is an identical event which can be programmed in a different PMC. Before: # perf stat -e r3e054,r300fc Performance counter stats for 'system wide': 1057860 r3e054 (50.21%) 379 r300fc (49.79%) 0.944329741 seconds time elapsed Since both the events are using PMC3 in this case, they are multiplexed here. After: # perf stat -e r3e054,r300fc Performance counter stats for 'system wide': 1006948 r3e054 182 r300fc Fixes: 91e0bd1e6251 ("powerpc/perf: Add PM_LD_MISS_L1 and PM_BR_2PATH to power9 event list") Signed-off-by: Athira Rajeev Reviewed-by: Madhavan Srinivasan Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220419114828.89843-1-atrajeev@linux.vnet.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/perf/power9-pmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/perf/power9-pmu.c b/arch/powerpc/perf/power9-pmu.c index ff3382140d7e..cbdd074ee2a7 100644 --- a/arch/powerpc/perf/power9-pmu.c +++ b/arch/powerpc/perf/power9-pmu.c @@ -133,11 +133,11 @@ int p9_dd22_bl_ev[] = { /* Table of alternatives, sorted by column 0 */ static const unsigned int power9_event_alternatives[][MAX_ALT] = { - { PM_INST_DISP, PM_INST_DISP_ALT }, - { PM_RUN_CYC_ALT, PM_RUN_CYC }, - { PM_RUN_INST_CMPL_ALT, PM_RUN_INST_CMPL }, - { PM_LD_MISS_L1, PM_LD_MISS_L1_ALT }, { PM_BR_2PATH, PM_BR_2PATH_ALT }, + { PM_INST_DISP, PM_INST_DISP_ALT }, + { PM_RUN_CYC_ALT, PM_RUN_CYC }, + { PM_LD_MISS_L1, PM_LD_MISS_L1_ALT }, + { PM_RUN_INST_CMPL_ALT, PM_RUN_INST_CMPL }, }; static int power9_get_alternatives(u64 event, unsigned int flags, u64 alt[]) -- 2.35.1