From patchwork Wed Dec 11 16:50:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903940 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 4FBBBE77180 for ; Wed, 11 Dec 2024 16:51:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF9AA10EBB1; Wed, 11 Dec 2024 16:51:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="XFMgLd/L"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="XFMgLd/L"; dkim-atps=neutral Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2041.outbound.protection.outlook.com [40.107.105.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3687910EBB1 for ; Wed, 11 Dec 2024 16:51:11 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=FLPNUWXkLZwsEybcXa9K3ijcrbv7WpjTZEZrRQLKbKmLPpclD/PJ0itsbEDklpuOvNeqAsjKPUUGHn59E17zarXdyWcfesuXNOquHXebWK+YUSRaMvjf66h8a0itEb0/i7dRB2f48UY/c6BGd0jSKr96pVupY56TQdZRE3jdPYA8C8kBOlqSCnYQG+Lk5wCbMUdxMJGLMTodr4S4ooWuBOmqSq8+AgFYesZtkRT2pskTlMAKHwwK0FV7mqthL26CoKGCECPkrG+/mHZAHxLDh7iaGg+0T71Q1RHGwVtjBOBc4T/OSkwRx3aZWTbbkonTpqJb2z0tBa7Mbq4JioSLGA== ARC-Message-Signature: i=2; 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=AaX14YeBrqQ55oL90hZxXWkPfrsjE1oA4+6EggOQyC8=; b=Uf+ywg+b5cyczqh/tbS2tpQFbaJytRjCkFS0McD/cns+K8sXy+6I6B8Ihp3haLGJUJpKi+ZmPz+llgv7xLZSU3xSPEM+A7mgHfGz1AJT9jfYU10+yO87WH+/V4k4wAC2PR+3ASQHO4cKgAaB9Dq2v9cwqzfB6sztBL0fTx79W383VdWHzHFII/iBkpGjHsjzFoC2VsykkPhe80bHbgJglDc6GkWyIXntuhg8bkl8E8vd2Kt880gQrHJE8tdrPtucFsT6pv03a+vY+glLm0ayuB6HYKS89pIQ5INd8cta3AmggLRUsWJgkfHdv4EMPDqsP3V20GOsv65I1T7W8gom1Q== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AaX14YeBrqQ55oL90hZxXWkPfrsjE1oA4+6EggOQyC8=; b=XFMgLd/Ld6kKWf1W9JZ/+/jL8CKBtab8BGi8xXSmDX9/7P1tKFPXmw+YI6Ickk/Z3910I7iy/3z+Ki6rDC4lsCSd6DHu1Yb8m4yHwfasLjc4qMAzkquwuG/V0bqIdq4VwXC1Dx1TUEBZj9S5JDpKAsNeJkmBSLT/+XFdrgEy5+8= Received: from PR1P264CA0113.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:2cd::14) by DB9PR08MB6508.eurprd08.prod.outlook.com (2603:10a6:10:262::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:51:04 +0000 Received: from AMS0EPF000001A2.eurprd05.prod.outlook.com (2603:10a6:102:2cd:cafe::8a) by PR1P264CA0113.outlook.office365.com (2603:10a6:102:2cd::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AMS0EPF000001A2.mail.protection.outlook.com (10.167.16.235) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:03 +0000 Received: ("Tessian outbound b4c479532664:v524"); Wed, 11 Dec 2024 16:51:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6735a9b1c298019f X-TessianGatewayMetadata: mPGgXeDGlzWhPLjJz6rDC4d2cvl90ccw1fRBdYPODbBdthwifJsUQpXMkSSYO4HYLdF/lbY/4GIEGWHrxUc/3gfug4OnW+uzaDjU+TrLw0KfWPLN+uvOA9YNDRWg0llQWvD+d5yM+GMFOtr6HAJteQFnZsKOR6MHY8RK4JLxblQ= X-CR-MTA-TID: 64aa7808 Received: from Lb4d115023e01.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 08B2961B-B90F-474D-810F-F2A149523A9E.1; Wed, 11 Dec 2024 16:50:55 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id Lb4d115023e01.1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:50:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WsGj0TMHKm4PbUpHkC3vRJoagy6AH5peNiF+Htxn3EUrPhTNUAe5dPaFiSquqynr3IRyKTTADr96g6PkpCvirhZgANHKXjQCRrtU9Ni34mognSM4qexcrowSdW64B+DB2wWjeBvP6WuugzoGuncWjiq5O1tbqGvPLS1NpiPJ43RQHAH0cbjmk8lY5S0+4esvETTy7vApIIMJAhrIR2IY6xSuB9ZrLjcdFBcwtvWnzcyFLY7v5KNsbUXGhltIUAALZutTJJCBQ9Z1WSJ3kuy0TB1viVLfGEULE2ViCkBh39PqoMwqDn9djXUT3+iOqZzNp0KkkfR5Xm3whvu5ih8B6Q== 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=AaX14YeBrqQ55oL90hZxXWkPfrsjE1oA4+6EggOQyC8=; b=YJ1CHGpx9xf2GBJHz66izkfnNZS/zW94aez85YYiWPlfLx8LmLAepFCzeWe0xVM89IaU4oxcSJGPlweDJGY9jjGztBD/l9vULeKOcrLb8pSTudqe54e8lHjp3vGIN14QxH9FWs57ekprTVNYhFpwOGTuM9kjYo5uGvdrm3guTKya19JF6hcTtHrSBm/yUBNrkROlIxhLAkWN98SAywlaho958uc/KOWALNVdrzmO6Obsd3Cgs0REVP8XEC4kfyNdWH63p16/pBQl21ATcPVoUJ10v64TSdvAVGoi2U2JXJkigjfx0L9PRT0nhxYz4E09rkuC7mpEza4SnR+L+j8YOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AaX14YeBrqQ55oL90hZxXWkPfrsjE1oA4+6EggOQyC8=; b=XFMgLd/Ld6kKWf1W9JZ/+/jL8CKBtab8BGi8xXSmDX9/7P1tKFPXmw+YI6Ickk/Z3910I7iy/3z+Ki6rDC4lsCSd6DHu1Yb8m4yHwfasLjc4qMAzkquwuG/V0bqIdq4VwXC1Dx1TUEBZj9S5JDpKAsNeJkmBSLT/+XFdrgEy5+8= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:50:53 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:50:53 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 1/8] drm/panthor: Add performance counter uAPI Date: Wed, 11 Dec 2024 16:50:17 +0000 Message-Id: <20241211165024.490748-2-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO2P265CA0300.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::24) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8422:EE_|AMS0EPF000001A2:EE_|DB9PR08MB6508:EE_ X-MS-Office365-Filtering-Correlation-Id: c939e4df-3ca4-4d0d-6874-08dd1a04000b X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: f1x9mEA7Pj3F1p1p/MQTC81bMimZQHUpcizg8JG2def6O9fiVANiXt0gWMQbvIanwAjF2mKoXt31s0nt5QnDRYyTguzVhv9+QvfX1c4MBfnVQUeIX0L3dD/J72X26O5c95UxpJRNQcDFPMZU2mPaBfA5aWfQRR7Jx5tHhn9sL/pDbjo6KIDip2V1IjvB+4dFW1KLb0LwQGTf7dy5wt13MwJuH9YA1wjJPosWSQCXZFAE8DP4NOTL7zjXLIER2mU9CmfHUoJGrgAfUwReQhvcs5eJHMtFRGLo1ucECITQph2aKNaKjdOb5M4Sm3CA0AZZzlZ6FyZmeP5G1uUcusFzle6e16ZO/9GzxBR9OvbIVlIdEKWO7z7uzmrvBU/qjm4j5GcVnkKChu9KSB0+TfLMOjXG+1/WjOaDSVm/Li5RdNBS9Xm40bW2dP/XqA1brWyehRzvXAYT6spncc6OWXiw5thBXDNljfDW8p/z3knW7/aqq1Nb79L++ags8/sLmwm9jzD+DI4PMdlGo+gUl63pXtzw7mH7oeZFBnJgNbrbslf05Z/+Ovtzffa8t3rcFhKa1uvqsQOhqA3u3jtA0nO7vZvsSI5ZkW/E6zn80e/I5Swwvpwrt2S7K/BN7pDAWa6+pOFhC0ely7jlyhCwMtl4qiT0mxtv89TFemDbkW+0oHNv8pqecOz3TZNgqC4G+nFbuBDtNW0S1wA+shbonBRec5hnpnAp6EyvBZPi+2loATDkbctBJ9Y8oripV11Pf62a9uyY37sWnJi1/PTju7HWWMQwZRwHQ6lLs0Tk7xQwWqIGcvBBlIVP10+JGGkVTTLiT6OQIen/61zlaI2X6fr5aJUEha8eNJxG60TTKm7nQQ+w+YvhWebOoyhzgAdVEqBY/rOYnEs5hxlVFhNO2yzp/rcdRhmlG1IJn0mvHQURPy2BfPldAZ8q948H0O5AXsPwLVH/iddAFuU9I+cJ+93KguMrMGWR1xyO5ht5wdWWroclaKVB+pMfO+i4BRwXmX4cY7/mSIfib7lRlIfO8LlsdGOQuO4j/dDTxZR/8459AgQPELOCdiQFs835DOvnEF5A9REfS1OIylsgGGUmJsW2COMp4orrbOUCKgOExXRA5Jnw/Hff6fp5uJxKl+LjQGAAlzCkYEj6heMPNpkbK4vLofHn9/OAsl6Ow1xED77eUkToqLlQH4kyEudwelnV31rt6G3WvuM3IT4P7/cHp2S2dwZXD08sgMJhJ8/ZLUQDtzzeU3PlBnrq6aqBRX/NFtVMPDlSxwaVXqmRRRwxoDwcWDy5rDwyF1saSQqilbX2wiAaYwj2GrbU2Kv4YochJ8d9nEbEgD1Xa8RERsg56Me0Nw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF000001A2.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ec41d26e-bcb4-4b2b-c35c-08dd1a03f984 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|14060799003|36860700013|376014|82310400026|35042699022; X-Microsoft-Antispam-Message-Info: Zms8MDA83Trvgj5chjkSzstcPXkeM9Nq/GSUqOJY4LNNIZCrIzqnNFTIAlDm2WekNG29OXkfkImU6fdDtDSgFBV6gApP3rcZmUb2uD+qMKoltYC2ESqVcl49UaaWanacwVI5UFaM9wP7gVLvtBteDvSnNvgI66L1ANUC7LDOQMruIj4qXqdvXg1XQbVtfj7rgJJAOQkFDHLJrXfXUN7fKog7xcs/ob4QuzT/UT2Vz4m7VXpJ/MFSGMWZZ4hno+Yt7RVBZ5HkZCNeeknNRT6oqvV8QUegRu2UKU3tWSmgv4tZYJ1ug1Vt8ATVbN9GmN7/R9TAq1nD/HcwAIeIyR1lp3FbB5zAWGqjyYf5m2APSsZof4oxFsmTfx2ofnHUg1Xp8qInn6Ob3Pu38+vEsA1t6mrcHPkyXrZxUKM/t+bNt0oVBBhypWniUtGUwkDz/E5POZ3LQ4ba3d2yEWTjJ052qI6FOo3nbel2TMKoCiU/v1nt5AiuSuGx2Oh/d89UMVJ8QescnMi7lIgCVAzse+KtjqT0hHpg3wg4US3Aq8UlBZ9c3tWBdFRnrEYAxFggie8nXFQz/sVbSpKSjJGXgDC1QoOP2yTOGJUiY5CwxTmB5SsytOgC/lYSkRSPmmZQiakopc8tBE0mU1B5FTnk7ppZVSok6OqVQ/LJmnRo10SNyMKGIad4hely1sgqOA9LGg0gngASnDX+qQ6PTEAlmPnAKfJwX42NrfYb9bOtLH2Npi2BnEMXli9JUIPpO/KrH7+pDuiHSTwtqzj2lcha9L5kAqH7DA2GOAbt0XGh7PHT4mbn5qodkhyKrwWWDig/1vFY2B4tkN3FFCCQoQsPK9KVM9+02WJfMJF9+9rCwDKgfB3sExtqTRGOFBDU8vukL/dgU2ZI9hOsjFKmOr5n0YeCcnrW49FddiV0Yhdp3zGGdoDZAAlu6e6A6tA81TeuxcvpN01nP1ApkxV6GBjMqLMic036IVc3iRYnYt/Fbrdxb4ggmHn1aTGvfypIjFbbs/7hUBGAdJymMXwU9oGKy5Gl/KRspprfTDCboXBqLeoMaU/7AkgRcaOhoQ1xdovDHoNozDsrUaYi6JcDFhDDfDrDHAFBt/V3dmL0DAM0Ex5Dg8GsLhZfCRfwknJiUX9kmSV3cQyeGJksZ3DUiJv+Czz0IEc1cYKSamt2tT6BVOIUept3ntXtwxEaHPUZHVwa2VVTPhYsXOwo40oymEznvg+5TIJR4FzHHjd/naOEhGjmN4H7joxE+aec/hhCASQEw7HyVrZp+qHhPIOTZzJigH/SpWp/rfHUbL6q6UTP9rkFQhFmJYl6115uDFd3frXtKmfHOh7USoWciFcwkfIxsNcubMef6m8sZYKKr7foEcZFNHWkIzarX/wz/2AzuIURNeYkEygLGolOeZI+XEdJiO5lvGtjiXRVpWjl/vWSgYjSi/SL15GoLdfiLJW432rZSXZ4SQSFDLHr+zflgVBp2T/+9g== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(1800799024)(14060799003)(36860700013)(376014)(82310400026)(35042699022); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:03.8792 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c939e4df-3ca4-4d0d-6874-08dd1a04000b X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001A2.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6508 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This patch extends the DEV_QUERY ioctl to return information about the performance counter setup for userspace, and introduces the new ioctl DRM_PANTHOR_PERF_CONTROL in order to allow for the sampling of performance counters. The new design is inspired by the perf aux ringbuffer, with the insert and extract indices being mapped to userspace, allowing multiple samples to be exposed at any given time. To avoid pointer chasing, the sample metadata and block metadata are inline with the elements they describe. Userspace is responsible for passing in resources for samples to be exposed, including the event file descriptor for notification of new sample availability, the ringbuffer BO to store samples, and the control BO along with the offset for mapping the insert and extract indices. Though these indices are only a total of 8 bytes, userspace can then reuse the same physical page for tracking the state of multiple buffers by giving different offsets from the BO start to map them. Co-developed-by: Mihail Atanassov Signed-off-by: Mihail Atanassov Signed-off-by: Lukas Zapolskas --- include/uapi/drm/panthor_drm.h | 487 +++++++++++++++++++++++++++++++++ 1 file changed, 487 insertions(+) diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h index 87c9cb555dd1..8a431431da6b 100644 --- a/include/uapi/drm/panthor_drm.h +++ b/include/uapi/drm/panthor_drm.h @@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id { /** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */ DRM_PANTHOR_TILER_HEAP_DESTROY, + + /** @DRM_PANTHOR_PERF_CONTROL: Control a performance counter session. */ + DRM_PANTHOR_PERF_CONTROL, }; /** @@ -170,6 +173,8 @@ enum drm_panthor_ioctl_id { DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create) #define DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY \ DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy) +#define DRM_IOCTL_PANTHOR_PERF_CONTROL \ + DRM_IOCTL_PANTHOR(WR, PERF_CONTROL, perf_control) /** * DOC: IOCTL arguments @@ -268,6 +273,9 @@ enum drm_panthor_dev_query_type { * @DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO: Query allowed group priorities information. */ DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO, + + /** @DRM_PANTHOR_DEV_QUERY_PERF_INFO: Query performance counter interface information. */ + DRM_PANTHOR_DEV_QUERY_PERF_INFO, }; /** @@ -421,6 +429,120 @@ struct drm_panthor_group_priorities_info { __u8 pad[3]; }; +/** + * enum drm_panthor_perf_feat_flags - Performance counter configuration feature flags. + */ +enum drm_panthor_perf_feat_flags { + /** @DRM_PANTHOR_PERF_BLOCK_STATES_SUPPORT: Coarse-grained block states are supported. */ + DRM_PANTHOR_PERF_BLOCK_STATES_SUPPORT = 1 << 0, +}; + +/** + * enum drm_panthor_perf_block_type - Performance counter supported block types. + */ +enum drm_panthor_perf_block_type { + /** @DRM_PANTHOR_PERF_BLOCK_FW: The FW counter block. */ + DRM_PANTHOR_PERF_BLOCK_FW = 1, + + /** @DRM_PANTHOR_PERF_BLOCK_CSG: A CSG counter block. */ + DRM_PANTHOR_PERF_BLOCK_CSG, + + /** @DRM_PANTHOR_PERF_BLOCK_CSHW: The CSHW counter block. */ + DRM_PANTHOR_PERF_BLOCK_CSHW, + + /** @DRM_PANTHOR_PERF_BLOCK_TILER: The tiler counter block. */ + DRM_PANTHOR_PERF_BLOCK_TILER, + + /** @DRM_PANTHOR_PERF_BLOCK_MEMSYS: A memsys counter block. */ + DRM_PANTHOR_PERF_BLOCK_MEMSYS, + + /** @DRM_PANTHOR_PERF_BLOCK_SHADER: A shader core counter block. */ + DRM_PANTHOR_PERF_BLOCK_SHADER, +}; + +/** + * enum drm_panthor_perf_clock - Identifier of the clock used to produce the cycle count values + * in a given block. + * + * Since the integrator has the choice of using one or more clocks, there may be some confusion + * as to which blocks are counted by which clock values unless this information is explicitly + * provided as part of every block sample. Not every single clock here can be used: in the simplest + * case, all cycle counts will be associated with the top-level clock. + */ +enum drm_panthor_perf_clock { + /** @DRM_PANTHOR_PERF_CLOCK_TOPLEVEL: Top-level CSF clock. */ + DRM_PANTHOR_PERF_CLOCK_TOPLEVEL, + + /** + * @DRM_PANTHOR_PERF_CLOCK_COREGROUP: Core group clock, responsible for the MMU, L2 + * caches and the tiler. + */ + DRM_PANTHOR_PERF_CLOCK_COREGROUP, + + /** @DRM_PANTHOR_PERF_CLOCK_SHADER: Clock for the shader cores. */ + DRM_PANTHOR_PERF_CLOCK_SHADER, +}; + +/** + * struct drm_panthor_perf_info - Performance counter interface information + * + * Structure grouping all queryable information relating to the performance counter + * interfaces. + */ +struct drm_panthor_perf_info { + /** + * @counters_per_block: The number of 8-byte counters available in a block. + */ + __u32 counters_per_block; + + /** + * @sample_header_size: The size of the header struct available at the beginning + * of every sample. + */ + __u32 sample_header_size; + + /** + * @block_header_size: The size of the header struct inline with the counters for a + * single block. + */ + __u32 block_header_size; + + /** @flags: Combination of drm_panthor_perf_feat_flags flags. */ + __u32 flags; + + /** + * @supported_clocks: Bitmask of the clocks supported by the GPU. + * + * Each bit represents a variant of the enum drm_panthor_perf_clock. + * + * For the same GPU, different implementers may have different clocks for the same hardware + * block. At the moment, up to four clocks are supported, and any clocks that are present + * will be reported here. + */ + __u32 supported_clocks; + + /** @fw_blocks: Number of FW blocks available. */ + __u32 fw_blocks; + + /** @csg_blocks: Number of CSG blocks available. */ + __u32 csg_blocks; + + /** @cshw_blocks: Number of CSHW blocks available. */ + __u32 cshw_blocks; + + /** @tiler_blocks: Number of tiler blocks available. */ + __u32 tiler_blocks; + + /** @memsys_blocks: Number of memsys blocks available. */ + __u32 memsys_blocks; + + /** @shader_blocks: Number of shader core blocks available. */ + __u32 shader_blocks; + + /** @pad: MBZ. */ + __u32 pad; +}; + /** * struct drm_panthor_dev_query - Arguments passed to DRM_PANTHOR_IOCTL_DEV_QUERY */ @@ -1010,6 +1132,371 @@ struct drm_panthor_tiler_heap_destroy { __u32 pad; }; +/** + * DOC: Performance counter decoding in userspace. + * + * Each sample will be exposed to userspace in the following manner: + * + * +--------+--------+------------------------+--------+-------------------------+-----+ + * | Sample | Block | Block | Block | Block | ... | + * | header | header | counters | header | counters | | + * +--------+--------+------------------------+--------+-------------------------+-----+ + * + * Each sample will start with a sample header of type @struct drm_panthor_perf_sample header, + * providing sample-wide information like the start and end timestamps, the counter set currently + * configured, and any errors that may have occurred during sampling. + * + * After the fixed size header, the sample will consist of blocks of + * 64-bit @drm_panthor_dev_query_perf_info::counters_per_block counters, each prefaced with a + * header of its own, indicating source block type, as well as the cycle count needed to normalize + * cycle values within that block, and a clock source identifier. + */ + +/** + * enum drm_panthor_perf_block_state - Bitmask of the power and execution states that an individual + * hardware block went through in a sampling period. + * + * Because the sampling period is controlled from userspace, the block may undergo multiple + * state transitions, so this must be interpreted as one or more such transitions occurring. + */ +enum drm_panthor_perf_block_state { + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_UNKNOWN: The state of this block was unknown during + * the sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_UNKNOWN = 0, + + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_ON: This block was powered on for some or all of + * the sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_ON = 1 << 0, + + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_OFF: This block was powered off for some or all of the + * sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_OFF = 1 << 1, + + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_AVAILABLE: This block was available for execution for + * some or all of the sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_AVAILABLE = 1 << 2, + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_UNAVAILABLE: This block was unavailable for execution for + * some or all of the sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_UNAVAILABLE = 1 << 3, + + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_NORMAL: This block was executing in normal mode + * for some or all of the sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_NORMAL = 1 << 4, + + /** + * @DRM_PANTHOR_PERF_BLOCK_STATE_PROTECTED: This block was executing in protected mode + * for some or all of the sampling period. + */ + DRM_PANTHOR_PERF_BLOCK_STATE_PROTECTED = 1 << 5, +}; + +/** + * struct drm_panthor_perf_block_header - Header present before every block in the + * sample ringbuffer. + */ +struct drm_panthor_perf_block_header { + /** @block_type: Type of the block. */ + __u8 block_type; + + /** @block_idx: Block index. */ + __u8 block_idx; + + /** + * @block_states: Coarse-grained block transitions, bitmask of enum + * drm_panthor_perf_block_states. + */ + __u8 block_states; + + /** + * @clock: Clock used to produce the cycle count for this block, taken from + * enum drm_panthor_perf_clock. The cycle counts are stored in the sample header. + */ + __u8 clock; + + /** @pad: MBZ. */ + __u8 pad[4]; + + /** @enable_mask: Bitmask of counters requested during the session setup. */ + __u64 enable_mask[2]; +}; + +/** + * enum drm_panthor_perf_sample_flags - Sample-wide events that occurred over the sampling + * period. + */ +enum drm_panthor_perf_sample_flags { + /** + * @DRM_PANTHOR_PERF_SAMPLE_OVERFLOW: This sample contains overflows due to the duration + * of the sampling period. + */ + DRM_PANTHOR_PERF_SAMPLE_OVERFLOW = 1 << 0, + + /** + * @DRM_PANTHOR_PERF_SAMPLE_ERROR: This sample encountered an error condition during + * the sample duration. + */ + DRM_PANTHOR_PERF_SAMPLE_ERROR = 1 << 1, +}; + +/** + * struct drm_panthor_perf_sample_header - Header present before every sample. + */ +struct drm_panthor_perf_sample_header { + /** + * @timestamp_start_ns: Earliest timestamp that values in this sample represent, in + * nanoseconds. Derived from CLOCK_MONOTONIC_RAW. + */ + __u64 timestamp_start_ns; + + /** + * @timestamp_end_ns: Latest timestamp that values in this sample represent, in + * nanoseconds. Derived from CLOCK_MONOTONIC_RAW. + */ + __u64 timestamp_end_ns; + + /** @block_set: Set of performance counter blocks. */ + __u8 block_set; + + /** @pad: MBZ. */ + __u8 pad[3]; + + /** @flags: Current sample flags, combination of drm_panthor_perf_sample_flags. */ + __u32 flags; + + /** + * @user_data: User data provided as part of the command that triggered this sample. + * + * - Automatic samples (periodic ones or those around non-counting periods or power state + * transitions) will be tagged with the user_data provided as part of the + * DRM_PANTHOR_PERF_COMMAND_START call. + * - Manual samples will be tagged with the user_data provided with the + * DRM_PANTHOR_PERF_COMMAND_SAMPLE call. + * - A session's final automatic sample will be tagged with the user_data provided with the + * DRM_PANTHOR_PERF_COMMAND_STOP call. + */ + __u64 user_data; + + /** + * @toplevel_clock_cycles: The number of cycles elapsed between + * drm_panthor_perf_sample_header::timestamp_start_ns and + * drm_panthor_perf_sample_header::timestamp_end_ns on the top-level clock if the + * corresponding bit is set in drm_panthor_perf_info::supported_clocks. + */ + __u64 toplevel_clock_cycles; + + /** + * @coregroup_clock_cycles: The number of cycles elapsed between + * drm_panthor_perf_sample_header::timestamp_start_ns and + * drm_panthor_perf_sample_header::timestamp_end_ns on the coregroup clock if the + * corresponding bit is set in drm_panthor_perf_info::supported_clocks. + */ + __u64 coregroup_clock_cycles; + + /** + * @shader_clock_cycles: The number of cycles elapsed between + * drm_panthor_perf_sample_header::timestamp_start_ns and + * drm_panthor_perf_sample_header::timestamp_end_ns on the shader core clock if the + * corresponding bit is set in drm_panthor_perf_info::supported_clocks. + */ + __u64 shader_clock_cycles; +}; + +/** + * enum drm_panthor_perf_command - Command type passed to the DRM_PANTHOR_PERF_CONTROL + * IOCTL. + */ +enum drm_panthor_perf_command { + /** @DRM_PANTHOR_PERF_COMMAND_SETUP: Create a new performance counter sampling context. */ + DRM_PANTHOR_PERF_COMMAND_SETUP, + + /** @DRM_PANTHOR_PERF_COMMAND_TEARDOWN: Teardown a performance counter sampling context. */ + DRM_PANTHOR_PERF_COMMAND_TEARDOWN, + + /** @DRM_PANTHOR_PERF_COMMAND_START: Start a sampling session on the indicated context. */ + DRM_PANTHOR_PERF_COMMAND_START, + + /** @DRM_PANTHOR_PERF_COMMAND_STOP: Stop the sampling session on the indicated context. */ + DRM_PANTHOR_PERF_COMMAND_STOP, + + /** + * @DRM_PANTHOR_PERF_COMMAND_SAMPLE: Request a manual sample on the indicated context. + * + * When the sampling session is configured with a non-zero sampling frequency, any + * DRM_PANTHOR_PERF_CONTROL calls with this command will be ignored and return an + * -EINVAL. + */ + DRM_PANTHOR_PERF_COMMAND_SAMPLE, +}; + +/** + * struct drm_panthor_perf_control - Arguments passed to DRM_PANTHOR_IOCTL_PERF_CONTROL. + */ +struct drm_panthor_perf_control { + /** @cmd: Command from enum drm_panthor_perf_command. */ + __u32 cmd; + + /** + * @handle: session handle. + * + * Returned by the DRM_PANTHOR_PERF_COMMAND_SETUP call. + * It must be used in subsequent commands for the same context. + */ + __u32 handle; + + /** + * @size: size of the command structure. + * + * If the pointer is NULL, the size is updated by the driver to provide the size of the + * output structure. If the pointer is not NULL, the driver will only copy min(size, + * struct_size) to the pointer and update the size accordingly. + */ + __u64 size; + + /** @pointer: user pointer to a command type struct. */ + __u64 pointer; +}; + + +/** + * struct drm_panthor_perf_cmd_setup - Arguments passed to DRM_PANTHOR_IOCTL_PERF_CONTROL + * when the DRM_PANTHOR_PERF_COMMAND_SETUP command is specified. + */ +struct drm_panthor_perf_cmd_setup { + /** + * @block_set: Set of performance counter blocks. + * + * This is a global configuration and only one set can be active at a time. If + * another client has already requested a counter set, any further requests + * for a different counter set will fail and return an -EBUSY. + * + * If the requested set does not exist, the request will fail and return an -EINVAL. + */ + __u8 block_set; + + /** @pad: MBZ. */ + __u8 pad[7]; + + /** @fd: eventfd for signalling the availability of a new sample. */ + __u32 fd; + + /** @ringbuf_handle: Handle to the BO to write perf counter sample to. */ + __u32 ringbuf_handle; + + /** + * @control_handle: Handle to the BO containing a contiguous 16 byte range, used for the + * insert and extract indices for the ringbuffer. + */ + __u32 control_handle; + + /** + * @sample_slots: The number of slots available in the userspace-provided BO. Must be + * a power of 2. + * + * If sample_slots * sample_size does not match the BO size, the setup request will fail. + */ + __u32 sample_slots; + + /** + * @control_offset: Offset into the control BO where the insert and extract indices are + * located. + */ + __u64 control_offset; + + /** + * @sample_freq_ns: Period between automatic counter sample collection in nanoseconds. Zero + * disables automatic collection and all collection must be done through explicit calls + * to DRM_PANTHOR_PERF_CONTROL.SAMPLE. Non-zero values will disable manual counter sampling + * via the DRM_PANTHOR_PERF_COMMAND_SAMPLE command. + * + * This disables software-triggered periodic sampling, but hardware will still trigger + * automatic samples on certain events, including shader core power transitions, and + * entries to and exits from non-counting periods. The final stop command will also + * trigger a sample to ensure no data is lost. + */ + __u64 sample_freq_ns; + + /** + * @fw_enable_mask: Bitmask of counters to request from the FW counter block. Any bits + * past the first drm_panthor_perf_info.counters_per_block bits will be ignored. + */ + __u64 fw_enable_mask[2]; + + /** + * @csg_enable_mask: Bitmask of counters to request from the CSG counter blocks. Any bits + * past the first drm_panthor_perf_info.counters_per_block bits will be ignored. + */ + __u64 csg_enable_mask[2]; + + /** + * @cshw_enable_mask: Bitmask of counters to request from the CSHW counter block. Any bits + * past the first drm_panthor_perf_info.counters_per_block bits will be ignored. + */ + __u64 cshw_enable_mask[2]; + + /** + * @tiler_enable_mask: Bitmask of counters to request from the tiler counter block. Any + * bits past the first drm_panthor_perf_info.counters_per_block bits will be ignored. + */ + __u64 tiler_enable_mask[2]; + + /** + * @memsys_enable_mask: Bitmask of counters to request from the memsys counter blocks. Any + * bits past the first drm_panthor_perf_info.counters_per_block bits will be ignored. + */ + __u64 memsys_enable_mask[2]; + + /** + * @shader_enable_mask: Bitmask of counters to request from the shader core counter blocks. + * Any bits past the first drm_panthor_perf_info.counters_per_block bits will be ignored. + */ + __u64 shader_enable_mask[2]; +}; + +/** + * struct drm_panthor_perf_cmd_start - Arguments passed to DRM_PANTHOR_IOCTL_PERF_CONTROL + * when the DRM_PANTHOR_PERF_COMMAND_START command is specified. + */ +struct drm_panthor_perf_cmd_start { + /** + * @user_data: User provided data that will be attached to automatic samples collected + * until the next DRM_PANTHOR_PERF_COMMAND_STOP. + */ + __u64 user_data; +}; + +/** + * struct drm_panthor_perf_cmd_stop - Arguments passed to DRM_PANTHOR_IOCTL_PERF_CONTROL + * when the DRM_PANTHOR_PERF_COMMAND_STOP command is specified. + */ +struct drm_panthor_perf_cmd_stop { + /** + * @user_data: User provided data that will be attached to the automatic sample collected + * at the end of this sampling session. + */ + __u64 user_data; +}; + +/** + * struct drm_panthor_perf_cmd_sample - Arguments passed to DRM_PANTHOR_IOCTL_PERF_CONTROL + * when the DRM_PANTHOR_PERF_COMMAND_SAMPLE command is specified. + */ +struct drm_panthor_perf_cmd_sample { + /** @user_data: User provided data that will be attached to the sample.*/ + __u64 user_data; +}; + #if defined(__cplusplus) } #endif From patchwork Wed Dec 11 16:50:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903941 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 85F2BE77183 for ; Wed, 11 Dec 2024 16:51:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EE01410EBB6; Wed, 11 Dec 2024 16:51:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="Eg2C9PJC"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Eg2C9PJC"; dkim-atps=neutral Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2052.outbound.protection.outlook.com [40.107.20.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id D2A7C10EBB1 for ; Wed, 11 Dec 2024 16:51:11 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=q+noVUvFQWt1gqnfXklI7UNbVaxbQ6ye/zZRjHEhDkwSbLepo3QvLeMlJuy132vOed/yg6z1Dai4KX5e9mtWBWasMOiH2ZieMaVFUEQA2VKNCSb55CsF2A0JTnSGUzcUinN/LJUTKR0E++ZBAJ3vQcIZT8VI2R+K0t3s9biocOCkSYPhuFwNnNzUPrHXShYgl9ElWhfLBCmfbZogOCqoDkAB34mx/8OiwwccRgrMx8fent2jgzVKsUI6Pgaxca0fXfaB8G3TeiHHrSAmrJBNUTsN6F43Zfh+4t9T4SRH1ovkuA7y7yfUJb0zj2DIyIcFWc8JXPoM+3607Dcz+QYL5g== ARC-Message-Signature: i=2; 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=PnRRPi1qgykoryDTpNMWdOoeaBEICiR/2/DWUN0P42I=; b=rJjSxFo7Q0RCKrgqm9mn/LeOro1BJxQp0nfo0/0NI3rJNBh/NfeKd/RW/LXTb3f26nad9AwfmfowhtmrzBkslNz6IDLy0+MzRQVQjjJPrByPllw0wfh7/w+iRFoRcBCxbJTcUyno+U1WUY0ghUeQP4fE6lNdtXc+vnz7Uoq55OyLILI+KkCmZgvfHMy7l6P6JONeCjoPJKkhApvJ06/PvyZpfI3eW6bfqeworzAZJcGITKlmJJvJvRu8zTIWNQrOfN8XjPL7E9eZlgF/sutGinl4Fe18pyUXysQnZOcWwHRegWiHTMJH80l5SAMwRfRuth1zeYqlOCawE92PcXKTAg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PnRRPi1qgykoryDTpNMWdOoeaBEICiR/2/DWUN0P42I=; b=Eg2C9PJC0Ctt8dr5Q85JZvFyITLvFihjQRZx85nQb0dRJJiOQNkWwRVehQxB5InvXILatnmiLS0ca6IyKca9xKYctypJtBP6iIK6Pz5tmT/ZSDolrwjnaCk9v4/s9T3nsWr3PkDO0Mgt15YCeemPFVBH3rpE+DrgPh2camk1bsQ= Received: from AS9PR06CA0046.eurprd06.prod.outlook.com (2603:10a6:20b:463::29) by AM8PR08MB5699.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:51:05 +0000 Received: from AM3PEPF0000A78D.eurprd04.prod.outlook.com (2603:10a6:20b:463:cafe::35) by AS9PR06CA0046.outlook.office365.com (2603:10a6:20b:463::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM3PEPF0000A78D.mail.protection.outlook.com (10.167.16.116) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:04 +0000 Received: ("Tessian outbound b4c479532664:v524"); Wed, 11 Dec 2024 16:51:04 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 273b848151f7c5a6 X-TessianGatewayMetadata: zESo4hTlpDNPaXta/xOJhQiMWFWLFKIdZ1358u8XZBHJoi53weNnK/ZNKZx7p9x2HeYLU1lYq4M0FjXNh/q7smGZZQMvFsfZMDTxa7aU4yE2ZF+2WkU6jrWuDOIFH7k792OeEo5553vu7Df7ldVGZooXnb3UqZ3YtVttq8Yt1NI= X-CR-MTA-TID: 64aa7808 Received: from Le3bc87cfaf57.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D244D080-42E7-4966-9FE1-F7003380A67A.1; Wed, 11 Dec 2024 16:50:57 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id Le3bc87cfaf57.1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:50:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Hvpxv9WayDe3LCbh9ZDVua2Q8fFcUuq1OpmC0aXEqmvzZHNl8lleG0GKa9bfmdsKGu32UHwvrI8hzmql2tH+6TYrZrARZHJKkkJDRUKq97QhKvP8HNJYopfjm2Pz4tulerq6B/p+UynJKvGTzZl8p//yoNAL6X44bi9hu5y/mFe9OzwszbCUeWrv0z4poUcaBqLNOOVthq7Xgw5GPtj4wHqwOXCQxO6TqKK+acPZph7K/lqbMKH7Wr1UqcKRCq5LNwtMovRmRP3aKwmpdUNdR++mRBeli+LbPdTuF36RZy5tcc/XKCiWl04uABsu26hfAneUjXCLIZdyUtB2SQQIYg== 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=PnRRPi1qgykoryDTpNMWdOoeaBEICiR/2/DWUN0P42I=; b=pxZTuTZFGkoLs43eWIFRTwl1FsRrUsLAy5nCdCidvstSjjibR5znq5nYBNJ3oVjEyV9mIEnpMccYFYwzPX3SWLBpGT3BL6lgwfxM8x32zzZMC3UelqcTO40AjZSng0IKs22qwbi3DDfvcIL9C9rK0Sqqi+2vmqV0G/DP762LT/zq2wRTzrapbONUyvaTgPKiYjHkA8BtzrRqO3PekAeKqY9ymLS0cwTJa/wT85eE5wruNO9rXL7PYoM6X6UsqwcYaFtqvrSwLUmXV7HqVFCxGV+y1dOiYOe8WbtkgAmiJtB1pK7bLyzw7nEhxOT2jcizX16Gy7PiaK3y8ea/edsjJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PnRRPi1qgykoryDTpNMWdOoeaBEICiR/2/DWUN0P42I=; b=Eg2C9PJC0Ctt8dr5Q85JZvFyITLvFihjQRZx85nQb0dRJJiOQNkWwRVehQxB5InvXILatnmiLS0ca6IyKca9xKYctypJtBP6iIK6Pz5tmT/ZSDolrwjnaCk9v4/s9T3nsWr3PkDO0Mgt15YCeemPFVBH3rpE+DrgPh2camk1bsQ= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:50:54 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:50:54 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 2/8] drm/panthor: Add DEV_QUERY.PERF_INFO handling for Gx10 Date: Wed, 11 Dec 2024 16:50:18 +0000 Message-Id: <20241211165024.490748-3-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO6P123CA0042.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::13) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8422:EE_|AM3PEPF0000A78D:EE_|AM8PR08MB5699:EE_ X-MS-Office365-Filtering-Correlation-Id: 6593a7c2-9442-4ed3-5dbe-08dd1a0400ac X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: fa2EnVB0DefRBAh0xIHXMtgpQW4qJ+KZdIokFSkwKwqagoRNRgS0MHwocF/n33An7Auj7aIfiiPWuGovaZHDlUtm3QmFHToUKrewcWsPnjrq7+klTvGcZmCqS9xVykjzY9Fnn54I23DMcXwdu7jvplyqAFMTndDPk7wWxw8HxZv1e/4ye8kdt9xUdoH7UzFdPb2EwAIRysTAflAcJSfiXxPqApK72ciRAfdJ0ER0xv10APw0yEIvhz2rqdoVIWfdwBMl5Jm1zvd4vxEa7yZsXM0mDxWyl+BSAOj2mPdhj6Pj+A+do4tQyXkl0LC/o7dRwryAU2xGqgxvfBDRseOu1SwVluaDj6wRDKyeXbpiqWxO1+ZqIGKLaQwgxT7mJY6nGcumK8tJ6DTl3JcG7zyWu2jh5I5Dxq5kWIEThqYyMGWM4YYH5jJRM8Vf6jyYk5NZ9p1NhFTrd6lt/5uho5l4VgktMkguAmcSR7OJpaIyxNfqZ/EqaJ/A4MKt3ituHpQscL3G58er/YXi2IP4Sfi1OFiYlBvE1888UK9F14WB/G2gUSsuOV0OPVvOtSRTJ4BwDYXSJvKHdkVIr2OnnW6mnSDLn7LfRWYGIR/IULBKE3LcmwQn82hBQRaB0JO048+JcqodTyrW8lxcxnGkONlcISrO5EhiKt/2tmx8kLBA8BL808B0rekjP+tIl/LHzacx6U1Q8TqlUblhbzsNthI/4Arcv8q+7iALY4mNXLYlUfpbIcyUGOHlJro6J6vmGnqPeUEV2/U+dysnt9GET6e1kxmlq6/yt1ADBg/LKeguyIGD0X93DUsHBhuArI4/JLUOf6nmrubDoKcwBLDszqnjsowFz510GTLRG6EgvPjqiyVU65iT9ot/Xrq+Fylv2dia10U1VkwOtuFf+pd3Ybon4iMtlWPdaINqJsWPKB4RVJYJN3Rc4A6VvgU8QO/Vrj4NYctsZCR5KoVvoOuTo1WoUweqhd2j1Ln/tTT2spvmklovqLuEMmqVXr17ploYAx8zGhIvEl6/+pl9jr3IB6dNCj9p8LmVxHBj/Ms8yawlEb/Pzo9yneoNOJAanOQh4qRF5L8fuZkNe6DkW8aZ5aYqmXX/+uOlrfFKB9fvc8AbhG/hA26eM/YJb5t+WdmIcDUdARYygpcBzdl/2TRMr9EofkgrJJwRZCahovFSxCie30sbc7/26cYbpFBRrIed8XW1ugbM2r/qODbLdrq0t1sPlUOEkuAkKj5GKyfOgsBWAtmMiGiBuDwBKivQjuhWbJenNauzsiVMAOMITCO6z7bnKgCrEsMMAn5Y7yf+7De3YqmU71ZCnNEgIKhIPyudrNExJSirvSRSeW1vSfzJBqKQbw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM3PEPF0000A78D.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: f36cd835-dbd7-443e-4c92-08dd1a03fa8c X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|14060799003|376014|35042699022|82310400026; X-Microsoft-Antispam-Message-Info: i7N1knDyDIEyIBf9SEyQzNoBEDmMUOODmTG8Qc/qx2Z/p7ow8QYK9Ni67zw2lKNqd58xz449bCyv8m8+8I9IK5ux/V9vWkLlJ5dJxpTrjzvKzfW2YZaQaAL0hE8gNTVvP+pIKrmnXfFQKX/02TlAV0sns3JLK9jGrP2VXm4lv5gG1+oOhTQdLCFm90lVNnagDpuNxiC+1dV6Te7OfLNImGAHRsJNxO2mi4dUNWPVOMNXXcBYSjedBeFHT6WJNSxTfT1XqcPy5seV2QLdaXrPFtsz+9c2WJe4KGM71ZtjleK1TmP0/BesTEM8EtEStzsPSBmeYkSjI8JKcqhbXTrjzmNBUxAgGVam94wMEfCIPtIHfIKJMfFqZhdiipvDT53O8kpoDkeyU9ssmGKTsPo8h3pCgEK1abF9xxytiMxL1HKzCtua0BVz79kZdIkCUsg2CJ5u2xb5FDKQqbTnpOawrRpuNm092Z1xAHkMglClcM/HLp0yktM8daqLaSLJT3igFdfyMfDJ6iU4ix7yp2rdICE/JUi72auHbB35sDsErQanXdGMw5gPMx26iz3/W8zERrzoXW4ZK0y9S1ryCOpcwH34RAmGr+hJxCOFcfGXVGK+YkWfxz7BTk5I4JjFjjNh79mh7kOrTCqriVBjYxtYjkaP3DTlPzmDBlA/T0625BNUAjVAQE81I86b4iCpoigJKYwHVr+ckX5yDUF4r6U4sz0wzCJiNliFgbR47cG5697KTHSiIb+8q+TwzHQGjza1Cm/LnpmOvUpr2lLIdYnIzVa3bsibXd/pthkHsNWAAnvTsK1qKX2neqrqca7GABAiUzT/cgoC4RsQr0U1T2TLDuThZ4d5WOmFrJdcMwqBErQ5ztKo5EP4YBQTRZfcK6Oat68ffpJXnLb+qaacIDRl7s76NK3mEtU6oCS+YaWyA+KB7YWMYefRKiOrnDVSCadAxWvi0MxHDm4GmIC5beSK+0trIBmFlwi0gOuGSEbuaKjGNNyAHtHRz+3r4eKDLKIS+Q6jQOFyGg2gygiW89W4RjUieyc2iiMr4nrA/IYnlS7XpzTLGNvVMiSZVem43BMUFqUrxii946LRHmgSDT6+NeFODx+Mt3RrbZp+C6bW8HRpla48Hp7/3bGAviz8yatH813lSPGCCf0GnPuk7mKDAGr95Nr9oR1kwdniLGkATr0m4qXxwZkvZ13GWh8646kZs9PhFFbn8+8ascftXtQKCF6C7TBP2EzO/fXVZuN6ENegK5Cp99e5Ef/Ic+JEznF97SZ6jl2s0SjW2mfJB4v1IFdmSMlEtR0hAlMXPlVex7YKtqiN6eiJkfB76P07rGio8v0uyodC7RP83Hs0gLpk1WAVWs6cJdhAk78MhP2fKJyxqqbs5iO74gI5zDmEn6RJGAtna5s8QSOStG/IByPPGRPZrrzJc15YzGmyY+kAOyJsYTneGqhlaIcAzX6Y0Vyb7pyvR7WBj+DKgfvDh6Z1Kw== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(14060799003)(376014)(35042699022)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:04.8716 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6593a7c2-9442-4ed3-5dbe-08dd1a0400ac X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A78D.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5699 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This change adds the IOCTL to query data about the performance counter setup. Some of this data was available via previous DEV_QUERY calls, for instance for GPU info, but exposing it via PERF_INFO minimizes the overhead of creating a single session to just the one aggregate IOCTL. To better align the FW interfaces with the arch spec, the patch also renames perfcnt to prfcnt. Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/Makefile | 1 + drivers/gpu/drm/panthor/panthor_device.h | 3 ++ drivers/gpu/drm/panthor/panthor_drv.c | 11 +++++- drivers/gpu/drm/panthor/panthor_fw.c | 4 ++ drivers/gpu/drm/panthor/panthor_fw.h | 4 ++ drivers/gpu/drm/panthor/panthor_perf.c | 47 ++++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_perf.h | 12 ++++++ 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/panthor/panthor_perf.c create mode 100644 drivers/gpu/drm/panthor/panthor_perf.h diff --git a/drivers/gpu/drm/panthor/Makefile b/drivers/gpu/drm/panthor/Makefile index 15294719b09c..0df9947f3575 100644 --- a/drivers/gpu/drm/panthor/Makefile +++ b/drivers/gpu/drm/panthor/Makefile @@ -9,6 +9,7 @@ panthor-y := \ panthor_gpu.o \ panthor_heap.o \ panthor_mmu.o \ + panthor_perf.o \ panthor_sched.o obj-$(CONFIG_DRM_PANTHOR) += panthor.o diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h index 0e68f5a70d20..636542c1dcbd 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -119,6 +119,9 @@ struct panthor_device { /** @csif_info: Command stream interface information. */ struct drm_panthor_csif_info csif_info; + /** @perf_info: Performance counter interface information. */ + struct drm_panthor_perf_info perf_info; + /** @gpu: GPU management data. */ struct panthor_gpu *gpu; diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c index ad46a40ed9e1..e0ac3107c69e 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -175,7 +175,9 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride, PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \ PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \ PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \ - PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs)) + PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info, shader_blocks)) + /** * PANTHOR_UOBJ_SET() - Copy a kernel object to a user object. @@ -834,6 +836,10 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d args->size = sizeof(priorities_info); return 0; + case DRM_PANTHOR_DEV_QUERY_PERF_INFO: + args->size = sizeof(ptdev->perf_info); + return 0; + default: return -EINVAL; } @@ -858,6 +864,9 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d panthor_query_group_priorities_info(file, &priorities_info); return PANTHOR_UOBJ_SET(args->pointer, args->size, priorities_info); + case DRM_PANTHOR_DEV_QUERY_PERF_INFO: + return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->perf_info); + default: return -EINVAL; } diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c index 4a2e36504fea..e9530d1d9781 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.c +++ b/drivers/gpu/drm/panthor/panthor_fw.c @@ -21,6 +21,7 @@ #include "panthor_gem.h" #include "panthor_gpu.h" #include "panthor_mmu.h" +#include "panthor_perf.h" #include "panthor_regs.h" #include "panthor_sched.h" @@ -1417,6 +1418,9 @@ int panthor_fw_init(struct panthor_device *ptdev) goto err_unplug_fw; panthor_fw_init_global_iface(ptdev); + + panthor_perf_info_init(ptdev); + return 0; err_unplug_fw: diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h index 22448abde992..db10358e24bb 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.h +++ b/drivers/gpu/drm/panthor/panthor_fw.h @@ -5,6 +5,7 @@ #define __PANTHOR_MCU_H__ #include +#include struct panthor_device; struct panthor_kernel_bo; @@ -197,8 +198,11 @@ struct panthor_fw_global_control_iface { u32 output_va; u32 group_num; u32 group_stride; +#define GLB_PERFCNT_FW_SIZE(x) ((((x) >> 16) << 8)) u32 perfcnt_size; u32 instr_features; +#define PERFCNT_FEATURES_MD_SIZE(x) ((x) & GENMASK(3, 0)) + u32 perfcnt_features; }; struct panthor_fw_global_input_iface { diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c new file mode 100644 index 000000000000..0e3d769c1805 --- /dev/null +++ b/drivers/gpu/drm/panthor/panthor_perf.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 or MIT +/* Copyright 2023 Collabora Ltd */ +/* Copyright 2024 Arm ltd. */ + +#include +#include +#include +#include + +#include "panthor_device.h" +#include "panthor_fw.h" +#include "panthor_gpu.h" +#include "panthor_perf.h" +#include "panthor_regs.h" + +/** + * PANTHOR_PERF_COUNTERS_PER_BLOCK - On CSF architectures pre-11.x, the number of counters + * per block was hardcoded to be 64. Arch 11.0 onwards supports the PRFCNT_FEATURES GPU register, + * which indicates the same information. + */ +#define PANTHOR_PERF_COUNTERS_PER_BLOCK (64) + +void panthor_perf_info_init(struct panthor_device *ptdev) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev); + struct drm_panthor_perf_info *const perf_info = &ptdev->perf_info; + + if (PERFCNT_FEATURES_MD_SIZE(glb_iface->control->perfcnt_features)) + perf_info->flags |= DRM_PANTHOR_PERF_BLOCK_STATES_SUPPORT; + + if (GPU_ARCH_MAJOR(ptdev->gpu_info.gpu_id) < 11) + perf_info->counters_per_block = PANTHOR_PERF_COUNTERS_PER_BLOCK; + + perf_info->sample_header_size = sizeof(struct drm_panthor_perf_sample_header); + perf_info->block_header_size = sizeof(struct drm_panthor_perf_block_header); + + if (GLB_PERFCNT_FW_SIZE(glb_iface->control->perfcnt_size)) { + perf_info->fw_blocks = 1; + perf_info->csg_blocks = glb_iface->control->group_num; + } + + perf_info->cshw_blocks = 1; + perf_info->tiler_blocks = 1; + perf_info->memsys_blocks = hweight64(ptdev->gpu_info.l2_present); + perf_info->shader_blocks = hweight64(ptdev->gpu_info.shader_present); +} + diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h new file mode 100644 index 000000000000..cff537a370c9 --- /dev/null +++ b/drivers/gpu/drm/panthor/panthor_perf.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 or MIT */ +/* Copyright 2024 Collabora Ltd */ +/* Copyright 2024 Arm ltd. */ + +#ifndef __PANTHOR_PERF_H__ +#define __PANTHOR_PERF_H__ + +struct panthor_device; + +void panthor_perf_info_init(struct panthor_device *ptdev); + +#endif /* __PANTHOR_PERF_H__ */ From patchwork Wed Dec 11 16:50:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903942 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 22649E77182 for ; Wed, 11 Dec 2024 16:51:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9965C10EBB4; Wed, 11 Dec 2024 16:51:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="Qj4CMfTS"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Qj4CMfTS"; dkim-atps=neutral Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2070.outbound.protection.outlook.com [40.107.22.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id CDDE210EBB7 for ; Wed, 11 Dec 2024 16:51:16 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=gpBcc6dhdCiTxssKW7q441TqgabkzCULzBLGQf6iiwxtNOL8U1qv/XjLVo9AYMCtNiWkNHMZUWSWD3DTG9OeE+4JBo9aep/FXKyxF7NVJzICyF4DFINaHOgOY2Zl8nloMlkpVgxYWTENBB7yxMZjAEF7EMlJOzL18VPZvJuMhfPAXq2vSTQ2zjErlkxnf2wwW+ppQ7zNCkGqzyXVgNkBEvaFRNKa3CMBcFEHswtOEmR4qATJzsRlM6WWdQnCDnMPrf7EqD1wMGe9T7wBdjLcgdIiZ2oR7Yp4n3aTGC/Y+kKHsrfsvYYphzIbXzjbF18nZ4z009mTlUaaBGt2IhQZUA== ARC-Message-Signature: i=2; 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=HPFjvHzurYcGRDPl+eZz5UpIXNhjbNaySmNYBE0/D/4=; b=RMhNqR4G5L+fzI5KKwBSKxiCCM6y4kCgkQFOks4MUxQj8lLK3N7339RIpVnsIwBufiVa0YRrHZeuIvh5yi/zY4qsRGzu2C5r/8T2ygNQqB9ZdK9kfi8p1BZlvdrWL2GRXQeKhPL1tuj5q502zdkHftx8tgNtoN6M1E6YmnIlXD1GK7OO9/8QhtRbQt7juA5ENEnQYEsAdAJobBbJZ6aE6FIpt6LKX0jUbfk0I5FGy2NKERB8YDV2iIgCrXg1fizf1RYIMWjE8hUinMBmQxYbbsQV6FZCJhZv4kfR7usbbz7AeZX9uGgEVsedKSmKUnxbxeWtHH8THD/27Ap/Yd5gkA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HPFjvHzurYcGRDPl+eZz5UpIXNhjbNaySmNYBE0/D/4=; b=Qj4CMfTS+CWqpeVVkek4FwE7VYzXG1cNs8RSPHrQptRmLRDZrK0bAsMUGX5a7yAyeu3EZtaJWo87WrRx9kxb+rRR2egk07UKPyNFZSvIl0ud6D8aW7b07didUuInF3mYiZjq+zn52hiiMM4RpDMSQd8qKhCOh0RTN49Ivhkr+FU= Received: from PR0P264CA0108.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:19::24) by DU0PR08MB9026.eurprd08.prod.outlook.com (2603:10a6:10:47a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Wed, 11 Dec 2024 16:51:06 +0000 Received: from AM3PEPF00009B9D.eurprd04.prod.outlook.com (2603:10a6:100:19:cafe::86) by PR0P264CA0108.outlook.office365.com (2603:10a6:100:19::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM3PEPF00009B9D.mail.protection.outlook.com (10.167.16.22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:05 +0000 Received: ("Tessian outbound 20d64b55c711:v524"); Wed, 11 Dec 2024 16:51:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d5046944b1377f70 X-TessianGatewayMetadata: lKDehNbMszKsgNrnshmMjwjqk/rb/dPNqPQwW1p/B414W0QqvtU8IAgqrZZ1mpQdjicC3M/53+/KRHu5if/qhnQkLZnBQNfa21aDzJom7vOU97jTHsXunXR+2kvI9Y2tmXNGp/k4feLqjsiKNg2+riZvRRW2i1wU16sGO7h0jKk= X-CR-MTA-TID: 64aa7808 Received: from L0461535056b5.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0E5C8FBF-BB58-4C81-8256-20ADBF4A650D.1; Wed, 11 Dec 2024 16:50:58 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id L0461535056b5.1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:50:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jrP90VwBL4RMsJH2Tcsvxxv/PJdGMkVHiNSdcpOJFkOiBXoeCQvJhAfUYfPBpkFa6ueQFHI7OFcBIGeq/BYXE1xhkyGINMZ5hZxbgdUCuG/YaRu2Lrv8uwWowkz/QJZfouxA0tK0P8YTUtcDwjkBa98X5yQkwvtM62TT4FsSQwV5wxfQiTWsWyf72gCQGOFkN6gBIb6vf7geyyu0QePBUUo8WQwWyWUG7NVQPu6J2cms1Om/X8aH57AektMtIZwrYMSjVF3gk8PTCRqO87/LgcfgJVFS50vdDc7LB/fglB+DVGWPAmOdOUdylJdqtsFo7BetCj+tY+JZnSATzfqW+Q== 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=HPFjvHzurYcGRDPl+eZz5UpIXNhjbNaySmNYBE0/D/4=; b=guCIir2yg1Hp/FB6Sr7V2OE8fM9RHrQtz9L+Lo4ZlLHjHojWVLgkldWKLdKW6v/cYBdx51rDDk4mKEz0d/TBrKTpOiNasED/bo17LpOtbaqqJY7oRBSc/BmxvRif+QORFB+e7Sekf8e3CY/rYauCnIe5UYJ66j/W2udVZ5RH87GPC+nOw+7RY/Rxja+mC/skzcsvNAMJY+4bOURSQKdzMxlVcXKnZvoTvVRy6szbbt74Td6he/v6hP4FaC0iuFtQjBOP85cW5pFdcFBANFaD0x1n8r0e3Y6YT12dHFJn5jhDsvPc7cCV28rffztYKNyf0ac1CnXfLeClaS5yj541cQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HPFjvHzurYcGRDPl+eZz5UpIXNhjbNaySmNYBE0/D/4=; b=Qj4CMfTS+CWqpeVVkek4FwE7VYzXG1cNs8RSPHrQptRmLRDZrK0bAsMUGX5a7yAyeu3EZtaJWo87WrRx9kxb+rRR2egk07UKPyNFZSvIl0ud6D8aW7b07didUuInF3mYiZjq+zn52hiiMM4RpDMSQd8qKhCOh0RTN49Ivhkr+FU= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:50:56 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:50:56 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 3/8] drm/panthor: Add panthor_perf_init and panthor_perf_unplug Date: Wed, 11 Dec 2024 16:50:19 +0000 Message-Id: <20241211165024.490748-4-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO2P265CA0069.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::33) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8422:EE_|AM3PEPF00009B9D:EE_|DU0PR08MB9026:EE_ X-MS-Office365-Filtering-Correlation-Id: 5283ba3d-ea06-437a-f3d1-08dd1a040143 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: CZi/BeiXLDmTi6vumbQKSLWbyaJx6rpwHCSNpe9UMVZceNZryzuDTHKGTRqmTmwTI5mVS8LoFjWCZ9u7lM9VUHNTxueWUZPzuQLQEoPftKOUXgrFVgdaMlU4I8QfTujHQrdioXKvFbc/IPq1XlfBy4yVheOg94T/IV4FR03L3pJ7nQCoRPbLdkIVNci92mUKqbewQwaEYEQdt3/CHrmOqX7UhmRa4sBWAnfBJ4byWnlIFm04E9sH9i0xbHxESFr6KnVx6/Lt3Kmy2Q11oMGv8UCYU3H661dIc2aKnWfj4hydCPVADyMkMrZQRUPGXIkqWE3AGFO7igWmEbhU7UrJ1SAffbCg+9giToPr1iulnKighefjvhTFcYK4U6I3nPWmVeI3E8I7c6wMG207Bj2IJJ4kvk1F6xGc4RdGkiezcUZRwCGnGISUXCJE+HvGkjEqmJ0SsP1QMve905pQHEz67I0ODZib1rSFff5OW56iwQzQ/ALn98EGChiu90/jtLKkg2Mib5vC5ztEt980c3u/YS0yQwdNxqOvvCHWdDxhK3XdL6gg/qBbjZNTDkIDnBBZgRAKmDF7F3cknltPb423aN4/eYurTM0gxRUQhfBp1Z97kUDp5NnVok7H1gm7txpl4R9hIAEz0sWY89qSg3cKDEegeVywcGpap50VveQpz3mF11dLcPtPEXVFNxBpZW49Dnf3feONQYspA3KHqwEB/xxUkkrwjy9ABrt8Fa8rCzbnkZ+PseXEI89uhEjM91Yw+6wgeV3mvwYNbkRcRJxTOAfuLTG4ZOc4xbsZlbDxST5IIw6376vM7mluAiHRgXTS6FNlI2QRvkkaVka0WZf4lKf7PKtzPJKbYD8bpchG83rh2saLEkMoO33mwuqyhn56u4wgHw9o9si8hfVR5uabP5SuOUztaDjbE4BVQw4JvdSENbBCoR1MeYAeMofPf39sd3cb9n+pkhpYMie4hXEUeiXBY3k7o43zMcpYZgqmXume/kiGrAnxE8xkCkFBdY3FjFGTY5qaiESG2XrEukaQuEyactUQU/qaPWKQQRtgUqQiGO7cgEkbhLQ7qVaX0rwHGqDQS/Mdv8wfbEMKNSVxuzUDWvaPNAvpfqRXXba4X67im5lmCVzF2tXT3PHNFt7wVGC6HeE6clHl/bXVrlcRmtOVIuup0HIrZIFbLCObvpDWjayP+w9GMUlJ65ourf7KYynnrUUXD1y+8MvF0zFQcV9M/cPHCNCGHtxsQHm+0syZxUmpVP0fOzANFkcIS59IUZ+yMRgXxKicqF7Tk/OwzoYwNasfM1MwrFQkgoDbAjE8BmXMSTa2LA476+7IRcbaNKDmkWspSLn5FYwtgsYkQg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM3PEPF00009B9D.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c1d530cb-7b09-4c56-ca7e-08dd1a03fb80 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|35042699022|82310400026|1800799024|14060799003|36860700013; X-Microsoft-Antispam-Message-Info: EFK0oxYLhbB54LIK9ypNuyi3FMY/33Zq9pCIFewyLIkOwXvFOJSWbNR0CffzY5dQChylrF5K5djyouS51fkqslxuhID5jg6rKZ+mgEYdjcDCRbLgFSO/hZzC9lzsViTJJ93t4oR/WXKp2aglJ8rTFbRvBGMQuVKFrgmV7taxmFTq5dNJKWXsiWCqMgLy/s6Kg0WQhFhpXmbnFRP+VuvZqyu1yvZ7EHwGno1D4+6EbC1KHV4DHR2lwgn8qG9ABQMk7a98JgKYt4S+3foIYvUp5H41kJy/ZJ+0JoOEbhsuSRN4fna/aUPsutE5kELnbs44wmsAwgCA9Jq7d7EG7ucuMKA85jZ5EsjMRMRxZxjoyQG+bGjN+kzlsrVNT5DuBZjf+5hD2dgevgOhjYjADK04AOm2L7yDRKwniJCKLQmZrnxTcOQM8+fZYTfBQ2Ov/9qCKV8CyVkeX/ByfgL+7sxwngNCWeBuQ7OlNoi2bwPubhKRsi9kr6k+pCw3XTz8RV3VUX5arwrKT4lGgzdEMSn8WrhJGGb8q5I3SZMM+amEB7Cm2w7BHOHzbYJZ2xaBRWp8hHY7kG0Pk0Fgu/KDtPZFSfLaW1iFLW1VaX9/INTLAsxXxPKhRUThe72mY5lG6KqwdnvG7cofNsqzIP5sGDMl3JRz03qp1kQY11hmr+dcKH4G33+71zw6Zs02qEmZUut9hDw6TvdhRcJgCFr+8ldMMa00UEJ5scZjJlUnK+Axk0epI0xPxoBJN6IFPVsk6UAk57JjXpFAPs7nt2krATFiYsIVNOx4taF5uSW8lAIsDxxcpZ4MFBZN95GXzjx8aNeqwPgmMa54EPQqFF+KMSFo8W6X/se9ZBQ8mvfyYoxX1tU06ABfap0Ty0tLan4igrIfitbv0F8BgG6bkMLPiEYENiYrY4M81CN8wkeKnV2gA90ZZnZx2esWaxpNek2W9bSSHYmFW1eR57Ja9jEb/NlPNjFTt4Hx7qjBbbJcZoU4sBWaxQ8hO5JWJ9su8RW3x5SQM6Q9YdQa2deRWlIvgzuUKdITNLY+yXxlsFNrSYzN542d3QTk4ZJDx1hs95NfGNqrL1vaFDv3nzWDK1Gre/1aoYVGfI4crRAEmjbkHqppMiKPTkRwmCsdbaJxchFsLVeXZBrhLUjC1NR7/W7oyYe2qv/UhJWb6LOX7kbhkdhv8/1UKrr5upl02u2lezbYzDQ4n9A2DZIYcBI/hVZECPNsTKDQGJ87odFqeH98gGuIkrWKYuOYVAfpITM6D8Qzc42L583bFIdrqOSJ7agR8Gk9+3sQiud12l1jP/dVwZJXkv1jhpZgwbIicg/GUxBq09pU4AgaWiRtpJ4/SREVwN9tHeP8Ekk0O03KMwWGysaOo8ron/+DCf2zBzcBP9XuLMJVFq+DYSuTENOir+rwmTMpAXE/DD+a51aDe2IdZCXEX4tgSIL2y/WtbpzT9dMeqN9l4nlMPeNGzt0PV731jOXUdw== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(376014)(35042699022)(82310400026)(1800799024)(14060799003)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:05.9275 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5283ba3d-ea06-437a-f3d1-08dd1a040143 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF00009B9D.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9026 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Added the panthor_perf system initialization and unplug code to allow for the handling of userspace sessions to be added in follow-up patches. Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/panthor_device.c | 7 +++ drivers/gpu/drm/panthor/panthor_device.h | 5 +- drivers/gpu/drm/panthor/panthor_perf.c | 77 ++++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_perf.h | 3 + 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c index 00f7b8ce935a..1a81a436143b 100644 --- a/drivers/gpu/drm/panthor/panthor_device.c +++ b/drivers/gpu/drm/panthor/panthor_device.c @@ -19,6 +19,7 @@ #include "panthor_fw.h" #include "panthor_gpu.h" #include "panthor_mmu.h" +#include "panthor_perf.h" #include "panthor_regs.h" #include "panthor_sched.h" @@ -97,6 +98,7 @@ void panthor_device_unplug(struct panthor_device *ptdev) /* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed. */ + panthor_perf_unplug(ptdev); panthor_sched_unplug(ptdev); panthor_fw_unplug(ptdev); panthor_mmu_unplug(ptdev); @@ -262,6 +264,10 @@ int panthor_device_init(struct panthor_device *ptdev) if (ret) goto err_unplug_fw; + ret = panthor_perf_init(ptdev); + if (ret) + goto err_unplug_fw; + /* ~3 frames */ pm_runtime_set_autosuspend_delay(ptdev->base.dev, 50); pm_runtime_use_autosuspend(ptdev->base.dev); @@ -275,6 +281,7 @@ int panthor_device_init(struct panthor_device *ptdev) err_disable_autosuspend: pm_runtime_dont_use_autosuspend(ptdev->base.dev); + panthor_perf_unplug(ptdev); panthor_sched_unplug(ptdev); err_unplug_fw: diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h index 636542c1dcbd..aca33d03036c 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -26,7 +26,7 @@ struct panthor_heap_pool; struct panthor_job; struct panthor_mmu; struct panthor_fw; -struct panthor_perfcnt; +struct panthor_perf; struct panthor_vm; struct panthor_vm_pool; @@ -137,6 +137,9 @@ struct panthor_device { /** @devfreq: Device frequency scaling management data. */ struct panthor_devfreq *devfreq; + /** @perf: Performance counter management data. */ + struct panthor_perf *perf; + /** @unplug: Device unplug related fields. */ struct { /** @lock: Lock used to serialize unplug operations. */ diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c index 0e3d769c1805..e0dc6c4b0cf1 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.c +++ b/drivers/gpu/drm/panthor/panthor_perf.c @@ -13,6 +13,24 @@ #include "panthor_perf.h" #include "panthor_regs.h" +struct panthor_perf { + /** + * @block_set: The global counter set configured onto the HW. + */ + u8 block_set; + + /** @next_session: The ID of the next session. */ + u32 next_session; + + /** @session_range: The number of sessions supported at a time. */ + struct xa_limit session_range; + + /** + * @sessions: Global map of sessions, accessed by their ID. + */ + struct xarray sessions; +}; + /** * PANTHOR_PERF_COUNTERS_PER_BLOCK - On CSF architectures pre-11.x, the number of counters * per block was hardcoded to be 64. Arch 11.0 onwards supports the PRFCNT_FEATURES GPU register, @@ -45,3 +63,62 @@ void panthor_perf_info_init(struct panthor_device *ptdev) perf_info->shader_blocks = hweight64(ptdev->gpu_info.shader_present); } +/** + * panthor_perf_init - Initialize the performance counter subsystem. + * @ptdev: Panthor device + * + * The performance counters require the FW interface to be available to setup the + * sampling ringbuffers, so this must be called only after FW is initialized. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_init(struct panthor_device *ptdev) +{ + struct panthor_perf *perf; + + if (!ptdev) + return -EINVAL; + + perf = devm_kzalloc(ptdev->base.dev, sizeof(*perf), GFP_KERNEL); + if (ZERO_OR_NULL_PTR(perf)) + return -ENOMEM; + + xa_init_flags(&perf->sessions, XA_FLAGS_ALLOC); + + /* Currently, we only support a single session at a time. */ + perf->session_range = (struct xa_limit) { + .min = 0, + .max = 1, + }; + + drm_info(&ptdev->base, "Performance counter subsystem initialized"); + + ptdev->perf = perf; + + return 0; +} + +/** + * panthor_perf_unplug - Terminate the performance counter subsystem. + * @ptdev: Panthor device. + * + * This function will terminate the performance counter control structures and any remaining + * sessions, after waiting for any pending interrupts. + */ +void panthor_perf_unplug(struct panthor_device *ptdev) +{ + struct panthor_perf *perf = ptdev->perf; + + if (!perf) + return; + + if (!xa_empty(&perf->sessions)) + drm_err(&ptdev->base, + "Performance counter sessions active when unplugging the driver!"); + + xa_destroy(&perf->sessions); + + devm_kfree(ptdev->base.dev, ptdev->perf); + + ptdev->perf = NULL; +} diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h index cff537a370c9..90af8b18358c 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.h +++ b/drivers/gpu/drm/panthor/panthor_perf.h @@ -9,4 +9,7 @@ struct panthor_device; void panthor_perf_info_init(struct panthor_device *ptdev); +int panthor_perf_init(struct panthor_device *ptdev); +void panthor_perf_unplug(struct panthor_device *ptdev); + #endif /* __PANTHOR_PERF_H__ */ From patchwork Wed Dec 11 16:50:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903945 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 E0042E7717D for ; Wed, 11 Dec 2024 16:51:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3714210EBBF; Wed, 11 Dec 2024 16:51:25 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="Qs4JS9hZ"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Qs4JS9hZ"; dkim-atps=neutral Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2088.outbound.protection.outlook.com [40.107.22.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0881010EBB9 for ; Wed, 11 Dec 2024 16:51:23 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=H4VU4LOD7TwyUxOeoZztia+ekKrGdGCnmBoRkz3U8mUdT7VczUV9nHClaFMNR7XsfST3OCUq0hOJH/DpumFbUsXtwsmq9J7Sd4VP0O9LJ5r0TTNs4RKwgaqmer1WTm3IOoQ0skT6sKQjO+4gTfoFM2IMq3QDHZmouEikArjVyN31l5y2uAkBNE9jG5nGzJ21sbvtwY/XyJ3UDA0t33g368Up4yxb2kYi6Kf8q9kCQ/CbbJUVfTIJO7coOfmt3gXL0hkQl+UcxCdoOEcI3gniJEcgmOEYcNYPkNa31yN4RJo7GIH6MHb2LY9p2ctRkgutTyKTb93lh10w1iQmJEmLVQ== ARC-Message-Signature: i=2; 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=0M0fqUueGrM75pIOTP2ln7I3QgIGIq/MIWBiNgamU48=; b=XxpUFTvglYvI6CfZazU8vfTY2N/tiv9VadoXgiyFwD4x3PCa5gFnf+D+HvBoXuPpoVTPzg/wGakXd4KMRFfN3IZeMcR5ri0pzMkJiaby+cqGRNfGhPRincI2peMp8unSAdCYkcg74jSuHCgekA9AEGrUbuSh2TP8JgQTgg6U8sdGWddz5DgvY5f1ASrpbt7Q9bLBrsBahWQiAtJHKcA0knTmqiT2GAI+mZEauX8WycE+nTuLE8HLmbKNITqczLcyBHhn/fLs3gTJGgKjl1TKds7tqEky2bYzX5QRV0IHsw+Xz1d5Y14Y7Amxvww76V1wfS4Zqyt/APlVTy1A1oMVeA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0M0fqUueGrM75pIOTP2ln7I3QgIGIq/MIWBiNgamU48=; b=Qs4JS9hZ8DViZdTg/dqt34zD/AeSsFgaAovdwYc8hRXf3rL49nrxECkkp3hUl59s67v2Unp7R80xYiTGP20yVudRhfZBVIITeP3in3HvotlAvBO03gf03QJ62heOurQPBVRvJilyj11toqN5Kf6yQnXh3d6VWrTrxOCvT2tSFr8= Received: from DB3PR08CA0036.eurprd08.prod.outlook.com (2603:10a6:8::49) by AM8PR08MB5747.eurprd08.prod.outlook.com (2603:10a6:20b:1c7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:51:13 +0000 Received: from DU2PEPF00028D10.eurprd03.prod.outlook.com (2603:10a6:8:0:cafe::1a) by DB3PR08CA0036.outlook.office365.com (2603:10a6:8::49) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.20 via Frontend Transport; Wed, 11 Dec 2024 16:51:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DU2PEPF00028D10.mail.protection.outlook.com (10.167.242.24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:12 +0000 Received: ("Tessian outbound 2d228e31de9a:v524"); Wed, 11 Dec 2024 16:51:12 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 54ad7c95618afe61 X-TessianGatewayMetadata: QF7v0RaNDlZKgrjFIC/FrPbHsYltlmLl4KfRn77Vab8V52jP2Mkjx2h4AvC5H+JsHqdKUrCOrcPgCM+tBQIGHpEhp68njmIk1hD8z/tpElKAcv5uOh8tJFhZcJLPlfuj4WEIj685QnIix5JYLmYGxy89YHv0uliol+oFX/6Q7tw= X-CR-MTA-TID: 64aa7808 Received: from Lbbb948cb6fe8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id AB1415DD-17FE-40B0-9681-68D3F8AF9154.1; Wed, 11 Dec 2024 16:51:00 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id Lbbb948cb6fe8.1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:51:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ogGGURi1gvbKuRz6fxhbmR7/Xk5sJnbmSk0uOwD9u5czeNGoLxelPPz3d16MgyUPiT67Z8saa3++1LBI+LVCEJKYR2rJWC9NGOLYVlV/2dhCXlyh7k75kwBjUMnuDmrjidfgxQ6kEJD6PS1sd6ugaPpF2lIotXi1GC/5cnY7RIkzAteN2hKUT4Qltb3+W4Vf7reLXJUK6H8wmzA9wMPYKcM41N7cCdENLKmrVGymEY+BUIq/uQoxMyDQ4gj9mHl6gT7tuvRlCjeZKdScTHZtIhrXoKsvy5pm1OFnx7OIwjkGGhZjGhAGvM8ffozRiq75lyqI96UDZtfNUZlvtkASvQ== 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=0M0fqUueGrM75pIOTP2ln7I3QgIGIq/MIWBiNgamU48=; b=KZYuRbAngRlGk8F4fhiV2wbuy0qVCYVX8cnMit0YGZtfaBoqt3uZchJj1GxU7gwWDFtfb2f5uyOeyEVWUCqtMeC6jZ0MdJZeS0Yh8DkXdsVoks8SgP9kcsXshg0KOexmnLzEsRCO3CQOtkLcMQdrs6OLGapHequVD0N0uzvzOnkSzTQxutJIHaXBEbjcoyoXSf0FF5zEiBGH+6jIt3R2NDNa3h6fR/70KgvWqYVoTDdqNEfF05vMyU4t4d8J1Pw9UABRUG70ltSMn6fGvXvXDCWqbdNj1o67ZWGUF7OZJyCsCj/2JyCWXuNux1PreCmecN0kigDL98N7yXPcj69paQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0M0fqUueGrM75pIOTP2ln7I3QgIGIq/MIWBiNgamU48=; b=Qs4JS9hZ8DViZdTg/dqt34zD/AeSsFgaAovdwYc8hRXf3rL49nrxECkkp3hUl59s67v2Unp7R80xYiTGP20yVudRhfZBVIITeP3in3HvotlAvBO03gf03QJ62heOurQPBVRvJilyj11toqN5Kf6yQnXh3d6VWrTrxOCvT2tSFr8= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:50:58 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:50:58 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 4/8] drm/panthor: Add panthor perf ioctls Date: Wed, 11 Dec 2024 16:50:20 +0000 Message-Id: <20241211165024.490748-5-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO2P265CA0190.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::34) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8422:EE_|DU2PEPF00028D10:EE_|AM8PR08MB5747:EE_ X-MS-Office365-Filtering-Correlation-Id: d5d26243-4120-413e-69c8-08dd1a040572 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: fGtZtgayl8WlmUuylfDKId/jfjaCETC/P8yIADu9IbcAj7Iwxu4rvXwJznKONbIstCxxaVveZDzOIvcHKpnv8FE6I2EF1ng8/E2wrHbLuNuSOktw9C0Sj4ztoclZehxWmd6qml23uV1gWSkZBUseJWQQoqBBQg4tvb/EvBJwFGpzj2dyZ9Sc01XXuCQydmobe+7WHoHadi0Dpz2ZVFPGwyncKCVnQWft4tG8up/qAD6kP6GSWtkn4i7kcdV+SBC3ZA4EbK0Q6MwNMednCnjCJZesp59J3NStZvdh5cGfEmAR3ixlFwUPh2+ucDKgQlcqcrG3qfWkBkDgdPco4nQIfUgskVUmJG/R3llx7qjmmAhOhJb4JhbY7FCrfSzKQ+0fkvWHWnZpSnWjHy8DRx8s+xIviq51hni0zM01T8xsVMC1hVrrsQlT79/sEzp/zR8HQ/331zVoV01j56SSHW/YCavRLzWNU96YsRyN3lRzgeTR+mMOAzVWjh1m599yQjZh8E9XgECpG0iZRDwWdg0hwuM4sDis40oZAa6Q1sZDjsDuT29IJkvMgdmYm12KFxmpGPGuuwoscCBrkn1slet6ePV2ANL9FroGEWc9+Jgf0YCCmZIkPT9CXPItiZwSvY41TCyRiMABnOCUGktKRN3AlWiImG8abMQKUEAeZmdhH/ttgeHtYVBv1e15E4GcLJBi4VaKXeUHzHQouyZq/VP5cqNDtB8ihYu06VlfXRqkz7huKKXxcx8IVoSHA30E7WhVRHaDD38KBWL804437bjwg2RvvUAEya4iVD5Y/eAhLCLuq3DVEZCrv92JaBsa4ZbZKjdLAH8Qjwk6O9TXdKKdbsCaEM4oLgZPXVkcjjru5MeMnxYh0y/Hf1wQnsnZ8CHr5JAwiOyQElzAsjnqmrHO2k/FlZfNcm1RsZdaw0LjVQ64UGPa52UayQ6AGdWRwR5ycpRyVyDhaT2p5nzZ8uo0ic/3P29X3Znmio8GBhcsZBvD826rbq477DIhLQ1RsYRkwpkvoxfzNCccTMw0olI7w7E8rjW0Ai+cwpLmydj40oxcFr/6fscVSqb165it/i3GBPlJPNictuax/N0prEPtCT0+Zm4rcqwQ6Qd2YzQ7nsJzxPDDZJ/6eOCdRgsK5xtzGjMqWJdz2peosS4UFYo373WqyEtmlX8RBcaNCdIL+GU5NXs3PNGMHc1kbrGLu+0lCSCPe1hi4XKdEnuCpZV6WsDA8ztqiq7JNY7MIILaRWoeGu8Ehd8pzcu0YyQFGkb2us2AUPMTFEg2wSvrwet5wnV0UL8o257kyxALGU7IxmqSPDgFkbkacuHumcTRYejGbZydEqNv4ll/lGht7lrZtw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU2PEPF00028D10.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0e9f8942-a122-4540-9f39-08dd1a03fc67 X-Microsoft-Antispam: BCL:0; ARA:13230040|14060799003|1800799024|376014|36860700013|82310400026|35042699022; X-Microsoft-Antispam-Message-Info: yUjJ49eGmPY6u4bFohVZZmI5SOr5S9xV9Hd7gM11+WI8dF6oefclHL+hi4G5+GENRWclVYeNBsSsniLndDJkRKUUPnFrWxxUxS66sH6ov7vQU0gnlT+KpIpHCYivQ0NslG4JlL9iQLDzkoedA+Y7eo0BtFfkgIKutv3MAQ7JLyYDl4Z8lARfOAauONiYR2ZdcjQOvQjn6ecrSMvNnQvM4anorQu+HpO0KKptWtRcG0bGXzx1t+Dh1kYgfZuM/WHk1uGLYISOIEsrf59T/FUV9EG63tTVyBePvCiwV9mK0WbFZ0thgVqBRprhuda7JBDMlv6MyJXm8e5i0FTMzj7eeOsGQGt45AZ4e/LCSKK2NvMfLO/fv3pqtdEm4tzybKwuotmLjCVK9nIw4mLeHOGak/TxDmnAuFbok03RGTTdoBCp50nMRVrRl6t2DiL07QXZ2UfZonlrV2WGNG4C5na2xSAK7B3Nrnf8xAAynIkAvHRKIRxMmTT1SOZ7Jq1mljIbAOighB3eKN/JkL15GqmqrQCoz5wDI6QaVa7wCuRwk8zrPpkuJc4zplPNatl94nCFgPg9xYTISUKzMuMlUkmCduQEUEhq8JlwuMpSlZoy1dbB2tnOgTVLKSHiFGrtk0mVLBjQ0tM+VfEMTOhsGpKmIRfACCiI8dv4kVQt35K2lMaee2QAaZHbQRvBdcxXs/hXMZHMxPyOsHYSpjGqZk8eSVOrGwOzFqIrczvgnQTiqA/pWdJPsfPygHjg7fq8kGWWnQMskHxeU6RlOvE4xtM1YqTRJek08axQcDLZ+PSh4KLd1JF8so+BFes9DEi0BJXVO58DLv09dt153PgkdUhX8bBwhHC2bs7zNHR9R5V5r5mAw2Db7U+Y6RaZK/GreU73xCeLZLwsWbtAI+gVYPGKv74OugD8pYYP94x7tLbvOaTXA9EAVN4+Y4dVFLllGzREJa7zUbJXtw2ZVdAsoAs8eQKJ3QwXGw+j4NtQSKAbWAxSXM7TXotIh/2YHHUqomRYfOhFbXqDmdPjSQ87LuOKb9YycwRdPlv2poik6PiBVu8msKUu3OIfi8S5MXTV3yCUdP9NlO7hVQ6/H/gS0OexPTbJEhgfyW3MH5qdEJAJn+DfjG3YpEm7BIJmReh1gfhif47ppSTrMC/tMBVFcz7Ssyh7rAMZw1Gqpw/tRzdiZCM7sSiqYH8dPoW4kW3TiZUSMdgb1b/A3E4wwqtJsk1Qi1AzPcldR5Doed2EKyhK3Cj2I25HN5LiF7gU4i9cH+rxXX2mwv+euSxVG/aLaol4tSWpZHv4nPiiT4z2aGgJXprquT4l0meVfLOZMVGhA7cIBqADYCnmOPP4fNgJBCqch6qKvx+IyMDle9sTQ95jS02cPQ1OWY6ObOQvIL9yY2MqDWoJ1ScOxob8umX0e8C+civmY+/ZeEGroysIrvicSlO0gCogjY6mLfuLSvb5z3n+w3mH3luq5ecpnFwxvtZMyQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(14060799003)(1800799024)(376014)(36860700013)(82310400026)(35042699022); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:12.9585 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5d26243-4120-413e-69c8-08dd1a040572 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D10.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5747 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This patch implements the PANTHOR_PERF_CONTROL ioctl series, and a PANTHOR_GET_UOBJ wrapper to deal with the backwards and forwards compatibility of the uAPI. Stub function definitions are added to ensure the patch builds on its own, and will be removed later in the series. Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/panthor_drv.c | 155 ++++++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_perf.c | 34 ++++++ drivers/gpu/drm/panthor/panthor_perf.h | 19 +++ 3 files changed, 206 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c index e0ac3107c69e..458175f58b15 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -7,6 +7,7 @@ #include #endif +#include #include #include #include @@ -31,6 +32,7 @@ #include "panthor_gpu.h" #include "panthor_heap.h" #include "panthor_mmu.h" +#include "panthor_perf.h" #include "panthor_regs.h" #include "panthor_sched.h" @@ -73,6 +75,39 @@ panthor_set_uobj(u64 usr_ptr, u32 usr_size, u32 min_size, u32 kern_size, const v return 0; } +/** + * panthor_get_uobj() - Copy kernel object to user object. + * @usr_ptr: Users pointer. + * @usr_size: Size of the user object. + * @min_size: Minimum size for this object. + * + * Helper automating kernel -> user object copies. + * + * Don't use this function directly, use PANTHOR_UOBJ_GET() instead. + * + * Return: valid pointer on success, an encoded error code otherwise. + */ +static void* +panthor_get_uobj(u64 usr_ptr, u32 usr_size, u32 min_size) +{ + int ret; + void *out_alloc __free(kvfree) = NULL; + + /* User size shouldn't be smaller than the minimal object size. */ + if (usr_size < min_size) + return ERR_PTR(-EINVAL); + + out_alloc = kvmalloc(min_size, GFP_KERNEL); + if (!out_alloc) + return ERR_PTR(-ENOMEM); + + ret = copy_struct_from_user(out_alloc, min_size, u64_to_user_ptr(usr_ptr), usr_size); + if (ret) + return ERR_PTR(ret); + + return_ptr(out_alloc); +} + /** * panthor_get_uobj_array() - Copy a user object array into a kernel accessible object array. * @in: The object array to copy. @@ -176,8 +211,11 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride, PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \ PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \ PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \ - PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info, shader_blocks)) - + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info, shader_blocks), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_cmd_setup, shader_enable_mask), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_cmd_start, user_data), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_cmd_stop, user_data), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_cmd_sample, user_data)) /** * PANTHOR_UOBJ_SET() - Copy a kernel object to a user object. @@ -192,6 +230,24 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride, PANTHOR_UOBJ_MIN_SIZE(_src_obj), \ sizeof(_src_obj), &(_src_obj)) +/** + * PANTHOR_UOBJ_GET() - Copies a user object from _usr_ptr to a kernel accessible _dest_ptr. + * @_dest_ptr: Local varialbe + * @_usr_size: Size of the user object. + * @_usr_ptr: The pointer of the object in userspace. + * + * Return: Error code. See panthor_get_uobj(). + */ +#define PANTHOR_UOBJ_GET(_dest_ptr, _usr_size, _usr_ptr) \ + ({ \ + typeof(_dest_ptr) _tmp; \ + _tmp = panthor_get_uobj(_usr_ptr, _usr_size, \ + PANTHOR_UOBJ_MIN_SIZE(_tmp[0])); \ + if (!IS_ERR(_tmp)) \ + _dest_ptr = _tmp; \ + PTR_ERR_OR_ZERO(_tmp); \ + }) + /** * PANTHOR_UOBJ_GET_ARRAY() - Copy a user object array to a kernel accessible * object array. @@ -1339,6 +1395,99 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data, return 0; } +static int panthor_ioctl_perf_control(struct drm_device *ddev, void *data, + struct drm_file *file) +{ + struct panthor_device *ptdev = container_of(ddev, struct panthor_device, base); + struct panthor_file *pfile = file->driver_priv; + struct drm_panthor_perf_control *args = data; + int ret; + + if (!args->pointer) { + switch (args->cmd) { + case DRM_PANTHOR_PERF_COMMAND_SETUP: + args->size = sizeof(struct drm_panthor_perf_cmd_setup); + return 0; + + case DRM_PANTHOR_PERF_COMMAND_TEARDOWN: + args->size = 0; + return 0; + + case DRM_PANTHOR_PERF_COMMAND_START: + args->size = sizeof(struct drm_panthor_perf_cmd_start); + return 0; + + case DRM_PANTHOR_PERF_COMMAND_STOP: + args->size = sizeof(struct drm_panthor_perf_cmd_stop); + return 0; + + case DRM_PANTHOR_PERF_COMMAND_SAMPLE: + args->size = sizeof(struct drm_panthor_perf_cmd_sample); + return 0; + + default: + return -EINVAL; + } + } + + switch (args->cmd) { + case DRM_PANTHOR_PERF_COMMAND_SETUP: + { + struct drm_panthor_perf_cmd_setup *setup_args __free(kvfree) = NULL; + + ret = PANTHOR_UOBJ_GET(setup_args, args->size, args->pointer); + if (ret) + return -EINVAL; + + if (setup_args->pad[0]) + return -EINVAL; + + ret = panthor_perf_session_setup(ptdev, ptdev->perf, setup_args, pfile); + + return ret; + } + case DRM_PANTHOR_PERF_COMMAND_TEARDOWN: + { + return panthor_perf_session_teardown(pfile, ptdev->perf, args->handle); + } + case DRM_PANTHOR_PERF_COMMAND_START: + { + struct drm_panthor_perf_cmd_start *start_args __free(kvfree) = NULL; + + ret = PANTHOR_UOBJ_GET(start_args, args->size, args->pointer); + if (ret) + return -EINVAL; + + return panthor_perf_session_start(pfile, ptdev->perf, args->handle, + start_args->user_data); + } + case DRM_PANTHOR_PERF_COMMAND_STOP: + { + struct drm_panthor_perf_cmd_stop *stop_args __free(kvfree) = NULL; + + ret = PANTHOR_UOBJ_GET(stop_args, args->size, args->pointer); + if (ret) + return -EINVAL; + + return panthor_perf_session_stop(pfile, ptdev->perf, args->handle, + stop_args->user_data); + } + case DRM_PANTHOR_PERF_COMMAND_SAMPLE: + { + struct drm_panthor_perf_cmd_sample *sample_args __free(kvfree) = NULL; + + ret = PANTHOR_UOBJ_GET(sample_args, args->size, args->pointer); + if (ret) + return -EINVAL; + + return panthor_perf_session_sample(pfile, ptdev->perf, args->handle, + sample_args->user_data); + } + default: + return -EINVAL; + } +} + static int panthor_open(struct drm_device *ddev, struct drm_file *file) { @@ -1386,6 +1535,7 @@ panthor_postclose(struct drm_device *ddev, struct drm_file *file) panthor_group_pool_destroy(pfile); panthor_vm_pool_destroy(pfile); + panthor_perf_session_destroy(pfile, pfile->ptdev->perf); kfree(pfile); module_put(THIS_MODULE); @@ -1408,6 +1558,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = { PANTHOR_IOCTL(TILER_HEAP_CREATE, tiler_heap_create, DRM_RENDER_ALLOW), PANTHOR_IOCTL(TILER_HEAP_DESTROY, tiler_heap_destroy, DRM_RENDER_ALLOW), PANTHOR_IOCTL(GROUP_SUBMIT, group_submit, DRM_RENDER_ALLOW), + PANTHOR_IOCTL(PERF_CONTROL, perf_control, DRM_RENDER_ALLOW), }; static int panthor_mmap(struct file *filp, struct vm_area_struct *vma) diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c index e0dc6c4b0cf1..6498279ec036 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.c +++ b/drivers/gpu/drm/panthor/panthor_perf.c @@ -63,6 +63,40 @@ void panthor_perf_info_init(struct panthor_device *ptdev) perf_info->shader_blocks = hweight64(ptdev->gpu_info.shader_present); } +int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf *perf, + struct drm_panthor_perf_cmd_setup *setup_args, + struct panthor_file *pfile) +{ + return -EOPNOTSUPP; +} + +int panthor_perf_session_teardown(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid) +{ + return -EOPNOTSUPP; +} + +int panthor_perf_session_start(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data) +{ + return -EOPNOTSUPP; +} + +int panthor_perf_session_stop(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data) +{ + return -EOPNOTSUPP; +} + +int panthor_perf_session_sample(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data) +{ + return -EOPNOTSUPP; + +} + +void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_perf *perf) { } + /** * panthor_perf_init - Initialize the performance counter subsystem. * @ptdev: Panthor device diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h index 90af8b18358c..bfef8874068b 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.h +++ b/drivers/gpu/drm/panthor/panthor_perf.h @@ -5,11 +5,30 @@ #ifndef __PANTHOR_PERF_H__ #define __PANTHOR_PERF_H__ +#include + +struct drm_gem_object; +struct drm_panthor_perf_cmd_setup; struct panthor_device; +struct panthor_file; +struct panthor_perf; void panthor_perf_info_init(struct panthor_device *ptdev); int panthor_perf_init(struct panthor_device *ptdev); void panthor_perf_unplug(struct panthor_device *ptdev); +int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf *perf, + struct drm_panthor_perf_cmd_setup *setup_args, + struct panthor_file *pfile); +int panthor_perf_session_teardown(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid); +int panthor_perf_session_start(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data); +int panthor_perf_session_stop(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data); +int panthor_perf_session_sample(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data); +void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_perf *perf); + #endif /* __PANTHOR_PERF_H__ */ From patchwork Wed Dec 11 16:50:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903946 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 87F2FE7717D for ; Wed, 11 Dec 2024 16:51:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 049C510EBBB; Wed, 11 Dec 2024 16:51:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="Bb2evrXD"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Bb2evrXD"; dkim-atps=neutral Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2051.outbound.protection.outlook.com [40.107.20.51]) by gabe.freedesktop.org (Postfix) with ESMTPS id B44DF10EBC2 for ; Wed, 11 Dec 2024 16:51:25 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=nnsryV8jupNF5myHKaB9g+SD3yRFDimjufPqLipDqOh7/WIElgBwSj5SNUzIwcnHLfO5uI6hLEmTCpqaj12ViYCjAiJ3Pq44/XDle/17vlCIoAjs5Q2bGxkdV5PwY8w0rMJWWGomU4aTcSPjVlwMH4zbzq88DyhzKXG858H48/1HEfFtKQnbyXdWeTp0LtKmnmaZuIxDNffp3Hkvhx2GID89V2Mev8LAxaDuT+Szsnsd4kkDq7ZQyfNf9ErLTR6z3DIGWXgwVCt/M8J9WHZQD2omy/OyMXIZG54wYpiYVTcTBuvL6Nfz6lVneRVE9fK989soPnP9RZ+g8BY/2t109w== ARC-Message-Signature: i=2; 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=jZuRX+eUV6aIwFRo4Jc2T3cXWMzxDhQduw5WQ3Mm9EU=; b=BSXaPmm4EQOTZvKiad/Upmb8aLGuVTRsdJUViX7X+sQEaInQlmRN384MpD5QpV7VqOj7MpfQdnu1P4dOtiS5pJ6k+WY8R5eqZZ+rcjojQRvDNn0d2AGj3G2P4o4jY5beYIy5TgXeF8o9JzX9MEFmViR4ocPN355xjOiyGwynHMFjrrTwNnazkeRBbpIC/S47OmLzB11sxABGyVVk6dsoSvtGwuJTTFvbthQjqwdDByMW+8MFUu1GwqC+AD3+ZyShMmzLQ3gf34OiInYbJJDz/05blvMmPm2YhV3knR6CAd11XbCcHT15XOKhk5SKFyyDrLTZeHdFhJf5zW7KmOCGIg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jZuRX+eUV6aIwFRo4Jc2T3cXWMzxDhQduw5WQ3Mm9EU=; b=Bb2evrXD1qw1DKeSRAzVITnWnKPAo2alR45Ollzkm5WmHhYxmrdFBFe2RcE8rpOgCp0haeJgObU6KftPh3j/p2pkJ34yn4xmcdzDYFjLqGWENC4gkTg6x+DDgMHNtr5MLbdTjif11Ovle/TIdAsBVSLKvf5D0uFW9IlV9eEcNYQ= Received: from AS9PR0301CA0019.eurprd03.prod.outlook.com (2603:10a6:20b:468::29) by GV1PR08MB7345.eurprd08.prod.outlook.com (2603:10a6:150:20::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:51:16 +0000 Received: from AMS1EPF0000004B.eurprd04.prod.outlook.com (2603:10a6:20b:468:cafe::d2) by AS9PR0301CA0019.outlook.office365.com (2603:10a6:20b:468::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AMS1EPF0000004B.mail.protection.outlook.com (10.167.16.136) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:16 +0000 Received: ("Tessian outbound 2d228e31de9a:v524"); Wed, 11 Dec 2024 16:51:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 7264bd6342dbc3ec X-TessianGatewayMetadata: /ZD/i4uMS2m2bTcn5403529Z8gtSYuYgnzwSa5tdkE3zoVyRw6wqn2PpzSmgZSzLdN53VmoHnjZepKb2xoKFWW51+nEYu3/hynctHZ6s1JBUsYAItHWtegQbbEcUUGdsNroC9n1n2fNor0MB6CHOnLFxKfQy/t2sG6AI27ejRGw= X-CR-MTA-TID: 64aa7808 Received: from Ld853ad558fcb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4DAAD5A8-5FFB-40D0-B08C-B43E21D8230F.1; Wed, 11 Dec 2024 16:51:03 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id Ld853ad558fcb.1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:51:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=obj4/R5EUpv6AJzU77+HYKRrEmRzKcqQngfjHdGy42Tvmv6azrfFMwAPaJKxvmpgO/LCziPT0WfISUMJ+OT3SVlzl5snLgSVscK9E4j02Q/k2RsoM+ucPmTAEZmuJDj40kxwht79fFWLlqZkdb49Hy7j+YWYnxjuuAAlv5Z/YuW1WqZW670HlQAPrG1aAe+hwF2PlHC+aa9hdWbkVGP9ZOOJ0n6rvxbVxasxKt7oZEE4dGy6W0FKp/YSuTt2V8No9VecLjErg3pv2qvBzDHEEieebw56dK3w43RwF4scH5jMxmuR76VItsZy1Kwmuq6qcw+PHwhYQ17gf52Jt5E4Vg== 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=jZuRX+eUV6aIwFRo4Jc2T3cXWMzxDhQduw5WQ3Mm9EU=; b=n2nDHpPU/BAMKvVn0sQ3jAsz8BV14FQbzXjEU6mmD2V+bJOVshYicCKE3N7klDYPukGVCL+vi+MQPmSgdZjtrhQYpr2zwHRqXPShoBKrVFHLPGda8txdTEfSv6tfK8/Yd4J2heEcjFeAMshcMkdo02e2cbWJYX4qsM1I5SgFakwvHAg/nvKLkXPw0+OBx+vArOIrzr6KUznMSCJyDF71SCCXRUqJJTl3i4Oumy3DeP/tcr65Kk98KthJ1eQYo+zPzr8N/RVmDOZ6JHl+6dms2aVTmC6wnUnNPcoIL/kizsaYBDV+YKtBvlErHivojkj7O2/F9knGZAsdCFfU1H140Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jZuRX+eUV6aIwFRo4Jc2T3cXWMzxDhQduw5WQ3Mm9EU=; b=Bb2evrXD1qw1DKeSRAzVITnWnKPAo2alR45Ollzkm5WmHhYxmrdFBFe2RcE8rpOgCp0haeJgObU6KftPh3j/p2pkJ34yn4xmcdzDYFjLqGWENC4gkTg6x+DDgMHNtr5MLbdTjif11Ovle/TIdAsBVSLKvf5D0uFW9IlV9eEcNYQ= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:50:59 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:50:59 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 5/8] drm/panthor: Introduce sampling sessions to handle userspace clients Date: Wed, 11 Dec 2024 16:50:21 +0000 Message-Id: <20241211165024.490748-6-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO4P265CA0082.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bd::15) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8422:EE_|AMS1EPF0000004B:EE_|GV1PR08MB7345:EE_ X-MS-Office365-Filtering-Correlation-Id: bbf19867-1f72-4707-c1b0-08dd1a040774 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: iVueNGWKsox5QPfdG+byGGBOn8+YhLWd64zWCU19koXM4lRlUqN1xS+Z2/NwjSuqHqFwXvgck2+69wUzoWMXEYqJGorXGCpEZcdxxZ6MpLwt3z5nO7cNfq7pzqqEGrnbhLiRWF9xFHB+BeVtGY+DDC5yuqmTCUWAnuRT2wNjw5GUjKPmCAz1shbyXB3EGsH8gfY3b+pBplYSwrqN02ybF6m3UgXBBz/2AM0wcgjC54UScIYLNtAbsMXIwjIMoPlxac6ARtuFDjKk5CL7Gy+5KwqHThihFNXmVGghM4TFCfIrcdDAUxlbcZaVxoE0uyVReb9U77yCPDbGSbPCXtIRUU85iqo3i2fcaPtwI5GHg5lWc/SuAeV28AYP6k4OF1pcP2giXaz/7AqLkpfnwjB8AkhvqwSolQ8AQJRC+JFo54kCWp49VaEqfWO0s+3xkSBu8+ChE2vEC67gyS8aztvmQN99sT3pMbe0QAXt2RllFVLcdo9cJrrGEo2iLPfyrQefpWNU5hOE54ably/3m0OWls+JcsixtYQ1hNd/kAHqxsBlb4G+Ppz5qbWNH/NhINycblo8QKEFFSbmplnwPrXCBanXGQXO/PYvb6WpZA4/P/6P7PzkS00q3oBcfpTw2LzkX+zG+57p0tSAGYdWg2ndh75e+qw3/r5piBgRaZ3mmofxJmPAz1yrUo6LiVrtLePwvHEY0vQtZkbKHkzu+TKF0/Atrvsi7RRxWX2SNzx76TjVCfzO9IerQRkcEGhaKgcFLiEFAo3a4EKWDMKd/iGS0pQ9+z18r2VRntYn5sTA+iqczfJFdm90bm5Z/AIIfxtXsrJRTXOv2f1Njk9H2QRaOIxCtNnQSQwY5JQxl7bDwWFjvRbKHtnu7aqiiqUxASXjyqDifwMrL01TNEsEZ0J6TvCxW0g8ZtIwO/s5ldIr44Kb43vLS5wrgZcsuFk/PlNpCntGT9E3JTq89QRrse19NY5vGqbolh/lL8cOQVmg1LYmoDBKfcizDEehSllOyynJHfGNlg4Sjfl0btJSD5YfF7WIF8pppwoZaBODllQOa6/lpkEW/UUT44n3h+jZX+PqyefQ0ULTFyI5IeQHQgBA31WYWLfvlXW/Gl46b01Co8boPmMNQtA76+uM1vkVU/JDPpPcWa2WoB7Vm9iubBxED+nii2sRPO9oan3zNoJRBDami17YxJPVXS6mfEgskwQ0EpyO4gIZlPp3BrJsjrli9zzbUSd5ojCtNq6vdCZjNko5Pa70fN1YVqSXSrhIlwvwShsw2WRBJM5B1kT8uYE3U8qr+5oWUCsFpL6Up6rteI3rH1jhmdjIOe9zjtoPY9VPPH1bC3173CgxlEAF+k8uYg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS1EPF0000004B.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 2b8dc574-f29b-488f-3699-08dd1a03fd56 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|14060799003|36860700013|376014|30052699003|35042699022|82310400026; X-Microsoft-Antispam-Message-Info: 4q/q2U2l6VV0IuWVKnpwsQXQKWGksmwzixnEMwk7Td4Q0/6U1A5SGM2WhlFNFrb7gjPQBC2GjZZ1H3CdBS9RyRnxRTBHGY0dtEyuCf7fsz2RHgxV79O+4AhDHKY3DDcwNtemQj7RgH6bUXP9og9vQX2SusLdaGtfuPDVRVfkqdNYAFqw0ii0EJSLdHQL/2w+4klOG1wtxW8T4Vpv1i7ba1RtKxPmQrodu3/L4XdVyimDbmTHGwrCC2NarlwD9B7vCWwL5wgHNtIyiptDdyBChh01CzjLMm4GGbXjQpwMH5kD069/BxX9rpLnfTM5ToRjsCORkfE59xmQJzvqSqCkr9CKKQUYz6SUuMUtqpVe/2opuriRp+PYdYb9+5djbXc3xUR+zK03d9l10AbRKN//bQl1lWOU/fTXQKY6osw38f/P7hwevBFNEaqLtEegqIz5A8DFt01ECQd7iaUjfH8CojH4bio6ezC37uIgWdmMpqiZ3d0GXNI0RVPUO5H0+2lAHewOoFJzIJM9AsNLRZRsP6GUXOG8QcMmNTNOMtldcV5TmD+klUqr0ZT8+ueIlvWijKhxaH7lT0TWQzDZr6iWExTStONiw7X0+5bQEGwse+au60z5AFmKPU0iHTB+wUmooekB2R52ahpIqUvmBZoEr/jYe9rAd/h+N37DnJNfka87CbXOtho5OGT9fjwXhRzkO2QmArKMqWIjU613F3Fxn7XiQR4xADZ1/cVHM+EdoLYr0O4wN0hgTLh+p4Jt7XUcZ7q4NtWGRsaGbPseu67nvvfKmGDPhmIOeIm73rqJlXs0PD2ebcPRuJTnnRyyb1foCaTQnJROhTd/72wG9huSwElElMjZHOEF9nXR4V0mjXaF8W9Q7BngnCFKi2pNhuYmetVE9uMaaqxG62osWzh/ANu3fHluxeo8HAVj/syAvgRAYxmWwCRYh29PEElQ7dWX3nMr8TNKlJejbWDReNd+axnozDjb7nz4MJpGGyRlkqUInUkXP+DwIVX7M5kSsMU2j6rNRdTa9rXZqC6FcThhFvVciSf8WAV/JPNPYvZXLKEV4gSOrvIHJ6ER+/k8USYcq1p+8gSdFeIZfb5vvGCU0aCotp37GJS9tXx9WPvkq9WKpTZAuanmjh/Xy7GiPHcGlVLw/5kwW6ZvrhRyVOCkPto2S+u3xO0kF/3jhelOMyqYQTRd5era6OoeeJ7btiT7AXxjS6dRUAKRh3fRhW9jqnLEoFw67LHDpALzSdUeXMXyIb4q2saXQbQ+/WFGGNo3P6D1W0x32tnU+3qbAsSrXFhJJFiFV1KSGw1tlCSXUp7yBjmx5cepNmTyMljFtDMa6AGG3hQPRrKCj3k2cBsMAJQgFITUbfPwku3T1R5RDVEivB3JbDfgy1kuFBhbvx5wd7xiYvymQYPneIlOJl8MM+ZgVeXexBgND6PfEkJzF5OFyITfjaC+/fI9KNU28YJO/er6DWpqBk7kt65J9zyvBQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(1800799024)(14060799003)(36860700013)(376014)(30052699003)(35042699022)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:16.2668 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbf19867-1f72-4707-c1b0-08dd1a040774 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AMS1EPF0000004B.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7345 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allow for combining the requests from multiple userspace clients, an intermediary layer between the HW/FW interfaces and userspace is created, containing the information for the counter requests and tracking of insert and extract indices. Each session starts inactive and must be explicitly activated via PERF_CONTROL.START, and explicitly stopped via PERF_CONTROL.STOP. Userspace identifies a single client with its session ID and the panthor file it is associated with. The SAMPLE and STOP commands both produce a single sample when called, and these samples can be disambiguated via the opaque user data field passed in the PERF_CONTROL uAPI. If this functionality is not desired, these fields can be kept as zero, as the kernel copies this value into the corresponding sample without attempting to interpret it. Currently, only manual sampling sessions are supported, providing samples when userspace calls PERF_CONTROL.SAMPLE, and only a single session is allowed at a time. Multiple sessions and periodic sampling will be enabled in following patches. No protected is provided against the 32-bit hardware counter overflows, so for the moment it is up to userspace to ensure that the counters are sampled at a reasonable frequency. The counter set enum is added to the uapi to clarify the restrictions on calling the interface. Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/panthor_device.h | 3 + drivers/gpu/drm/panthor/panthor_drv.c | 1 + drivers/gpu/drm/panthor/panthor_perf.c | 697 ++++++++++++++++++++++- include/uapi/drm/panthor_drm.h | 50 +- 4 files changed, 732 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h index aca33d03036c..9ed1e9aed521 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -210,6 +210,9 @@ struct panthor_file { /** @ptdev: Device attached to this file. */ struct panthor_device *ptdev; + /** @drm_file: Corresponding drm_file */ + struct drm_file *drm_file; + /** @vms: VM pool attached to this file. */ struct panthor_vm_pool *vms; diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c index 458175f58b15..2848ab442d10 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -1505,6 +1505,7 @@ panthor_open(struct drm_device *ddev, struct drm_file *file) } pfile->ptdev = ptdev; + pfile->drm_file = file; ret = panthor_vm_pool_create(pfile); if (ret) diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c index 6498279ec036..42d8b6f8c45d 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.c +++ b/drivers/gpu/drm/panthor/panthor_perf.c @@ -3,16 +3,162 @@ /* Copyright 2024 Arm ltd. */ #include +#include #include #include +#include #include +#include +#include +#include + #include "panthor_device.h" #include "panthor_fw.h" #include "panthor_gpu.h" #include "panthor_perf.h" #include "panthor_regs.h" +/** + * PANTHOR_PERF_EM_BITS - Number of bits in a user-facing enable mask. This must correspond + * to the maximum number of counters available for selection on the newest + * Mali GPUs (128 as of the Mali-Gx15). + */ +#define PANTHOR_PERF_EM_BITS (BITS_PER_TYPE(u64) * 2) + +/** + * enum panthor_perf_session_state - Session state bits. + */ +enum panthor_perf_session_state { + /** @PANTHOR_PERF_SESSION_ACTIVE: The session is active and can be used for sampling. */ + PANTHOR_PERF_SESSION_ACTIVE = 0, + + /** + * @PANTHOR_PERF_SESSION_OVERFLOW: The session encountered an overflow in one of the + * counters during the last sampling period. This flag + * gets propagated as part of samples emitted for this + * session, to ensure the userspace client can gracefully + * handle this data corruption. + */ + PANTHOR_PERF_SESSION_OVERFLOW, + + /** @PANTHOR_PERF_SESSION_MAX: Bits needed to represent the state. Must be last.*/ + PANTHOR_PERF_SESSION_MAX, +}; + +struct panthor_perf_enable_masks { + /** + * @link: List node used to keep track of the enable masks aggregated by the sampler. + */ + struct list_head link; + + /** @refs: Number of references taken out on an instantiated enable mask. */ + struct kref refs; + + /** + * @mask: Array of bitmasks indicating the counters userspace requested, where + * one bit represents a single counter. Used to build the firmware configuration + * and ensure that userspace clients obtain only the counters they requested. + */ + DECLARE_BITMAP(mask, PANTHOR_PERF_EM_BITS)[DRM_PANTHOR_PERF_BLOCK_MAX]; +}; + +struct panthor_perf_counter_block { + struct drm_panthor_perf_block_header header; + u64 counters[]; +}; + +struct panthor_perf_session { + DECLARE_BITMAP(state, PANTHOR_PERF_SESSION_MAX); + + /** + * @user_sample_size: The size of a single sample as exposed to userspace. For the sake of + * simplicity, the current implementation exposes the same structure + * as provided by firmware, after annotating the sample and the blocks, + * and zero-extending the counters themselves (to account for in-kernel + * accumulation). + * + * This may also allow further memory-optimizations of compressing the + * sample to provide only requested blocks, if deemed to be worth the + * additional complexity. + */ + size_t user_sample_size; + + /** + * @sample_freq_ns: Period between subsequent sample requests. Zero indicates that + * userspace will be responsible for requesting samples. + */ + u64 sample_freq_ns; + + /** @sample_start_ns: Sample request time, obtained from a monotonic raw clock. */ + u64 sample_start_ns; + + /** + * @user_data: Opaque handle passed in when starting a session, requesting a sample (for + * manual sampling sessions only) and when stopping a session. This handle + * allows the disambiguation of a sample in the ringbuffer. + */ + u64 user_data; + + /** + * @eventfd: Event file descriptor context used to signal userspace of a new sample + * being emitted. + */ + struct eventfd_ctx *eventfd; + + /** + * @enabled_counters: This session's requested counters. Note that these cannot change + * for the lifetime of the session. + */ + struct panthor_perf_enable_masks *enabled_counters; + + /** @ringbuf_slots: Slots in the user-facing ringbuffer. */ + size_t ringbuf_slots; + + /** @ring_buf: BO for the userspace ringbuffer. */ + struct drm_gem_object *ring_buf; + + /** + * @control_buf: BO for the insert and extract indices. + */ + struct drm_gem_object *control_buf; + + /** + * @extract_idx: The extract index is used by userspace to indicate the position of the + * consumer in the ringbuffer. + */ + u32 *extract_idx; + + /** + * @insert_idx: The insert index is used by the kernel to indicate the position of the + * latest sample exposed to userspace. + */ + u32 *insert_idx; + + /** @samples: The mapping of the @ring_buf into the kernel's VA space. */ + u8 *samples; + + /** + * @waiting: The list node used by the sampler to track the sessions waiting for a sample. + */ + struct list_head waiting; + + /** + * @pfile: The panthor file which was used to create a session, used for the postclose + * handling and to prevent a misconfigured userspace from closing unrelated + * sessions. + */ + struct panthor_file *pfile; + + /** + * @ref: Session reference count. The sample delivery to userspace is asynchronous, meaning + * the lifetime of the session must extend at least until the sample is exposed to + * userspace. + */ + struct kref ref; +}; + + struct panthor_perf { /** * @block_set: The global counter set configured onto the HW. @@ -63,39 +209,154 @@ void panthor_perf_info_init(struct panthor_device *ptdev) perf_info->shader_blocks = hweight64(ptdev->gpu_info.shader_present); } -int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf *perf, - struct drm_panthor_perf_cmd_setup *setup_args, - struct panthor_file *pfile) +static struct panthor_perf_enable_masks *panthor_perf_em_new(void) { - return -EOPNOTSUPP; + struct panthor_perf_enable_masks *em = kmalloc(sizeof(*em), GFP_KERNEL); + + if (!em) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&em->link); + + kref_init(&em->refs); + + return em; } -int panthor_perf_session_teardown(struct panthor_file *pfile, struct panthor_perf *perf, - u32 sid) +static struct panthor_perf_enable_masks *panthor_perf_create_em(struct drm_panthor_perf_cmd_setup + *setup_args) { - return -EOPNOTSUPP; + struct panthor_perf_enable_masks *em = panthor_perf_em_new(); + + if (IS_ERR_OR_NULL(em)) + return em; + + bitmap_from_arr64(em->mask[DRM_PANTHOR_PERF_BLOCK_FW], + setup_args->fw_enable_mask, PANTHOR_PERF_EM_BITS); + bitmap_from_arr64(em->mask[DRM_PANTHOR_PERF_BLOCK_CSG], + setup_args->csg_enable_mask, PANTHOR_PERF_EM_BITS); + bitmap_from_arr64(em->mask[DRM_PANTHOR_PERF_BLOCK_CSHW], + setup_args->cshw_enable_mask, PANTHOR_PERF_EM_BITS); + bitmap_from_arr64(em->mask[DRM_PANTHOR_PERF_BLOCK_TILER], + setup_args->tiler_enable_mask, PANTHOR_PERF_EM_BITS); + bitmap_from_arr64(em->mask[DRM_PANTHOR_PERF_BLOCK_MEMSYS], + setup_args->memsys_enable_mask, PANTHOR_PERF_EM_BITS); + bitmap_from_arr64(em->mask[DRM_PANTHOR_PERF_BLOCK_SHADER], + setup_args->shader_enable_mask, PANTHOR_PERF_EM_BITS); + + return em; } -int panthor_perf_session_start(struct panthor_file *pfile, struct panthor_perf *perf, - u32 sid, u64 user_data) +static void panthor_perf_destroy_em_kref(struct kref *em_kref) { - return -EOPNOTSUPP; + struct panthor_perf_enable_masks *em = container_of(em_kref, typeof(*em), refs); + + if (!list_empty(&em->link)) + return; + + kfree(em); } -int panthor_perf_session_stop(struct panthor_file *pfile, struct panthor_perf *perf, - u32 sid, u64 user_data) +static size_t get_annotated_block_size(size_t counters_per_block) { - return -EOPNOTSUPP; + return struct_size_t(struct panthor_perf_counter_block, counters, counters_per_block); } -int panthor_perf_session_sample(struct panthor_file *pfile, struct panthor_perf *perf, - u32 sid, u64 user_data) +static u32 session_read_extract_idx(struct panthor_perf_session *session) +{ + /* Userspace will update their own extract index to indicate that a sample is consumed + * from the ringbuffer, and we must ensure we read the latest value. + */ + return smp_load_acquire(session->extract_idx); +} + +static u32 session_read_insert_idx(struct panthor_perf_session *session) +{ + return *session->insert_idx; +} + +static void session_get(struct panthor_perf_session *session) +{ + kref_get(&session->ref); +} + +static void session_free(struct kref *ref) +{ + struct panthor_perf_session *session = container_of(ref, typeof(*session), ref); + + if (session->samples) { + struct iosys_map map = IOSYS_MAP_INIT_VADDR(session->samples); + + drm_gem_vunmap_unlocked(session->ring_buf, &map); + drm_gem_object_put(session->ring_buf); + } + + if (session->insert_idx && session->extract_idx) { + struct iosys_map map = IOSYS_MAP_INIT_VADDR(session->extract_idx); + + drm_gem_vunmap_unlocked(session->control_buf, &map); + drm_gem_object_put(session->control_buf); + } + + kref_put(&session->enabled_counters->refs, panthor_perf_destroy_em_kref); + eventfd_ctx_put(session->eventfd); + + devm_kfree(session->pfile->ptdev->base.dev, session); +} + +static void session_put(struct panthor_perf_session *session) +{ + kref_put(&session->ref, session_free); +} + +/** + * session_find - Find a session associated with the given session ID and + * panthor_file. + * @pfile: Panthor file. + * @perf: Panthor perf. + * @sid: Session ID. + * + * The reference count of a valid session is increased to ensure it does not disappear + * in the window between the XA lock being dropped and the internal session functions + * being called. + * + * Return: valid session pointer or an ERR_PTR. + */ +static struct panthor_perf_session *session_find(struct panthor_file *pfile, + struct panthor_perf *perf, u32 sid) { - return -EOPNOTSUPP; + struct panthor_perf_session *session; + if (!perf) + return ERR_PTR(-EINVAL); + + xa_lock(&perf->sessions); + session = xa_load(&perf->sessions, sid); + + if (!session || xa_is_err(session)) { + xa_unlock(&perf->sessions); + return ERR_PTR(-EBADF); + } + + if (session->pfile != pfile) { + xa_unlock(&perf->sessions); + return ERR_PTR(-EINVAL); + } + + session_get(session); + xa_unlock(&perf->sessions); + + return session; } -void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_perf *perf) { } +static size_t session_get_max_sample_size(const struct drm_panthor_perf_info *const info) +{ + const size_t block_size = get_annotated_block_size(info->counters_per_block); + const size_t block_nr = info->cshw_blocks + info->csg_blocks + info->fw_blocks + + info->tiler_blocks + info->memsys_blocks + info->shader_blocks; + + return sizeof(struct drm_panthor_perf_sample_header) + (block_size * block_nr); +} /** * panthor_perf_init - Initialize the performance counter subsystem. @@ -130,6 +391,399 @@ int panthor_perf_init(struct panthor_device *ptdev) ptdev->perf = perf; return 0; + +} + +static int session_validate_set(u8 set) +{ + if (set > DRM_PANTHOR_PERF_SET_TERTIARY) + return -EINVAL; + + if (set == DRM_PANTHOR_PERF_SET_PRIMARY) + return 0; + + if (set > DRM_PANTHOR_PERF_SET_PRIMARY) + return capable(CAP_PERFMON) ? 0 : -EACCES; + + return -EINVAL; +} + +/** + * panthor_perf_session_setup - Create a user-visible session. + * + * @ptdev: Handle to the panthor device. + * @perf: Handle to the perf control structure. + * @setup_args: Setup arguments passed in via ioctl. + * @pfile: Panthor file associated with the request. + * + * Creates a new session associated with the session ID returned. When initialized, the + * session must explicitly request sampling to start with a successive call to PERF_CONTROL.START. + * + * Return: non-negative session identifier on success or negative error code on failure. + */ +int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf *perf, + struct drm_panthor_perf_cmd_setup *setup_args, + struct panthor_file *pfile) +{ + struct panthor_perf_session *session; + struct drm_gem_object *ringbuffer; + struct drm_gem_object *control; + const size_t slots = setup_args->sample_slots; + struct panthor_perf_enable_masks *em; + struct iosys_map rb_map, ctrl_map; + size_t user_sample_size; + int session_id; + int ret; + + ret = session_validate_set(setup_args->block_set); + if (ret) + return ret; + + session = devm_kzalloc(ptdev->base.dev, sizeof(*session), GFP_KERNEL); + if (ZERO_OR_NULL_PTR(session)) + return -ENOMEM; + + ringbuffer = drm_gem_object_lookup(pfile->drm_file, setup_args->ringbuf_handle); + if (!ringbuffer) { + ret = -EINVAL; + goto cleanup_session; + } + + control = drm_gem_object_lookup(pfile->drm_file, setup_args->control_handle); + if (!control) { + ret = -EINVAL; + goto cleanup_ringbuf; + } + + user_sample_size = session_get_max_sample_size(&ptdev->perf_info) * slots; + + if (ringbuffer->size != PFN_ALIGN(user_sample_size)) { + ret = -ENOMEM; + goto cleanup_control; + } + + ret = drm_gem_vmap_unlocked(ringbuffer, &rb_map); + if (ret) + goto cleanup_control; + + + ret = drm_gem_vmap_unlocked(control, &ctrl_map); + if (ret) + goto cleanup_ring_map; + + session->eventfd = eventfd_ctx_fdget(setup_args->fd); + if (IS_ERR_OR_NULL(session->eventfd)) { + ret = PTR_ERR_OR_ZERO(session->eventfd) ?: -EINVAL; + goto cleanup_control_map; + } + + em = panthor_perf_create_em(setup_args); + if (IS_ERR_OR_NULL(em)) { + ret = -ENOMEM; + goto cleanup_eventfd; + } + + INIT_LIST_HEAD(&session->waiting); + session->extract_idx = ctrl_map.vaddr; + *session->extract_idx = 0; + session->insert_idx = session->extract_idx + 1; + *session->insert_idx = 0; + + session->samples = rb_map.vaddr; + + /* TODO This will need validation when we support periodic sampling sessions */ + if (setup_args->sample_freq_ns) { + ret = -EOPNOTSUPP; + goto cleanup_em; + } + + session->sample_freq_ns = setup_args->sample_freq_ns; + session->user_sample_size = user_sample_size; + session->enabled_counters = em; + session->ring_buf = ringbuffer; + session->control_buf = control; + session->pfile = pfile; + + ret = xa_alloc_cyclic(&perf->sessions, &session_id, session, perf->session_range, + &perf->next_session, GFP_KERNEL); + if (ret < 0) + goto cleanup_em; + + kref_init(&session->ref); + + return session_id; + +cleanup_em: + kref_put(&em->refs, panthor_perf_destroy_em_kref); + +cleanup_eventfd: + eventfd_ctx_put(session->eventfd); + +cleanup_control_map: + drm_gem_vunmap_unlocked(control, &ctrl_map); + +cleanup_ring_map: + drm_gem_vunmap_unlocked(ringbuffer, &rb_map); + +cleanup_control: + drm_gem_object_put(control); + +cleanup_ringbuf: + drm_gem_object_put(ringbuffer); + +cleanup_session: + devm_kfree(ptdev->base.dev, session); + + return ret; +} + +static int session_stop(struct panthor_perf *perf, struct panthor_perf_session *session, + u64 user_data) +{ + if (!test_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state)) + return 0; + + const u32 extract_idx = session_read_extract_idx(session); + const u32 insert_idx = session_read_insert_idx(session); + + /* Must have at least one slot remaining in the ringbuffer to sample. */ + if (WARN_ON_ONCE(!CIRC_SPACE_TO_END(insert_idx, extract_idx, session->ringbuf_slots))) + return -EBUSY; + + session->user_data = user_data; + + clear_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state); + + /* TODO Calls to the FW interface will go here in later patches. */ + return 0; +} + +static int session_start(struct panthor_perf *perf, struct panthor_perf_session *session, + u64 user_data) +{ + if (test_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state)) + return 0; + + set_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state); + + /* + * For manual sampling sessions, a start command does not correspond to a sample, + * and so the user data gets discarded. + */ + if (session->sample_freq_ns) + session->user_data = user_data; + + /* TODO Calls to the FW interface will go here in later patches. */ + return 0; +} + +static int session_sample(struct panthor_perf *perf, struct panthor_perf_session *session, + u64 user_data) +{ + if (!test_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state)) + return -EACCES; + + const u32 extract_idx = session_read_extract_idx(session); + const u32 insert_idx = session_read_insert_idx(session); + + /* Manual sampling for periodic sessions is forbidden. */ + if (session->sample_freq_ns) + return -EINVAL; + + /* + * Must have at least two slots remaining in the ringbuffer to sample: one for + * the current sample, and one for a stop sample, since a stop command should + * always be acknowledged by taking a final sample and stopping the session. + */ + if (CIRC_SPACE_TO_END(insert_idx, extract_idx, session->ringbuf_slots) < 2) + return -EBUSY; + + session->sample_start_ns = ktime_get_raw_ns(); + session->user_data = user_data; + + /* TODO Calls to the FW interface will go here in later patches. */ + return 0; +} + +static int session_destroy(struct panthor_perf *perf, struct panthor_perf_session *session) +{ + session_put(session); + + return 0; +} + +static int session_teardown(struct panthor_perf *perf, struct panthor_perf_session *session) +{ + if (test_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state)) + return -EINVAL; + + if (!list_empty(&session->waiting)) + return -EBUSY; + + return session_destroy(perf, session); +} + +/** + * panthor_perf_session_teardown - Teardown the session associated with the @sid. + * @pfile: Open panthor file. + * @perf: Handle to the perf control structure. + * @sid: Session identifier. + * + * Destroys a stopped session where the last sample has been explicitly consumed + * or discarded. Active sessions will be ignored. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_session_teardown(struct panthor_file *pfile, struct panthor_perf *perf, u32 sid) +{ + int err; + struct panthor_perf_session *session; + + xa_lock(&perf->sessions); + session = __xa_store(&perf->sessions, sid, NULL, GFP_KERNEL); + + if (xa_is_err(session)) { + err = xa_err(session); + goto restore; + } + + if (session->pfile != pfile) { + err = -EINVAL; + goto restore; + } + + session_get(session); + xa_unlock(&perf->sessions); + + err = session_teardown(perf, session); + + session_put(session); + + return err; + +restore: + __xa_store(&perf->sessions, sid, session, GFP_KERNEL); + xa_unlock(&perf->sessions); + + return err; +} + +/** + * panthor_perf_session_start - Start sampling on a stopped session. + * @pfile: Open panthor file. + * @perf: Handle to the panthor perf control structure. + * @sid: Session identifier for the desired session. + * @user_data: An opaque value passed in from userspace. + * + * A session counts as stopped when it is created or when it is explicitly stopped after being + * started. Starting an active session is treated as a no-op. + * + * The @user_data parameter will be associated with all subsequent samples for a periodic + * sampling session and will be ignored for manual sampling ones in favor of the user data + * passed in the PERF_CONTROL.SAMPLE ioctl call. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_session_start(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data) +{ + struct panthor_perf_session *session = session_find(pfile, perf, sid); + int err; + + if (IS_ERR_OR_NULL(session)) + return IS_ERR(session) ? PTR_ERR(session) : -EINVAL; + + err = session_start(perf, session, user_data); + + session_put(session); + + return err; +} + +/** + * panthor_perf_session_stop - Stop sampling on an active session. + * @pfile: Open panthor file. + * @perf: Handle to the panthor perf control structure. + * @sid: Session identifier for the desired session. + * @user_data: An opaque value passed in from userspace. + * + * A session counts as active when it has been explicitly started via the PERF_CONTROL.START + * ioctl. Stopping a stopped session is treated as a no-op. + * + * To ensure data is not lost when sampling is stopping, there must always be at least one slot + * available for the final automatic sample, and the stop command will be rejected if there is not. + * + * The @user_data will always be associated with the final sample. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_session_stop(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data) +{ + struct panthor_perf_session *session = session_find(pfile, perf, sid); + int err; + + if (IS_ERR_OR_NULL(session)) + return IS_ERR(session) ? PTR_ERR(session) : -EINVAL; + + err = session_stop(perf, session, user_data); + + session_put(session); + + return err; +} + +/** + * panthor_perf_session_sample - Request a sample on a manual sampling session. + * @pfile: Open panthor file. + * @perf: Handle to the panthor perf control structure. + * @sid: Session identifier for the desired session. + * @user_data: An opaque value passed in from userspace. + * + * Only an active manual sampler is permitted to request samples directly. Failing to meet either + * of these conditions will cause the sampling request to be rejected. Requesting a manual sample + * with a full ringbuffer will see the request being rejected. + * + * The @user_data will always be unambiguously associated one-to-one with the resultant sample. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_session_sample(struct panthor_file *pfile, struct panthor_perf *perf, + u32 sid, u64 user_data) +{ + struct panthor_perf_session *session = session_find(pfile, perf, sid); + int err; + + if (IS_ERR_OR_NULL(session)) + return IS_ERR(session) ? PTR_ERR(session) : -EINVAL; + + err = session_sample(perf, session, user_data); + + session_put(session); + + return err; +} + +/** + * panthor_perf_session_destroy - Destroy a sampling session associated with the @pfile. + * @perf: Handle to the panthor perf control structure. + * @pfile: The file being closed. + * + * Must be called when the corresponding userspace process is destroyed and cannot close its + * own sessions. As such, we offer no guarantees about data delivery. + */ +void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_perf *perf) +{ + unsigned long sid; + struct panthor_perf_session *session; + + xa_for_each(&perf->sessions, sid, session) + { + if (session->pfile == pfile) { + session_destroy(perf, session); + xa_erase(&perf->sessions, sid); + } + } } /** @@ -146,10 +800,17 @@ void panthor_perf_unplug(struct panthor_device *ptdev) if (!perf) return; - if (!xa_empty(&perf->sessions)) + if (!xa_empty(&perf->sessions)) { + unsigned long sid; + struct panthor_perf_session *session; + drm_err(&ptdev->base, "Performance counter sessions active when unplugging the driver!"); + xa_for_each(&perf->sessions, sid, session) + session_destroy(perf, session); + } + xa_destroy(&perf->sessions); devm_kfree(ptdev->base.dev, ptdev->perf); diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h index 8a431431da6b..576d3ad46e6d 100644 --- a/include/uapi/drm/panthor_drm.h +++ b/include/uapi/drm/panthor_drm.h @@ -458,6 +458,12 @@ enum drm_panthor_perf_block_type { /** @DRM_PANTHOR_PERF_BLOCK_SHADER: A shader core counter block. */ DRM_PANTHOR_PERF_BLOCK_SHADER, + + /** @DRM_PANTHOR_PERF_BLOCK_LAST: Internal use only. */ + DRM_PANTHOR_PERF_BLOCK_LAST = DRM_PANTHOR_PERF_BLOCK_SHADER, + + /** @DRM_PANTHOR_PERF_BLOCK_MAX: Internal use only. */ + DRM_PANTHOR_PERF_BLOCK_MAX = DRM_PANTHOR_PERF_BLOCK_LAST + 1, }; /** @@ -1368,6 +1374,44 @@ struct drm_panthor_perf_control { __u64 pointer; }; +/** + * enum drm_panthor_perf_counter_set - The counter set to be requested from the hardware. + * + * The hardware supports a single performance counter set at a time, so requesting any set other + * than the primary may fail if another process is sampling at the same time. + * + * If in doubt, the primary counter set has the most commonly used counters and requires no + * additional permissions to open. + */ +enum drm_panthor_perf_counter_set { + /** + * @DRM_PANTHOR_PERF_SET_PRIMARY: The default set configured on the hardware. + * + * This is the only set for which all counters in all blocks are defined. + */ + DRM_PANTHOR_PERF_SET_PRIMARY, + + /** + * @DRM_PANTHOR_PERF_SET_SECONDARY: The secondary performance counter set. + * + * Some blocks may not have any defined counters for this set, and the block will + * have the UNAVAILABLE block state permanently set in the block header. + * + * Accessing this set requires the calling process to have the CAP_PERFMON capability. + */ + DRM_PANTHOR_PERF_SET_SECONDARY, + + /** + * @DRM_PANTHOR_PERF_SET_TERTIARY: The tertiary performance counter set. + * + * Some blocks may not have any defined counters for this set, and the block will have + * the UNAVAILABLE block state permanently set in the block header. Note that the + * tertiary set has the fewest defined counter blocks. + * + * Accessing this set requires the calling process to have the CAP_PERFMON capability. + */ + DRM_PANTHOR_PERF_SET_TERTIARY, +}; /** * struct drm_panthor_perf_cmd_setup - Arguments passed to DRM_PANTHOR_IOCTL_PERF_CONTROL @@ -1375,13 +1419,17 @@ struct drm_panthor_perf_control { */ struct drm_panthor_perf_cmd_setup { /** - * @block_set: Set of performance counter blocks. + * @block_set: Set of performance counter blocks, member of + * enum drm_panthor_perf_block_set. * * This is a global configuration and only one set can be active at a time. If * another client has already requested a counter set, any further requests * for a different counter set will fail and return an -EBUSY. * * If the requested set does not exist, the request will fail and return an -EINVAL. + * + * Some sets have additional requirements to be enabled, and the setup request will + * fail with an -EACCES if these requirements are not satisfied. */ __u8 block_set; From patchwork Wed Dec 11 16:50:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903947 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 69A14E77182 for ; Wed, 11 Dec 2024 16:51:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D635E10EBCE; Wed, 11 Dec 2024 16:51:32 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="W29RHsa1"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="W29RHsa1"; dkim-atps=neutral Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2040.outbound.protection.outlook.com [40.107.21.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id DA13C10EBB3 for ; Wed, 11 Dec 2024 16:51:28 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=JOIwpX1aIfrifIC1XWTtNlOxha6vKzKkFvY6cA1DO7OnYjHUKK/GWEExYZoRlSrSFlL+Lj0g67NxB+YLHMXT1fC9kBkK0pn4kv/gdvxxX3g/kN9dsciJkGHqMbvB6JyDPQMIyd69bc+3kOeKA8Nns/eje6kUb1UjhSX5Ts4m1ViO6R+fiptD1DWrV5vvqzZmg1dfERFTelzVUT24DFqpu7lL8NfOltEMGTlXe9UH1gajyy7DYHSDKnBasug0z3GA5P/qisizw4eNirIYAFsT7PnDT86GZWDGruDzlKzZYMm+RLJ1qVGRy+h0hoVv9jUP3JgQa7xMjBSF6G37U2oiPQ== ARC-Message-Signature: i=2; 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=xSnbtu7/4b0xcoVBcmxU4opQ6rHX/5VJgVS4QuzkGCY=; b=RndwGbBLiLBLk1yWSqbmcZU9t2Ci1V+B0N/YmQWpPZL3GYAmca4u8NSHFW1C6Whq5vPFUrzIoKIJlkmQYZY+/qndQusBntFw9DEAvuay+DV5LwrQgryiw8QStKAxPa1TDI9mCvn4zddDYUGwCku+COqounepUD7V/OYxlv4AnQXMeiO7tzDace7WkTHPb/YnGQWCu6stVVu0oGMmJbWy/oXUd5F9rk1r71Fuy28Ay9oRm546tRPbEX6w+ZVIn2c2D1Gf2ZsTH+Jt88CcnEbZzWcRyvsTuV19ua33lDYA58ZNklOpEDhP596j89IY1av5Op+6K5jxbDf2QLbgbMbRQQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xSnbtu7/4b0xcoVBcmxU4opQ6rHX/5VJgVS4QuzkGCY=; b=W29RHsa1JUnD8APJJU/Pkjdia1uxOQc7DwIFOYQAZKLBAUbQAQ9nd+8WeR4TY4/0f/h4Qk8E7eUjJbtLaEFmhsmtPRQHaEeLm19MWlo4dju9DOknENvoXCeLSejbVWNUMPmVO19KpN3HJFZofO0R6Q+VeIikGRrtugK2WmnwQ1k= Received: from DBBPR09CA0039.eurprd09.prod.outlook.com (2603:10a6:10:d4::27) by PAWPR08MB10212.eurprd08.prod.outlook.com (2603:10a6:102:369::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.19; Wed, 11 Dec 2024 16:51:18 +0000 Received: from DU2PEPF00028D03.eurprd03.prod.outlook.com (2603:10a6:10:d4:cafe::fc) by DBBPR09CA0039.outlook.office365.com (2603:10a6:10:d4::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DU2PEPF00028D03.mail.protection.outlook.com (10.167.242.187) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:18 +0000 Received: ("Tessian outbound 9c6259131e4d:v524"); Wed, 11 Dec 2024 16:51:17 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0cf303c8a12e35c1 X-TessianGatewayMetadata: Erkx3mfIPFDV+UBvGmTwpPGEsBZElLkAyVxmVk9GCqp67IqFZhyBnl7nr7Wtd+KfLBh9wZo4x4WfJ0cQpcU6Y77lJAy9IK5R1sENjUs4CqyBCZKuODKNakRtilROawAPJjHyMJxJjMBpcuOrrWdHKx8ItqW0PQqG/mmdd+CNBzU= X-CR-MTA-TID: 64aa7808 Received: from L1c19647b0b3f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F35F1243-C2CA-471D-9E3B-B6656E8F2F07.1; Wed, 11 Dec 2024 16:51:06 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id L1c19647b0b3f.1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:51:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jubFSn72R58paVuwGhmcbClcor13WMqYVkAg6jPoCa5ev0iT57hR2Hlvrtm0sm7MIBdlh57YHciHk/X+Uoe+S2OkMSdZsUFBd7Ywm6RDKQHmC+GugSmOIMSImeBVLQkEhDYnjwTaomQKyOEjPe5uWP9UalPLxWfR2ZiiGouK1q2MbXTWZRAwkF9tS0rNmJqTY8xTP49hmJDF2ztbir6iFWcryNdY8gTHvJAFHFtR73/gXnPbiBnoxjxswVcPV7LaLiLR7zhQjs2d6XIapbFo+b/qFbqWgRghkcZv+fh9wQSvXIAqH2yk6LVVRPeesUZ1tNwGFkJ+gDvUEJ+0YdVkVA== 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=xSnbtu7/4b0xcoVBcmxU4opQ6rHX/5VJgVS4QuzkGCY=; b=lM0R+/7a/OHkHzncTpjM/bPYM3Hvfk7B7cwHWEziVJxb2W6lx5W+wYDm2ChO7Sg4cZSARmAuTnQheGyFmZ7ZX261ueWRNX5YMUyOMsvxkDbEwDNbnSDVC3JIj++uONd3cSnDpK4+Ar4pMghpmyEK3qtp4qCEM0LQasbin0hfO1PkUXfTxfkX896vuhSCqjikW9hsc94jN0YLKl/hIx3phoXZnmxjypSkwQw8ns46YGXz8hkzRnS8h0pKPdHNDLBzK0MgXoIXJG/rfEahREKMoBOV8kTg3wQnfcM0Me+P2TdogE1Rth9uIHXXlsFJoh4b5fS9ERiKMo68BmS22YdZiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xSnbtu7/4b0xcoVBcmxU4opQ6rHX/5VJgVS4QuzkGCY=; b=W29RHsa1JUnD8APJJU/Pkjdia1uxOQc7DwIFOYQAZKLBAUbQAQ9nd+8WeR4TY4/0f/h4Qk8E7eUjJbtLaEFmhsmtPRQHaEeLm19MWlo4dju9DOknENvoXCeLSejbVWNUMPmVO19KpN3HJFZofO0R6Q+VeIikGRrtugK2WmnwQ1k= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:51:02 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:51:02 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 6/8] drm/panthor: Implement the counter sampler and sample handling Date: Wed, 11 Dec 2024 16:50:22 +0000 Message-Id: <20241211165024.490748-7-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO2P265CA0169.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::13) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8422:EE_|DU2PEPF00028D03:EE_|PAWPR08MB10212:EE_ X-MS-Office365-Filtering-Correlation-Id: 69fda95d-c9cd-4bfe-37e0-08dd1a0408b4 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: =?utf-8?q?TbXBvY4NYcQEe3tZo/2qC4?= =?utf-8?q?8fuLOrYa2ASuCZqRUQA15bEdSDo630nGN5ahTlsQroW9eONI2Ufa9odIoUcfOYqZA?= =?utf-8?q?L8IQ9O+Uzr9q/bw/bpfU7FPQH5GCKDm+WMhcG7Ox1xpoqP6gFwl/DplyCCm/Fp8bg?= =?utf-8?q?PX5Dc37cGeXqDQUIampxiM3ClHIVi3/A0qsTi2xdufqCNgpDjbIj4n27+b9tSiEGt?= =?utf-8?q?yBy5CuFnSrq7LLbmWPtzCYzmPOzsbjueNpzEf6yUB8aF3WJ8mQP/J1GaEtwkFasHz?= =?utf-8?q?c+C0lzz7BybwdksAvATmQAzijOrZiE7FKW66TSl7LF8Y+rvx+ZiZrlZAwKyOk0Fqq?= =?utf-8?q?HWS1UMUe4G+uI/6q/TDbBNTxyYYzZQL9n6hYp0cgrWAXwfdHGqwRDjr4aPU8vP+Lv?= =?utf-8?q?JC+RrPBGF7KKuwaKax3SFHACLPi62gBmWcaSSnlRw/8CMSYOdKSzjr3dOr1h+BUyh?= =?utf-8?q?ptq2GXsfKBndFf7WlkXmUX71Gq3uQxEmwSYHMbFcPz7Mc0z8B8sBXDwhwIkHtmt2u?= =?utf-8?q?D/VchbYpBIlbaLjIAJ6Db/TguPX1yck6+JDT0hEb+sy9IxIxnuAB03W8RlH1y7SPq?= =?utf-8?q?TXkjD/Yi94oZGGA4XQlOzkSY4CAYsQVSWxliwFiPQnyDVnBhsiIqiYCkqIsZSJ9J1?= =?utf-8?q?XYxuL2HxYXGr3tpozDFpbwagTR+KLd2s7iQ26+Ld8ClmH3l4WpPcM1oWdJG3O/a7h?= =?utf-8?q?TGNoEP99wFn7+oI8s2byr1rhHJXV/7KakFdbqgGGvGGYrhJyCeuXJrwIxpClROhWf?= =?utf-8?q?NJJ/NtjtM+cvSstnU4DT9FCaVdG1v0ICxqr1cezx8vR09Hx5ynhCyBClCFChIvXtM?= =?utf-8?q?BiOUbvzwunXNMRsIUoOaHFX6Yn2vtImXKv77aZuLQ/aNt/Hix7hLdC/HwQIaAd4+t?= =?utf-8?q?3zcx014vg6Z+ap2NtFI41BqofkqAW4/KHlx0aKmf9H4tRfebSixXPuyir8cyZVhy2?= =?utf-8?q?mIxfOmFSL3yo/TsQYMR+kSiK0q/x5lc90U4hG1vF3PftFV2G5hLQQxiXEtZGgiiVG?= =?utf-8?q?8uZcgoJFDZ0Zi+9L5fjuUhZczaAmCtwFva0VWeWW+iS8jwOyk46zQGZ1OU0bK15ec?= =?utf-8?q?QLzsJ8S/22XlzsCpK/1hkCX1DmpUr7Qu6Lo0foN6sZeQUFWQIuNgEIvpd1uxfMxJC?= =?utf-8?q?KPN9vSsm4SzEpfW9TfT+iZiETFcFZkx4B9kjBaxuHwhApPN1JQsGrMIk40RKc+hoE?= =?utf-8?q?Eh8EEqnWbeTX/KdwMKOpw0nzALWBgDIAuWi2/U1hu5lLY2y5Z1wDaOT8yrxkGRzs5?= =?utf-8?q?xOEjxKoK07y7722SXj6RyFx4AQgeqDmyF9IHSvFRGxaQ=3D=3D?= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU2PEPF00028D03.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7a7f4b6b-5fc6-4a01-43ff-08dd1a03ff01 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|35042699022|14060799003|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?dKn54slrK/JyyUD4vyQNZaSA1MFDGHJ?= =?utf-8?q?fI6riKYNC1AJIXUaGF01UrmKp6GNH0MHcTsl+kTSSgji/uVy22gKzFRawyE9snRWJ?= =?utf-8?q?08mZScuJvY/JOyF3nunBMlmSEsjP0jmmXZdltghWqtI+mRANNgdjMWvHsGLi9i5/F?= =?utf-8?q?y/w7Uzvo8Q0psqNdlPRJiwXln5Wv3QJWMXMtHXBGInfW7IRi7WC4snOMscog4ZouS?= =?utf-8?q?XzwWvrS2XlJFhtzQf8XMsNZ18aIff2IWMRdPTRJ4wKGOJ+Eva6zQg7Txh44go0jS/?= =?utf-8?q?KtMzpU/FXWK93VRwVfH1u90deb7dEe19sloH4OkDWFqA0hZNilVQ+eegoyjvDgUcF?= =?utf-8?q?GJQE9Jfb4MXrQ6+rRmg2JJtHRTR33v0/UUJSpYiVWC2m4duMy1ke3Z0+kTIGIXIbw?= =?utf-8?q?hRyQNr2S0HJQ+EEiclIUZVOJNlX5D3JIOFF0CWOIIoB5ikXBhVFfxa5GbAlCKe87S?= =?utf-8?q?UiemwvIbVI+Cjo2tyUTDuXDGhtzlwu7p9Z19+WzrCUOymZwmNKx6uydsAAA1sFB/J?= =?utf-8?q?pwDGLubyiU3BERS7vhtkwO5OUtzgD9aWet4/U5ZtQ3Sc0ktt/hN6Ykxrk8dLfB3d3?= =?utf-8?q?h4jn2JH7NqSrJb6RDsMRGnnEak1vagHJ/ei1Uj9q99h7updZU0Ilbh1oERzOPpgWp?= =?utf-8?q?HCHhXDO01FLSOoKYrRmR7DZhhr69e9dMmN0pF2K7UIHbfF0dEPHnUmLhHxN4XlWJB?= =?utf-8?q?rptCXSndMyGMHfaoEDfsa5iLvfyFq+pp4Qux4WPoKT2W3NRqA2ppRDDJhYz+PKN13?= =?utf-8?q?YY5udMTNCsNt+n1Ap2DiMqflDPTkRo8xRVikmX9Li5Te4MkZhdCiqp0/PTAYgvEnd?= =?utf-8?q?bf+64ozvLYMMneUxlt4evNhxhJhwSPQ7lu9+Bv/UKfTjIOhdwnUmmP1azTxCqI6ND?= =?utf-8?q?uaUf6Mckulcv7w7BjwbwER+d43WHkeI8TRpEPfPm391Bz3hbO3mD45P1PyvhxJWYb?= =?utf-8?q?/NLKOmm2hgJnmPhIlbnOBD1yXDd9Rou4XX97MonT5MtRA09cvsrZsdiMwdtuBYQ1V?= =?utf-8?q?FP8FnATWb1/UlNfDr9IelQfNWF6uLgoCjhhiCNE9ywEGDgZSzZ8/5RIYfmcg+gQcV?= =?utf-8?q?0IEQ9ISpefSa4LXJkVRasSehej+llQd0ubMHta9FMG4aT9qDoAKYIislE/1b1Ikzm?= =?utf-8?q?W2Gu6rkQicbPfUPBe3gRlkM9NBw3eealSjJSt4hlTmDze536rpuJWZKsTd3XKwHiO?= =?utf-8?q?7MP9KsD8OipcQ3KCCSV1vIFe9N7lMvnLmpYVUQjakSBp9O59E46EeQ7OLFKzntkU1?= =?utf-8?q?egg18iIYdr7lEhizeEePIdlFaAlnVj0CJMIVJnUKEh8DLrJyBRWeN9EnNbwEL6WJb?= =?utf-8?q?W1r5In9CukS5UMv5IGPXkyfqTzkmXPKnzNDX9WtrPbxDxT2AJ4XkTYnxZ4Vj9x8gk?= =?utf-8?q?dwZrAabxZkzfwYhoEGV4jz6PybToheNNg=3D=3D?= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(376014)(82310400026)(35042699022)(14060799003)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:18.4229 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69fda95d-c9cd-4bfe-37e0-08dd1a0408b4 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D03.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB10212 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Adrián Larumbe The sampler aggregates counter and set requests coming from userspace and mediates interactions with the FW interface, to ensure that user sessions cannot override the global configuration. From the top-level interface, the sampler supports two different types of samples: clearing samples and regular samples. Clearing samples are a special sample type that allow for the creation of a sampling baseline, to ensure that a session does not obtain counter data from before its creation. Upon receipt of a relevant interrupt, corresponding to one of the three relevant bits of the GLB_ACK register, the sampler takes any samples that occurred, and, based on the insert and extract indices, accumulates them to an internal storage buffer after zero-extending the counters from the 32-bit counters emitted by the hardware to 64-bit counters for internal accumulation. When the performance counters are enabled, the FW ensures no counter data is lost when entering and leaving non-counting regions by producing automatic samples that do not correspond to a GLB_REQ.PRFCNT_SAMPLE request. Such regions may be per hardware unit, such as when a shader core powers down, or global. Most of these events do not directly correspond to session sample requests, so any intermediary counter data must be stored into a temporary accumulation buffer. If there are sessions waiting for a sample, this accumulated buffer will be taken, and emitted for each waiting client. During this phase, information like the timestamps of sample request and sample emission, type of the counter block and block index annotations are added to the sample header and block headers. If no sessions are waiting for a sample, this accumulation buffer is kept until the next time a sample is requested. Special handling is needed for the PRFCNT_OVERFLOW interrupt, which is an indication that the internal sample handling rate was insufficient. The sampler also maintains a buffer descriptor indicating the structure of a firmware sample, since neither the firmware nor the hardware give any indication of the sample structure, only that it is composed out of three parts: - the metadata is an optional initial counter block on supporting firmware versions that contains a single counter, indicating the reason a sample was taken when entering global non-counting regions. This is used to provide coarse-grained information about why a sample was taken to userspace, to help userspace interpret variations in counter magnitude. - the firmware component of the sample is composed out of a global firmware counter block on supporting firmware versions. - the hardware component is the most sizeable of the three and contains a block of counters for each of the underlying hardware resources. It has a fixed structure that is described in the architecture specification, and contains the command stream hardware block(s), the tiler block(s), the MMU and L2 blocks (collectively named the memsys blocks) and the shader core blocks, in that order. The structure of this buffer changes based on the firmware and hardware combination, but is constant on a single system. Signed-off-by: Adrián Larumbe Co-developed-by: Lukas Zapolskas Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/panthor_fw.c | 5 + drivers/gpu/drm/panthor/panthor_fw.h | 9 +- drivers/gpu/drm/panthor/panthor_perf.c | 882 ++++++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_perf.h | 2 + include/uapi/drm/panthor_drm.h | 5 +- 5 files changed, 892 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c index e9530d1d9781..cd68870ced18 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.c +++ b/drivers/gpu/drm/panthor/panthor_fw.c @@ -1000,9 +1000,12 @@ static void panthor_fw_init_global_iface(struct panthor_device *ptdev) /* Enable interrupts we care about. */ glb_iface->input->ack_irq_mask = GLB_CFG_ALLOC_EN | + GLB_PERFCNT_SAMPLE | GLB_PING | GLB_CFG_PROGRESS_TIMER | GLB_CFG_POWEROFF_TIMER | + GLB_PERFCNT_THRESHOLD | + GLB_PERFCNT_OVERFLOW | GLB_IDLE_EN | GLB_IDLE; @@ -1031,6 +1034,8 @@ static void panthor_job_irq_handler(struct panthor_device *ptdev, u32 status) return; panthor_sched_report_fw_events(ptdev, status); + + panthor_perf_report_irq(ptdev, status); } PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler); diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h index db10358e24bb..7ed34d2de8b4 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.h +++ b/drivers/gpu/drm/panthor/panthor_fw.h @@ -199,9 +199,10 @@ struct panthor_fw_global_control_iface { u32 group_num; u32 group_stride; #define GLB_PERFCNT_FW_SIZE(x) ((((x) >> 16) << 8)) +#define GLB_PERFCNT_HW_SIZE(x) (((x) & GENMASK(15, 0)) << 8) u32 perfcnt_size; u32 instr_features; -#define PERFCNT_FEATURES_MD_SIZE(x) ((x) & GENMASK(3, 0)) +#define PERFCNT_FEATURES_MD_SIZE(x) (((x) & GENMASK(3, 0)) << 8) u32 perfcnt_features; }; @@ -211,7 +212,7 @@ struct panthor_fw_global_input_iface { #define GLB_CFG_ALLOC_EN BIT(2) #define GLB_CFG_POWEROFF_TIMER BIT(3) #define GLB_PROTM_ENTER BIT(4) -#define GLB_PERFCNT_EN BIT(5) +#define GLB_PERFCNT_ENABLE BIT(5) #define GLB_PERFCNT_SAMPLE BIT(6) #define GLB_COUNTER_EN BIT(7) #define GLB_PING BIT(8) @@ -234,7 +235,6 @@ struct panthor_fw_global_input_iface { u32 doorbell_req; u32 reserved1; u32 progress_timer; - #define GLB_TIMER_VAL(x) ((x) & GENMASK(30, 0)) #define GLB_TIMER_SOURCE_GPU_COUNTER BIT(31) u32 poweroff_timer; @@ -244,6 +244,9 @@ struct panthor_fw_global_input_iface { u64 perfcnt_base; u32 perfcnt_extract; u32 reserved3[3]; +#define GLB_PRFCNT_CONFIG_SIZE(x) ((x) & GENMASK(7, 0)) +#define GLB_PRFCNT_CONFIG_SET(x) (((x) & GENMASK(1, 0)) << 8) +#define GLB_PRFCNT_METADATA_ENABLE BIT(10) u32 perfcnt_config; u32 perfcnt_csg_select; u32 perfcnt_fw_enable; diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c index 42d8b6f8c45d..d62d97c448da 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.c +++ b/drivers/gpu/drm/panthor/panthor_perf.c @@ -15,7 +15,9 @@ #include "panthor_device.h" #include "panthor_fw.h" +#include "panthor_gem.h" #include "panthor_gpu.h" +#include "panthor_mmu.h" #include "panthor_perf.h" #include "panthor_regs.h" @@ -26,6 +28,41 @@ */ #define PANTHOR_PERF_EM_BITS (BITS_PER_TYPE(u64) * 2) +/** + * PANTHOR_PERF_FW_RINGBUF_SLOTS - Number of slots allocated for individual samples when configuring + * the performance counter ring buffer to firmware. This can be + * used to reduce memory consumption on low memory systems. + */ +#define PANTHOR_PERF_FW_RINGBUF_SLOTS (32) + +/** + * PANTHOR_CTR_TIMESTAMP_LO - The first architecturally mandated counter of every block type + * contains the low 32-bits of the TIMESTAMP value. + */ +#define PANTHOR_CTR_TIMESTAMP_LO (0) + +/** + * PANTHOR_CTR_TIMESTAMP_HI - The register offset containinig the high 32-bits of the TIMESTAMP + * value. + */ +#define PANTHOR_CTR_TIMESTAMP_HI (1) + +/** + * PANTHOR_CTR_PRFCNT_EN - The register offset containing the enable mask for the enabled counters + * that were written to memory. + */ +#define PANTHOR_CTR_PRFCNT_EN (2) + +/** + * PANTHOR_HEADER_COUNTERS - The first four counters of every block type are architecturally + * defined to be equivalent. The fourth counter is always reserved, + * and should be zero and as such, does not have a separate define. + * + * These are the only four counters that are the same between different + * blocks and are consistent between different architectures. + */ +#define PANTHOR_HEADER_COUNTERS (4) + /** * enum panthor_perf_session_state - Session state bits. */ @@ -158,6 +195,135 @@ struct panthor_perf_session { struct kref ref; }; +struct panthor_perf_buffer_descriptor { + /** + * @block_size: The size of a single block in the FW ring buffer, equal to + * sizeof(u32) * counters_per_block. + */ + size_t block_size; + + /** + * @buffer_size: The total size of the buffer, equal to (#hardware blocks + + * #firmware blocks) * block_size. + */ + size_t buffer_size; + + /** + * @available_blocks: Bitmask indicating the blocks supported by the hardware and firmware + * combination. Note that this can also include blocks that will not + * be exposed to the user. + */ + DECLARE_BITMAP(available_blocks, DRM_PANTHOR_PERF_BLOCK_MAX); + struct { + /** @offset: Starting offset of a block of type @type in the FW ringbuffer. */ + size_t offset; + + /** @type: Type of the blocks between @blocks[i].offset and @blocks[i+1].offset. */ + enum drm_panthor_perf_block_type type; + + /** @block_count: Number of blocks of the given @type, starting at @offset. */ + size_t block_count; + } blocks[DRM_PANTHOR_PERF_BLOCK_MAX]; +}; + + +/** + * struct panthor_perf_sampler - Interface to de-multiplex firmware interaction and handle + * global interactions. + */ +struct panthor_perf_sampler { + /** @sample_requested: A sample has been requested. */ + bool sample_requested; + + /** + * @last_ack: Temporarily storing the last GLB_ACK status. Without storing this data, + * we do not know whether a toggle bit has been handled. + */ + u32 last_ack; + + /** + * @enabled_clients: The number of clients concurrently requesting samples. To ensure that + * one client cannot deny samples to another, we must ensure that clients + * are effectively reference counted. + */ + atomic_t enabled_clients; + + /** + * @sample_handled: Synchronization point between the interrupt bottom half and the + * main sampler interface. Must be re-armed solely on a new request + * coming to the sampler. + */ + struct completion sample_handled; + + /** @rb: Kernel BO in the FW AS containing the sample ringbuffer. */ + struct panthor_kernel_bo *rb; + + /** + * @sample_size: The size of a single sample in the FW ringbuffer. This is computed using + * the hardware configuration according to the architecture specification, + * and cross-validated against the sample size reported by FW to ensure + * a consistent view of the buffer size. + */ + size_t sample_size; + + /** + * @sample_slots: Number of slots for samples in the FW ringbuffer. Could be static, + * but may be useful to customize for low-memory devices. + */ + size_t sample_slots; + + /** + * @config_lock: Lock serializing changes to the global counter configuration, including + * requested counter set and the counters themselves. + */ + struct mutex config_lock; + + /** + * @ems: List of enable maps of the active sessions. When removing a session, the number + * of requested counters may decrease, and the union of enable masks from the multiple + * sessions does not provide sufficient information to reconstruct the previous + * enable mask. + */ + struct list_head ems; + + /** @em: Combined enable mask for all of the active sessions. */ + struct panthor_perf_enable_masks *em; + + /** + * @desc: Buffer descriptor for a sample in the FW ringbuffer. Note that this buffer + * at current time does some interesting things with the zeroth block type. On + * newer FW revisions, the first counter block of the sample is the METADATA block, + * which contains a single value indicating the reason the sample was taken (if + * any). This block must not be exposed to userspace, as userspace does not + * have sufficient context to interpret it. As such, this block type is not + * added to the uAPI, but we still use it in the kernel. + */ + struct panthor_perf_buffer_descriptor desc; + + /** + * @sample: Pointer to an upscaled and annotated sample that may be emitted to userspace. + * This is used both as an intermediate buffer to do the zero-extension of the + * 32-bit counters to 64-bits and as a storage buffer in case the sampler + * requests an additional sample that was not requested by any of the top-level + * sessions (for instance, when changing the enable masks). + */ + u8 *sample; + + /** @sampler_lock: Lock used to guard the list of sessions requesting samples. */ + struct mutex sampler_lock; + + /** @sampler_list: List of sessions requesting samples. */ + struct list_head sampler_list; + + /** @set_config: The set that will be configured onto the hardware. */ + u8 set_config; + + /** + * @ptdev: Backpointer to the Panthor device, needed to ring the global doorbell and + * interface with FW. + */ + struct panthor_device *ptdev; +}; struct panthor_perf { /** @@ -175,6 +341,9 @@ struct panthor_perf { * @sessions: Global map of sessions, accessed by their ID. */ struct xarray sessions; + + /** @sampler: FW control interface. */ + struct panthor_perf_sampler sampler; }; /** @@ -247,6 +416,23 @@ static struct panthor_perf_enable_masks *panthor_perf_create_em(struct drm_panth return em; } +static void panthor_perf_em_add(struct panthor_perf_enable_masks *dst_em, + const struct panthor_perf_enable_masks *const src_em) +{ + size_t i = 0; + + for (i = DRM_PANTHOR_PERF_BLOCK_FW; i <= DRM_PANTHOR_PERF_BLOCK_LAST; i++) + bitmap_or(dst_em->mask[i], dst_em->mask[i], src_em->mask[i], PANTHOR_PERF_EM_BITS); +} + +static void panthor_perf_em_zero(struct panthor_perf_enable_masks *em) +{ + size_t i = 0; + + for (i = DRM_PANTHOR_PERF_BLOCK_FW; i <= DRM_PANTHOR_PERF_BLOCK_LAST; i++) + bitmap_zero(em->mask[i], PANTHOR_PERF_EM_BITS); +} + static void panthor_perf_destroy_em_kref(struct kref *em_kref) { struct panthor_perf_enable_masks *em = container_of(em_kref, typeof(*em), refs); @@ -270,6 +456,12 @@ static u32 session_read_extract_idx(struct panthor_perf_session *session) return smp_load_acquire(session->extract_idx); } +static void session_write_insert_idx(struct panthor_perf_session *session, u32 idx) +{ + /* Userspace needs the insert index to know where to look for the sample. */ + smp_store_release(session->insert_idx, idx); +} + static u32 session_read_insert_idx(struct panthor_perf_session *session) { return *session->insert_idx; @@ -349,6 +541,70 @@ static struct panthor_perf_session *session_find(struct panthor_file *pfile, return session; } +static u32 compress_enable_mask(unsigned long *const src) +{ + size_t i; + u32 result = 0; + unsigned long clump; + + for_each_set_clump8(i, clump, src, PANTHOR_PERF_EM_BITS) { + const unsigned long shift = div_u64(i, 4); + + result |= !!(clump & GENMASK(3, 0)) << shift; + result |= !!(clump & GENMASK(7, 4)) << (shift + 1); + } + + return result; +} + +static void expand_enable_mask(u32 em, unsigned long *const dst) +{ + size_t i; + DECLARE_BITMAP(emb, BITS_PER_TYPE(u32)); + + bitmap_from_arr32(emb, &em, BITS_PER_TYPE(u32)); + + for_each_set_bit(i, emb, BITS_PER_TYPE(u32)) + bitmap_set(dst, i * 4, 4); +} + +/** + * panthor_perf_block_data - Identify the block index and type based on the offset. + * + * @desc: FW buffer descriptor. + * @offset: The current offset being examined. + * @idx: Pointer to an output index. + * @type: Pointer to an output block type. + * + * To disambiguate different types of blocks as well as different blocks of the same type, + * the offset into the FW ringbuffer is used to uniquely identify the block being considered. + * + * In the future, this is a good time to identify whether a block will be empty, + * allowing us to short-circuit its processing after emitting header information. + */ +static void panthor_perf_block_data(struct panthor_perf_buffer_descriptor *const desc, + size_t offset, u32 *idx, enum drm_panthor_perf_block_type *type) +{ + unsigned long id; + + for_each_set_bit(id, desc->available_blocks, DRM_PANTHOR_PERF_BLOCK_LAST) { + const size_t block_start = desc->blocks[id].offset; + const size_t block_count = desc->blocks[id].block_count; + const size_t block_end = desc->blocks[id].offset + + desc->block_size * block_count; + + if (!block_count) + continue; + + if ((offset >= block_start) && (offset < block_end)) { + *type = desc->blocks[id].type; + *idx = div_u64(offset - desc->blocks[id].offset, desc->block_size); + + return; + } + } +} + static size_t session_get_max_sample_size(const struct drm_panthor_perf_info *const info) { const size_t block_size = get_annotated_block_size(info->counters_per_block); @@ -358,6 +614,520 @@ static size_t session_get_max_sample_size(const struct drm_panthor_perf_info *co return sizeof(struct drm_panthor_perf_sample_header) + (block_size * block_nr); } +static u32 panthor_perf_handle_sample(struct panthor_device *ptdev, u32 extract_idx, u32 insert_idx) +{ + struct panthor_perf *perf = ptdev->perf; + struct panthor_perf_sampler *sampler = &ptdev->perf->sampler; + const size_t ann_block_size = + get_annotated_block_size(ptdev->perf_info.counters_per_block); + u32 i; + + for (i = extract_idx; i != insert_idx; i = (i + 1) % sampler->sample_slots) { + u8 *fw_sample = (u8 *)sampler->rb->kmap + i * sampler->sample_size; + + for (size_t fw_off = 0, ann_off = sizeof(struct drm_panthor_perf_sample_header); + fw_off < sampler->desc.buffer_size; + fw_off += sampler->desc.block_size) + + { + u32 idx; + enum drm_panthor_perf_block_type type; + DECLARE_BITMAP(expanded_em, PANTHOR_PERF_EM_BITS); + struct panthor_perf_counter_block *blk = + (typeof(blk))(perf->sampler.sample + ann_off); + const u32 prfcnt_en = blk->counters[PANTHOR_CTR_PRFCNT_EN]; + + panthor_perf_block_data(&sampler->desc, fw_off, &idx, &type); + + /** + * TODO Data from the metadata block must be used to populate the + * block state information. + */ + if (type == DRM_PANTHOR_PERF_BLOCK_METADATA) + continue; + + expand_enable_mask(prfcnt_en, expanded_em); + + blk->header = (struct drm_panthor_perf_block_header) { + .clock = 0, + .block_idx = idx, + .block_type = type, + .block_states = DRM_PANTHOR_PERF_BLOCK_STATE_UNKNOWN + }; + bitmap_to_arr64(blk->header.enable_mask, expanded_em, PANTHOR_PERF_EM_BITS); + + u32 *block = (u32 *)(fw_sample + fw_off); + + /* + * The four header counters must be treated differently, because they are + * not additive. For the fourth, the assignment does not matter, as it + * is reserved and should be zero. + */ + blk->counters[PANTHOR_CTR_TIMESTAMP_LO] = block[PANTHOR_CTR_TIMESTAMP_LO]; + blk->counters[PANTHOR_CTR_TIMESTAMP_HI] = block[PANTHOR_CTR_TIMESTAMP_HI]; + blk->counters[PANTHOR_CTR_PRFCNT_EN] = block[PANTHOR_CTR_PRFCNT_EN]; + + for (size_t k = PANTHOR_HEADER_COUNTERS; + k < ptdev->perf_info.counters_per_block; + k++) + blk->counters[k] += block[k]; + + ann_off += ann_block_size; + } + } + + return i; +} + +static size_t panthor_perf_get_fw_reported_size(struct panthor_device *ptdev) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev); + + size_t fw_size = GLB_PERFCNT_FW_SIZE(glb_iface->control->perfcnt_size); + size_t hw_size = GLB_PERFCNT_HW_SIZE(glb_iface->control->perfcnt_size); + size_t md_size = PERFCNT_FEATURES_MD_SIZE(glb_iface->control->perfcnt_features); + + return md_size + fw_size + hw_size; +} + +#define PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, typ, blk_count, offset) \ + ({ \ + (desc)->blocks[(typ)].type = (typ); \ + (desc)->blocks[(typ)].offset = (offset); \ + (desc)->blocks[(typ)].block_count = (blk_count); \ + if ((blk_count)) \ + set_bit((typ), (desc)->available_blocks); \ + (offset) + ((desc)->block_size) * (blk_count); \ + }) + +static int panthor_perf_setup_fw_buffer_desc(struct panthor_device *ptdev, + struct panthor_perf_sampler *sampler) +{ + const struct drm_panthor_perf_info *const info = &ptdev->perf_info; + const size_t block_size = info->counters_per_block * sizeof(u32); + struct panthor_perf_buffer_descriptor *desc = &sampler->desc; + const size_t fw_sample_size = panthor_perf_get_fw_reported_size(ptdev); + size_t offset = 0; + + desc->block_size = block_size; + + for (enum drm_panthor_perf_block_type type = 0; type < DRM_PANTHOR_PERF_BLOCK_MAX; type++) { + switch (type) { + case DRM_PANTHOR_PERF_BLOCK_METADATA: + if (info->flags & DRM_PANTHOR_PERF_BLOCK_STATES_SUPPORT) + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, + DRM_PANTHOR_PERF_BLOCK_METADATA, 1, offset); + break; + case DRM_PANTHOR_PERF_BLOCK_FW: + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, type, info->fw_blocks, + offset); + break; + case DRM_PANTHOR_PERF_BLOCK_CSG: + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, type, info->csg_blocks, + offset); + break; + case DRM_PANTHOR_PERF_BLOCK_CSHW: + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, type, info->cshw_blocks, + offset); + break; + case DRM_PANTHOR_PERF_BLOCK_TILER: + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, type, info->tiler_blocks, + offset); + break; + case DRM_PANTHOR_PERF_BLOCK_MEMSYS: + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, type, info->memsys_blocks, + offset); + break; + case DRM_PANTHOR_PERF_BLOCK_SHADER: + offset = PANTHOR_PERF_SET_BLOCK_DESC_DATA(desc, type, info->shader_blocks, + offset); + break; + case DRM_PANTHOR_PERF_BLOCK_MAX: + drm_WARN_ON_ONCE(&ptdev->base, + "DRM_PANTHOR_PERF_BLOCK_MAX should be unreachable!"); + break; + } + } + + /* Computed size is not the same as the reported size, so we should not proceed in + * initializing the sampling session. + */ + if (offset != fw_sample_size) + return -EINVAL; + + desc->buffer_size = offset; + + return 0; +} + +static int panthor_perf_fw_stop_sampling(struct panthor_device *ptdev) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev); + u32 acked; + int ret; + + if (~READ_ONCE(glb_iface->input->req) & GLB_PERFCNT_ENABLE) + return 0; + + panthor_fw_update_reqs(glb_iface, req, 0, GLB_PERFCNT_ENABLE); + gpu_write(ptdev, CSF_DOORBELL(CSF_GLB_DOORBELL_ID), 1); + ret = panthor_fw_glb_wait_acks(ptdev, GLB_PERFCNT_ENABLE, &acked, 100); + if (ret) + drm_warn(&ptdev->base, "Could not disable performance counters"); + + return ret; +} + +static int panthor_perf_fw_start_sampling(struct panthor_device *ptdev) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev); + u32 acked; + int ret; + + if (READ_ONCE(glb_iface->input->req) & GLB_PERFCNT_ENABLE) + return 0; + + panthor_fw_update_reqs(glb_iface, req, GLB_PERFCNT_ENABLE, GLB_PERFCNT_ENABLE); + gpu_write(ptdev, CSF_DOORBELL(CSF_GLB_DOORBELL_ID), 1); + ret = panthor_fw_glb_wait_acks(ptdev, GLB_PERFCNT_ENABLE, &acked, 100); + if (ret) + drm_warn(&ptdev->base, "Could not enable performance counters"); + + return ret; +} + +static void panthor_perf_fw_write_em(struct panthor_perf_sampler *sampler, + struct panthor_perf_enable_masks *em) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(sampler->ptdev); + u32 perfcnt_config; + + glb_iface->input->perfcnt_csf_enable = + compress_enable_mask(em->mask[DRM_PANTHOR_PERF_BLOCK_CSHW]); + glb_iface->input->perfcnt_shader_enable = + compress_enable_mask(em->mask[DRM_PANTHOR_PERF_BLOCK_SHADER]); + glb_iface->input->perfcnt_mmu_l2_enable = + compress_enable_mask(em->mask[DRM_PANTHOR_PERF_BLOCK_MEMSYS]); + glb_iface->input->perfcnt_tiler_enable = + compress_enable_mask(em->mask[DRM_PANTHOR_PERF_BLOCK_TILER]); + glb_iface->input->perfcnt_fw_enable = + compress_enable_mask(em->mask[DRM_PANTHOR_PERF_BLOCK_FW]); + glb_iface->input->perfcnt_csg_enable = + compress_enable_mask(em->mask[DRM_PANTHOR_PERF_BLOCK_CSG]); + + perfcnt_config = GLB_PRFCNT_CONFIG_SIZE(PANTHOR_PERF_FW_RINGBUF_SLOTS); + perfcnt_config |= GLB_PRFCNT_CONFIG_SET(sampler->set_config); + glb_iface->input->perfcnt_config = perfcnt_config; + + /** + * The spec mandates that the host zero the PRFCNT_EXTRACT register before an enable + * operation, and each (re-)enable will require an enable-disable pair to program + * the new changes onto the FW interface. + */ + WRITE_ONCE(glb_iface->input->perfcnt_extract, 0); +} + +static void session_populate_sample_header(struct panthor_perf_session *session, + struct drm_panthor_perf_sample_header *hdr) +{ + hdr->block_set = 0; + hdr->user_data = session->user_data; + hdr->timestamp_start_ns = session->sample_start_ns; + /** + * TODO This should be changed to use the GPU clocks and the TIMESTAMP register, + * when support is added. + */ + hdr->timestamp_end_ns = ktime_get_raw_ns(); +} + +/** + * session_patch_sample - Update the PRFCNT_EN header counter and the counters exposed to the + * userspace client to only contain requested counters. + * + * @ptdev: Panthor device + * @session: Perf session + * @sample: Starting offset of the sample in the userspace mapping. + * + * The hardware supports counter selection at the granularity of 1 bit per 4 counters, and there + * is a single global FW frontend to program the counter requests from multiple sessions. This may + * lead to a large disparity between the requested and provided counters for an individual client. + * To remove this cross-talk, we patch out the counters that have not been requested by this + * session and update the PRFCNT_EN, the header counter containing a bitmask of enabled counters, + * accordingly. + */ +static void session_patch_sample(struct panthor_device *ptdev, + struct panthor_perf_session *session, u8 *sample) +{ + const struct drm_panthor_perf_info *const perf_info = &ptdev->perf_info; + + const size_t block_size = get_annotated_block_size(perf_info->counters_per_block); + const size_t sample_size = session_get_max_sample_size(perf_info); + + for (size_t i = 0; i < sample_size; i += block_size) { + size_t ctr_idx; + DECLARE_BITMAP(em_diff, PANTHOR_PERF_EM_BITS); + struct panthor_perf_counter_block *blk = (typeof(blk))(sample + block_size); + enum drm_panthor_perf_block_type type = blk->header.block_type; + unsigned long *blk_em = session->enabled_counters->mask[type]; + + bitmap_from_arr64(em_diff, blk->header.enable_mask, PANTHOR_PERF_EM_BITS); + + bitmap_andnot(em_diff, em_diff, blk_em, PANTHOR_PERF_EM_BITS); + + for_each_set_bit(ctr_idx, em_diff, PANTHOR_PERF_EM_BITS) + blk->counters[ctr_idx] = 0; + + bitmap_to_arr64(blk->header.enable_mask, blk_em, PANTHOR_PERF_EM_BITS); + } +} + +static int session_copy_sample(struct panthor_device *ptdev, + struct panthor_perf_session *session) +{ + struct panthor_perf *perf = ptdev->perf; + const size_t sample_size = session_get_max_sample_size(&ptdev->perf_info); + const u32 insert_idx = session_read_insert_idx(session); + const u32 extract_idx = session_read_extract_idx(session); + u8 *new_sample; + + if (!CIRC_SPACE_TO_END(insert_idx, extract_idx, session->ringbuf_slots)) + return -ENOSPC; + + new_sample = session->samples + extract_idx * sample_size; + + memcpy(new_sample, perf->sampler.sample, sample_size); + + session_populate_sample_header(session, + (struct drm_panthor_perf_sample_header *)new_sample); + + session_patch_sample(ptdev, session, new_sample + + sizeof(struct drm_panthor_perf_sample_header)); + + session_write_insert_idx(session, (insert_idx + 1) % session->ringbuf_slots); + + /* Since we are about to notify userspace, we must ensure that all changes to memory + * are visible. + */ + wmb(); + + eventfd_signal(session->eventfd); + + return 0; +} + +#define PERFCNT_IRQS (GLB_PERFCNT_OVERFLOW | GLB_PERFCNT_SAMPLE | GLB_PERFCNT_THRESHOLD) + +void panthor_perf_report_irq(struct panthor_device *ptdev, u32 status) +{ + struct panthor_perf *const perf = ptdev->perf; + struct panthor_perf_sampler *sampler; + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev); + + if (!(status & JOB_INT_GLOBAL_IF)) + return; + + if (!perf) + return; + + sampler = &perf->sampler; + + /* TODO This needs locking. */ + const u32 ack = READ_ONCE(glb_iface->output->ack); + const u32 fw_events = sampler->last_ack ^ ack; + + sampler->last_ack = ack; + + if (!(fw_events & PERFCNT_IRQS)) + return; + + /* TODO Fix up the error handling for overflow. */ + if (fw_events & GLB_PERFCNT_OVERFLOW) + return; + + if (fw_events & (GLB_PERFCNT_SAMPLE | GLB_PERFCNT_THRESHOLD)) { + const u32 extract_idx = READ_ONCE(glb_iface->input->perfcnt_extract); + const u32 insert_idx = READ_ONCE(glb_iface->output->perfcnt_insert); + + WRITE_ONCE(glb_iface->input->perfcnt_extract, + panthor_perf_handle_sample(ptdev, extract_idx, insert_idx)); + } + + scoped_guard(mutex, &sampler->sampler_lock) + { + struct list_head *pos, *temp; + + list_for_each_safe(pos, temp, &sampler->sampler_list) { + struct panthor_perf_session *session = list_entry(pos, + struct panthor_perf_session, waiting); + + session_copy_sample(ptdev, session); + list_del_init(pos); + + session_put(session); + } + } + + memset(sampler->sample, 0, session_get_max_sample_size(&ptdev->perf_info)); + sampler->sample_requested = false; + complete(&sampler->sample_handled); +} + + +static int panthor_perf_sampler_init(struct panthor_perf_sampler *sampler, + struct panthor_device *ptdev) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev); + struct panthor_kernel_bo *bo; + u8 *sample; + int ret; + + ret = panthor_perf_setup_fw_buffer_desc(ptdev, sampler); + if (ret) { + drm_err(&ptdev->base, + "Failed to setup descriptor for FW ring buffer, err = %d", ret); + return ret; + } + + bo = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev), + sampler->desc.buffer_size * PANTHOR_PERF_FW_RINGBUF_SLOTS, + DRM_PANTHOR_BO_NO_MMAP, + DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC | DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED, + PANTHOR_VM_KERNEL_AUTO_VA); + + if (IS_ERR_OR_NULL(bo)) + return IS_ERR(bo) ? PTR_ERR(bo) : -ENOMEM; + + ret = panthor_kernel_bo_vmap(bo); + if (ret) + goto cleanup_bo; + + sample = devm_kzalloc(ptdev->base.dev, + session_get_max_sample_size(&ptdev->perf_info), GFP_KERNEL); + if (ZERO_OR_NULL_PTR(sample)) { + ret = -ENOMEM; + goto cleanup_vmap; + } + + glb_iface->input->perfcnt_as = panthor_vm_as(panthor_fw_vm(ptdev)); + glb_iface->input->perfcnt_base = panthor_kernel_bo_gpuva(bo); + glb_iface->input->perfcnt_extract = 0; + glb_iface->input->perfcnt_csg_select = GENMASK(glb_iface->control->group_num, 0); + + sampler->rb = bo; + sampler->sample = sample; + sampler->sample_slots = PANTHOR_PERF_FW_RINGBUF_SLOTS; + + sampler->em = panthor_perf_em_new(); + + mutex_init(&sampler->sampler_lock); + mutex_init(&sampler->config_lock); + INIT_LIST_HEAD(&sampler->sampler_list); + INIT_LIST_HEAD(&sampler->ems); + init_completion(&sampler->sample_handled); + + sampler->ptdev = ptdev; + + return 0; + +cleanup_vmap: + panthor_kernel_bo_vunmap(bo); + +cleanup_bo: + panthor_kernel_bo_destroy(bo); + + return ret; +} + +static void panthor_perf_sampler_term(struct panthor_perf_sampler *sampler) +{ + int ret; + + if (sampler->sample_requested) + wait_for_completion_killable(&sampler->sample_handled); + + panthor_perf_fw_write_em(sampler, &(struct panthor_perf_enable_masks) {}); + + ret = panthor_perf_fw_stop_sampling(sampler->ptdev); + if (ret) + drm_warn_once(&sampler->ptdev->base, "Sampler termination failed, ret = %d", ret); + + devm_kfree(sampler->ptdev->base.dev, sampler->sample); + + panthor_kernel_bo_destroy(sampler->rb); +} + +static int panthor_perf_sampler_add(struct panthor_perf_sampler *sampler, + struct panthor_perf_enable_masks *const new_em, + u8 set) +{ + int ret = 0; + + guard(mutex)(&sampler->config_lock); + + /* Early check for whether a new set can be configured. */ + if (!atomic_read(&sampler->enabled_clients)) + sampler->set_config = set; + else + if (sampler->set_config != set) + return -EBUSY; + + kref_get(&new_em->refs); + list_add_tail(&sampler->ems, &new_em->link); + + panthor_perf_em_add(sampler->em, new_em); + pm_runtime_get_sync(sampler->ptdev->base.dev); + + if (atomic_read(&sampler->enabled_clients)) { + ret = panthor_perf_fw_stop_sampling(sampler->ptdev); + if (ret) + return ret; + } + + panthor_perf_fw_write_em(sampler, sampler->em); + + ret = panthor_perf_fw_start_sampling(sampler->ptdev); + if (ret) + return ret; + + atomic_inc(&sampler->enabled_clients); + + return 0; +} + +static int panthor_perf_sampler_remove(struct panthor_perf_sampler *sampler, + struct panthor_perf_enable_masks *session_em) +{ + int ret; + struct list_head *em_node; + + guard(mutex)(&sampler->config_lock); + + list_del_init(&session_em->link); + kref_put(&session_em->refs, panthor_perf_destroy_em_kref); + + panthor_perf_em_zero(sampler->em); + list_for_each(em_node, &sampler->ems) + { + struct panthor_perf_enable_masks *curr_em = + container_of(em_node, typeof(*curr_em), link); + + panthor_perf_em_add(sampler->em, curr_em); + } + + ret = panthor_perf_fw_stop_sampling(sampler->ptdev); + if (ret) + return ret; + + atomic_dec(&sampler->enabled_clients); + pm_runtime_put_sync(sampler->ptdev->base.dev); + + panthor_perf_fw_write_em(sampler, sampler->em); + + if (atomic_read(&sampler->enabled_clients)) + return panthor_perf_fw_start_sampling(sampler->ptdev); + return 0; +} + /** * panthor_perf_init - Initialize the performance counter subsystem. * @ptdev: Panthor device @@ -370,6 +1140,7 @@ static size_t session_get_max_sample_size(const struct drm_panthor_perf_info *co int panthor_perf_init(struct panthor_device *ptdev) { struct panthor_perf *perf; + int ret; if (!ptdev) return -EINVAL; @@ -386,12 +1157,93 @@ int panthor_perf_init(struct panthor_device *ptdev) .max = 1, }; + ret = panthor_perf_sampler_init(&perf->sampler, ptdev); + if (ret) + goto cleanup_perf; + drm_info(&ptdev->base, "Performance counter subsystem initialized"); ptdev->perf = perf; - return 0; + return ret; + +cleanup_perf: + devm_kfree(ptdev->base.dev, perf); + + return ret; +} + + +static void panthor_perf_fw_request_sample(struct panthor_perf_sampler *sampler) +{ + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(sampler->ptdev); + + panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PERFCNT_SAMPLE); + gpu_write(sampler->ptdev, CSF_DOORBELL(CSF_GLB_DOORBELL_ID), 1); +} + +/** + * panthor_perf_sampler_request_clearing - Request a clearing sample. + * @sampler: Panthor sampler + * + * Perform a synchronous sample that gets immediately discarded. This sets a baseline at the point + * of time a new session is started, to avoid having counters from before the session. + * + */ +static int panthor_perf_sampler_request_clearing(struct panthor_perf_sampler *sampler) +{ + scoped_guard(mutex, &sampler->sampler_lock) { + if (!sampler->sample_requested) { + panthor_perf_fw_request_sample(sampler); + sampler->sample_requested = true; + } + } + + return wait_for_completion_timeout(&sampler->sample_handled, + msecs_to_jiffies(1000)); +} + +/** + * panthor_perf_sampler_request_sample - Request a counter sample for the userspace client. + * @sampler: Panthor sampler + * @session: Target session + * + * A session that has already requested a sample cannot request another one until the previous + * sample has been delivered. + * + * Return: + * * %0 - The sample has been requested successfully. + * * %-EBUSY - The target session has already requested a sample and has not received it yet. + */ +static int panthor_perf_sampler_request_sample(struct panthor_perf_sampler *sampler, + struct panthor_perf_session *session) +{ + struct list_head *head; + + reinit_completion(&sampler->sample_handled); + + guard(mutex)(&sampler->sampler_lock); + + /* + * If a previous sample has not been handled yet, the session cannot request another + * sample. If this happens too often, the requested sample rate is too high. + */ + list_for_each(head, &sampler->sampler_list) { + struct panthor_perf_session *cur_session = list_entry(head, + typeof(*cur_session), waiting); + + if (session == cur_session) + return -EBUSY; + } + + if (list_empty(&sampler->sampler_list) && !sampler->sample_requested) + panthor_perf_fw_request_sample(sampler); + sampler->sample_requested = true; + list_add_tail(&session->waiting, &sampler->sampler_list); + session_get(session); + + return 0; } static int session_validate_set(u8 set) @@ -483,7 +1335,12 @@ int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf goto cleanup_eventfd; } + ret = panthor_perf_sampler_add(&perf->sampler, em, setup_args->block_set); + if (ret) + goto cleanup_em; + INIT_LIST_HEAD(&session->waiting); + session->extract_idx = ctrl_map.vaddr; *session->extract_idx = 0; session->insert_idx = session->extract_idx + 1; @@ -507,12 +1364,15 @@ int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf ret = xa_alloc_cyclic(&perf->sessions, &session_id, session, perf->session_range, &perf->next_session, GFP_KERNEL); if (ret < 0) - goto cleanup_em; + goto cleanup_sampler_add; kref_init(&session->ref); return session_id; +cleanup_sampler_add: + panthor_perf_sampler_remove(&perf->sampler, em); + cleanup_em: kref_put(&em->refs, panthor_perf_destroy_em_kref); @@ -540,6 +1400,8 @@ int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf static int session_stop(struct panthor_perf *perf, struct panthor_perf_session *session, u64 user_data) { + int ret; + if (!test_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state)) return 0; @@ -552,6 +1414,10 @@ static int session_stop(struct panthor_perf *perf, struct panthor_perf_session * session->user_data = user_data; + ret = panthor_perf_sampler_request_sample(&perf->sampler, session); + if (ret) + return ret; + clear_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state); /* TODO Calls to the FW interface will go here in later patches. */ @@ -573,8 +1439,7 @@ static int session_start(struct panthor_perf *perf, struct panthor_perf_session if (session->sample_freq_ns) session->user_data = user_data; - /* TODO Calls to the FW interface will go here in later patches. */ - return 0; + return panthor_perf_sampler_request_clearing(&perf->sampler); } static int session_sample(struct panthor_perf *perf, struct panthor_perf_session *session, @@ -601,15 +1466,16 @@ static int session_sample(struct panthor_perf *perf, struct panthor_perf_session session->sample_start_ns = ktime_get_raw_ns(); session->user_data = user_data; - /* TODO Calls to the FW interface will go here in later patches. */ - return 0; + return panthor_perf_sampler_request_sample(&perf->sampler, session); } static int session_destroy(struct panthor_perf *perf, struct panthor_perf_session *session) { + int ret = panthor_perf_sampler_remove(&perf->sampler, session->enabled_counters); + session_put(session); - return 0; + return ret; } static int session_teardown(struct panthor_perf *perf, struct panthor_perf_session *session) @@ -813,6 +1679,8 @@ void panthor_perf_unplug(struct panthor_device *ptdev) xa_destroy(&perf->sessions); + panthor_perf_sampler_term(&perf->sampler); + devm_kfree(ptdev->base.dev, ptdev->perf); ptdev->perf = NULL; diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h index bfef8874068b..3485e4a55e15 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.h +++ b/drivers/gpu/drm/panthor/panthor_perf.h @@ -31,4 +31,6 @@ int panthor_perf_session_sample(struct panthor_file *pfile, struct panthor_perf u32 sid, u64 user_data); void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_perf *perf); +void panthor_perf_report_irq(struct panthor_device *ptdev, u32 status); + #endif /* __PANTHOR_PERF_H__ */ diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h index 576d3ad46e6d..a29b755d6556 100644 --- a/include/uapi/drm/panthor_drm.h +++ b/include/uapi/drm/panthor_drm.h @@ -441,8 +441,11 @@ enum drm_panthor_perf_feat_flags { * enum drm_panthor_perf_block_type - Performance counter supported block types. */ enum drm_panthor_perf_block_type { + /** DRM_PANTHOR_PERF_BLOCK_METADATA: Internal use only. */ + DRM_PANTHOR_PERF_BLOCK_METADATA = 0, + /** @DRM_PANTHOR_PERF_BLOCK_FW: The FW counter block. */ - DRM_PANTHOR_PERF_BLOCK_FW = 1, + DRM_PANTHOR_PERF_BLOCK_FW, /** @DRM_PANTHOR_PERF_BLOCK_CSG: A CSG counter block. */ DRM_PANTHOR_PERF_BLOCK_CSG, From patchwork Wed Dec 11 16:50:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903943 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 64CCCE77182 for ; Wed, 11 Dec 2024 16:51:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB09510EBB7; Wed, 11 Dec 2024 16:51:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="f/lRgIB3"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="f/lRgIB3"; dkim-atps=neutral Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2072.outbound.protection.outlook.com [40.107.21.72]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5304C10EBB7 for ; Wed, 11 Dec 2024 16:51:20 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=kZHQToOu52yG+SNHsUoWICXyTjR2/3R/bGZTeCDG6X9GowhL+iKAETrmI1kQJfLDibJH7XRgHEPQEC+Y4w7bOWPcp0ANdDJGs4RgHp6sYZ3R6ZF48RhCsz3J7z8ZbMgZiDUr3towC2sZkhCWpEceUKRpZ+BZSJfIqOzTXZtF+qXFMopm4DwPr9AqN+9+hy26AXvETWtffuyX6PblldSDxIVB6Thbr8vyE+JxDdRfwtlDWW/bbh5IClCJtn419GL9Ovf1KadRHZu76dIP+ZWkNIV5+esFmjnTiEi/ezGOf8tUyhh06ElJDrlbzcjqLTLcHo1bpoEIXqR5QxSH/QMcQQ== ARC-Message-Signature: i=2; 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=bKg/67rYZmh6NYjhU9gjQ53VEeK6A3Xe2GXQM/vg0RA=; b=mI17xF+CrgDTW3nH2n4GEFeU6GSqZj6cPFWxjiH1uOzShBOok01pNZRR922HlOmk9qlon2jFNsBujBOFKEunXMpSlYkJRKVUYRfg1uxsni/dxfLl3TIKtaS/TkQRGQkBIK+HEuCGXMi8thc6aOw8ndcle5wBLwK9fdNWgDD+z5V2ZqHm4WoGY7jN3ZHWNQYLp/OpairMrxBCopwQtZ84FAzAl03dN3a7PyWtcPACphVjmpQsBsmoXv/SYzeo2bgJ/x5w+fPdEjdCXDM81rtjgHoI92wp3uc8VfVDGbirglmnR2IqYKRo36YMVsFZ3Ro2jlM2igDujM6v+JpEywa2hQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bKg/67rYZmh6NYjhU9gjQ53VEeK6A3Xe2GXQM/vg0RA=; b=f/lRgIB3WwsDA92oUJsLaYiFWDCc3Lmk4rMMtmnJwRl08lIZme1i1/i5O8UgbOF/gSQQDvpkcIfQJZyJTkE6MnyApG206yASckrBpfgPiJfnzeglB6oeci5zUCxMDQaodsMOi5S4ahdO7nWlYc1d0TAXV0KahF9SnUwhyRvGRL0= Received: from DB7PR02CA0035.eurprd02.prod.outlook.com (2603:10a6:10:52::48) by DU2PR08MB10016.eurprd08.prod.outlook.com (2603:10a6:10:49e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Wed, 11 Dec 2024 16:51:14 +0000 Received: from DB1PEPF000509FE.eurprd03.prod.outlook.com (2603:10a6:10:52:cafe::f2) by DB7PR02CA0035.outlook.office365.com (2603:10a6:10:52::48) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.19 via Frontend Transport; Wed, 11 Dec 2024 16:51:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB1PEPF000509FE.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:14 +0000 Received: ("Tessian outbound 2d228e31de9a:v524"); Wed, 11 Dec 2024 16:51:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e164a7827162b85c X-TessianGatewayMetadata: wxMRNHlx9L39bHspbKxLxr3AW2TQwIOmcja+JkZbt6ndO7KrG6k7fbFn9JAVIFINwvb34QoJWgMk0+f77oTF0BCt/g562l/FRzjcvr95SyoAxnFTloAhkO29/FYta8QOeKVapRv/IPWKjaj6s25sXFY2/PQenyogqGHc+MkZSXw= X-CR-MTA-TID: 64aa7808 Received: from Lf4c2a157c311.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 213540C7-8374-4E74-9716-3B02186A3045.1; Wed, 11 Dec 2024 16:51:08 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id Lf4c2a157c311.2 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:51:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yF9QsjirKIV4mkm8N0xCPNHQzMBC4X35fdg1bEpzQARAW++4jBiXwkMCdIX0aYHOGmiFLGY6bNwVY4LJ+DBfqfyStLLt1MF9/i58wsfP/aZgaTya7saUDkoVB14DsYgR+dWyTG0Pw973H2waq76bceTa7ztw7JsnPz9nvq4F3f8lzYAEIrIbublMlMCTl4aEI2Pw3Y6oo82F9YDQqEU+ViHTbTi2SYiiFkaDAQw5M2frAmtxXYrPZajaqXxgMKs8nAX+mQ/w8OvM2msuixIcNazB7uCOyTDWhWm17wTTz+FJtS8P8I4/Kg3x4cTknnLds7SdOOn6IrkJ2begyhyKcw== 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=bKg/67rYZmh6NYjhU9gjQ53VEeK6A3Xe2GXQM/vg0RA=; b=rrY0Ptvf4H2LzMAIEExGZjXFrBbTk3RFGID0Bha3+olL+MOBnhNStUIvP21r5rhMiU7aH6Aj1n9vQ296B+hMso8thTV2GpA+3tAByp7wbWFv36/GSRKajOjJGBrFyNH6oGEXfrDa5D36pTMoXFPVf85wBRSA8Culfy6B9SDzCvO4KEQo1WPdbKg7dLGc+ojMjgYVxIz+fhDoZp99ce9mLVr8UqsN0UYuA68ooIni3tyMoMVUCdgqmPigGbWfAUlnispVtriQZrSz/uWFK7uTsZ9UfPN2JRlSx/IM0FBV6jwX7o8HS9Fd3ytmD0IyLvLn62KBiy77yNTj1nNfXESCug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bKg/67rYZmh6NYjhU9gjQ53VEeK6A3Xe2GXQM/vg0RA=; b=f/lRgIB3WwsDA92oUJsLaYiFWDCc3Lmk4rMMtmnJwRl08lIZme1i1/i5O8UgbOF/gSQQDvpkcIfQJZyJTkE6MnyApG206yASckrBpfgPiJfnzeglB6oeci5zUCxMDQaodsMOi5S4ahdO7nWlYc1d0TAXV0KahF9SnUwhyRvGRL0= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8493.eurprd08.prod.outlook.com (2603:10a6:10:406::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.19; Wed, 11 Dec 2024 16:51:04 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:51:04 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 7/8] drm/panthor: Add suspend/resume handling for the performance counters Date: Wed, 11 Dec 2024 16:50:23 +0000 Message-Id: <20241211165024.490748-8-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO4P265CA0218.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:33a::19) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8493:EE_|DB1PEPF000509FE:EE_|DU2PR08MB10016:EE_ X-MS-Office365-Filtering-Correlation-Id: 87883752-609a-446e-369e-08dd1a040672 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: Q4MaBE183tweZDq/aeTaI4GBfoVDzQYgCcL6URYthgYr9aJdUtHpxI2NXw8/ST7wYEQGv3GQ4y6izI7a1OxBzRLLctAJnApYuyMGQRtNmMtLpaq8JvGReL0Y9EzbTLTDjNI78wvxFQ+E/dKTwZLLSUQ2yrhDSCVa3U6DgJ9Iw10rpGOkv8YP1WKwowaYoazePZ3S2d/DfEcAZ+6IuX6MtF//je9USC2GhW5ScvdXsXww9NQvRrzDJ/Rc/UbTrOro/Q5HMVGJ51ksMsoJ6NhnT6d8mdG+T636ap4N+J/ucuWfZVCVwdUxn3QyV0Xh7LnlZz5aqcFEycQLkwAQYmFwfSZPTiRZUC88dn4xRu8U4eGaN2Rmy+G66WgaksB7v2K3VMd9BrcSwJJCvXBnARMJ4ymVqHc333HLJxEUnlF0IVkPMCuBfo663b5RGCPFbaeqvDywN2b8EMMrNl0NMY6Af9e853v0D9GVwl3486c+9vfxPZJm79SXn8KNv3S/71ZCOcZy0a0XIW0BC14mbBSmkpG7Nw0RQJYUYqDctkwzdye1NIiXCXWMNwt54vhWxAwBOQshDehF69qUXy1It9rAoIjA5VjLr83sFohuWPNnC//yUAcX66bkxyU9HjAPfN+3qJOE3Q9UYUtjxk3tIRvzhPenQJz555Aqsv10P+Hn+1309GAu8VEuFUI5+SkSaT3hy8P9OMgp06N2StFGh81q+IoEuV+E/ITzCntayMKBmOh4dg4VZLTGTqgcXJnRLACoesVfwWuWscu19CcsFdqaGbKILvnoDIDYk2oW4RjX5DoOJcH58IjRVkPh4+gj8qvZEH+6ibdhLmi7juAt1IG1nHZyQeMgfwNCmzEo6NbKnsBCth107EmUu/CZ4wXweT89y1OgblooTyT2sk7VePS9aXjsbY8owj1dxnntcV0d84Q65lQnU0Xf3hzUwT5g52xC88L3l0WQ2sY/6vuspOArhHsIqERKJznmYVKLLFRH7D7F3ZM9qRoqR8JSbUfviy4+eD7iApGtk/Lp/OLUAZQ3S78wGniitHx2YQVr4J5C66wRXwXiYEmKP5DhujIRQc23ln5ddgP50BiGGIzoQ5e0gHDFmBK0oDb1qFp8+EwkMJ0wWCA9WmTw6pMM6lpgoCCyaSoWU4g9wRp/hMJY8OxiyH32eH07y/SaL4aw091JWxg2JAvTiN67f6kUMYDakQW+pRldQgRCOufThLnYunI1WtTLtKB/911x1pb7iJ5BHnQ3Bsrl1Lc4YqhverYR0fdJxPcAsWGWk9xJ7J/EpUXTnSnuEidswqmpTevk3gnjuNM3iqv/o2AvZN/9M3qTHp8asy4+w+XUp8cVPoNn6glwjQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8493 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB1PEPF000509FE.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 9f9ca443-e79e-4f73-1fd8-08dd1a040060 X-Microsoft-Antispam: BCL:0; ARA:13230040|35042699022|82310400026|376014|1800799024|14060799003|36860700013; X-Microsoft-Antispam-Message-Info: Ftl9stvA/xA6OCZdmwHj3nDgN4TWCJa7Ebh/CRBmvJkrl0AwapI6PjUO7la9o8REFHY3u1iuUoNU4TmVzuFcL82iMu8GJ3FYqqdQfVgGJQICkvKqvtwxb37lxZWBemzWG5D/HO6wrAMoyyBbZ+xWZWE3DZ1NfU6Fw+Y66q6xlxXDXX+qR8vMaxrBVDkUXMISrX/xPiVZfTeoyxhUeI1kQvewPzgkDurImpxjbzGA8Y8gm+vIQ2p+lF3fxZzBVlSGgnWD0TXUOLawijlaeDCQNrR3ELvStG0xPhf52ErkcE5CcTY/1kXe4tKsskyu0G3e7OH0R5/ofsAWUHdqQJnfJOneXDqMD2h8dVHWAz6jJwZVPj1qPgS2K4WTko5B0HGx2yUAUCEOnlXrK7DpWyY+RHzb+SvmCaL6a3bXBsL009VGlD3381k97b/IpPwQsDdPJhx4L1RvV5PKLT02vm0OcSROOGCttfx5S/JqY9tnPDhzUFWjCq2aUJJXmPQtGu4nPgIyJVoKUuy/wHX31HK2pORXn9bqBnbKYVSu9O3GLM64hX+EZ4ObOBtr4GApXpvM/JZiwjjIpV+89aBGcbur+B7oIWWJAiRLEy8egaxOo98CFyQDoiltck+MR8fzi9c8GOItJIUdxzhnP3ypGfus8SbDUsVM5xMHkgGmzBcqnG6StvBR8GAIEbMtLqR2sVIbbcFtqRbsz+mlLur27Y7VkxLqnh8DfytIAG1D1aHB66GOYVh06a3aoIUkJynzvuvA3yuWIDk3+vPBA2Hoq4KQ6iUcPvibD6rnYpuUfsZdBzkaXEpIzziqAjoRWXJKHEBdlavtou/tD6P+MuFgsailQyDgp6r28yM2gUZIKKt3kMqBVPSH24HxBm8XPyjibhiLtAq9dqW5iiZTtuoZO0yN0BYK9Iw4pkZ+jGleCgkDc3k5RvqLK6+xH1Nm9S0EuPKEo1zsSNBrqYq9FCi2GW1HwE4pB2Db7mRVUYUdZBGQcG0zb3NEnxcAzFspVR3F81UPZH6cmcM9bI+Dh85piZ0lXmQI1iinGlZj+jRX7qcWbU2XX6hQ+2Wyhpdk4RiNnALd5BN53mww9Fh3QMf3d5a2eBQnf52rbmHpzgTI7qXgtCFySbCbrAFpXkMTemcj5Cdhz8hNiSP21usSl+ax4lDtEZwWPU4mHO+8N6KDGahlNJGZlundzCqRKwATojP6aecZQGolm23yxfcM/rzD/WBTg1kL7LjXtpi8U9jYHFmbOSMKIRUkc2hYyngofZA8nbjg9AsrkXrLot7OaXAWnVl8x+Cis3oUGzWuhfPH6tCjjJ3JEE0zj9srTUFQyKZNtNOG/QddGE/5sXb+nZ+lGWmiZjh55vn72PR/hgAWWIUp6gZwQkddKopn6Z0+uBlp3nk9wczvt94KC7dyrysFZN/YjFOCmW6qdwjktFaAeiyWCOI036xXjH83Vqx7wbTvQzhS1zlFQuOg67y5UAHW+r5i+w== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(35042699022)(82310400026)(376014)(1800799024)(14060799003)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:14.6349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87883752-609a-446e-369e-08dd1a040672 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509FE.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR08MB10016 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/panthor_device.c | 3 + drivers/gpu/drm/panthor/panthor_perf.c | 86 ++++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_perf.h | 2 + 3 files changed, 91 insertions(+) diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c index 1a81a436143b..69536fbdb5ef 100644 --- a/drivers/gpu/drm/panthor/panthor_device.c +++ b/drivers/gpu/drm/panthor/panthor_device.c @@ -475,6 +475,7 @@ int panthor_device_resume(struct device *dev) ret = drm_WARN_ON(&ptdev->base, panthor_fw_resume(ptdev)); if (!ret) { panthor_sched_resume(ptdev); + panthor_perf_resume(ptdev); } else { panthor_mmu_suspend(ptdev); panthor_gpu_suspend(ptdev); @@ -543,6 +544,7 @@ int panthor_device_suspend(struct device *dev) drm_dev_enter(&ptdev->base, &cookie)) { cancel_work_sync(&ptdev->reset.work); + panthor_perf_suspend(ptdev); /* We prepare everything as if we were resetting the GPU. * The end of the reset will happen in the resume path though. */ @@ -561,6 +563,7 @@ int panthor_device_suspend(struct device *dev) panthor_mmu_resume(ptdev); drm_WARN_ON(&ptdev->base, panthor_fw_resume(ptdev)); panthor_sched_resume(ptdev); + panthor_perf_resume(ptdev); drm_dev_exit(cookie); } diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c index d62d97c448da..727e66074eab 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.c +++ b/drivers/gpu/drm/panthor/panthor_perf.c @@ -433,6 +433,17 @@ static void panthor_perf_em_zero(struct panthor_perf_enable_masks *em) bitmap_zero(em->mask[i], PANTHOR_PERF_EM_BITS); } +static bool panthor_perf_em_empty(const struct panthor_perf_enable_masks *const em) +{ + bool empty = true; + size_t i = 0; + + for (i = DRM_PANTHOR_PERF_BLOCK_FW; i <= DRM_PANTHOR_PERF_BLOCK_LAST; i++) + empty &= bitmap_empty(em->mask[i], PANTHOR_PERF_EM_BITS); + + return empty; +} + static void panthor_perf_destroy_em_kref(struct kref *em_kref) { struct panthor_perf_enable_masks *em = container_of(em_kref, typeof(*em), refs); @@ -1652,6 +1663,81 @@ void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_per } } +static int panthor_perf_sampler_resume(struct panthor_perf_sampler *sampler) +{ + int ret; + + if (!atomic_read(&sampler->enabled_clients)) + return 0; + + if (!panthor_perf_em_empty(sampler->em)) { + guard(mutex)(&sampler->config_lock); + panthor_perf_fw_write_em(sampler, sampler->em); + } + + ret = panthor_perf_fw_start_sampling(sampler->ptdev); + if (ret) + return ret; + + return 0; +} + +static int panthor_perf_sampler_suspend(struct panthor_perf_sampler *sampler) +{ + int ret; + + if (!atomic_read(&sampler->enabled_clients)) + return 0; + + ret = panthor_perf_fw_stop_sampling(sampler->ptdev); + if (ret) + return ret; + + return 0; +} + +/** + * panthor_perf_suspend - Prepare the performance counter subsystem for system suspend. + * @ptdev: Panthor device. + * + * Indicate to the performance counters that the system is suspending. + * + * This function must not be used to handle MCU power state transitions: just before MCU goes + * from on to any inactive state, an automatic sample will be performed by the firmware, and + * the performance counter firmware state will be restored on warm boot. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_suspend(struct panthor_device *ptdev) +{ + struct panthor_perf *perf = ptdev->perf; + + if (!perf) + return 0; + + return panthor_perf_sampler_suspend(&perf->sampler); +} + +/** + * panthor_perf_resume - Resume the performance counter subsystem after system resumption. + * @ptdev: Panthor device. + * + * Indicate to the performance counters that the system has resumed. This must not be used + * to handle MCU state transitions, for the same reasons as detailed in the kerneldoc for + * @panthor_perf_suspend. + * + * Return: 0 on success, negative error code on failure. + */ +int panthor_perf_resume(struct panthor_device *ptdev) +{ + struct panthor_perf *perf = ptdev->perf; + + if (!perf) + return 0; + + return panthor_perf_sampler_resume(&perf->sampler); +} + /** * panthor_perf_unplug - Terminate the performance counter subsystem. * @ptdev: Panthor device. diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h index 3485e4a55e15..a22a511a0809 100644 --- a/drivers/gpu/drm/panthor/panthor_perf.h +++ b/drivers/gpu/drm/panthor/panthor_perf.h @@ -16,6 +16,8 @@ struct panthor_perf; void panthor_perf_info_init(struct panthor_device *ptdev); int panthor_perf_init(struct panthor_device *ptdev); +int panthor_perf_suspend(struct panthor_device *ptdev); +int panthor_perf_resume(struct panthor_device *ptdev); void panthor_perf_unplug(struct panthor_device *ptdev); int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf *perf, From patchwork Wed Dec 11 16:50:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Zapolskas X-Patchwork-Id: 13903944 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 8C0AAE77180 for ; Wed, 11 Dec 2024 16:51:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F057110EBB9; Wed, 11 Dec 2024 16:51:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="c544+nLq"; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="c544+nLq"; dkim-atps=neutral Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2052.outbound.protection.outlook.com [40.107.21.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id D19E810EBB8 for ; Wed, 11 Dec 2024 16:51:22 +0000 (UTC) ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=GpCNGVILzDAJF3SfKAfXAI8dxE6wOHIPtHPUNVjSSARH2q8uM/sbYlzD2xo2i0oSxbHtdx8oWyIQAntwBhNAHKL5SR0vIoJX/oyc1GbYLGOLDMcLJ32fd2kzSg0ishj5pWqIqjtHIZLC1TayUZSTRUBEezCMg4r0p5vGX3O4zfOcm1KmDA7RPnOyirachluWGdWkst4kND+codS71RfJURZss5hI3F1ogXQ9hRXQmGKhOIvih/Ta/QFD6Ma0tYEVBg3eWdPTJTyokVkf5T9uS4kL/ggqbKQzynUoIfsR2t1/eotzJdj4JfzGyQgAmK6AyIT1Cz7R+fvFm7LEx1wy0g== ARC-Message-Signature: i=2; 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=Ah54vksIAL1XBn9oTvm0ntr07MfGjKJQMzj3zX/uYF8=; b=epLDHZoABz3E+Hx9vB0NBKQ2Q8Qnt4lGE5LgUJBiFk77fDvsORO8jCsq0Fn2mrcJTVvfgVhjq3VC83taQtVvXcim2aAVibiABRNcSgP6mlamTvmGakXTO0rWcmiguQMHjMmHY/22YZi5N2igU7iX/JFiAIKaaTPlPaDjsJkIvz9Zvntftm1+s4eBkDEqhtKkQLwYQBwgoqC9AA0vvFIxYpyi6HyvJexkd4VZa7EYlRpcHlHkJH37V+TiczixVpjtBGlMmkjP99qPT1NSe+MhDxufHORkFIqJDSHm4P0wq0dG6Yn5PBZXeMMhi+MTCUXE0GZF9vaOFY1Dlws+kYEwiw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ah54vksIAL1XBn9oTvm0ntr07MfGjKJQMzj3zX/uYF8=; b=c544+nLqQdNQRuBgKSvafcV/FzYJa/mPg6CJAKhOrBTQLVYg4S7ELKX4aADWQ5QW1EnUti1gU34pf3dgyAImpFY73pvgPilAJXQWsdcDuzVPI9M5e2ue0d2PFgNmWjown+/wrT5SzfIAyM2qq4S0MFxRfqylOFTDguzZmIQRTHo= Received: from DUZPR01CA0254.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b5::26) by DU4PR08MB10935.eurprd08.prod.outlook.com (2603:10a6:10:575::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 16:51:16 +0000 Received: from DB1PEPF000509FC.eurprd03.prod.outlook.com (2603:10a6:10:4b5:cafe::f4) by DUZPR01CA0254.outlook.office365.com (2603:10a6:10:4b5::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB1PEPF000509FC.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.15 via Frontend Transport; Wed, 11 Dec 2024 16:51:16 +0000 Received: ("Tessian outbound 20d64b55c711:v524"); Wed, 11 Dec 2024 16:51:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: acce7723b911880f X-TessianGatewayMetadata: gHELJN3cN6pU0hGP3jWmJfHP7jS32iiWXC7SQbWHErBrkbyhDQUaAxNG+ObV0k+E5VGSBtnD3dx+TRk/eJr0lbMbtoC21D2A9Aiyjyj9wQke1gDNHQi83KbNWkB+xWngwjgEmefBu5C7FkV5o7qkaph6CAygRawItYSvCjebde8= X-CR-MTA-TID: 64aa7808 Received: from Lf4c2a157c311.3 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 16F5E391-AB5C-4C79-90BB-E28DF4A0E328.1; Wed, 11 Dec 2024 16:51:08 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id Lf4c2a157c311.3 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 11 Dec 2024 16:51:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Va+LKlxVo3A8doHLFCSpQHiFfpReW/9y/m8p+f0mGiADR0C1menkgqjE2eIL2o2td9gBfmLu7zLb7D4GPmDXt+UqQuB6f4/CancC9NZCxOWh/MgZrRNf+DsB10LLXkyzE7ignBhGPVjvFePymHrzApwSgKGG6ToRbeggMKIpeoj2BFz4aAKr7v3VJT9YIFt1+JCYkKMte7JGl411Sd6f7uZDq/pIipR4MeypJvNesC3JiLGiubn6opm0bmasWCb94qIehk3VZ939wmxGXYOMRpbJG1tlrsa65YiIsMWrq4j4tdqkelDbd3fIwwVZ13LGB/AOBcu/K5GLtFw287XDsw== 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=Ah54vksIAL1XBn9oTvm0ntr07MfGjKJQMzj3zX/uYF8=; b=kv42CKYaH7yNRZBAepTwVMQqH4L3swOk1JEQwun6wNCNl4ZXy54K4F1GX7U9NoZ4KcaHbd2Njlbz2bTke7eysUmSc71/R+l/MAZZzY54/YjpXuN4MnNe38IrTqr5kpylq+QahGL3lJZ4idr3eGYTv1pQW4SyXI3zGyH+nVEQV88+wsMyc/UCorSG9Uh5vQghQ0huOL/ZkxJBkX6Ay7csqPsqX9dl1do03tlTFa0u0oqQsdSpAFNe8uKh5Z4LGZ6VZHcyP01qduleAbv3VjHugiGaq/pKOK9RuOXPSJlSRuEz1aLbNM+uCqPTigWCLtp7Kat2igTaxTvBwyS/6U54aA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ah54vksIAL1XBn9oTvm0ntr07MfGjKJQMzj3zX/uYF8=; b=c544+nLqQdNQRuBgKSvafcV/FzYJa/mPg6CJAKhOrBTQLVYg4S7ELKX4aADWQ5QW1EnUti1gU34pf3dgyAImpFY73pvgPilAJXQWsdcDuzVPI9M5e2ue0d2PFgNmWjown+/wrT5SzfIAyM2qq4S0MFxRfqylOFTDguzZmIQRTHo= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) by DU0PR08MB8493.eurprd08.prod.outlook.com (2603:10a6:10:406::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.19; Wed, 11 Dec 2024 16:51:06 +0000 Received: from AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897]) by AM6PR08MB3317.eurprd08.prod.outlook.com ([fe80::e42a:494c:6581:1897%7]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 16:51:06 +0000 From: Lukas Zapolskas To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?utf-8?q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Mihail Atanassov , nd@arm.com, Lukas Zapolskas Subject: [RFC v2 8/8] drm/panthor: Expose the panthor perf ioctls Date: Wed, 11 Dec 2024 16:50:24 +0000 Message-Id: <20241211165024.490748-9-lukas.zapolskas@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241211165024.490748-1-lukas.zapolskas@arm.com> References: <20241211165024.490748-1-lukas.zapolskas@arm.com> X-ClientProxiedBy: LO2P265CA0102.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::18) To AM6PR08MB3317.eurprd08.prod.outlook.com (2603:10a6:209:42::28) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3317:EE_|DU0PR08MB8493:EE_|DB1PEPF000509FC:EE_|DU4PR08MB10935:EE_ X-MS-Office365-Filtering-Correlation-Id: c8e246fd-0f15-42c0-538d-08dd1a04075d X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info-Original: 2bMmBzCdjC4e/Gtqup0QtTlUnqdJve+Y5D0hUmlfJTITQYD8DIlgN93Ik70NaFAfnq/er5Tw7NVem+FXS//AeZbQpoSKbcTyI9wJE8/bZmi25FL4pQML5f+fBS0LsX2770tlFVKM0xCeUNUL/syaHKqHfUVKXTtiWsUyZa/Upjawsv8KQ/BrgDBObnGc6UCPJt1un4RDJAFTDmmqQRpY8mQ4EP2YDC4zVfu1pYl+RNwu3Wdn6OBmW6D9vQdb6bCbZreY9VXXpWft/4xDAzNXbtHTDrlkN03aygw2v8BSqb2X1S7l4tkgxxOjvRAeUSDwkewW4h/5uJLflN3L/oTydb8CluGH0QfpVgRQ9hhx2665Xj/XMpfjyIcfR5D/7dkQeRECbP96IRyon/9JpdpevyL6CNXOPMAjEMDj2KPemz9SiES3mNiLBXbFJvCTKdbfj8zQ8Tzw0+PsVNCdIeLvCPukfUqhHQB+NBwKSNHRSGJfNzVHzjub53biRgTQBdip/86z+7/dwzXcg5XnD/av07SzjnlOK2By0VGeAAOO6VCIBRH51ZxoWdWmJghSm/uwsa5OfyMH+dCv2wB2gpf1cDrjBQMbBrS5152/tvufnhOf/22vQ48scXLjxDEOkcw88b9kN+OkCz72WkkRVirt2Vq7o76g4oEVeyX7xSFuvgB75Km7ZBe6oMnPYkBqyjqkHXaa2dLVX5cirCAaQNc2jBW7knjjrakodRALw1b1gvWpqpD/deNQK2YGsLHRMbfstuCnmB3qtHcxR2t94OhJQNlveweJLpFwhk9aHEzw2XNuJBr0BsTkHfwnlLMAghfXsMFhyNnlPcTcUgZ16c9TS6+gsTaPbLq71saY4OUMoJKKeDZBzb3ZEFbZn4FjXXsBF705cQE+PP+6tsZq+t7V1U4OGfkrrbFZh3A7usSJdhjS+E7hyuygt47NmEfQi85G835KRyA4EifMpih3pPTblbhu2Ies8k8afo/gtzLPByaCl21O8LW8TL4T8By78WAoi/LQc4cvOKnOzrNihvy9BqrqbWd7sH6BW9Soc8RlhumWFTb5Lans+A6/Y30UxBQFS7Xo4YI2EvuWmpL3j7GrgSm5YlLbkwdW56w7CcRP6J2UaCPRyjLsUODMy7WCJ9f0aZTSz6kI6UQ88y+LpN9cIy4p8zn/jY8bXKl8sEgscNxBSXAnKbqQZWBXVbB9NHJjNVofyhoMmBHA6gON+pE4HFnLg/kTIfzuMf6qicUh58bhXfGPpTg7OSfDWrtlsRar7EJO9QMJYYqKIeeVBkaGKIgadfYWHKFCzKU38dwWY9zybyOhCxW2DK0pLXkA5qFGOlaaEodHMox6UgzTRXi8kQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3317.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8493 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-SkipListedInternetSender: ip=[2603:10a6:209:42::28]; domain=AM6PR08MB3317.eurprd08.prod.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB1PEPF000509FC.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 24195952-0700-41d8-e43c-08dd1a040165 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|14060799003|1800799024|35042699022|82310400026; X-Microsoft-Antispam-Message-Info: yz21hd5Fa35vHHyCeB9FW2H35SApuWuiaEiiiBHgGgYMW9CAQUzoHu+3NvVSR2NHz6GPVhVDVFImuho/rZnsNDdlsTOC+Jb2qbRKLeQ4LIoPAZd/PGqqrnTEg7WLiz23xxWn4GAp+Pw5/2oW0DWc9o9kAjv2ifmBH8evTVnH817aDD0XHn0NAYcDyCVj0sRU6KD0MvcqYWTiWscmABX8ors3z56lWlWG0OZ0IhlXDgyUmgZQ+W7crQYR0hIueR/dLhLgtS+4PbhlJ+L1yA6/u/Cz4IWdrzu3ET85kob7KfSlZl3GcILCQYApa7ZzEZRiaqtBGcfynj7ijY8jacAoLCaLyZdvE/QnXmtvYUYhhSBECYKLumzZ3mIeJmpwL9pUHAGVi1OPORgGB/9Se8mj2E0dsk6cVSay8ue0k+Sq9a7gPT5GlJ2MgqZRCPz4TcQq6ytpJqmSC+glIyTOp5EhC+eDaBBnPvvWi6+rh7t3OIf5Pg1sL1su0BXQK9hgxnhTbNiPi6AgQFxXzNfmuHVv0SzSMadnaMwpJKbrv2PZz8yMgz7PcvwuQrLEsdhT3Gg3nj5AObGgs7zI1cCXDykXObqz4R2zCNlbFQFPe26fkHCqDCMmNet3Dd0455u+SajNpDflL0O125ROx1OfisEp2sTcKz1yTnkWoLDvQRe7BhLG2TifgNTMGf7VIVLmybThroorLrKgJ4pUg+hfvKM/FsUCGoCuiVDkGDH9xn8ydigxJKR8PdGimdv91vxXyr+zTFcdjfXsJ4in3pQfJmrhwBm6gZdjJajsKuQuRoDHoi80ahnViXlQLxLnngJEoBFkb7n8a9i1Jw1nNO86egvqbdbUvq1BoQIYCUp2Oew2qiO9WfEUbWhyuaLryyWbGMnnLbS+W7wxRBpqxWkLIzNcrIoi/S4WsTBSLYpt91C7ccKLHGmPAZrHyfQgoFQuC0zwZOXo2ZhLT0mJMMr85QV8LKbXXn6WHNDQvImhrNFsR9Lsbdjg2MY1VbxGlmYK1coJYZ0Vxw30z9MsVEf9Oh+n7hxceMoT7X/XqcA54xgfppNIqb+rYQE37e7mkOcc4fZzv94HlA4o9BIhwWUzBgVNuvi+Ps4wApS7HGW8/CwJuexJtA7KG/xGHuhE+01RXLc7IjeTkh1GVPUvw7Vos33+r5vudsajiGk3tHzi1vDqOG8FvyBltfhnRMQ3Hh8fm/flyMVBUn7p1jxjNZGtYGG+LFiQrGrvo0T5/cXt5AxaoLDjv1mdTEH7c+/MiH5DbaT6ePGXAzMUUHY/8YUbWT1K88HXm8CTd4vfDegpjVh0KTFF9HdjJuye8NFgsJC2Lz6jtd+Q8/AS5xmidZ6s9kiVezGu3hbJ0ymE9JjN2CvHxNC4i1ad+DSnQGdapBf3qp7E8+LoWF7k9vgdWKebspSexkfDgGQWX3GPj7rUgAl2DR/72JifwWOec9DD2e2IFmZ86s5SwpREcqgr8cp50KgQ2w== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:64aa7808-outbound-1.mta.getcheckrecipient.com; CAT:NONE; SFS:(13230040)(376014)(36860700013)(14060799003)(1800799024)(35042699022)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 16:51:16.1914 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8e246fd-0f15-42c0-538d-08dd1a04075d X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509FC.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR08MB10935 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Signed-off-by: Lukas Zapolskas --- drivers/gpu/drm/panthor/panthor_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c index 2848ab442d10..ef081a383fa9 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -1654,6 +1654,8 @@ static void panthor_debugfs_init(struct drm_minor *minor) * - 1.1 - adds DEV_QUERY_TIMESTAMP_INFO query * - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query * - adds PANTHOR_GROUP_PRIORITY_REALTIME priority + * - 1.3 - adds DEV_QUERY_PERF_INFO query + * adds PERF_CONTROL ioctl */ static const struct drm_driver panthor_drm_driver = { .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ | @@ -1667,7 +1669,7 @@ static const struct drm_driver panthor_drm_driver = { .name = "panthor", .desc = "Panthor DRM driver", .major = 1, - .minor = 2, + .minor = 3, .gem_create_object = panthor_gem_create_object, .gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table,