From patchwork Thu Sep 5 20:47:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilkka Koskinen X-Patchwork-Id: 13792987 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 A7494CE7A9C for ; Thu, 5 Sep 2024 20:49:33 +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: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:In-Reply-To:References:List-Owner; bh=6bEZfU9CPXhWTeY88jGqHAT+Y7Cl3c7XFLardbZihFc=; b=i8k9LqcsfKk5six2X8LbFvvS3u fkMxVEsmRhitx79AC4EbHe/FKDtEZXCc2doEYRATcdOQwERKI90faPNH91258kYwRuU5pBcJsESMw dkRUuIPDW/RyEyG0t0YvkIYwLYOnpKWLlS2rDfkAvp3SJA4OQI+aaGQ3VAGlEZMEwtBqO8Zu6rAOJ FT21itpuX6HtCE53UAr1wnpJbQeC04Km74Mg3UIktVmAYzvgTIzhBVXCHJ9vJKMW23aPaJTioFHal bcVATJx7WsQufWkZD2WBaCV3mTB8reew/64KYlPOmHDNJLNbh0vsdH3oRWUs7OH1hru6aZZ/nJlGD L8LyRNmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smJPv-00000009ntp-39Ya; Thu, 05 Sep 2024 20:49:24 +0000 Received: from mail-centralusazlp170100005.outbound.protection.outlook.com ([2a01:111:f403:c111::5] helo=DM1PR04CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smJOw-00000009nfW-4BWi for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 20:48:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B9637AZKn7CBkKg+ixaI4vaNpwgzszPaURJ8Giyszs7s/A4nXA/cQThw2ccRpeR2cJX/ltmTSzs2BnwJWbQlqVp6Um77nTTJ3DHjWENnLO5yThU0IkOeFbnJCFcbgmibFPdlrwHgLlsM4vNAGAuk70XQD6aUjcUqacpz7+FkKQELdFn8qd72YdqAtOee4EK1Edk8Sb2rGGolxXXNfij+4DvzH7le8HX4bUm144eO9tFCPKHMonDeouSbad9XMqPeh1qmhfVN9SAogM0c5ekkJCckNYx1UZKxH5vxa/N1yRVjvlIf/LPY+v1OJw7L6SyE9VBPvJGZB7GJFZhAK2vqYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=6bEZfU9CPXhWTeY88jGqHAT+Y7Cl3c7XFLardbZihFc=; b=aic/Wco2UgtxyYSDvi4i6k02g8MJH70guD2X6yjVSY+kR5jcBaTQXiVYX5ksgTnVRAVo4IP3BQnXUTXovcHe2A39TpkTGh5NysEPqxZYOCi+MaMcvwLnW0ZN7F/c02Q7qq81xzV/BQ9Npql1jLsUtvdr0G1bPRp7rrM7xVOhIHMcc4PmALcV8tcV+WW+/pRIuKZ2o1OUbQqTX6lw4tr6YU3DqkAA+hicgwYN6akn2wZlalSeQRS59tXveAQt6jV6fNEHTotCgmm/bwfboN86vypDgeM3EKC28aKvLJMsxvnblchO48RKLHhAUdV5JfqpxpUpVXU770QdkIwc26GAiw== 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=6bEZfU9CPXhWTeY88jGqHAT+Y7Cl3c7XFLardbZihFc=; b=g0sOiDshDlk6jveDSoS9LGnwu0L+qnj+kyvri533GyqWNdjfceY6A45cvi2/9IqKJxC9LhDjHoJLPgqYzkzuQZ8qjQXBGPTOmkaHs5FG1lvcRcneFI8ic1E3fJpMTnuPIBa8TCJD99r2JcFuChSW+TUSJYLG6D+hRpG1DzBKEoU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SJ0PR01MB6237.prod.exchangelabs.com (2603:10b6:a03:2a2::23) by PH0PR01MB7236.prod.exchangelabs.com (2603:10b6:510:10c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Thu, 5 Sep 2024 20:48:04 +0000 Received: from SJ0PR01MB6237.prod.exchangelabs.com ([fe80::ba9b:75fd:46b8:c984]) by SJ0PR01MB6237.prod.exchangelabs.com ([fe80::ba9b:75fd:46b8:c984%3]) with mapi id 15.20.7918.024; Thu, 5 Sep 2024 20:48:04 +0000 From: Ilkka Koskinen To: Will Deacon , Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ilkka@os.amperecomputing.com Subject: [PATCH] perf: arm_pmuv3: Use BR_RETIRED for HW branch event if enabled Date: Thu, 5 Sep 2024 13:47:32 -0700 Message-ID: <20240905204732.20546-1-ilkka@os.amperecomputing.com> X-Mailer: git-send-email 2.42.0 X-ClientProxiedBy: CH2PR04CA0028.namprd04.prod.outlook.com (2603:10b6:610:52::38) To SJ0PR01MB6237.prod.exchangelabs.com (2603:10b6:a03:2a2::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR01MB6237:EE_|PH0PR01MB7236:EE_ X-MS-Office365-Filtering-Correlation-Id: f76db03f-4d5e-4597-d9ec-08dccdec0a1f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|366016|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: G0lvclgfD/o/Q9AoEx5PaVi9yiCP5tkwMNHoMsTkNMntStHmS74qpcBLjok2DFvf2nEEjGjdtbErFOos0kqz7T5gNJDgoKNMdHfbtdyLe0JC11dccrEEoR5bUFhS0OAVvPrnsc39c2SFL5R+kKJlJL7Q3V3UK5NjG2cH3JV0blhTjBnJ/0TBEsj7CA/uEx3qbNoaOaZ7JYnr6UKCKo4eNu5a8yiQekrkbBVoK//vdYyK+8dXVc+U2z1KHFzJJ2lAzkBN05OMHCkWOPv0t9Fsw/TdvRjUNjnRdLiYY0F+7EhKxFf1uHyWzXpsXUWLblKUKcujXtgdP6Vic7Cm85kG4heg7dqup1csxicc/D+gmb5Gpq23O/GnLTqSB4YXNWrb5Y6nsa+XLSPK2aWCchnCzs0rechLVhME4w56jXT/8t3XikmaaavSD1dyy0J+nsPC0aCh2CpcNhgq2kAOoFZrGhQsh0w8ee1rpOZ0tZOoae637CtiHU7sw82FgITLSAegFnhR5LmlivC0JJQZkitXetE2FAgezti30POxW+WIO4qSzKcfQcOQ5MA3SeBsGV2m2DtiM9egbcEmQg70T+isJR+xQc8V2cN/cqU5k6T8idbGMTPoiWF7+kP3r6s9+gkJLNVICbekeaKn1/xWgA4IlMTqjY9jw5VEFNdY3SaQentgK7g28euXBNwWpP5sV/00qURFApIH86gZDOi2T18tSJtjCVQfbVlaV1XTYSiZXn7lp2yiZDiSbDN4AaMenK6lto9K0ipBqN1Rqa+4JIi8NS85MkEAYcGLcGcqSz8fcU37oAlY3bWmaI/MUIuBTs+DAH9nRtsyygx6aaeaSpcB4N/d9BRAABqOEciZ1vY7nEgxxfOctoB5ibaYDp29Gvwn9WGHEl+MHBW/LtT7Upvcb8Ofll+yOJ8rXisCq02sD7KL3KgOfjVuHHxYVnrBn2dwrCLDx+ULDMLe2HNjuiLWNeiIB5tP34s7OFLjcajrLQTz/Ygpih9hxWhHGth2po2yMM3AnQZHE/OJ0aV7rRs+vmZIRUhe27IbP/urlY8dvDh2AOAb//lZGc8BU32klHycADdH67npIXTvBTYhaUWDewdhW+QtclUCRhxxY8blwJkzNCBvdKfgph5jk+3pYq3PiFRF/3loI+8f0tqB8c+VEmpGnEVHilF2ibiz5nevwoXw83/sMOGyzzOqp01YJMgUfYlu0P/TlsFdLHvC5WN2oYDB5IOo6240EjvXAetlDQCarMAWUCmsRMCEg3Pdzi/chPMcGC9JhgGbJLcXHkaKITr3B08Uagbx7OOKDFsGe4u0lyXxsOkbgMExyyKGCTd7MHEOrHxXhBHehVNwDPVrtIiXm67nIQ8h5Gy9KJSVi+ZTVzZW+GuN+H3j/b+LNYh4zFybsGdCsvh6Q5cQP/f5cA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR01MB6237.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(366016)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JRV2Xo6yrtJmbiM6VMuCjuHEkDM0F0n4IJG2Q4RXc5F2RN7IDfyF4jevUR+1djHxQzwAQWAY/OjSwtYJ0m9YcrNt3jPUB/zxClV8TnV7yP03iA/RJ/hj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dI0o5Bqm7j+ydTVVZ1/p+ukzl3fKGlWy8ug40yBIHQCVlT+INKsc0QGdGpggs/7m9IqneteijKaPUIAeQDcdhWTTdUY3UL36oIgqMy66c/qWJyML1+DH/ggvCzYIXacyMGReZL3zALvVdTS+RAman0+Vuhe7HPCcbz+3QdGvh4ZdtrKxhl6abl42GA0OCfIW5YTCObE0L1rIhDu10KOVV9ti/c/IXEAIk8xMc3yXQ3yvPeysnSaPcqrWr+OX8Fma8t3gCUOfIHH70nPWczT1PTylg4mvPUk5JNTEHPyAmwyv5CMfe/eB4N8W460Um8RX1YLPUSUADCQuwwwtpJ1QqNnV0BtlAkfjvsgDt7FBfrDQ4cjr9nYyBJq48ire8AS5L5maeLdXjjHoS63LXKNs8LmFw/66jU3YRJWB7vSRkd9K3AogqKGu69WJRb8x+Xsg= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: f76db03f-4d5e-4597-d9ec-08dccdec0a1f X-MS-Exchange-CrossTenant-AuthSource: SJ0PR01MB6237.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2024 20:48:04.6851 (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: ViB1tTLghP2vLdzeYsZCV2ljNyGHHgyRb8MNsUcLZveZ3JfturUVd9LlAO98ZdGerdNcNXfngrPJL4Iy9SV+yqALrP8w9fMWrUgmENHTT1CIYzojy82icy1FNuBPP2Ir X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB7236 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_134823_047627_75726CC4 X-CRM114-Status: GOOD ( 10.84 ) 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 The PMU driver attempts to use PC_WRITE_RETIRED for the HW branch event, if enabled. However, PC_WRITE_RETIRED counts only taken branches, whereas BR_RETIRED counts also non-taken ones. Furthermore, perf uses HW branch event to calculate branch misses ratio, implying BR_RETIRED is the correct event to count. Signed-off-by: Ilkka Koskinen --- drivers/perf/arm_pmuv3.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c index d246840797b6..a8ed08df1411 100644 --- a/drivers/perf/arm_pmuv3.c +++ b/drivers/perf/arm_pmuv3.c @@ -46,6 +46,7 @@ static const unsigned armv8_pmuv3_perf_map[PERF_COUNT_HW_MAX] = { [PERF_COUNT_HW_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_INST_RETIRED, [PERF_COUNT_HW_CACHE_REFERENCES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE, [PERF_COUNT_HW_CACHE_MISSES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL, + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_BR_RETIRED, [PERF_COUNT_HW_BRANCH_MISSES] = ARMV8_PMUV3_PERFCTR_BR_MIS_PRED, [PERF_COUNT_HW_BUS_CYCLES] = ARMV8_PMUV3_PERFCTR_BUS_CYCLES, [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = ARMV8_PMUV3_PERFCTR_STALL_FRONTEND, @@ -1083,28 +1084,6 @@ static void armv8pmu_reset(void *info) armv8pmu_pmcr_write(pmcr); } -static int __armv8_pmuv3_map_event_id(struct arm_pmu *armpmu, - struct perf_event *event) -{ - if (event->attr.type == PERF_TYPE_HARDWARE && - event->attr.config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) { - - if (test_bit(ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED, - armpmu->pmceid_bitmap)) - return ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED; - - if (test_bit(ARMV8_PMUV3_PERFCTR_BR_RETIRED, - armpmu->pmceid_bitmap)) - return ARMV8_PMUV3_PERFCTR_BR_RETIRED; - - return HW_OP_UNSUPPORTED; - } - - return armpmu_map_event(event, &armv8_pmuv3_perf_map, - &armv8_pmuv3_perf_cache_map, - ARMV8_PMU_EVTYPE_EVENT); -} - static int __armv8_pmuv3_map_event(struct perf_event *event, const unsigned (*extra_event_map) [PERF_COUNT_HW_MAX], @@ -1116,7 +1095,9 @@ static int __armv8_pmuv3_map_event(struct perf_event *event, int hw_event_id; struct arm_pmu *armpmu = to_arm_pmu(event->pmu); - hw_event_id = __armv8_pmuv3_map_event_id(armpmu, event); + hw_event_id = armpmu_map_event(event, &armv8_pmuv3_perf_map, + &armv8_pmuv3_perf_cache_map, + ARMV8_PMU_EVTYPE_EVENT); /* * CHAIN events only work when paired with an adjacent counter, and it