From patchwork Thu Mar 7 23:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13586337 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 90A33C54798 for ; Thu, 7 Mar 2024 23:10:28 +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:MIME-Version: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=1AJfT/FSzLJTqZ/eI42cpRtCiGa2h0ea11uS/1IA+Fg=; b=0YwLijnwH/FJbI plcj8iEFSv5yHjUfyVqnKVGTskI6aa0e7I/PvFayTFH0QaJcElwTSScMJW9SVBZPupjShWo/jdP8Y +heRpAhKdykK3dppDzYD+BzqCAASukWmzL13XI4k4OJeVkMVzHUOsWBOvXzKKtzblF2sZyPzULSfa MTyNANS2aYQDxs9GYzq+39zGD1HPClgjsZ6O2vQ9XAPyNbFsp8236Xny3pv4gooT5tdT/mJ4FZi+X WoY9R9fOZuPGU276fiihG7RMI3CKWixc2Jyvk3V8wJ+rpOiSSd8ElaZpbfsPOVciSAxdFjG+gKMZ9 NcRHjaJE0uE+6Szx/xSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riMsS-00000006kun-1UDV; Thu, 07 Mar 2024 23:10:16 +0000 Received: from mail-bn8nam12on20701.outbound.protection.outlook.com ([2a01:111:f403:2418::701] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riMsO-00000006kqw-1cCX for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 23:10:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=km70QExyaBLg/tYBdbnPI9q8+z3IWYIO1jiG6jKHLns4gWyLurFsS+mL0UvvW/oIWEu8sL/7WOzZOALsvMby0l8IwGk4CMX36dEGL2UkedcnK3zG9NmccLsOQwtbeusZfAwcwuwE/aI/1PnBuQIoVu5KQgHzF20UgTQcjN3Tjy9pT2cG0LbslRSBqmWT0Uv8VjaHoHbCHpS06SPnWkavMZwxn412pf8buJz9voAgnZnfMuGDxpAm78lGoQxm1hsS8ztInVCfa8Z66IuweaFgxXOV69e92+fm2FCVjBY3WIN9frlZz3qNRsrwvb3lQj5d9kSEIasKLTsqPlp/gy5Bqg== 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=+twEQDvykkkKJyXddL9pYIiCIC4qHdRWT5XHHYExKM8=; b=i+ReFGMBwXI7CQ5v8uR0NnQVIc59OBLvzZfoCWaJLrtMQETuR83KgSXpODuDqnYSLzQ3IAlciZD/S/jomE+CuxcE2mc64NKA+EFYPKnM1hdXKLrN13lKlZvnGqGGxZ8pmnUkuMdx4QYvb94oVkk5wU8+WsVUpZOAzRdD3UOV9r5KedLdED/0+JKTwBYMTCpLrGqxasE1cLnk1pc7jp7jnQ89Ae2fujaNFcKesq1+4dfhrdVp/4hSgrsqChsiZdzgKk9KYVGlUsTN+0ibF+Vl71rI+R/PMDN7OhSkuDsMW5dhMcXvF9lgK2riS1eYyJQhN6wHqX9fIauKarZzSK3V+Q== 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=+twEQDvykkkKJyXddL9pYIiCIC4qHdRWT5XHHYExKM8=; b=X12JIIqvTamq7bBN7LghJJ8yY6hqpYu2RQGGWUJgyWhMw1XckAC8CFisCKov4BzJlJ5C9Gz6DfvF8L4P+5slEVMRku7awU7vwV/uW1rpYX04apaJaM6L28M3agh9UtqSelMQ5K7dRj8nJEm4gIKiGXVCqjpatPaH7A+b3+xnR08= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) by BL3PR01MB7116.prod.exchangelabs.com (2603:10b6:208:33b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Thu, 7 Mar 2024 23:10:02 +0000 Received: from BL0PR01MB4226.prod.exchangelabs.com ([fe80::12be:916:b914:8b26]) by BL0PR01MB4226.prod.exchangelabs.com ([fe80::12be:916:b914:8b26%7]) with mapi id 15.20.7362.024; Thu, 7 Mar 2024 23:10:02 +0000 From: Ilkka Koskinen To: Robin Murphy , Will Deacon Cc: Mark Rutland , Jing Zhang , Ilkka Koskinen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] perf/arm-cmn: Decouple wp_config registers from filter group number Date: Thu, 7 Mar 2024 15:09:28 -0800 Message-ID: <20240307230929.6233-2-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240307230929.6233-1-ilkka@os.amperecomputing.com> References: <20240307230929.6233-1-ilkka@os.amperecomputing.com> X-ClientProxiedBy: CH0PR13CA0057.namprd13.prod.outlook.com (2603:10b6:610:b2::32) To BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR01MB4226:EE_|BL3PR01MB7116:EE_ X-MS-Office365-Filtering-Correlation-Id: d24b0d63-d5d4-4a66-34b0-08dc3efbb834 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7zceF4Q9fQaC5o6bn2zk4ch9l73bbHbcOZeu7mPFiW6PP985WQQDrtTJC+E/fUJkMfFoGQDr5zDWJBRTv9asWpjzduxLU5PgQqDkpmcWbgFZ+eHRfs+dbIjBZZvpcSYgLXRUXgtJvHLej0uzMqsTmuvTt2oYWT4f7F18ylBdXBjBuLklNHnz3GZxnNqNCmJbcXQQV6cdKzLomvfw53towJnBnaBSyxjEfmN5ioK34Z3In0Yle8165MTIj+TEaLgO/QmFrKD6lc3ea+KSDwjlJatmJTU7U8PCssI4hLbxsaNhrmFDuscDIDiA0CtCRPp5aMTaEVQ7tISwq9BTMFHqvumwFjLXMLtUI08TP+ZCIEgVC+kObUkk2IAqe8evW1ieGBD4/8rl1QZI2nYJfZVfhDEgTJM2sx8iRtEtIJ/78r/Lv1tlRPCik8oYmj1iFcKFRvOal3GtawoU5Rts1zA6YGfJFuFPnu5LgV9nBb+0IoGl8TZrAvS8g1b/QjJg+3LwQLBuDBMl03FXYj03oiIc/dhTQYnFvtITZv3FWeYVwUYonnPgC3xi2xC9X98aze9J5uBgzq/5LZPv58sntb07kMHWRvdaMPAqw7R5mFf/ucIQEho3XqHV6n3TzE0nbS+/In8VwmwspY1VHh+IvmzVCSY91+/zyyeH3DozEpH+2Ta/EJdHhTkyx7AA+t7iMc2y6qp4Nu6NfPavWF+tUg7H18CIMxKOUbT/xsUGp7pRwBU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR01MB4226.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XIBEwk8PoyFW6PsGDUSHzKCpyPJtaesN0qF22DzV7s7adrwjHOK6A5ujJQj56p25W6e3fOV1AX5D3wBNeYW/HmczL5ItTKiG36rTx8eZC2+HmB5wRIAJYqeplJLqz6aZgBvYWzSp9ZpZ7Tea8FRbSBNqGi2daNQ/q79J8FH0YO7s5JIfO8GBKvB8X34qtixsc+z2+hC+Nrng3VXRDhStTXfLaU9q5qi/L420cTvucrUWD1bVJIeXYRlZdcF/WXjPGxPd/nuUCVymS4HRJivvTzdaXdjYqQbaAC6nmAIxBPoQOFwSiJQdVfS+kVdgPxmMqzuvBApQJlqR+Vsz9JyDhTi+XVn4YO3DbtLg/svr4gvrq8wWaAJMu9A70jofgTR1YCjziVfaRcC1yQghvUUiFTrmD8F0zxD/ThHNse52+6vxuvhW7QI1JGTK8ofieivkql8wCN1zFqL5BJessT7jwKEU7xrDwx3OTZsAL6bj+7hMhkk8E9yw6iXPBr6W4Mwg7Jm8oSFBLarEZFcPFckjBf7Kw6GH6OdC8lsb3aq3NI2S9e2oBxFFWTcTmWm9vmcPz6FuDzKX7Iw00Quznwk/uIVsdRKMZlS+7+3g2FqH4kX1qlK+m+wzRL3SYJGq9HSpJ2JdfXDlgG7na+KX5WtKt3+egAqgAqQ40dedtoE60IkEhOLv54061/4d4aQjj65Ow+wbtl+AdstiSQ3z5yVJsrd+Np3ROtB1wqZCCCicPcer3LcTFYfc6Tc8IxQxvvba/UFTi6tjwmwXhGter4RsfHuN+VgQGVVUjdqqvlzeVJ+11R/OBAUUQk2GGqo66pi5kt8E22NXOfTQRNpiR+oaTbB38nfcUOfYWRtxLEvakumxNIViGwdQn0lp6oq1C3yTTAgRkR5dTptvlq87Zx0ODw1i6aRA/gM9x0vGugRU9fmi7l0XmKL5YGhbW4XI/cXHr8m+FRtGbByTfDKXSCg91FGsVGhTgvORor2B8porTufQplLyF5qN3OKgJU1xJg9v/cpqbEvlQIizuey8Vk1OKGMWehDNrvl1txScV8exKsHY/HS5yeUztvR3lR3i7M/q7gMXc6JjI9YV7TJLrztcOyix6LFJqu2gyT2dI9/SCY3BeBfmL24NJA7D4pV7cmsAtV/ovShisbv3LtMhJ3YGmcF1Fri6q9qdiWqbOyT9zdffcWHpPxryzBlmnMgnpSkcpeFsTRF/eiKer4YdnBdhfq2JZsoB/pkgEcqNrPOBKiYn+0I8Jw1nFPp0x798OAf3HzbvLMfOwkcYOihvA7EEvrUR6rbEcIr4BjIdgWW64TnzWpx7M36rk3CMKhmb6S5gVi4EwltV2QCTcpgX80lYmBAkPd1UgJhbIgo07Q1SHlYxCx3NgnVnk1HbqdVpvR0/EEviXOxCo0gkgtk/IpHSrUHMxdu6doKVWUUqP4Fp4ovUpF0NDhgrZIUplfc7JIzXoFmgyxCyw1nKNKOVVaZ+fdnspfG68wI8ppGHI2DexOujLrCm3mGm9vvxcXDYXysMHNXxMmufvB8kmA2eiGfp/sPXfeZCCLnEQVwI5xn1EV3hEYQJFFY12bwFCN5NSfUM37twDQ6I4SE2BRoNrZwwLjTiUy7AuS2u5hFxec4FoRc= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: d24b0d63-d5d4-4a66-34b0-08dc3efbb834 X-MS-Exchange-CrossTenant-AuthSource: BL0PR01MB4226.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 23:10:02.8775 (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: oEbz2oIJv0Mx3hx7JCgS0jmUxGEl9mVnnj5f6KszLYX55SqyqA8Fom2CUDKf3imZQLhK1/NP/WGwpzg1FuyX9Ua5IugsVT5PVO7H+ewqjYpiVM1qu2bYEpeqXdMOoPLx X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR01MB7116 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240307_151012_644096_E0DCE22A X-CRM114-Status: GOOD ( 19.26 ) 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 | 125 ++++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 20 deletions(-) diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index 7e3aa7e2345f..29d46e0cf1cd 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -589,6 +589,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_cfg, 2 * CMN_MAX_XPS); + bool wide_sel; enum cmn_filter_select filter_sel; }; @@ -1335,9 +1342,51 @@ static const struct attribute_group *arm_cmn_attr_groups[] = { NULL }; -static int arm_cmn_wp_idx(struct perf_event *event) +static inline unsigned int arm_cmn_get_xp_idx(struct arm_cmn *cmn, + struct arm_cmn_node *xp) { - return CMN_EVENT_EVENTID(event) + CMN_EVENT_WP_GRP(event); + return ((unsigned long) xp - (unsigned long) cmn->xps) / sizeof(struct arm_cmn_node); +} + +static int arm_cmn_find_free_wp_idx(struct arm_cmn *cmn, 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 arm_cmn *cmn, + struct arm_cmn_node *xp, + struct perf_event *event, + struct arm_cmn_hw_event *hw) +{ + int xp_idx = arm_cmn_get_xp_idx(cmn, xp); + + if (test_bit(2 * xp_idx, hw->wp_cfg)) + return CMN_EVENT_EVENTID(event); + else if (test_bit(2 * xp_idx + 1, hw->wp_cfg)) + return CMN_EVENT_EVENTID(event) + 1; + + dev_err(cmn->dev, "Could't find the assigned wp_cfg\n"); + return -EINVAL; +} + +static void arm_cmn_claim_wp_idx(struct arm_cmn *cmn, + struct arm_cmn_dtm *dtm, + struct perf_event *event, + struct arm_cmn_node *xp, + int wp_idx, unsigned int dtc) +{ + struct arm_cmn_hw_event *hw = to_cmn_hw(event); + int xp_idx = arm_cmn_get_xp_idx(cmn, xp); + + dtm->wp_event[wp_idx] = hw->dtc_idx[dtc]; + set_bit(2 * xp_idx + (wp_idx & 1), hw->wp_cfg); } static u32 arm_cmn_wp_config(struct perf_event *event) @@ -1519,12 +1568,16 @@ 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; + + wp_idx = arm_cmn_get_assigned_wp_idx(cmn, dn, event, hw); + if (wp_idx < 0) + return; writeq_relaxed(val, base + CMN_DTM_WPn_VAL(wp_idx)); writeq_relaxed(mask, base + CMN_DTM_WPn_MASK(wp_idx)); @@ -1549,10 +1602,13 @@ 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; + + wp_idx = arm_cmn_get_assigned_wp_idx(cmn, dn, event, hw); + if (wp_idx < 0) + continue; writeq_relaxed(0, base + CMN_DTM_WPn_MASK(wp_idx)); writeq_relaxed(~0ULL, base + CMN_DTM_WPn_VAL(wp_idx)); @@ -1574,8 +1630,20 @@ struct arm_cmn_val { bool cycles; }; -static void arm_cmn_val_add_event(struct arm_cmn *cmn, struct arm_cmn_val *val, - struct perf_event *event) +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 int arm_cmn_val_add_event(struct arm_cmn *cmn, struct arm_cmn_val *val, + struct perf_event *event) { struct arm_cmn_hw_event *hw = to_cmn_hw(event); struct arm_cmn_node *dn; @@ -1583,12 +1651,12 @@ static void arm_cmn_val_add_event(struct arm_cmn *cmn, struct arm_cmn_val *val, int i; if (is_software_event(event)) - return; + return 0; type = CMN_EVENT_TYPE(event); if (type == CMN_TYPE_DTC) { val->cycles = true; - return; + return 0; } for_each_hw_dtc_idx(hw, dtc, idx) @@ -1605,9 +1673,14 @@ 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); + wp_idx = arm_cmn_val_find_free_wp_config(event, val, dtm); + if (wp_idx < 0) + return -ENOSPC; + val->wp[dtm][wp_idx] = CMN_EVENT_WP_COMBINE(event) + 1; } + + return 0; } static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event) @@ -1629,9 +1702,15 @@ static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event) if (!val) return -ENOMEM; - arm_cmn_val_add_event(cmn, val, leader); - for_each_sibling_event(sibling, leader) - arm_cmn_val_add_event(cmn, val, sibling); + ret = arm_cmn_val_add_event(cmn, val, leader); + if (ret) + goto done; + + for_each_sibling_event(sibling, leader) { + ret = arm_cmn_val_add_event(cmn, val, sibling); + if (ret) + goto done; + } type = CMN_EVENT_TYPE(event); if (type == CMN_TYPE_DTC) { @@ -1656,8 +1735,8 @@ 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]; @@ -1772,8 +1851,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(cmn, &hw->dn[i], event, hw); + + dtm->wp_event[wp_idx] = -1; + } if (hw->filter_sel > SEL_NONE) hw->dn[i].occupid[hw->filter_sel].count--; @@ -1782,6 +1864,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)); + bitmap_zero(hw->wp_cfg, 2 * CMN_MAX_XPS); for_each_hw_dtc_idx(hw, j, idx) cmn->dtc[j].counters[idx] = NULL; @@ -1835,10 +1918,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(cmn, dtm, event); + if (wp_idx < 0) goto free_dtms; tmp = dtm->wp_event[wp_idx ^ 1]; @@ -1847,7 +1931,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(cmn, dtm, event, dn, wp_idx, d); 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 Thu Mar 7 23:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13586338 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 D1BE9C54E58 for ; Thu, 7 Mar 2024 23:10:29 +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:MIME-Version: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=w0FHU+2Tw5FtU+xxCFXgVja2j7agVPp3eXi6ocUGLkU=; b=ElNo6pxiGBNLIV TpZFqPvDMZofROgObDgn7t8Xx1QevK1vR3IVcpcG9+p0TPDtva6yhHZgi2DoXA9suDunocHon/lSQ ljjOLhpSicUYXY9mXHFxAzSy5WJuqP/DJnX2X8z5LQqQCd1EI+8hNsguwFGo2TPlfiLyb7jMx9c6B MlULTRQI4Dg4D+B9hnFtqanz6uDyNquF12bMvnWTmT8aF34QlDct3JS+DTuAQnCurzh9aZ3IAyBRM L1XkRLuySY0VBtd/BhyBMDBjQpPJXkpZnQLBLLfvEwS15YLPQLK0SzKRGIPCC8C6bpw50Vip1g97S PyRrr20OoUG5DKWVVpmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riMsW-00000006kwL-2Xt3; Thu, 07 Mar 2024 23:10:20 +0000 Received: from mail-bn8nam12on20701.outbound.protection.outlook.com ([2a01:111:f403:2418::701] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riMsR-00000006kqw-2BRa for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 23:10:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z+yhcpa0v7wGPpPoxfhxvXRnUQh1FNNQU93zKHepp8ItqmomFbI+u1rpJJHgy02osVsTnX9/SKh18N7hU9RRny/PtEN+EOJK8A2/OMN7mGLmyhhD6q1kR2F7XyaJvxFc4E5zseJLP1kol9neBzhKFyUyx3IHGbfVyr82aojMUW010G0tjDlUBnSxZxIA6xPYdXM0JgCaNLyknAeeIWfIyMb5ibA/SqQWJ23VkR+Zb7sPWgiAKNgZ0ss83kTDlVPu4ZyyuJmNE6rLqrMNkFA9tGum5Pcwm+ouWjV42aLmitO+gPw8hBkU2I4bjEMR0Hyn9O7I9e+07a36C4Nw6txSTA== 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=Yz9PQEvFfwG6wVXiBGYiS73jbjIkADRgYDz8OtJmYoM=; b=jOqIdda4OrQbWTsjSQuoETlAcjxKgnRguKiVDltYWqeL9pmitnitw+qk6yUGdR42sFIxkp56vsYGwLFzPzUXbL+vYX2wf/EVWGHjwO0bDZDMH1CAV584R4+lfHV+uuU7beEYp26S8W+ToHYmZm5pJ1xkmCBXiW8N8jY+t9IAEtLK5qJSdjdSNaW03IY2XR4u2CXUIKYcArUeDmfzj+BDuDbt+h0/X+vH8uI6FWnYd6mslLhnZXZ/jFm7v/og3KYtAg0HZSH1LRlLwG+yN6vRWhH1UH3wK7p+Y9LWfhDdO6Nu1SUkQAtXCdImOhOgYZTfJ8m8IqH+oNc03DlG8BVy6g== 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=Yz9PQEvFfwG6wVXiBGYiS73jbjIkADRgYDz8OtJmYoM=; b=WJwRndHNBEaiJz6AA0tyhCvYvzrrGisVqZo7PsOwSBH3L9WuBq4nki7hQhrPG8o+nmGrtljFiIEHtt8WspBvPOGM+XwigNo2tg632ACKZunrUrxRHvUuAAfe9e5qncG54cZ+dnUWsV5ZTpMg4DHy3wGoG+Hxdf54mnxdxKegswg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) by BL3PR01MB7116.prod.exchangelabs.com (2603:10b6:208:33b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Thu, 7 Mar 2024 23:10:05 +0000 Received: from BL0PR01MB4226.prod.exchangelabs.com ([fe80::12be:916:b914:8b26]) by BL0PR01MB4226.prod.exchangelabs.com ([fe80::12be:916:b914:8b26%7]) with mapi id 15.20.7362.024; Thu, 7 Mar 2024 23:10:05 +0000 From: Ilkka Koskinen To: Robin Murphy , Will Deacon Cc: Mark Rutland , Jing Zhang , Ilkka Koskinen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] perf/arm-cmn: Enable support for tertiary match group Date: Thu, 7 Mar 2024 15:09:29 -0800 Message-ID: <20240307230929.6233-3-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240307230929.6233-1-ilkka@os.amperecomputing.com> References: <20240307230929.6233-1-ilkka@os.amperecomputing.com> X-ClientProxiedBy: CH0PR13CA0057.namprd13.prod.outlook.com (2603:10b6:610:b2::32) To BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR01MB4226:EE_|BL3PR01MB7116:EE_ X-MS-Office365-Filtering-Correlation-Id: ccb123db-7ca0-4f9d-b3b3-08dc3efbb9d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jOQtDABqmR9uIgWGtPO0Q3SqDtAVee7QHs6ZaC8EJN2o2opehU+naT90MKnEgzwXDFWtoX4TfZ0UchIc1FyP8OUnxSW98qqfSn4d+V0ywCPAt3iEZvaUz5soc/1pfC2IEW03RTWZ3eh3c7wc+jy2prLWpnWIWQbWrexfeK4KdMwVQtKtMmjL9yTgflOjQROjo8hUKo0AxvApEgugwv7I0PvXZknv8M4JubC2U0G/RYyolO3et51RozsmL8XK4C1dJxIhjY4JgD9cjmahrN67HM10SnkrRJi95VNU3ydOq4OzKFQf90rCLkN4sEJmT5qepJ67I97d8BiQdUiuOt7554oP8Lq8KBuA9aw+9Sxiwn7OKWCL9dDHomvAF2L5adk35gnkHfaM/X7RTjcVBx3MySAW4NS11blX/dgrRPU3fUHl/f5httEYRPhU6H0jrJEOtzMnFusrvgHYlcSgOcCLp8LNJRpxegGnt5TfcL7c79FbWtHtSHVSh0azA2kK8KFyKTm1zMntK4gT3X7T9gGEMzqI8vyRXHhvHj9vv4T6xbUirY5J/3MYgizlEMfZHv8vRaZzUgQsSLrkxEyLRiKBoeCVcAGVo1FAZYt09HJfX8DUKZXFo0Bn6Ahi5VI7cIe3y2qFueqtkOR+FcS/VdmgRdJcMmAdwHjgzbE/R8++sdy33KuQaKk5Lz9LyFE++itD//VKQQrOuh310PGBtE1QxReyguZv3awMG80zbAxvkdc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR01MB4226.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9nvlRhMR1pricGk1g5+nC6ET+hQo8yN9gXsaQCMlYQfwzpEGr0qGmu25nAfKRjEPZcqoWo/2upxBMiRidyN27+HWNDwaAuJkY3Sh9F7PR1CEXvm5IGShePfhfC8lxzCVsnNHtOGoivf4WjwtD/hvJ9T0Xwm3Yk4+PgGBDZOApww2eVLf0TiwmL1lAPReYyM46gxH0cIwop1wC420d8ndorRqTtO/Emcs3Q2RkYY+LtLSewOwlcF2c9YWFaxUIM3Rzj48Pd5cixG/3a4rZiFHDSjo8Cz0/hEBipA4EVUG33856BmaIBEJUa+e0MMVPalnJYAFUJ32vp7y29l/2PqyQssZv9SV3//vDuTwyPCeQfj+EKnbwkeYSxE/8jZYYho7y1PDEFRov0wm6o1mrEB/iPLo2mwpjT8EMPKcEoreCh1M1gialF80XswJjSMAfdd5O0RRzeg22F3OsE/Yguf77VXW6a3Ggdk/KfHv3btAnlch1BEQo7HFx5uxSyt0vErnvc4996caD8+kxp95xWQAix2XK40I5X7XllFrQYRlAgUK9Z7TzJHksINrOfYkyMnnjKVtim1SW5WUkLqA6Y7bVqaxFDowCPOr4LsPLtJfKWvGPktUdCxAySrcC02oLnJbttskOOuS6qIi5CPbNLVDP0Rgjufxy5BTyZkrcKLi38WnTmdEzOshjukQPEmyiLc+415jOfG7K3NxGB7pmqoIJbOOOmMdSP/ghghqLP3Z0bnJoen6198GtXE56Lv0ITD6sFtA9KBXhPAV0OtYM2jqhFLOZvPToePy6IS9FHvYMGNt69AwplZ7yyJyIgWRgTAyNx7YUbwPg+DYJ40cRVQ7037MWzwYtm53azgwucyVq5Y9o5T7NGH8s9PdA3chQ8YNiowROvtjJzD2nr6eTST8wMhTjocnKH/WoLc8sXWn/MMIvIdt5F2wvajXpRaif+EUdMavBkMyHcoHIgaaIT0vPSPIhD6BcueCm1dlqxMjlyHHVc+OxQc8PbY1Pouag6xnmSqrtiSc/0Pov4glZIlIAu/PIpGECv7TSAk2CThQ9SBO+RCo65R8SbbrfGv5EgDQfD195iN/QKi/KV65p2CdLcp/stE4e/9+m81xCRV10Yg2DNU2eYvlw7QJISeBr8Tgp1uceuv0I9qlwKtGfz/Qf4N3XmbxR/VT5FW7lA1uTJNqWyMv+LFHFPURN5C9Zw9pvyXMPF31+d5t1H7MDRLH8Z6Su9D+h5FuZO7fAfUDuF1WHPmshNy2WXDBj1AfNDbTC41ggaJ1H1R1J8Q/OB2dr62hrp8h65MqhFIMcPud2lNcrekFuFKyuROZvxoHaE/xHtDK/7T5TQNyAI8db0Up6NHjDz9Ro0Zg7PvPfjh4LfYsMyn0CBtQCO1CW+C0XLgg1bFUzDHZZs5hi1Rlo/x1WArYczorAMc+wuNy7sov0/ihluZSinfp3AeK6Lxi++/ntjsva4ja6Ehc+QwASfpVkuXcVhWFN46JHMiYunnlT4fTWAu28bLcYlsCNfzVhAueZE4xllDJH++fEUdFgJteD6ixNbBPi0qkDePfPBybiB02sPLIgp34+J3kzkvPmaQ24FJ21O1eOWA4dugIRAL5fsWervbOFTxMRjzqy75FGtQ= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: ccb123db-7ca0-4f9d-b3b3-08dc3efbb9d6 X-MS-Exchange-CrossTenant-AuthSource: BL0PR01MB4226.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 23:10:05.7255 (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: M/OLTt8qYmRLHp2ovRFi/AtIIxIRRn4okPTc5dQcHUNqv1G7Gg8dbv7sDpeyxRPwGPtiio0kCiQtcgPCj4PmLIWv0B5zs5XyyT2r1mD3bpqxjSXB8lO9+ZoIB+2KdWIm X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR01MB7116 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240307_151015_602989_EFDFBC92 X-CRM114-Status: GOOD ( 15.32 ) 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 29d46e0cf1cd..4a4cbda94907 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) @@ -1389,7 +1388,7 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn *cmn, set_bit(2 * xp_idx + (wp_idx & 1), hw->wp_cfg); } -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); @@ -1399,6 +1398,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) | @@ -1406,7 +1409,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; @@ -1919,12 +1924,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(cmn, 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]))