From nobody Sun Dec 14 13:58:36 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 886A5223E9D; Tue, 10 Dec 2024 09:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823330; cv=fail; b=gFnXkT5rtNEhRvkSxxxJOUtP9QAUgt/UWrzmZ/2CWtR2jpUpoZCAZW0bwNu3zHY5hiimXdvTUSdS9Er91g9nbyI8sePgji3htlS0rkb6WKhmsUtbEzlhcGZzptpYsydST6j0dG1OHp4FVvn0wercMELh1V4tke4bpDsYiLCXNGw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823330; c=relaxed/simple; bh=n+HWv0Q+pOPhcb+PfllJ8UIvXY1SnYjH6JA531VqVu4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LLldAAFbthmcrZ3HzXqrERGGFLthRUtCa2LLIFApG3rqb6ZMExtqGqLAbx+K1L/e4ruI0xfob1M2COfUjterczmHEWA0c1b125h7NcHPKiUf886ySCugB+g1hfuTgkd9oSJpd51Byu7vegE2/jsMDNwBH/9Zy8b2TgXExAs2uts= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=FQyqYQXL; arc=fail smtp.client-ip=40.107.236.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="FQyqYQXL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AovVjFDeO3GV2RhDyB/l0gAw/yUZnbihzNlgiAstNiEQwoR1bDcUb1on5pkoh4plWW9sx9pfSgB5WMv9StgGUF1manSmFQf40epmjHHDOTWmKhyhaqB91hliOopy8wYSjCQIwQtGJ8TrcQAw5X72eNdJI5w6B+LNzsdd6ubzeyXh/GuIL4BlfnHCudniE38zextggW2YoxQ4YULhuzaa1ZaN/8cVIT4vQ0Rw1/9ifsTp+PVwA8BqAxCGeVFiPHHvBUaErC55eziwjAf/VQwYkgXiUuMyg/6ll8+kzjYK9P/ugL8XnVf0VkXDgF6sMRqScmX55cy8dyqXH9aCLwdNRg== 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=L7prG4ufdRXruifM+sWVwi9X6Ewy6VrtxiBVtiq7/Y0=; b=h2b/CSQ9UZN+d2aoBlv05eRChe3JUuPClq0nk+u85qucIa7NkagDCCobLwNL9kirArdAldGfXINwkGixkV2lq6TLGPj5RWFcArn2vrbxxJMYoGQP9zNi2Wdd+Sb5HrJs1bfQLAcB0MBjmbWvOk4glkHHSrEIoR6L5BRsY9E/fiTUGc8Hd/us+v+r99r6s6sVlEOjKCGOd1MVduVDQcPZ4wiUcKZNGsGWc2JnOtEOwtCJ25oOPZ80QLicu98sAR5Miud5XUNQwkcWP9zUBHC5pnZKfoNLyKjlO8q+Sh/Xq4NqHL+duz7/v61GjQ5IddiuGWltqSX5LNvSis+OinJGmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L7prG4ufdRXruifM+sWVwi9X6Ewy6VrtxiBVtiq7/Y0=; b=FQyqYQXLEqpI4v0ACpOxE7MRc5LV+hdDbZxhucDeHceQ7EAK3wozIOMIkZlykbqZ9HSBkcV5SvQ0IbBCdBna5HFdNOT0WPtINhreHPBSZ5k8FJCdZF/F0VDCEsbBO/N/EwV88uD9RfnPO6H1A8aBa9gz3xvyTRNiHN3fjBdpXWE= Received: from BN9PR03CA0890.namprd03.prod.outlook.com (2603:10b6:408:13c::25) by MW4PR12MB7262.namprd12.prod.outlook.com (2603:10b6:303:228::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Tue, 10 Dec 2024 09:35:22 +0000 Received: from BN3PEPF0000B371.namprd21.prod.outlook.com (2603:10b6:408:13c:cafe::3b) by BN9PR03CA0890.outlook.office365.com (2603:10b6:408:13c::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Tue, 10 Dec 2024 09:35:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B371.mail.protection.outlook.com (10.167.243.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:21 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:15 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 01/10] perf/amd/ibs: Remove IBS_{FETCH|OP}_CONFIG_MASK macros Date: Tue, 10 Dec 2024 09:34:40 +0000 Message-ID: <20241210093449.1662-2-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B371:EE_|MW4PR12MB7262:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c0f3eb8-1670-4cb2-f413-08dd18fdf761 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?b5DRW5DIt6ieR15n8uB7djz3wheakq2UwTGEaw7rjqPY54Lw61zsW7itE0Xb?= =?us-ascii?Q?XaTUWMEK40vRJLh+MOIweE2FLkJPk9KcEnhE0Up951nr9XqOQyttrXEANED0?= =?us-ascii?Q?3Zz54SUIzzqfEG1BEC/Jq7Oa62MrjXtZi0e0mwuNH1V2OddjwBiiUp5RDlHa?= =?us-ascii?Q?fCphqaw817WfzQQc9nYHeBxlEwTDe4nSg+K6dG59DeWIx/VDzRG9oPz66zJh?= =?us-ascii?Q?MNLSr7GNh8NNLzu8XXib356g1wLpWDojiLD1xvTqm8hbMiOxst2m1pevvHKT?= =?us-ascii?Q?g7WgASZRO63F8HAKVCB0+xcC9acCDa0X6Ef0h0JHLEQLY3c32RTLUs9mIl3b?= =?us-ascii?Q?ZbHCHAsKdgNbNj6BFFOMD2y3tBRf1i+Kta7aKtc0oRVHjSnWlDogniOjxTmL?= =?us-ascii?Q?r/bHL1jv++/DE5QZj/dJdZkwmsEj6mO7Qj+9CZx04YTO2BZcFPvD3FrBePBb?= =?us-ascii?Q?MXt9/UVPALrcoiH8BFGs2VBf2I33ey+zz/Ns66OsIx7wK8d5YWVL+uxuRrKL?= =?us-ascii?Q?qXRBraHZWri1kIRMH4pr5bnpCxbv/86tQ5d1peGDVrIPekd8Z+hGeDAxZuQX?= =?us-ascii?Q?opOcNnJiEtftNKEc8geDwID2PipP/nO/nc3vdc3ve42FuYXEhvcw29P+enQj?= =?us-ascii?Q?qG4Rbqvv50zvCNxCHKczxBwaaqzfXa55vzjjIlJ53cYlsTNqQ1rlxm1oKb1t?= =?us-ascii?Q?2qkb9lQW318nDixX2Ul5vuUhEGKq/nqqogxMlmAGizewvf5pg1NbUCDgmL/M?= =?us-ascii?Q?TVOrNEKLvcVLB0dWc0oFK2nlziWi3xQQt9Q8uc6YV16azLsTQLmzSeHNalfv?= =?us-ascii?Q?Ip4sLMdVNHtAoJK+T6hWgecmp5qNcCLf2fPq1KRAxNOp1ynGGfwYVJH66u3O?= =?us-ascii?Q?D+WRXVI3jAd4GSIa/OQ77g5HGnHjWjaFIrPpHJuWJnvo7QecmMmLraemdrtu?= =?us-ascii?Q?IQykwidQt+6sZvTaEmXUEcXqPhfyCfYhcoxPtIy2+lzHygGUi9XjyVUZPMQr?= =?us-ascii?Q?x5Q/6C91xUrAfPwqXELYcMxrQSZmINdyYCvUFZ+4Fqd3LftCPqxQZlbduV5q?= =?us-ascii?Q?FdLgSHaThlPF7Ue/dsElmlQ+Tjt7p3YqXY3UPa0xJlJWoRKFPjoHqoYsSaul?= =?us-ascii?Q?a2vzenLvJYqpLozwPMDircojZuJ7mk+teBUc+J0A3L9NAhA9Khk2Me3QkzRv?= =?us-ascii?Q?wKrvWU6VqIXN12OmtiNPMyhNJQY3MmR6zqFBByGIiuFng/5HZcxD2OfhAYXo?= =?us-ascii?Q?jASsLKlKs8Wp08MuPz9YK/GGPPmdXE+Y3oVyq8GrKy/T0yIjP6P4r/762yn+?= =?us-ascii?Q?70bab9qZKSfeSeUDPqEZ6evQsiNDffD1Fmd7V131AtkLFDEr2Kp79VrGTx94?= =?us-ascii?Q?fl4jj56ZgJAv+R+Mmd+wyHOxu1tNFJGlR1oTaPlELCu+skJ6O/bBamiXrIUM?= =?us-ascii?Q?ckoSOoPAtJMWY3VY6ApFbAajNz1bT+Us?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:21.1881 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c0f3eb8-1670-4cb2-f413-08dd18fdf761 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B371.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7262 Content-Type: text/plain; charset="utf-8" Definition of these macros are very simple and they are used at only one place. Get rid of unnecessary redirection. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index e7a8b8758e08..4ca8006d2221 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -28,9 +28,6 @@ static u32 ibs_caps; #include #include =20 -#define IBS_FETCH_CONFIG_MASK (IBS_FETCH_RAND_EN | IBS_FETCH_MAX_CNT) -#define IBS_OP_CONFIG_MASK IBS_OP_MAX_CNT - /* attr.config2 */ #define IBS_SW_FILTER_MASK 1 =20 @@ -688,7 +685,7 @@ static struct perf_ibs perf_ibs_fetch =3D { .read =3D perf_ibs_read, }, .msr =3D MSR_AMD64_IBSFETCHCTL, - .config_mask =3D IBS_FETCH_CONFIG_MASK, + .config_mask =3D IBS_FETCH_MAX_CNT | IBS_FETCH_RAND_EN, .cnt_mask =3D IBS_FETCH_MAX_CNT, .enable_mask =3D IBS_FETCH_ENABLE, .valid_mask =3D IBS_FETCH_VAL, @@ -711,7 +708,7 @@ static struct perf_ibs perf_ibs_op =3D { .read =3D perf_ibs_read, }, .msr =3D MSR_AMD64_IBSOPCTL, - .config_mask =3D IBS_OP_CONFIG_MASK, + .config_mask =3D IBS_OP_MAX_CNT, .cnt_mask =3D IBS_OP_MAX_CNT | IBS_OP_CUR_CNT | IBS_OP_CUR_CNT_RAND, .enable_mask =3D IBS_OP_ENABLE, --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2087.outbound.protection.outlook.com [40.107.220.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4190078F37; Tue, 10 Dec 2024 09:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823332; cv=fail; b=Z2sGeZOTCeWFRr8kFAIBKaCmLWpoor79NLpEhog5Oi1444NqDFIFM32Bf11hr+ViWZXMp6G41d9iyxzfKT1Vyjwjm+MHPddN9gjIxsrs9E2wbMxDIICmaXsGGxw1X4Hl8z7lhzqdwXMdK5dDS/vK62M9iEjUJ4ZXNHorAcdwW1k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823332; c=relaxed/simple; bh=TRB3+hLi+ggudg0JCZ+912Ji1H8WrzYPFfUcdTjovXg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gSvMGRQyNuc66KVq5EU3VkV33gvV49IblHcM1Kd30xhSZuxC8g1dDAOLSuWn8DAuh6Cg5rfJdnlDzkeb5e2ts68mjOnSvW14l0RAIldXZa7B6iInO/nXpfd9KfNKpcjwu3dkgqE0NO53c+B+/rqaMmyrliPnfgiMzBjEqJmM5As= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Umaf0Ana; arc=fail smtp.client-ip=40.107.220.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Umaf0Ana" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dNpOsJQ8rTjQcEHRy6EsQvdk/8EgwyBIGlEC0piETQNx3HJzo1+geV0JP0I8hMbT3/qZE1Mb3lK9RR2PMmoJlQFRHCfS/t7PM1OyxT8iyCe4qWgSwJ90msC+QMsrtuwb3MPAqqPZZTXJD2UCfzkS9WatNfxZpOG8JUVCgzKbFsexgXtemEQLVlLlsqrONUCBe9irKHJysaU+oYmqoLxJFkpUIwI3wI3F+3c8hTx63m2gVbdnrNr0g4uo3jqCmpXwzJDNFFkmbNlZBIVfz9ojvmiJ3JnIw30H72xO75OyWAYSH9p/JfmJI1NH075drzjdKy4J4YaA71C6KoJHLVoc7w== 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=OXcI9ACM3+mQ8XBMssEZPaTlM0c3fPenKr5075P9MAs=; b=SkgGUrsBKmjvcBJCX1Q5chfFceGaxcYDzblEXSiMRhnKF1Dp/xmsTI3hYcBD6zvCpL4U8J2QDsMzgrWXhihEn1HVZJGF81i3xQ2g2bpwhqknpoCFIa9xNQa32sn5QqzgD5YmkHNkptXBw0wU6vhIZdW9PHl6or7WsVk437PK/wO7RSZWNEK4luPFX7x3K9CPsrVI9Selki7rtNOny5vnnQp7ecP8K3ogY3ynFFNXLxQ8G4iokLGo1lTVhpRO0Qk25K8WXv/G7xd5cb7vPmOsWTC7O0dxWPWkxCwCvr2qpUCO6DzO6gWEDr6NIzN7tUbnvN7sJ83vmT5614w395cXJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OXcI9ACM3+mQ8XBMssEZPaTlM0c3fPenKr5075P9MAs=; b=Umaf0AnaDM29Zk8VIJk3pNAHJy7yK1U5RBvHXnLe3dQ6XZ7ZJ6m/8fFIUkcaED8uVVo2DFtLPzpHXaSXwEUjNEfMuhquY9BoU8UqUvBFPQ/hBsUUGI1VcYMAK0qitbK5XsTjWv9cVKH4kp+8WH9f2kQz8cGZPyamPOMUnZ4tGIo= Received: from MN2PR17CA0012.namprd17.prod.outlook.com (2603:10b6:208:15e::25) by CY8PR12MB7338.namprd12.prod.outlook.com (2603:10b6:930:52::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Tue, 10 Dec 2024 09:35:28 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:208:15e:cafe::c5) by MN2PR17CA0012.outlook.office365.com (2603:10b6:208:15e::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.14 via Frontend Transport; Tue, 10 Dec 2024 09:35:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:27 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:21 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 02/10] perf/amd/ibs: Remove pointless sample period check Date: Tue, 10 Dec 2024 09:34:41 +0000 Message-ID: <20241210093449.1662-3-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B372:EE_|CY8PR12MB7338:EE_ X-MS-Office365-Filtering-Correlation-Id: d9c57a2b-cd40-4ece-9b11-08dd18fdfaff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WUV0B3h/WiHwvgMBVr8rpEOGmSOFuUq2JhSI+EtRBsXehSWPLrtF5VVwGbu7?= =?us-ascii?Q?6wzYitiyX8MB1M71aSCdGaKELxUmU78GbKCfRGGFlk8naGrumwnHze9kuq7i?= =?us-ascii?Q?nSCY0VZb1GE0hWRsEhCtMOsAJmpZJJWFYjaHu4k8EUMoR6KEZpF2g0SHFxOd?= =?us-ascii?Q?tn9RHZUNEkpnn1yZ5KXlw+EjbJgtXIYxnzUOyhecVbRM2YgKpttC/PzeWmr/?= =?us-ascii?Q?7iCf1bM/OZBW5PcQHD0MhcdtMQRZAdKI4H0ksMcaUYOAQCQexDN7dUFgmcrn?= =?us-ascii?Q?+kCd6cUwrtjZNnt9nxlIUTJF3x1v0TmxIPcz6tbR6O/9wUKuNd86rNvw6yzB?= =?us-ascii?Q?jBcMlWXDCf2eHVwhOh3yVptDIqDHjt7suubNVrkMlUN65d4eYsYFaVLhLym5?= =?us-ascii?Q?Oph9sMTcvSWXgMghfRHff6NC80PSlcbXGHkhIXGnTbosOytLUN6dGK8XgT4o?= =?us-ascii?Q?hLJhIU0iAGjYrURBLNKf5wlDAYA30Om2/1hkiPSN3Sfev8T7K62o22+/NjVm?= =?us-ascii?Q?AUl5uxdyT9ujprTO+XCtfRRhXdfW5X21Qeyc78Sqychc6Kfcej2Yeb9VkD2/?= =?us-ascii?Q?oMFihfcHoPbCT12Or4chiVRlmHgyHtqkfFusrUH6RrmXu4crrxeC2RsNtyS3?= =?us-ascii?Q?UNxdQE9/7UuEM3h0eoPU7+hUATTDYZmvxoqZHKmWC9G9v4GwL0YN5eiTPns4?= =?us-ascii?Q?sglhmEWiPR0Nlht9gmWDWnTQ+im0oO6TOgqn9Ij8FQGRMIUSnmH93yJmLkfp?= =?us-ascii?Q?gVNEBzM4KMMZLdwg8pTF/NbHVjqsvwVpZeR6gzhOZoaLnBgnhVbBY+kO4JLl?= =?us-ascii?Q?hDUnZQGLacPbkL80UFrxP/FLHoGjKCg1Fry3N5tPMxIq6b7of8DuZTXnkmZk?= =?us-ascii?Q?9xGDm1JbDwYxxqCCinDs/nLqislPA/cYpSrOBsJ6N0wWivszgYzU2F5nqCZR?= =?us-ascii?Q?cEple5pZUfwQHju+csBPVNheCe1vezCxYTiaANmgz/y4Bs5Ch13NXFV8manE?= =?us-ascii?Q?j6L2htYmv14VxKc/mdONFmp9zbS6/C5I57pXDVUdTsxHOUGkYV0Pc0xbBhU4?= =?us-ascii?Q?dpTTbT/0ZG8CjQ2NnwO44mjwpTUaUZzytWkmYZWhJ+cs41zM7eOT7NMqtLXN?= =?us-ascii?Q?W6tzdbfFUvw7aFCL+zQk6Ec0+Rjx6J9jvQtYGj+WH7c1rfJ16KVMOg235azX?= =?us-ascii?Q?UdYHidVdNtctEEDfLwN+OWdffWs8cUgfT0ekz+wQ9XSvjgzkmRl+B/sRy3lj?= =?us-ascii?Q?9+FBtjDhGGiKTdG5cqKkZ57PoxbWCPtYbA1+gik+iGG8aoOFCR8/TO2lCnik?= =?us-ascii?Q?qWYnVYpyhPWad/mgVKjZjJi0lvIqWv5agwJtyF42ldD/HiZsL7rjv9dpcj0Y?= =?us-ascii?Q?jOI5KK+1dspV3b5rcCBZWed2oOH5jzdFgKEkAOuLJzxtBc5ZEK2kV0570ALI?= =?us-ascii?Q?TWQ0+NKeoTNww6uc8gJhcXIcUTOI/Gym?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:27.2701 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9c57a2b-cd40-4ece-9b11-08dd18fdfaff X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7338 Content-Type: text/plain; charset="utf-8" Valid perf event sample period value for IBS PMUs (Fetch and Op both) is limited to multiple of 0x10. perf_ibs_init() has this check: if (!event->attr.sample_freq && hwc->sample_period & 0x0f) return -EINVAL; But it's broken since hwc->sample_period will always be 0 when event->attr.sample_freq is 0 (irrespective of event->attr.freq value.) One option to fix this is to change the condition: - if (!event->attr.sample_freq && hwc->sample_period & 0x0f) + if (!event->attr.freq && hwc->sample_period & 0x0f) However, that will break all userspace tools which have been using IBS event with sample_period not multiple of 0x10. Another option is to remove the condition altogether and mask lower nibble _silently_, same as what current code is inadvertently doing. I'm preferring this approach as it keeps the existing behavior. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 4ca8006d2221..bd8919e7c3b1 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -307,13 +307,8 @@ static int perf_ibs_init(struct perf_event *event) if (config & perf_ibs->cnt_mask) /* raw max_cnt may not be set */ return -EINVAL; - if (!event->attr.sample_freq && hwc->sample_period & 0x0f) - /* - * lower 4 bits can not be set in ibs max cnt, - * but allowing it in case we adjust the - * sample period to set a frequency. - */ - return -EINVAL; + + /* Silently mask off lower nibble. IBS hw mandates it. */ hwc->sample_period &=3D ~0x0FULL; if (!hwc->sample_period) hwc->sample_period =3D 0x10; --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2071.outbound.protection.outlook.com [40.107.93.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7301778F37; Tue, 10 Dec 2024 09:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823339; cv=fail; b=eme/G17/5gLNbXk5qxGXLAlpFZi6E91/jrdLrLojW7FyH4r0xNZhEDGT7KhE0Hr5FpqpQ4A6TqqWaFW118S4L7WehewvUF0c65qGyhgkCfeyscF/s4ciFl4vtWROFLE8L7eAl+BedsibRYa4u2uaaySPKlzF6/9ycNl7YPm49n0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823339; c=relaxed/simple; bh=PkNT6OYwh7m9BoNlFz1q9iFM0Fum02O2rUmZVLxo1mM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vgf57NKOJzJjqq4Ep3iRy+INlBUoqaTZ7nBWh7ofC0jhArJdMnBPoeeyU4DR/xNBRIVFvlo4HkiCuN2OSJMGd6+eR9GL4yr/AufVOKsDJjIrHMVRAGmwkOV/cF/NQKq5g8AV3mgu/mCgQ1TY0AHvB0dPbjl27fml9Q6zGiaW/ro= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=29lQuODm; arc=fail smtp.client-ip=40.107.93.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="29lQuODm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qa05ODRVWtF5KsS237kMEidLsHebMt9Q2ULE129qFShrIQUFRgHaaUow1BOVT5UnQ1qQoGUPA0tT+0i5+hDTmcfXv3O2X/SQIa0+Sb/ycZ5zMQKpAbsF8mqrljaZ28/9sC4Lo+Lb68G//emW3k8hdgHR0BBND+Kl2Yuf74VHj7f9tYk50Sngyhp50tlwDzT+y4gLvMb6hOtEAJYqZl7LHHSoAaqcbx30cmNV2eLvdObcfjpWNl8Ghgv6vNQ1jt+1Jut1Smv1nNgWbn1zeLxa8PynV14EQX/I2KAeHUzx72zAQsLdeYqwOnc2Et4ShL/a019x0jUtmY1XpoCTZ+tPag== 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=pg50NUp16WRlTABDwhzW40w51FSZ/eZIlxiNDZUP1eo=; b=eZsBjOpRqBCgTCNQ29a92IOzJaodttJYoDPuS1I7M2J88XGxdFmWpsLc+rT6z3fbBHgyBvC/oyqZ9XvuUmSwTiQM3dVzgESVUATx9k3WpusIemUqC4uyKlN29yJKnmSEaj7w9jIikKypFFvxnV9Ax/KUgGuvp6AChJV9k93L3leiEkQApHQFtqH9MrGGYa9SebjHIs+KdC3PM6HG2KVUXlyEo/dA5AqCXKhTdM43BtXlLBox9955ifqlTvezpWuq8uSzc+RACNx8AlbWDs4qIb2nhmT1vSxmQ2AeVRYM65eZqFS1KLY67I7u8Y4BiQ7t9tIsZCHfM56RxDAn3QT4+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pg50NUp16WRlTABDwhzW40w51FSZ/eZIlxiNDZUP1eo=; b=29lQuODmehgpkA4RaFiFyJ5mHdT7jURPxpChiOYxtdYjZoykvVKpbFX+0qigU82ueLJNqEG1chDYpqn+bsMSxlgIoVyoS3PiiUiKhqoOCY7ewP7GgSqlV3MZIwljc+8YPtfLZISeyL6TxT/c0c5FaxS33nyGSddwbniOZhG8XnQ= Received: from BLAPR03CA0078.namprd03.prod.outlook.com (2603:10b6:208:329::23) by PH7PR12MB8596.namprd12.prod.outlook.com (2603:10b6:510:1b7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Tue, 10 Dec 2024 09:35:34 +0000 Received: from BN3PEPF0000B36D.namprd21.prod.outlook.com (2603:10b6:208:329:cafe::e6) by BLAPR03CA0078.outlook.office365.com (2603:10b6:208:329::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Tue, 10 Dec 2024 09:35:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B36D.mail.protection.outlook.com (10.167.243.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:33 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:27 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 03/10] perf/amd/ibs: Fix ->config to sample period calculation for OP PMU Date: Tue, 10 Dec 2024 09:34:42 +0000 Message-ID: <20241210093449.1662-4-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B36D:EE_|PH7PR12MB8596:EE_ X-MS-Office365-Filtering-Correlation-Id: 06fbe83a-5266-426b-d44b-08dd18fdfe8b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|1800799024|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?jXIXlraSbYrzkfZgKRQtU/CxjARy3VNBKbzshomkK6Adw2KIe71iBEfIPsE+?= =?us-ascii?Q?jvglaWH/SxueIbcLjHmRpvDPQOxUly3ihH/P91xwckSbpHNdirfKYbwvNaCq?= =?us-ascii?Q?zBFpSQtYk2QMWu2rJA5Dz3fa7lgQYJmjAZ4BiF/I6hPpxJpMItM2RQmKiDgR?= =?us-ascii?Q?G3ddTPdTuDvJwMb0Jf2D53AbiPorzAjZl5K96mpeMYN4GY4LddsZr62l3bq7?= =?us-ascii?Q?TK4jcGQT82QU5xhIHopW0MWidB6E9piU4U4bD8Kovv2lzTLse/fbKCFGfU6Q?= =?us-ascii?Q?UfC/V42Tw05So9mqi1GvL2dFpin7C/unxfCIeNMQB3BhWRdZtcCGr7iSx+DL?= =?us-ascii?Q?TS8h70GnUaRlRIgp9Aysb6suD1OtmRvFwNtpKkQ17VBAo1ZLavCuhS2klocw?= =?us-ascii?Q?V99GNVQO/7HiqV8F5VoFVj4qk6YROgJ4HgRmO1wRdTEFUGT1AbKJPageXEoK?= =?us-ascii?Q?yU4Gskv8e5ZiInc0kJfuHIWO5BzGXqhMXhDnr4IKc4/EdIW51aVmzTtJeVR+?= =?us-ascii?Q?Y9BkR19ZPEJSvuzmCpgpDNK3FCzQq6emyJ5ocw3wpP1c9RfU8Z+mu42mAu4Y?= =?us-ascii?Q?johoGS6b9EaJyx5wLntRiTaK+JVfp9Q/JMmoKV/jjUE75gNQqLUJ+BitXJzx?= =?us-ascii?Q?wnRtI6lC2CEEvuPN54czFR+NRMALWJvsctAZ52jJaFhNV8Pjd80GbplDXiKA?= =?us-ascii?Q?g9qvWAj/qF/PZtGRzWo0Kv0/4//GTl3NFgqtxp1HF1PAnXG8OchlO5EYHP+0?= =?us-ascii?Q?ioWypPChohpeBqTag7uT4Bv6XR9k0nnovLDCQXnTAWOkzZJ5OU9ac11g7TJn?= =?us-ascii?Q?jHSTcX3hwFOE6XlpEcZw3Gmia9W8vOc802hDR5DlUYPRQgio2LmLz76EehxS?= =?us-ascii?Q?t8cNPm8qCEypjduPyRYA69Dkeql1pTvJlWVuLliguWBY/QimB7sYxK+Xjel7?= =?us-ascii?Q?oabd3Gst0K+9cyc/wL0keLe6Ym2eJ9eJrxc5wvcYlbEWix5PS9Z61czQuyJM?= =?us-ascii?Q?oTlrufAeAv/p07ZgzX7g5osz3i05j5ckG32cBFHV92Mgxou7oq/bdIDsNZYr?= =?us-ascii?Q?INKojEQFqkp7f9b6lMrd090uLdvXqysXotIXLS1aWbi6Rj3qbckgMrl/aTWd?= =?us-ascii?Q?6ccyEsW9Nc0q5WsuIsEIyWzLYjGsBvr7iIWUF17I7hUnaoDJZS1BoSVY79IS?= =?us-ascii?Q?WvZVyAPRZ2CuYCXmKcok1XGxV6PLBkea47Ff9a/lksW6P0Sat+A1e9T7P26t?= =?us-ascii?Q?jq8m5QbrToNV5pc9bhmJF1Wdybo32inPHI5obyodrtBKonB6Qb5QPa5Efyc+?= =?us-ascii?Q?gCpjSXQ1YRx1I8RyPo1JWw5whPxssO4Fh3J1yJC8AvLgdpCrcSFfLH9FffHy?= =?us-ascii?Q?zpQHV6BWRoYuJG/FckxQQLTRSEqnkHs/WhK+rZfP2tE49sEwpA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(1800799024)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:33.2066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06fbe83a-5266-426b-d44b-08dd18fdfe8b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B36D.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8596 Content-Type: text/plain; charset="utf-8" Instead of using standard perf_event_attr->freq=3D0 and ->sample_period fields, IBS event in 'sample period mode' can also be opened by setting period value directly in perf_event_attr->config in a MaxCnt bit-field format. IBS OP MaxCnt bits are defined as: (high bits) IbsOpCtl[26:20] =3D IbsOpMaxCnt[26:20] (low bits) IbsOpCtl[15:0] =3D IbsOpMaxCnt[19:4] Perf event sample period can be derived from MaxCnt bits as: sample_period =3D (high bits) | ((low_bits) << 4); However, current code just masks MaxCnt bits and shifts all of them, including high bits, which is incorrect. Fix it. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index bd8919e7c3b1..f95542b75b91 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -271,7 +271,7 @@ static int perf_ibs_init(struct perf_event *event) { struct hw_perf_event *hwc =3D &event->hw; struct perf_ibs *perf_ibs; - u64 max_cnt, config; + u64 config; int ret; =20 perf_ibs =3D get_ibs_pmu(event->attr.type); @@ -313,10 +313,19 @@ static int perf_ibs_init(struct perf_event *event) if (!hwc->sample_period) hwc->sample_period =3D 0x10; } else { - max_cnt =3D config & perf_ibs->cnt_mask; + u64 period =3D 0; + + if (perf_ibs =3D=3D &perf_ibs_op) { + period =3D (config & IBS_OP_MAX_CNT) << 4; + if (ibs_caps & IBS_CAPS_OPCNTEXT) + period |=3D config & IBS_OP_MAX_CNT_EXT_MASK; + } else { + period =3D (config & IBS_FETCH_MAX_CNT) << 4; + } + config &=3D ~perf_ibs->cnt_mask; - event->attr.sample_period =3D max_cnt << 4; - hwc->sample_period =3D event->attr.sample_period; + event->attr.sample_period =3D period; + hwc->sample_period =3D period; } =20 if (!hwc->sample_period) --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060.outbound.protection.outlook.com [40.107.243.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 881D2231C80; Tue, 10 Dec 2024 09:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823346; cv=fail; b=X8ynQ4ncd6LYt7ckaUgapYaio2va7Zn7MzGor3N5BvkS9G4+K7DtV+jP0U19K1LsezQF0Gf4nh0ifFZOiljuQZAvkuWIYQe9ltp5inhU0xDPuGAzbQccsamFNQA44CFG7mVdCanzpwcWLdkGfkXbM9P+Q8/PD39bWCXfbyP9Gxo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823346; c=relaxed/simple; bh=dXVxjJv7mIY/YEnJmqXOZyzHe3BHcoTte7cJFi0tAX8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eZBhTNgSpriSD3AckzdMq/ZJZSS5K7klvuuDdASIGYY/xd6N7f/Zf61Lzu9yqdnpm9/MgIRi5KJl3AXyEwSJovGuN8Q2lXloRz/03igf71p3jg0yBLBTH6ho489RBOJBfkdcLd73MzBDWruPsyDo824rqwkvphTBo3nsBAHvdic= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=U6XtdUn5; arc=fail smtp.client-ip=40.107.243.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="U6XtdUn5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=StbXGOvYhGZw8s/dXnzCh4m3GbuQoHU3S61jTK9T8PK4x4O9jLjWRdbTiMGcYDWDgTe2wtBdL7dwrRih//pRot3jPmmtmHYY35YKTqlRETYtDTtks9MkDvofL6hWVFoihLvr8fY0xEZIQG10Cuc/15OpYexwA2qnBNdpdjUGBgtdrTQziFYSDmiYsvRZ8C5I+VC6Pi8u8+wEHRFgBNRG4CnEvlM3zADPpA6XqKE/W8YyDX+q8d3k41TalMlSe8l6EGxoEs+yiyS6LMh/E/2unogMqk/QqJAHKOkgoUMW+1jvm6pBIVGuedMTCZ0VskRavEC4jTWP2qcoMFqkv0YJRA== 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=PcY1kExmgIkETtefDOJ2ADwu3i9bJZLmUEZUzU1dHDM=; b=D/Vrg3KJuAfY/cN7kd/bpKNkMOrEBfckvEcj10sgcpI/WvpxiDCxOjmbN7VzlTp6aWildjL1B8YjVW55KbL16IAgBB21RpUsIuRYuaoLJWiA7OGjVrqRxVyNaF0Wb7ie3H4Usz+I1zGGHmSZxl90iB3u6A+x7G7EkFhx3NUSG4KinKkceNO7Cv8mzjis+05bRza08CDuEvBOyZvaEhNCTq5LEwi//7RP/AREqcs8AUNaQ+dBpvAsS8BdjUyhOiEw+I1HXcj6yOZ6rEEpt5q+eFHXgL2uZNiIKuFOwc2ND4cM5NnMfKBw2THbdyGkgB1zaG3FHuztmazRRF/M1K3fAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PcY1kExmgIkETtefDOJ2ADwu3i9bJZLmUEZUzU1dHDM=; b=U6XtdUn5EbCGMkuOTzDHwqMrGC7tSCIlLEHuhTCXJE7n9rHw5jsBrskMNc48queJNq0IUusmCUlCdlqWs7uvIso8iSRC2ljvyrCOVbUoFPLZAa254bFY06c1e2j9R068ynDqElGB76WOd1a1nX4dskhltPKnD8AWa/7qPJbKtOE= Received: from BN9PR03CA0872.namprd03.prod.outlook.com (2603:10b6:408:13c::7) by DS7PR12MB6312.namprd12.prod.outlook.com (2603:10b6:8:93::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Tue, 10 Dec 2024 09:35:39 +0000 Received: from BN3PEPF0000B371.namprd21.prod.outlook.com (2603:10b6:408:13c:cafe::31) by BN9PR03CA0872.outlook.office365.com (2603:10b6:408:13c::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Tue, 10 Dec 2024 09:35:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B371.mail.protection.outlook.com (10.167.243.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:39 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:33 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 04/10] perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt Date: Tue, 10 Dec 2024 09:34:43 +0000 Message-ID: <20241210093449.1662-5-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B371:EE_|DS7PR12MB6312:EE_ X-MS-Office365-Filtering-Correlation-Id: 22a4d317-7875-4754-623b-08dd18fe0215 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?l8ZLRzWQmbm4ZGhISCKKb1mwBju1PkkjXs6n+ZCLleVI7f9by/1OgLSOwfW9?= =?us-ascii?Q?//bZpTB6cNe/8kn+2yA8rfFTSyNli5TLRMm+DZkk1l5C+fnwk3qiv2XeOegC?= =?us-ascii?Q?+L66jjhbCBdbI7pEm0Kd8PAAuedP74bbPFnUBcg+SJUa21X6qDLJ4H1hPzlj?= =?us-ascii?Q?MqEK4HVMr4DFjO1Hl///8PQoX3SKKPflbTn4a8m/GL05KyHP/gO8LJXB6dlg?= =?us-ascii?Q?wsV+VaxlRN7oOjLpBpk/x7xgBz7qwnBqCLskv8x0Uhf7ugiEXnWPuwkD8WiJ?= =?us-ascii?Q?emqYQYe99oZ3jWW0kTt75+Q8f/XQUcDb2HuGvfNQS+x3rArROALTc+ADCSsc?= =?us-ascii?Q?CDA0H63Bixg8D5RU4SxeQ5PXAMJH9kaxbWMEXf20bFf/gN29YuD7eaQDVtMd?= =?us-ascii?Q?IK7G4MeIpOJEOSzOgflRLygvq01hiel59kDXxPovyPHLj3+pggNgvu27FYnN?= =?us-ascii?Q?yQpF4+DpgddxsvrCB6LrFGtKkOsZVAjRIuzaOOxQRqTrLQQ2vSYVQsBoHgDS?= =?us-ascii?Q?InbGiYDGzLS8tdp5SwHeOoaUiVt59wmepEc5QoWRem7ZbVAo1pBYcdqULFgo?= =?us-ascii?Q?Ww5EFbAtpmJCS9SzccW/X4K1q9UfV4L4Z65y9I2ja8DxtL6Pgzw4pa6rN7J1?= =?us-ascii?Q?3MddFTLZyvInnG9iO3EQMlkulzDiaVOwBxASwjmQ5qm64JKgYTLoSzrMfSxk?= =?us-ascii?Q?Gc/XhHu1P5RXz5IroiwUDwc+ayAx4L7can56dcqpJ5wq4c1ww22hBuWrgbU1?= =?us-ascii?Q?x0ObEbyw/bXMU2O9Spl1J72n96085H1SORpvuKTLUhpY/8naqRWYhBI0EwU5?= =?us-ascii?Q?yk6efS2MNtzuQcKSja3Xka1j3NdOqM984EDW+OGo3O+YIQXmRmDDPd9lO5BX?= =?us-ascii?Q?iZl1z3qWGyEOPMup8inoxQ1qobNvhGHiGPo3v/3DpMpneQQPztHP5LG6Q7u4?= =?us-ascii?Q?ygDaHmXLSJadfchl/AUbpiO3yYKDnVx7luOsyTJG7AGhGeAB5mPHXCfWcEoV?= =?us-ascii?Q?ZxybbyxMLZmNn0OT+CWa2wOipkydme8F1zrzLDbm8cTUevzAQT6FnlJELLj4?= =?us-ascii?Q?wD/228ewsY0kNdVhIa7GWcK7k7NYPu6nMYKCwV8rFTKJxW1aehUhccxtCWtP?= =?us-ascii?Q?VVn+PcrYUfsSGOM6TwyANgz8hMSoeCMhNELCI6ir5wDrPn8d5F3QbxeowGvh?= =?us-ascii?Q?tNfWdCnaIbz6XeufRl/gr1HbnlNzTrEphK2sCOBHukfXpvLMaI5CrbksMxZH?= =?us-ascii?Q?W/PFZpmg8I+Gr9aBrjfmATfOFyLN3KXMDlQZyjZ8IP0HQ+3i4EfWzQ38U7SY?= =?us-ascii?Q?syydTH3tbGXgjh7mzm6jKp1dXTTJmOtJDhR+oQeT7aPxgA03Hk5OBeLgnSxq?= =?us-ascii?Q?R5y10VKfiKnMxT4xYsTWRBo95uHNSnKd7i+qjjvDwylmnzu4/mmuSL80fnq1?= =?us-ascii?Q?5JWXmkd0llqZgv8jXMbCyIBVeKcKPg6q?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:39.1412 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22a4d317-7875-4754-623b-08dd18fe0215 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B371.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6312 Content-Type: text/plain; charset="utf-8" IBS Op uses two counters: MaxCnt and CurCnt. MaxCnt is programmed with the desired sample period. IBS hw generates sample when CurCnt reaches to MaxCnt. The size of these counter used to be 20 bits but later they were extended to 27 bits. The 7 bit extension is indicated by CPUID Fn8000_001B_EAX[6 / OpCntExt]. perf_ibs->cnt_mask variable contains bit masks for MaxCnt and CurCnt. But IBS driver does not set upper 7 bits of CurCnt in cnt_mask even when OpCntExt CPUID bit is set. Fix this. IBS driver uses cnt_mask[CurCnt] bits only while disabling an event. Fortunately, CurCnt bits are not read from MSR while re-enabling the event, instead MaxCnt is programmed with desired period and CurCnt is set to 0. Hence, we did not see any issues so far. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 3 ++- arch/x86/include/asm/perf_event.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index f95542b75b91..d9c84f1d530f 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -1245,7 +1245,8 @@ static __init int perf_ibs_op_init(void) if (ibs_caps & IBS_CAPS_OPCNTEXT) { perf_ibs_op.max_period |=3D IBS_OP_MAX_CNT_EXT_MASK; perf_ibs_op.config_mask |=3D IBS_OP_MAX_CNT_EXT_MASK; - perf_ibs_op.cnt_mask |=3D IBS_OP_MAX_CNT_EXT_MASK; + perf_ibs_op.cnt_mask |=3D (IBS_OP_MAX_CNT_EXT_MASK | + IBS_OP_CUR_CNT_EXT_MASK); } =20 if (ibs_caps & IBS_CAPS_ZEN4) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index cb9c4679f45c..aff9fc693b11 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -510,6 +510,7 @@ struct pebs_xmm { */ #define IBS_OP_CUR_CNT (0xFFF80ULL<<32) #define IBS_OP_CUR_CNT_RAND (0x0007FULL<<32) +#define IBS_OP_CUR_CNT_EXT_MASK (0x7FULL<<52) #define IBS_OP_CNT_CTL (1ULL<<19) #define IBS_OP_VAL (1ULL<<18) #define IBS_OP_ENABLE (1ULL<<17) --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A86FB1DC98E; Tue, 10 Dec 2024 09:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823351; cv=fail; b=M1OFUtNM2fZwoTo2Mu2sdjgK5QKkJ2M7UotJllWGPt4g2ovBYJilw9nSlF/4LhSpLIIezA8PkluJQTuwou7MAieW5lpBxciLyJT4q8QoSw/jLACTJJDwai/3YW4o9+thDGIBOBY8bX7+R3Kh0fjmW6T/z61SXtFsZUyc8LaZpBE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823351; c=relaxed/simple; bh=oXwMspnklaEKw+3Dnwk+UzHBujLoVmxzLBT/pyUJqcU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ARmCvn4963RoeWy7NupGpaP26tnq++uR1tHbj+wTJqWaZ9nbCjXuPuSI6c+qSZBJUiA/vaX4wWHMzlMyCU+kx5t89fY5iUGXBzhx+lhkUhli1MJEtY/NKlI17wFqacjOOJ/6gzEYFJz94S1BpfV9NAHT1rWihHRW2OsLk7XxgfQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=UG66CuMM; arc=fail smtp.client-ip=40.107.96.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="UG66CuMM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YCXxvJfLRTMcu1OFIXhU5SkL9xgP1fyW07LzgQYw6zvd+IRVoPQgXwB0KQukF63KT1/0wT6DolrQq6NiP7NAO01wevLspZ2hm6XFVthgiS4Ss6pixqwBqbYy5BCsQlkDFCLGo6nUB2k+N1J5eyk1o7ZcRbvSq2kPG6JRCZ1mnEKnOLN9x0kP/Uejx/LXBGfRCIgGg2koLgO26aM8LgIdAVFC75eZk32ekG4ay2HPZ7Pazhw94SpYRa2sHWf7ng8P8wampT4TN/BYmJeepT0tq9R2oUpOuU33vHzSihOdHktXF2WAUEErlMQZt34HGvnRhLxVEyxwrMync2e4Kuwqvg== 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=HwDzLvP8sO/hht95liQJ+am7mc0dDiplwj1UV7IIzG0=; b=Z+UBjknMSCLMzVBXA6nQz5vKDLs0taH/tmQvSkYUEuICsJxZKXbTCNR/rUNv4OUx/9QkPNzdf8P0sgm7E+w4lU7quQlSJpnMoZ+ceudDlo2uOfxfY/rJ7ImNcspyyD8KpFxAX7Z1+KCKOWrrCUfKKKk/Jm3spUL0VMVYQQlDKJOKrhN1hvIuxG0iWCabkRFA+UtW2NGI/0wZw7xED8gq7RVoGGLKK+hAELZgDe20M9ELy6lL5DSzYSjBPZxky+l8Ftzi4TDl0B/rrvWriEMQzKpS+aOGoXLma5CDKXnjJie6+9MZxxNKWCD8n4ikSpZmBkNCqN2JS4Rw4ehUn5C8sQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HwDzLvP8sO/hht95liQJ+am7mc0dDiplwj1UV7IIzG0=; b=UG66CuMMW/ShV53h4cZqJBkg7BXhed3Q0n/7fbjqNjacAQvNR7yRnjjaPhugn9B5hVxoHYmqky/SyJYphq+13f/vOvAlObflMkSEQwSOTEP6BnLZXQb8RA5YuTQj7viGy+XAOtO+99dJSpBF1/sFcZOyiUnXYXp6L+E1eRiqKwk= Received: from MN2PR17CA0002.namprd17.prod.outlook.com (2603:10b6:208:15e::15) by LV2PR12MB5775.namprd12.prod.outlook.com (2603:10b6:408:179::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Tue, 10 Dec 2024 09:35:45 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:208:15e:cafe::6c) by MN2PR17CA0002.outlook.office365.com (2603:10b6:208:15e::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.12 via Frontend Transport; Tue, 10 Dec 2024 09:35:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:45 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:39 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 05/10] perf/amd/ibs: Don't allow freq mode event creation through ->config interface Date: Tue, 10 Dec 2024 09:34:44 +0000 Message-ID: <20241210093449.1662-6-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B372:EE_|LV2PR12MB5775:EE_ X-MS-Office365-Filtering-Correlation-Id: 90fcd872-cd49-403a-8176-08dd18fe05a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?GBOrJvu/+nwt/aK+dQxsb8kCvNGuJO8u7gXX93+xJHEJIvT9JTuVzhUrbWkp?= =?us-ascii?Q?n4Uy9FpqeISYQsL7GPMfdVZVeug4OHOJfRpPwVlWgKv+Ozl9WL83C/UXMFx9?= =?us-ascii?Q?fRij7YDzqtoLJcn2mcZkkipcEjwjJ6bkAA8p+9fhdHDrWyFwR5dJqdczJO1N?= =?us-ascii?Q?haxnyL1eLw9L6CYFms9infAYoIRPwWT/gthNVMZKzJ0W1Ev4wKnjWEGWm6Gf?= =?us-ascii?Q?72v8m7CrIwyteGfsG3/JtL6cYu6y4mI4KM214cxhIcVUoJ3KHXqKDVniaEdX?= =?us-ascii?Q?Vj3XIXI6ltCMSXx65Lzv0MVp+AudoA/RK8anoDjBVKeDCyRrMlslXOCHPMDb?= =?us-ascii?Q?/iDy+W0LHncAT5/RMUYBrBkDQFer6L4Ob2TXUZrpY4n6tnZmH4YODI6x2EEL?= =?us-ascii?Q?DbKaRnLLzWtWmcnF1rddxmALsSztnvnh5DocJHhC9ign+9vM+0+QwkKrR/g8?= =?us-ascii?Q?roqvG1GSz1Pf8LlEohqEApMgTIMN3Jhki9n8V8WXPPq2zerNb6NhPYcbU/Tg?= =?us-ascii?Q?VLG0vXVnkzDDfRZvZcwUD0AGdgYPgOS0cu7rHC/F0jMWVQkM+5eHdC3bpFwP?= =?us-ascii?Q?XXPCweTtp615Azc1fCypZdGrz9eybAAy6gLaynec6eL5YVcXvoW7IVw3DSx3?= =?us-ascii?Q?TUuavfcDrQ034Cu/ITyp5Thfp47GsMYHjHTrhOxHljJdUse0XkzfUiTOPh30?= =?us-ascii?Q?2tEgap2GeO4A9zK74EtjK+6oMGtsQDHz3aFu2Ehais+3Ed1/kJC1mtYecqIh?= =?us-ascii?Q?koFsSvHevBswc8Y0EGFOOwlau76URHO0w1Na8J7hLYj+i0Zn0239G/EpgxWH?= =?us-ascii?Q?5TBKzbLn+xeZgqjF4Io6CuB2tAYkTYI6bOkmDGMIA84p+Vz9ZCou81KtYQc1?= =?us-ascii?Q?TQwKXny0/vkUihLClhMMy2BaeCBwq0sOgqcGS9r9rxE0ofgb006uS81Fc388?= =?us-ascii?Q?GdE/iomKd81SubVXJJAWXcjXYGY/NoPtwrKiUOImhY5QaTcf9bbcsMXIVrjB?= =?us-ascii?Q?J5Sa9zjGoo4xYRcJagEGkl52jaMfexTdP7YV7OI4PKxB2UfECYSOY4g+iGHt?= =?us-ascii?Q?0EeqFwxCvFRcSoyv0OKNJzQD1AhZ2E9oCezo9+CrkT1K+DtGzeZlSTIcKVFj?= =?us-ascii?Q?RHoiY/r1HvKt/2f6fTspSr161zgcoiBEzQ4D+3pF0ZtrNFoN8rwe8TWmE1BP?= =?us-ascii?Q?I0dv4saz85OY/neJosP8aOM+yfy/1eiSLokBlX09BkdZY4JI4MMFZMMg2bO8?= =?us-ascii?Q?0Gu487Qld1lka3Az3dETdSbUnES77OsPN9vaXRv2UY+KdmK38YuTNHxmJ+2p?= =?us-ascii?Q?RBtN4DCTK6JoxGNc/2rl453foKBGn4JzNkmyl5n+von0AZOpmWLnzOERxYQO?= =?us-ascii?Q?SzT4eiyrHuvNEMyNJ7oNm7JwshknSn3qpjG4V6x9qq3wUTP7sv8gdeYYOMRW?= =?us-ascii?Q?AVIAlwrl9fwSkUQX5Zk18zPI0zb55aZa?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:45.1451 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90fcd872-cd49-403a-8176-08dd18fe05a9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5775 Content-Type: text/plain; charset="utf-8" Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL MSR. Since the sample period is programmed in these control registers, IBS PMU driver allows opening an IBS event by setting sample period value directly in perf_event_attr->config instead of using explicit perf_event_attr->sample_period interface. However, this logic is not applicable for freq mode events since the semantics of control register fields are applicable only to fixed sample period whereas the freq mode event adjusts sample period after each and every sample. Currently, IBS driver (unintentionally) allows creating freq mode event via ->config interface, which is semantically wrong as well as detrimental because it can be misused to bypass perf_event_max_sample_rate checks. Don't allow freq mode event creation through perf_event_attr->config interface. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index d9c84f1d530f..3e7ca1e2f25e 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -315,6 +315,9 @@ static int perf_ibs_init(struct perf_event *event) } else { u64 period =3D 0; =20 + if (event->attr.freq) + return -EINVAL; + if (perf_ibs =3D=3D &perf_ibs_op) { period =3D (config & IBS_OP_MAX_CNT) << 4; if (ibs_caps & IBS_CAPS_OPCNTEXT) --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2050.outbound.protection.outlook.com [40.107.243.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 192ED238732; Tue, 10 Dec 2024 09:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823356; cv=fail; b=jr8jLvLXqCokU+j3IoUt+q9Fc5FEgVmU+UZ8HNz8c1O42EFAfxAMjhRb+uAHWhO0jiOwoR9BB5GRd57OZVGCz0o9MZm3L95DigXdUA82AfRuNMH/yDN0SNXcoDaVa8kh7VzAp7yCwfr1+K+UdmGWAp0rTBoGifzJjQ6WZtCZYjU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823356; c=relaxed/simple; bh=6DUSl3hOkhElUC7/h6ai+56QchQyf6WiS+ilpvkxes4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jg6GHb17/7vHZIS8t0+wY5su/EmZW1j4Qxf3N/rSE1QEBHmGcZZpjGs7bFN1QPHN/SKpOfqPu+sc+5/AC1Xt1JjvzDwtmvaIDBOy7bWbnj1PD1veDeAeXOU0YPQqfrtSX0EW1Oz44i+K/xADn73wPXH9FNsmhAfRxarSzEsmIuo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Hs77jbZ0; arc=fail smtp.client-ip=40.107.243.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Hs77jbZ0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KGICtJo9Fmjsn8gLsc595GHue3Ilxomfs03+T+sGuGBGheQV/i1361LLt6bNAyJexNGQjzMUsOJHA9SN/EpViUJl9Pj0f+PhCsEBOty64Gp9O6AO+J1ae0/elXL7JJLRxdV1gX5GqoqPn/mEqu6WW6qQHEKkJ3hWIPlru/03aGptqWxEI+ffHeW2gNEuGzFOed/BwnYas5SDIdTYPf4TBylvA54ihKwr003ugv9n4p+cU4M/jkc6YMr+8WOkRTIkb+TqE2fQuXJomHm7kaMZxNVSjxS0GFMgFQK3dhbHvbvnZrATINxV29kC2b6kOHFPpWVvaPWzeVl85y54XlLCZg== 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=OngcRt5TyTocHT4x/EO+sj96PqNmn5WHeeSVujNmMaQ=; b=pNS4vIJB8iJGsNWYG0yXjiDvAli0vlzspQo2yI3zxsmhqTeW31Z+qUJoyDh63JX2/JZb2dhOn64MWmW+jdi0YkW8PdjuXHBB2P4T9pwsRudARlrMX5qSZW6QbyEUBzrdEXLB/3JYZV8tmtQFqD+4jPbAzWqDh5K1o3wTvlkMak/cHkA9HOMQGjne6tzKa0YFu8MxzSKqM9EKM+fwmBYTKuTNaFKYJqet5lAaC8aCBP73ibLbmgCQ+LfOHUz+OXYKEBC4vkmRIl+AeRQJAvHNBT0ytCxCDSdr0QWps9+hAeTU1il48NeA4tnfY9dQ7cPI4+AaJY4yx06VCmOFVvh+QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OngcRt5TyTocHT4x/EO+sj96PqNmn5WHeeSVujNmMaQ=; b=Hs77jbZ0gs+t3v8d/Jolv1ukWnNzIqHO/p9rCXe9Ew3vao6PoAvUxyqw3oO3CMVmd3FApFRhKrI/BvPPhcWi4qP7GeJ+88yZZxLwxtG9TeyzSuQIeD9lYcDJ/C6v0UcKJ7GxOj+RgfHLRU8K/nSjQ8x/dkD+Fbtdv6wvI1pm1Rs= Received: from BLAPR03CA0080.namprd03.prod.outlook.com (2603:10b6:208:329::25) by SJ0PR12MB8116.namprd12.prod.outlook.com (2603:10b6:a03:4ec::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.20; Tue, 10 Dec 2024 09:35:51 +0000 Received: from BN3PEPF0000B36D.namprd21.prod.outlook.com (2603:10b6:208:329:cafe::39) by BLAPR03CA0080.outlook.office365.com (2603:10b6:208:329::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Tue, 10 Dec 2024 09:35:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B36D.mail.protection.outlook.com (10.167.243.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:51 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:44 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 06/10] perf/amd/ibs: Add PMU specific minimum period Date: Tue, 10 Dec 2024 09:34:45 +0000 Message-ID: <20241210093449.1662-7-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B36D:EE_|SJ0PR12MB8116:EE_ X-MS-Office365-Filtering-Correlation-Id: 23933f46-d93a-4422-5631-08dd18fe0933 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?X2Tal1qrLambz52/wJ2qgxslLCQHsaoyMAPPppjdSFb8AS8uEK7fbqk7dWbj?= =?us-ascii?Q?SINjjAFKdy/sAlck/Sa5V+jiG1JAzghA62HAnDcWakO+7kig7kIzzfcxLJLH?= =?us-ascii?Q?Tm+ZwpOpJwWO9pKhJa68C8KDgjWMsfFI+pYdfRbXaBvj8b1LcFUtnGEKfjEd?= =?us-ascii?Q?3CoILWpVpf0a2pSeTebWmzwcBRmSZx6OKt4/suoQANWLF7uNb4mtlNxgZDFR?= =?us-ascii?Q?JXQX5KPksllcgGHvkZ7KHtNVN+srkUHIDDp5yGPf5FaX+5nstriWq7cL6BKf?= =?us-ascii?Q?a/2ZY81X1S9uddukn9KtaZZKv98EUnerEKwbAo6oUc8umD5Kv+YcmwQ2EgfT?= =?us-ascii?Q?vteYTJp2oPArT6aXgn5T1zFJ1gOorJw1Nb9cVNWmrhlRtHA2KXSKkMGmLtQt?= =?us-ascii?Q?lGg5eXklbAHFBacSnkIWSebZ6b/vKRIvtoU8UrB9mg/AjShjASbjxCVaFKgs?= =?us-ascii?Q?hOLAo4+XI1oSsmLR1wKfbQmXOVQsddpgAwqZ9cu3e2dERHPaVONxOVp4wOaE?= =?us-ascii?Q?PD9npoQb3dwSQT/LxO46GqE2pFW7yFEEim3zrltOabTavcf9fdimKzA9GYiT?= =?us-ascii?Q?ETpg07bJfAwrpStJrt59H+MeQxzogmlsKB9Wj5xTYJtKVOx65SYPMRi4m6QD?= =?us-ascii?Q?YkgpL1qgLCZtIej3yhMqTszzBk1j9t6FxOr9jvgT2HUM13IFizfuMO+6YOV5?= =?us-ascii?Q?saCFVIyV4w36T0J2oHejcgeqwLHCPCF42mCccX6GMBWQnZ0/UbThQzFcLd/V?= =?us-ascii?Q?dta8j6daiw8qgFUtVlR+ackBTe9mhJ/JxwNE41EvDlG7Yh0raAEesETODt1b?= =?us-ascii?Q?mkZcPi0ZsHpZjfweFneUaQxuyOFTWa73ThTxOQYO+qaog22ypPnB5SvDszzE?= =?us-ascii?Q?EZX75dRsOQGy6yR77mTRKFlDz39OAjgEWMv5TSvZy7U8HTws5rerGVJ+3HCF?= =?us-ascii?Q?/ZVKJ/gVpMAiRQcpVCVJuqr85creWIVTIHjJcAkKePM5gChMqyB3qleOjug3?= =?us-ascii?Q?un7uorJk1y4GlRcWwFmI0h36VI5wM2qoDTzEDcQpF6iSDBx+tWTayyzx6Bdg?= =?us-ascii?Q?uoL0jz3992KtL6zUhsQEj9+IA6tnu8pggiltsCCmW/n6/mS3UrXSYkSSNwXL?= =?us-ascii?Q?JMJ+H366jxoiijyVv4wBE5CHwo5R2vxa1tsYPRBqRz2BbZ8Gv2Qkvxt8PgJO?= =?us-ascii?Q?EWjwb7EdHaFBTs+qBkfN2+JuTm3Dnx9NkUCEBsf8eCiwFUxRRb3BrJKuJZEQ?= =?us-ascii?Q?mKHs38SkhaKUqpwekd+Wi9JaPBoQ5bsQfaYElDx/FgyKczz0f46QXbBLO2xv?= =?us-ascii?Q?fVkeZ/faT0cvn5/16L4/jU4KYgDrrqZsxRo0M5wAplNeu+OqNL9kHX08obwa?= =?us-ascii?Q?boT5ZzJOTsZtRNBznHrxfPTiN9JTrmHXLaqu/r/Giwq10giZaA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:51.0972 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23933f46-d93a-4422-5631-08dd18fe0933 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B36D.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8116 Content-Type: text/plain; charset="utf-8" 0x10 is the minimum sample period for IBS Fetch and 0x90 for IBS Op. Current IBS PMU driver uses 0x10 for both the PMUs, which is incorrect. Fix it by adding PMU specific minimum period values in struct perf_ibs. Also, bail out opening a 'sample period mode' event if the user requested sample period is less than PMU supported minimum value. For a 'freq mode' event, start calibrating sample period from PMU specific minimum period. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 3e7ca1e2f25e..7b54b76d39f5 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -86,6 +86,7 @@ struct perf_ibs { u64 cnt_mask; u64 enable_mask; u64 valid_mask; + u16 min_period; u64 max_period; unsigned long offset_mask[1]; int offset_max; @@ -308,10 +309,14 @@ static int perf_ibs_init(struct perf_event *event) /* raw max_cnt may not be set */ return -EINVAL; =20 - /* Silently mask off lower nibble. IBS hw mandates it. */ - hwc->sample_period &=3D ~0x0FULL; - if (!hwc->sample_period) - hwc->sample_period =3D 0x10; + if (event->attr.freq) { + hwc->sample_period =3D perf_ibs->min_period; + } else { + /* Silently mask off lower nibble. IBS hw mandates it. */ + hwc->sample_period &=3D ~0x0FULL; + if (hwc->sample_period < perf_ibs->min_period) + return -EINVAL; + } } else { u64 period =3D 0; =20 @@ -329,10 +334,10 @@ static int perf_ibs_init(struct perf_event *event) config &=3D ~perf_ibs->cnt_mask; event->attr.sample_period =3D period; hwc->sample_period =3D period; - } =20 - if (!hwc->sample_period) - return -EINVAL; + if (hwc->sample_period < perf_ibs->min_period) + return -EINVAL; + } =20 /* * If we modify hwc->sample_period, we also need to update @@ -353,7 +358,8 @@ static int perf_ibs_set_period(struct perf_ibs *perf_ib= s, int overflow; =20 /* ignore lower 4 bits in min count: */ - overflow =3D perf_event_set_period(hwc, 1<<4, perf_ibs->max_period, perio= d); + overflow =3D perf_event_set_period(hwc, perf_ibs->min_period, + perf_ibs->max_period, period); local64_set(&hwc->prev_count, 0); =20 return overflow; @@ -696,6 +702,7 @@ static struct perf_ibs perf_ibs_fetch =3D { .cnt_mask =3D IBS_FETCH_MAX_CNT, .enable_mask =3D IBS_FETCH_ENABLE, .valid_mask =3D IBS_FETCH_VAL, + .min_period =3D 0x10, .max_period =3D IBS_FETCH_MAX_CNT << 4, .offset_mask =3D { MSR_AMD64_IBSFETCH_REG_MASK }, .offset_max =3D MSR_AMD64_IBSFETCH_REG_COUNT, @@ -720,6 +727,7 @@ static struct perf_ibs perf_ibs_op =3D { IBS_OP_CUR_CNT_RAND, .enable_mask =3D IBS_OP_ENABLE, .valid_mask =3D IBS_OP_VAL, + .min_period =3D 0x90, .max_period =3D IBS_OP_MAX_CNT << 4, .offset_mask =3D { MSR_AMD64_IBSOP_REG_MASK }, .offset_max =3D MSR_AMD64_IBSOP_REG_COUNT, --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2089.outbound.protection.outlook.com [40.107.243.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 105F11DC9B8; Tue, 10 Dec 2024 09:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823363; cv=fail; b=oTUDOon6mDBdgBvQIqkJVULVU2MXaQYll0CMjd73opg2tCHJLTPDvNP/kTP49uc7wQVKfBcGPi0KWIjmRhAegIilydPPF+KfnlyrHuev7YdWFIr6XpKlRZzkQhGdzLPQAuC//olu5kYgz3DWgKjF5lplSUCfruyPkQjHYK1zdUI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823363; c=relaxed/simple; bh=i0A3OCkDuilZk35AaFJGvtjNUXlwAi176YnfoGaTVoo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jTMc8uBTAlTdLd2139RI0tQKyPMAlrpFmJSxXLsZwS1Qe4KUUJJ2caSAMPY3MbCqc4+udznyB0T5lbeMzJYZidVhLtK5JPXCtyzoBSMztNI7aiUm2qEu2KdM3GzUkcoyJiCZ0nT2V/fN9gmcLhD1x6LAAXjVT6mZo8Yn7IQxTjg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Ldu4xmDk; arc=fail smtp.client-ip=40.107.243.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Ldu4xmDk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=O4CvVU7JPLin7JSbzTE4PfztTQbaoRfhcHQWjLVDxG4y3BSt+JnJ3U2qLtVhbg2P6R1mIUxDMe/KJ+1qz3u7OudO0lWvBie9wd1VfuHPPdQpUU78ECFE4+q7oBUNIMBJg6UWXvzqt/KM+frMOGEu23By2ZDNLle+590EmgbPNOjZjFEZgZ3QXX4MMyGC/jwLCqxcbkaaqj7vPW9hx7joJ+09PXRvOWP6L0BuqgidXwALdIWt8393MIj9XfPUyA7bCoTokuOAosQs0b2KDDc0JcnOdL4iLOOlUAEe3iQuFxbcIsRZ9IMRkO5aNkwktPGWsLNRpmP1BIYfVnSxRfQ2wA== 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=yahYhVz4twi48hph3lwzlrT/hp2CKvMmSCu2tdlGwIM=; b=qTzjm1Y6Nb2Xgaepc3aoaHDCLD/H3CC4ERa6LUqqxoTC9Z88cAPPxEEeGfIfG1FP6rPmtew1y+D6kbuRjIyQq31ofU5AhvCP6MJw4fPYn06ovYmuJI1YfZ4vdeNDwZOXhce7veWtt8flh6fhalv+AS6nMlmLe032AE8j7BgIEJJkEpo0wwZENIS384sMBvi/f6g4V2T/coaFX+RNNN7Umnt9ucZNso29nAWRXWSR3jJ11UAGayhdYZTo90yBsTdSzljsdPHcgiVn+MV0caQWpJneZK2F2cuhQal83URyb6f9PIsTB4bYWXcI4yfIwPDy0rCsW/QIKtLeM4xpR6NmLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yahYhVz4twi48hph3lwzlrT/hp2CKvMmSCu2tdlGwIM=; b=Ldu4xmDkoOFxqYG8DTwtO5oEYLuSm8yB+Enb4ERQ8VPPZM3lNYXe6nJpCKEnlh6v5TwHkgqF/ZjI6uHjbzBYdIJT7Nm3kcQUU+p2iDuLCnAOCT+qVxYVyMg1A9WL6wJPt4rpcCG9oxxo/vVL7go2Oa9gi1WxiJoyqhNhLMxT2As= Received: from BN6PR17CA0036.namprd17.prod.outlook.com (2603:10b6:405:75::25) by CY5PR12MB6407.namprd12.prod.outlook.com (2603:10b6:930:3c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Tue, 10 Dec 2024 09:35:57 +0000 Received: from BN3PEPF0000B373.namprd21.prod.outlook.com (2603:10b6:405:75:cafe::24) by BN6PR17CA0036.outlook.office365.com (2603:10b6:405:75::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.9 via Frontend Transport; Tue, 10 Dec 2024 09:35:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B373.mail.protection.outlook.com (10.167.243.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:35:57 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:50 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 07/10] perf/amd/ibs: Add ->check_period() callback Date: Tue, 10 Dec 2024 09:34:46 +0000 Message-ID: <20241210093449.1662-8-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B373:EE_|CY5PR12MB6407:EE_ X-MS-Office365-Filtering-Correlation-Id: 83bb6731-16c5-430e-735b-08dd18fe0cc2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MZMxaY9F2ZGYq2hlM1IAFM7h9cn+tzyWvu4C/xYj2mtZML34DyPchfOMjhmd?= =?us-ascii?Q?5lOyES6aKrKe95tRwRwla6oAhx1E8USY+QqAu9xtNw3uZJMD8jhDlIuhOACh?= =?us-ascii?Q?I0dPhI0RdOJIrcwmDC00bjmOnfkSg8wVdKEF0LhOzdWiXsK/YHbGjbmOmOW3?= =?us-ascii?Q?+vC/0PL0DZReqwJ/bp3vyXndUYcUMd3zisb5VLSbkJzfakL1TdLHo4OsxsTL?= =?us-ascii?Q?r26MXmUeSoK/RRiugWPnWjlfY0HOfz97RKBGVI/YeVfIe+nwOEwFAcVgqCQY?= =?us-ascii?Q?x/JtxCnAzr+eTgKh0fezUvJA0FIDLksmWRPfPyO8v3+TqZDCWefiurruc6Ch?= =?us-ascii?Q?Au4KCaexQmavt7r9+EuvnZeuT4sC/ouSZfTv/YWy2MsAtOSvaTbIx8gMkVQr?= =?us-ascii?Q?zfKpXFMjTOJJu6q8z4cq/iZla/M8V99GfyMC615fDcXsQSztoIgwQLHCJXZO?= =?us-ascii?Q?p4XeCwNjtp+bS3BbhSOqK9/kSWeZW31zIMzs2bBOgAK4ZFVJlyGE8nJNqEJh?= =?us-ascii?Q?AgMkacookkuktX9geVWWLLa0WUwdCzhaj83hC69CMmJdbxef+AQrpoeRJQJL?= =?us-ascii?Q?vf+1LSeySS1tC/Flns4p/LMLl647/7Gsyvk8Ky5pcfnkIpyT6Cg9EElta37o?= =?us-ascii?Q?GX1I4rfQC0NOh5WClC4Yy77jrk3/7PJISUNAgb3hbhOf3ioBc0KZiskP5p0K?= =?us-ascii?Q?Xem8z12JY7VTmaDOwhjJFnnzxYN4MKgFvPxc8WPcyw/BeDLEpFUagGS7eKgJ?= =?us-ascii?Q?4Wv8dvA/k2OlyAoynjafkLot/Ird8EBG/uBuKxk0P9rz4WH0AOacw+1gqhaH?= =?us-ascii?Q?+cqOkklAhsm9AApbHdNtxAzXdwvdZjv+6QasYZANVXKmQ2kcF1Rhd2EEgXtz?= =?us-ascii?Q?DHlWjzkfYdMrrhT9Qb3vGjivyd1QTSHsGy+K+EYOM8QNZon8e5qpQ+1t27Be?= =?us-ascii?Q?mtChCL0TnaCKeSIJv4cUU5tmflSqUH9nUAeLcxZhGNyE4A3q63WuGwzn6oyx?= =?us-ascii?Q?xk7eCB1g3q6f1VuTYALreZKMIlvAozd/adQA1uSMUhFEPUANaJIWvp6aefuy?= =?us-ascii?Q?hyJoKshDKSzlPlGHaTOwewMSML76WJrLtwFZMQQh+OmrFfWPbtANKjvOwTHu?= =?us-ascii?Q?rwbyVYXKtR0XUpyJMWN41yatEMphXLB25aoqFApJWDtD8YvKym6Oi3X94HBE?= =?us-ascii?Q?LINeVS9WHiczeoQoH9HiEPvDhqbdkMhJkAQoyFi/0b4VKiv1Fjqp17fl4S0F?= =?us-ascii?Q?MMYakBL++H5an/jW1sVI3akvpwrfiYQFhiHniVt/OfP1zAwDW3O75CpEZrnO?= =?us-ascii?Q?5qO8V2TN/lfU4Bm5vF1uVdoSXqUM7CPahQJzWHpOOvT+SKBJ/B9nq6hdDcEa?= =?us-ascii?Q?J7nAz35T1sA3gUfDuogtzLnD6iejKqvOkbC1OMtLgOimhkmBxWv8QQi7+GEn?= =?us-ascii?Q?rGp0w+CBShqV5YS4DJbq+EA5E5M+9jaj?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:35:57.0683 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83bb6731-16c5-430e-735b-08dd18fe0cc2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B373.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6407 Content-Type: text/plain; charset="utf-8" IBS Fetch and IBS Op PMUs have constraints on sample period. The sample period is verified at the time of opening an event but not at the ioctl() interface. Hence, a user can open an event with valid period but change it later with ioctl(). Add a ->check_period() callback to verify the period provided at ioctl() is also valid. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 7b54b76d39f5..aea893a971b6 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -564,6 +564,28 @@ static void perf_ibs_del(struct perf_event *event, int= flags) =20 static void perf_ibs_read(struct perf_event *event) { } =20 +static int perf_ibs_check_period(struct perf_event *event, u64 value) +{ + struct perf_ibs *perf_ibs; + u64 low_nibble; + + if (event->attr.freq) + return 0; + + perf_ibs =3D container_of(event->pmu, struct perf_ibs, pmu); + low_nibble =3D value & 0xFULL; + + /* + * This contradicts with perf_ibs_init() which allows sample period + * with lower nibble bits set but silently masks them off. Whereas + * this returns error. + */ + if (low_nibble || value < perf_ibs->min_period) + return -EINVAL; + + return 0; +} + /* * We need to initialize with empty group if all attributes in the * group are dynamic. @@ -696,6 +718,7 @@ static struct perf_ibs perf_ibs_fetch =3D { .start =3D perf_ibs_start, .stop =3D perf_ibs_stop, .read =3D perf_ibs_read, + .check_period =3D perf_ibs_check_period, }, .msr =3D MSR_AMD64_IBSFETCHCTL, .config_mask =3D IBS_FETCH_MAX_CNT | IBS_FETCH_RAND_EN, @@ -720,6 +743,7 @@ static struct perf_ibs perf_ibs_op =3D { .start =3D perf_ibs_start, .stop =3D perf_ibs_stop, .read =3D perf_ibs_read, + .check_period =3D perf_ibs_check_period, }, .msr =3D MSR_AMD64_IBSOPCTL, .config_mask =3D IBS_OP_MAX_CNT, --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2063.outbound.protection.outlook.com [40.107.223.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A368F2080C5; Tue, 10 Dec 2024 09:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823369; cv=fail; b=MyhlsvbIqNhYTo86sads9z5tSTCvZQKm5oZexHSaAzygnGw9KsPRTN8SMkkW96egBS5dUS0uK/M64UXs3yYTbyBiL5yv9K78rMOOjs/XxwOSgkNdcms86dHpU9YAB54mV5c1lOieAMDzGFRdIgJEINZwFfPz4lbMnyhzabJExkE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823369; c=relaxed/simple; bh=ef6uWAO2V8mdUZUy94/vbZPIN/G86x3iyNhkUcQ5MHE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cJ8ysU3wzu38ML7+hAn9DnzmPkwSkHmmx6ttWaxfQRuOL9jyqaVGKg9XnVVfSJsampQ7ainExxuzDkN25NqHM1QnMgwUtsYxT6pGxr/fyfMe1la4iqWpFyxvgy3bUNgqDH9ROMrO5SiYttpcQK6nIwheOYTs7FXQUieYCtncI8k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=xxZFNEEu; arc=fail smtp.client-ip=40.107.223.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="xxZFNEEu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D70WXdzgv+l3pEYCPKRq3hm4LZ8BFrYBp9rvcZ8VybrRYItJ8T7Yvwa5rFDXfO2OK4ethkxb2DHM5cr4B+5fZOVPri0LZMuD2+AdUhfmpnKIrgZJY9orLg3Pbbv2sl3QVxUO76kiTv+j/sLF0yy+Phr481x91IGmwEOxLadspSqv4fjabbymWbZ0ZHlqVtNAa1/1YXaXtTfK88Ll33Yt6nIYKrGJBfIiFi7+0BjmA7AkhQIlL1V59oN8GyiTD0GFUTPwUdnIXsDDJASR3H1IeKGUBcb2Imbs+8Si1Q1t486j8NWcZRsruqMxLW2VHlAT9SwydX7GmpLF/jioR0hdEg== 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=ePMNRwKyiSsA1gn+/WRfWye0ct5yXvD7Nkg/J2TTYmo=; b=AGJ6nVQ3eE8lENlCZ1SMEnldcEZMOLxmPzJFEnJ6lfuHLqU29ZocRzpQVX6omzaiTzbP/Xq8QyOUI+bXB9x3mYI0paMC5+HvOL96/F2y3dnGgrrM5T09Sb+fmrdEmebLflRgMoOB9K0DA26X19afu0jn/44pdis6ZZCuBjvqxVFCEKcF/XBsZoxPFXoh0PvoglQaFROYkNaedW/7AhAN6ClBWf5sInr2BoklqnUH1b/WW5F5bZb7C2RORcXU6PaEAnGBUbOLkZGpaM9e08HZYSvCNP8wN8ICuJfqfasCDGC06OOni6H4//MBAAjU3/oAofPbpYv2nl2MwCDxJ3xBOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ePMNRwKyiSsA1gn+/WRfWye0ct5yXvD7Nkg/J2TTYmo=; b=xxZFNEEuOU6H+1et28PTuZE4meF2x3p84mnUjNR2Zbbf5iPu2AmYL0YNHwiUxRnZ1+Vw2QM+fJlF9XMWqY97o2JSujkjQy4ln2qoqyfXyC8/X2L120x2wjECmj3cCSZbkrOgBYxPKYa+7wI2mxE90t4CoZ0wHqzFQsXQOhZLEUI= Received: from MN2PR18CA0012.namprd18.prod.outlook.com (2603:10b6:208:23c::17) by CYXPR12MB9387.namprd12.prod.outlook.com (2603:10b6:930:e6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Tue, 10 Dec 2024 09:36:03 +0000 Received: from BN3PEPF0000B36F.namprd21.prod.outlook.com (2603:10b6:208:23c:cafe::11) by MN2PR18CA0012.outlook.office365.com (2603:10b6:208:23c::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.20 via Frontend Transport; Tue, 10 Dec 2024 09:36:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B36F.mail.protection.outlook.com (10.167.243.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:36:02 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:35:56 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 08/10] perf/core: Introduce pmu->adjust_period() callback Date: Tue, 10 Dec 2024 09:34:47 +0000 Message-ID: <20241210093449.1662-9-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B36F:EE_|CYXPR12MB9387:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d5af772-6e1d-441b-1d59-08dd18fe1043 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gto650qhIQg11DkS42u5jxdY3qCmOxT+XUC4jxe850y/8qPlcWnYVD3s7JIv?= =?us-ascii?Q?siub+iWX7qpFNIHFWujrx5c+npJcH79DahQqe2IxHdRMaGHL6dlveOvkprx7?= =?us-ascii?Q?NlQLXnYYCtc/zuPnyGK+FNrPD9K1tWyhg2tBrPWfk2UEvQBBXCQ04pJuOxhs?= =?us-ascii?Q?m+FE0is9y3JHig3ncz0hiITXmSDBT7TCuRrnQAt6/F/6n9XqTJX8TF6uDzg0?= =?us-ascii?Q?uivgBuJtH+pqB8oS7AmV2K3fPCKIRMuvx/Qpdza6qVjvtkXKuFOa/FQNMXvE?= =?us-ascii?Q?zUggPMXmm3SWCpvq/v3liUwC4+WOIfdtjIt/VFz5YO0hNhTm6FlH3skDT7td?= =?us-ascii?Q?UhzG5gRINqNhagMMTsx9VS5JKyYWHanKZDqjGGRejlRmy2ks1mltqDGgxbpV?= =?us-ascii?Q?LWlA08sIWOHOlgOslsj8RCqQlM3fCnJ+UOKwzDwXr8S9nYmIzxxjeJPmCWHS?= =?us-ascii?Q?gZe6lqgQbgGy6I3cyaValOXOx8A0ITKD7Nc6z8Wc7bCs6rOnHkKTr38CriIG?= =?us-ascii?Q?ZKFjQOimYz36aTUvH9oqWRb5r25bFvG+43n2zL3suE2b+qgt0glztAFpEpMs?= =?us-ascii?Q?5SQ31DkMI5y+SRZ3wwulS+Nv/7+g4j25VYb9wwmqJP48KzXJtTOX5ibExaJB?= =?us-ascii?Q?U72b9LSwMWmW9+vM/zuFE/4Pu/WGIBwi2t/T8Z1W7tLNudZKo7Mg3Px3/Tws?= =?us-ascii?Q?EweuweD9h2i/tfJulSCV57aXbf0PbotrfgaE7O+GLnKbzkz22q7uwLl5lmI2?= =?us-ascii?Q?tsIiW/PGLvFzfk7+X/RBNvNpNgsH+jSvJ8n+RVILtTJgwLd0a36pYqAkp3QI?= =?us-ascii?Q?Yu0m475XpUoPHHSC9YaB0m+WoLmCHzTEge+cr96MiJpg7RDDFiZmDbCIMz4B?= =?us-ascii?Q?s8bdR6pUzyJmyt8RbRDE2o4YQ0hqNnwB3HoYa3rEibUFPNA8Zwk/b/POh5Tx?= =?us-ascii?Q?wHQ1VXQpVoUUqJHbteI2cdronp9MLj+tRpzZnhrX7TGpc8qVROHIorroWgM+?= =?us-ascii?Q?lP2iup/JpliXs7HX2eqnkCBt1l7vq+X37+WLuXcGACqLKf5g4mWi6PrsuNSP?= =?us-ascii?Q?c1YOgH2ipJkhorn1vmx26e84hdGAzrPkhokpySfyNEaC+GWOKBGAjUi1nQOn?= =?us-ascii?Q?ZxKpF3otv6hoyOKXpMT6HX9r3Iam9rZU1pG50BycsURJ8HCg+G7bs2AqRvQt?= =?us-ascii?Q?qUXmnJ0TZwXKgbEdfb3AkRVdGzZoicSmOt+otehtNofmrXL//qbBlHY0Ots7?= =?us-ascii?Q?JxDL3ywDTBD13rKBPEpAzb+74V0jmb+u9J80iCZEfoqA9uO9HNb4ABu7Wtla?= =?us-ascii?Q?QLMeG0LAEwfcuMg3OPit9s9F/kSh125jwpboRKCrXUs1XIntYbDr3MyITW0e?= =?us-ascii?Q?IepLD64Fv//1cJjYR6xosu3tVU0tdUITr1zEDZj/ex7F04+UyA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:36:02.9290 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d5af772-6e1d-441b-1d59-08dd18fe1043 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B36F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9387 Content-Type: text/plain; charset="utf-8" Many hardware PMUs have constraints about sample period. For ex, minimum supported sample period for IBS Op PMU is 0x90, the sample period must be multiple of 0x10 for IBS Fetch and IBS Op. Add an optional callback adjust_period() to struct PMU to allow PMU specific drivers to adjust sample period calculated by generic code. This will ensure the sample_period value will always be valid and no additional code is required in PMU specific drivers to re-adjust the period. Acked-by: Namhyung Kim Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 11 +++++++++++ include/linux/perf_event.h | 5 +++++ kernel/events/core.c | 12 ++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index aea893a971b6..db6dc7b231e2 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -586,6 +586,15 @@ static int perf_ibs_check_period(struct perf_event *ev= ent, u64 value) return 0; } =20 +static u64 perf_ibs_adjust_period(struct perf_event *event, u64 period) +{ + struct perf_ibs *perf_ibs =3D container_of(event->pmu, struct perf_ibs, p= mu); + + period &=3D ~0xFULL; + + return period < perf_ibs->min_period ? perf_ibs->min_period : period; +} + /* * We need to initialize with empty group if all attributes in the * group are dynamic. @@ -719,6 +728,7 @@ static struct perf_ibs perf_ibs_fetch =3D { .stop =3D perf_ibs_stop, .read =3D perf_ibs_read, .check_period =3D perf_ibs_check_period, + .adjust_period =3D perf_ibs_adjust_period, }, .msr =3D MSR_AMD64_IBSFETCHCTL, .config_mask =3D IBS_FETCH_MAX_CNT | IBS_FETCH_RAND_EN, @@ -744,6 +754,7 @@ static struct perf_ibs perf_ibs_op =3D { .stop =3D perf_ibs_stop, .read =3D perf_ibs_read, .check_period =3D perf_ibs_check_period, + .adjust_period =3D perf_ibs_adjust_period, }, .msr =3D MSR_AMD64_IBSOPCTL, .config_mask =3D IBS_OP_MAX_CNT, diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 8333f132f4a9..4dcc51f5d2b6 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -582,6 +582,11 @@ struct pmu { * Check period value for PERF_EVENT_IOC_PERIOD ioctl. */ int (*check_period) (struct perf_event *event, u64 value); /* optional */ + + /* + * Adjust period value according to PMU constraints. + */ + u64 (*adjust_period) (struct perf_event *event, u64 period); /* optional= */ }; =20 enum perf_addr_filter_action_t { diff --git a/kernel/events/core.c b/kernel/events/core.c index b2bc67791f84..e71aded67ce6 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4192,9 +4192,9 @@ static void perf_adjust_period(struct perf_event *eve= nt, u64 nsec, u64 count, bo if (!sample_period) sample_period =3D 1; =20 - hwc->sample_period =3D sample_period; + hwc->sample_period =3D event->pmu->adjust_period(event, sample_period); =20 - if (local64_read(&hwc->period_left) > 8*sample_period) { + if (local64_read(&hwc->period_left) > 8*hwc->sample_period) { if (disable) event->pmu->stop(event, PERF_EF_UPDATE); =20 @@ -11519,6 +11519,11 @@ static int perf_event_nop_int(struct perf_event *e= vent, u64 value) return 0; } =20 +static u64 perf_pmu_nop_adjust_period(struct perf_event *event, u64 period) +{ + return period; +} + static DEFINE_PER_CPU(unsigned int, nop_txn_flags); =20 static void perf_pmu_start_txn(struct pmu *pmu, unsigned int flags) @@ -11856,6 +11861,9 @@ int perf_pmu_register(struct pmu *pmu, const char *= name, int type) if (!pmu->check_period) pmu->check_period =3D perf_event_nop_int; =20 + if (!pmu->adjust_period) + pmu->adjust_period =3D perf_pmu_nop_adjust_period; + if (!pmu->event_idx) pmu->event_idx =3D perf_event_idx_default; =20 --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2061.outbound.protection.outlook.com [40.107.223.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5E273DAC03; Tue, 10 Dec 2024 09:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823380; cv=fail; b=aHm2md6HipnALvEmd7IYVecPZLINVNE9Ml3UivIzh4LXfJjSPBrzENuzbVBX5GzKZdJbai+67pi7BZyn8fVo4XJ6NYFFNU57pEcomELugvjwPkXPXbzUUwZKLmbn/fZM388yKfIykLWOnj/dJSOsMzgDbbtdJBWnful1GONf4jk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823380; c=relaxed/simple; bh=drxzPZRjUmQywzoZnjHpe/W9Q2rWV0XQlFe7j6UzpbA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O7mapT5Ar3FO5gpVBCuYiFvNXLt8Fh+EGCgQhzVW6/czBtiqvrYHcC85blreNhzazK76IOX5N9B9ewK9f9po6oVPpbuJD0XVDno1+A4M8Ph9ugylDL0pCjQdb1xQAz/jIfWefkTOMJ96PhF0fBdWemYkvsxO+t5MrImeQyxPwgs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=fhGF2bqV; arc=fail smtp.client-ip=40.107.223.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="fhGF2bqV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ngwHd1NR/U+xk+IBmzUtIR6XKMTLHr0JA1RrOp615x8V0iMQMZpZNtf9pznOgmhWzZXbZZS12EcRK+bITBWQy4k3WgZ41gPeZ3LqtRBUXbx3hwztE+85Xvcy/Q0bEAkT2j69/Qm+WdI2EEkueCIFckSDTFZLAl2TIxosxLSMzhGhVg8DMPdliox3Ero1aStv/baWL8qS8zLwXt01Kbj7MNOytwlolAyz4iG3464PA8lLguMQ9KQck2H3DyNiXDokdDrN8vXxgvb62oeUkTvmer/kwRiWDGWE3r8xvc35Q61SDlvzu7PkTlm3pbVREKNScLlJYAeMxDvW5t9Fm6GzIg== 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=I0XtYqDJJ1bCxzYSCuSDX0wLfN9IQ7FdrZiFR6bqhfI=; b=saH799sguliLMU0dbBr6OVhBunoEeTCYvdEiVnosdxs9NC/HTsR+FNUaNy2GTJP4yv9LA9+mS/FWKvrNBTmDS+S7P3WEC55Eq3sjtzqmuMlEOsUGMNu7sD0t0mEpP6yygIDxOBbC9BF6MoaynwWmdVUdUEjLDyBcW48fglLe5u59GJAyZ1nSm33IcjmpUccjKkChP2pki9cGDp4FlbrGpA34XPOQIRRKAZy2fK8XyW5hY2cAVDqBv0n3ChDwCAtzddtuBCqxRPGbbt4Ddz5ADclbHowKaUNM9yjbfZUetoWBpDprFF9gP0hxTxU8ebzzliurHQbL8AqIMIrZP7WNWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I0XtYqDJJ1bCxzYSCuSDX0wLfN9IQ7FdrZiFR6bqhfI=; b=fhGF2bqVQ4V/pcO3pa1namMxfeQQL8D50Y0VnfAqO8BQvEgqrIlMNAlOd2fuaePq78lFOABBSRHQ8Qw1+k9T7ker76zD5YjIUh7lkzrDIFgcKtQIhCUz6ziieyHiKT1athYjKG1eVCpd/azsssLBsi6j9l8j3e8U4t0HfCnXBWg= Received: from BLAPR03CA0087.namprd03.prod.outlook.com (2603:10b6:208:329::32) by CH2PR12MB4102.namprd12.prod.outlook.com (2603:10b6:610:a9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.13; Tue, 10 Dec 2024 09:36:08 +0000 Received: from BN3PEPF0000B36D.namprd21.prod.outlook.com (2603:10b6:208:329:cafe::cc) by BLAPR03CA0087.outlook.office365.com (2603:10b6:208:329::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.14 via Frontend Transport; Tue, 10 Dec 2024 09:36:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B36D.mail.protection.outlook.com (10.167.243.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:36:08 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:36:02 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 09/10] perf test: Introduce DEFINE_SUITE_EXCLUSIVE() Date: Tue, 10 Dec 2024 09:34:48 +0000 Message-ID: <20241210093449.1662-10-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B36D:EE_|CH2PR12MB4102:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ea4c553-f1e8-4ac7-62be-08dd18fe13c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?V0EigCpk1HJ4rchFAqvdupQZD6jUNxiSk5J4llPFXpRteGZvrHgyBiSHTLiF?= =?us-ascii?Q?m3tJ3sUsRQHyfLvC8dcMmjGfloPW+0YJ6qd4vQKuWMUAsRFeqQsjNEMzQDg3?= =?us-ascii?Q?sEb1Q7sE0wPTakRG2czeFkpa2CSCUGjkqrAtlwxHuNN8Pw/dzrRGBFoSjwOi?= =?us-ascii?Q?w49904Nqnv9OGph8pGqr5oeh84BegCFeaEh6SBCONYvBPMnlXBVOmFnTyLK0?= =?us-ascii?Q?9gC5ykSGZmabdIp+TxqacU+YeMWoUZp0IGxoiMGPe6Qhv4N0M43J6pQjzIH/?= =?us-ascii?Q?lf1Kt919YeDH1mCK6ox7EPg/lI5zcya53T7gdypfs2+dcurzxmunIwsELtmM?= =?us-ascii?Q?+Mv5IOGjJPCvDf2svTJx9AYXu+1ebPEqOC/OuvZqB/QupFJ5+7l25k3VYxGx?= =?us-ascii?Q?LA4Q4i/vI1OSD6jT0DTIWhWtJvmUIy0OIoU+cMxiHZUJGZb4tw5iJ/2QuSLM?= =?us-ascii?Q?8YEskj4nDp+J1a7eUztk3KICbcphomqBUrP2+P/kXmeYN6Lsys5FxRM0MiTD?= =?us-ascii?Q?pT1h4wNAnL8a0ipn0xhKZrAevBmU5IQdtfo2VZC3saLbKHpkweXWbMYjheKq?= =?us-ascii?Q?rjNfQOUnxF2CLUkftVRggOOuPd7y7lL4c6X/98SebarD1jFd21aHXUP2lMG/?= =?us-ascii?Q?2sz5gizC3wY3S1BpWa12uSF5pZaWNaoicIOT6TAW+n+Rhm1pUyxGCB7WXfU3?= =?us-ascii?Q?lIunrladahcFlnr6FUV8W5Tj/fe9zasjkCp0iYPGpM3GcRg64Rxj+WElZVoq?= =?us-ascii?Q?m/JrjhWzpc7F2bzxY32edWf3NsirArA8CvI+Rx6YgjfpScb5Mk5IruighUM+?= =?us-ascii?Q?hkXlhqXoq3zNjMtSoNLxsZ64Vx6W4y9ojX0ZaUrxUxvaMIwZYj4j3Lfgb8wl?= =?us-ascii?Q?VnvePFltaa+/aF19sgC1E6o/wQ0cJygO+J/TW7IBKHL2oJKdf92ztcaSayvn?= =?us-ascii?Q?NHWnRVkK4TOheEC6DdYwODDYcI+rNsZvfwEXMqwSo/2qNJJnFiVLRe1OO+hV?= =?us-ascii?Q?J63mKwQRpAj3R7vccYouquITvdnHntnOdmspjY0wKHtO2/YXvZOQ9Dq8uAKO?= =?us-ascii?Q?8r8mw64yWD3c6AKcH1kX6XFGD0Le7az1oh/GloyomR0KjwFpcqP8Y4niutX0?= =?us-ascii?Q?O2h1gT9Nu3POQeYvs95fXzvxOAksALEKMbHBOLJeauNaAzfBi0I5OqlSOpaI?= =?us-ascii?Q?0Q0SU3FnvmGbwGZC3XotHzsCzaBMoyLy6QnrvSJ2fvqNN3jfkGz6zpxE1dxK?= =?us-ascii?Q?CeDRHnr+qn0ZvOC2J46YzACfZ3yIMibVReyAS0pSA0EYzucgmzco7LceYlE9?= =?us-ascii?Q?7PKpW5DO3Z/xJRY8mIyYZ13byd8tGD45NbGlTcxAyrFwxA+jsnfrZJwkwZtt?= =?us-ascii?Q?sBrpjN9NBUNdS8lmcKVI4Kx8U7+TsM2zw8qLP5Qde9WdOLkmHg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(1800799024)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:36:08.8160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ea4c553-f1e8-4ac7-62be-08dd18fe13c5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B36D.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4102 Content-Type: text/plain; charset="utf-8" A variant of DEFINE_SUITE() but sets ->exclusive bit for the test so the test will be executed sequentially. Signed-off-by: Ravi Bangoria --- tools/perf/tests/tests.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index cb58b43aa063..8aea344536b8 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -81,6 +81,16 @@ struct test_suite { .test_cases =3D tests__##_name, \ } =20 +#define DEFINE_SUITE_EXCLUSIVE(description, _name) \ + struct test_case tests__##_name[] =3D { \ + TEST_CASE_EXCLUSIVE(description, _name),\ + { .name =3D NULL, } \ + }; \ + struct test_suite suite__##_name =3D { \ + .desc =3D description, \ + .test_cases =3D tests__##_name, \ + } + /* Tests */ DECLARE_SUITE(vmlinux_matches_kallsyms); DECLARE_SUITE(openat_syscall_event); --=20 2.43.0 From nobody Sun Dec 14 13:58:36 2025 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2087.outbound.protection.outlook.com [40.107.101.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EDFE212D77; Tue, 10 Dec 2024 09:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823388; cv=fail; b=OG4vqeAN2f2ZF8s8yFkixYKqhDCbVRzpqgr2Z+peHGoUEIlHxcQuPIFbiR5NcyDjF1N2CIuWHVApsCd1G26KiM3YZxZCxOQLXqpNMux87fyqxlE3n98T578+V+qzVuyr71jklCFWyawY+HXo4dhvkUmlE8pcNlOSurux3yvHVOQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823388; c=relaxed/simple; bh=x9tA8RyeYZI+52FfN6PhPV963Vi7bIMGtd957xcShn4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XfMY8Btth999C0NC6Bf2YfkniJLe/uYhB4HgGHMj8pNtA4FXxrCV8EfSH2iovlJzzi7JZhqjzJwfBzjuxWOT351eDOxbbqqSMnq9KdKRx5MweXMexg0u+5ErQPqO2lpxK+jduOenXDNojvf0RpI190bQoQZtnSwMtywBsMjbR7E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=nR4IH4/T; arc=fail smtp.client-ip=40.107.101.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nR4IH4/T" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iyxzu+XqYGq5WaqH9Hi85P6E3MF1EBVl9+tD6uLYNWbFKLh7z7KSNZDuF7Q2Uq8Ww7JFgeYpR0WKeDh0RAuI4IikgOT+JOksEMQiHJ5KzW+emwPr7QatT+93VhvW3HR1tUmgpMwiLQpmQkY8HIy8mXBTLECOK5Ffy7rFXyNINz3TuHkJ8UQEMSEx0xulh+yjJnep61ahjafLziNYA0K/Qr1mGpzrIvip0MrJnDptcBj5P01P4tEyWbJPKIF8draErqwczKNGh7qjD2y/pxZYX4ULXMPA5kc5qVIuFx8wKmRNHTetX81CvemUPskoYa+bbKiCaV6vLacF2+W/6XG/oA== 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=Xvi1bFW/ctZ3eZSPrs9Yg7NkhCpJzt2/nCOA49KIMqo=; b=mqHw6Pdwz9CZVeZy3W+4/TxDIi3lkqD9YA+p0Pz/cTRO4lgW32KwGsyoVMwYQZuy0dZwB1zThdMgv3njCQ0pyBBkGisyDLKZcKQrOkfxIPkEfT5gM875KeMMKeoog85SBazho+ByhUW69mJS0eztBFtBd8aGmgD/pqQJqI2gvvuuEBi5pldX73Km/fCNFau7qHl0rBlUlsHx/nmK346ff27ajF8RM71w+wgpePiQtKa3pARfHtaZyHHv1KhyzpgRRNNps79I0SWSrLpyurLm7MYK6a7w3BJ6anoWTZIFFyGr9o9RIeYpoib+5nzETMWGsMnsc6UPV3LGOTQWruM73w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xvi1bFW/ctZ3eZSPrs9Yg7NkhCpJzt2/nCOA49KIMqo=; b=nR4IH4/TGSE5mXG5lv8QKPFvO7s1HSTNBVWe45dI0D8h0X4ZYNtU9SVv1vXO11p9voSBT0/LQDCT+yfqyhRyYQNf22q+iYpZNS9gBiRjxn4mfiY9BdEsZUSt7SF73zPjHA93+wP1jWqkaD8SVNfPryo5dOs3uGGLBQGsf+qoKrw= Received: from BLAPR03CA0090.namprd03.prod.outlook.com (2603:10b6:208:329::35) by IA1PR12MB6330.namprd12.prod.outlook.com (2603:10b6:208:3e4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Tue, 10 Dec 2024 09:36:15 +0000 Received: from BN3PEPF0000B36D.namprd21.prod.outlook.com (2603:10b6:208:329:cafe::d4) by BLAPR03CA0090.outlook.office365.com (2603:10b6:208:329::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.18 via Frontend Transport; Tue, 10 Dec 2024 09:36:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B36D.mail.protection.outlook.com (10.167.243.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Tue, 10 Dec 2024 09:36:15 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 10 Dec 2024 03:36:08 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 10/10] perf test amd ibs: Add sample period unit test Date: Tue, 10 Dec 2024 09:34:49 +0000 Message-ID: <20241210093449.1662-11-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210093449.1662-1-ravi.bangoria@amd.com> References: <20241210093449.1662-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B36D:EE_|IA1PR12MB6330:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ec9ea9d-f3d5-434f-fa0e-08dd18fe17a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?iGXX+7DYOqcemGN7Pc8jRpX4J8X44gYqS8lrCFNJSKx+cDh82Ie+pfE3w0yr?= =?us-ascii?Q?QhCW7yAkyzPtFUVoDXGfxnvdk1GPJTP3NfjtsfwP4tu9xhPNRBCKYgy2cNAN?= =?us-ascii?Q?FlYrAkfus2kxXa0BQ6GmXMtn4dx1m7e8uxzsIY4s2vJIiPRyEIsPVMEIvt5U?= =?us-ascii?Q?XeViCWu1wzFE+b7kI9IhvHN3ElHKu6iq1JblpsFaykQfnGXoYTHeJwyR5KdG?= =?us-ascii?Q?TlgU+wh4XG50B0BsS7R69pK0Qh9X2tOXejMaQwpqWRhpkc66zCromL0f91V7?= =?us-ascii?Q?Dqw4bW4Eq5nPEIHwxjcYCLHgj0w7+zV11y7VZgGj2g6TArvESG/uCapaJFiA?= =?us-ascii?Q?bQ7lv4lHK6ej3cWD0BAocsEnBgbpTZ7MVNMxif55T7uGxmRddpHdDtggyObU?= =?us-ascii?Q?X+Y+yyNmxEIJFP12gc6+XoLeMbYtLiopw+A8DyhU6u+9XeQbCGIZExUZ+7+x?= =?us-ascii?Q?OTu1AWkf/RbyRPgu+l6sEUZ5ZRhxdY3SPzzQ+xXjBrjluq5PpvhpJV7VfuMT?= =?us-ascii?Q?nULcDTqMmPTc1ki5HOAXJqWl2Sv25drJorossZ1NpSoJxN7NS5/cH3FOpuRp?= =?us-ascii?Q?ab0uKgvrpiH6by6qZvGCDaMZ01Vo/FMnmP0WsCATi7xEqu7PjkBgeoScsBDx?= =?us-ascii?Q?GO/NTXUOQRnwmvSbbpcjOXYDKgQBgYZ507VAkXZUt4b1fVpXXAXXRklnLUyx?= =?us-ascii?Q?El7omF2Np4dPcRkonS8rnet9yyhCGNcEF+7ylYyixnBA1FDxgcVdy+a9pMSm?= =?us-ascii?Q?PMylt0jM980VWVnWrl296JA7xrYHWs0Q5NhPf8icAXttDMcnG0mitDrMs5yk?= =?us-ascii?Q?GlnrW10jKcbeGiM26OHlEinpeGNrr63+qIQZN+bZmw2ldQHnJ4bCDrXk/+6q?= =?us-ascii?Q?FjBvgHmlDfz9xGWIKBPPKSZo0c+qaOf1XYH0bH1y2Xcy9IcZgvLATAsQDYi6?= =?us-ascii?Q?S5xTDs7cn1ZpmOdr6SwgKuCqNLcgp8N/mR5X0f5xVkxFiuunpMg7b2G+b3oE?= =?us-ascii?Q?JC5cGmPBrhrl+RLi5o22GmerkdXgJyRS4u5ryNm+b5RILIsy9Fh2sO9vzrvw?= =?us-ascii?Q?1gFVFjaCfo5umuwKc3XaZdS3IuZOWru0+grF+V+1Z0x2+3T3dlH/ey/HFrov?= =?us-ascii?Q?mpQCpbbw5ilL8rsMRd0S2qlhe22V2jJZ4F3lEdy68uFjUDhi6OUgIv3uR79B?= =?us-ascii?Q?EgSzzw5UbAtIi62cyaCqTLo18lFeSZXCtp9gGc7qj+s/lv6Thc97VY7ImGI+?= =?us-ascii?Q?Sbnv9lTbuqLSr2WMrg/WARu4xo97NbsbcIlnp36bTUSupvgq3GiKTLd76SAE?= =?us-ascii?Q?D+EUgiedgpnCflYcWlZ9JETr3GEYFdVOFhASWmsB8M/78+z/6ZK24Or6cLZ2?= =?us-ascii?Q?Gvnqb9TaOPLbrbpPCF31t1lnmzaxL2jJ4usawzwkn+O940UcCw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 09:36:15.3628 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ec9ea9d-f3d5-434f-fa0e-08dd18fe17a9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B36D.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6330 Content-Type: text/plain; charset="utf-8" IBS Fetch and IBS Op PMUs has various constraints on supported sample periods. Add perf unit tests to test those. Running it in parallel with other tests causes intermittent failures. Mark it exclusive to force it to run sequentially. Sample output on a Zen5 machine: Without kernel fixes: $ sudo ./perf test -vv 112 112: AMD IBS sample period: --- start --- test child forked, pid 16675 Using CPUID AuthenticAMD-26-2-1 =20 IBS config tests: ----------------- Fetch PMU tests: 0xffff : Ok (nr samples: 1001) 0x1000 : Ok (nr samples: 15557) 0xff : Ok (nr samples: 40993) 0x1 : Ok (nr samples: 40543) 0x0 : Ok 0x10000 : Ok Op PMU tests: 0x0 : Ok 0x1 : Fail 0x8 : Fail 0x9 : Ok (nr samples: 40543) 0xf : Ok (nr samples: 40543) 0x1000 : Ok (nr samples: 18399) 0xffff : Ok (nr samples: 1191) 0x10000 : Ok 0x100000 : Fail (nr samples: 19) 0xf00000 : Fail (nr samples: 1) 0xf0ffff : Fail (nr samples: 2) 0x1f0ffff : Fail (nr samples: 1) 0x7f0ffff : Fail (nr samples: 0) 0x8f0ffff : Ok 0x17f0ffff : Ok =20 IBS sample period constraint tests: ----------------------------------- Fetch PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Fail freq 0, sample_freq 15: Fail freq 0, sample_freq 16: Ok (nr samples: 1604) freq 0, sample_freq 17: Ok (nr samples: 1604) freq 0, sample_freq 143: Ok (nr samples: 1604) freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1604) freq 0, sample_freq 1234: Ok (nr samples: 1604) freq 0, sample_freq 4103: Ok (nr samples: 1471) freq 0, sample_freq 65520: Ok (nr samples: 2294) freq 0, sample_freq 65535: Ok (nr samples: 2130) freq 0, sample_freq 65552: Ok (nr samples: 2253) freq 0, sample_freq 8388607: Ok (nr samples: 26) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Ok (nr samples: 4) freq 1, sample_freq 15: Ok (nr samples: 4) freq 1, sample_freq 16: Ok (nr samples: 4) freq 1, sample_freq 17: Ok (nr samples: 4) freq 1, sample_freq 143: Ok (nr samples: 5) freq 1, sample_freq 144: Ok (nr samples: 5) freq 1, sample_freq 145: Ok (nr samples: 5) freq 1, sample_freq 1234: Ok (nr samples: 7) freq 1, sample_freq 4103: Ok (nr samples: 32) freq 1, sample_freq 65520: Ok (nr samples: 530) freq 1, sample_freq 65535: Ok (nr samples: 406) freq 1, sample_freq 65552: Ok (nr samples: 129) freq 1, sample_freq 8388607: Ok Op PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Fail freq 0, sample_freq 15: Fail freq 0, sample_freq 16: Fail freq 0, sample_freq 17: Fail freq 0, sample_freq 143: Fail freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1604) freq 0, sample_freq 1234: Ok (nr samples: 1604) freq 0, sample_freq 4103: Ok (nr samples: 1473) freq 0, sample_freq 65520: Ok (nr samples: 2159) freq 0, sample_freq 65535: Ok (nr samples: 2185) freq 0, sample_freq 65552: Ok (nr samples: 2105) freq 0, sample_freq 8388607: Ok (nr samples: 24) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Fail (nr samples: 4) freq 1, sample_freq 15: Fail (nr samples: 4) freq 1, sample_freq 16: Fail (nr samples: 4) freq 1, sample_freq 17: Fail (nr samples: 4) freq 1, sample_freq 143: Fail (nr samples: 5) freq 1, sample_freq 144: Fail (nr samples: 5) freq 1, sample_freq 145: Fail (nr samples: 5) freq 1, sample_freq 1234: Fail (nr samples: 7) freq 1, sample_freq 4103: Fail (nr samples: 33) freq 1, sample_freq 65520: Fail (nr samples: 554) freq 1, sample_freq 65535: Fail (nr samples: 561) freq 1, sample_freq 65552: Fail (nr samples: 551) freq 1, sample_freq 8388607: Ok =20 IBS ioctl() tests: ------------------ Fetch PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Fail ioctl(period =3D 0xf ): Fail ioctl(period =3D 0x10 ): Ok ioctl(period =3D 0x11 ): Fail ioctl(period =3D 0x1f ): Fail ioctl(period =3D 0x20 ): Ok ioctl(period =3D 0x80 ): Ok ioctl(period =3D 0x8f ): Fail ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Fail ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Fail ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Fail ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok Op PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Fail ioctl(period =3D 0xf ): Fail ioctl(period =3D 0x10 ): Fail ioctl(period =3D 0x11 ): Fail ioctl(period =3D 0x1f ): Fail ioctl(period =3D 0x20 ): Fail ioctl(period =3D 0x80 ): Fail ioctl(period =3D 0x8f ): Fail ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Fail ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Fail ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Fail ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok =20 IBS freq (negative) tests: -------------------------- freq 1, sample_freq 200000: Fail =20 IBS L3MissOnly test: (takes a while) -------------------- Fetch L3MissOnly: Fail (nr_samples: 1358) Op L3MissOnly: Ok (nr_samples: 1422) ---- end(-1) ---- 112: AMD IBS sample period : FA= ILED! With kernel fixes: $ sudo ./perf test -vv 112 112: AMD IBS sample period: --- start --- test child forked, pid 11681 Using CPUID AuthenticAMD-26-2-1 =20 IBS config tests: ----------------- Fetch PMU tests: 0xffff : Ok (nr samples: 942) 0x1000 : Ok (nr samples: 15396) 0xff : Ok (nr samples: 40547) 0x1 : Ok (nr samples: 40543) 0x0 : Ok 0x10000 : Ok Op PMU tests: 0x0 : Ok 0x1 : Ok 0x8 : Ok 0x9 : Ok (nr samples: 40543) 0xf : Ok (nr samples: 40543) 0x1000 : Ok (nr samples: 18656) 0xffff : Ok (nr samples: 1187) 0x10000 : Ok 0x100000 : Ok (nr samples: 1178) 0xf00000 : Ok (nr samples: 77) 0xf0ffff : Ok (nr samples: 69) 0x1f0ffff : Ok (nr samples: 34) 0x7f0ffff : Ok (nr samples: 7) 0x8f0ffff : Ok 0x17f0ffff : Ok =20 IBS sample period constraint tests: ----------------------------------- Fetch PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Ok freq 0, sample_freq 15: Ok freq 0, sample_freq 16: Ok (nr samples: 1604) freq 0, sample_freq 17: Ok (nr samples: 1604) freq 0, sample_freq 143: Ok (nr samples: 1604) freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1203) freq 0, sample_freq 1234: Ok (nr samples: 1430) freq 0, sample_freq 4103: Ok (nr samples: 638) freq 0, sample_freq 65520: Ok (nr samples: 2018) freq 0, sample_freq 65535: Ok (nr samples: 2002) freq 0, sample_freq 65552: Ok (nr samples: 345) freq 0, sample_freq 8388607: Ok (nr samples: 24) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Ok (nr samples: 4) freq 1, sample_freq 15: Ok (nr samples: 4) freq 1, sample_freq 16: Ok (nr samples: 4) freq 1, sample_freq 17: Ok (nr samples: 4) freq 1, sample_freq 143: Ok (nr samples: 5) freq 1, sample_freq 144: Ok (nr samples: 5) freq 1, sample_freq 145: Ok (nr samples: 5) freq 1, sample_freq 1234: Ok (nr samples: 8) freq 1, sample_freq 4103: Ok (nr samples: 30) freq 1, sample_freq 65520: Ok (nr samples: 1604) freq 1, sample_freq 65535: Ok (nr samples: 1604) freq 1, sample_freq 65552: Ok (nr samples: 1604) freq 1, sample_freq 8388607: Ok Op PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Ok freq 0, sample_freq 15: Ok freq 0, sample_freq 16: Ok freq 0, sample_freq 17: Ok freq 0, sample_freq 143: Ok freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1203) freq 0, sample_freq 1234: Ok (nr samples: 1435) freq 0, sample_freq 4103: Ok (nr samples: 1467) freq 0, sample_freq 65520: Ok (nr samples: 2209) freq 0, sample_freq 65535: Ok (nr samples: 2230) freq 0, sample_freq 65552: Ok (nr samples: 2265) freq 0, sample_freq 8388607: Ok (nr samples: 25) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Ok (nr samples: 4) freq 1, sample_freq 15: Ok (nr samples: 4) freq 1, sample_freq 16: Ok (nr samples: 4) freq 1, sample_freq 17: Ok (nr samples: 4) freq 1, sample_freq 143: Ok (nr samples: 5) freq 1, sample_freq 144: Ok (nr samples: 4) freq 1, sample_freq 145: Ok (nr samples: 5) freq 1, sample_freq 1234: Ok (nr samples: 7) freq 1, sample_freq 4103: Ok (nr samples: 31) freq 1, sample_freq 65520: Ok (nr samples: 548) freq 1, sample_freq 65535: Ok (nr samples: 446) freq 1, sample_freq 65552: Ok (nr samples: 541) freq 1, sample_freq 8388607: Ok =20 IBS ioctl() tests: ------------------ Fetch PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Ok ioctl(period =3D 0xf ): Ok ioctl(period =3D 0x10 ): Ok ioctl(period =3D 0x11 ): Ok ioctl(period =3D 0x1f ): Ok ioctl(period =3D 0x20 ): Ok ioctl(period =3D 0x80 ): Ok ioctl(period =3D 0x8f ): Ok ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Ok ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Ok ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Ok ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok Op PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Ok ioctl(period =3D 0xf ): Ok ioctl(period =3D 0x10 ): Ok ioctl(period =3D 0x11 ): Ok ioctl(period =3D 0x1f ): Ok ioctl(period =3D 0x20 ): Ok ioctl(period =3D 0x80 ): Ok ioctl(period =3D 0x8f ): Ok ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Ok ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Ok ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Ok ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok =20 IBS freq (negative) tests: -------------------------- freq 1, sample_freq 200000: Ok =20 IBS L3MissOnly test: (takes a while) -------------------- Fetch L3MissOnly: Ok (nr_samples: 1523) Op L3MissOnly: Ok (nr_samples: 1771) ---- end(0) ---- 112: AMD IBS sample period : Ok Signed-off-by: Ravi Bangoria --- tools/perf/arch/x86/include/arch-tests.h | 1 + tools/perf/arch/x86/tests/Build | 1 + tools/perf/arch/x86/tests/amd-ibs-period.c | 953 +++++++++++++++++++++ tools/perf/arch/x86/tests/arch-tests.c | 2 + 4 files changed, 957 insertions(+) create mode 100644 tools/perf/arch/x86/tests/amd-ibs-period.c diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86= /include/arch-tests.h index c0421a26b875..4fd425157d7d 100644 --- a/tools/perf/arch/x86/include/arch-tests.h +++ b/tools/perf/arch/x86/include/arch-tests.h @@ -14,6 +14,7 @@ int test__intel_pt_hybrid_compat(struct test_suite *test,= int subtest); int test__bp_modify(struct test_suite *test, int subtest); int test__x86_sample_parsing(struct test_suite *test, int subtest); int test__amd_ibs_via_core_pmu(struct test_suite *test, int subtest); +int test__amd_ibs_period(struct test_suite *test, int subtest); int test__hybrid(struct test_suite *test, int subtest); =20 extern struct test_suite *arch_tests[]; diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Bu= ild index 3227053f3355..db4b7945fc40 100644 --- a/tools/perf/arch/x86/tests/Build +++ b/tools/perf/arch/x86/tests/Build @@ -10,6 +10,7 @@ perf-test-$(CONFIG_AUXTRACE) +=3D insn-x86.o endif perf-test-$(CONFIG_X86_64) +=3D bp-modify.o perf-test-y +=3D amd-ibs-via-core-pmu.o +perf-test-y +=3D amd-ibs-period.o =20 ifdef SHELLCHECK SHELL_TESTS :=3D gen-insn-x86-dat.sh diff --git a/tools/perf/arch/x86/tests/amd-ibs-period.c b/tools/perf/arch/x= 86/tests/amd-ibs-period.c new file mode 100644 index 000000000000..573fa8de81c2 --- /dev/null +++ b/tools/perf/arch/x86/tests/amd-ibs-period.c @@ -0,0 +1,953 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + +#include "arch-tests.h" +#include "linux/perf_event.h" +#include "linux/zalloc.h" +#include "tests/tests.h" +#include "../perf-sys.h" +#include "pmu.h" +#include "pmus.h" +#include "debug.h" +#include "util.h" +#include "strbuf.h" +#include "../util/env.h" + +#define PAGE_SIZE sysconf(_SC_PAGESIZE) + +#define PERF_MMAP_DATA_PAGES 32L +#define PERF_MMAP_DATA_SIZE (PERF_MMAP_DATA_PAGES * PAGE_SIZE) +#define PERF_MMAP_DATA_MASK (PERF_MMAP_DATA_SIZE - 1) +#define PERF_MMAP_TOTAL_PAGES (PERF_MMAP_DATA_PAGES + 1) +#define PERF_MMAP_TOTAL_SIZE (PERF_MMAP_TOTAL_PAGES * PAGE_SIZE) + +#define rmb() asm volatile("lfence":::"memory") + +enum { + FD_ERROR, + FD_SUCCESS, +}; + +enum { + IBS_FETCH, + IBS_OP, +}; + +struct perf_pmu *fetch_pmu; +struct perf_pmu *op_pmu; +unsigned int perf_event_max_sample_rate; + +/* Dummy workload to generate IBS samples. */ +static int dummy_workload_1(unsigned long count) +{ + int (*func)(void); + int ret =3D 0; + char *p; + char insn1[] =3D { + 0xb8, 0x01, 0x00, 0x00, 0x00, /* mov 1,%eax */ + 0xc3, /* ret */ + 0xcc, /* int 3 */ + }; + + char insn2[] =3D { + 0xb8, 0x02, 0x00, 0x00, 0x00, /* mov 2,%eax */ + 0xc3, /* ret */ + 0xcc, /* int 3 */ + }; + + p =3D zalloc(2 * PAGE_SIZE); + if (!p) { + printf("malloc() failed. %m"); + return 1; + } + + func =3D (void *)((unsigned long)(p + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)); + + ret =3D mprotect(func, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC); + if (ret) { + printf("mprotect() failed. %m"); + goto out; + } + + if (count < 100000) + count =3D 100000; + else if (count > 1000000) + count =3D 1000000; + while (count--) { + memcpy(func, insn1, sizeof(insn1)); + if (func() !=3D 1) { + pr_debug("ERROR insn1\n"); + ret =3D -1; + goto out; + } + memcpy(func, insn2, sizeof(insn2)); + if (func() !=3D 2) { + pr_debug("ERROR insn2\n"); + ret =3D -1; + goto out; + } + } + +out: + free(p); + return ret; +} + +/* Another dummy workload to generate IBS samples. */ +static void dummy_workload_2(char *perf) +{ + char bench[] =3D " bench sched messaging -g 10 -l 5000 > /dev/null 2>&1"; + char taskset[] =3D "taskset -c 0 "; + int ret __maybe_unused; + struct strbuf sb; + char *cmd; + + strbuf_init(&sb, 0); + strbuf_add(&sb, taskset, strlen(taskset)); + strbuf_add(&sb, perf, strlen(perf)); + strbuf_add(&sb, bench, strlen(bench)); + cmd =3D strbuf_detach(&sb, NULL); + ret =3D system(cmd); + free(cmd); +} + +static int sched_affine(int cpu) +{ + cpu_set_t set; + + CPU_ZERO(&set); + CPU_SET(cpu, &set); + if (sched_setaffinity(getpid(), sizeof(set), &set) =3D=3D -1) { + pr_debug("sched_setaffinity() failed. [%m]"); + return -1; + } + return 0; +} + +static void +copy_sample_data(void *src, unsigned long offset, void *dest, size_t size) +{ + size_t chunk1_size, chunk2_size; + + if ((offset + size) < (size_t)PERF_MMAP_DATA_SIZE) { + memcpy(dest, src + offset, size); + } else { + chunk1_size =3D PERF_MMAP_DATA_SIZE - offset; + chunk2_size =3D size - chunk1_size; + + memcpy(dest, src + offset, chunk1_size); + memcpy(dest + chunk1_size, src, chunk2_size); + } +} + +static int rb_read(struct perf_event_mmap_page *rb, void *dest, size_t siz= e) +{ + void *base; + unsigned long data_tail, data_head; + + /* Casting to (void *) is needed. */ + base =3D (void *)rb + PAGE_SIZE; + + data_head =3D rb->data_head; + rmb(); + data_tail =3D rb->data_tail; + + if ((data_head - data_tail) < size) + return -1; + + data_tail &=3D PERF_MMAP_DATA_MASK; + copy_sample_data(base, data_tail, dest, size); + rb->data_tail +=3D size; + return 0; +} + +static void rb_skip(struct perf_event_mmap_page *rb, size_t size) +{ + size_t data_head =3D rb->data_head; + + rmb(); + + if ((rb->data_tail + size) > data_head) + rb->data_tail =3D data_head; + else + rb->data_tail +=3D size; +} + +/* Sample period value taken from perf sample must match with expected val= ue. */ +static int period_equal(unsigned long exp_period, unsigned long act_period) +{ + return exp_period =3D=3D act_period ? 0 : -1; +} + +/* + * Sample period value taken from perf sample must be >=3D minimum sample = period + * supported by IBS HW. + */ +static int period_higher(unsigned long min_period, unsigned long act_perio= d) +{ + return min_period <=3D act_period ? 0 : -1; +} + +static int rb_drain_samples(struct perf_event_mmap_page *rb, + unsigned long exp_period, + int *nr_samples, + int (*callback)(unsigned long, unsigned long)) +{ + struct perf_event_header hdr; + unsigned long period; + int ret =3D 0; + + /* + * PERF_RECORD_SAMPLE: + * struct { + * struct perf_event_header hdr; + * { u64 period; } && PERF_SAMPLE_PERIOD + * }; + */ + while (1) { + if (rb_read(rb, &hdr, sizeof(hdr))) + return ret; + + if (hdr.type =3D=3D PERF_RECORD_SAMPLE) { + (*nr_samples)++; + period =3D 0; + if (rb_read(rb, &period, sizeof(period))) + pr_debug("rb_read(period) error. [%m]"); + ret |=3D callback(exp_period, period); + } else { + rb_skip(rb, hdr.size - sizeof(hdr)); + } + } + return ret; +} + +static long perf_event_open(struct perf_event_attr *attr, pid_t pid, + int cpu, int group_fd, unsigned long flags) +{ + return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); +} + +static void fetch_prepare_attr(struct perf_event_attr *attr, + unsigned long config, int freq, + unsigned long sample_period) +{ + memset(attr, 0, sizeof(struct perf_event_attr)); + + attr->type =3D fetch_pmu->type; + attr->size =3D sizeof(struct perf_event_attr); + attr->config =3D config; + attr->disabled =3D 1; + attr->sample_type =3D PERF_SAMPLE_PERIOD; + attr->freq =3D freq; + attr->sample_period =3D sample_period; /* =3D ->sample_freq */ +} + +static void op_prepare_attr(struct perf_event_attr *attr, + unsigned long config, int freq, + unsigned long sample_period) +{ + memset(attr, 0, sizeof(struct perf_event_attr)); + + attr->type =3D op_pmu->type; + attr->size =3D sizeof(struct perf_event_attr); + attr->config =3D config; + attr->disabled =3D 1; + attr->sample_type =3D PERF_SAMPLE_PERIOD; + attr->freq =3D freq; + attr->sample_period =3D sample_period; /* =3D ->sample_freq */ +} + +struct ibs_configs { + /* Input */ + unsigned long config; + + /* Expected output */ + unsigned long period; + int fd; +}; + +/* + * Somehow first Fetch event with sample period =3D 0x10 causes 0 + * samples. So start with large period and decrease it gradually. + */ +struct ibs_configs fetch_configs[] =3D { + { .config =3D 0xffff, .period =3D 0xffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1000, .period =3D 0x10000, .fd =3D FD_SUCCESS }, + { .config =3D 0xff, .period =3D 0xff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1, .period =3D 0x10, .fd =3D FD_SUCCESS }, + { .config =3D 0x0, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x10000, .period =3D -1, .fd =3D FD_ERROR }, +}; + +struct ibs_configs op_configs[] =3D { + { .config =3D 0x0, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x1, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x8, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x9, .period =3D 0x90, .fd =3D FD_SUCCESS }, + { .config =3D 0xf, .period =3D 0xf0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1000, .period =3D 0x10000, .fd =3D FD_SUCCESS }, + { .config =3D 0xffff, .period =3D 0xffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x10000, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x100000, .period =3D 0x100000, .fd =3D FD_SUCCESS }, + { .config =3D 0xf00000, .period =3D 0xf00000, .fd =3D FD_SUCCESS }, + { .config =3D 0xf0ffff, .period =3D 0xfffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1f0ffff, .period =3D 0x1fffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x7f0ffff, .period =3D 0x7fffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x8f0ffff, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x17f0ffff, .period =3D -1, .fd =3D FD_ERROR }, +}; + +static int __ibs_config_test(int ibs_type, struct ibs_configs *config, int= *nr_samples) +{ + struct perf_event_attr attr; + int fd, i; + void *rb; + int ret =3D 0; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, config->config, 0, 0); + else + op_prepare_attr(&attr, config->config, 0, 0); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (config->fd =3D=3D FD_ERROR) { + if (fd !=3D -1) { + close(fd); + return -1; + } + return 0; + } + if (fd <=3D -1) + return -1; + + rb =3D mmap(NULL, PERF_MMAP_TOTAL_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (rb =3D=3D MAP_FAILED) { + pr_debug("mmap() failed. [%m]\n"); + return -1; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + + i =3D 5; + while (i--) { + dummy_workload_1(1000000); + + ret =3D rb_drain_samples(rb, config->period, nr_samples, + period_equal); + if (ret) + break; + } + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + munmap(rb, PERF_MMAP_TOTAL_SIZE); + close(fd); + return ret; +} + +static int ibs_config_test(void) +{ + int nr_samples =3D 0; + unsigned long i; + int ret =3D 0; + int r; + + pr_debug("\nIBS config tests:\n"); + pr_debug("-----------------\n"); + + pr_debug("Fetch PMU tests:\n"); + for (i =3D 0; i < ARRAY_SIZE(fetch_configs); i++) { + nr_samples =3D 0; + r =3D __ibs_config_test(IBS_FETCH, &(fetch_configs[i]), &nr_samples); + + if (fetch_configs[i].fd =3D=3D FD_ERROR) { + pr_debug("0x%-16lx: %-4s\n", fetch_configs[i].config, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("0x%-16lx: %-4s (nr samples: %d)\n", fetch_configs[i].config, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + + ret |=3D r; + } + + pr_debug("Op PMU tests:\n"); + for (i =3D 0; i < ARRAY_SIZE(op_configs); i++) { + nr_samples =3D 0; + r =3D __ibs_config_test(IBS_OP, &(op_configs[i]), &nr_samples); + + if (op_configs[i].fd =3D=3D FD_ERROR) { + pr_debug("0x%-16lx: %-4s\n", op_configs[i].config, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("0x%-16lx: %-4s (nr samples: %d)\n", op_configs[i].config, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + + ret |=3D r; + } + + return ret; +} + +struct ibs_period { + /* Input */ + int freq; + unsigned long sample_freq; + + /* Output */ + int ret; + unsigned long period; +}; + +struct ibs_period fetch_period[] =3D { + { .freq =3D 0, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 1, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0xf, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x10, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 0, .sample_freq =3D 0x11, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 0, .sample_freq =3D 0x8f, .ret =3D FD_SUCCESS, .period = =3D 0x80 }, + { .freq =3D 0, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x4d0 }, + { .freq =3D 0, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x1000 }, + { .freq =3D 0, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x10010 }, + { .freq =3D 0, .sample_freq =3D 0x7fffff, .ret =3D FD_SUCCESS, .period = =3D 0x7ffff0 }, + { .freq =3D 1, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 1, .sample_freq =3D 1, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0xf, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x10, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x11, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x8f, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + + /* ret=3D-1 because it's beyond default perf_event_max_sample_rate (10000= 0) */ + { .freq =3D 1, .sample_freq =3D 0x7fffff, .ret =3D FD_ERROR, .period = =3D -1 }, +}; + +struct ibs_period op_period[] =3D { + { .freq =3D 0, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 1, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0xf, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x10, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x11, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x8f, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x4d0 }, + { .freq =3D 0, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x1000 }, + { .freq =3D 0, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x10010 }, + { .freq =3D 0, .sample_freq =3D 0x7fffff, .ret =3D FD_SUCCESS, .period = =3D 0x7ffff0 }, + { .freq =3D 1, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 1, .sample_freq =3D 1, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0xf, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x10, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x11, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x8f, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + + /* ret=3D-1 because it's beyond default perf_event_max_sample_rate (10000= 0) */ + { .freq =3D 1, .sample_freq =3D 0x7fffff, .ret =3D FD_ERROR, .period = =3D -1 }, +}; + +static int __ibs_period_constraint_test(int ibs_type, struct ibs_period *p= eriod, + int *nr_samples) +{ + struct perf_event_attr attr; + int ret =3D 0; + void *rb; + int fd; + + if (period->freq && period->sample_freq >=3D perf_event_max_sample_rate) { + nr_samples =3D 0; + return 0; + } + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, 0, period->freq, period->sample_freq); + else + op_prepare_attr(&attr, 0, period->freq, period->sample_freq); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (period->ret =3D=3D FD_ERROR) { + if (fd !=3D -1) { + close(fd); + return -1; + } + return 0; + } + if (fd <=3D -1) + return -1; + + rb =3D mmap(NULL, PERF_MMAP_TOTAL_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (rb =3D=3D MAP_FAILED) { + pr_debug("mmap() failed. [%m]\n"); + close(fd); + return -1; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + + if (period->freq) { + dummy_workload_1(100000); + ret =3D rb_drain_samples(rb, period->period, nr_samples, + period_higher); + } else { + dummy_workload_1(period->sample_freq * 10); + ret =3D rb_drain_samples(rb, period->period, nr_samples, + period_equal); + } + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + munmap(rb, PERF_MMAP_TOTAL_SIZE); + close(fd); + return ret; +} + +static int ibs_period_constraint_test(void) +{ + unsigned long i; + int nr_samples; + int ret =3D 0; + int r; + + pr_debug("\nIBS sample period constraint tests:\n"); + pr_debug("-----------------------------------\n"); + + pr_debug("Fetch PMU test:\n"); + for (i =3D 0; i < ARRAY_SIZE(fetch_period); i++) { + nr_samples =3D 0; + r =3D __ibs_period_constraint_test(IBS_FETCH, &fetch_period[i], + &nr_samples); + + if (fetch_period[i].ret =3D=3D FD_ERROR) { + pr_debug("freq %d, sample_freq %7ld: %-4s\n", + fetch_period[i].freq, fetch_period[i].sample_freq, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("freq %d, sample_freq %7ld: %-4s (nr samples: %d)\n", + fetch_period[i].freq, fetch_period[i].sample_freq, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + ret |=3D r; + } + + pr_debug("Op PMU test:\n"); + for (i =3D 0; i < ARRAY_SIZE(op_period); i++) { + nr_samples =3D 0; + r =3D __ibs_period_constraint_test(IBS_OP, &op_period[i], + &nr_samples); + + if (op_period[i].ret =3D=3D FD_ERROR) { + pr_debug("freq %d, sample_freq %7ld: %-4s\n", + op_period[i].freq, op_period[i].sample_freq, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("freq %d, sample_freq %7ld: %-4s (nr samples: %d)\n", + op_period[i].freq, op_period[i].sample_freq, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + ret |=3D r; + } + + return ret; +} + +struct ibs_ioctl { + /* Input */ + int freq; + unsigned long period; + + /* Expected output */ + int ret; +}; + +struct ibs_ioctl fetch_ioctl[] =3D { + { .freq =3D 0, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0xf, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x11, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x20, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x80, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x8f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x91, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x100, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xfff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xffff, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10000, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff5, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x1, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0xf, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x10, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x11, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x1f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x20, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x80, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x8f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x91, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x100, .ret =3D FD_SUCCESS }, +}; + +struct ibs_ioctl op_ioctl[] =3D { + { .freq =3D 0, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0xf, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x11, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x20, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x80, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x8f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x91, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x100, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xfff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xffff, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10000, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff5, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x1, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0xf, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x10, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x11, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x1f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x20, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x80, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x8f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x91, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x100, .ret =3D FD_SUCCESS }, +}; + +static int __ibs_ioctl_test(int ibs_type, struct ibs_ioctl *ibs_ioctl) +{ + struct perf_event_attr attr; + int ret =3D 0; + int fd; + int r; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, 0, ibs_ioctl->freq, 1000); + else + op_prepare_attr(&attr, 0, ibs_ioctl->freq, 1000); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (fd <=3D -1) { + pr_debug("event_open() Failed\n"); + return -1; + } + + r =3D ioctl(fd, PERF_EVENT_IOC_PERIOD, &ibs_ioctl->period); + if ((ibs_ioctl->ret =3D=3D FD_SUCCESS && r <=3D -1) || + (ibs_ioctl->ret =3D=3D FD_ERROR && r >=3D 0)) { + ret =3D -1; + } + + close(fd); + return ret; +} + +static int ibs_ioctl_test(void) +{ + unsigned long i; + int ret =3D 0; + int r; + + pr_debug("\nIBS ioctl() tests:\n"); + pr_debug("------------------\n"); + + pr_debug("Fetch PMU tests\n"); + for (i =3D 0; i < ARRAY_SIZE(fetch_ioctl); i++) { + r =3D __ibs_ioctl_test(IBS_FETCH, &fetch_ioctl[i]); + + pr_debug("ioctl(%s =3D 0x%-7lx): %s\n", + fetch_ioctl[i].freq ? "freq " : "period", + fetch_ioctl[i].period, r ? "Fail" : "Ok"); + ret |=3D r; + } + + pr_debug("Op PMU tests\n"); + for (i =3D 0; i < ARRAY_SIZE(op_ioctl); i++) { + r =3D __ibs_ioctl_test(IBS_OP, &op_ioctl[i]); + + pr_debug("ioctl(%s =3D 0x%-7lx): %s\n", + op_ioctl[i].freq ? "freq " : "period", + op_ioctl[i].period, r ? "Fail" : "Ok"); + ret |=3D r; + } + + return ret; +} + +static int ibs_freq_neg_test(void) +{ + struct perf_event_attr attr; + int fd; + + pr_debug("\nIBS freq (negative) tests:\n"); + pr_debug("--------------------------\n"); + + /* + * Assuming perf_event_max_sample_rate <=3D 100000, + * config: 0x300D40 =3D=3D> MaxCnt: 200000 + */ + op_prepare_attr(&attr, 0x300D40, 1, 0); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (fd !=3D -1) { + pr_debug("freq 1, sample_freq 200000: Fail\n"); + close(fd); + return -1; + } + + pr_debug("freq 1, sample_freq 200000: Ok\n"); + + return 0; +} + +static int __ibs_l3missonly_test(char *perf, int ibs_type, int *nr_samples= , int min_period) +{ + struct perf_event_attr attr; + int ret =3D 0; + void *rb; + int fd; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, 0x800000000000000UL, 1, 10000); + else + op_prepare_attr(&attr, 0x10000, 1, 10000); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (fd =3D=3D -1) { + pr_debug("perf_event_open() failed. [%m]\n"); + return -1; + } + + rb =3D mmap(NULL, PERF_MMAP_TOTAL_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (rb =3D=3D MAP_FAILED) { + pr_debug("mmap() failed. [%m]\n"); + close(fd); + return -1; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + + dummy_workload_2(perf); + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + + ret =3D rb_drain_samples(rb, min_period, nr_samples, period_higher); + + munmap(rb, PERF_MMAP_TOTAL_SIZE); + close(fd); + return ret; +} + +static int ibs_l3missonly_test(char *perf) +{ + int nr_samples =3D 0; + int ret =3D 0; + int r =3D 0; + + pr_debug("\nIBS L3MissOnly test: (takes a while)\n"); + pr_debug("--------------------\n"); + + if (perf_pmu__has_format(fetch_pmu, "l3missonly")) { + nr_samples =3D 0; + r =3D __ibs_l3missonly_test(perf, IBS_FETCH, &nr_samples, 0x10); + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("Fetch L3MissOnly: %-4s (nr_samples: %d)\n", + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + ret |=3D r; + } + + if (perf_pmu__has_format(op_pmu, "l3missonly")) { + nr_samples =3D 0; + r =3D __ibs_l3missonly_test(perf, IBS_OP, &nr_samples, 0x90); + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("Op L3MissOnly: %-4s (nr_samples: %d)\n", + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + ret |=3D r; + } + + return ret; +} + +static unsigned int get_perf_event_max_sample_rate(void) +{ + unsigned int max_sample_rate =3D 100000; + FILE *fp; + int ret; + + fp =3D fopen("/proc/sys/kernel/perf_event_max_sample_rate", "r"); + if (!fp) { + pr_debug("Can't open perf_event_max_sample_rate. Asssuming %d\n", + max_sample_rate); + goto out; + } + + ret =3D fscanf(fp, "%d", &max_sample_rate); + if (ret =3D=3D EOF) { + pr_debug("Can't read perf_event_max_sample_rate. Assuming 100000\n"); + max_sample_rate =3D 100000; + } + fclose(fp); + +out: + return max_sample_rate; +} + +int test__amd_ibs_period(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + char perf[PATH_MAX] =3D {'\0'}; + int ret =3D TEST_OK; + + perf_event_max_sample_rate =3D get_perf_event_max_sample_rate(); + fetch_pmu =3D perf_pmus__find("ibs_fetch"); + op_pmu =3D perf_pmus__find("ibs_op"); + + if (!x86__is_amd_cpu() || !fetch_pmu || !op_pmu) + return TEST_SKIP; + + perf_exe(perf, sizeof(perf)); + + if (sched_affine(0)) + return TEST_FAIL; + + /* + * Perf event can be opened in two modes: + * 1 Freq mode + * perf_event_attr->freq =3D 1, ->sample_freq =3D + * 2 Sample period mode + * perf_event_attr->freq =3D 0, ->sample_period =3D + * + * Instead of using above interface, IBS event in 'sample period mode' + * can also be opened by passing value directly in a MaxCnt + * bitfields of perf_event_attr->config. Test this IBS specific special + * interface. + */ + if (ibs_config_test()) + ret =3D TEST_FAIL; + + /* + * IBS Fetch and Op PMUs have HW constraints on minimum sample period. + * Also, sample period value must be in multiple of 0x10. Test that IBS + * driver honors HW constraints for various possible values in Freq as + * well as Sample Period mode IBS events. + */ + if (ibs_period_constraint_test()) + ret =3D TEST_FAIL; + + /* + * Test ioctl() with various sample period values for IBS event. + */ + if (ibs_ioctl_test()) + ret =3D TEST_FAIL; + + /* + * Test that opening of freq mode IBS event fails when the freq value + * is passed through ->config, not explicitly in ->sample_freq. Also + * use high freq value (beyond perf_event_max_sample_rate) to test IBS + * driver do not bypass perf_event_max_sample_rate checks. + */ + if (ibs_freq_neg_test()) + ret =3D TEST_FAIL; + + /* + * L3MissOnly is a post-processing filter, i.e. IBS HW checks for L3 + * Miss at the completion of the tagged uOp. The sample is discarded + * if the tagged uOp did not cause L3Miss. Also, IBS HW internally + * resets CurCnt to a small pseudo-random value and resumes counting. + * A new uOp is tagged once CurCnt reaches to MaxCnt. But the process + * repeats until the tagged uOp causes an L3 Miss. + * + * With the freq mode event, the next sample period is calculated by + * generic kernel on every sample to achieve desired freq of samples. + * + * Since the number of times HW internally reset CurCnt and the pseudo- + * random value of CurCnt for all those occurrences are not known to SW, + * the sample period adjustment by kernel goes for a toes for freq mode + * IBS events. Kernel will set very small period for the next sample if + * the window between current sample and prev sample is too high due to + * multiple samples being rejected by IBS internally. + * + * Test that IBS sample period constraints are honored when L3MissOnly + * is ON. + */ + if (ibs_l3missonly_test(perf)) + ret =3D TEST_FAIL; + + return ret; +} diff --git a/tools/perf/arch/x86/tests/arch-tests.c b/tools/perf/arch/x86/t= ests/arch-tests.c index a216a5d172ed..bfee2432515b 100644 --- a/tools/perf/arch/x86/tests/arch-tests.c +++ b/tools/perf/arch/x86/tests/arch-tests.c @@ -25,6 +25,7 @@ DEFINE_SUITE("x86 bp modify", bp_modify); #endif DEFINE_SUITE("x86 Sample parsing", x86_sample_parsing); DEFINE_SUITE("AMD IBS via core pmu", amd_ibs_via_core_pmu); +DEFINE_SUITE_EXCLUSIVE("AMD IBS sample period", amd_ibs_period); static struct test_case hybrid_tests[] =3D { TEST_CASE_REASON("x86 hybrid event parsing", hybrid, "not hybrid"), { .name =3D NULL, } @@ -50,6 +51,7 @@ struct test_suite *arch_tests[] =3D { #endif &suite__x86_sample_parsing, &suite__amd_ibs_via_core_pmu, + &suite__amd_ibs_period, &suite__hybrid, NULL, }; --=20 2.43.0