From patchwork Fri Mar 29 01:32:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13609871 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 D6126CD1288 for ; Fri, 29 Mar 2024 01:33:12 +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=iHxjLfTcE9jnnkZgwMFgMUy96znar9d5aLi5BOCNhTA=; b=WUNQ/gF5tV6b9E n10kFOu162ij1OXEk9Jqd76Sg5vFKmSzsJ7QwZKco3ztpd8zSJl6ZICT4dXM8hLl6UbCKl7inaqYY n8jHd+KLPa3snOISrnf0+uWoWQBSdIcYXhl02Tt74hPXVQ5Hz1S4I9GqqBpsNSQOXvTqyZU7xaQRH Pefh8FqwjiPLlaqLvpWdcSn83kEnOEKxuHAazIalwlBK4GTFbAklELjniq45kf9/ccurUzVStFaTj xhroKZZwnjbIXg1hza7Tisc54+FuNEGuSZxgoX8jnHFTp6J/tgYuqmoOsANbst0IeDJdcOZfZibk+ OAqi95qn1FvMAWZnsYAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq177-0000000GOH8-1iBi; Fri, 29 Mar 2024 01:33:01 +0000 Received: from mail-co1nam11on20701.outbound.protection.outlook.com ([2a01:111:f403:2416::701] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq16w-0000000GOBw-3Pot for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 01:32:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aAJcmHcgbTCPDOI3eJIiQwk0CYvoV/DEJI5MvWkJOPj6mHb17jnQ9X0Z2f6t1e5RB5TqKZreujrIvy2D/+AJCa3qRk4GwUE35GZvpSSygYYKercueyhaUPdGYsDuxfFw455gYA/WPh8gZ2z4ZVH4iCQR1JqKNSx3quuW7uIcS8x/nF3FE5Td0EhpUyUoikk6H6m+aQct9ZevUOzfp06XUnxVua717caQ8m0P6FbnOOIPO9UGoeLNAtzzb0U+exwtXR2lhgSJCYnbyOxGoVGW/hB48r2qpaad/r0J/AiE18h5L3cOHY1CukhC7NpaKgiWEYOrWzkMR2tusGHWSdGiUA== 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=ll5JW0l5WfxPWTGpRYxt/P9NbQPRIrY/boPHLZaVqVo=; b=cBQ+TYsPbK1cqW3EZN5qzxr7t4q/hrTwFExq84Ez0e0UtYj2m27UE0x3JEby8OesXwvHvIcrGPeF9ksCvqFG6GkDwrc4r1nm0M7AANx/eQ5/ymwxjCFISNoi7YePSZDBCDGNpzI0XS6iK2SqJiKoiDB0WNXkor0HEe0nsBW1d0m55omUipc/NCqhxNKvqU+mubazRLb49brE/V5MUjwQg8S8oRl3bteTJfNA+s2mY8kj+LH1TZ45Viv9hKVeE/2BK3wkHYUJDGPnseJNGTXWEzVilfMbOUvPq1POS+dGKRQDEwKpBPIcIiSIrd5pZ8+YkC5PW4nWyIxXqXOJVRNhww== 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=ll5JW0l5WfxPWTGpRYxt/P9NbQPRIrY/boPHLZaVqVo=; b=Ivk9n8G5DknRULFYr/8inYvXnh8n97r4VMnVZg1WGDHUgjE0K/LwBzprHibv6wnXqSgaazNJyQhv9lHXtoZov1QwKmm099roZqAgz1yM6mOP3bH1TcUxh0ryw9xeOuyGcWzXnwER/otN60ycDIeKhhPFtBFa9K9vXQwA6bMnyt0= Received: from BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) by DS7PR01MB7878.prod.exchangelabs.com (2603:10b6:8:81::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Fri, 29 Mar 2024 01:32:42 +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.7409.038; Fri, 29 Mar 2024 01:32:42 +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 v3 1/2] perf/arm-cmn: Decouple wp_config registers from filter group number Date: Thu, 28 Mar 2024 18:32:14 -0700 Message-ID: <20240329013215.169345-2-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329013215.169345-1-ilkka@os.amperecomputing.com> References: <20240329013215.169345-1-ilkka@os.amperecomputing.com> X-ClientProxiedBy: CH0PR13CA0008.namprd13.prod.outlook.com (2603:10b6:610:b1::13) To BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR01MB4226:EE_|DS7PR01MB7878:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aGQauRpTEm1LBxllEfx3pd+g0M26WFOQFqZKAUurhFIk1Cgjz5l9aYl+NO+yl3oEAHm6vmPv51QTMB06IOFhocnjQ+cRDweaZUs/gG8vcN6PEuGZcJshLRriX/HvSS404IYG2PoIEZ+/vNbrTNl3qJxCJPtGsTQMKPMXHDub0Xpty9okko0I1VsbhUpB4squYgnSwMZzIG+qBXA86BaNXWk/TWXnuOJPrked0FfUj9GPoPch8iMDSVQXhFQppshBCJ7EDAyM64mnAQtpWJuMLMwV/xUprUGjeSp44iFH29ASUbQ2WD0rgN+KJIOdxEPPhzhhVhLkAu4+EiezuDwtElPLVs5Ry8/EDwQSVJuygiBdTi9EmS9VCb2O4uf8MckV5GgHpjZ0oQ2zyzEcQuRl/21YhqoPhKe0t0OFIXL+hSC/30RYKSGuzRlglYyqCtqup1FTmmnPi38KE1RJttpklDlb/zxp5wq4hIR1L+B5prM47Z02YKDgNmOdP8gPJFqHkAvQ3d0vHzYAtE74Rj5kixla1vH/9c6mQm8aAY7McmLR5ym4CRlKdNjgBtMXFA3s3WU4owjj44aOFzfVkEgXnQvgzFqACGJmBVv6G47pvKLglH1w4Kl7mmeOwzo9BdvbDfbMZWN6RAeMZesloiyw/Yg4Uz7ejArjmHO4FC2x9M/AB7pmEc63L1FfrVmzmjxPeWEU9KThYoYE+b27kjEwie2ub+oxE0oaZatqztHz3VQ= 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)(366007)(376005)(1800799015)(52116005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UV7b3EwDusVmGdHQ1lZqFdXb75TfpfU0cS4P6uVaBGJQ+XNE2LM8gPkwSu9E9kkVom+TKA0kbs+jY9KINf8ezNXjZXXHtqAZwCye2T+JtQ26d7GJYwgDpHeH6gGzuVOvA7UN1lVqJnjlxEP+2cBQEsdXE7lqNZeUhxeT/36Dp0eefb0oHfVVcLJeQuYJhjZuVaC4jBDtfSpNkpflYAYMmbIqDQoFT2AJAkT7TuZnvKnhQMZVszNemuoKcqJ20xnqTZhirHSr0tpMFdveuasCBiiy7WlbIgQrLZTBHRVIQkeGIWQ6v9kQG7hYSMkNHscdC6xsvpFCv3GcslXYyYfVNbsguE++KgKyZrHrbqNhV0mbBHjMqrtT/rG7eJusSVHeawdozykAhECJ508ciiXlVizAp+VcUePDgiXBsDGG4LbzMBSvt9rvq2X2POg5ZAlprp2veRD0DfYszSnSGSOFe09Ir94NCTZJTZ7n6bOnek60EjWQamwgFI+ournCedjZn3KTJfBUhoCeDYLMC+ZaXmk6nNT+ORfgAPmdo2cBdOPJghWYn4fOz4VojdDDmNC/6ZiNEmUO+C0KejeDyN+Napv99B0c2yU+LohsMaKRGK/gGBEUqrSgbDsT2+tjwDTO6ndQxo4k9VJkvIbKjdhnF0meh+luzSbjVdfWDuEhoEuEGeFUmdVgV2CT3cEmoejFuMlv8Msyi/aiC303M1IQ1NoxsfKe2H+wAN6Sby+5YhnvNUrdGmzMo3iEgPbxpa1j36/Vd3kvTCXqAQca9tOHMSf9dVg/6aGFaR6ub+neFCVdJeND0TqcBSIalOcqbfSeAPt0suf/Q6sewT29+VQhe2DtaE6lTMpznOGRGQ+qtGR95ACWfwLM8krZkxBv+9AYoYGmwTqlpcmUsQ+L2bHe7DjbGtDYceQA1M0OEO0XFvXiVS3zPou8bmM8rRc81SzOk67v3HI/pea0oL4Sc6mvJR/jWZtX2WSDjZi7k8D/pRbrwkU5wr8/EDeLrvgHMkTd+BTxk8S1tVwBoIW2TUUBGpVDJwwrT5DbUuJ3HgEhBoonSSkJer4V/MUKhM6Yfn6RayKVbhyAOCyfLmtb4hzEPEyBr3tTxpaH23hjSKqy+pfs6bItseuE4ojU0gOxA+WzbR3SzCrWVCxDP7ONfSvsQDGEfM1WIwk7+mKB0qAlaMzVECetL8FbqYLcijOnUxIvDO77EIhCOBOcNUkmPIses++w+8Vg3AHOJ66zfbv660Jwm15XHKyHZKyCVupA+XuiqlukYtvpydbnj2NYY4c/eV6VIwYzHpoKDEG5Wl6EsX1mtFLtjvM0/xBIXrcRpTpjTeDCsgzXRRZ3EQKPHrwM7zK1xY2IJjdrBP8X6nodbrWhYZD1hViqUeLwRTmpOwq5P0/ZltRwaclXo7Kkzbb4QPvBLchkKSFOlyYFqXGtFOeFhUTknhYgjdsdiPyY23lpiVXfBnbkuFLB8scicbXMlDFw/UQd5DzF5AONM25/VmdbWHIHoiiCcClbLjTU1xprbxuYWyBE6nmh5csAMvxMFulM9sFChxn58uT9UMp7IYgMzZaMw1ToPP2hRLXkDKKuDhL/iBT0wwQRKXiCWa6DNOw98R9QZubMSdYp78DKLtc= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3fd1745-5458-4607-08b2-08dc4f902111 X-MS-Exchange-CrossTenant-AuthSource: BL0PR01MB4226.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 01:32:42.9339 (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: K+8mXnNzUquQXjpdYIbRBrGGQfhY1Px9efsIi90APIXWKmfq0bvS5A7Qz3hwW2YBBOb/3EJd1R+mN26BjPx0278621CKPkoI8JsZpcGFU+4SkVoSUaotr1nH0rPNShOf X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7878 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_183250_892873_6DC332AF X-CRM114-Status: GOOD ( 18.64 ) 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 7ef9c7e4836b..9f4a82861faa 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 Fri Mar 29 01:32:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13609872 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 767A3CD128A for ; Fri, 29 Mar 2024 01:33:14 +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=InYL8z+AlIv1V6tj+E2FX2yyEoSWkdyNyt81lKaXNRU=; b=JO5HsZe9zbr11u zWkez2pWjlrlucObGzsyRdr5RY4k2DrFCIw92pYaNhCbT+hzb87wASnwh6lMyzUjC1dnoa2r1IvF+ cCoMw5nK9emXy+azMlHGDfBY3LLYu3yPSO/+k71vRIGDnPu6qvj2T1gB/HKwdg5GB3M0Tw2P3e0mb K2ugRlTdzSB8exIRheXI/k6o2gDj79l9aa5XgpYSRoJlYEp4ghpoNuWmpGWc2flj/YP/0QQyio5Bp r2fOSDchRaSL2RpyG53PExEGVR8VYpk3odck10QBxmpUd3UDJM+SqfVT3PMC2R/wQimsgUwQ28spb EOPZjmPQc8CKBzGJ/e9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq178-0000000GOHk-1RnT; Fri, 29 Mar 2024 01:33:02 +0000 Received: from mail-co1nam11on20701.outbound.protection.outlook.com ([2a01:111:f403:2416::701] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq16y-0000000GOBw-0rCs for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 01:32:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GqITA1LouALJWQmaMV0ViwNFD5ljTXS++aaPmdcyeF15KIoPa81icz77QQ4dTRjA2KTH3eCtv/G9vS1Vg9xyywxFS6glX9QnhAGoc1DJ24Zx5/JKCN3duv0KQLhdtpAXdYuC45oWYsUMG1iUDzaQ1RWEJ3yjdTbiE9+ZkpbJ9PcyEOzwyfM1O+h3NhLGSnBS5g67wmzNZlrh8FfFgWXi/LANGL/UazuWbCRlDaJkdUyWX6W45mLBhm2JtujUPLRrdMHoL1/N5eJC39cZWrsHW9muk7TDk0lzTlhJNd5R69lMq5lpWpPMb/UieFp41vsAReh8W5Cwi67DhkHflgb6bA== 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=yIlgrDq++UMPhf1VB0EHtOXrFD9q9CvhESCm85k9EgE=; b=KdvXTooXWV1mpeG8zSwSTj4PJxjEwYR3PEi3bagSyJWodAqjRRwptXDEcdEd2yyHG5GY1gU+HacLbbTmccJGPQhqpua5sQA7CDEZcAdFN2xbnl3ANUzlxq2OB9b8z8jx6AdnBWrFa8OsjELGu5eAH7otJnZKvcwmRk9BPTocViP8w6ldikWeu7zRRUHH3KK8w3YACUkMSkR5keZtjjEvqdZf6Y3zOx1JYAzxUlkCtvPs4bbWjW7/GnbD1KaJKf32LrQkDD+N15kEMYBPwS+Q4iOtVH6gtSIKzFMu+kEUuqEcUx4DQ82f7enIWXZyFl2IZAT4TteZJyhXi0UFK4mudA== 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=yIlgrDq++UMPhf1VB0EHtOXrFD9q9CvhESCm85k9EgE=; b=JLWKVD+zcZWtpKY6+tAzTfA8mYyw6P/qGcDTG08anUzDwaHBCQLvLedm+VNJ1jK5ODRCaHrfUR8PapK4ALDoJgbc3EYNScDqQejVEeJtyRgAlIritTzOGAjTFXVW5OFSS5/0lnOKtMAfQFg8nFDkECXk9day8EQEIFHtGdYV3HI= Received: from BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) by DS7PR01MB7878.prod.exchangelabs.com (2603:10b6:8:81::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Fri, 29 Mar 2024 01:32:48 +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.7409.038; Fri, 29 Mar 2024 01:32:47 +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 v3 2/2] perf/arm-cmn: Enable support for tertiary match group Date: Thu, 28 Mar 2024 18:32:15 -0700 Message-ID: <20240329013215.169345-3-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329013215.169345-1-ilkka@os.amperecomputing.com> References: <20240329013215.169345-1-ilkka@os.amperecomputing.com> X-ClientProxiedBy: CH0PR13CA0008.namprd13.prod.outlook.com (2603:10b6:610:b1::13) To BL0PR01MB4226.prod.exchangelabs.com (2603:10b6:208:49::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR01MB4226:EE_|DS7PR01MB7878:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SbG9qLf69RV3Fnf4b+OGbXFBCzBb7MIom/4VY0Zaa8TF6eVblRVeXaZVScbTKq8CIYxIMONmJ3vtRJGbUUhQC/y+KkDWHdqcCbU1ILGMRQ7w5XR1gk5WKe6EitvOFBp3G/FoSZhP1fp54huO2AIHfXM43qjlb2lHWzTQNdbjGOAc5T0FAU5H+sBiXL+7UEIGqdZZcQvSouXT3w+8TVKCjwWn1zBMy5v7MRO1lQS6SktVISkvA6l2n6t7KzqUvVM5HHSEgu0de0UCeyBKNmC1p2XyDzcC2Q3+rWZkpPTbWevRPniVXGtq0uIUwHJfnxnbDuMrwfpgtig7j4aqQF4hBz0ypg7AoQp0BDiDM1MVb/PMOCqKc/TjtiT6m7EznhhSbotfqgx8dyEw7S0Hb7d2tnTf5etDoDo2fZygGKSgUepKJk0HReiafJYC1MYLF6Uk1hAzb/t+4rR6z89tmv3mPM/Dyp3jl4AQH/6tePQGux+eAbeeKCZgvChBvuekc3fsRzjCoVttQ0JDjm8zjPRnfqu/zssXgvS2GOf3MGH2qNyOZ4BqtD0JxPdSHDonSKiV2J4ZMmE1tTgd9y8QE740yEPDXfEIbDuteIPhiF8IzwITd1AwcIZKnrXZX7pyJ6XoRZ194F/MRsotI44O8/OZurkFYDwjpwAsQtG5IFgFo0AZrT8xG4FJ3JYt3WKv4EYtiEt/RFX7pu84Imk+sHryXkaW4UcrHxdc5ICTkepx1OQ= 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)(366007)(376005)(1800799015)(52116005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vxYU38GydlZDKK9eTTbvg+mPbf07/ZwL4A0OjJP+Vt3f4PbgKgbJ03Pl3YfTal3YVJ/GPVkjWL8DJM+vPqJO59l06l8f/ZFau4D9ZiKYjtCAqGPRKgDXYjJj9ULb7CD9lBSGzYBQ1sQ7y/OR0qX6L5vxK6nO4jkjcQIF9BMt/MP9rDs20hbYh2jHR2KVBCt8XEhYgGFck3v5/AMshoXDwEEm1ZdQ7YweetrazvF0LG6Up+lUa3wciOksdSyn1ZCnnA427Anvh6/c4rgrEjpsurMgobSobDkUHkxnmjRbY2fRObUXltZnrYDRJAFLcrKkwVpRVoFqukta3OQ00u/n79Zqo5zbNKHZxnL9zm3fam16yOBQEVDpuAwa8g0CmHy64tOXro+HGl6OM+zNiXv+rLbrubnpZwqH4xvAJQafqkKUz5V+/+AInxLqaFg5Llf0AY9e0XrauhqsGEVqOUMHl5X7dfYoKCqUShRWyXWFYPXZ2fP3sxZcXUAV6fatObZ8AUipw2iUSxRUZZ8IxCc7bcSD3RNeGhw+0IbczEzxowvlvp/+5eAnVlgdcoDbKRM/EM6TCyDB42QiMPVM3NBz3s8d1EQMqj2GdcF6FNE9tmpYJC8HXPiNvslh/GQa7470y5ZIsakCGnoiM4rPo7kfCCw9zhb/k4hrmCL1++GHg/Vl9aCaXRPMLRGMW/shHliUkfE/kZbvp/bP6CFbYKpCzlJMpAHA6px4FTlnAKJJx5TwLNa/hZlmNCYN+JIgqHJ0qVaisDjT9UWpvwRdJ9uHZ+9hAGhIY7md3OR4sWV6LIqYH+qq5546QrCAXfYGRrQeMDYJZ1xo0+NGhKqZsAJGSCGapZC1AXzYZtRS7vn2qsdSxM4cFggr2e+raPhWCnovwN7idE8ZeTm1N7NMVKnBpSY31NXl4S/WWkQ0Ruy+uHCRFgWOsgLCkOB/T9XhIHdIbk3EN1vtbye/BrdTKHtqDCjRb8Ftqm86MM2sDXTrqsE6fKJJaAO3p2mt63qSXH9qIhsLqwt87B3mC+KP1K66aTUqGJe5VZfp9Y1DF4RtgREH1Yl4A63TVV3YeFgvlvtc5U6zkjRfpPJNckWV5ygoDrHh5C16+QCj1TaLVu8Uv6y2lSYWcL+7iCfsboexJkC/S8XAdxqknfq0fGYVN2p9mkpUg8FamN9u3Nz7WzTR0KjaY0DjCP6nitAFROUmkQv2aU3uuz69MvDDZFbh6THGJFMa3d/gZzXEYgSy1JNVT/+669nLTJFsmJG1L4gkkvqIWYyPJkAYXFb1m9/6buNEoT3V715ETxjEAp2UBPStxidK5zDy6qDJVFivdFmjOJY+bhCsAYtKJ3iOkpIpuSF1iuIXJwQmei0S/WzZ6YhyebJJgP6TSRbYYcM9EVYi4lxtP3fmfb+liG+yUuVFMhd53wMp5vQQrRmfCrKtXrAMBVfwmoywkaza/I1DPWxOqUndkTe4CwzaW00KbXtki+RNxZArvq8Yhkn1iFjkznlkOZ1ktFHASA4tiuUK+cG+5t7lV3Fvax41cq8QjtEnTZM5KoeF9SrgHppR0i5m04GBUy5dwiJYpbnrDIDxvIGp6hAf1Lzk6RpuddgX6j1WRs0KSSeaPKiABz4UMePKboiJtBQ= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bf73bd7-063d-4b83-a274-08dc4f9023b5 X-MS-Exchange-CrossTenant-AuthSource: BL0PR01MB4226.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 01:32:47.6464 (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: R0lKLplhGi/g1nPtOodfCYXCNQJSENvHtDEfowBHtIz4tptaSRNEoAgRDlyB64UJ5e2cMp620RB1FVZ+/98jZoaXYqHPcJiF76FBsliF2wceTXEU4lEdimXRhHRwoOOv X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7878 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_183252_301945_D8872C61 X-CRM114-Status: GOOD ( 14.69 ) 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 9f4a82861faa..3d7db1254753 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]))