Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4196117ioa; Tue, 26 Apr 2022 20:23:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDBDDTV5zrjy0KGGKVLEXM8Xk2mh4Z34yNTKa3XnbLpI2jaEqDFq5O86kGLITc8NCkeonB X-Received: by 2002:a17:90b:1d90:b0:1d9:acbb:ab18 with SMTP id pf16-20020a17090b1d9000b001d9acbbab18mr7619430pjb.170.1651029800678; Tue, 26 Apr 2022 20:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651029800; cv=none; d=google.com; s=arc-20160816; b=dNYed3ClbO5IPG0nZpagzi63cY0cr2kMN31c+x2NjtD9613pRZkL8Kh8FFRasVBO0h pWe7zoHMg+p3PCTtRpp8Z5ARvoG5x5mF4tI1ZIg0hJDhYa/vHyxicF8ih9M4FS68SVMp t8RBnBa/HtsrK1+sNyFF/TkJgH0npsW8BUobVc0biRM8mhNTeACMlJcZU/WHzT6azHFk +oNo7yF/T5hvQ2YrYJz/YcpHzjpEg2IEU4Fr05aGKRzqniollbdYOwd1A0+HxnCt8mWa ruoPEqsbqABbKlOAfjvgl1uFJy4RxTSg/5VgzHtz9j2M0YSOrv/3BKxc9xh92LeOXukE U49w== 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=RUrUn7F/jGdICO0TPED0EYhjjidiPRQR9pRutwP/flQ=; b=GxT0uQN8XQhf0HlLeJE4ER0EtLns2o6YjK/O1OW5PTR4uLMFTMTD/OxwoEaQqwjL1F DNS3yJJHYlKI9PKzZJp+ur5N1rrbbS1mNTmtP3sYyt7d6kHSR3q67GyaUC4kT82OsamM Tl7lGTUMSum26Gv63fLOYBPi0PSjpSP5r2Z/N0TucyiTD/wUjV61lUy1C5XcFLUw/wBm 2Ig8wnizhWRSRxGCIWmJHEMx0cUIszI6L/e/gZmJloyqIQepHNNk3XxLRxS0PEMvpTJA tcmEyL1HfVTy2y8IscoIZDf0WoSHYzxs6/OssesviCnP+12Q0E1s4Z1J6HVMWvMM14GA hrMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dF1ficWf; 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 l8-20020a17090aaa8800b001d9928adeb5si463332pjq.123.2022.04.26.20.23.05; Tue, 26 Apr 2022 20:23:20 -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=dF1ficWf; 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 S1347315AbiDZJOG (ORCPT + 99 others); Tue, 26 Apr 2022 05:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347644AbiDZIvt (ORCPT ); Tue, 26 Apr 2022 04:51:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8422DD1CFD; Tue, 26 Apr 2022 01:40:43 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8F52F6090C; Tue, 26 Apr 2022 08:40:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2F94C385A4; Tue, 26 Apr 2022 08:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962434; bh=zSDmJ6fUt5MMEw2xJrfGFiI+Dx6P8QzmJvl3KZzetKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dF1ficWfjAtWfUaQbaA6+kyBPFUMgMEXhcB3FMHnuwRYYxrIQHa01zzKnJb69bgWq 0EjyYsdEpv02lnqpzSbtYc4IGZdgjk1CMYns4Z5sZE6Fa/fWkt5N4lfteDP+UO3o0n hCAGhnviVsJKpEkL0XWkkmLSka/EV6J94FLwiTBM= 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 096/124] powerpc/perf: Fix power10 event alternatives Date: Tue, 26 Apr 2022 10:21:37 +0200 Message-Id: <20220426081750.029063718@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 c6cc9a852f123301d5271f1484df8e961b2b64f1 ] 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 power10 PMU code, the alternative event array is not sorted properly and hence there is breakage in finding alternative event. To work with existing logic, fix the alternative event array to be sorted by column 0 for power10-pmu.c Results: In case where an alternative event is not chosen when we could, events will be multiplexed. ie, time sliced where it could actually run concurrently. Example, in power10 PM_INST_CMPL_ALT(0x00002) has alternative event, PM_INST_CMPL(0x500fa). Without the fix, if a group of events with PMC1 to PMC4 is used along with PM_INST_CMPL_ALT, it will be time sliced since all programmable PMC's are consumed already. But with the fix, when it picks alternative event on PMC5, all events will run concurrently. Before: # perf stat -e r00002,r100fc,r200fa,r300fc,r400fc Performance counter stats for 'system wide': 328668935 r00002 (79.94%) 56501024 r100fc (79.95%) 49564238 r200fa (79.95%) 376 r300fc (80.19%) 660 r400fc (79.97%) 4.039150522 seconds time elapsed With the fix, since alternative event is chosen to run on PMC6, events will be run concurrently. After: # perf stat -e r00002,r100fc,r200fa,r300fc,r400fc Performance counter stats for 'system wide': 23596607 r00002 4907738 r100fc 2283608 r200fa 135 r300fc 248 r400fc 1.664671390 seconds time elapsed Fixes: a64e697cef23 ("powerpc/perf: power10 Performance Monitoring support") Signed-off-by: Athira Rajeev Reviewed-by: Madhavan Srinivasan Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220419114828.89843-2-atrajeev@linux.vnet.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/perf/power10-pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/perf/power10-pmu.c b/arch/powerpc/perf/power10-pmu.c index 9dd75f385837..07ca62d084d9 100644 --- a/arch/powerpc/perf/power10-pmu.c +++ b/arch/powerpc/perf/power10-pmu.c @@ -91,8 +91,8 @@ extern u64 PERF_REG_EXTENDED_MASK; /* Table of alternatives, sorted by column 0 */ static const unsigned int power10_event_alternatives[][MAX_ALT] = { - { PM_CYC_ALT, PM_CYC }, { PM_INST_CMPL_ALT, PM_INST_CMPL }, + { PM_CYC_ALT, PM_CYC }, }; static int power10_get_alternatives(u64 event, unsigned int flags, u64 alt[]) -- 2.35.1