From patchwork Tue Jun 18 00:50:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13701647 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 02FA8C2BA18 for ; Tue, 18 Jun 2024 00:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Sxc/nQHmPvo+ExHbbWQAPJrcukAcjBKpsaZsjAevwk4=; b=QO++hYvs6Hnw1xsYm/jQUAu+/W PgJHZE8TKjtR7ts1ClEXqONKeDdBZ/a9GbyZjGrjDkdkBk7UbEwLjp4He+1ax1iD1uBg7EujMBvAg qNAUImhUnj0WYDQxzEcGKyJ0oGfKwIXh07S0Aoklz0D1dLxU+711er+KCVeHu7w9Zuff2a8ulSeTo Xsow5AdyeXXuRoxUd/J80Gy1rpoD3j8W1ESqXicH2SSynhiWq0H4JmWVkPNmGYHQakoz9pBooO+Gp CNaVc+gf3CLUfNVVeoNn+DBexe2k7YoUDDes9HTdt1i8wpEqxjEb8QMI+i3Ox0zLYYpI4qx+9uCA0 oGhKBNxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJN4V-0000000D7I7-3LTM; Tue, 18 Jun 2024 00:51:39 +0000 Received: from mail-mw2nam12on20709.outbound.protection.outlook.com ([2a01:111:f403:200a::709] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJN4S-0000000D7Fi-1wEL for linux-arm-kernel@lists.infradead.org; Tue, 18 Jun 2024 00:51:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PSf12xWvpjabCqldpbfKidgKoXbmFEqHMTZi0EHMIZMZuDvOrUWGj4VzVBd0xdznZVkBJInf05AlVOZHMNze4mQAu1Cps3qw9XRtO8421FjRAA6dm/yigtcpMC3sGjDdzAdt2cdxF3/8s4mrbQ81deL1aCIQ6R58n7+AEpTAADPYmKQCJXWHEXM/DCArc0QZ301Apfu0Csw02kSx/4j2CtL7kvkMeC1z5KWKQ8jv16h7C2rXE1nmQGhvVnE2VB895NYKmcvFX7u3VKJVH4EVU9c0EmZUU0ucsWDdhNRPLHP7hAVuqnYxmg+E1wxDizn6SHSPJvN+65L6sqYwgTvSPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Sxc/nQHmPvo+ExHbbWQAPJrcukAcjBKpsaZsjAevwk4=; b=ix02j+NZ2m7OxN7Rsu12cUQo5bNANBmD/idsv3WLZujYQI77eXPYp9w+0KUrlyxNbVYV1pmP3ibD8uziob54clCnDC0O3PfA4/sEfuRhAgKmpwIK75AdRcvZ193hPt4vHWvcqX+KY0RfNa1Jc098KFsKlaI4KSGHC9OPZFcfZz5q0aIWSfpKQPMSPgkCYYOhiTPdTUkwe9s5IfE2n+2iymne27vcOjw4ApsrEJ+56X2z4btrNuep2ATNiNqCtiyg6Z8qJCUZHtxmsgC2YiHnXYbWHbUaBQSX2rbFrxlzNstg7eVKQC2tAglpz4js1pxuTYnYXGWX0f0YVUgip2QMhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sxc/nQHmPvo+ExHbbWQAPJrcukAcjBKpsaZsjAevwk4=; b=KZd7JFj4ysSlm72/DBCpNI8vErTrN3GQEIqxu0cygU9WNcmS2SKaTvnEXy9tPkF0bRBiRLEmobL6e2BdpzKxgQV0Q1dtEslOgkj87/dHYgHOnJh5NhaqDQQNN/V2R/NHYwCB+lo4e1NokwZyp/vqZsteXJEbJPijmPF0Hr+TMFs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MW4PR01MB6228.prod.exchangelabs.com (2603:10b6:303:76::7) by CYYPR01MB8410.prod.exchangelabs.com (2603:10b6:930:c9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Tue, 18 Jun 2024 00:51:32 +0000 Received: from MW4PR01MB6228.prod.exchangelabs.com ([fe80::13ba:df5b:8558:8bba]) by MW4PR01MB6228.prod.exchangelabs.com ([fe80::13ba:df5b:8558:8bba%3]) with mapi id 15.20.7677.030; Tue, 18 Jun 2024 00:51:32 +0000 From: Ilkka Koskinen To: Robin Murphy , Will Deacon Cc: Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jing Zhang , Ilkka Koskinen Subject: [PATCH v4 1/2] perf/arm-cmn: Decouple wp_config registers from filter group number Date: Mon, 17 Jun 2024 17:50:55 -0700 Message-Id: <20240618005056.3092866-2-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240618005056.3092866-1-ilkka@os.amperecomputing.com> References: <20240618005056.3092866-1-ilkka@os.amperecomputing.com> X-ClientProxiedBy: CH2PR02CA0025.namprd02.prod.outlook.com (2603:10b6:610:4e::35) To MW4PR01MB6228.prod.exchangelabs.com (2603:10b6:303:76::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR01MB6228:EE_|CYYPR01MB8410:EE_ X-MS-Office365-Filtering-Correlation-Id: 336d5231-fd85-43cf-31c3-08dc8f30cbeb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|376011|52116011|366013|38350700011; X-Microsoft-Antispam-Message-Info: HdiAHWE3tzOSsJ+rhOqG3Tg4I1sDt6GFporPQt/W49PkFPx2utyXzhHqnVEzQlQba9bd6Wm71BMxNZmsD0m9rNrsj0Wf1AsEF4v/J5kDdRtg96BePkDHEpfS8UvgDw6sOqM6PcYfC7UBrXa/vBBFkN/cRoJqgPqa6sZn0cB7blg6egEYnxTVUrc7a3HOts0KsCHlkOhnxhTQQUWi4lQlI5crcgEkM+sifLwgC8x8cVsjUoZYQWiSz0PSa8UXZvzyXmDiNyQhixI1wlPWSJJWpDRhmn3EgyWPospM8VnS6wlThQELErqJNrBU/Yb6pUz18oNUqkgKAOEqgVbELVHyfvSUFXIcLR68BrmwmN7yCwuGrpyHJYhQOnuCCWa5+SXg8J14NjV67DMIUpXynRiGXHUx1lTSm0sTNwMSXaPA+Xa3BO9bfj3gNpiXb7J/gIQmValVpZHtXfIrLFOoXv2D8mt9/MVFMI/gUnTUBh6sfHFPbGNicKkpEEH1XYBeaOWqejVXMYsJ3Kq44pWTMB3zNWtPXiVbNOQnNGp+1THBak8FjTScexiAUF8WYo+E6YNw6CFmipdMJRBRoV1W82VjQtWOhvapSUtpEjZfjE3POEicSMMelxdFVOJ465/lCTHPhLb1I02t+MpUmCYv+i1LLndF9bHQwjpVsjisduVx7fmWZjTK9hpMQQc5KkdnAARm0DVjZ/FAPSuutZ5SqI4C/vkJN/VYfCcVU2Py6rwNKIoml0PnnY3UUzHt1HGosMfPHPvWZgwIKclellUyVE/zpjDveKIF63jogyDZ6FBs0RnWdg5brjvHpBgZhR3ADZ4jmxt/KoWVi434RuZ45No9m42mdSr+K0kO3WNGhPfe5kIzfBg7wyzKGhXT0NfhHnwN4xhlB9TIcj5o2c59yQj9wePRsbGqu4UYkRUMXEUS134KR2HxBqSkzgpMhOey53WVqH0tfFXeINga3ouJO1JVCySKE55lO1LE4hpup4IAUU74l1xH63bN1BXdjNAb+x4odDEqm8z3rSEcKoZod8xescDUPmrzqBIKE3yZUOpnZi0T1wG549lpUZOXaU6wBCILgo7qA25ycCvprYGfVtpHBlF9azMOonhVAC33Fr1wtrTOZik01h0gJJ8913D4s5gJcRr/+tMUcjKHbJ0kJp7F7Elc+2OsGI1zQic7gbuyZ9BQ+UudnkeByctDd5R1ZxTC20HrejheNHa0muEa1JY1ZpHDNZ3fgiIMbmO4Xkine9sg23aGGSXiCwg6ZsiX7m/14Y/WILnspg1NHkkv6V+PPMusWN6V8TWq3Y2OFT1P6baO+z9594E5HNFVGKrqMu6XPi+G/xwGJwC01kHYQqoIro/oJM8iZkbG9+SwIwCDcwU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR01MB6228.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230037)(1800799021)(376011)(52116011)(366013)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nxeeqYuMn3CRFtbbu+KN7gOcMM5EImuJKcwiOO/A1npcIV0IuSMxTyK+opzle+OrM7UdGp3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5QUul4rEaaBYVniowDSSMGBsNZeZgmp++Ue4yQ7PpK/tHKuc7qLrKE8eLNj3ol7qbIAGJkFpIG+5UXZ7be+knV/SQPlk7V+8D5dnLwCQPUGh6kh8NnTppsnN8zhByrjTQtiWHEyvd1j8DttKdsIuLHNLfrT/zF1rakPd3zo0CkI3ajMk4bksHZcLWCi2DQ3Jz6NbIBXO43n2mXn+gJN0fxUJzDOClE4QK1r1XnleXm3BjOM5zo3H+iojKMvEFeLLsRDeTzyIwNV7Wc9irA3n/gE4zAji7Wd+V3fWqW8Xn14BubgkdxKz0o4yd5Lm5qWUJgWY4S9ZmzGc/BX3O9Adxp8b71mTFe44k6pGYZ7f76HVN5RpngHSdTbBjjNzEOCq2anTRbaOxlKMefTDKDkmfuItwi/KpUPShwjSZPiQgaO4ARaiWwrpfbR33VYxB85xVym70yvU+PXPaUh7J9LQqbzKL49N2+dFq1K7wUcDazdhevCodI= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 336d5231-fd85-43cf-31c3-08dc8f30cbeb X-MS-Exchange-CrossTenant-AuthSource: MW4PR01MB6228.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jun 2024 00:51:32.3290 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 32rrMFQEMYfghgwMRtbs3rMHP0myWj6GS9hf0z1dZsmXveJnnOiOqQ85b7PHmOz2sJnlWrnEFDy4SYlHB+LnqMNfZZSO1De45bog+LDUrY5MIxIXKkzts6iOTxJ9IRLC X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR01MB8410 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_175136_605189_DA5AE144 X-CRM114-Status: GOOD ( 18.19 ) 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 Previously, wp_config0/2 registers were used for primary match group and wp_config1/3 registers for secondary match group. In order to support tertiary match group, this patch decouples the registers and the groups. Signed-off-by: Ilkka Koskinen --- drivers/perf/arm-cmn.c | 97 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index e26ad1d3ed0b..f2349d23df57 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -590,6 +590,13 @@ struct arm_cmn_hw_event { s8 dtc_idx[CMN_MAX_DTCS]; u8 num_dns; u8 dtm_offset; + + /* + * WP config registers are divided to UP and DOWN events. We need to + * keep to track only one of them. + */ + DECLARE_BITMAP(wp_idx, CMN_MAX_XPS); + bool wide_sel; enum cmn_filter_select filter_sel; }; @@ -617,6 +624,17 @@ static unsigned int arm_cmn_get_index(u64 x[], unsigned int pos) return (x[pos / 32] >> ((pos % 32) * 2)) & 3; } +static void arm_cmn_set_wp_idx(unsigned long *wp_idx, unsigned int pos, bool val) +{ + if (val) + set_bit(pos, wp_idx); +} + +static unsigned int arm_cmn_get_wp_idx(unsigned long *wp_idx, unsigned int pos) +{ + return test_bit(pos, wp_idx); +} + struct arm_cmn_event_attr { struct device_attribute attr; enum cmn_model model; @@ -1336,9 +1354,34 @@ static const struct attribute_group *arm_cmn_attr_groups[] = { NULL }; -static int arm_cmn_wp_idx(struct perf_event *event) +static int arm_cmn_find_free_wp_idx(struct arm_cmn_dtm *dtm, + struct perf_event *event) +{ + int wp_idx = CMN_EVENT_EVENTID(event); + + if (dtm->wp_event[wp_idx] >= 0) + if (dtm->wp_event[++wp_idx] >= 0) + return -ENOSPC; + + return wp_idx; +} + +static int arm_cmn_get_assigned_wp_idx(struct perf_event *event, + struct arm_cmn_hw_event *hw, + unsigned int pos) { - return CMN_EVENT_EVENTID(event) + CMN_EVENT_WP_GRP(event); + return CMN_EVENT_EVENTID(event) + arm_cmn_get_wp_idx(hw->wp_idx, pos); +} + +static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm, + struct perf_event *event, + unsigned int dtc, int wp_idx, + unsigned int pos) +{ + struct arm_cmn_hw_event *hw = to_cmn_hw(event); + + dtm->wp_event[wp_idx] = hw->dtc_idx[dtc]; + arm_cmn_set_wp_idx(hw->wp_idx, pos, wp_idx - CMN_EVENT_EVENTID(event)); } static u32 arm_cmn_wp_config(struct perf_event *event) @@ -1520,12 +1563,12 @@ static void arm_cmn_event_start(struct perf_event *event, int flags) writeq_relaxed(CMN_CC_INIT, cmn->dtc[i].base + CMN_DT_PMCCNTR); cmn->dtc[i].cc_active = true; } else if (type == CMN_TYPE_WP) { - int wp_idx = arm_cmn_wp_idx(event); u64 val = CMN_EVENT_WP_VAL(event); u64 mask = CMN_EVENT_WP_MASK(event); for_each_hw_dn(hw, dn, i) { void __iomem *base = dn->pmu_base + CMN_DTM_OFFSET(hw->dtm_offset); + int wp_idx = arm_cmn_get_assigned_wp_idx(event, hw, i); writeq_relaxed(val, base + CMN_DTM_WPn_VAL(wp_idx)); writeq_relaxed(mask, base + CMN_DTM_WPn_MASK(wp_idx)); @@ -1550,10 +1593,9 @@ static void arm_cmn_event_stop(struct perf_event *event, int flags) i = hw->dtc_idx[0]; cmn->dtc[i].cc_active = false; } else if (type == CMN_TYPE_WP) { - int wp_idx = arm_cmn_wp_idx(event); - for_each_hw_dn(hw, dn, i) { void __iomem *base = dn->pmu_base + CMN_DTM_OFFSET(hw->dtm_offset); + int wp_idx = arm_cmn_get_assigned_wp_idx(event, hw, i); writeq_relaxed(0, base + CMN_DTM_WPn_MASK(wp_idx)); writeq_relaxed(~0ULL, base + CMN_DTM_WPn_VAL(wp_idx)); @@ -1571,10 +1613,23 @@ struct arm_cmn_val { u8 dtm_count[CMN_MAX_DTMS]; u8 occupid[CMN_MAX_DTMS][SEL_MAX]; u8 wp[CMN_MAX_DTMS][4]; + u8 wp_combine[CMN_MAX_DTMS][2]; int dtc_count[CMN_MAX_DTCS]; bool cycles; }; +static int arm_cmn_val_find_free_wp_config(struct perf_event *event, + struct arm_cmn_val *val, int dtm) +{ + int wp_idx = CMN_EVENT_EVENTID(event); + + if (val->wp[dtm][wp_idx]) + if (val->wp[dtm][++wp_idx]) + return -ENOSPC; + + return wp_idx; +} + static void arm_cmn_val_add_event(struct arm_cmn *cmn, struct arm_cmn_val *val, struct perf_event *event) { @@ -1606,8 +1661,9 @@ static void arm_cmn_val_add_event(struct arm_cmn *cmn, struct arm_cmn_val *val, if (type != CMN_TYPE_WP) continue; - wp_idx = arm_cmn_wp_idx(event); - val->wp[dtm][wp_idx] = CMN_EVENT_WP_COMBINE(event) + 1; + wp_idx = arm_cmn_val_find_free_wp_config(event, val, dtm); + val->wp[dtm][wp_idx] = 1; + val->wp_combine[dtm][wp_idx >> 1] += !!CMN_EVENT_WP_COMBINE(event); } } @@ -1631,6 +1687,7 @@ static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event) return -ENOMEM; arm_cmn_val_add_event(cmn, val, leader); + for_each_sibling_event(sibling, leader) arm_cmn_val_add_event(cmn, val, sibling); @@ -1645,7 +1702,7 @@ static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event) goto done; for_each_hw_dn(hw, dn, i) { - int wp_idx, wp_cmb, dtm = dn->dtm, sel = hw->filter_sel; + int wp_idx, dtm = dn->dtm, sel = hw->filter_sel; if (val->dtm_count[dtm] == CMN_DTM_NUM_COUNTERS) goto done; @@ -1657,12 +1714,12 @@ static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event) if (type != CMN_TYPE_WP) continue; - wp_idx = arm_cmn_wp_idx(event); - if (val->wp[dtm][wp_idx]) + wp_idx = arm_cmn_val_find_free_wp_config(event, val, dtm); + if (wp_idx < 0) goto done; - wp_cmb = val->wp[dtm][wp_idx ^ 1]; - if (wp_cmb && wp_cmb != CMN_EVENT_WP_COMBINE(event) + 1) + if (wp_idx & 1 && + val->wp_combine[dtm][wp_idx >> 1] != !!CMN_EVENT_WP_COMBINE(event)) goto done; } @@ -1773,8 +1830,11 @@ static void arm_cmn_event_clear(struct arm_cmn *cmn, struct perf_event *event, struct arm_cmn_dtm *dtm = &cmn->dtms[hw->dn[i].dtm] + hw->dtm_offset; unsigned int dtm_idx = arm_cmn_get_index(hw->dtm_idx, i); - if (type == CMN_TYPE_WP) - dtm->wp_event[arm_cmn_wp_idx(event)] = -1; + if (type == CMN_TYPE_WP) { + int wp_idx = arm_cmn_get_assigned_wp_idx(event, hw, i); + + dtm->wp_event[wp_idx] = -1; + } if (hw->filter_sel > SEL_NONE) hw->dn[i].occupid[hw->filter_sel].count--; @@ -1783,6 +1843,7 @@ static void arm_cmn_event_clear(struct arm_cmn *cmn, struct perf_event *event, writel_relaxed(dtm->pmu_config_low, dtm->base + CMN_DTM_PMU_CONFIG); } memset(hw->dtm_idx, 0, sizeof(hw->dtm_idx)); + memset(hw->wp_idx, 0, sizeof(hw->wp_idx)); for_each_hw_dtc_idx(hw, j, idx) cmn->dtc[j].counters[idx] = NULL; @@ -1836,10 +1897,11 @@ static int arm_cmn_event_add(struct perf_event *event, int flags) if (type == CMN_TYPE_XP) { input_sel = CMN__PMEVCNT0_INPUT_SEL_XP + dtm_idx; } else if (type == CMN_TYPE_WP) { - int tmp, wp_idx = arm_cmn_wp_idx(event); + int tmp, wp_idx; u32 cfg = arm_cmn_wp_config(event); - if (dtm->wp_event[wp_idx] >= 0) + wp_idx = arm_cmn_find_free_wp_idx(dtm, event); + if (wp_idx < 0) goto free_dtms; tmp = dtm->wp_event[wp_idx ^ 1]; @@ -1848,7 +1910,8 @@ static int arm_cmn_event_add(struct perf_event *event, int flags) goto free_dtms; input_sel = CMN__PMEVCNT0_INPUT_SEL_WP + wp_idx; - dtm->wp_event[wp_idx] = hw->dtc_idx[d]; + + arm_cmn_claim_wp_idx(dtm, event, d, wp_idx, i); writel_relaxed(cfg, dtm->base + CMN_DTM_WPn_CONFIG(wp_idx)); } else { struct arm_cmn_nodeid nid = arm_cmn_nid(cmn, dn->id); From patchwork Tue Jun 18 00:50:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13701648 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 E1C73C27C79 for ; Tue, 18 Jun 2024 00:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RgCVxU8gDmcDqevGGX50xb2hvEd7LRwWj8UR2cpUb68=; b=ix9VNf6m7TeA4k1kJa1WSyIJrw Nixy3aVpvgQXAX4sfimsB6UQcLq99JezZu7IDZMjky2sXyr3UIOc5s58TXaFsqJvYe0VLaQBCMOmt D8rAEPvaiKHSZaZYlqP3N9/LwqY2BRJ35SLF+H6JIkQRQhy/6d5zlRGDrGpbSoJkGotbOTE+pRx/d HBDwLkD2BUsj87mvWPCfA3XGp1qF8lq9/tLXmLlI8Oolje0kXzxmi4m66n8vldYgdavlUzqEuwD0E 8nmGO7a5X3RnwtYXGlhL+Flyxdd+ehBWv7xU3RRQbemQxyYFPeGmkM3poAuQf6SDiTG0cSVgFRIXg f/KXxO8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJN4d-0000000D7Kp-00WO; Tue, 18 Jun 2024 00:51:47 +0000 Received: from mail-mw2nam12on20709.outbound.protection.outlook.com ([2a01:111:f403:200a::709] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJN4U-0000000D7Fi-1pWK for linux-arm-kernel@lists.infradead.org; Tue, 18 Jun 2024 00:51:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M4yK1LD5WTpVSLmMXjC2r8s9ro2izlWVl4Yf1sFGq/XTek9smB3FLc7cDArkzTa4w6pz5mtHvvdcW0xhd4GkNZC+Ykg/B6lDzVtDGJ9Cq+ZwG76ON576KHJCGx3Mwm34Sx967AxIr6LB1O9pzBceuqSrHWnBOt/uDGpe+y1nzoWJ25nOg9+6cUeCAKQNJC93f0rFBxWjSq+qTuTNpY4ARRWjYbqRpzRuqwA+5YsJcFDJFGFBOnZ+fG2kUoHVSv19aRSQd1qQrvvVvXq/N9rkpyrGWrVVvWXZ924437Ry1CrAQTNaDCgz12UCZUXPfZo+BVzUwplMPQ2QXGdgTSF4FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RgCVxU8gDmcDqevGGX50xb2hvEd7LRwWj8UR2cpUb68=; b=AlALk9QLaVq8OKu8CeZWl8ZdReBxyv6yAcSW4iqYNsgCPu673DDJGQ/CmPCwZxF/mOZZOYgKSaMiPR/V8k5qzWdXtGW8vptfmdWB2J5e5vLOSISnTcYwBdIDTZ/7CXbAdGoALX3y83OBX80K+AXew1O8PIwQpwXSwLA9Th6QWXBlCyxCWgwljEYQChbYHwJI9HzhDaYmT5fFfE7r96eu4CDpG6hcYDVTw923GY4i7Z0PER4K6HeMNn65Rho367fN1Hri3Fxkl7NEMl7LUzPHesg3MAqmW+HjlPSRNqM/t2aDXAhBaZdcVhZUyc9A6retywIigvFyg9F+gwwQ2+cqrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RgCVxU8gDmcDqevGGX50xb2hvEd7LRwWj8UR2cpUb68=; b=tfEUgCQweCtXlCxenwjvOrpYXA6Mgp8QE2jeSSmC2z1i33DZVZSg9aiDBl65fVgO8fux1WxCPvRxliOtHqhzgV/kK7AevLixl8L4qBJ89UD5DUN25t07K/zwWnDNT3RuNHQklZlxNAAvEMYPejmDeo/z85zLz0zR+nvE5kRAsy0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MW4PR01MB6228.prod.exchangelabs.com (2603:10b6:303:76::7) by CYYPR01MB8410.prod.exchangelabs.com (2603:10b6:930:c9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Tue, 18 Jun 2024 00:51:35 +0000 Received: from MW4PR01MB6228.prod.exchangelabs.com ([fe80::13ba:df5b:8558:8bba]) by MW4PR01MB6228.prod.exchangelabs.com ([fe80::13ba:df5b:8558:8bba%3]) with mapi id 15.20.7677.030; Tue, 18 Jun 2024 00:51:35 +0000 From: Ilkka Koskinen To: Robin Murphy , Will Deacon Cc: Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jing Zhang , Ilkka Koskinen Subject: [PATCH v4 2/2] perf/arm-cmn: Enable support for tertiary match group Date: Mon, 17 Jun 2024 17:50:56 -0700 Message-Id: <20240618005056.3092866-3-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240618005056.3092866-1-ilkka@os.amperecomputing.com> References: <20240618005056.3092866-1-ilkka@os.amperecomputing.com> X-ClientProxiedBy: CH2PR02CA0025.namprd02.prod.outlook.com (2603:10b6:610:4e::35) To MW4PR01MB6228.prod.exchangelabs.com (2603:10b6:303:76::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR01MB6228:EE_|CYYPR01MB8410:EE_ X-MS-Office365-Filtering-Correlation-Id: 205fce94-c872-443d-886b-08dc8f30ce0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|376011|52116011|366013|38350700011; X-Microsoft-Antispam-Message-Info: Jyt/lJwsGOoI6bjr0zFG40ERIAFpsdurldYbvPcFugrsIqC5fE8tjjmp6XinSO29rNKqAGIfj8Okwz5htxXmDpBpN+B0o4HnIka9wuY/BqQCFS+Byu5ZTHeUw03eXmzk41gLrHvcr/pvHYjOcPIoChetTtcvb6TiQbSZP1mKv0fQqdj0FGNDJNA/+cLnEcD9opamzeTzhIw8z02Duw1sqN4b/t+2ONWquvhoM2unaf1iTXvs3B2ZsriQ8VLjollPSmYv96n1lCM0NUIQMtl/YaePAhvXrrxSewyTDcf3wdaUeah+50FAXwVMtmsyWohKmdzSd67PwXgnhVxELD9AeGiSscR02KyrL87aKxZwBmyCaHb902nZ9FDol0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PM;H:MW4PR01MB6228.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230037)(1800799021)(376011)(52116011)(366013)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AfuWgEyGd/FVYzG98QU0UO8HWCz7uaLDG5953Rbsb701yxqbijdzKGIjVM30yDigfZCADJIX31Pg+YZQ64tjZSp7TU11wnohjZA6unNpZn/qJbGpwIArmiXF7P5VN3IiymwtFDx8sMhoPp80t2hzvJrKnGj3in/Ij8mvtNvzIcPXo6vlIV6ZdHmxUfux9vvpjNrT8ikpIIEHnihRny9lWxzQ5EPKbamnMJBi5UMz1gBalxzy+V18jLdT3p+5BNmkcAnA1i5hxR3m9P4THIZ0VqsZ3TGts9AE21WmiKZKJZnFtAiXXRxEMAJmUqC/otL79rFpDj27Sr1nW062H8vpwnJmm+1p0VfeXcSCp1jVIkcW3dTvWyzAntyaxk6nP0ZDl3HymdoJ4L8BNhGhtJc0b84xokSNAY1H0qmFGjoLMHjkRqP5SdLB+fyym8o8nkBLKZfCnm20Gu0u/WwHCUWT6odDrG7QXTAoe0bPjlzc4feX+taFYSCoNWR/N7OUr4Sxd+i5mkz83kj1MWa/uEXbriGP3GsViHGjti2rlR5tiPV4eM7gtlzwnehdHZzRHsAKNDzu57hBKXrZqy1XHp26164s0CGybN6egYfTT1NjQma3Nyqn01fz2ZygrYudYKPgmMYduihpdo7KNFwZp6o+lrbtXDcLXKAbWq/N36TkeRj2P75Lfm+s1ZmRXC7vk+vO8zJoT9Iy/ewM5nvFY5XzPhxpCZmUSmIWjd7HUQNsAGQ+zaYE/LA5ZTpyRMYDd/WGZleqYwWSOrnWLrLeDXh9e3MU8mav3xOIXv3QOx/sSPNpahaTc6QfPTfnBQCQ6nT2eKGMlSG0efAxBS5f0Ht7l4VqNJmgFpsWPipbQQRJJlmtFxg2c43svg1lhagUkLqOfXSLaLFjq2sSVw3OHhvIBDssYj/5ib7u0HqKIN4jvtfsyjHjBmwPdmTTezHjmtzT3cSM5IaJBLepYwbm0vkY0pmCQ52BEX1LYrKPfX1dKm0BIFiw8QtW3IRY12b6TZfBXtTjSjbYtdqogIzVgJfvOdvNNUq+WCfVqSvSvRtJWO+UKudmerdMeaJ0RnGvRUpUUPQYvZlt5w9BA6WlZjZkIthRqWbGmS2RXaqnN+pdA/Gjc40ahkLE3vWS9gV1OQ+SEBrGHQK76Hk2A4xrmB9caG3xYhJ9sVVc1RD4NJ0AdjQ6rURNaQIVHVEa1QHsrwgCa92+9GkGdY8L1y3kBdiUVFqPeAr4TJxZIQR7KKwVcM6cOpN4hV3r/VSnY7F5exQZAXOnhExC5eZEYdypRZjKsQQspmBnXzCfJMdoJe6jyFJQLr4BLplCNxSOktShS1pz3XfbHBLAIBF3t07gG1V7KljAijpgLH0vVj9/ZfBRdIPiUj1bzUq/2xLIcCiX/vdHgQDx4myuBbWFoEfIriM05rSkao4ZZekLW0M646mfeLjI3cblP3l/9WDLONBhbFjQHgz+GuCijItRr4espM4aK2E97z1vs0Yh6AoqkdzlIMUAfj2DBPR8Xvmo3j9SrhbjVcqQzR2xaQ42kU3MY4WCVskfxTiJRQw0U7EkLy2ehwmILFitYC8lMzoeNOKUmcnfA0O3iGCVQyTIK6rfMIoJ5JpxKFHr1l/XtLr2Bw0+y4Q= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 205fce94-c872-443d-886b-08dc8f30ce0d X-MS-Exchange-CrossTenant-AuthSource: MW4PR01MB6228.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jun 2024 00:51:35.9020 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Fw35DyKlFrc0H/XY4p+5cAbXzS6yY5Kn/1v4Oe1Pkt4OBKmRBKTrrg9PNVPjDc9A66MjNBc8M1/5ZQrAp9MtcdSA+8rIgjvOuMnbHYHvRDRMuIRATgqtQCyJ3/N+yXIV X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR01MB8410 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_175138_547156_D7EC5588 X-CRM114-Status: GOOD ( 14.47 ) 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 Add support for tertiary match group. Signed-off-by: Ilkka Koskinen --- drivers/perf/arm-cmn.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index f2349d23df57..c932d9d355cf 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -174,9 +174,8 @@ #define CMN_CONFIG_WP_COMBINE GENMASK_ULL(30, 27) #define CMN_CONFIG_WP_DEV_SEL GENMASK_ULL(50, 48) #define CMN_CONFIG_WP_CHN_SEL GENMASK_ULL(55, 51) -/* Note that we don't yet support the tertiary match group on newer IPs */ -#define CMN_CONFIG_WP_GRP BIT_ULL(56) -#define CMN_CONFIG_WP_EXCLUSIVE BIT_ULL(57) +#define CMN_CONFIG_WP_GRP GENMASK_ULL(57, 56) +#define CMN_CONFIG_WP_EXCLUSIVE BIT_ULL(58) #define CMN_CONFIG1_WP_VAL GENMASK_ULL(63, 0) #define CMN_CONFIG2_WP_MASK GENMASK_ULL(63, 0) @@ -1384,7 +1383,7 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm, arm_cmn_set_wp_idx(hw->wp_idx, pos, wp_idx - CMN_EVENT_EVENTID(event)); } -static u32 arm_cmn_wp_config(struct perf_event *event) +static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx) { u32 config; u32 dev = CMN_EVENT_WP_DEV_SEL(event); @@ -1394,6 +1393,10 @@ static u32 arm_cmn_wp_config(struct perf_event *event) u32 combine = CMN_EVENT_WP_COMBINE(event); bool is_cmn600 = to_cmn(event->pmu)->part == PART_CMN600; + /* CMN-600 supports only primary and secondary matching groups */ + if (is_cmn600) + grp &= 1; + config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) | FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) | FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) | @@ -1401,7 +1404,9 @@ static u32 arm_cmn_wp_config(struct perf_event *event) if (exc) config |= is_cmn600 ? CMN600_WPn_CONFIG_WP_EXCLUSIVE : CMN_DTM_WPn_CONFIG_WP_EXCLUSIVE; - if (combine && !grp) + + /* wp_combine is available only on WP0 and WP2 */ + if (combine && !(wp_idx & 0x1)) config |= is_cmn600 ? CMN600_WPn_CONFIG_WP_COMBINE : CMN_DTM_WPn_CONFIG_WP_COMBINE; return config; @@ -1898,12 +1903,14 @@ static int arm_cmn_event_add(struct perf_event *event, int flags) input_sel = CMN__PMEVCNT0_INPUT_SEL_XP + dtm_idx; } else if (type == CMN_TYPE_WP) { int tmp, wp_idx; - u32 cfg = arm_cmn_wp_config(event); + u32 cfg; wp_idx = arm_cmn_find_free_wp_idx(dtm, event); if (wp_idx < 0) goto free_dtms; + cfg = arm_cmn_wp_config(event, wp_idx); + tmp = dtm->wp_event[wp_idx ^ 1]; if (tmp >= 0 && CMN_EVENT_WP_COMBINE(event) != CMN_EVENT_WP_COMBINE(cmn->dtc[d].counters[tmp]))