Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4422217ioa; Wed, 27 Apr 2022 03:36:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZ9tIWrhZzAxLgzLGPnffjrkG6I42CIEMllyOHmCEQyzCd4PLbZ9LpK09ZFNCJOLxBf1N9 X-Received: by 2002:a63:834a:0:b0:3ab:5946:17b with SMTP id h71-20020a63834a000000b003ab5946017bmr10979367pge.59.1651055818854; Wed, 27 Apr 2022 03:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651055818; cv=none; d=google.com; s=arc-20160816; b=U/V518y2sF5wvxEoNHdDIQx2HyKjzxY8W6UI6pQ7uGsfbDzKvPKPVbjC7Jje2Co/4G fJ730KoNfVoppl/WZbFYlQ8AqqupDqBcoIxFKkX6niGi84aPmXynIS2ZuPlMsvZ4GcJs I5y0hlByJqUHA94pJIgS6X5cp3kG5OdVj7d9e5DRGQNSsUAWibfNJLR3yKBAnsUQPGWK JoZwXoI5roMeuiX3co/YYcyH6zc4S4LMH4Q8t0hua16a0BDkd19BGRl+I+y0X2kPflVi XIpTdzqoyoxBGK5LuPAovHuTFboysfpMHfM4E8SzRrjqxTbnbqdurce8XEdRkuzkB+nB 898w== 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=KFJP8BNaM6aw9sMTVbIayZv0iDLmBuCJ1pLKqJQgPEE=; b=COf6ZDpsTvF/NZrafN2j8wLW1xXHgY91WTGOptvsY3Ea+rsAmpZ7B8mlRq1kTNsXTS UeDlYsYiLEU5N07NEydEIIp+bUR6tYcDkcjaH44rZqINX5VGT7Z+BKR3hU7HLQ7KrdRb UNTul7Nmu6WcTd1yPrS6PkHGmdGITUU4OhdaY84h2wmm5u8ATbpf3+8y4HP7jYQUojR6 3eyn/ffKFEzdxOwrW0Jz11WwHTksZ8VXZptGT9nTnvCjzegl327k4S8qTMFN2NIWO0NM RHFT5cs+U4elmPQHPrErjo+2oMplTaaaL3qfMwwU1b7Q0X0PXXqI8OKejKbiCcHYC/T2 xhjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r3HA4AQA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id lw17-20020a17090b181100b001d170dc834asi1762762pjb.62.2022.04.27.03.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:36:58 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r3HA4AQA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CF8C22A78F; Wed, 27 Apr 2022 02:48:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347601AbiDZIvq (ORCPT + 99 others); Tue, 26 Apr 2022 04:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345759AbiDZIj2 (ORCPT ); Tue, 26 Apr 2022 04:39:28 -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 BE9451DA7D; Tue, 26 Apr 2022 01:30:52 -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 123EBB81CFA; Tue, 26 Apr 2022 08:30:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 643A3C385AE; Tue, 26 Apr 2022 08:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650961849; bh=Eo6mTp73waa3f5yP2nmLHCgRXXu0Ial0krgj6rRKqJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r3HA4AQAxKUZrZ0E0hOrhZg4FSFWLmSxDrO6iTpZcTHuALl3RzhJrY7GvO1c1q5Lc dK/PSeNakVvYKCVrMZg3/LlXLyxvaoKhKqRE5M7hcIvPlZaTUt20i7Vnm/d5mg4Si6 W0SK1ZOXb3r/GRe08YMLrwcvuCYHpes2YMV5xTfo= 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.4 44/62] powerpc/perf: Fix power9 event alternatives Date: Tue, 26 Apr 2022 10:21:24 +0200 Message-Id: <20220426081738.485907049@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081737.209637816@linuxfoundation.org> References: <20220426081737.209637816@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=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 08c3ef796198..1225f53609a4 100644 --- a/arch/powerpc/perf/power9-pmu.c +++ b/arch/powerpc/perf/power9-pmu.c @@ -131,11 +131,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