From nobody Sun Feb 8 13:27:39 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010004.outbound.protection.outlook.com [52.101.46.4]) (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 180032C15A2; Mon, 19 Jan 2026 17:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845580; cv=fail; b=B70fXQTUt7ShQnEGVqwMMcbeS9nFBtbVQZ0aUApNOEOxOLT8LSRxoUk2BtvXzHqeT1sWtrihsXQkkE3XF8vFyp5DNIyqIgfNfDbs3lV7eUnBx0eRtsHIGxxk1Nwaa09MJzzbo1KU4h0EIchtFq3JvBJeXCTI5u/OFzYEkU7ql+4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845580; c=relaxed/simple; bh=1ksHutykAyCAs3ZIxz8+aGwFZ5EHhlZ7Mcm8WTeuMyI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qEoyNP+0KlEiEXmZZNWnJK5iVuUlSUpUbJ2VveQGvFQ0fs+UuNPNSmCDnNMZHE08yGaBlAXkeWKtfPCZ4egfMdeCxlRX8OH/7KGNSeyYmr8AeZxoEFuhMmDcD5iiuOc8rhUo+i89dicnroJjqGnX9y6FuJcetZTbG9PZOO5mDZQ= 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=P9nopaHN; arc=fail smtp.client-ip=52.101.46.4 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="P9nopaHN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bzREyyyGOGB+aCgOWcRLDEkw3gc/KWx8Ab1AyjWB71BQ2b0hJ+qnt01bNIeiU1ibyCwBUOKGZDXvPn0dhmXYggO0zll7JEZZ8JoRGRPhbBw237v8Ja1xruy2TV4FUagEvah3w0XKa4pndilQ572H+YFKEfk49MjSXGgsfHbF4gi4sCPb/ZxS4IYe3t427IbJPkHzZhOOPJB+Iwm8Dg1nPRA49eNxj3YnhElMbwIizjJer2qFFZi5avhgKN3zrsfVfOXnhLEFg5XDft7UxWsIycL+kkCh4zAUgNhZZT6bFdru5dwTpsgDJNSTifBzm8Z8rqU1tYnI8sOkU6NoC9mPFQ== 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=nmfPCxHr4SSdqLB7mMRioZTXfR7oOdb555GIlHj+bgA=; b=eFRp1lHNMoL/CSa5wbMkagpv66WLQ0cV+/rPGoxIUyXPdHfyoJk1Qs9D2X9tfe7OxgWDREhEhABcONTAzZ5hUvvW9L4Z6OJycON+zmkcA1+LNGVYUQQFbDi1y1T84suhZQhXytvDAQOWHCugBxAsaKOfa/3mZJw6HmSHCHNLQ8OTc8eL4mxP4do7DcXSQRHVWSAaJ0f6oBx8kz6vs3L3FROddP27vnm107IfAPeiFHc3168f7FJIFUQkQE/lDdhhYJlqKQETsmxWF12snPdL5lmmI8pQeO1/OISfxVUin+DRrzlOK1xd60tqRTI22SWmcC5p+CsHW2WXu58aiijd0g== 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=nmfPCxHr4SSdqLB7mMRioZTXfR7oOdb555GIlHj+bgA=; b=P9nopaHNhkf2VLiSHAnWR0LRm1ItG5GoA2Qcuk1O/q19/MeWr0FT9qvl91GhtkmttL2gnecPNVXjiYY8kqNFvDc1wwIj/+Yu2wgoCFfbiH7zr82KnmWV9Af3FGcopvgAVMyR5LaiADLaj1NhlAjf6t+4mtfSe+Nn1HRXIRN8vqY= Received: from IA4P221CA0005.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:559::10) by BL1PR12MB5729.namprd12.prod.outlook.com (2603:10b6:208:384::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 17:59:33 +0000 Received: from BL6PEPF0001AB50.namprd04.prod.outlook.com (2603:10b6:208:559:cafe::bd) by IA4P221CA0005.outlook.office365.com (2603:10b6:208:559::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.12 via Frontend Transport; Mon, 19 Jan 2026 17:59:58 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB50.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 17:59:33 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 11:59:23 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 01/10] tools/lib: Add list_is_first() Date: Mon, 19 Jan 2026 17:58:23 +0000 Message-ID: <20260119175833.340369-2-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB50:EE_|BL1PR12MB5729:EE_ X-MS-Office365-Filtering-Correlation-Id: eae10db1-1bf0-48bd-6c27-08de57848052 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?c28fNMiEpoiOA93ge+MA144cftFR/qqxZfsgKlBjxMUEDROdZ0vIpBYPdM2V?= =?us-ascii?Q?6JwkeNywHL7zgBdWkmlvccvxaedklBIS15EmusLoiJ0Kv6ARd6bHnplS/KiY?= =?us-ascii?Q?M+V9L/naJz1vb2/Xhsw0RfHwz4D9EXsmaAHUAzWZG+HiOBbeinGi1iwOPsVa?= =?us-ascii?Q?RSLL1U5V27KPLjIExiAhIDLJ6p4M8lpyfQbP5NJY1yGSr3BwUTiVLdmtDrcq?= =?us-ascii?Q?WdUYKgq5ndShp+93fld2P/RBSGvNp+e2jeCV4aJg0duktbcavhlq2nYPrkeZ?= =?us-ascii?Q?mr6b5qglKke6bQedqZhV++FENUOL1T1bCESHYNncMI05smpOrWcPqsJUn90T?= =?us-ascii?Q?qkZzzi0ODsylsyrW7k3+tyDW65G8fry+Uwbp/5RJh0Huh9qRl8s5T+LuicIr?= =?us-ascii?Q?yo3ssHQGoFjZ1xuSoSn/iGSEq0ykhID+FkHYfSLIQInMzEVQNImOCVD6cFxe?= =?us-ascii?Q?GVjozLOrO3upb3TM+RXTCsOzsVZkOnICx+I1dGNkHpXXmmFDi5p43xd1M0fk?= =?us-ascii?Q?YgwFzJAeH0E8vZrIM13Sjm4WYG0Hph4gzZko23NjdPEPANkHLD4dIUCgNLnm?= =?us-ascii?Q?DG57iDlCVUQPLNOZ43+mvrXjiAXpWfqDOi92n/QHXuuavYRaIoRQaEPdUFxo?= =?us-ascii?Q?9mLujDTlq+8kz8a09HqrwyYZMNN7b7CVoBCZG6ZoUU7KuHIb3GCvlzzKUnd2?= =?us-ascii?Q?DL5SCLWH6Ki3CUqf/KWAYFU6jyZWQtlO7ypgBuCnv6FYCWVb3BsspICXnEbu?= =?us-ascii?Q?1NXlUmGFhVZvfeS73/+9tITkNx9Vfw76TOheUuTYmXzo7dZeQfTun+xivMt3?= =?us-ascii?Q?bPR5KtZwX97RfU1wX07h4xvruQTPqRbyX3+QmwrpxxJwM0pVaYarpjlfZd7q?= =?us-ascii?Q?fbQBZx6EwP7JSMxQuI5CA7dYPPEA+9gXBmiav1JPdPdHfCInu/x0qv0jAqmT?= =?us-ascii?Q?49em3rgkaY85Tgu8IgwOhs4RTHEUYauWzpeAXqy0tQ2dQN9CEcgrLhwZojse?= =?us-ascii?Q?hyE/FmIn2p6TvMstB1JMAJQA+PHJZLhN19oOMzPmxbaR3sKuva+Ro4eIhJb4?= =?us-ascii?Q?FR/Ami7+KhwYGwMQCuVnDS7Hd5yblkQ1c29SagEiwyIK7JHqkcGvfRokIHGc?= =?us-ascii?Q?Sz2uxL07GjbDZFDGoGyoZB3/HLIYpRgnJZd+uYadqOhTkA87O+btWrTPqxD1?= =?us-ascii?Q?kVYx3/NaOPf3fkySN4cB9a06vdbNp8RVRoNcG+3MQFeJmrIvJ9VSubOU+YSZ?= =?us-ascii?Q?JOMaicZqsbco8NSFSwcGKV4gWBGFBO5D8jC1ys3wDEdIO0TgQw8MkiV6/lFp?= =?us-ascii?Q?QQ0RfOON6DwrWeSoLlexy5BVLY15OXN0T3gNWw2HS6AhUc8pPi/aT9uSO4t+?= =?us-ascii?Q?ckilJ1BcqCVf2IBZf5S2LUjf7/8MHpOxLWByAxGqHqdMovqPoF9Yy7SbH8If?= =?us-ascii?Q?2CvjZlHGbgKxHjLidPeHqV9hdVbt8s82cNBaA+ZS4Sa7cts/zg2jqR+gfp5m?= =?us-ascii?Q?2W67py/GMui36GuC3o8AJ4i3GTFqUK50wA0E8BoKXlxxlmkn6poCYs2Ehle8?= =?us-ascii?Q?pBLXqfM9VooWOQHxaf/4LgyAKsj1Oo7xK/mOvzfBAS8kf9TRRvLtpj3/R26t?= =?us-ascii?Q?uYSaLMatjIcRYLunL19zUuAfckmoeq1wNXJG240AwYMQVKSCqPMqTAj+UgDB?= =?us-ascii?Q?Na6gyA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 17:59:33.2940 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eae10db1-1bf0-48bd-6c27-08de57848052 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB50.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5729 Content-Type: text/plain; charset="utf-8" Add list_is_first() to check whether @list is the first entry in list @head Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/include/linux/list.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/include/linux/list.h b/tools/include/linux/list.h index a4dfb6a7cc6a..a692ff7aed5c 100644 --- a/tools/include/linux/list.h +++ b/tools/include/linux/list.h @@ -169,6 +169,16 @@ static inline void list_move_tail(struct list_head *li= st, list_add_tail(list, head); } =20 +/** + * list_is_first -- tests whether @list is the first entry in list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_first(const struct list_head *list, const struct= list_head *head) +{ + return list->prev =3D=3D head; +} + /** * list_is_last - tests whether @list is the last entry in list @head * @list: the entry to test --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010043.outbound.protection.outlook.com [52.101.56.43]) (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 2A3FC32D0DC; Mon, 19 Jan 2026 18:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845609; cv=fail; b=tMRUa2lOpE2REw/eLSFICL+QOIpsfr6sqXUF8eg4/nY3bqyoKOe9NAAp3omWKc0Ct0K1ikVcHMCgHs6NOToC6SxJLFzwJfVLgHTdOHtbny9z7GSO97Cxe9CQn5IFLL7h+6mN4KwqShWse/g4RfZA0CTh91WckXJkYQ+EObIWw28= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845609; c=relaxed/simple; bh=JdjpCSovzT4LWPgbSjRYvmBTip9iLUsLIspuJBmTyOs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TJGPwxb8nN/acEQORpL3L+irgsdPe8QzwlydkEE+F4GJzMXghZxQhno2k3/iV6BZ1nTWRUySAF09STZJvdobK0QqtykFhSV0GsKTMIUVvQIc6SCDTZh73Viy26VmJFpn21Etk5BC1So5wQpSMo1ZWFFUv7nAJDUlZX0RvBU/mpg= 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=gnj4HdPe; arc=fail smtp.client-ip=52.101.56.43 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="gnj4HdPe" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=keil96/EpgwEYmoQtKSpRDmg6OK5l2LCV7BtsP1l+R0BKVsBOkaX5QK7MQ1dBwAHFxB8pdqxt6gD61ip72dgYAfKgtHxGVzM+lO4Y/6ZZJxKVeZhDkh4AfPwmy+EK91X1BMbxQGOWwsmJqShx0CH9mhY3SvuHZgVObgj+lewlQBjbUoA1qGzDVKWU/Q/UoSC2ZLhNAOh2A+UJFQ3UvPc8fkGGZoXK73302eQriQbnqsuQIXMGIqq8P/omBySk6JiAis8e+oXzEL4joLmiO14dTOnG51NixeSx+Bigc6wFRRNBOVf4/XroUmli6OqS7V7ZS/LTv5hhHU+MrHMynhENQ== 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=J94kY+PT8SKVHFSHeQD2A+eJCaXShVW/BKJdkxy96Zs=; b=XP0G0paSiIa6OIds1WJLycPq5sNJkXPj9l+Gl8ci2BSMkKRK4l1aEk9FscgryDAnAARCxN4xQlD17DaclrUVTPxRcoUA6n6IAr/Ylob4STz/IkaQIiEY3ewpEKAjpn0Ykkm2ewOO8WU8EJlOep3ZZ4vMn6yDSP2Bp6ak0ZusX4sE1IHRjA7oorZJF0q9SbHyW96uOQdHkEwqtbWuYFW0qZAL+P35ixHF0tTsbdof0EMIxIsTvT2VCbUblwTc22f2WuUtttsGBgEjqPkUyPDYycizd4zoRneJdN/5V4jSSmmeU7249RzoPmB+xMLcEOulErr0rA+vRFeADAaiFm8ukQ== 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=J94kY+PT8SKVHFSHeQD2A+eJCaXShVW/BKJdkxy96Zs=; b=gnj4HdPeBIc8pVG6hFlHkN08yNvF8GfxIh5Ut8VkYZ3pNibcObE+igutKZTDERsowMia7n1xkDWADWunc1pVsxiHx+T3yoHO0BwtyNDa8aXTjTwJ+n8D2xyomrmpPzynX7loc/S9IBEdmb2bScOM9hcsxOIeuzGeWSblKyE3+og= Received: from IA4P221CA0010.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:559::13) by BY5PR12MB4289.namprd12.prod.outlook.com (2603:10b6:a03:204::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.9; Mon, 19 Jan 2026 17:59:56 +0000 Received: from BL6PEPF0001AB50.namprd04.prod.outlook.com (2603:10b6:208:559:cafe::6f) by IA4P221CA0010.outlook.office365.com (2603:10b6:208:559::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.12 via Frontend Transport; Mon, 19 Jan 2026 17:59:56 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB50.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 17:59:56 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 11:59:46 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 02/10] perf header: Support CPU DOMAIN relation info Date: Mon, 19 Jan 2026 17:58:24 +0000 Message-ID: <20260119175833.340369-3-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB50:EE_|BY5PR12MB4289:EE_ X-MS-Office365-Filtering-Correlation-Id: a506cd8a-99cd-4484-0125-08de57848e1f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ugUyMM0O/j298+/intTCitJQya/3RWl7sTyJYrjrusEVoKfe03f1cfIkOwFl?= =?us-ascii?Q?sLTg2IvHpr6H9RvQwohAbmrfKlks+/fOTx9MA9RLyKK8JnfUR2Vip9iMJYVV?= =?us-ascii?Q?5zSWTLnr8I9iWDvYSfKHvpSbKWyPU6VfpC2p4RM6hNcXrk6t9wBobeOf1rNL?= =?us-ascii?Q?RCmxbmPnffUXaWYiJRdK6EUXjRly0XPFjtfoI+H8EFT/xTrkbunEnhuWDTmU?= =?us-ascii?Q?PPDGwlMo/HWdZIbjAKEXLTyrVWbwMqDt1Q4/Jow3rTJ7EoVnHjWoFbPADNTc?= =?us-ascii?Q?lj3n+ETYOvN0kHDKhmLa1D+FOKzZ4SV0wClc8DnisNdRVu/kKeYmIuf/ghYb?= =?us-ascii?Q?pSoPBrNr8pjuyWiyD7a1UGj5no+bfXcVPvd3wA/OevGs2xKtQjYunprrew29?= =?us-ascii?Q?X6Wh2D3cqMGkQOuQ7JrbzoWG/uMuKvh0itRklGd8BUb/7HXadqjuMhBssu2u?= =?us-ascii?Q?LibVmOuZY309IcR4CpxtIYetKm9U8BNkTQviOTEd4UBSzA8nxcuyx5HoytLB?= =?us-ascii?Q?gjRnY9g4vro0B6WjOLNd17GE6h5SqPvb896GoANT6iUM7TzCMe22OImasgUJ?= =?us-ascii?Q?ROzs36M2woMtMBhGiKjQgQr1xABGfRyAUJiYyt8hJmmnkqz9mys29gL0H2Kr?= =?us-ascii?Q?0EdECf/QkfBgWPZh6g9AAEGypbsa/sUv6OLcOx/2JajxhNRG/gWrZyNoTjBz?= =?us-ascii?Q?JeSIIZZuuTsmYCpWA5HzuLfPJWdouT5+O+Y0A6Sk++90vO89VLKEqzpxOBfC?= =?us-ascii?Q?yguAnjiLqAhiTojVqsTANNckA/YfQWYWIUM6P/lVkn+goGy7+icCxzoKfE5O?= =?us-ascii?Q?rQoHnwL8F3s+RIsI9mdW7F3mgB6tjW38R7EEWVYC7yJAyJ82P6JZ907BXjR9?= =?us-ascii?Q?Y9QH7oHRLasUQcyhgxztGfBU/8eg06ox3P02T70uMwKM7DnmcLYkh2wHYEsG?= =?us-ascii?Q?2En4LilT3LotzWOQY5N+NxYLXIU9RMBSwK0sixRFODSRZPbTGuPcwqQhpxUI?= =?us-ascii?Q?O0B3qbYSQcAhki9cVpsd7RC3mAvpTboqZENoTtRyNuVP/ZlXr5Dy82+P6snh?= =?us-ascii?Q?/4vUswzFb1miCPy/jksUGMMeBP1jgzxBZ+OJV4U8KJLp5uLewJ6OF/NIrsZH?= =?us-ascii?Q?D/3Qk1hrum9TyGXtSYcf2y0Z9q+Inh+t7I3pC4bLTYBsNz+s4d8CA3xQ3R3M?= =?us-ascii?Q?EyGSrCkTwj3cWZckdNKCCt7bS9ovnTlo7gEc6peix8/m0xAs2nQRK84CLX0c?= =?us-ascii?Q?ef4DT9N4w2Z1sQUteZMNGGSWY0xi7ejYutHC1UugUDmntHMTozFvGFnTYW+b?= =?us-ascii?Q?/+wma66H/V4SrVxONXvy6cFju8HPoXlHviAi5ZOMxbtJfwwbQCQg0yPvDf4F?= =?us-ascii?Q?ORpHaFrg7GuB/XQr/4UgsSfcYJIWilKnt/BeFltuzzy2XEh4xkw87kACIoEZ?= =?us-ascii?Q?ofZHBMmGpRL94omyJ9XsF5AAs+3rjZQH7AFHZDAFDhoToJr1B3EqwxDu/5Ef?= =?us-ascii?Q?HVwvQErpA3h32X11LtczuFCnQ5pdctSibbTjohI44+9uw+rNvbGaajQN1Gd9?= =?us-ascii?Q?wKpCDJGkx9KFQAyfpXbELho0JnnEz8457bLXzHzTfeR987VdPTsdTunLtDZ6?= =?us-ascii?Q?48tJJMqac5n23TsnlFjwHCoANhh5jtepqEylZZT8S1TLJnseK24POSDnsSUb?= =?us-ascii?Q?jTAZuA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 17:59:56.4447 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a506cd8a-99cd-4484-0125-08de57848e1f 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB50.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4289 Content-Type: text/plain; charset="utf-8" '/proc/schedstat' gives the info about load balancing statistics within a given domain. It also contains the cpu_mask giving information about the sibling cpus and domain names after schedstat version 17. Storing this information in perf header will help tools like `perf sched stats` for better analysis. Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- .../Documentation/perf.data-file-format.txt | 17 ++ tools/perf/builtin-inject.c | 1 + tools/perf/util/env.c | 29 ++ tools/perf/util/env.h | 17 ++ tools/perf/util/header.c | 286 ++++++++++++++++++ tools/perf/util/header.h | 1 + tools/perf/util/util.c | 42 +++ tools/perf/util/util.h | 3 + 8 files changed, 396 insertions(+) diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/per= f/Documentation/perf.data-file-format.txt index c9d4dec65344..0e4d0ecc9e12 100644 --- a/tools/perf/Documentation/perf.data-file-format.txt +++ b/tools/perf/Documentation/perf.data-file-format.txt @@ -447,6 +447,23 @@ struct { } [nr_pmu]; }; =20 + HEADER_CPU_DOMAIN_INFO =3D 32, + +List of cpu-domain relation info. The format of the data is as below. + +struct domain_info { + int domain; + char dname[]; + char cpumask[]; + char cpulist[]; +}; + +struct cpu_domain_info { + int cpu; + int nr_domains; + struct domain_info domains[]; +}; + other bits are reserved and should ignored for now HEADER_FEAT_BITS =3D 256, =20 diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 6080afec537d..587c180035b2 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2047,6 +2047,7 @@ static bool keep_feat(struct perf_inject *inject, int= feat) case HEADER_CLOCK_DATA: case HEADER_HYBRID_TOPOLOGY: case HEADER_PMU_CAPS: + case HEADER_CPU_DOMAIN_INFO: return true; /* Information that can be updated */ case HEADER_BUILD_ID: diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index f1626d2032cd..93d475a80f14 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -216,6 +216,34 @@ static void perf_env__purge_bpf(struct perf_env *env _= _maybe_unused) } #endif // HAVE_LIBBPF_SUPPORT =20 +void free_cpu_domain_info(struct cpu_domain_map **cd_map, u32 schedstat_ve= rsion, u32 nr) +{ + if (!cd_map) + return; + + for (u32 i =3D 0; i < nr; i++) { + if (!cd_map[i]) + continue; + + for (u32 j =3D 0; j < cd_map[i]->nr_domains; j++) { + struct domain_info *d_info =3D cd_map[i]->domains[j]; + + if (!d_info) + continue; + + if (schedstat_version >=3D 17) + zfree(&d_info->dname); + + zfree(&d_info->cpumask); + zfree(&d_info->cpulist); + zfree(&d_info); + } + zfree(&cd_map[i]->domains); + zfree(&cd_map[i]); + } + zfree(&cd_map); +} + void perf_env__exit(struct perf_env *env) { int i, j; @@ -265,6 +293,7 @@ void perf_env__exit(struct perf_env *env) zfree(&env->pmu_caps[i].pmu_name); } zfree(&env->pmu_caps); + free_cpu_domain_info(env->cpu_domain, env->schedstat_version, env->nr_cpu= s_avail); } =20 void perf_env__init(struct perf_env *env) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 9977b85523a8..76ba1a36e9ff 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -54,6 +54,19 @@ struct pmu_caps { char *pmu_name; }; =20 +struct domain_info { + u32 domain; + char *dname; + char *cpumask; + char *cpulist; +}; + +struct cpu_domain_map { + u32 cpu; + u32 nr_domains; + struct domain_info **domains; +}; + typedef const char *(arch_syscalls__strerrno_t)(int err); =20 struct perf_env { @@ -70,6 +83,8 @@ struct perf_env { unsigned int max_branches; unsigned int br_cntr_nr; unsigned int br_cntr_width; + unsigned int schedstat_version; + unsigned int max_sched_domains; int kernel_is_64_bit; =20 int nr_cmdline; @@ -92,6 +107,7 @@ struct perf_env { char **cpu_pmu_caps; struct cpu_topology_map *cpu; struct cpu_cache_level *caches; + struct cpu_domain_map **cpu_domain; int caches_cnt; u32 comp_ratio; u32 comp_ver; @@ -151,6 +167,7 @@ struct bpf_prog_info_node; struct btf_node; =20 int perf_env__read_core_pmu_caps(struct perf_env *env); +void free_cpu_domain_info(struct cpu_domain_map **cd_map, u32 schedstat_ve= rsion, u32 nr); void perf_env__exit(struct perf_env *env); =20 int perf_env__kernel_is_64_bit(struct perf_env *env); diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index f5cad377c99e..673d53bb2a2c 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1614,6 +1614,162 @@ static int write_pmu_caps(struct feat_fd *ff, return 0; } =20 +static struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version= , u32 *max_sched_domains, + u32 nr) +{ + struct domain_info *domain_info; + struct cpu_domain_map **cd_map; + char dname[16], cpumask[256]; + char cpulist[1024]; + char *line =3D NULL; + u32 cpu, domain; + u32 dcount =3D 0; + size_t len; + FILE *fp; + + fp =3D fopen("/proc/schedstat", "r"); + if (!fp) { + pr_err("Failed to open /proc/schedstat\n"); + return NULL; + } + + cd_map =3D zalloc(sizeof(*cd_map) * nr); + if (!cd_map) + goto out; + + while (getline(&line, &len, fp) > 0) { + int retval; + + if (strncmp(line, "version", 7) =3D=3D 0) { + retval =3D sscanf(line, "version %d\n", schedstat_version); + if (retval !=3D 1) + continue; + + } else if (strncmp(line, "cpu", 3) =3D=3D 0) { + retval =3D sscanf(line, "cpu%u %*s", &cpu); + if (retval =3D=3D 1) { + cd_map[cpu] =3D zalloc(sizeof(*cd_map[cpu])); + if (!cd_map[cpu]) + goto out_free_line; + cd_map[cpu]->cpu =3D cpu; + } else + continue; + + dcount =3D 0; + } else if (strncmp(line, "domain", 6) =3D=3D 0) { + struct domain_info **temp_domains; + + dcount++; + temp_domains =3D realloc(cd_map[cpu]->domains, dcount * sizeof(domain_i= nfo)); + if (!temp_domains) + goto out_free_line; + else + cd_map[cpu]->domains =3D temp_domains; + + domain_info =3D zalloc(sizeof(*domain_info)); + if (!domain_info) + goto out_free_line; + + cd_map[cpu]->domains[dcount - 1] =3D domain_info; + + if (*schedstat_version >=3D 17) { + retval =3D sscanf(line, "domain%u %s %s %*s", &domain, dname, + cpumask); + if (retval !=3D 3) + continue; + + domain_info->dname =3D strdup(dname); + if (!domain_info->dname) + goto out_free_line; + } else { + retval =3D sscanf(line, "domain%u %s %*s", &domain, cpumask); + if (retval !=3D 2) + continue; + } + + domain_info->domain =3D domain; + if (domain > *max_sched_domains) + *max_sched_domains =3D domain; + + domain_info->cpumask =3D strdup(cpumask); + if (!domain_info->cpumask) + goto out_free_line; + + cpumask_to_cpulist(cpumask, cpulist); + domain_info->cpulist =3D strdup(cpulist); + if (!domain_info->cpulist) + goto out_free_line; + + cd_map[cpu]->nr_domains =3D dcount; + } + } + +out_free_line: + free(line); +out: + fclose(fp); + return cd_map; +} + +static int write_cpu_domain_info(struct feat_fd *ff, + struct evlist *evlist __maybe_unused) +{ + u32 max_sched_domains =3D 0, schedstat_version =3D 0; + struct cpu_domain_map **cd_map; + u32 i, j, nr, ret; + + nr =3D cpu__max_present_cpu().cpu; + + cd_map =3D build_cpu_domain_map(&schedstat_version, &max_sched_domains, n= r); + if (!cd_map) + return -1; + + ret =3D do_write(ff, &schedstat_version, sizeof(u32)); + if (ret < 0) + goto out; + + max_sched_domains +=3D 1; + ret =3D do_write(ff, &max_sched_domains, sizeof(u32)); + if (ret < 0) + goto out; + + for (i =3D 0; i < nr; i++) { + if (!cd_map[i]) + continue; + + ret =3D do_write(ff, &cd_map[i]->cpu, sizeof(u32)); + if (ret < 0) + goto out; + + ret =3D do_write(ff, &cd_map[i]->nr_domains, sizeof(u32)); + if (ret < 0) + goto out; + + for (j =3D 0; j < cd_map[i]->nr_domains; j++) { + ret =3D do_write(ff, &cd_map[i]->domains[j]->domain, sizeof(u32)); + if (ret < 0) + goto out; + if (schedstat_version >=3D 17) { + ret =3D do_write_string(ff, cd_map[i]->domains[j]->dname); + if (ret < 0) + goto out; + } + + ret =3D do_write_string(ff, cd_map[i]->domains[j]->cpumask); + if (ret < 0) + goto out; + + ret =3D do_write_string(ff, cd_map[i]->domains[j]->cpulist); + if (ret < 0) + goto out; + } + } + +out: + free_cpu_domain_info(cd_map, schedstat_version, nr); + return ret; +} + static void print_hostname(struct feat_fd *ff, FILE *fp) { fprintf(fp, "# hostname : %s\n", ff->ph->env.hostname); @@ -2247,6 +2403,39 @@ static void print_mem_topology(struct feat_fd *ff, F= ILE *fp) } } =20 +static void print_cpu_domain_info(struct feat_fd *ff, FILE *fp) +{ + struct cpu_domain_map **cd_map =3D ff->ph->env.cpu_domain; + u32 nr =3D ff->ph->env.nr_cpus_avail; + struct domain_info *d_info; + u32 i, j; + + fprintf(fp, "# schedstat version : %u\n", ff->ph->env.schedstat_version); + fprintf(fp, "# Maximum sched domains : %u\n", ff->ph->env.max_sched_domai= ns); + + for (i =3D 0; i < nr; i++) { + if (!cd_map[i]) + continue; + + fprintf(fp, "# cpu : %u\n", cd_map[i]->cpu); + fprintf(fp, "# nr_domains : %u\n", cd_map[i]->nr_domains); + + for (j =3D 0; j < cd_map[i]->nr_domains; j++) { + d_info =3D cd_map[i]->domains[j]; + if (!d_info) + continue; + + fprintf(fp, "# Domain : %u\n", d_info->domain); + + if (ff->ph->env.schedstat_version >=3D 17) + fprintf(fp, "# Domain name : %s\n", d_info->dname); + + fprintf(fp, "# Domain cpu map : %s\n", d_info->cpumask); + fprintf(fp, "# Domain cpu list : %s\n", d_info->cpulist); + } + } +} + static int __event_process_build_id(struct perf_record_header_build_id *be= v, char *filename, struct perf_session *session) @@ -3388,6 +3577,102 @@ static int process_pmu_caps(struct feat_fd *ff, voi= d *data __maybe_unused) return ret; } =20 +static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_= unused) +{ + u32 schedstat_version, max_sched_domains, cpu, domain, nr_domains; + struct perf_env *env =3D &ff->ph->env; + char *dname, *cpumask, *cpulist; + struct cpu_domain_map **cd_map; + struct domain_info *d_info; + u32 nra, nr, i, j; + int ret; + + nra =3D env->nr_cpus_avail; + nr =3D env->nr_cpus_online; + + cd_map =3D zalloc(sizeof(*cd_map) * nra); + if (!cd_map) + return -1; + + env->cpu_domain =3D cd_map; + + ret =3D do_read_u32(ff, &schedstat_version); + if (ret) + return ret; + + env->schedstat_version =3D schedstat_version; + + ret =3D do_read_u32(ff, &max_sched_domains); + if (ret) + return ret; + + env->max_sched_domains =3D max_sched_domains; + + for (i =3D 0; i < nr; i++) { + if (do_read_u32(ff, &cpu)) + return -1; + + cd_map[cpu] =3D zalloc(sizeof(*cd_map[cpu])); + if (!cd_map[cpu]) + return -1; + + cd_map[cpu]->cpu =3D cpu; + + if (do_read_u32(ff, &nr_domains)) + return -1; + + cd_map[cpu]->nr_domains =3D nr_domains; + + cd_map[cpu]->domains =3D zalloc(sizeof(*d_info) * max_sched_domains); + if (!cd_map[cpu]->domains) + return -1; + + for (j =3D 0; j < nr_domains; j++) { + if (do_read_u32(ff, &domain)) + return -1; + + d_info =3D zalloc(sizeof(*d_info)); + if (!d_info) + return -1; + + cd_map[cpu]->domains[domain] =3D d_info; + d_info->domain =3D domain; + + if (schedstat_version >=3D 17) { + dname =3D do_read_string(ff); + if (!dname) + return -1; + + d_info->dname =3D zalloc(strlen(dname) + 1); + if (!d_info->dname) + return -1; + + d_info->dname =3D strdup(dname); + } + + cpumask =3D do_read_string(ff); + if (!cpumask) + return -1; + + d_info->cpumask =3D zalloc(strlen(cpumask) + 1); + if (!d_info->cpumask) + return -1; + d_info->cpumask =3D strdup(cpumask); + + cpulist =3D do_read_string(ff); + if (!cpulist) + return -1; + + d_info->cpulist =3D zalloc(strlen(cpulist) + 1); + if (!d_info->cpulist) + return -1; + d_info->cpulist =3D strdup(cpulist); + } + } + + return ret; +} + #define FEAT_OPR(n, func, __full_only) \ [HEADER_##n] =3D { \ .name =3D __stringify(n), \ @@ -3453,6 +3738,7 @@ const struct perf_header_feature_ops feat_ops[HEADER_= LAST_FEATURE] =3D { FEAT_OPR(CLOCK_DATA, clock_data, false), FEAT_OPN(HYBRID_TOPOLOGY, hybrid_topology, true), FEAT_OPR(PMU_CAPS, pmu_caps, false), + FEAT_OPR(CPU_DOMAIN_INFO, cpu_domain_info, true), }; =20 struct header_print_data { diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index c058021c3150..c62f3275a80f 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -53,6 +53,7 @@ enum { HEADER_CLOCK_DATA, HEADER_HYBRID_TOPOLOGY, HEADER_PMU_CAPS, + HEADER_CPU_DOMAIN_INFO, HEADER_LAST_FEATURE, HEADER_FEAT_BITS =3D 256, }; diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 0f031eb80b4c..b87ff96a9f45 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -257,6 +257,48 @@ static int rm_rf_kcore_dir(const char *path) return 0; } =20 +void cpumask_to_cpulist(char *cpumask, char *cpulist) +{ + int i, j, bm_size, nbits; + int len =3D strlen(cpumask); + unsigned long *bm; + char cpus[1024]; + + for (i =3D 0; i < len; i++) { + if (cpumask[i] =3D=3D ',') { + for (j =3D i; j < len; j++) + cpumask[j] =3D cpumask[j + 1]; + } + } + + len =3D strlen(cpumask); + bm_size =3D (len + 15) / 16; + nbits =3D bm_size * 64; + if (nbits <=3D 0) + return; + + bm =3D calloc(bm_size, sizeof(unsigned long)); + if (!cpumask) + goto free_bm; + + for (i =3D 0; i < bm_size; i++) { + char blk[17]; + int blklen =3D len > 16 ? 16 : len; + + strncpy(blk, cpumask + len - blklen, blklen); + blk[blklen] =3D '\0'; + bm[i] =3D strtoul(blk, NULL, 16); + cpumask[len - blklen] =3D '\0'; + len =3D strlen(cpumask); + } + + bitmap_scnprintf(bm, nbits, cpus, sizeof(cpus)); + strcpy(cpulist, cpus); + +free_bm: + free(bm); +} + int rm_rf_perf_data(const char *path) { const char *pat[] =3D { diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 3423778e39a5..1572c8cf04e5 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #ifndef __cplusplus #include @@ -48,6 +49,8 @@ bool sysctl__nmi_watchdog_enabled(void); =20 int perf_tip(char **strp, const char *dirpath); =20 +void cpumask_to_cpulist(char *cpumask, char *cpulist); + #ifndef HAVE_SCHED_GETCPU_SUPPORT int sched_getcpu(void); #endif --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012036.outbound.protection.outlook.com [40.107.209.36]) (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 8092032E6A2; Mon, 19 Jan 2026 18:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845630; cv=fail; b=qsUigfgNorLj/ATyVL0GHdnY6IgIjNsVt8V7oh9FDacLhEpBP1xQzpGIrtFxwwz8/VTTvsEs9emfcNmWyoU2C5TmRPgvmpc+swgLi6tH3NadItevSXdhDmlOtXCBur49P/CQ80zZOKmNVvWjk0WqlSh1ePK+LmDPYLMBvpKehTs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845630; c=relaxed/simple; bh=WVYduS1CE6NwNduvrcdZwKOYBb6RFOxOaNcXqWqdf6s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WLKo9IQ+8fiiK3tNDUBaivKmbvuoVwaJ9253tsoDQdYbxhuJAJpvz9olMm2uDSiO2MV8q+qz3J7goY2ORdBht9YXQMONIuUafftOtNdns94NGoz9TURLBQAON5n5m5xkhECFyanz7BVYoZhTdUPXvDkhSnixlnIqyfABwS0id2E= 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=q3F+g2Y1; arc=fail smtp.client-ip=40.107.209.36 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="q3F+g2Y1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bicn+GEBpduHSDoZZvrMrZVg8G5G0p/WapWzh052W2C6CekDwr47v5hDazVt+zgru0HzopzT6G0LNWK1yojirvOhlF9b8ULnN9htCa1A6CtTlRJtHc1D9fvN+tZCi3piUec2mKNCZc2yfRrZm/mkAtDJTKCqTkiOHk2++6yK4cGZLJAKZyVPV2Hj3pBxe4nq9O6Jr4F13JTRrPCJDhgk9IJJMYs0n934sMdn24ZynFyKNCgj36Uk8IsT7mWPCl2sMPvu7RkK4ri1IObQ4YV5fAJ0CUYMR6d/FcZpl0ahdfZZ9HMPTvnUr7NTefZFFdEFPp9v587aORl0dluf0cwmMA== 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=GrUoHoB7oP/k7aOgAbJN/+gZ7anpgsH7bNVc6WdBl4A=; b=ffoLcY4HHoElv5yGm8tXoUROwUeDbHTJpOwQID1tVil2eL/sdMCM1UeB9/zETWyUl85yqBaB5hf/ctFEusVo6yqGXdtL5NMYoB8EEvpn697aV2Kyv24q+p4Y3KtrDABOJovNVzd/joblloUB6Jbo3Z/32VJJ/EfS2Yo7oy64LSKozX0RpKcBDS7ajXmrmd/jZ8474EFTALmdGyuo+fri1/SAv8uqKD7YbxuH+OikS05ioW0uP6QNrW3txwGYUsvcOoLywdbeabaesfYAfP/mOY/RCkzjzmMYhRcY7yoiQO8WvKzO+zdI1pqMSPrRY4coDW1cQf1VSAYOJkKFvvqkow== 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=GrUoHoB7oP/k7aOgAbJN/+gZ7anpgsH7bNVc6WdBl4A=; b=q3F+g2Y1OxSIPTPDPLFj/e09CD6rlYQnxE0j28/488POXEQKbAV5HWGUY+yNbmPSy/w7q0sbs7kVWt6A6Ys3hHFHOPoReFaAp7lOgmUF4wy9HFxorwexIIf/bRv2oBaxn9Oq3pG7R3VSHVOX7G50BmquvtZPMG+/rKTvXCe3BOs= Received: from BL1PR13CA0311.namprd13.prod.outlook.com (2603:10b6:208:2c1::16) by MW4PR12MB7288.namprd12.prod.outlook.com (2603:10b6:303:223::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 18:00:20 +0000 Received: from BL6PEPF0001AB4D.namprd04.prod.outlook.com (2603:10b6:208:2c1:cafe::cb) by BL1PR13CA0311.outlook.office365.com (2603:10b6:208:2c1::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9542.8 via Frontend Transport; Mon, 19 Jan 2026 18:00:17 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB4D.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:00:19 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:00:09 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "James Clark" Subject: [PATCH v5 03/10] perf sched stats: Add record and rawdump support Date: Mon, 19 Jan 2026 17:58:25 +0000 Message-ID: <20260119175833.340369-4-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4D:EE_|MW4PR12MB7288:EE_ X-MS-Office365-Filtering-Correlation-Id: b6afe84c-5150-4e6e-d544-08de57849c10 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?6XvkZvm1zJIvC93PMHPhmDf1DmlIvszhxJwpnZ2XcwGn8VItpq5AZrftBZkM?= =?us-ascii?Q?u86TbeJdLGvmUHQDMS1j4Rga6Iklb80QjedQNjmvDMAdpBxJAW6IwniM5/sp?= =?us-ascii?Q?H5z7RsM3NnKa/vDiEDpiVynUli9EMipnbQa3lUex/6jX4Ex8/9d/T40d+2MI?= =?us-ascii?Q?+M4+fUAj3mj+XmZW4ZigGcpYRc97WrOedemTDYd0ldAee2qFS5WOqIl/pR0C?= =?us-ascii?Q?5VoRbCYPiAcBlv5pMkIXqcrjJZz341GevxicMmKz9LBAOX8LQQ6WLoJlHX4q?= =?us-ascii?Q?d8SPoVqTbXO4ZoxIK0Sg9Soo+Ora0Wm52rNnNC6vovFqAnwl8ngEUURmQr/H?= =?us-ascii?Q?NmJnW97X48pSZ7sYeqNL6hZmRkrH/irjgIfjviDbr/qbySziha3tK1LPhqAS?= =?us-ascii?Q?98CApChp2NpGUaw5v3Wx9gafxSkOUePHlPRjBcQkEbpPENqQl7TYILWwc2VP?= =?us-ascii?Q?Ig7oZxO7vz8ZolAR/BISI523yIaRrFx83XEv6nuCsK7mumx43nvQtcKYR+It?= =?us-ascii?Q?wm1YlsWrSjjYsfSB224WZemcLSFDEfBGLFtj5DcaSR18WAatIX/PXWD9zjuz?= =?us-ascii?Q?tL2S+ZBwORzY9FWTWSjuzlfeplSoy2E8QDyJAqa4gpPO1S5cuQ3tMi5Nxn9f?= =?us-ascii?Q?wW/P5SnFnVCsDNOQGTYw84mmSOTuIbG9fudqbDG85gkbRP9cl7Fmb5vZBRwi?= =?us-ascii?Q?V5EMv7Df4RZbQf+1o7qlQANkml05CPl6DalYBHxdM/inBb0+RfnG588RSqZz?= =?us-ascii?Q?kxEC6LcbciLy8v3lsk2yJaHEj6vdmhNxymL1bnP7x7pkbni863GwaxFMkP6t?= =?us-ascii?Q?WhOc+l4OgddQkr8Z5P4oE9fAL6Q+yJxQErQAcUd1o3r63oEI8O2CkvAGSRsc?= =?us-ascii?Q?csMAh3Ufi6sIqYnIoiWTdSuyrTDnqyMbPegG73I00JdwGfapK1yopfwiH5Rn?= =?us-ascii?Q?hUrEFL7Rj0s7TKMQkK6uMwxPCNEDTNZMZrz3Tbey5jS2ZwfuB77wROvu5q3J?= =?us-ascii?Q?izlr9xr3zA8RX8dNS1x7beO3qxlAfCGKcngPIb3L+W0INh/khTQO8tBRBQdg?= =?us-ascii?Q?To97YJKLa5/pQPMzx9NibvAxfCJhUdlLiM25fhI129i2/kTR9436l1Zh6iWk?= =?us-ascii?Q?LVzdHcNjRdpzRXypVhaYLyuRuthbUrRQFs5+VPTlbJQEGCuNuew7L8pKKlmx?= =?us-ascii?Q?YkLUSVyXnlMVCMizHGmqxK+zGSJDpwOyyuHOuhe8baawts/kcrb0TQsoemOG?= =?us-ascii?Q?YLVBaZe6xNX3Yfk4chU7x//bEoK1gMZrDQUwUJR1ZNOuMd/BofgoLeGYXqP5?= =?us-ascii?Q?nZZP7fq5kMxv84kLcD/pMQk546hPrkRoSEsNsOVEzEoG4/IIxLVvkjVGfTDD?= =?us-ascii?Q?KvaPvx9BNKtUtZff/VgBUGp/hT4/dgsbVk47zlcgfMHhKbOIaMcPBUdvWlgv?= =?us-ascii?Q?keEZgAQXnXB6vrhBqXNDxM9tqxwsoq0VEh8p4E9CgyuRTH5ByMxNJ3DWpbdG?= =?us-ascii?Q?bCI5IvxMNuBVRknC8A42H5pP+bCXz3csibTylb+acHsF5xzFxcWIRe2CWhxS?= =?us-ascii?Q?I8mlz7mCBuq6dmYX58CO3X8Icsk9QPwUsASDxAnz4SqfIejuOEm8m6iDhFwt?= =?us-ascii?Q?gk0l19VCuOGKP+Zr3EEn+18nRPcpcEbYUm1O2f4heZhHsoPmVPz1pfDPIPzE?= =?us-ascii?Q?EP0q5A=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:00:19.8399 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6afe84c-5150-4e6e-d544-08de57849c10 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB4D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7288 Content-Type: text/plain; charset="utf-8" Define new, perf tool only, sample types and their layouts. Add logic to parse /proc/schedstat, convert it to perf sample format and save samples to perf.data file with `perf sched stats record` command. Also add logic to read perf.data file, interpret schedstat samples and print rawdump of samples with `perf script -D`. Note that, /proc/schedstat file output is standardized with version number. The patch supports v15 but older or newer version can be added easily. Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/lib/perf/Documentation/libperf.txt | 2 + tools/lib/perf/Makefile | 1 + tools/lib/perf/include/perf/event.h | 41 ++++ tools/lib/perf/include/perf/schedstat-v15.h | 146 +++++++++++++ tools/perf/builtin-inject.c | 2 + tools/perf/builtin-sched.c | 222 +++++++++++++++++++- tools/perf/util/event.c | 40 ++++ tools/perf/util/event.h | 2 + tools/perf/util/session.c | 22 ++ tools/perf/util/synthetic-events.c | 179 ++++++++++++++++ tools/perf/util/synthetic-events.h | 3 + tools/perf/util/tool.c | 20 ++ tools/perf/util/tool.h | 4 +- 13 files changed, 682 insertions(+), 2 deletions(-) create mode 100644 tools/lib/perf/include/perf/schedstat-v15.h diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index 4072bc9b7670..576ecc5fc312 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -211,6 +211,8 @@ SYNOPSIS struct perf_record_header_feature; struct perf_record_compressed; struct perf_record_compressed2; + struct perf_record_schedstat_cpu; + struct perf_record_schedstat_domain; -- =20 DESCRIPTION diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile index 7fbb50b74c00..9fa28e512ca8 100644 --- a/tools/lib/perf/Makefile +++ b/tools/lib/perf/Makefile @@ -179,6 +179,7 @@ install_lib: libs cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) =20 HDRS :=3D bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h = mmap.h +HDRS +=3D schedstat-v15.h INTERNAL_HDRS :=3D cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threa= dmap.h xyarray.h =20 INSTALL_HDRS_PFX :=3D $(DESTDIR)$(prefix)/include/perf diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/p= erf/event.h index 43a8cb04994f..ce04fed7cefc 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -496,6 +496,43 @@ struct perf_record_bpf_metadata { struct perf_record_bpf_metadata_entry entries[]; }; =20 +struct perf_record_schedstat_cpu_v15 { +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) _= type _name +#include "schedstat-v15.h" +#undef CPU_FIELD +}; + +struct perf_record_schedstat_cpu { + struct perf_event_header header; + __u64 timestamp; + __u32 cpu; + __u16 version; + /* Padding */ + char __pad[2]; + union { + struct perf_record_schedstat_cpu_v15 v15; + }; +}; + +struct perf_record_schedstat_domain_v15 { +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) _ty= pe _name +#include "schedstat-v15.h" +#undef DOMAIN_FIELD +}; + +#define DOMAIN_NAME_LEN 16 + +struct perf_record_schedstat_domain { + struct perf_event_header header; + __u64 timestamp; + __u32 cpu; + __u16 version; + __u16 domain; + union { + struct perf_record_schedstat_domain_v15 v15; + }; +}; + enum perf_user_event_type { /* above any possible kernel type */ PERF_RECORD_USER_TYPE_START =3D 64, PERF_RECORD_HEADER_ATTR =3D 64, @@ -519,6 +556,8 @@ enum perf_user_event_type { /* above any possible kerne= l type */ PERF_RECORD_FINISHED_INIT =3D 82, PERF_RECORD_COMPRESSED2 =3D 83, PERF_RECORD_BPF_METADATA =3D 84, + PERF_RECORD_SCHEDSTAT_CPU =3D 85, + PERF_RECORD_SCHEDSTAT_DOMAIN =3D 86, PERF_RECORD_HEADER_MAX }; =20 @@ -562,6 +601,8 @@ union perf_event { struct perf_record_compressed pack; struct perf_record_compressed2 pack2; struct perf_record_bpf_metadata bpf_metadata; + struct perf_record_schedstat_cpu schedstat_cpu; + struct perf_record_schedstat_domain schedstat_domain; }; =20 #endif /* __LIBPERF_EVENT_H */ diff --git a/tools/lib/perf/include/perf/schedstat-v15.h b/tools/lib/perf/i= nclude/perf/schedstat-v15.h new file mode 100644 index 000000000000..639458df05f8 --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-v15.h @@ -0,0 +1,146 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CPU_FIELD +CPU_FIELD(__u32, yld_count, "sched_yield() count", + "%11u", false, yld_count, v15); +CPU_FIELD(__u32, array_exp, "Legacy counter can be ignored", + "%11u", false, array_exp, v15); +CPU_FIELD(__u32, sched_count, "schedule() called", + "%11u", false, sched_count, v15); +CPU_FIELD(__u32, sched_goidle, "schedule() left the processor idle", + "%11u", true, sched_count, v15); +CPU_FIELD(__u32, ttwu_count, "try_to_wake_up() was called", + "%11u", false, ttwu_count, v15); +CPU_FIELD(__u32, ttwu_local, "try_to_wake_up() was called to wake up the l= ocal cpu", + "%11u", true, ttwu_count, v15); +CPU_FIELD(__u64, rq_cpu_time, "total runtime by tasks on this processor (i= n jiffies)", + "%11llu", false, rq_cpu_time, v15); +CPU_FIELD(__u64, run_delay, "total waittime by tasks on this processor (in= jiffies)", + "%11llu", true, rq_cpu_time, v15); +CPU_FIELD(__u64, pcount, "total timeslices run on this cpu", + "%11llu", false, pcount, v15); +#endif + +#ifdef DOMAIN_FIELD +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, idle_lb_count, + "load_balance() count on cpu idle", "%11u", true, v15); +DOMAIN_FIELD(__u32, idle_lb_balanced, + "load_balance() found balanced on cpu idle", "%11u", true, v15); +DOMAIN_FIELD(__u32, idle_lb_failed, + "load_balance() move task failed on cpu idle", "%11u", true, v15); +DOMAIN_FIELD(__u32, idle_lb_imbalance, + "imbalance sum on cpu idle", "%11u", false, v15); +DOMAIN_FIELD(__u32, idle_lb_gained, + "pull_task() count on cpu idle", "%11u", false, v15); +DOMAIN_FIELD(__u32, idle_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu idle", "%11u", fa= lse, v15); +DOMAIN_FIELD(__u32, idle_lb_nobusyq, + "load_balance() failed to find busier queue on cpu idle", "%11u", tr= ue, v15); +DOMAIN_FIELD(__u32, idle_lb_nobusyg, + "load_balance() failed to find busier group on cpu idle", "%11u", tr= ue, v15); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(idle_lb_success_count, "load_balance() success count on = cpu idle", "%11u", + idle_lb_count, idle_lb_balanced, idle_lb_failed, v15); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(idle_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu idle)", "%11.2Lf", + idle_lb_count, idle_lb_balanced, idle_lb_failed, idle_lb_gained, v15); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, busy_lb_count, + "load_balance() count on cpu busy", "%11u", true, v15); +DOMAIN_FIELD(__u32, busy_lb_balanced, + "load_balance() found balanced on cpu busy", "%11u", true, v15); +DOMAIN_FIELD(__u32, busy_lb_failed, + "load_balance() move task failed on cpu busy", "%11u", true, v15); +DOMAIN_FIELD(__u32, busy_lb_imbalance, + "imbalance sum on cpu busy", "%11u", false, v15); +DOMAIN_FIELD(__u32, busy_lb_gained, + "pull_task() count on cpu busy", "%11u", false, v15); +DOMAIN_FIELD(__u32, busy_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu busy", "%11u", fa= lse, v15); +DOMAIN_FIELD(__u32, busy_lb_nobusyq, + "load_balance() failed to find busier queue on cpu busy", "%11u", tr= ue, v15); +DOMAIN_FIELD(__u32, busy_lb_nobusyg, + "load_balance() failed to find busier group on cpu busy", "%11u", tr= ue, v15); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(busy_lb_success_count, "load_balance() success count on = cpu busy", "%11u", + busy_lb_count, busy_lb_balanced, busy_lb_failed, v15); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(busy_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu busy)", "%11.2Lf", + busy_lb_count, busy_lb_balanced, busy_lb_failed, busy_lb_gained, v15); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, newidle_lb_count, + "load_balance() count on cpu newly idle", "%11u", true, v15); +DOMAIN_FIELD(__u32, newidle_lb_balanced, + "load_balance() found balanced on cpu newly idle", "%11u", true, v15= ); +DOMAIN_FIELD(__u32, newidle_lb_failed, + "load_balance() move task failed on cpu newly idle", "%11u", true, v= 15); +DOMAIN_FIELD(__u32, newidle_lb_imbalance, + "imbalance sum on cpu newly idle", "%11u", false, v15); +DOMAIN_FIELD(__u32, newidle_lb_gained, + "pull_task() count on cpu newly idle", "%11u", false, v15); +DOMAIN_FIELD(__u32, newidle_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu newly idle", "%11= u", false, v15); +DOMAIN_FIELD(__u32, newidle_lb_nobusyq, + "load_balance() failed to find busier queue on cpu newly idle", "%11= u", true, v15); +DOMAIN_FIELD(__u32, newidle_lb_nobusyg, + "load_balance() failed to find busier group on cpu newly idle", "%11= u", true, v15); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(newidle_lb_success_count, + "load_balance() success count on cpu newly idle", "%11u", + newidle_lb_count, newidle_lb_balanced, newidle_lb_failed, v15); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(newidle_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu newly idle)", "%11.2Lf= ", + newidle_lb_count, newidle_lb_balanced, newidle_lb_failed, newidle_lb_g= ained, v15); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, alb_count, + "active_load_balance() count", "%11u", false, v15); +DOMAIN_FIELD(__u32, alb_failed, + "active_load_balance() move task failed", "%11u", false, v15); +DOMAIN_FIELD(__u32, alb_pushed, + "active_load_balance() successfully moved a task", "%11u", false, v1= 5); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, sbe_count, + "sbe_count is not used", "%11u", false, v15); +DOMAIN_FIELD(__u32, sbe_balanced, + "sbe_balanced is not used", "%11u", false, v15); +DOMAIN_FIELD(__u32, sbe_pushed, + "sbe_pushed is not used", "%11u", false, v15); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, sbf_count, + "sbf_count is not used", "%11u", false, v15); +DOMAIN_FIELD(__u32, sbf_balanced, + "sbf_balanced is not used", "%11u", false, v15); +DOMAIN_FIELD(__u32, sbf_pushed, + "sbf_pushed is not used", "%11u", false, v15); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, ttwu_wake_remote, + "try_to_wake_up() awoke a task that last ran on a diff cpu", "%11u",= false, v15); +DOMAIN_FIELD(__u32, ttwu_move_affine, + "try_to_wake_up() moved task because cache-cold on own cpu", "%11u",= false, v15); +DOMAIN_FIELD(__u32, ttwu_move_balance, + "try_to_wake_up() started passive balancing", "%11u", false, v15); +#endif /* DOMAIN_FIELD */ diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 587c180035b2..06735a7c495a 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2528,6 +2528,8 @@ int cmd_inject(int argc, const char **argv) inject.tool.compressed =3D perf_event__repipe_op4_synth; inject.tool.auxtrace =3D perf_event__repipe_auxtrace; inject.tool.bpf_metadata =3D perf_event__repipe_op2_synth; + inject.tool.schedstat_cpu =3D perf_event__repipe_op2_synth; + inject.tool.schedstat_domain =3D perf_event__repipe_op2_synth; inject.tool.dont_split_sample_group =3D true; inject.tool.merge_deferred_callchains =3D false; inject.session =3D __perf_session__new(&data, &inject.tool, diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index eca3b1c58c4b..ee3b4e42156e 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -28,6 +28,8 @@ #include "util/debug.h" #include "util/event.h" #include "util/util.h" +#include "util/synthetic-events.h" +#include "util/target.h" =20 #include #include @@ -55,6 +57,7 @@ #define MAX_PRIO 140 =20 static const char *cpu_list; +static struct perf_cpu_map *user_requested_cpus; static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); =20 struct sched_atom; @@ -236,6 +239,9 @@ struct perf_sched { volatile bool thread_funcs_exit; const char *prio_str; DECLARE_BITMAP(prio_bitmap, MAX_PRIO); + + struct perf_session *session; + struct perf_data *data; }; =20 /* per thread run time data */ @@ -3734,6 +3740,195 @@ static void setup_sorting(struct perf_sched *sched,= const struct option *options sort_dimension__add("pid", &sched->cmp_pid); } =20 +static int process_synthesized_schedstat_event(const struct perf_tool *too= l, + union perf_event *event, + struct perf_sample *sample __maybe_unused, + struct machine *machine __maybe_unused) +{ + struct perf_sched *sched =3D container_of(tool, struct perf_sched, tool); + + if (perf_data__write(sched->data, event, event->header.size) <=3D 0) { + pr_err("failed to write perf data, error: %m\n"); + return -1; + } + + sched->session->header.data_size +=3D event->header.size; + return 0; +} + +static void sighandler(int sig __maybe_unused) +{ +} + +static int enable_sched_schedstats(int *reset) +{ + char path[PATH_MAX]; + FILE *fp; + char ch; + + snprintf(path, PATH_MAX, "%s/sys/kernel/sched_schedstats", procfs__mountp= oint()); + fp =3D fopen(path, "w+"); + if (!fp) { + pr_err("Failed to open %s\n", path); + return -1; + } + + ch =3D getc(fp); + if (ch =3D=3D '0') { + *reset =3D 1; + rewind(fp); + putc('1', fp); + fclose(fp); + } + return 0; +} + +static int disable_sched_schedstat(void) +{ + char path[PATH_MAX]; + FILE *fp; + + snprintf(path, PATH_MAX, "%s/sys/kernel/sched_schedstats", procfs__mountp= oint()); + fp =3D fopen(path, "w"); + if (!fp) { + pr_err("Failed to open %s\n", path); + return -1; + } + + putc('0', fp); + fclose(fp); + return 0; +} + +/* perf.data or any other output file name used by stats subcommand (only)= . */ +const char *output_name; + +static int perf_sched__schedstat_record(struct perf_sched *sched, + int argc, const char **argv) +{ + struct perf_session *session; + struct target target =3D {}; + struct evlist *evlist; + int reset =3D 0; + int err =3D 0; + int fd; + struct perf_data data =3D { + .path =3D output_name, + .mode =3D PERF_DATA_MODE_WRITE, + }; + + signal(SIGINT, sighandler); + signal(SIGCHLD, sighandler); + signal(SIGTERM, sighandler); + + evlist =3D evlist__new(); + if (!evlist) + return -ENOMEM; + + session =3D perf_session__new(&data, &sched->tool); + if (IS_ERR(session)) { + pr_err("Perf session creation failed.\n"); + evlist__delete(evlist); + return PTR_ERR(session); + } + + session->evlist =3D evlist; + + sched->session =3D session; + sched->data =3D &data; + + fd =3D perf_data__fd(&data); + + /* + * Capture all important metadata about the system. Although they are + * not used by `perf sched stats` tool directly, they provide useful + * information about profiled environment. + */ + perf_header__set_feat(&session->header, HEADER_HOSTNAME); + perf_header__set_feat(&session->header, HEADER_OSRELEASE); + perf_header__set_feat(&session->header, HEADER_VERSION); + perf_header__set_feat(&session->header, HEADER_ARCH); + perf_header__set_feat(&session->header, HEADER_NRCPUS); + perf_header__set_feat(&session->header, HEADER_CPUDESC); + perf_header__set_feat(&session->header, HEADER_CPUID); + perf_header__set_feat(&session->header, HEADER_TOTAL_MEM); + perf_header__set_feat(&session->header, HEADER_CMDLINE); + perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY); + perf_header__set_feat(&session->header, HEADER_NUMA_TOPOLOGY); + perf_header__set_feat(&session->header, HEADER_CACHE); + perf_header__set_feat(&session->header, HEADER_MEM_TOPOLOGY); + perf_header__set_feat(&session->header, HEADER_HYBRID_TOPOLOGY); + perf_header__set_feat(&session->header, HEADER_CPU_DOMAIN_INFO); + + err =3D perf_session__write_header(session, evlist, fd, false); + if (err < 0) + goto out; + + /* + * `perf sched stats` does not support workload profiling (-p pid) + * since /proc/schedstat file contains cpu specific data only. Hence, a + * profile target is either set of cpus or systemwide, never a process. + * Note that, although `-- ` is supported, profile data are + * still cpu/systemwide. + */ + if (cpu_list) + target.cpu_list =3D cpu_list; + else + target.system_wide =3D true; + + if (argc) { + err =3D evlist__prepare_workload(evlist, &target, argv, false, NULL); + if (err) + goto out; + } + + err =3D evlist__create_maps(evlist, &target); + if (err < 0) + goto out; + + user_requested_cpus =3D evlist->core.user_requested_cpus; + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_schedstat_event, + user_requested_cpus); + if (err < 0) + goto out; + + err =3D enable_sched_schedstats(&reset); + if (err < 0) + goto out; + + if (argc) + evlist__start_workload(evlist); + + /* wait for signal */ + pause(); + + if (reset) { + err =3D disable_sched_schedstat(); + if (err < 0) + goto out; + } + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_schedstat_event, + user_requested_cpus); + if (err < 0) + goto out; + + err =3D perf_session__write_header(session, evlist, fd, true); + +out: + if (!err) + fprintf(stderr, "[ perf sched stats: Wrote samples to %s ]\n", data.path= ); + else + fprintf(stderr, "[ perf sched stats: Failed !! ]\n"); + + evlist__delete(evlist); + close(fd); + return err; +} + static bool schedstat_events_exposed(void) { /* @@ -3910,6 +4105,12 @@ int cmd_sched(int argc, const char **argv) OPT_BOOLEAN('P', "pre-migrations", &sched.pre_migrations, "Show pre-migra= tion wait time"), OPT_PARENT(sched_options) }; + const struct option stats_options[] =3D { + OPT_STRING('o', "output", &output_name, "file", + "`stats record` with output filename"), + OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), + OPT_END() + }; =20 const char * const latency_usage[] =3D { "perf sched latency []", @@ -3927,9 +4128,13 @@ int cmd_sched(int argc, const char **argv) "perf sched timehist []", NULL }; + const char *stats_usage[] =3D { + "perf sched stats {record} []", + NULL + }; const char *const sched_subcommands[] =3D { "record", "latency", "map", "replay", "script", - "timehist", NULL }; + "timehist", "stats", NULL }; const char *sched_usage[] =3D { NULL, NULL @@ -4027,6 +4232,21 @@ int cmd_sched(int argc, const char **argv) ret =3D symbol__validate_sym_arguments(); if (!ret) ret =3D perf_sched__timehist(&sched); + } else if (!strcmp(argv[0], "stats")) { + const char *const stats_subcommands[] =3D {"record", NULL}; + + argc =3D parse_options_subcommand(argc, argv, stats_options, + stats_subcommands, + stats_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + + if (argv[0] && !strcmp(argv[0], "record")) { + if (argc) + argc =3D parse_options(argc, argv, stats_options, + stats_usage, 0); + return perf_sched__schedstat_record(&sched, argc, argv); + } + usage_with_options(stats_usage, stats_options); } else { usage_with_options(sched_usage, sched_options); } diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 4c92cc1a952c..edacf13455d8 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -83,6 +83,8 @@ static const char *perf_event__names[] =3D { [PERF_RECORD_FINISHED_INIT] =3D "FINISHED_INIT", [PERF_RECORD_COMPRESSED2] =3D "COMPRESSED2", [PERF_RECORD_BPF_METADATA] =3D "BPF_METADATA", + [PERF_RECORD_SCHEDSTAT_CPU] =3D "SCHEDSTAT_CPU", + [PERF_RECORD_SCHEDSTAT_DOMAIN] =3D "SCHEDSTAT_DOMAIN", }; =20 const char *perf_event__name(unsigned int id) @@ -571,6 +573,44 @@ size_t perf_event__fprintf_text_poke(union perf_event = *event, struct machine *ma return ret; } =20 +size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp) +{ + struct perf_record_schedstat_cpu *cs =3D &event->schedstat_cpu; + size_t size =3D fprintf(fp, "\ncpu%u ", cs->cpu); + __u16 version =3D cs->version; + +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ + size +=3D fprintf(fp, "%" PRIu64 " ", (unsigned long)cs->_ver._name) + + if (version =3D=3D 15) { +#include + return size; + } +#undef CPU_FIELD + + return fprintf(fp, "Unsupported /proc/schedstat version %d.\n", + event->schedstat_cpu.version); +} + +size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE = *fp) +{ + struct perf_record_schedstat_domain *ds =3D &event->schedstat_domain; + __u16 version =3D ds->version; + size_t size =3D fprintf(fp, "\ndomain%u ", ds->domain); + +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ + size +=3D fprintf(fp, "%" PRIu64 " ", (unsigned long)ds->_ver._name) + + if (version =3D=3D 15) { +#include + return size; + } +#undef DOMAIN_FIELD + + return fprintf(fp, "Unsupported /proc/schedstat version %d.\n", + event->schedstat_domain.version); +} + size_t perf_event__fprintf(union perf_event *event, struct machine *machin= e, FILE *fp) { size_t ret =3D fprintf(fp, "PERF_RECORD_%s", diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 64c63b59d617..2ea83fdf8a03 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -392,6 +392,8 @@ size_t perf_event__fprintf_ksymbol(union perf_event *ev= ent, FILE *fp); size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp); size_t perf_event__fprintf_bpf_metadata(union perf_event *event, FILE *fp); size_t perf_event__fprintf_text_poke(union perf_event *event, struct machi= ne *machine,FILE *fp); +size_t perf_event__fprintf_schedstat_cpu(union perf_event *event, FILE *fp= ); +size_t perf_event__fprintf_schedstat_domain(union perf_event *event, FILE = *fp); size_t perf_event__fprintf(union perf_event *event, struct machine *machin= e, FILE *fp); =20 int kallsyms__get_function_start(const char *kallsyms_filename, diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 922ef6577bbb..475fe20d6c25 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -697,6 +697,20 @@ static void perf_event__time_conv_swap(union perf_even= t *event, } } =20 +static void +perf_event__schedstat_cpu_swap(union perf_event *event __maybe_unused, + bool sample_id_all __maybe_unused) +{ + /* FIXME */ +} + +static void +perf_event__schedstat_domain_swap(union perf_event *event __maybe_unused, + bool sample_id_all __maybe_unused) +{ + /* FIXME */ +} + typedef void (*perf_event__swap_op)(union perf_event *event, bool sample_id_all); =20 @@ -736,6 +750,8 @@ static perf_event__swap_op perf_event__swap_ops[] =3D { [PERF_RECORD_STAT_ROUND] =3D perf_event__stat_round_swap, [PERF_RECORD_EVENT_UPDATE] =3D perf_event__event_update_swap, [PERF_RECORD_TIME_CONV] =3D perf_event__time_conv_swap, + [PERF_RECORD_SCHEDSTAT_CPU] =3D perf_event__schedstat_cpu_swap, + [PERF_RECORD_SCHEDSTAT_DOMAIN] =3D perf_event__schedstat_domain_swap, [PERF_RECORD_HEADER_MAX] =3D NULL, }; =20 @@ -1659,6 +1675,12 @@ static s64 perf_session__process_user_event(struct p= erf_session *session, case PERF_RECORD_BPF_METADATA: err =3D tool->bpf_metadata(tool, session, event); break; + case PERF_RECORD_SCHEDSTAT_CPU: + err =3D tool->schedstat_cpu(tool, session, event); + break; + case PERF_RECORD_SCHEDSTAT_DOMAIN: + err =3D tool->schedstat_domain(tool, session, event); + break; default: err =3D -EINVAL; break; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 2ba9fa25e00a..5366ea921e70 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2529,3 +2529,182 @@ int parse_synth_opt(char *synth) =20 return ret; } + +static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 v= ersion, + __u64 *cpu, __u64 timestamp) +{ + struct perf_record_schedstat_cpu *cs; + union perf_event *event; + size_t size; + char ch; + + size =3D sizeof(*cs); + size =3D PERF_ALIGN(size, sizeof(u64)); + event =3D zalloc(size); + + if (!event) + return NULL; + + cs =3D &event->schedstat_cpu; + cs->header.type =3D PERF_RECORD_SCHEDSTAT_CPU; + cs->header.size =3D size; + cs->timestamp =3D timestamp; + + if (io__get_char(io) !=3D 'p' || io__get_char(io) !=3D 'u') + goto out_cpu; + + if (io__get_dec(io, (__u64 *)cpu) !=3D ' ') + goto out_cpu; + +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ + do { \ + __u64 _tmp; \ + ch =3D io__get_dec(io, &_tmp); \ + if (ch !=3D ' ' && ch !=3D '\n') \ + goto out_cpu; \ + cs->_ver._name =3D _tmp; \ + } while (0) + + if (version =3D=3D 15) { +#include + } +#undef CPU_FIELD + + cs->cpu =3D *cpu; + cs->version =3D version; + + return event; +out_cpu: + free(event); + return NULL; +} + +static union perf_event *__synthesize_schedstat_domain(struct io *io, __u1= 6 version, + __u64 cpu, __u64 timestamp) +{ + struct perf_record_schedstat_domain *ds; + union perf_event *event =3D NULL; + __u64 d_num; + size_t size; + char ch; + + if (io__get_char(io) !=3D 'o' || io__get_char(io) !=3D 'm' || io__get_cha= r(io) !=3D 'a' || + io__get_char(io) !=3D 'i' || io__get_char(io) !=3D 'n') + return NULL; + + ch =3D io__get_dec(io, &d_num); + + /* Skip cpumask as it can be extracted from perf header */ + while (io__get_char(io) !=3D ' ') + continue; + + size =3D sizeof(*ds); + size =3D PERF_ALIGN(size, sizeof(u64)); + event =3D zalloc(size); + + ds =3D &event->schedstat_domain; + ds->header.type =3D PERF_RECORD_SCHEDSTAT_DOMAIN; + ds->header.size =3D size; + ds->version =3D version; + ds->timestamp =3D timestamp; + ds->domain =3D d_num; + +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ + do { \ + __u64 _tmp; \ + ch =3D io__get_dec(io, &_tmp); \ + if (ch !=3D ' ' && ch !=3D '\n') \ + goto out_domain; \ + ds->_ver._name =3D _tmp; \ + } while (0) + + if (version =3D=3D 15) { +#include + } +#undef DOMAIN_FIELD + + ds->cpu =3D cpu; + goto out; + +out_domain: + free(event); + event =3D NULL; +out: + return event; +} + +int perf_event__synthesize_schedstat(const struct perf_tool *tool, + perf_event__handler_t process, + struct perf_cpu_map *user_requested_cpus) +{ + char *line =3D NULL, path[PATH_MAX]; + union perf_event *event =3D NULL; + size_t line_len =3D 0; + char bf[BUFSIZ]; + __u64 timestamp; + __u64 cpu =3D -1; + __u16 version; + struct io io; + int ret =3D -1; + char ch; + + snprintf(path, PATH_MAX, "%s/schedstat", procfs__mountpoint()); + io.fd =3D open(path, O_RDONLY, 0); + if (io.fd < 0) { + pr_err("Failed to open %s. Possibly CONFIG_SCHEDSTAT is disabled.\n", pa= th); + return -1; + } + io__init(&io, io.fd, bf, sizeof(bf)); + + if (io__getline(&io, &line, &line_len) < 0 || !line_len) + goto out; + + if (!strcmp(line, "version 15\n")) { + version =3D 15; + } else { + pr_err("Unsupported %s version: %s", path, line + 8); + goto out_free_line; + } + + if (io__getline(&io, &line, &line_len) < 0 || !line_len) + goto out_free_line; + timestamp =3D atol(line + 10); + + /* + * FIXME: Can be optimized a bit by not synthesizing domain samples + * for filtered out cpus. + */ + for (ch =3D io__get_char(&io); !io.eof; ch =3D io__get_char(&io)) { + struct perf_cpu this_cpu; + + if (ch =3D=3D 'c') { + event =3D __synthesize_schedstat_cpu(&io, version, + &cpu, timestamp); + } else if (ch =3D=3D 'd') { + event =3D __synthesize_schedstat_domain(&io, version, + cpu, timestamp); + } + if (!event) + goto out_free_line; + + this_cpu.cpu =3D cpu; + + if (user_requested_cpus && !perf_cpu_map__has(user_requested_cpus, this_= cpu)) + continue; + + if (process(tool, event, NULL, NULL) < 0) { + free(event); + goto out_free_line; + } + + free(event); + } + + ret =3D 0; + +out_free_line: + free(line); +out: + close(io.fd); + return ret; +} diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic= -events.h index f8588b6cf11a..b0edad0c3100 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -128,4 +128,7 @@ int perf_event__synthesize_for_pipe(const struct perf_t= ool *tool, struct perf_data *data, perf_event__handler_t process); =20 +int perf_event__synthesize_schedstat(const struct perf_tool *tool, + perf_event__handler_t process, + struct perf_cpu_map *user_requested_cpu); #endif // __PERF_SYNTHETIC_EVENTS_H diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index 27ba5849c74a..013c7839e2cf 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -253,7 +253,25 @@ static int perf_event__process_bpf_metadata_stub(const= struct perf_tool *tool __ { if (dump_trace) perf_event__fprintf_bpf_metadata(event, stdout); + dump_printf(": unhandled!\n"); + return 0; +} +static int process_schedstat_cpu_stub(const struct perf_tool *tool __maybe= _unused, + struct perf_session *perf_session __maybe_unused, + union perf_event *event) +{ + if (dump_trace) + perf_event__fprintf_schedstat_cpu(event, stdout); + dump_printf(": unhandled!\n"); + return 0; +} =20 +static int process_schedstat_domain_stub(const struct perf_tool *tool __ma= ybe_unused, + struct perf_session *perf_session __maybe_unused, + union perf_event *event) +{ + if (dump_trace) + perf_event__fprintf_schedstat_domain(event, stdout); dump_printf(": unhandled!\n"); return 0; } @@ -317,6 +335,8 @@ void perf_tool__init(struct perf_tool *tool, bool order= ed_events) #endif tool->finished_init =3D process_event_op2_stub; tool->bpf_metadata =3D perf_event__process_bpf_metadata_stub; + tool->schedstat_cpu =3D process_schedstat_cpu_stub; + tool->schedstat_domain =3D process_schedstat_domain_stub; } =20 bool perf_tool__compressed_is_stub(const struct perf_tool *tool) diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index e96b69d25a5b..2d9a4b1ca9d0 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -81,7 +81,9 @@ struct perf_tool { stat_round, feature, finished_init, - bpf_metadata; + bpf_metadata, + schedstat_cpu, + schedstat_domain; event_op4 compressed; event_op3 auxtrace; bool ordered_events; --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013025.outbound.protection.outlook.com [40.93.201.25]) (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 01C1A2C21DD; Mon, 19 Jan 2026 18:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.25 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845659; cv=fail; b=UBOtv7AIdAOxyat0k70Zzw4+AjBQ0uDEPJM0dk2koQUpcsnOA0Rse6ibsWuOhnoc5hMk+q5BsSn3nKdAoiOPOqOHTWNVwSlAzHQD+Ay46MZXcwg26T9Rkv2PvymjayZGewMYsBjU5pb3+MYAxJPVv6Zlaq0eBBUYnNiVDYLYddY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845659; c=relaxed/simple; bh=nbRL3KO7D3zwjA2WEr8ernjYwi9uFhYgup1bHMhOa0U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X+qv9fKIh+lKWJLZGyAtoVTEhPbX1hCkkk+EQvo0qMDpycvaSOQxlwpUOR7k4fvUIKJh2Lvmd+QhS0hKfGYW8I4RXk3x+QB/5hyZEnWiyHvwZop73eVlmMRLnJV6nycxj39MpNf1wdOvmN569QqYWJ3YjYRwsRDCmxxWIijYrsQ= 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=0jWR++kX; arc=fail smtp.client-ip=40.93.201.25 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="0jWR++kX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=So0K1irIOSZLYG61n/slnfhwyU5zAurzbO1V3BaBHlrwG6hXFyG44zXv/gzLRHX4FQ991IGUlM3+pQFmivKAI6VteapYHo6bp4CbbCTNGp8NrOT4eiSAnpIzegHAN77XTjVIxldy0MwZNLFARUeoAvBabUzQ2k9OHpqKyqXW69HFWKz3iQIDpGGCb01j/vsZczq8gJn9gVn/eXVgU7XanBjoG4mPgTu+yyMnLLAOKBRRm0KN6DlsyZpHbacpQ6sguGBbJWfnlGUePc0eT7exIhEBmgA3GPN+ZLCWhqyAE+prGO6CklIdR/PaoVRrnR2ERDhQa7I4zI57Vk8YWMMVwQ== 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=mnvcyynvvtJtY1bnqeKR4NqgZHqKh4tIjFiClq17IQo=; b=Q1XCiV9qkCbHGWtHeJlPcbMVJ6XKBQqDATz3VnssJ2M/qscx4UVZVvXL+CTJOaSNh9lCJQ2VG6Vo/tOV3vFuxB8nJsJL8+qDDZovdKlF2LwIKigBHsPs82hfbS+Lux2Y9SMU4r3dM/wc9a3geqeUAdlwcGuXZcllIINuech5LM1N6tPVT4G5g7UlGAawLUwaSO/n0thp0Z+xbsukJ6g2IujGGP85X1V2njXiqoV7PjX2hN+F4bWSOlcsXEvcpPklfjHYOxBn0bwfhNGOKNfEGR1jO1a5l0QtbSOTcbWJyVipOHQbAr0IGKzN3F8UrBn4+WVjacFmfNjxLqvWx5JMhA== 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=mnvcyynvvtJtY1bnqeKR4NqgZHqKh4tIjFiClq17IQo=; b=0jWR++kXKLMv6FNU4nCZli4zUDeeJpM1PytsclvMfLCA9J6TC1PXsm71aVegMF+0BqEqczJSn8ptXwY3C3I02NJUAGiVFkAPFnxBZNWCFiQzpjFUfxavGkA8Ib9q92UbhGgtr0/bw1LVAajnvmSDSt+ppk1IMdh01uKDTxbvz74= Received: from MN0PR04CA0030.namprd04.prod.outlook.com (2603:10b6:208:52d::29) by SN7PR12MB7882.namprd12.prod.outlook.com (2603:10b6:806:348::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 18:00:43 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2603:10b6:208:52d:cafe::e) by MN0PR04CA0030.outlook.office365.com (2603:10b6:208:52d::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.12 via Frontend Transport; Mon, 19 Jan 2026 18:00:43 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:00:43 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:00:32 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "James Clark" Subject: [PATCH v5 04/10] perf sched stats: Add schedstat v16 support Date: Mon, 19 Jan 2026 17:58:26 +0000 Message-ID: <20260119175833.340369-5-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4E:EE_|SN7PR12MB7882:EE_ X-MS-Office365-Filtering-Correlation-Id: 861aa4ae-8300-46d2-083b-08de5784aa11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?fxZEdE99RgimxBzf/lJ9ObmbR3SPKqWDWcgAejXxJIRQHoSiiC4iDEwnW2kO?= =?us-ascii?Q?kXfYA2wAmYMp3WhC7XVYIWzkE0RwA2PJ+9kfcq4/HHhhKs1z7v2Vq3mz7fpq?= =?us-ascii?Q?BfQDHQmlNyBYUmxk7tmOOrRiZ5DqvF32cmp1cmiMAt4oonBYSHXsZTPF0Y7q?= =?us-ascii?Q?3GCeB0NDmAejANWKKn+sSr5tg0u5rUzQpgXGafIU7THlftgXTN9p1m7jxZN4?= =?us-ascii?Q?v0vLKBtzdKGGFjTDIH2Z56dkTg2OjR98rUM7IRovm5zAzOamgMNfXE22LH+f?= =?us-ascii?Q?XvufSooQMR06DFBmttAeUl8mbtcpz/12mEtPOQ3P0sK8eJSgvEYyr5m3h5zJ?= =?us-ascii?Q?Wdziej443W+u9XFLUAzeQH0PVTkOHOxVTm2dFRr4y+ft20BQYozxBU+5WtRx?= =?us-ascii?Q?CpDbdti7/UdP4B6l26ub914ZbeU+FmdRvrK6NgBj3ykrNfRcESuFUIlNcruZ?= =?us-ascii?Q?oYmGuIzu7oNmMry30w/Jrb9qqjjW+BXTmSRUueCoAVbiNzut4MSmPWBew/PG?= =?us-ascii?Q?67MvYDbyeKndxZs+sbIZN79fxsrr/XEdQEb/jYhOBQZ1ip4//JKcdxvW5TiF?= =?us-ascii?Q?IDke5PwMtLrQws2IQYy4XMcJvx8oS1WOl8uzzSijXiGu3COF+r1lJP/hsTCh?= =?us-ascii?Q?8yHDg4MdGdnqkyLO0PPNm/mApMOfhO16PXzIZNFcYHRio3x0H46T4xEPL/Qp?= =?us-ascii?Q?Ice2aPXs1ANz8A7Uxq6NTQjpoG8fEh34uw5FMAmv0soHBlGaK0U4514VqAQs?= =?us-ascii?Q?RigI2BhUnfQgXVcNoHXIHSYIswDgqnbYtWBD4FuYq1eZbmbOwPz3MScxCqqd?= =?us-ascii?Q?88WnNby4h1d8mS80+FLNd6RisSxAPIcT+f5wdSrn/xYmgn0gm+fdw1ZIYWCO?= =?us-ascii?Q?TWw/S2vlZYoVd0Fkt4Z0+pn98m9PgQ9kBa5xMTcdr/AYNQdE5v68jBRMh4RG?= =?us-ascii?Q?D0RBm4r3k6HKCZDab7D2JToT00OvMFC46f6gQBEzMwZ+9V1fVhKOL1/SY7Wg?= =?us-ascii?Q?kB3MKLHh4Og2Gp5wzVCl14FKr1xRhKkgdJembxody7JnEKHqSUDb7rUh6fFt?= =?us-ascii?Q?C98wcYmhBl4dpqwz+VXFFQQDG+UUdHSpa1MiDl0Nrd838Oh6LosCZOPo7bv8?= =?us-ascii?Q?UJdubPG6ZOdlKDF4L5/ly2JH75F5XiDqvP6wJ5+HS5y25NmVpfrCL2CbxWSL?= =?us-ascii?Q?4+mG7dUWsaOGfY26tkLYYV5NUH/gh3vN+zjGyivrGyB9jILVLUyWlGCnRgBB?= =?us-ascii?Q?G0nB1YuKv/OuWwx0I24pYkAtIsTAni00QDz6mif6l/8fh5SRu4mwbrBuYr2X?= =?us-ascii?Q?K0Vir67uHMNcEQM8FZZFINFVKtMLeECEZ8BGo4JJ8jZFW8KTdZar4mCFoTzD?= =?us-ascii?Q?KlFKcXu1h49Cs8UWoOBxK0+aNcTUzX0NQJJNz4O2oUjSmg7O5xTv/lQ0okj0?= =?us-ascii?Q?2KnBn7RzW72MqYiMHkDZYHDNljkfKJ+hPCmMwZqIqPsVnCq9oINx1LRxeBpn?= =?us-ascii?Q?wOF1BppTDKY7B3V88S89ZSLfsNX/ki0yhmTnrpi/gg95IDoz0cPu3XQkgzrp?= =?us-ascii?Q?KUw3Trc8JvguPWBUruZfRCnppGW5b3xzONQbvVwcmQg3N0ReaBRe3gzbOk/1?= =?us-ascii?Q?qAz1jmv8JDtrVXWwoyAEHROAUzapCWMGcqyll0yNnzN1F14wbTEzT8LzOQhZ?= =?us-ascii?Q?FmeGxQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:00:43.3294 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 861aa4ae-8300-46d2-083b-08de5784aa11 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7882 Content-Type: text/plain; charset="utf-8" /proc/schedstat file output is standardized with version number. Add support to record and raw dump v16 version layout. Version 16 of schedstats changed the order of definitions within 'enum cpu_idle_type', which changed the order of [CPU_MAX_IDLE_TYPES] columns in show_schedstat(). In particular the position of CPU_IDLE and __CPU_NOT_IDLE changed places. Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/lib/perf/Makefile | 2 +- tools/lib/perf/include/perf/event.h | 14 ++ tools/lib/perf/include/perf/schedstat-v16.h | 146 ++++++++++++++++++++ tools/perf/util/event.c | 6 + tools/perf/util/synthetic-events.c | 6 + 5 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tools/lib/perf/include/perf/schedstat-v16.h diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile index 9fa28e512ca8..965e066fd780 100644 --- a/tools/lib/perf/Makefile +++ b/tools/lib/perf/Makefile @@ -179,7 +179,7 @@ install_lib: libs cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) =20 HDRS :=3D bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h = mmap.h -HDRS +=3D schedstat-v15.h +HDRS +=3D schedstat-v15.h schedstat-v16.h INTERNAL_HDRS :=3D cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threa= dmap.h xyarray.h =20 INSTALL_HDRS_PFX :=3D $(DESTDIR)$(prefix)/include/perf diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/p= erf/event.h index ce04fed7cefc..bd4d507ea8ab 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -502,6 +502,12 @@ struct perf_record_schedstat_cpu_v15 { #undef CPU_FIELD }; =20 +struct perf_record_schedstat_cpu_v16 { +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) _= type _name +#include "schedstat-v16.h" +#undef CPU_FIELD +}; + struct perf_record_schedstat_cpu { struct perf_event_header header; __u64 timestamp; @@ -511,6 +517,7 @@ struct perf_record_schedstat_cpu { char __pad[2]; union { struct perf_record_schedstat_cpu_v15 v15; + struct perf_record_schedstat_cpu_v16 v16; }; }; =20 @@ -520,6 +527,12 @@ struct perf_record_schedstat_domain_v15 { #undef DOMAIN_FIELD }; =20 +struct perf_record_schedstat_domain_v16 { +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) _ty= pe _name +#include "schedstat-v16.h" +#undef DOMAIN_FIELD +}; + #define DOMAIN_NAME_LEN 16 =20 struct perf_record_schedstat_domain { @@ -530,6 +543,7 @@ struct perf_record_schedstat_domain { __u16 domain; union { struct perf_record_schedstat_domain_v15 v15; + struct perf_record_schedstat_domain_v16 v16; }; }; =20 diff --git a/tools/lib/perf/include/perf/schedstat-v16.h b/tools/lib/perf/i= nclude/perf/schedstat-v16.h new file mode 100644 index 000000000000..3462b79c29af --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-v16.h @@ -0,0 +1,146 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CPU_FIELD +CPU_FIELD(__u32, yld_count, "sched_yield() count", + "%11u", false, yld_count, v16); +CPU_FIELD(__u32, array_exp, "Legacy counter can be ignored", + "%11u", false, array_exp, v16); +CPU_FIELD(__u32, sched_count, "schedule() called", + "%11u", false, sched_count, v16); +CPU_FIELD(__u32, sched_goidle, "schedule() left the processor idle", + "%11u", true, sched_count, v16); +CPU_FIELD(__u32, ttwu_count, "try_to_wake_up() was called", + "%11u", false, ttwu_count, v16); +CPU_FIELD(__u32, ttwu_local, "try_to_wake_up() was called to wake up the l= ocal cpu", + "%11u", true, ttwu_count, v16); +CPU_FIELD(__u64, rq_cpu_time, "total runtime by tasks on this processor (i= n jiffies)", + "%11llu", false, rq_cpu_time, v16); +CPU_FIELD(__u64, run_delay, "total waittime by tasks on this processor (in= jiffies)", + "%11llu", true, rq_cpu_time, v16); +CPU_FIELD(__u64, pcount, "total timeslices run on this cpu", + "%11llu", false, pcount, v16); +#endif /* CPU_FIELD */ + +#ifdef DOMAIN_FIELD +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, busy_lb_count, + "load_balance() count on cpu busy", "%11u", true, v16); +DOMAIN_FIELD(__u32, busy_lb_balanced, + "load_balance() found balanced on cpu busy", "%11u", true, v16); +DOMAIN_FIELD(__u32, busy_lb_failed, + "load_balance() move task failed on cpu busy", "%11u", true, v16); +DOMAIN_FIELD(__u32, busy_lb_imbalance, + "imbalance sum on cpu busy", "%11u", false, v16); +DOMAIN_FIELD(__u32, busy_lb_gained, + "pull_task() count on cpu busy", "%11u", false, v16); +DOMAIN_FIELD(__u32, busy_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu busy", "%11u", fa= lse, v16); +DOMAIN_FIELD(__u32, busy_lb_nobusyq, + "load_balance() failed to find busier queue on cpu busy", "%11u", tr= ue, v16); +DOMAIN_FIELD(__u32, busy_lb_nobusyg, + "load_balance() failed to find busier group on cpu busy", "%11u", tr= ue, v16); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(busy_lb_success_count, "load_balance() success count on = cpu busy", "%11u", + busy_lb_count, busy_lb_balanced, busy_lb_failed, v16); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(busy_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu busy)", "%11.2Lf", + busy_lb_count, busy_lb_balanced, busy_lb_failed, busy_lb_gained, v16); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, idle_lb_count, + "load_balance() count on cpu idle", "%11u", true, v16); +DOMAIN_FIELD(__u32, idle_lb_balanced, + "load_balance() found balanced on cpu idle", "%11u", true, v16); +DOMAIN_FIELD(__u32, idle_lb_failed, + "load_balance() move task failed on cpu idle", "%11u", true, v16); +DOMAIN_FIELD(__u32, idle_lb_imbalance, + "imbalance sum on cpu idle", "%11u", false, v16); +DOMAIN_FIELD(__u32, idle_lb_gained, + "pull_task() count on cpu idle", "%11u", false, v16); +DOMAIN_FIELD(__u32, idle_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu idle", "%11u", fa= lse, v16); +DOMAIN_FIELD(__u32, idle_lb_nobusyq, + "load_balance() failed to find busier queue on cpu idle", "%11u", tr= ue, v16); +DOMAIN_FIELD(__u32, idle_lb_nobusyg, + "load_balance() failed to find busier group on cpu idle", "%11u", tr= ue, v16); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(idle_lb_success_count, "load_balance() success count on = cpu idle", "%11u", + idle_lb_count, idle_lb_balanced, idle_lb_failed, v16); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(idle_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu idle)", "%11.2Lf", + idle_lb_count, idle_lb_balanced, idle_lb_failed, idle_lb_gained, v16); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, newidle_lb_count, + "load_balance() count on cpu newly idle", "%11u", true, v16); +DOMAIN_FIELD(__u32, newidle_lb_balanced, + "load_balance() found balanced on cpu newly idle", "%11u", true, v16= ); +DOMAIN_FIELD(__u32, newidle_lb_failed, + "load_balance() move task failed on cpu newly idle", "%11u", true, v= 16); +DOMAIN_FIELD(__u32, newidle_lb_imbalance, + "imbalance sum on cpu newly idle", "%11u", false, v16); +DOMAIN_FIELD(__u32, newidle_lb_gained, + "pull_task() count on cpu newly idle", "%11u", false, v16); +DOMAIN_FIELD(__u32, newidle_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu newly idle", "%11= u", false, v16); +DOMAIN_FIELD(__u32, newidle_lb_nobusyq, + "load_balance() failed to find busier queue on cpu newly idle", "%11= u", true, v16); +DOMAIN_FIELD(__u32, newidle_lb_nobusyg, + "load_balance() failed to find busier group on cpu newly idle", "%11= u", true, v16); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(newidle_lb_success_count, + "load_balance() success count on cpu newly idle", "%11u", + newidle_lb_count, newidle_lb_balanced, newidle_lb_failed, v16); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(newidle_lb_avg_count, + "avg task pulled per successful lb attempt (cpu newly idle)", "%11.2Lf= ", + newidle_lb_count, newidle_lb_balanced, newidle_lb_failed, newidle_lb_g= ained, v16); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, alb_count, + "active_load_balance() count", "%11u", false, v16); +DOMAIN_FIELD(__u32, alb_failed, + "active_load_balance() move task failed", "%11u", false, v16); +DOMAIN_FIELD(__u32, alb_pushed, + "active_load_balance() successfully moved a task", "%11u", false, v1= 6); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, sbe_count, + "sbe_count is not used", "%11u", false, v16); +DOMAIN_FIELD(__u32, sbe_balanced, + "sbe_balanced is not used", "%11u", false, v16); +DOMAIN_FIELD(__u32, sbe_pushed, + "sbe_pushed is not used", "%11u", false, v16); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, sbf_count, + "sbf_count is not used", "%11u", false, v16); +DOMAIN_FIELD(__u32, sbf_balanced, + "sbf_balanced is not used", "%11u", false, v16); +DOMAIN_FIELD(__u32, sbf_pushed, + "sbf_pushed is not used", "%11u", false, v16); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, ttwu_wake_remote, + "try_to_wake_up() awoke a task that last ran on a diff cpu", "%11u",= false, v16); +DOMAIN_FIELD(__u32, ttwu_move_affine, + "try_to_wake_up() moved task because cache-cold on own cpu", "%11u",= false, v16); +DOMAIN_FIELD(__u32, ttwu_move_balance, + "try_to_wake_up() started passive balancing", "%11u", false, v16); +#endif /* DOMAIN_FIELD */ diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index edacf13455d8..9a434e2e480f 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -585,6 +585,9 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_eve= nt *event, FILE *fp) if (version =3D=3D 15) { #include return size; + } else if (version =3D=3D 16) { +#include + return size; } #undef CPU_FIELD =20 @@ -604,6 +607,9 @@ size_t perf_event__fprintf_schedstat_domain(union perf_= event *event, FILE *fp) if (version =3D=3D 15) { #include return size; + } else if (version =3D=3D 16) { +#include + return size; } #undef DOMAIN_FIELD =20 diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 5366ea921e70..4ce37357db05 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2567,6 +2567,8 @@ static union perf_event *__synthesize_schedstat_cpu(s= truct io *io, __u16 version =20 if (version =3D=3D 15) { #include + } else if (version =3D=3D 16) { +#include } #undef CPU_FIELD =20 @@ -2620,6 +2622,8 @@ static union perf_event *__synthesize_schedstat_domai= n(struct io *io, __u16 vers =20 if (version =3D=3D 15) { #include + } else if (version =3D=3D 16) { +#include } #undef DOMAIN_FIELD =20 @@ -2661,6 +2665,8 @@ int perf_event__synthesize_schedstat(const struct per= f_tool *tool, =20 if (!strcmp(line, "version 15\n")) { version =3D 15; + } else if (!strcmp(line, "version 16\n")) { + version =3D 16; } else { pr_err("Unsupported %s version: %s", path, line + 8); goto out_free_line; --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012042.outbound.protection.outlook.com [52.101.53.42]) (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 D6AA032D0DC; Mon, 19 Jan 2026 18:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845688; cv=fail; b=m0fT57R2gFe7Nry375ikH2P5dVqO3QJ6HRkZ62S1qz8buTu6sZ5sma01qbOLb+wfg38gl+HkHxdD3bXWwJniobs/R4kU9jUTC0FtU4JMVfQK3miOdUstRNeLQmcDr11Y5hxQVJ/i27+JqeIimKTWGSGUUDIHoB01COSC9aMQv9o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845688; c=relaxed/simple; bh=rDhE3Ux5cZVTParHEZl2QoOADBykEQQhBFVUZRdU47k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Qv/hZqUUX4CU9+gtX+3L+S1f4AVhxpFkLJkKNjastJsH2+NDH0jKfKX6BEVzCfhSiTz51wKwao/S4LPEtO5q8qGTwPFvdLYGIt+EuhNi6jE3yd+CH1NCr8562xQFMwf2zKavA4dJg5mI3zXjIUNt6ZaUopGxxAE7hYaffC5N5L0= 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=1SU/vKEk; arc=fail smtp.client-ip=52.101.53.42 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="1SU/vKEk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cGME+0kkwoU3gpvWX1s7Y/Ww5XymNYo+vcWrrL48K92Ko4EHJJqYTHrbN+WCSR2v/He8n/eUqS2eq1hTe5aPmxWSzr+BVQVgID6ECPT3TDdB+8NeBmDID3IiImf8yopc4usi77yvL2Z3PgjN8gHgEiae8aeN5Ldn8iACa/u/sSS4OaQh+1jU+Xcr0fWl87AHPaWsjYQ6KqzY3U2HgYXlI22D8Kj7jAG6h1O+xQ9PgXO1JM5g0M0YViTwlH0g1UW+iadZ6KQr5F5qYWTMHJWjWxt3++vVMRudhA/Sef24gXEPPDjAa/HghOkS5g+soj3XCu9bSXgtSkOxHDO5bc9q2Q== 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=2uN8SeQa1Mv7hN4ATDO82Lzp2YWUTdJf1WKf8+sXDSw=; b=Y/hNE+qx0KhSJhRmGytBAlXz1n6lNtFfGHYACZOPjCWF5EgBgW9QYSBvb0MOab2Ia2rATHz/IM8zxz6ltG0OXrO6WLYIEqRzkJiClonxDF8alMW7oS2HMLuDKDd11EbDU9cA6r0S2QvVCQHELdcEvUiXXFrQ8ZX87ssa0p1S719I8bCkiy5u5vM28qN4Hdj3HNSYEQIySK22bpjQ0Zain3PmtfVL1aDpDA+n5e/w+Dg3RMJb+8kwBDtEUa1wwnqByDQmSDR0CsXF+7wOBz57Osp6eUQf56Fjz92CPz0YT8ZZj65JDH6LRrxlyQmsj9LgqQDzyRVm0gc4ZaQi8F9E+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=2uN8SeQa1Mv7hN4ATDO82Lzp2YWUTdJf1WKf8+sXDSw=; b=1SU/vKEkHDGFNPdQdA/CgxuQ8XIcMAHsXS/VKk/1QYMUdnsx+8iJKASS9DWXp2S6T5oVXWZdBUSUE8U322+afkd4RDz6zi9FoQ89YDf/kxF9PFoCEY+tePu1tOW3Ou4bSDVRn4XqB8vLeemrqSOckNy/L9PmHH0dmApsOXe6FYg= Received: from IA4P221CA0006.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:559::9) by IA1PR12MB6627.namprd12.prod.outlook.com (2603:10b6:208:3a1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9478.4; Mon, 19 Jan 2026 18:01:08 +0000 Received: from BL6PEPF0001AB50.namprd04.prod.outlook.com (2603:10b6:208:559:cafe::9) by IA4P221CA0006.outlook.office365.com (2603:10b6:208:559::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.12 via Frontend Transport; Mon, 19 Jan 2026 18:01:30 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB50.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:01:08 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:00:56 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 05/10] perf sched stats: Add schedstat v17 support Date: Mon, 19 Jan 2026 17:58:27 +0000 Message-ID: <20260119175833.340369-6-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB50:EE_|IA1PR12MB6627:EE_ X-MS-Office365-Filtering-Correlation-Id: ecb4be16-08a2-4dce-d078-08de5784b90b 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?0wVIkKJNSKpD8XWbh6ykjPB6z6oOofNXXU8JhIx1IpB0UiBGS+pA5f96YYS3?= =?us-ascii?Q?XQsO4SL2w32x9tH0WvUJDjUhbth90RAHFpuzbWvTLjPvPgnA8iQz8y4YULSc?= =?us-ascii?Q?ugaBnD+G6/9hw8qkCTNN55V8I9J8t5VmL/jENhWvg2qBSjg1ScePSNade3WI?= =?us-ascii?Q?wsndkH+KF2yfASvqNf38pScC9OcAdJNdlpLtvHJJbPkcFphkL946fFy6Jt/M?= =?us-ascii?Q?/xY/CnYPJCuYC2yC0qPe86uFg7RXpB016FLf3Xl8vEOCku1sWFhfmFjmhTOL?= =?us-ascii?Q?tHLKvh0gRkLcRcw9CEH1yICApNi7CKic7ljtPAqqGjEoSTwdlzF/hukSUf8w?= =?us-ascii?Q?Szgns6LCZRwVxYHwFCZJ20sBlduOp8DgxPrwzD/wqtpdhQYkwc6WQrwrVWja?= =?us-ascii?Q?ZFqccReN1KWTyl9VTnyjECseN1mBFMXhS9cmSAmL2gla0Sramd68rKronw5n?= =?us-ascii?Q?CvY+cLFzblKkqBcsNqtkPGw6xN3p+BfZdncDo94i1gEwHBE+NpDj6++ixtRF?= =?us-ascii?Q?/W4ZxjeRVqFHI8HXMY7PULoWkIS9mVMtXPyuWF4O5rlPjnx3Yomo7IeZsxHH?= =?us-ascii?Q?CTVk7jIbpGqQLqDRqog3D/qKuCI/GpUP15YFqrgTSUtNZTqH7+myCw+6Gvob?= =?us-ascii?Q?Y6IVubPcJ0zpVRqwVg3THvHYf3fKTinGmT3ObHctL/4rbIm6tq8nxN2mdPMH?= =?us-ascii?Q?xoEE/DIYUAC48u9gaDpLcSsMYGRLw6FDCLSugpIDuOUptKo91Xl4nJS+jzKr?= =?us-ascii?Q?SAHCR+HU6msRt8tyyDJOckM7k9LNE6751+uglJ49GXz6C8dz4zaqr2e8bLdy?= =?us-ascii?Q?lOJzf2cw4EIcsBYbr3pFd3+cQL0LKXNwB7Nea/eZIrhanq/QuPYIwRutAXlj?= =?us-ascii?Q?SJUDguTTEqLlPgSm0ibh/fJahWomAhSZvDscMXtzUQfW8xEMUMzmcDji64pD?= =?us-ascii?Q?Tzc/BLgAa1Q2NQJAF5LQZvYRb+4oRqtPtl8RIDzQTlR2kuzyOUKV2lgSlmGs?= =?us-ascii?Q?apSndTu7j4emaz3F+KUISv15c5NcAS8Wlhu+3OmGalTNL4dqi7eFE96Mplxu?= =?us-ascii?Q?wAwSC0BNkSDnqEJ3Erbdo0jt8mT4FzuYsxOGZyZcsz7WQTfWgyEKTaQKomU7?= =?us-ascii?Q?bOkh67qmfjNSvqXDQbBVc8XEASkdpxoPXAoNwbgBFLtxdv/uZ5wOvZvIrcul?= =?us-ascii?Q?VSmuZoXHd2AvZ+kAvDqKGxVyNwwinJ7pP4vdfrgF2gCTzczjQWNieFTJzHVf?= =?us-ascii?Q?uAEbdqt3s6geCnJruVVyHzYwHUJD8ijNR5tNxEX9fl5Z5N9/MJAahz8BSHlz?= =?us-ascii?Q?5ZZ1R1WAXdkZp/spMujNIT9AvlTXquaJwDBtst1c2LPd+KiP5FYV60b0Sc36?= =?us-ascii?Q?PR+tw1wKHtOgKoVsVVyhPTumH9sJkl26SR84ugnkDNPt3TiElRdk71FTeEEF?= =?us-ascii?Q?Pk2wxzDv3vz18OftXh1kLL1A5C70kBtSmYKk7/h1DMUpdafhhbpKzJJgpPxf?= =?us-ascii?Q?IuqFRMLGNnpfaifPh5kAm5oVzKyrUrwcNoAWg6aKl6wdVGaxnoJ8ZqTIP7g1?= =?us-ascii?Q?YxeaRCg1lpyzVQYe3gpm+SEQTBIq/9kdBYSBxMimRqmz0QYYgMjK6CDC3Ato?= =?us-ascii?Q?J6x6ZYPdC/KvyxzWOxa4EyfnqNBno4jeaeyQwP2eWrjYTVMZUxNEufxBC9MU?= =?us-ascii?Q?5qHEmg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.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: 19 Jan 2026 18:01:08.3181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecb4be16-08a2-4dce-d078-08de5784b90b 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB50.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6627 Content-Type: text/plain; charset="utf-8" /proc/schedstat file output is standardized with version number. Add support to record and raw dump v17 version layout. Version 17 of schedstats removed 'lb_imbalance' field as it has no significance anymore and instead added more relevant fields namely 'lb_imbalance_load', 'lb_imbalance_util', 'lb_imbalance_task' and 'lb_imbalance_misfit'. The domain field prints the name of the corresponding sched domain from this version onwards. Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/lib/perf/Makefile | 2 +- tools/lib/perf/include/perf/event.h | 14 ++ tools/lib/perf/include/perf/schedstat-v17.h | 164 ++++++++++++++++++++ tools/perf/util/event.c | 6 + tools/perf/util/synthetic-events.c | 11 ++ 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 tools/lib/perf/include/perf/schedstat-v17.h diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile index 965e066fd780..27e6490f64dc 100644 --- a/tools/lib/perf/Makefile +++ b/tools/lib/perf/Makefile @@ -179,7 +179,7 @@ install_lib: libs cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) =20 HDRS :=3D bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h = mmap.h -HDRS +=3D schedstat-v15.h schedstat-v16.h +HDRS +=3D schedstat-v15.h schedstat-v16.h schedstat-v17.h INTERNAL_HDRS :=3D cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threa= dmap.h xyarray.h =20 INSTALL_HDRS_PFX :=3D $(DESTDIR)$(prefix)/include/perf diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/p= erf/event.h index bd4d507ea8ab..9043dc72b5d6 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -508,6 +508,12 @@ struct perf_record_schedstat_cpu_v16 { #undef CPU_FIELD }; =20 +struct perf_record_schedstat_cpu_v17 { +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) _= type _name +#include "schedstat-v17.h" +#undef CPU_FIELD +}; + struct perf_record_schedstat_cpu { struct perf_event_header header; __u64 timestamp; @@ -518,6 +524,7 @@ struct perf_record_schedstat_cpu { union { struct perf_record_schedstat_cpu_v15 v15; struct perf_record_schedstat_cpu_v16 v16; + struct perf_record_schedstat_cpu_v17 v17; }; }; =20 @@ -533,6 +540,12 @@ struct perf_record_schedstat_domain_v16 { #undef DOMAIN_FIELD }; =20 +struct perf_record_schedstat_domain_v17 { +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) _ty= pe _name +#include "schedstat-v17.h" +#undef DOMAIN_FIELD +}; + #define DOMAIN_NAME_LEN 16 =20 struct perf_record_schedstat_domain { @@ -544,6 +557,7 @@ struct perf_record_schedstat_domain { union { struct perf_record_schedstat_domain_v15 v15; struct perf_record_schedstat_domain_v16 v16; + struct perf_record_schedstat_domain_v17 v17; }; }; =20 diff --git a/tools/lib/perf/include/perf/schedstat-v17.h b/tools/lib/perf/i= nclude/perf/schedstat-v17.h new file mode 100644 index 000000000000..865dc7c1039c --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-v17.h @@ -0,0 +1,164 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CPU_FIELD +CPU_FIELD(__u32, yld_count, "sched_yield() count", + "%11u", false, yld_count, v17); +CPU_FIELD(__u32, array_exp, "Legacy counter can be ignored", + "%11u", false, array_exp, v17); +CPU_FIELD(__u32, sched_count, "schedule() called", + "%11u", false, sched_count, v17); +CPU_FIELD(__u32, sched_goidle, "schedule() left the processor idle", + "%11u", true, sched_count, v17); +CPU_FIELD(__u32, ttwu_count, "try_to_wake_up() was called", + "%11u", false, ttwu_count, v17); +CPU_FIELD(__u32, ttwu_local, "try_to_wake_up() was called to wake up the l= ocal cpu", + "%11u", true, ttwu_count, v17); +CPU_FIELD(__u64, rq_cpu_time, "total runtime by tasks on this processor (i= n jiffies)", + "%11llu", false, rq_cpu_time, v17); +CPU_FIELD(__u64, run_delay, "total waittime by tasks on this processor (in= jiffies)", + "%11llu", true, rq_cpu_time, v17); +CPU_FIELD(__u64, pcount, "total timeslices run on this cpu", + "%11llu", false, pcount, v17); +#endif /* CPU_FIELD */ + +#ifdef DOMAIN_FIELD +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, busy_lb_count, + "load_balance() count on cpu busy", "%11u", true, v17); +DOMAIN_FIELD(__u32, busy_lb_balanced, + "load_balance() found balanced on cpu busy", "%11u", true, v17); +DOMAIN_FIELD(__u32, busy_lb_failed, + "load_balance() move task failed on cpu busy", "%11u", true, v17); +DOMAIN_FIELD(__u32, busy_lb_imbalance_load, + "imbalance in load on cpu busy", "%11u", false, v17); +DOMAIN_FIELD(__u32, busy_lb_imbalance_util, + "imbalance in utilization on cpu busy", "%11u", false, v17); +DOMAIN_FIELD(__u32, busy_lb_imbalance_task, + "imbalance in number of tasks on cpu busy", "%11u", false, v17); +DOMAIN_FIELD(__u32, busy_lb_imbalance_misfit, + "imbalance in misfit tasks on cpu busy", "%11u", false, v17); +DOMAIN_FIELD(__u32, busy_lb_gained, + "pull_task() count on cpu busy", "%11u", false, v17); +DOMAIN_FIELD(__u32, busy_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu busy", "%11u", fa= lse, v17); +DOMAIN_FIELD(__u32, busy_lb_nobusyq, + "load_balance() failed to find busier queue on cpu busy", "%11u", tr= ue, v17); +DOMAIN_FIELD(__u32, busy_lb_nobusyg, + "load_balance() failed to find busier group on cpu busy", "%11u", tr= ue, v17); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(busy_lb_success_count, "load_balance() success count on = cpu busy", "%11u", + busy_lb_count, busy_lb_balanced, busy_lb_failed, v17); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(busy_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu busy)", "%11.2Lf", + busy_lb_count, busy_lb_balanced, busy_lb_failed, busy_lb_gained, v17); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, idle_lb_count, + "load_balance() count on cpu idle", "%11u", true, v17); +DOMAIN_FIELD(__u32, idle_lb_balanced, + "load_balance() found balanced on cpu idle", "%11u", true, v17); +DOMAIN_FIELD(__u32, idle_lb_failed, + "load_balance() move task failed on cpu idle", "%11u", true, v17); +DOMAIN_FIELD(__u32, idle_lb_imbalance_load, + "imbalance in load on cpu idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, idle_lb_imbalance_util, + "imbalance in utilization on cpu idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, idle_lb_imbalance_task, + "imbalance in number of tasks on cpu idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, idle_lb_imbalance_misfit, + "imbalance in misfit tasks on cpu idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, idle_lb_gained, + "pull_task() count on cpu idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, idle_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu idle", "%11u", fa= lse, v17); +DOMAIN_FIELD(__u32, idle_lb_nobusyq, + "load_balance() failed to find busier queue on cpu idle", "%11u", tr= ue, v17); +DOMAIN_FIELD(__u32, idle_lb_nobusyg, + "load_balance() failed to find busier group on cpu idle", "%11u", tr= ue, v17); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(idle_lb_success_count, "load_balance() success count on = cpu idle", "%11u", + idle_lb_count, idle_lb_balanced, idle_lb_failed, v17); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(idle_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu idle)", "%11.2Lf", + idle_lb_count, idle_lb_balanced, idle_lb_failed, idle_lb_gained, v17); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, newidle_lb_count, + "load_balance() count on cpu newly idle", "%11u", true, v17); +DOMAIN_FIELD(__u32, newidle_lb_balanced, + "load_balance() found balanced on cpu newly idle", "%11u", true, v17= ); +DOMAIN_FIELD(__u32, newidle_lb_failed, + "load_balance() move task failed on cpu newly idle", "%11u", true, v= 17); +DOMAIN_FIELD(__u32, newidle_lb_imbalance_load, + "imbalance in load on cpu newly idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, newidle_lb_imbalance_util, + "imbalance in utilization on cpu newly idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, newidle_lb_imbalance_task, + "imbalance in number of tasks on cpu newly idle", "%11u", false, v17= ); +DOMAIN_FIELD(__u32, newidle_lb_imbalance_misfit, + "imbalance in misfit tasks on cpu newly idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, newidle_lb_gained, + "pull_task() count on cpu newly idle", "%11u", false, v17); +DOMAIN_FIELD(__u32, newidle_lb_hot_gained, + "pull_task() when target task was cache-hot on cpu newly idle", "%11= u", false, v17); +DOMAIN_FIELD(__u32, newidle_lb_nobusyq, + "load_balance() failed to find busier queue on cpu newly idle", "%11= u", true, v17); +DOMAIN_FIELD(__u32, newidle_lb_nobusyg, + "load_balance() failed to find busier group on cpu newly idle", "%11= u", true, v17); +#ifdef DERIVED_CNT_FIELD +DERIVED_CNT_FIELD(newidle_lb_success_count, + "load_balance() success count on cpu newly idle", "%11u", + newidle_lb_count, newidle_lb_balanced, newidle_lb_failed, v17); +#endif +#ifdef DERIVED_AVG_FIELD +DERIVED_AVG_FIELD(newidle_lb_avg_pulled, + "avg task pulled per successful lb attempt (cpu newly idle)", "%11.2Lf= ", + newidle_lb_count, newidle_lb_balanced, newidle_lb_failed, newidle_lb_g= ained, v17); +#endif +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, alb_count, + "active_load_balance() count", "%11u", false, v17); +DOMAIN_FIELD(__u32, alb_failed, + "active_load_balance() move task failed", "%11u", false, v17); +DOMAIN_FIELD(__u32, alb_pushed, + "active_load_balance() successfully moved a task", "%11u", false, v1= 7); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, sbe_count, + "sbe_count is not used", "%11u", false, v17); +DOMAIN_FIELD(__u32, sbe_balanced, + "sbe_balanced is not used", "%11u", false, v17); +DOMAIN_FIELD(__u32, sbe_pushed, + "sbe_pushed is not used", "%11u", false, v17); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, sbf_count, + "sbf_count is not used", "%11u", false, v17); +DOMAIN_FIELD(__u32, sbf_balanced, + "sbf_balanced is not used", "%11u", false, v17); +DOMAIN_FIELD(__u32, sbf_pushed, + "sbf_pushed is not used", "%11u", false, v17); +#ifdef DOMAIN_CATEGORY +DOMAIN_CATEGORY(" "); +#endif +DOMAIN_FIELD(__u32, ttwu_wake_remote, + "try_to_wake_up() awoke a task that last ran on a diff cpu", "%11u",= false, v17); +DOMAIN_FIELD(__u32, ttwu_move_affine, + "try_to_wake_up() moved task because cache-cold on own cpu", "%11u",= false, v17); +DOMAIN_FIELD(__u32, ttwu_move_balance, + "try_to_wake_up() started passive balancing", "%11u", false, v17); +#endif /* DOMAIN_FIELD */ diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 9a434e2e480f..f40419d21034 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -588,6 +588,9 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_eve= nt *event, FILE *fp) } else if (version =3D=3D 16) { #include return size; + } else if (version =3D=3D 17) { +#include + return size; } #undef CPU_FIELD =20 @@ -610,6 +613,9 @@ size_t perf_event__fprintf_schedstat_domain(union perf_= event *event, FILE *fp) } else if (version =3D=3D 16) { #include return size; + } else if (version =3D=3D 17) { +#include + return size; } #undef DOMAIN_FIELD =20 diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 4ce37357db05..ef79433ebc3a 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2569,6 +2569,8 @@ static union perf_event *__synthesize_schedstat_cpu(s= truct io *io, __u16 version #include } else if (version =3D=3D 16) { #include + } else if (version =3D=3D 17) { +#include } #undef CPU_FIELD =20 @@ -2595,6 +2597,11 @@ static union perf_event *__synthesize_schedstat_doma= in(struct io *io, __u16 vers return NULL; =20 ch =3D io__get_dec(io, &d_num); + if (version >=3D 17) { + /* Skip domain name as it can be extracted from perf header */ + while (io__get_char(io) !=3D ' ') + continue; + } =20 /* Skip cpumask as it can be extracted from perf header */ while (io__get_char(io) !=3D ' ') @@ -2624,6 +2631,8 @@ static union perf_event *__synthesize_schedstat_domai= n(struct io *io, __u16 vers #include } else if (version =3D=3D 16) { #include + } else if (version =3D=3D 17) { +#include } #undef DOMAIN_FIELD =20 @@ -2667,6 +2676,8 @@ int perf_event__synthesize_schedstat(const struct per= f_tool *tool, version =3D 15; } else if (!strcmp(line, "version 16\n")) { version =3D 16; + } else if (!strcmp(line, "version 17\n")) { + version =3D 17; } else { pr_err("Unsupported %s version: %s", path, line + 8); goto out_free_line; --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013010.outbound.protection.outlook.com [40.93.196.10]) (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 5F3A232ED4D; Mon, 19 Jan 2026 18:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845706; cv=fail; b=SirWmudr5Myeserm1JTzoeb0NYc/nPZpiazpeo5ZPe5OL2huVx1wRVgkEUjrxVmI/gdd9JLT3LioeTadiTfwFMy6d0IOT3zEXyWdLAp4pzmVPerFEEPrGwEOP1Y/IpVoYYcQmO1oxEd062uc5+90QZBTqe87k9uyOvjCf9bfCZ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845706; c=relaxed/simple; bh=PeRdMaljwzlhlagfKruHIpNwbDbkktifM970h0Gnbhc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MBf6AsYIPyrQsKbNgjLEJWUhdPBCG9Yqtp8aW3feNkRF7nLL8a9qFLvYeKJ/tX1TBCuZqZB+iZTGi9iWe/HZRtb8tiRSMqrCjeDWc5bQ3NzulBZnDlr3evqOsPBOi+zFRlTBFwh2Gn7NOQbfaBC9+Dct24tS0eGf53a9st16H70= 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=PWkCYk0H; arc=fail smtp.client-ip=40.93.196.10 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="PWkCYk0H" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H0J8mg5N0LKGt1iifi5CkI59DGF7d/M+EycZrHB3RRUppJNf18lTMLZ7qc35tWnozwJFtziBNLK1ZcWL27IULLhTRVygwoxkoWgUaFwAFtUCNOvEXDjpYYuENzltYC2sXEDe9wwKuqs86uT8n/vbC9wx3YiAQCP0SdXOCr97uc70nA2BqhJ9mMxpGYTRZwfhLjBjreACBvIgi0lIpzFORfc23uakwm0ku5ANV7Ym9Mbf5UFDAK+kGaaJDmelIjdTtPHqWzYYFadszLMaAndYCDBTrz6sMtHEw04mk1N5SNJjxV6O83u3RL5Idgzb6NQWIKaVMxIAEr5aWXG2WiouWw== 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=1NhA3Rd2UmeUqV1FRQzMtu2mvrxdNkmFhhDTDghj+D8=; b=uTrMzAYwNnwK1Auy92ODy89+pJjTEoyhJMWCFH06golNdnzDX722/5tvX8Uw6Yekgy+o46y01I6C1PtSWTCPQSMY+Sj/ajgzM5vb2C2qIqFpWR76EwaYJaYEBn+PLEM4LxKhb7BXA/HGkcKsGoy0AlHbICbgymdjYCzjg51vysMLg2PMKYC2VkRa/nPCJ4u6tQYoWf23geMYA1NhMJR0PgZIfB5wFkYf2n+4uR1qN/Dt5hYaeS2sFXkDzkCW/mvoM2FGO/q6PZWug/YcgxTFFu4Yy4EWDRGV9DVYOIQkEKpuethNl1DzceT+76T6PJ9ASpav5uFZjWBKInaXDQYlVQ== 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=1NhA3Rd2UmeUqV1FRQzMtu2mvrxdNkmFhhDTDghj+D8=; b=PWkCYk0H32HCbTHct4t0Gfo8KtcR+Zt2yGhFjyhw4ultUucevZe9ryToIPspaEParpBavIlevM6ntaRu0lH+N0AI83SMF1y+MTvbU50SV1Z6rati6zzKXn0PGki6IcW6FUIu8EdCHvC9t7QLb6oX/kYndFg4AplgwPiXX92h5pA= Received: from MN0PR05CA0019.namprd05.prod.outlook.com (2603:10b6:208:52c::26) by DM4PR12MB6040.namprd12.prod.outlook.com (2603:10b6:8:af::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 18:01:32 +0000 Received: from BL6PEPF0001AB4C.namprd04.prod.outlook.com (2603:10b6:208:52c:cafe::42) by MN0PR05CA0019.outlook.office365.com (2603:10b6:208:52c::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9542.8 via Frontend Transport; Mon, 19 Jan 2026 18:01:28 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB4C.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:01:30 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:01:19 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "James Clark" Subject: [PATCH v5 06/10] perf sched stats: Add support for report subcommand Date: Mon, 19 Jan 2026 17:58:28 +0000 Message-ID: <20260119175833.340369-7-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4C:EE_|DM4PR12MB6040:EE_ X-MS-Office365-Filtering-Correlation-Id: da303346-d137-4ba9-bfad-08de5784c61f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?tku1drr76rlPM/Nfz1Ci1X9zKwe8gIZ9RbkBqy4dkj34cYVzBd1o3J6H+cU3?= =?us-ascii?Q?1Xj3zpU95pfpm/bfp3k6PXe2ElDnZYLup9Cs5CFSqBeWZ/qyZtyWQWz5sGPj?= =?us-ascii?Q?kY3kwk+O8bA2qhJy4ZfAwDAfPaGv1KgtT3s5v1HFUqnZf/d6gg4VdGIth8h9?= =?us-ascii?Q?JfDN+k2trhRr7B2RHLyveiBI3dzspXv0AMmapSx3vsGzVdhCC+0Ti2eqCC5y?= =?us-ascii?Q?L6bWeUr7QzDUP+0ihocLSHMuUjcmS+tdJYjpVpKDTXKRJ84wzklGrRwg7Eno?= =?us-ascii?Q?nRnmfiwU7eSd9geefURsNhE/0wH8NZmP++TvBdZdDzIlZuBNTM31EGwoU/8X?= =?us-ascii?Q?OvR7USduDEjbLJEFGRUNqzSHLhISRgfU96gr1qj7UXIdXtWhxGlevybv0fMF?= =?us-ascii?Q?XLWizLYsMlEmfO//TAWtaYxSIjQRV518SmI7gPm3CJ3Q470VIsxsj2V1iTMR?= =?us-ascii?Q?LIy4z5WRhMp1kgMPwRzjr+a61tFC0aIL35iQ4BtkLcQZmus0sBck4Zim+3Ft?= =?us-ascii?Q?siIRm4jt4QmKiYMqTg8KtmZzSsGB93IxpjMK0IJCAhMXYZ/y1hkmwn3T3w/I?= =?us-ascii?Q?NB+73eIJjxdAdUwr3rDttJsX3iEh5WlCQaiAYuhJ7VToe/qAaAkfeAtzrTu+?= =?us-ascii?Q?9xIhYVfaTqTPGLKHjWMBPX6shLIQm9KGGDhsOTbzX+LR2bIbuKi9lbIgWoYu?= =?us-ascii?Q?mfLF67lBy0I50BrXnDC2YMRgrQ43LzwDTpmInmx5/pLMrUR9yKQCgAeUp837?= =?us-ascii?Q?OAualh1nawOVX/LvnXjY00xf0cNk9QJFwFIRLSxi5Qm0h32KolD5OdOv/98t?= =?us-ascii?Q?S82asMXj40gQjPp8xehT8Sfzl1q0oQD2+n5R8EnuIswOK74ANOcCYqg2Vr9x?= =?us-ascii?Q?+Wm+50R0nVvTpB+nTb1yhnmmWIEHEeqUov5N7C5xx0pz/qLuQLdKb1wFTOd5?= =?us-ascii?Q?VD7SLEtgeteGCLgntgE05Y89OOKor19GvzboqwLTjkBvW0ulYTU7rtaDZyo9?= =?us-ascii?Q?AQVeGgvkaKJ6GvQtbt8mpifORvMKLPXmqR89+uDAgLNudo3zgeodk9QVjCn3?= =?us-ascii?Q?yY/8KP1UdUE6qW35VnE6EBbUe/xSFMys5pMaFOAnJrvyTjLnXxf8gzZiKrwm?= =?us-ascii?Q?YtMM/eFJrQkyQ4N3/XzqjnUB+c/dKHTKn1ULvYnrt1XP7XlBNJmsF1w3LkrM?= =?us-ascii?Q?P70CGE6O7jMC4Z6/YY4k+L1S+NzihjWUXnqjF6KY4RKapG0sLhGmThqCpxRA?= =?us-ascii?Q?gw4YxGXRfg5/IaW6bbt9Z0IMsc5Qy2zw2oo9t3Y+IUa4XDbJ422nnBzscOHN?= =?us-ascii?Q?NMJlhJL0tpe9i8rvRmJ1XlAkuEDvgd8NjJLoivN+0tN6TaTzpr22JAFskrWA?= =?us-ascii?Q?BaesZlsf5tYAGDi2Qml+4FtlzOhX5MlZtP1/SIiOAC0kXprpgWx9DY/mcqlc?= =?us-ascii?Q?PIFRmbDtFEj7Rz332L4bKIIMzxoQVe7DkHIEuKvtpXz9nBlVBQi98WD976M4?= =?us-ascii?Q?WH/2JyftoYtga4Vc7sCNoRwjzxn/pXVZl8OX7v9mBpVjZpFOHZrelqOeMYBz?= =?us-ascii?Q?whZ7zH9w5mwxWWCzBTF8WbSBubujnE8usJQPrT/K+fzw5wIVbnwx66z8JIMw?= =?us-ascii?Q?IZeKXwjHZvvdfw6h9v/mPCWY6ggVYGs43S0nmbA0FZCUtC9S8FKJhBoD6WT7?= =?us-ascii?Q?pz5oMQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:01:30.4005 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da303346-d137-4ba9-bfad-08de5784c61f 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB4C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6040 Content-Type: text/plain; charset="utf-8" `perf sched stats record` captures two sets of samples. For workload profile, first set right before workload starts and second set after workload finishes. For the systemwide profile, first set at the beginning of profile and second set on receiving SIGINT signal. Add `perf sched stats report` subcommand that will read both the set of samples, get the diff and render a final report. Final report prints scheduler stat at cpu granularity as well as sched domain granularity. Example usage: # ./perf sched stats record -- true [ perf sched stats: Wrote samples to perf.data ] # perf sched stats report Description -------------------------------------------------------------------------= --------------------------- DESC -> Description of the field COUNT -> Value of the field PCT_CHANGE -> Percent change with corresponding base v= alue AVG_JIFFIES -> Avg time in jiffies between two consecut= ive occurrence of event -------------------------------------------------------------------------= --------------------------- Time elapsed (in jiffies) : = 1 -------------------------------------------------------------------------= --------------------------- CPU: -------------------------------------------------------------------------= --------------------------- DESC = COUNT PCT_CHANGE -------------------------------------------------------------------------= --------------------------- yld_count : = 0 array_exp : = 0 sched_count : = 0 sched_goidle : = 0 ( 0.00% ) ttwu_count : = 0 ttwu_local : = 0 ( 0.00% ) rq_cpu_time : = 33525 run_delay : = 436 ( 1.30% ) pcount : = 0 -------------------------------------------------------------------------= --------------------------- CPU: | DOMAIN: SMT -------------------------------------------------------------------------= --------------------------- DESC = COUNT AVG_JIFFIES ----------------------------------------- ---------------= --------------------------- busy_lb_count : = 0 $ 0.00 $ busy_lb_balanced : = 0 $ 0.00 $ busy_lb_failed : = 0 $ 0.00 $ busy_lb_imbalance_load : = 0 busy_lb_imbalance_util : = 0 busy_lb_imbalance_task : = 0 busy_lb_imbalance_misfit : = 0 busy_lb_gained : = 0 busy_lb_hot_gained : = 0 busy_lb_nobusyq : = 0 $ 0.00 $ busy_lb_nobusyg : = 0 $ 0.00 $ *busy_lb_success_count : = 0 *busy_lb_avg_pulled : = 0.00 ... and so on. Output shows similar data for all the cpus in the system. Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/perf/builtin-sched.c | 509 ++++++++++++++++++++++++++++++++++++- tools/perf/util/util.c | 6 + tools/perf/util/util.h | 2 + 3 files changed, 515 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index ee3b4e42156e..c6b054b9b12a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3929,6 +3929,503 @@ static int perf_sched__schedstat_record(struct perf= _sched *sched, return err; } =20 +struct schedstat_domain { + struct list_head domain_list; + struct perf_record_schedstat_domain *domain_data; +}; + +struct schedstat_cpu { + struct list_head cpu_list; + struct list_head domain_head; + struct perf_record_schedstat_cpu *cpu_data; +}; + +static struct list_head cpu_head =3D LIST_HEAD_INIT(cpu_head); +static struct schedstat_cpu *cpu_second_pass; +static struct schedstat_domain *domain_second_pass; +static bool after_workload_flag; +static bool verbose_field; + +static void store_schedtstat_cpu_diff(struct schedstat_cpu *after_workload) +{ + struct perf_record_schedstat_cpu *before =3D cpu_second_pass->cpu_data; + struct perf_record_schedstat_cpu *after =3D after_workload->cpu_data; + __u16 version =3D after_workload->cpu_data->version; + +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ + (before->_ver._name =3D after->_ver._name - before->_ver._name) + + if (version =3D=3D 15) { +#include + } else if (version =3D=3D 16) { +#include + } else if (version =3D=3D 17) { +#include + } + +#undef CPU_FIELD +} + +static void store_schedstat_domain_diff(struct schedstat_domain *after_wor= kload) +{ + struct perf_record_schedstat_domain *before =3D domain_second_pass->domai= n_data; + struct perf_record_schedstat_domain *after =3D after_workload->domain_dat= a; + __u16 version =3D after_workload->domain_data->version; + +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ + (before->_ver._name =3D after->_ver._name - before->_ver._name) + + if (version =3D=3D 15) { +#include + } else if (version =3D=3D 16) { +#include + } else if (version =3D=3D 17) { +#include + } +#undef DOMAIN_FIELD +} + +static inline void print_cpu_stats(struct perf_record_schedstat_cpu *cs) +{ + printf("%-65s %12s %12s\n", "DESC", "COUNT", "PCT_CHANGE"); + printf("%.*s\n", 100, graph_dotted_line); + +#define CALC_PCT(_x, _y) ((_y) ? ((double)(_x) / (_y)) * 100 : 0.0) + +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ + do { \ + printf("%-65s: " _format, verbose_field ? _desc : #_name, \ + cs->_ver._name); \ + if (_is_pct) { \ + printf(" ( %8.2lf%% )", \ + CALC_PCT(cs->_ver._name, cs->_ver._pct_of)); \ + } \ + printf("\n"); \ + } while (0) + + if (cs->version =3D=3D 15) { +#include + } else if (cs->version =3D=3D 16) { +#include + } else if (cs->version =3D=3D 17) { +#include + } + +#undef CPU_FIELD +#undef CALC_PCT +} + +static inline void print_domain_stats(struct perf_record_schedstat_domain = *ds, + __u64 jiffies) +{ + printf("%-65s %12s %14s\n", "DESC", "COUNT", "AVG_JIFFIES"); + +#define DOMAIN_CATEGORY(_desc) \ + do { \ + size_t _len =3D strlen(_desc); \ + size_t _pre_dash_cnt =3D (100 - _len) / 2; \ + size_t _post_dash_cnt =3D 100 - _len - _pre_dash_cnt; \ + print_separator2((int)_pre_dash_cnt, _desc, (int)_post_dash_cnt);\ + } while (0) + +#define CALC_AVG(_x, _y) ((_y) ? (long double)(_x) / (_y) : 0.0) + +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ + do { \ + printf("%-65s: " _format, verbose_field ? _desc : #_name, \ + ds->_ver._name); \ + if (_is_jiffies) { \ + printf(" $ %11.2Lf $", \ + CALC_AVG(jiffies, ds->_ver._name)); \ + } \ + printf("\n"); \ + } while (0) + +#define DERIVED_CNT_FIELD(_name, _desc, _format, _x, _y, _z, _ver) \ + printf("*%-64s: " _format "\n", verbose_field ? _desc : #_name, \ + (ds->_ver._x) - (ds->_ver._y) - (ds->_ver._z)) + +#define DERIVED_AVG_FIELD(_name, _desc, _format, _x, _y, _z, _w, _ver) \ + printf("*%-64s: " _format "\n", verbose_field ? _desc : #_name, \ + CALC_AVG(ds->_ver._w, \ + ((ds->_ver._x) - (ds->_ver._y) - (ds->_ver._z)))) + + if (ds->version =3D=3D 15) { +#include + } else if (ds->version =3D=3D 16) { +#include + } else if (ds->version =3D=3D 17) { +#include + } + +#undef DERIVED_AVG_FIELD +#undef DERIVED_CNT_FIELD +#undef DOMAIN_FIELD +#undef CALC_AVG +#undef DOMAIN_CATEGORY +} + +static void summarize_schedstat_cpu(struct schedstat_cpu *summary_cpu, + struct schedstat_cpu *cptr, + int cnt, bool is_last) +{ + struct perf_record_schedstat_cpu *summary_cs =3D summary_cpu->cpu_data, + *temp_cs =3D cptr->cpu_data; + +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ + do { \ + summary_cs->_ver._name +=3D temp_cs->_ver._name; \ + if (is_last) \ + summary_cs->_ver._name /=3D cnt; \ + } while (0) + + if (cptr->cpu_data->version =3D=3D 15) { +#include + } else if (cptr->cpu_data->version =3D=3D 16) { +#include + } else if (cptr->cpu_data->version =3D=3D 17) { +#include + } +#undef CPU_FIELD +} + +static void summarize_schedstat_domain(struct schedstat_domain *summary_do= main, + struct schedstat_domain *dptr, + int cnt, bool is_last) +{ + struct perf_record_schedstat_domain *summary_ds =3D summary_domain->domai= n_data, + *temp_ds =3D dptr->domain_data; + +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ + do { \ + summary_ds->_ver._name +=3D temp_ds->_ver._name; \ + if (is_last) \ + summary_ds->_ver._name /=3D cnt; \ + } while (0) + + if (dptr->domain_data->version =3D=3D 15) { +#include + } else if (dptr->domain_data->version =3D=3D 16) { +#include + } else if (dptr->domain_data->version =3D=3D 17) { +#include + } +#undef DOMAIN_FIELD +} + +/* + * get_all_cpu_stats() appends the summary to the head of the list. + */ +static int get_all_cpu_stats(struct list_head *head) +{ + struct schedstat_cpu *cptr =3D list_first_entry(head, struct schedstat_cp= u, cpu_list); + struct schedstat_cpu *summary_head =3D NULL; + struct perf_record_schedstat_domain *ds; + struct perf_record_schedstat_cpu *cs; + struct schedstat_domain *dptr, *tdptr; + bool is_last =3D false; + int cnt =3D 1; + int ret =3D 0; + + if (cptr) { + summary_head =3D zalloc(sizeof(*summary_head)); + if (!summary_head) + return -ENOMEM; + + summary_head->cpu_data =3D zalloc(sizeof(*cs)); + memcpy(summary_head->cpu_data, cptr->cpu_data, sizeof(*cs)); + + INIT_LIST_HEAD(&summary_head->domain_head); + + list_for_each_entry(dptr, &cptr->domain_head, domain_list) { + tdptr =3D zalloc(sizeof(*tdptr)); + if (!tdptr) + return -ENOMEM; + + tdptr->domain_data =3D zalloc(sizeof(*ds)); + if (!tdptr->domain_data) + return -ENOMEM; + + memcpy(tdptr->domain_data, dptr->domain_data, sizeof(*ds)); + list_add_tail(&tdptr->domain_list, &summary_head->domain_head); + } + } + + list_for_each_entry(cptr, head, cpu_list) { + if (list_is_first(&cptr->cpu_list, head)) + continue; + + if (list_is_last(&cptr->cpu_list, head)) + is_last =3D true; + + cnt++; + summarize_schedstat_cpu(summary_head, cptr, cnt, is_last); + tdptr =3D list_first_entry(&summary_head->domain_head, struct schedstat_= domain, + domain_list); + + list_for_each_entry(dptr, &cptr->domain_head, domain_list) { + summarize_schedstat_domain(tdptr, dptr, cnt, is_last); + tdptr =3D list_next_entry(tdptr, domain_list); + } + } + + list_add(&summary_head->cpu_list, head); + return ret; +} + +static int show_schedstat_data(struct list_head *head, struct cpu_domain_m= ap **cd_map) +{ + struct schedstat_cpu *cptr =3D list_first_entry(head, struct schedstat_cp= u, cpu_list); + __u64 jiffies =3D cptr->cpu_data->timestamp; + struct perf_record_schedstat_domain *ds; + struct perf_record_schedstat_cpu *cs; + struct schedstat_domain *dptr; + bool is_summary =3D true; + int ret =3D 0; + + printf("Description\n"); + print_separator2(100, "", 0); + printf("%-30s-> %s\n", "DESC", "Description of the field"); + printf("%-30s-> %s\n", "COUNT", "Value of the field"); + printf("%-30s-> %s\n", "PCT_CHANGE", "Percent change with corresponding b= ase value"); + printf("%-30s-> %s\n", "AVG_JIFFIES", + "Avg time in jiffies between two consecutive occurrence of event"); + + print_separator2(100, "", 0); + printf("\n"); + + printf("%-65s: %11llu\n", "Time elapsed (in jiffies)", jiffies); + + ret =3D get_all_cpu_stats(head); + + list_for_each_entry(cptr, head, cpu_list) { + cs =3D cptr->cpu_data; + print_separator2(100, "", 0); + + if (is_summary) + printf("CPU: \n"); + else + printf("CPU: %d\n", cs->cpu); + + print_separator2(100, "", 0); + print_cpu_stats(cs); + print_separator2(100, "", 0); + + list_for_each_entry(dptr, &cptr->domain_head, domain_list) { + struct domain_info *dinfo; + + ds =3D dptr->domain_data; + dinfo =3D cd_map[ds->cpu]->domains[ds->domain]; + if (is_summary) { + if (dinfo->dname) + printf("CPU: | DOMAIN: %s\n", + dinfo->dname); + else + printf("CPU: | DOMAIN: %d\n", + dinfo->domain); + } else { + if (dinfo->dname) + printf("CPU: %d | DOMAIN: %s | DOMAIN_CPUS: ", + cs->cpu, dinfo->dname); + else + printf("CPU: %d | DOMAIN: %d | DOMAIN_CPUS: ", + cs->cpu, dinfo->domain); + + printf("%s\n", dinfo->cpulist); + } + print_separator2(100, "", 0); + print_domain_stats(ds, jiffies); + print_separator2(100, "", 0); + } + is_summary =3D false; + } + return ret; +} + +/* + * Creates a linked list of cpu_data and domain_data. Below represents the= structure of the linked + * list where CPU0,CPU1,CPU2, ..., CPU(N-1) stores the cpu_data. Here N is= the total number of cpus. + * Each of the CPU points to the list of domain_data. Here DOMAIN0, DOMAIN= 1, DOMAIN2, ... represents + * the domain_data. Here D0, D1, D2, ..., Dm are the number of domains in = the respective cpus. + * + * +----------+ + * | CPU_HEAD | + * +----------+ + * | + * v + * +----------+ +---------+ +---------+ +---------+ +--------= ------+ + * | CPU0 | -> | DOMAIN0 | -> | DOMAIN1 | -> | DOMAIN2 | -> ... -> | D= OMAIN(D0-1) | + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * | + * v + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * | CPU1 | -> | DOMAIN0 | -> | DOMAIN1 | -> | DOMAIN2 | -> ... -> | D= OMAIN(D1-1) | + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * | + * v + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * | CPU2 | -> | DOMAIN0 | -> | DOMAIN1 | -> | DOMAIN2 | -> ... -> | D= OMAIN(D2-1) | + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * | + * v + * ... + * | + * v + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * | CPU(N-1) | -> | DOMAIN0 | -> | DOMAIN1 | -> | DOMAIN2 | -> ... -> | D= OMAIN(Dm-1) | + * +----------+ +---------+ +---------+ +---------+ +--= ------------+ + * + * Each cpu as well as domain has 2 enties in the event list one before th= e workload starts and + * other after completion of the workload. The above linked list stores th= e diff of the cpu and + * domain statistics. + */ +static int perf_sched__process_schedstat(const struct perf_tool *tool __ma= ybe_unused, + struct perf_session *session __maybe_unused, + union perf_event *event) +{ + struct perf_cpu this_cpu; + static __u32 initial_cpu; + + switch (event->header.type) { + case PERF_RECORD_SCHEDSTAT_CPU: + this_cpu.cpu =3D event->schedstat_cpu.cpu; + break; + case PERF_RECORD_SCHEDSTAT_DOMAIN: + this_cpu.cpu =3D event->schedstat_domain.cpu; + break; + default: + return 0; + } + + if (user_requested_cpus && !perf_cpu_map__has(user_requested_cpus, this_c= pu)) + return 0; + + if (event->header.type =3D=3D PERF_RECORD_SCHEDSTAT_CPU) { + struct schedstat_cpu *temp =3D zalloc(sizeof(*temp)); + + if (!temp) + return -ENOMEM; + + temp->cpu_data =3D zalloc(sizeof(*temp->cpu_data)); + if (!temp->cpu_data) + return -ENOMEM; + + memcpy(temp->cpu_data, &event->schedstat_cpu, sizeof(*temp->cpu_data)); + + if (!list_empty(&cpu_head) && temp->cpu_data->cpu =3D=3D initial_cpu) + after_workload_flag =3D true; + + if (!after_workload_flag) { + if (list_empty(&cpu_head)) + initial_cpu =3D temp->cpu_data->cpu; + + list_add_tail(&temp->cpu_list, &cpu_head); + INIT_LIST_HEAD(&temp->domain_head); + } else { + if (temp->cpu_data->cpu =3D=3D initial_cpu) { + cpu_second_pass =3D list_first_entry(&cpu_head, struct schedstat_cpu, + cpu_list); + cpu_second_pass->cpu_data->timestamp =3D + temp->cpu_data->timestamp - cpu_second_pass->cpu_data->timestamp; + } else { + cpu_second_pass =3D list_next_entry(cpu_second_pass, cpu_list); + } + domain_second_pass =3D list_first_entry(&cpu_second_pass->domain_head, + struct schedstat_domain, domain_list); + store_schedtstat_cpu_diff(temp); + } + } else if (event->header.type =3D=3D PERF_RECORD_SCHEDSTAT_DOMAIN) { + struct schedstat_cpu *cpu_tail; + struct schedstat_domain *temp =3D zalloc(sizeof(*temp)); + + if (!temp) + return -ENOMEM; + + temp->domain_data =3D zalloc(sizeof(*temp->domain_data)); + if (!temp->domain_data) + return -ENOMEM; + + memcpy(temp->domain_data, &event->schedstat_domain, sizeof(*temp->domain= _data)); + + if (!after_workload_flag) { + cpu_tail =3D list_last_entry(&cpu_head, struct schedstat_cpu, cpu_list); + list_add_tail(&temp->domain_list, &cpu_tail->domain_head); + } else { + store_schedstat_domain_diff(temp); + domain_second_pass =3D list_next_entry(domain_second_pass, domain_list); + } + } + + return 0; +} + +static void free_schedstat(struct list_head *head) +{ + struct schedstat_domain *dptr, *n1; + struct schedstat_cpu *cptr, *n2; + + list_for_each_entry_safe(cptr, n2, head, cpu_list) { + list_for_each_entry_safe(dptr, n1, &cptr->domain_head, domain_list) { + list_del_init(&dptr->domain_list); + free(dptr); + } + list_del_init(&cptr->cpu_list); + free(cptr); + } +} + +static int perf_sched__schedstat_report(struct perf_sched *sched) +{ + struct cpu_domain_map **cd_map; + struct perf_session *session; + struct target target =3D {}; + struct perf_data data =3D { + .path =3D input_name, + .mode =3D PERF_DATA_MODE_READ, + }; + int err =3D 0; + + sched->tool.schedstat_cpu =3D perf_sched__process_schedstat; + sched->tool.schedstat_domain =3D perf_sched__process_schedstat; + + session =3D perf_session__new(&data, &sched->tool); + if (IS_ERR(session)) { + pr_err("Perf session creation failed.\n"); + return PTR_ERR(session); + } + + if (cpu_list) + target.cpu_list =3D cpu_list; + else + target.system_wide =3D true; + + err =3D evlist__create_maps(session->evlist, &target); + if (err < 0) + goto out; + + user_requested_cpus =3D session->evlist->core.user_requested_cpus; + + err =3D perf_session__process_events(session); + + if (!err) { + setup_pager(); + + if (list_empty(&cpu_head)) { + pr_err("Data is not available\n"); + err =3D -1; + goto out; + } + + cd_map =3D session->header.env.cpu_domain; + err =3D show_schedstat_data(&cpu_head, cd_map); + } + +out: + free_schedstat(&cpu_head); + perf_session__delete(session); + return err; +} + static bool schedstat_events_exposed(void) { /* @@ -4106,9 +4603,12 @@ int cmd_sched(int argc, const char **argv) OPT_PARENT(sched_options) }; const struct option stats_options[] =3D { + OPT_STRING('i', "input", &input_name, "file", + "`stats report` with input filename"), OPT_STRING('o', "output", &output_name, "file", "`stats record` with output filename"), OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), + OPT_BOOLEAN('v', "verbose", &verbose_field, "Show explanation for fields = in the report"), OPT_END() }; =20 @@ -4129,7 +4629,7 @@ int cmd_sched(int argc, const char **argv) NULL }; const char *stats_usage[] =3D { - "perf sched stats {record} []", + "perf sched stats {record|report} []", NULL }; const char *const sched_subcommands[] =3D { "record", "latency", "map", @@ -4233,7 +4733,7 @@ int cmd_sched(int argc, const char **argv) if (!ret) ret =3D perf_sched__timehist(&sched); } else if (!strcmp(argv[0], "stats")) { - const char *const stats_subcommands[] =3D {"record", NULL}; + const char *const stats_subcommands[] =3D {"record", "report", NULL}; =20 argc =3D parse_options_subcommand(argc, argv, stats_options, stats_subcommands, @@ -4245,6 +4745,11 @@ int cmd_sched(int argc, const char **argv) argc =3D parse_options(argc, argv, stats_options, stats_usage, 0); return perf_sched__schedstat_record(&sched, argc, argv); + } else if (argv[0] && !strcmp(argv[0], "report")) { + if (argc) + argc =3D parse_options(argc, argv, stats_options, + stats_usage, 0); + return perf_sched__schedstat_report(&sched); } usage_with_options(stats_usage, stats_options); } else { diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index b87ff96a9f45..03a603fbcd7d 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -299,6 +299,12 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist) free(bm); } =20 +void print_separator2(int pre_dash_cnt, const char *s, int post_dash_cnt) +{ + printf("%.*s%s%.*s\n", pre_dash_cnt, graph_dotted_line, s, post_dash_cnt, + graph_dotted_line); +} + int rm_rf_perf_data(const char *path) { const char *pat[] =3D { diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 1572c8cf04e5..394dbfa944ac 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -51,6 +51,8 @@ int perf_tip(char **strp, const char *dirpath); =20 void cpumask_to_cpulist(char *cpumask, char *cpulist); =20 +void print_separator2(int pre_dash_cnt, const char *s, int post_dash_cnt); + #ifndef HAVE_SCHED_GETCPU_SUPPORT int sched_getcpu(void); #endif --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010019.outbound.protection.outlook.com [52.101.85.19]) (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 EF68332E721; Mon, 19 Jan 2026 18:01:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.19 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845721; cv=fail; b=CnIQZdyf4v11RKt26faKFJkeLp1wBY4O/pYtJX+Ug5EzfmTxhBN8pXf0t2qZdhq7DeBZjHmDLCfHV185EDDvNnxvPN2NzkwoN1u+rLvM8/vFPaSB3eeMyeC050BfZB43c7LWPD2+oEIesNCixRuTb1rovm4m1RcW8MqLMTfYOCU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845721; c=relaxed/simple; bh=azpuIFGAPZuGe5bpPOSRoRSDdSNUs1pTGnW1tqErQso=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uzZWlwcdxvTvr7wuuE2SadsPxi9g7KnDfXp68RdtwU6Ln74WchMCgHo4JlnuoIeUgO+/GDUCm9hVBv0Uk8GC+EC7wjCEkrWbIyIgd49B34bLs+mFKXLUqQrw8atzToH95Cc61L+4UVzvVUPMO4TiMKcBMuXA0Uzkc3nlIa17C4o= 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=tB+APnG5; arc=fail smtp.client-ip=52.101.85.19 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="tB+APnG5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CeaxiX5l+neGPp/eKTJS+sYHHYuUyi8MKcw423A+/BHnbBeoMv7Xg/pP9+uqSrfPYaaljiDy3sP4z+2uGu0FxfqWouJfLIUoX2WkNwri3hGULv9L6deQ6y4C7hHOV7ASopwz+VTS0vwfwUnbUHiVPg1Kn6FlZ2ihr4h3Dnxa+dwwTVr9jUeYN952wE1x/6fy24PVBlEVAfIeOgW5QmyuwE5ZoLcqwNvXOQHDnZHxEHAULjcaUnwxhPvBFPl0rNEZzjLqasbW+os80HTiGXqUvjtw2Egpew5A2Voavj7S1CMZ4OK1+53uWJIA7SMhcU3DBDbeIlfgedIynruvtqCTYw== 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=WmJMd7fDjjUupdHqyktYY2gqSdeLdFwIMbYN3auFFQw=; b=c+OWeYmyFrRev50ny1ks9z1ffImfE9keD4++nNcvfEV44pyxftniOv4BxLsOMna2ZZX/w3BviOT0oiT1US9lhyXiZZZl2MoDLasINo0GliX6Ta+Pa8VXNzmSK56oEa3/zHZ5jXyEJO5uO+PaYUGDHh70shW2tmhv1MkCKSvLznIphUv+gIv+97tNRwYdQtVryDyUxOmq5qnlpmshmVaT2iFINUXR96VAH+yx/nA1g4nDTIdum8JCXJBHtLBUpB5oFN1nWyDlVTXAPhaAPMVYvyda1Tf3FL6gkgzPeqKUq3pziP1Lc8qwmQ1id5mQW923glc0dguG6kX2yQRVVK8Kuw== 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=WmJMd7fDjjUupdHqyktYY2gqSdeLdFwIMbYN3auFFQw=; b=tB+APnG5vimJ3PybqcUB9QypGD+SPiODGB8pGLwNcepBaszkUiCKzGow9GDjb0oJrb1vepsO6rwGUEevwU04kfihXqQg0GbE+1viaxgDc+qlT+sCFrn1/90roVEtgyYJ3nflNRiyHR4r15nkWTZ2+Lhtk7ycG5PkMhuPppqnYSs= Received: from CH2PR18CA0003.namprd18.prod.outlook.com (2603:10b6:610:4f::13) by DM4PR12MB7574.namprd12.prod.outlook.com (2603:10b6:8:10e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 18:01:54 +0000 Received: from CH1PEPF0000A347.namprd04.prod.outlook.com (2603:10b6:610:4f:cafe::8e) by CH2PR18CA0003.outlook.office365.com (2603:10b6:610:4f::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9499.7 via Frontend Transport; Mon, 19 Jan 2026 18:01:41 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0000A347.mail.protection.outlook.com (10.167.244.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:01:53 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:01:43 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "James Clark" Subject: [PATCH v5 07/10] perf sched stats: Add support for live mode Date: Mon, 19 Jan 2026 17:58:29 +0000 Message-ID: <20260119175833.340369-8-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A347:EE_|DM4PR12MB7574:EE_ X-MS-Office365-Filtering-Correlation-Id: c99ecc80-0dbf-4840-a284-08de5784d40a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WSVH0zv6ZZ3MkqXTD+uUOkOT6b9TSrdCwJRU2FFtXPRqVPF8ybQVEpwP3szo?= =?us-ascii?Q?QECf1SJfMevIpTGDls9u2LaTP1ShpWzi60tu11kOPKfnOBnB80p86IRWlYzI?= =?us-ascii?Q?2qG/yAss+5tVk8wOjhzm3tBDlkOpgZrxQ1XDRzDRyeTPPGOGGkZ9xCFnSZ+/?= =?us-ascii?Q?CQnW8xtnnWwsgbydawzbHniXuTiqB3vCR0BDZAiXfQx+p3zYYiRMUcsXU9UO?= =?us-ascii?Q?dpxAafxbYqecUVNPo0nskgJFIYDnNuquY6W2Qyb0NjTzQZ1K+UodhH1EJ1qr?= =?us-ascii?Q?SlOOb2Oo7eZPa5oi914waUn3rxTDvwE5YgYxonblvn3ZqG/78WHTtpYwAQbz?= =?us-ascii?Q?9JzRiiF7kw++NuHTkEA+eNR9eEh6aZg/Vfl00fZYTXmYtK/8mDLdSmaW+k7x?= =?us-ascii?Q?vw+HLwYjR+98BfHXQXQYOUGAWtKsD2+nxBWhcUesqmIfusrQAHaQoTIRqN2T?= =?us-ascii?Q?0k64QEO3CUi6xEaJQvZXkr9UYB4Rct4epzeKzrG8aHiXv47HvDJJN5IUHn6M?= =?us-ascii?Q?iliHNoRdwJiiBQGsz3irGCZpPllqFqh1yg4YyOVesJ07IaS5LK8B5NKoClqN?= =?us-ascii?Q?vdIYDXvm3oGstoKzdrkPYwUZa+CDGnwyf+QALdM/uOZPmHrwWcRgQ0Zmjfln?= =?us-ascii?Q?8Y6MFpknAMlYJS1YbHPNOt2Aw0hzrYmkc9R0Dbem7HxElwgYwTi6LfnT5FYK?= =?us-ascii?Q?J29CjzGiPxayyWBSntsi6apgh40JzrrJ2GNU8nk3TIpqB3Kw+I+GKkAH9P+V?= =?us-ascii?Q?z8J2wsPQfa8dtJvmnmH3/f65sUstSBPPJ4YbLG11KOj3SOr9TprLXgMVdc0G?= =?us-ascii?Q?ksW5xbdO6QE4/eBduryhuU5XWkp3i352LAgX3lDZ9UdIj5VKz4z6DjMDv9RR?= =?us-ascii?Q?HRH3pUgTqE1hbKKdZqCHKiVhuTo95i8ePvb1b/hrXjwbypf79myyHAiEgAEN?= =?us-ascii?Q?996oW+eCTkDmRXgVJo6gmEx4LL5sw4FeOK81P7aKzzrSRbMPdfSwLrqTa/QF?= =?us-ascii?Q?rDNHE5u2GoWJJ/OMAPfEdKAM1dRR4HVJvdi63k4Ohw6vaeDgUsQEpdDM12XZ?= =?us-ascii?Q?r+3HB05Vlm90u3ZafbINnGBDAUX+qwhMI6qrpLSiZNjzAmXUG/UNetTPUqYJ?= =?us-ascii?Q?TVI3T9Zb357NlODr1QkQXWoV9jsm8tXKaTO4Tdf6yt9kxz2FvA7h43/zG2eT?= =?us-ascii?Q?ot7ZPzTpgfSXWmWkdH6uTY+URjOofgV/UqtAykmK1CKbLC/cr2wwHoh6qNS0?= =?us-ascii?Q?b5CLl2M/oTANhmK3917vW5BChuqm2WqlkG+kNwlHt+SG6mDJl310F1fGbGjM?= =?us-ascii?Q?mULYbQ7eJa0pz+CROnszg17SogMj0tWXQsmy4Jsn4k2G7yJsjuTbvc/o8ffC?= =?us-ascii?Q?wq9HbMEhkBEeQaprh8hc/P0kn74WneMnn85+vUf5WTiK38ZgW8VlHwVu9S3E?= =?us-ascii?Q?PKAodHZri62PvdJmWR8FX4ddnAZBTUMJ5A4zCj6OzJOdcQLV2+/vnAwuVMSi?= =?us-ascii?Q?5ki05qnv70y7Rt1DlPlj2nE0/RW1jqVW7WuelJm9xOHmNzaNA3KsPFi0AWCR?= =?us-ascii?Q?2/nBtuXJp4jIPXxYAMNBpzEjZLUJKCFDoNLJrmZVfKgAx6g4cm2Jg3inPNy5?= =?us-ascii?Q?jr3Tcrx28KSCQgaAV7o66tiGPIUMWVQNSZpjBXmKCEkN8EHx8STuxLo1Oue3?= =?us-ascii?Q?5Sq8kA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:01:53.7265 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c99ecc80-0dbf-4840-a284-08de5784d40a 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A347.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7574 Content-Type: text/plain; charset="utf-8" The live mode works similar to simple `perf stat` command, by profiling the target and printing results on the terminal as soon as the target finishes. Example usage: # perf sched stats -- true Description -------------------------------------------------------------------------= --------------------------- DESC -> Description of the field COUNT -> Value of the field PCT_CHANGE -> Percent change with corresponding base v= alue AVG_JIFFIES -> Avg time in jiffies between two consecut= ive occurrence of event -------------------------------------------------------------------------= --------------------------- Time elapsed (in jiffies) : = 1 -------------------------------------------------------------------------= --------------------------- CPU: -------------------------------------------------------------------------= --------------------------- DESC = COUNT PCT_CHANGE -------------------------------------------------------------------------= --------------------------- yld_count : = 0 array_exp : = 0 sched_count : = 0 sched_goidle : = 0 ( 0.00% ) ttwu_count : = 0 ttwu_local : = 0 ( 0.00% ) rq_cpu_time : = 27875 run_delay : = 0 ( 0.00% ) pcount : = 0 -------------------------------------------------------------------------= --------------------------- CPU: | DOMAIN: SMT -------------------------------------------------------------------------= --------------------------- DESC = COUNT AVG_JIFFIES ----------------------------------------- ---------------= --------------------------- busy_lb_count : = 0 $ 0.00 $ busy_lb_balanced : = 0 $ 0.00 $ busy_lb_failed : = 0 $ 0.00 $ busy_lb_imbalance_load : = 0 busy_lb_imbalance_util : = 0 busy_lb_imbalance_task : = 0 busy_lb_imbalance_misfit : = 0 busy_lb_gained : = 0 busy_lb_hot_gained : = 0 busy_lb_nobusyq : = 0 $ 0.00 $ busy_lb_nobusyg : = 0 $ 0.00 $ *busy_lb_success_count : = 0 *busy_lb_avg_pulled : = 0.00 ... and so on. Output will show similar data for all the cpus in the system. Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/perf/builtin-sched.c | 99 +++++++++++++++++++++++++++++++++++++- tools/perf/util/header.c | 3 +- tools/perf/util/header.h | 3 ++ 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index c6b054b9b12a..8993308439bc 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -4426,6 +4426,103 @@ static int perf_sched__schedstat_report(struct perf= _sched *sched) return err; } =20 +static int process_synthesized_event_live(const struct perf_tool *tool __m= aybe_unused, + union perf_event *event, + struct perf_sample *sample __maybe_unused, + struct machine *machine __maybe_unused) +{ + return perf_sched__process_schedstat(tool, NULL, event); +} + +static int perf_sched__schedstat_live(struct perf_sched *sched, + int argc, const char **argv) +{ + struct cpu_domain_map **cd_map =3D NULL; + struct target target =3D {}; + u32 __maybe_unused md; + struct evlist *evlist; + u32 nr =3D 0, sv; + int reset =3D 0; + int err =3D 0; + + signal(SIGINT, sighandler); + signal(SIGCHLD, sighandler); + signal(SIGTERM, sighandler); + + evlist =3D evlist__new(); + if (!evlist) + return -ENOMEM; + + /* + * `perf sched schedstat` does not support workload profiling (-p pid) + * since /proc/schedstat file contains cpu specific data only. Hence, a + * profile target is either set of cpus or systemwide, never a process. + * Note that, although `-- ` is supported, profile data are + * still cpu/systemwide. + */ + if (cpu_list) + target.cpu_list =3D cpu_list; + else + target.system_wide =3D true; + + if (argc) { + err =3D evlist__prepare_workload(evlist, &target, argv, false, NULL); + if (err) + goto out; + } + + err =3D evlist__create_maps(evlist, &target); + if (err < 0) + goto out; + + user_requested_cpus =3D evlist->core.user_requested_cpus; + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_event_live, + user_requested_cpus); + if (err < 0) + goto out; + + err =3D enable_sched_schedstats(&reset); + if (err < 0) + goto out; + + if (argc) + evlist__start_workload(evlist); + + /* wait for signal */ + pause(); + + if (reset) { + err =3D disable_sched_schedstat(); + if (err < 0) + goto out; + } + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_event_live, + user_requested_cpus); + if (err) + goto out; + + setup_pager(); + + if (list_empty(&cpu_head)) { + pr_err("Data is not available\n"); + err =3D -1; + goto out; + } + + nr =3D cpu__max_present_cpu().cpu; + cd_map =3D build_cpu_domain_map(&sv, &md, nr); + show_schedstat_data(&cpu_head, cd_map); +out: + free_cpu_domain_info(cd_map, sv, nr); + free_schedstat(&cpu_head); + evlist__delete(evlist); + return err; +} + static bool schedstat_events_exposed(void) { /* @@ -4751,7 +4848,7 @@ int cmd_sched(int argc, const char **argv) stats_usage, 0); return perf_sched__schedstat_report(&sched); } - usage_with_options(stats_usage, stats_options); + return perf_sched__schedstat_live(&sched, argc, argv); } else { usage_with_options(sched_usage, sched_options); } diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 673d53bb2a2c..9a15dd4b7640 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1614,8 +1614,7 @@ static int write_pmu_caps(struct feat_fd *ff, return 0; } =20 -static struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version= , u32 *max_sched_domains, - u32 nr) +struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *= max_sched_domains, u32 nr) { struct domain_info *domain_info; struct cpu_domain_map **cd_map; diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index c62f3275a80f..36cc74e2d14d 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -211,4 +211,7 @@ char *get_cpuid_str(struct perf_cpu cpu); char *get_cpuid_allow_env_override(struct perf_cpu cpu); =20 int strcmp_cpuid_str(const char *s1, const char *s2); + +struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *= max_sched_domains, + u32 nr); #endif /* __PERF_HEADER_H */ --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011069.outbound.protection.outlook.com [52.101.52.69]) (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 D24A223C8AE; Mon, 19 Jan 2026 18:02:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845746; cv=fail; b=QQiW3Rwq/zLqKyDMA6r5Ez1GvLF9RwYCK0Yjx1A75+zfV5zqZdCNVQiySrDaN9/yssk548KSqIdFCvgZAjvdVkdPFrln2C7QR/BmPGyMjyZwCPed92cSE8vMcR/jpj1hSGVBia8J1N+1Dypgd0HnatAi3+IocZlRiQEspgiquHg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845746; c=relaxed/simple; bh=QsgeHdR2DLZYD2o7vwzrTYJtf0nsNrZ+cMdZeQeNGqc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=msPhNS5atjjQRQQ0YAAQ0kbCzlU0FPN0iEJ5E4YYszXb6jLyd3RfqpOTy8C/x14k5sjPGbk6KYJJHWdx7hmj9Ld/jIvH+7NASeBeiEqb3QTrRiRWSOauT3zIoym5uhkKEU4JMe4+BD8DkrM5S6lr0mdv8aNDmOCQ4Z27Cz8UN3w= 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=oyo7GQ15; arc=fail smtp.client-ip=52.101.52.69 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="oyo7GQ15" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=llQel933c2x0e6gcJvVVR3Z0VXEkdYhNFcMN9+kWyic6LlIqalBAYcIMaJ0+KapA2DTf//AZOPSKeJviJu6aXc9ZEAyAaKSbFbjIZ2OpareJCyPk5sob+7hSCKaz2H0OGIdoZ4Kwz/QRhlMPo+OZBKtLS+UK9sMDI6ovBUfAWx8C1327qfFuIbFikgT54TjSynNMD9eavW/nIhxWHLqUSMlsai0P6fWK7rgtVeUTxrnCBVf2O9/JAEozMfs++5CI9Z9MyOw+fpgdSFoK+fJQYaRBxNhY6HQm25DKrMbemT6o8BqR78WHEVB0Go80mtmxNGsNWAktKWxDQLj+DCFLcQ== 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=p1o+y9xaFRu71jx99PlNEK0ptBnrRx6Y5DIow8U2xY0=; b=KnNudBqpsaAq4c3r2eU7rqrfnhY91u4PpLjyDJhLWAJWWlFghXh/RMJqD1AS7zcI5SexHxYcJRRZReEG/EEUx2+a9+WYJER3TWrubXesVB50YOSAJvTyphvJ6csH4DojU6SLiqPdURIudgg5+zpPoEFasbcFZcqnkETHkYCHfmE67TqfWhhMGipTnc2/HHgbsWJxungKpIu6KODN/wVfmzWK9N4oiV3RvEKAcDdem+xrzgvm1NA8VDbq8eRUu+5QBE2wz4mrqTmRTR9uwVl6sFvoYfjlEjSDSYvWuKHQo4rnovbPwFhd8MxM7OC109lo7oJxwTlw7fRG/HiuyH/HZQ== 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=p1o+y9xaFRu71jx99PlNEK0ptBnrRx6Y5DIow8U2xY0=; b=oyo7GQ155G2OA6iTzL19+Qly/GoqoIRXLOtheVJdvXa2KYk9nOIrQWRa0XtQto7n4DpD5KeedEhQAUBg1lTbMkyMuYyS+rPFOaz1cHPCTNrkJu52btJGhnn86jXgnQ6Hrm8f0cccBfK8rldxldvy2Q+Cr+tbsaL4VkFS6CY5RnU= Received: from CH2PR18CA0016.namprd18.prod.outlook.com (2603:10b6:610:4f::26) by SA1PR12MB8988.namprd12.prod.outlook.com (2603:10b6:806:38e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 18:02:17 +0000 Received: from CH1PEPF0000A347.namprd04.prod.outlook.com (2603:10b6:610:4f:cafe::6d) by CH2PR18CA0016.outlook.office365.com (2603:10b6:610:4f::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.11 via Frontend Transport; Mon, 19 Jan 2026 18:01:43 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0000A347.mail.protection.outlook.com (10.167.244.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:02:17 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:02:06 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 08/10] perf sched stats: Add support for diff subcommand Date: Mon, 19 Jan 2026 17:58:30 +0000 Message-ID: <20260119175833.340369-9-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A347:EE_|SA1PR12MB8988:EE_ X-MS-Office365-Filtering-Correlation-Id: c3624696-6068-4c49-b1af-08de5784e209 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sCuDjDUMBbJwoiv1EgM2Nw6NJ+1kuHuJtXPpZAksVICkm2VYfh6TbtvNhu/W?= =?us-ascii?Q?R3xKogvnppVdy0aUVVkNCBCIRaQUVhLcfKT6k4dCClhw2iHc72DQzQ1cOYY6?= =?us-ascii?Q?f62wb8K5UOtk7UEwIoOlLPK5xCvJhCMVZCcYB7NN6A6Pm/cKrfiWPZTHpIKy?= =?us-ascii?Q?iE4I6zRpYgOlYez9Ntw98+vbXwJYCKSegW8YGxuiHjz0BjzqABCRDJDE/kbd?= =?us-ascii?Q?gTQ/cW8qKoEBysfLCAlL4Ie0ytpx11/Woo0kPMVB1Xg2VmdMwPI8i/3U9sVi?= =?us-ascii?Q?mUXo9mVoD0zlG7+2yV9fdxP2p2tJRyzuebLJknPjI6yBMjuh1uiWL9Saj/Ao?= =?us-ascii?Q?1zBsGOjtB1e6Psdp3Vuo97Y8yH5MU9Gjde/rmNaRJB/m5+hSwXMbFo54gfjP?= =?us-ascii?Q?MEeae/KvtYS+49obPjDDB6nDtAbm6LnpLgeQb2Ra7wgNoTPw6eE4jh/oxkXV?= =?us-ascii?Q?Sodelddi3Bl0C721aZNov4mixAFI+iJGQjU88aTiaXMovuktu5UxEc1Isc+g?= =?us-ascii?Q?6mo4sDByHd+deoQcKaRH8Bw1Gifhtot3dCNQyumZ+k5yzjAYrOeFDBzsFlJ3?= =?us-ascii?Q?0itOR4TMliJxA7yZG46HvyljYHGC2J0mtGXaYrKJzXod+Vd3mbugVbcvjHG5?= =?us-ascii?Q?M+NhYKt5S+tgxWNsp3ch39uOVNJJluUVOs36saykPUDcSgsClwqwMtw8v9Ca?= =?us-ascii?Q?tE07T7NDlFvs/o386gqTxSIzat/IMdcPV02ldJP8LTeC8cEEiIxziR/aX7gb?= =?us-ascii?Q?yKax8aftj6ssygc1VCPuS1vxozo83o7dc3Ddzo3dpiBDt4/uaC7/nOufcClb?= =?us-ascii?Q?cQoUPvZRRo6PuNeTOpNPnlJGCZA6PcIcUTWvRx1zYLC3iXUXlorweADLtlyt?= =?us-ascii?Q?PtjAfUBARh66F4dSL0yOMqULVsTR2MmlHexSvmRnGgvfM11IlaUSZfw02lD6?= =?us-ascii?Q?WEP2Xx4RShZAI0Kts+oG3H/Y3MmfFcpFNGo4VWcfZg40/tssGbm5VbEpS6qq?= =?us-ascii?Q?E+U/NHKvI0RdGqONLklOyip5qTuHpW9jWiwY1+zwQQo9OHXuvE2wIbkQ1/CG?= =?us-ascii?Q?QF7yCnYUyrpJ/2KNHslrUnVCKhoHdmclROy/wu0jByTxCl1w6ndSfkS0ey1+?= =?us-ascii?Q?dNlFUOaEWjshVft1lE+PY2eheEX5WwZNR8EpkwPQQdLTNFz8X48fmMwJdVxi?= =?us-ascii?Q?wytgwDlCQS4JffqWP2PpPnMeFvpzh5tcaaWpJMypBgANEaMSSCjupLTBSmk5?= =?us-ascii?Q?2nDkGLCB/5Pcq+Qjg2024qqVH7SiU1rnYaCq2pyAa4aXBx+wyNGi/VkT8ZPh?= =?us-ascii?Q?hhS8yT8WcMvbUVnOfF7/BRH1olusGhieQZZc97am4WI9U3qZYFX2f5Y0+q3u?= =?us-ascii?Q?R8Z9bVhr0EPEw1i9mNdsw9Rmg8RDB3DHuVzAPObFuJKjwQjLZLz/vNuIix4V?= =?us-ascii?Q?eWVWb1tnL+1YUZ8/kzqL0PaKvHeuClR0eJHLpvcS+KrH4a9cyOPySzG2AdCP?= =?us-ascii?Q?DhQ1llpYt9zgXKQRZGFYzWNzL+YRm3hDpCIJeS0xHX/JmHvPHcNFr9l+D33c?= =?us-ascii?Q?tgwiuY59x85hv7cRBx4UIwJOmz5hC0EjzgKtLAuEGDd2sQT2luVMdWXUQiB5?= =?us-ascii?Q?sAaVkyIc6rEUSOKj/ra9OXGBOArhV8lhDFCgXVQbds9JyTXbDtxrEU8ggpHJ?= =?us-ascii?Q?1Ap49A=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:02:17.2232 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3624696-6068-4c49-b1af-08de5784e209 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A347.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8988 Content-Type: text/plain; charset="utf-8" `perf sched stats diff` subcommand will take two perf.data files as an input and it will print the diff between the two perf.data files. The default input to this subcommnd is perf.data.old and perf.data. Example usage: # perf sched stats diff sample1.data sample2.data Description --------------------------------------------------------------------------= -------------------------- DESC -> Description of the field COUNT -> Value of the field PCT_CHANGE -> Percent change with corresponding base va= lue AVG_JIFFIES -> Avg time in jiffies between two consecuti= ve occurrence of event --------------------------------------------------------------------------= -------------------------- Time elapsed (in jiffies) : = 1, 1 --------------------------------------------------------------------------= -------------------------- CPU: --------------------------------------------------------------------------= -------------------------- DESC CO= UNT1 COUNT2 PCT_CHANGE PCT_CHANGE1 PCT_CHANGE2 --------------------------------------------------------------------------= -------------------------- yld_count : = 0, 0 | 0.00% | array_exp : = 0, 0 | 0.00% | sched_count : = 0, 0 | 0.00% | sched_goidle : = 0, 0 | 0.00% | ( 0.00%, 0.00% ) ttwu_count : = 0, 0 | 0.00% | ttwu_local : = 0, 0 | 0.00% | ( 0.00%, 0.00% ) rq_cpu_time : 3= 2565, 33525 | 2.95% | run_delay : = 0, 436 | 0.00% | ( 0.00%, 1.30% ) pcount : = 0, 0 | 0.00% | --------------------------------------------------------------------------= -------------------------- CPU: | DOMAIN: SMT --------------------------------------------------------------------------= -------------------------- DESC CO= UNT1 COUNT2 PCT_CHANGE AVG_JIFFIES1 AVG_JIFFIES2 ----------------------------------------- ----------------= -------------------------- busy_lb_count : = 0, 0 | 0.00% | $ 0.00, 0.00 $ busy_lb_balanced : = 0, 0 | 0.00% | $ 0.00, 0.00 $ busy_lb_failed : = 0, 0 | 0.00% | $ 0.00, 0.00 $ busy_lb_imbalance_load : = 0, 0 | 0.00% | busy_lb_imbalance_util : = 0, 0 | 0.00% | busy_lb_imbalance_task : = 0, 0 | 0.00% | busy_lb_imbalance_misfit : = 0, 0 | 0.00% | busy_lb_gained : = 0, 0 | 0.00% | busy_lb_hot_gained : = 0, 0 | 0.00% | busy_lb_nobusyq : = 0, 0 | 0.00% | $ 0.00, 0.00 $ busy_lb_nobusyg : = 0, 0 | 0.00% | $ 0.00, 0.00 $ *busy_lb_success_count : = 0, 0 | 0.00% | *busy_lb_avg_pulled : = 0.00, 0.00 | 0.00% | ... and so on. Output contains the diff of aggregated data of all the busy, idle and newidle categories for all the sched domains in the system. Signed-off-by: Ravi Bangoria Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/perf/builtin-sched.c | 316 ++++++++++++++++++++++++++++++------- 1 file changed, 260 insertions(+), 56 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 8993308439bc..01e6cb6a2fbc 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3985,29 +3985,46 @@ static void store_schedstat_domain_diff(struct sche= dstat_domain *after_workload) #undef DOMAIN_FIELD } =20 -static inline void print_cpu_stats(struct perf_record_schedstat_cpu *cs) +#define PCT_CHNG(_x, _y) ((_x) ? ((double)((double)(_y) - (_x)) / (= _x)) * 100 : 0.0) +static inline void print_cpu_stats(struct perf_record_schedstat_cpu *cs1, + struct perf_record_schedstat_cpu *cs2) { - printf("%-65s %12s %12s\n", "DESC", "COUNT", "PCT_CHANGE"); - printf("%.*s\n", 100, graph_dotted_line); + printf("%-65s ", "DESC"); + if (!cs2) + printf("%12s %12s", "COUNT", "PCT_CHANGE"); + else + printf("%12s %11s %12s %14s %10s", "COUNT1", "COUNT2", "PCT_CHANGE", + "PCT_CHANGE1", "PCT_CHANGE2"); + + printf("\n"); + print_separator2(100, "", 0); =20 #define CALC_PCT(_x, _y) ((_y) ? ((double)(_x) / (_y)) * 100 : 0.0) =20 -#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ - do { \ - printf("%-65s: " _format, verbose_field ? _desc : #_name, \ - cs->_ver._name); \ - if (_is_pct) { \ - printf(" ( %8.2lf%% )", \ - CALC_PCT(cs->_ver._name, cs->_ver._pct_of)); \ - } \ - printf("\n"); \ +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ + do { \ + printf("%-65s: " _format, verbose_field ? _desc : #_name, \ + cs1->_ver._name); \ + if (!cs2) { \ + if (_is_pct) \ + printf(" ( %8.2lf%% )", \ + CALC_PCT(cs1->_ver._name, cs1->_ver._pct_of)); \ + } else { \ + printf("," _format " | %8.2lf%% |", cs2->_ver._name, \ + PCT_CHNG(cs1->_ver._name, cs2->_ver._name)); \ + if (_is_pct) \ + printf(" ( %8.2lf%%, %8.2lf%% )", \ + CALC_PCT(cs1->_ver._name, cs1->_ver._pct_of), \ + CALC_PCT(cs2->_ver._name, cs2->_ver._pct_of)); \ + } \ + printf("\n"); \ } while (0) =20 - if (cs->version =3D=3D 15) { + if (cs1->version =3D=3D 15) { #include - } else if (cs->version =3D=3D 16) { + } else if (cs1->version =3D=3D 16) { #include - } else if (cs->version =3D=3D 17) { + } else if (cs1->version =3D=3D 17) { #include } =20 @@ -4015,10 +4032,17 @@ static inline void print_cpu_stats(struct perf_reco= rd_schedstat_cpu *cs) #undef CALC_PCT } =20 -static inline void print_domain_stats(struct perf_record_schedstat_domain = *ds, - __u64 jiffies) +static inline void print_domain_stats(struct perf_record_schedstat_domain = *ds1, + struct perf_record_schedstat_domain *ds2, + __u64 jiffies1, __u64 jiffies2) { - printf("%-65s %12s %14s\n", "DESC", "COUNT", "AVG_JIFFIES"); + printf("%-65s ", "DESC"); + if (!ds2) + printf("%12s %14s", "COUNT", "AVG_JIFFIES"); + else + printf("%12s %11s %12s %16s %12s", "COUNT1", "COUNT2", "PCT_CHANGE", + "AVG_JIFFIES1", "AVG_JIFFIES2"); + printf("\n"); =20 #define DOMAIN_CATEGORY(_desc) \ do { \ @@ -4033,28 +4057,54 @@ static inline void print_domain_stats(struct perf_r= ecord_schedstat_domain *ds, #define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ do { \ printf("%-65s: " _format, verbose_field ? _desc : #_name, \ - ds->_ver._name); \ - if (_is_jiffies) { \ - printf(" $ %11.2Lf $", \ - CALC_AVG(jiffies, ds->_ver._name)); \ + ds1->_ver._name); \ + if (!ds2) { \ + if (_is_jiffies) \ + printf(" $ %11.2Lf $", \ + CALC_AVG(jiffies1, ds1->_ver._name)); \ + } else { \ + printf("," _format " | %8.2lf%% |", ds2->_ver._name, \ + PCT_CHNG(ds1->_ver._name, ds2->_ver._name)); \ + if (_is_jiffies) \ + printf(" $ %11.2Lf, %11.2Lf $", \ + CALC_AVG(jiffies1, ds1->_ver._name), \ + CALC_AVG(jiffies2, ds2->_ver._name)); \ } \ printf("\n"); \ } while (0) =20 #define DERIVED_CNT_FIELD(_name, _desc, _format, _x, _y, _z, _ver) \ - printf("*%-64s: " _format "\n", verbose_field ? _desc : #_name, \ - (ds->_ver._x) - (ds->_ver._y) - (ds->_ver._z)) + do { \ + __u32 t1 =3D ds1->_ver._x - ds1->_ver._y - ds1->_ver._z; \ + printf("*%-64s: " _format, verbose_field ? _desc : #_name, t1); \ + if (ds2) { \ + __u32 t2 =3D ds2->_ver._x - ds2->_ver._y - ds2->_ver._z; \ + printf("," _format " | %8.2lf%% |", t2, \ + PCT_CHNG(t1, t2)); \ + } \ + printf("\n"); \ + } while (0) =20 #define DERIVED_AVG_FIELD(_name, _desc, _format, _x, _y, _z, _w, _ver) \ - printf("*%-64s: " _format "\n", verbose_field ? _desc : #_name, \ - CALC_AVG(ds->_ver._w, \ - ((ds->_ver._x) - (ds->_ver._y) - (ds->_ver._z)))) + do { \ + __u32 t1 =3D ds1->_ver._x - ds1->_ver._y - ds1->_ver._z; \ + printf("*%-64s: " _format, verbose_field ? _desc : #_name, \ + CALC_AVG(ds1->_ver._w, t1)); \ + if (ds2) { \ + __u32 t2 =3D ds2->_ver._x - ds2->_ver._y - ds2->_ver._z; \ + printf("," _format " | %8.2Lf%% |", \ + CALC_AVG(ds2->_ver._w, t2), \ + PCT_CHNG(CALC_AVG(ds1->_ver._w, t1), \ + CALC_AVG(ds2->_ver._w, t2))); \ + } \ + printf("\n"); \ + } while (0) =20 - if (ds->version =3D=3D 15) { + if (ds1->version =3D=3D 15) { #include - } else if (ds->version =3D=3D 16) { + } else if (ds1->version =3D=3D 16) { #include - } else if (ds->version =3D=3D 17) { + } else if (ds1->version =3D=3D 17) { #include } =20 @@ -4064,6 +4114,7 @@ static inline void print_domain_stats(struct perf_rec= ord_schedstat_domain *ds, #undef CALC_AVG #undef DOMAIN_CATEGORY } +#undef PCT_CHNG =20 static void summarize_schedstat_cpu(struct schedstat_cpu *summary_cpu, struct schedstat_cpu *cptr, @@ -4173,13 +4224,16 @@ static int get_all_cpu_stats(struct list_head *head) return ret; } =20 -static int show_schedstat_data(struct list_head *head, struct cpu_domain_m= ap **cd_map) +static int show_schedstat_data(struct list_head *head1, struct cpu_domain_= map **cd_map1, + struct list_head *head2, struct cpu_domain_map **cd_map2, + bool summary_only) { - struct schedstat_cpu *cptr =3D list_first_entry(head, struct schedstat_cp= u, cpu_list); - __u64 jiffies =3D cptr->cpu_data->timestamp; - struct perf_record_schedstat_domain *ds; - struct perf_record_schedstat_cpu *cs; - struct schedstat_domain *dptr; + struct schedstat_cpu *cptr1 =3D list_first_entry(head1, struct schedstat_= cpu, cpu_list); + struct perf_record_schedstat_domain *ds1 =3D NULL, *ds2 =3D NULL; + struct perf_record_schedstat_cpu *cs1 =3D NULL, *cs2 =3D NULL; + struct schedstat_domain *dptr1 =3D NULL, *dptr2 =3D NULL; + struct schedstat_cpu *cptr2 =3D NULL; + __u64 jiffies1 =3D 0, jiffies2 =3D 0; bool is_summary =3D true; int ret =3D 0; =20 @@ -4194,49 +4248,100 @@ static int show_schedstat_data(struct list_head *h= ead, struct cpu_domain_map **c print_separator2(100, "", 0); printf("\n"); =20 - printf("%-65s: %11llu\n", "Time elapsed (in jiffies)", jiffies); + printf("%-65s: ", "Time elapsed (in jiffies)"); + jiffies1 =3D cptr1->cpu_data->timestamp; + printf("%11llu", jiffies1); + if (head2) { + cptr2 =3D list_first_entry(head2, struct schedstat_cpu, cpu_list); + jiffies2 =3D cptr2->cpu_data->timestamp; + printf(",%11llu", jiffies2); + } + printf("\n"); + + ret =3D get_all_cpu_stats(head1); + if (cptr2) { + ret =3D get_all_cpu_stats(head2); + cptr2 =3D list_first_entry(head2, struct schedstat_cpu, cpu_list); + } =20 - ret =3D get_all_cpu_stats(head); + list_for_each_entry(cptr1, head1, cpu_list) { + struct cpu_domain_map *cd_info1 =3D NULL, *cd_info2 =3D NULL; + + cs1 =3D cptr1->cpu_data; + cd_info1 =3D cd_map1[cs1->cpu]; + if (cptr2) { + cs2 =3D cptr2->cpu_data; + cd_info2 =3D cd_map2[cs2->cpu]; + dptr2 =3D list_first_entry(&cptr2->domain_head, struct schedstat_domain, + domain_list); + } + + if (cs2 && cs1->cpu !=3D cs2->cpu) { + pr_err("Failed because matching cpus not found for diff\n"); + return -1; + } + + if (cd_info2 && cd_info1->nr_domains !=3D cd_info2->nr_domains) { + pr_err("Failed because nr_domains is not same for cpus\n"); + return -1; + } =20 - list_for_each_entry(cptr, head, cpu_list) { - cs =3D cptr->cpu_data; print_separator2(100, "", 0); =20 if (is_summary) printf("CPU: \n"); else - printf("CPU: %d\n", cs->cpu); + printf("CPU: %d\n", cs1->cpu); =20 print_separator2(100, "", 0); - print_cpu_stats(cs); + print_cpu_stats(cs1, cs2); print_separator2(100, "", 0); =20 - list_for_each_entry(dptr, &cptr->domain_head, domain_list) { - struct domain_info *dinfo; + list_for_each_entry(dptr1, &cptr1->domain_head, domain_list) { + struct domain_info *dinfo1 =3D NULL, *dinfo2 =3D NULL; + + ds1 =3D dptr1->domain_data; + dinfo1 =3D cd_info1->domains[ds1->domain]; + if (dptr2) { + ds2 =3D dptr2->domain_data; + dinfo2 =3D cd_info2->domains[ds2->domain]; + } + + if (dinfo2 && dinfo1->domain !=3D dinfo2->domain) { + pr_err("Failed because matching domain not found for diff\n"); + return -1; + } =20 - ds =3D dptr->domain_data; - dinfo =3D cd_map[ds->cpu]->domains[ds->domain]; if (is_summary) { - if (dinfo->dname) + if (dinfo1->dname) printf("CPU: | DOMAIN: %s\n", - dinfo->dname); + dinfo1->dname); else printf("CPU: | DOMAIN: %d\n", - dinfo->domain); + dinfo1->domain); } else { - if (dinfo->dname) + if (dinfo1->dname) printf("CPU: %d | DOMAIN: %s | DOMAIN_CPUS: ", - cs->cpu, dinfo->dname); + cs1->cpu, dinfo1->dname); else printf("CPU: %d | DOMAIN: %d | DOMAIN_CPUS: ", - cs->cpu, dinfo->domain); + cs1->cpu, dinfo1->domain); =20 - printf("%s\n", dinfo->cpulist); + printf("%s\n", dinfo1->cpulist); } print_separator2(100, "", 0); - print_domain_stats(ds, jiffies); + print_domain_stats(ds1, ds2, jiffies1, jiffies2); print_separator2(100, "", 0); + + if (dptr2) + dptr2 =3D list_next_entry(dptr2, domain_list); } + if (summary_only) + break; + + if (cptr2) + cptr2 =3D list_next_entry(cptr2, cpu_list); + is_summary =3D false; } return ret; @@ -4417,7 +4522,7 @@ static int perf_sched__schedstat_report(struct perf_s= ched *sched) } =20 cd_map =3D session->header.env.cpu_domain; - err =3D show_schedstat_data(&cpu_head, cd_map); + err =3D show_schedstat_data(&cpu_head, cd_map, NULL, NULL, false); } =20 out: @@ -4426,6 +4531,100 @@ static int perf_sched__schedstat_report(struct perf= _sched *sched) return err; } =20 +static int perf_sched__schedstat_diff(struct perf_sched *sched, + int argc, const char **argv) +{ + struct cpu_domain_map **cd_map0 =3D NULL, **cd_map1 =3D NULL; + struct list_head cpu_head_ses0, cpu_head_ses1; + struct perf_session *session[2]; + struct perf_data data[2]; + int ret =3D 0, err =3D 0; + static const char *defaults[] =3D { + "perf.data.old", + "perf.data", + }; + + if (argc) { + if (argc =3D=3D 1) + defaults[1] =3D argv[0]; + else if (argc =3D=3D 2) { + defaults[0] =3D argv[0]; + defaults[1] =3D argv[1]; + } else { + pr_err("perf sched stats diff is not supported with more than 2 files.\= n"); + goto out_ret; + } + } + + INIT_LIST_HEAD(&cpu_head_ses0); + INIT_LIST_HEAD(&cpu_head_ses1); + + sched->tool.schedstat_cpu =3D perf_sched__process_schedstat; + sched->tool.schedstat_domain =3D perf_sched__process_schedstat; + + data[0].path =3D defaults[0]; + data[0].mode =3D PERF_DATA_MODE_READ; + session[0] =3D perf_session__new(&data[0], &sched->tool); + if (IS_ERR(session[0])) { + ret =3D PTR_ERR(session[0]); + pr_err("Failed to open %s\n", data[0].path); + goto out_delete_ses0; + } + + err =3D perf_session__process_events(session[0]); + if (err) + goto out_delete_ses0; + + cd_map0 =3D session[0]->header.env.cpu_domain; + list_replace_init(&cpu_head, &cpu_head_ses0); + after_workload_flag =3D false; + + data[1].path =3D defaults[1]; + data[1].mode =3D PERF_DATA_MODE_READ; + session[1] =3D perf_session__new(&data[1], &sched->tool); + if (IS_ERR(session[1])) { + ret =3D PTR_ERR(session[1]); + pr_err("Failed to open %s\n", data[1].path); + goto out_delete_ses1; + } + + err =3D perf_session__process_events(session[1]); + if (err) + goto out_delete_ses1; + + cd_map1 =3D session[1]->header.env.cpu_domain; + list_replace_init(&cpu_head, &cpu_head_ses1); + after_workload_flag =3D false; + setup_pager(); + + if (list_empty(&cpu_head_ses1)) { + pr_err("Data is not available\n"); + ret =3D -1; + goto out_delete_ses1; + } + + if (list_empty(&cpu_head_ses0)) { + pr_err("Data is not available\n"); + ret =3D -1; + goto out_delete_ses0; + } + + show_schedstat_data(&cpu_head_ses0, cd_map0, &cpu_head_ses1, cd_map1, tru= e); + +out_delete_ses1: + free_schedstat(&cpu_head_ses1); + if (!IS_ERR(session[1])) + perf_session__delete(session[1]); + +out_delete_ses0: + free_schedstat(&cpu_head_ses0); + if (!IS_ERR(session[0])) + perf_session__delete(session[0]); + +out_ret: + return ret; +} + static int process_synthesized_event_live(const struct perf_tool *tool __m= aybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, @@ -4515,7 +4714,7 @@ static int perf_sched__schedstat_live(struct perf_sch= ed *sched, =20 nr =3D cpu__max_present_cpu().cpu; cd_map =3D build_cpu_domain_map(&sv, &md, nr); - show_schedstat_data(&cpu_head, cd_map); + show_schedstat_data(&cpu_head, cd_map, NULL, NULL, false); out: free_cpu_domain_info(cd_map, sv, nr); free_schedstat(&cpu_head); @@ -4847,6 +5046,11 @@ int cmd_sched(int argc, const char **argv) argc =3D parse_options(argc, argv, stats_options, stats_usage, 0); return perf_sched__schedstat_report(&sched); + } else if (argv[0] && !strcmp(argv[0], "diff")) { + if (argc) + argc =3D parse_options(argc, argv, stats_options, + stats_usage, 0); + return perf_sched__schedstat_diff(&sched, argc, argv); } return perf_sched__schedstat_live(&sched, argc, argv); } else { --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011000.outbound.protection.outlook.com [40.93.194.0]) (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 326373128BE; Mon, 19 Jan 2026 18:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.0 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845768; cv=fail; b=W7Is0qc2KGZTpEeNiKfxy92wP8//JaBs0HQZnx8mDxgMfuVUxncdbKlteKV4J3b0AtivKbskUwa/TpS6uIQgdlFSt3GFBaW9Kex+lYEu38MXvdlqio7h1ZJLAz8UdqoNB45eEk5a9jyoIqpr4o5lLLlQtWKco8sKuNddcEi0DdE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845768; c=relaxed/simple; bh=EfcLY3NDp1lMvkV1Jfb+289V3teDCdYSigVXRWpSN7g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KwCdaNLc6E8kikRORXgSG66Yq6FkGuLKoDyjO8lcLC+dqP8g17+GDVtsq/Rt9DwezGFviAbWnXlIQ1Gx+4J9ZokrT1pQQ6T7heXhqS9uZW5H08Hgrv18Y32wA7pVzQssWOtJaIOgoYU0lvvWTeTnMUHfqQSlkuBRHBf78/7AWsk= 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=IE9AF3Yx; arc=fail smtp.client-ip=40.93.194.0 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="IE9AF3Yx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=v1BhkxVFwUA+aRJReAhW9Xr/6TF0awiNsgaSqPE+VStpTlA5oY5QAeuGBKdrDDuYdF1WXkLf3Yrm0aC3Z4ctr/iJyK+9OPlD5RlKqoGBfTLTFmUCGSIti64lIbvvdJd3oqHt76/PmHE84YdwShZdsb5haDWulUn6AGo4ElXBtBNdK+cNVLdnA2M9NEEpEBkQvEJ3knecdg/qWZ2/EeYK8Xu5gjA60OGzvcVbjqrGiKQtF66qP5fzOyStwaC5ru0BxkZetxLQm+Y83Kb9EbFrPEKO4qoGtuDKVN1YsEPGijqTs4STUtkd6aKJNffUWnCO+hRRcnP34ZhoXs4xGZyqlw== 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=ZSWJRxFUSRR/75Ge00v7x+d4eXsR1bungyJ55lp1BIU=; b=hX/ULZ2YNaNFbvPPNwiwupBxaiM2jd49dDcAlg8E7LiMiTSMjR+Vvr0VMeQjJPw4wGitDduX3/MH1wOh9Wh8dNjkjFP/5lK+A8NhMPBM9iU98ghftCfoiZ1jE2HaJerQRh7SvFpFYAtFoQ8h5+upkW9E4IVLmzdchiNX4YjE/KqfkFONhf24XXoFuwlZDm5iN4xmN3cnfhtqi31JU7MPAYOp0ldG0tAKAMQdB5JjrSLt1TUiMLfxfm5CN19kRxvsJa+bO2UFsxdWsdAfTyPba0y07+jYoWHyLgNS/dxoRDcgQBR3LD6Y3/zPQC3m46Bk9qKKBpXXzNlRvE0nrL61Wg== 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=ZSWJRxFUSRR/75Ge00v7x+d4eXsR1bungyJ55lp1BIU=; b=IE9AF3Yxy1Fme8kgy+vSTjLlNUeIzOE+Vr3mx4ByAjUIgIpx204Ip94fp7T3e2x8JDZZ5Sauj+esJ750i8s20CT7v1po2CDPoWjc4qNlv2js5hAod+npLZLphwNTHdl7Nje2rsBXJ5vlUyZqe2QibHwvR8afjjBV58wy4u8uJ3s= Received: from CH2PR12CA0029.namprd12.prod.outlook.com (2603:10b6:610:57::39) by SA5PPFA403A61D8.namprd12.prod.outlook.com (2603:10b6:80f:fc04::8da) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.12; Mon, 19 Jan 2026 18:02:41 +0000 Received: from CH1PEPF0000A34A.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::81) by CH2PR12CA0029.outlook.office365.com (2603:10b6:610:57::39) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.12 via Frontend Transport; Mon, 19 Jan 2026 18:02:42 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0000A34A.mail.protection.outlook.com (10.167.244.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:02:40 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:02:29 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 09/10] perf sched stats: Add basic perf sched stats test Date: Mon, 19 Jan 2026 17:58:31 +0000 Message-ID: <20260119175833.340369-10-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A34A:EE_|SA5PPFA403A61D8:EE_ X-MS-Office365-Filtering-Correlation-Id: a6a496af-2f1e-48c4-5f5e-08de5784efb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?xaG2bmwWQm5rCaLKDcDiXqfNSxK9x7G5ENHP8w2D2oAJ/HRrwaNnEoUiA1F5?= =?us-ascii?Q?+4/2zKmSF7GpZT9J4kl1u4chK0hZrQeh569pFkXsM8QoKWcxS2lP8+fKymHz?= =?us-ascii?Q?8R/whj7S70pJRO+MWKVREBcRD9rzAl2svSs8GMjDiM5baAHgzLqgrgM6JyHG?= =?us-ascii?Q?RW/MaMULPzMwrH/AapblglACsPmXiQmB8vgXud+acU7tijn36hJCR9U5nH3x?= =?us-ascii?Q?2lH+Ez1m6aLnvqTQjVXjSPtx/J3A/1k66peXcEywxqVe07Lz9T635Ed/coCA?= =?us-ascii?Q?8Ss6OYchZDJahyVKubi76Ch1dHjWJFCDJmhtEDjLDSPm+z06oTmgEtO6gF9F?= =?us-ascii?Q?lfGYi8o3+GvdzerJg+NRAbbiLQvfaVcheZYdj/KysT034qPlkgzZekC47NWA?= =?us-ascii?Q?BgfZ5i0GuVzS/iQFW9V5NyBszDyhzZh3fj1zcOtdm1GrVZL1yIqR3AYZ+kXp?= =?us-ascii?Q?RGMmNNxb4/Amg6Mn6rCVLRrKvaXeQ6QEatitH2u2OPMH4L16scIQrwVkRUus?= =?us-ascii?Q?TUsIR+qVGlIt98DKtocZ3na537D+3wQD9ZC/iAllONt0n0o9ih+Uvv0Z4ANO?= =?us-ascii?Q?ZzsfgNTinTUwMK4VDzKMFnlMtFCP+2dz01V6m7y/w5zIPHeZWzj7SsRt69Q3?= =?us-ascii?Q?brlo2/2yXm5tHwM7G+kVPNVxZNsjPq/C+pre4bXvCwxav6JII+g/juXXG+WK?= =?us-ascii?Q?zsCJ+4a18sNOqxvaCaJGut7klKPdH2JJlCWbfz8rpxaq1yvIZqa23yJ+m3bk?= =?us-ascii?Q?3jRUrU6OdtYj0KzP3lA/6f5mTnvhSR/JmGtS4lz2koNqUHMybBKC7ofZKEdT?= =?us-ascii?Q?O7blPEOtB8HPAcGC2Yrw7tFBT9mw4SmMbuGuHgmo75BWaUGS0tJaKOr9xHSC?= =?us-ascii?Q?PgyiHtQskouorkZyUWwArlmKBqpGtyoTPJv9BzRVf4DKH28CG2gJKF1V9qck?= =?us-ascii?Q?PR+g6vPRMjSU+sByC936KuYOoAE7Th5GG/bSYvn8nmJCembpcZt9kvBqWNe5?= =?us-ascii?Q?VZVZXLDN2/sQtfZPW1uq4mDLSavmXVWlV2chOlI2hVl4p/U3QmQEkKhgPyWh?= =?us-ascii?Q?sq+KAONIn9SpM3nz+JuR7dnx2erU25HDUUWPWdFbmmtJ48Tjqb+hQ924F2/c?= =?us-ascii?Q?xVtdldEHkXQ0lhl7RcwjFCKybXunOD3QKOxrb8qyt3D+fZ1H1wX9V6OGcp5G?= =?us-ascii?Q?sSSO2CgNEkNaqNPHkeqT6VeOaddxXRXBbMXfVaAUolHBYtS5Csr6r4XyDKQL?= =?us-ascii?Q?DF2tIA56O+U47efYLVE68TsKV2SXuBm4HmrWCacv6r6Z+fMw0Oo1EVstVC8m?= =?us-ascii?Q?orC2zsPpTyJI8kuJ150Bi2VVrS18Aopu8ETXU1KLrHXJcrRy8tR70+MqzFtC?= =?us-ascii?Q?Bxe1Kj0Oecsbq4WmOXYhmSdz5yEkEanbQLE9S486lEGgQVXqqMAAiFH3RFFD?= =?us-ascii?Q?KNKavzJikXXYlLIdFBAB5C21WLGRv+SNL6Kore0lQ/UCVW9NCzqg9tcsDGke?= =?us-ascii?Q?801oa3x7DkBbreP7WqrAOtoIaNQzp2rVsSJoojwiSaMcLEbIZmscSqAl3WVn?= =?us-ascii?Q?EBP3aJj9wPbabkZ6pGsoVLJDlhI8Br/qIyAegmzViTPrcgzSGqn+nyrZynxE?= =?us-ascii?Q?jw4JFc2Cxv+gb/gWGNRaNCMyLrYKFQG7KQlfpcbbCPhJbnndU8ecuiRIxs9y?= =?us-ascii?Q?bQQNmA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:02:40.1483 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6a496af-2f1e-48c4-5f5e-08de5784efb1 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A34A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA5PPFA403A61D8 Content-Type: text/plain; charset="utf-8" Add basic test for perf sched stats {record|report|diff} subcommand. Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/perf/tests/shell/perf_sched_stats.sh | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 tools/perf/tests/shell/perf_sched_stats.sh diff --git a/tools/perf/tests/shell/perf_sched_stats.sh b/tools/perf/tests/= shell/perf_sched_stats.sh new file mode 100755 index 000000000000..2b1410b050d0 --- /dev/null +++ b/tools/perf/tests/shell/perf_sched_stats.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# perf sched stats tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +err=3D0 +test_perf_sched_stats_record() { + echo "Basic perf sched stats record test" + if ! perf sched stats record true 2>&1 | \ + grep -E -q "[ perf sched stats: Wrote samples to perf.data ]" + then + echo "Basic perf sched stats record test [Failed]" + err=3D1 + return + fi + echo "Basic perf sched stats record test [Success]" +} + +test_perf_sched_stats_report() { + echo "Basic perf sched stats report test" + perf sched stats record true > /dev/null + if ! perf sched stats report 2>&1 | grep -E -q "Description" + then + echo "Basic perf sched stats report test [Failed]" + err=3D1 + rm perf.data + return + fi + rm perf.data + echo "Basic perf sched stats report test [Success]" +} + +test_perf_sched_stats_live() { + echo "Basic perf sched stats live mode test" + if ! perf sched stats true 2>&1 | grep -E -q "Description" + then + echo "Basic perf sched stats live mode test [Failed]" + err=3D1 + return + fi + echo "Basic perf sched stats live mode test [Success]" +} + +test_perf_sched_stats_diff() { + echo "Basic perf sched stats diff test" + perf sched stats record true > /dev/null + perf sched stats record true > /dev/null + if ! perf sched stats diff > /dev/null + then + echo "Basic perf sched stats diff test [Failed]" + err=3D1 + rm perf.data.old perf.data + return + fi + rm perf.data.old perf.data + echo "Basic perf sched stats diff test [Success]" +} + +test_perf_sched_stats_record +test_perf_sched_stats_report +test_perf_sched_stats_live +test_perf_sched_stats_diff +exit $err --=20 2.43.0 From nobody Sun Feb 8 13:27:39 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012022.outbound.protection.outlook.com [40.93.195.22]) (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 D11703128BE; Mon, 19 Jan 2026 18:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.22 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845793; cv=fail; b=F1paWwwgkXKoaT8LPmKnVezjcfIdk4ibWpABpCON/nxNxbahIGfvlsn6xfiWyl9k4OGB5sL9UAPdKXd48lNyCzCyYoVqK5HwT3GO8NLDWLRZ5cU5okGHXt5npwCNPqfPfb4iqqk2LXvnDPGcR2hjVzQF9/GndMH/UgoxYqHfoTw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845793; c=relaxed/simple; bh=gqAZxoZKLiec3qn/670jAHkQUcHad5CAYPsvx7cZ5xo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hYQ6+mziXTHCy7AH3xeEaDfEnrQZ7v7DGtZ0T+HAkuTVR6M9aWVffUlMsj1IvGiVQS9i+t55SBDej4zmM20YO3WonyyHTme6GRsWRfNKoXs1bxbJyNTL4GeY152zrH7P3CYpm22qzHNHLbUAmK44Zt7djdXVttaz1KaBtHE9sdw= 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=1narVjxx; arc=fail smtp.client-ip=40.93.195.22 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="1narVjxx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=br6nCUFWYV773PEQXLLXpx6+YOHd0VySXoiW1Q9pEPy6jdU0nKL1GTcJpbR9vNiGHRfoULJczoWu3mAnmco1x4jfw+jOfZRKx0BHMW4GQCKcvuG3FGpmkGrgjG39QPMvr2ZCu7P8WLDFFy3gjWhzgOe04SeVHPlNk8xsPbXkcuBjgwHqJkHoaqipdiJKT4m9fVhqIuXwXcnFPYWWbrUAUHKxVH08est0VV9mOi2JSUH/m7AlBa3U2VgxXaxZf8pszOkeMgfbpK27BgVdP38ZwfuexLfqmLc88Fru5c1HRyTx8D+WTaG4Rft112d3OTKEO2n5exg9SufJfX8maDHHmw== 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=TR5lwR7ocSYg9xggvlfqb4UMGVkz4dpo1j/gcmPJlg0=; b=lq9JuhL5KlmqY6R5IsDhX6C8LRBRpH/wmCH+B8+tQ3Qg5q0z9XI2p5flzZ9eHpDlBu/SAH+O7MKG+hPNMTQfKID+PykARXtTNyPQ7c2RhEgc5E2rTiP+1EkYNkVvZIfTdoFJgO1QUwjwQ6r9Jz7+n7q+XQfTSw6/oMLdZeDraAWf5vaoCT2MFqX6phF5prQL1f5XaWj+TvmhlrnFyQxAluf7h0GdroILVFOtoo2oAP3oxrGtQwf8oh7VaehF6Q7NTe8BhSk8e6O0eUs00jQbkeOPMroKfB41Cwir6khESvlilO8mFf14w8hPajTO5kgoi4Hbh0OTb9NreqBRkcyphg== 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=TR5lwR7ocSYg9xggvlfqb4UMGVkz4dpo1j/gcmPJlg0=; b=1narVjxx68IIiXduoz03CO8WsLnRr88rCGwJthkE8H8fsk8agMz10soyBeecA2NeZhJ7GiIaSCuiXblmpxkM7GYUip5df5m4gKlFLHQcE4SeWJxR+MhH148NBslHqy9Nl3TI7y0FKMJCycgoGZhvXJPiv8J1jc2dN/FJ4q4ZF/0= Received: from CH2PR12CA0024.namprd12.prod.outlook.com (2603:10b6:610:57::34) by PH8PR12MB6844.namprd12.prod.outlook.com (2603:10b6:510:1cb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.10; Mon, 19 Jan 2026 18:03:04 +0000 Received: from CH1PEPF0000A34A.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::62) by CH2PR12CA0024.outlook.office365.com (2603:10b6:610:57::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.12 via Frontend Transport; Mon, 19 Jan 2026 18:03: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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0000A34A.mail.protection.outlook.com (10.167.244.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Mon, 19 Jan 2026 18:03:03 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 19 Jan 2026 12:02:52 -0600 From: Swapnil Sapkal To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 10/10] perf sched stats: Add details in man page Date: Mon, 19 Jan 2026 17:58:32 +0000 Message-ID: <20260119175833.340369-11-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119175833.340369-1-swapnil.sapkal@amd.com> References: <20260119175833.340369-1-swapnil.sapkal@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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A34A:EE_|PH8PR12MB6844:EE_ X-MS-Office365-Filtering-Correlation-Id: 2503640c-7e8e-48e4-99bc-08de5784fd5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?U52Oub0+8a5gfbDYLFfsHBGx9TKaLjhDtCfnCcgyTQDMb6JhmA2I/VYj6lt0?= =?us-ascii?Q?Io1G2qxiz1+UrSBlKvN7L6H23JbB8H6Sh4eb/80vbfaNfMZIq0L1+s74aQS5?= =?us-ascii?Q?lhgUEMQKMAfh1IXkwdgg7w1BhA2/BzwF0c9nEGk4zM74k6GB//ilKZ2ZtXiH?= =?us-ascii?Q?mf+4SJfL86wYlMrslr4tLB70UfhK/36ng14iApQCUJ2/59Hn/2kqsXCzxOAC?= =?us-ascii?Q?2Qkcmm/VD7Waz37n+V9YiLO+TI968Mq1fu+uA4Mpc3ifwRc7p+uJc8ulX0fj?= =?us-ascii?Q?biv55aDlZt/s2LwvIie1mA9D5gLMBt53tgPc/TKpmLlCTFJEvduyuHGD5qQm?= =?us-ascii?Q?e4Wh0F6LPThrZZ0LsWZNNbgOdPrKCUIoAQWmBSXPQD7Sk3597SoSVyc6lCIT?= =?us-ascii?Q?gKZntqEbrlZptSxSzPg3rINnq2HmaG6lhEzRf7wwVc4drXbr/HcCfPbnTA8S?= =?us-ascii?Q?9b7rpWtH88YMqfq0AWXC8l9Ej7+sqjfDsTceknvdsiZhH4k9zvWWTlgPGYPT?= =?us-ascii?Q?tsT0uhvpu8HA0S92iv+1YxaUFzwH9voOeW0FbNPn+YTe404QuH/NrED8MHy2?= =?us-ascii?Q?z2YrWerdoNAs5DxEpM7szztIGxJyb1pdrzCvjD5juCYDJivO6oeDOhK/EQRH?= =?us-ascii?Q?Vf6IRMHaqiEkEdHoVAecZpg2WPHanqqAFTKDfHx+xb781JWpM9/Tc9Irvv+H?= =?us-ascii?Q?2Px3Bows6aIYml27tEW1fVRVLXdUdX7eLXyobnIDxnR7ywZ6NNzYsx1HdJ1y?= =?us-ascii?Q?DCqPyG522Pi2zdD+uKYNUfFvtGiY+OUGDwSLDa3QDsriAa5pDqxC6nL1Qxxb?= =?us-ascii?Q?j7++JiTwPYREJARZmKDdfU134RB94ODpV93L6akraeSnvTjyYS/wXGR8iX49?= =?us-ascii?Q?LgShlMwTRo9W9kTYpZEaq2l49F9ICvgCIBLfxhz3mtzJtdwNPAgF+nKQli33?= =?us-ascii?Q?qXjeSJh1tG4nJNI5BzdlLy7m/MV5v31JhaqoyZ+h8cusYu+mPQ2Lom0nnBA3?= =?us-ascii?Q?IA7oyKnRkUcvgGW3lnl0M78qav8jcHcSis174QO6b/4Pff2pVgx1z6Dvm5DC?= =?us-ascii?Q?0bImqU8h9WusWq/L5q/5eNBHAEVNO4MKMnWzZXyDhokFjwqeUXi9KaNe08Yu?= =?us-ascii?Q?9hDJo+8bYP9rk4SkEHrI/LF3HiRhyPPcNfB6x+lTV8sZpcTPN+Qu+ONHZ6c7?= =?us-ascii?Q?kqyB2wup7N3dG4PfZBlkY49SfuFB+uojkUdaL4fUSGEn4An5S/6AKv57iXfc?= =?us-ascii?Q?Lo2HMFl6D3azvY1jDHY5qdfQ/rogFFQ66ybHGtiUpFO8dHqzM1sJD3nvIOtj?= =?us-ascii?Q?iHnhJ5Rx72f3zJ9HJjQdiRnyeeDKRBtzq7ioHU/0UGQZc+I0s54K+C5gX4Gx?= =?us-ascii?Q?g6qGQAUp7dOHdD3Rv/5EJ6JOSx61tQvyfTXMigs1t9JyHwcAYkn7O/QVk7ZH?= =?us-ascii?Q?gBNors2uwb1pQOj6GSOi0SEOF373D8+ojC5G3KKWNKBuGjdUrvuevtUOB41V?= =?us-ascii?Q?LYct3ZUR6jRfa+ZkPRFMH/qncH/L8GGm5a0b2zX+/6Kke4Tv+vEnTv8Wwr53?= =?us-ascii?Q?ac+Z4CpUBeIDru1KN42wrXyS/GsCe7k8MtHuVlVIb7/KHerA9VbqC87LcDXQ?= =?us-ascii?Q?RCgC83reMkTX0NHhGZxFIk+dZu+HfRDs3JtFtM0lKbcbJMcxQ6tJ1cUy3erM?= =?us-ascii?Q?2Cd6IA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2026 18:03:03.0641 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2503640c-7e8e-48e4-99bc-08de5784fd5d 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A34A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6844 Content-Type: text/plain; charset="utf-8" Document perf sched stats purpose, usage examples and guide on how to interpret the report data in the perf-sched man page. Signed-off-by: Ravi Bangoria Signed-off-by: Swapnil Sapkal Acked-by: Ian Rogers Acked-by: Namhyung Kim Acked-by: Peter Zijlstra (Intel) Tested-by: Chen Yu --- tools/perf/Documentation/perf-sched.txt | 261 +++++++++++++++++++++++- 1 file changed, 260 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documenta= tion/perf-sched.txt index 6dbbddb6464d..5bfb7bb6c633 100644 --- a/tools/perf/Documentation/perf-sched.txt +++ b/tools/perf/Documentation/perf-sched.txt @@ -8,7 +8,7 @@ perf-sched - Tool to trace/measure scheduler properties (la= tencies) SYNOPSIS -------- [verse] -'perf sched' {record|latency|map|replay|script|timehist} +'perf sched' {record|latency|map|replay|script|timehist|stats} =20 DESCRIPTION ----------- @@ -80,8 +80,267 @@ There are several variants of 'perf sched': =20 Times are in msec.usec. =20 + 'perf sched stats {record | report | diff} ' to capture, repor= t the diff + in schedstat counters and show the difference between perf sched stats = report + respectively. schedstat counters which are present in the linux kernel = and are + exposed through the file ``/proc/schedstat``. These counters are enable= d or disabled + via the sysctl governed by the file ``/proc/sys/kernel/sched_schedstats= ``. These + counters accounts for many scheduler events such as ``schedule()`` call= s, load-balancing + events, ``try_to_wakeup()`` call among others. This is useful in unders= tading the + scheduler behavior for the workload. + + Note: The tool will not give correct results if there is topological re= ordering or + online/offline of cpus in between capturing snapshots of `/proc/s= chedstat`. + + Example usage: + perf sched stats record -- sleep 1 + perf sched stats report + perf sched stats diff + + A detailed description of the schedstats can be found in the Kernel Doc= umentation: + https://www.kernel.org/doc/html/latest/scheduler/sched-stats.html + + The result can be interprested as follows: + + The `perf sched stats report` starts with description of the columns pr= esent in + the report. These column names are given before cpu and domain stats to= improve + the readability of the report. + + -----------------------------------------------------------------------= ----------------------------- + DESC -> Description of the field + COUNT -> Value of the field + PCT_CHANGE -> Percent change with corresponding base value + AVG_JIFFIES -> Avg time in jiffies between two consecutive = occurrence of event + -----------------------------------------------------------------------= ----------------------------- + + Next is the total profiling time in terms of jiffies: + + -----------------------------------------------------------------------= ----------------------------- + Time elapsed (in jiffies) : 245= 37 + -----------------------------------------------------------------------= ----------------------------- + + Next is CPU scheduling statistics. These are simple diffs of /proc/sche= dstat CPU lines + along with description. The report also prints % relative to base stat. + + In the example below, schedule() left the CPU0 idle 36.58% of the time.= 0.45% of total + try_to_wake_up() was to wakeup local CPU. And, the total waittime by ta= sks on CPU0 is + 48.70% of the total runtime by tasks on the same CPU. + + -----------------------------------------------------------------------= ----------------------------- + CPU 0 + -----------------------------------------------------------------------= ----------------------------- + DESC = COUNT PCT_CHANGE + -----------------------------------------------------------------------= ----------------------------- + yld_count : = 0 + array_exp : = 0 + sched_count : = 402267 + sched_goidle : = 147161 ( 36.58% ) + ttwu_count : = 236309 + ttwu_local : = 1062 ( 0.45% ) + rq_cpu_time : 708= 3791148 + run_delay : 344= 9973971 ( 48.70% ) + pcount : = 255035 + -----------------------------------------------------------------------= ----------------------------- + + Next is load balancing statistics. For each of the sched domains + (eg: `SMT`, `MC`, `DIE`...), the scheduler computes statistics under + the following three categories: + + 1) Idle Load Balance: Load balancing performed on behalf of a long + idling CPU by some other CPU. + 2) Busy Load Balance: Load balancing performed when the CPU was busy. + 3) New Idle Balance : Load balancing performed when a CPU just became + idle. + + Under each of these three categories, sched stats report provides + different load balancing statistics. Along with direct stats, the + report also contains derived metrics prefixed with *. Example: + + -----------------------------------------------------------------------= ----------------------------- + CPU 0, DOMAIN SMT CPUS 0,64 + -----------------------------------------------------------------------= ----------------------------- + DESC = COUNT AVG_JIFFIES + ----------------------------------------- -------------= ----------------------------- + busy_lb_count : = 136 $ 17.08 $ + busy_lb_balanced : = 131 $ 17.73 $ + busy_lb_failed : = 0 $ 0.00 $ + busy_lb_imbalance_load : = 58 + busy_lb_imbalance_util : = 0 + busy_lb_imbalance_task : = 0 + busy_lb_imbalance_misfit : = 0 + busy_lb_gained : = 7 + busy_lb_hot_gained : = 0 + busy_lb_nobusyq : = 2 $ 1161.50 $ + busy_lb_nobusyg : = 129 $ 18.01 $ + *busy_lb_success_count : = 5 + *busy_lb_avg_pulled : = 1.40 + ----------------------------------------- -------------= ----------------------------- + idle_lb_count : = 449 $ 5.17 $ + idle_lb_balanced : = 382 $ 6.08 $ + idle_lb_failed : = 3 $ 774.33 $ + idle_lb_imbalance_load : = 0 + idle_lb_imbalance_util : = 0 + idle_lb_imbalance_task : = 71 + idle_lb_imbalance_misfit : = 0 + idle_lb_gained : = 67 + idle_lb_hot_gained : = 0 + idle_lb_nobusyq : = 0 $ 0.00 $ + idle_lb_nobusyg : = 382 $ 6.08 $ + *idle_lb_success_count : = 64 + *idle_lb_avg_pulled : = 1.05 + ---------------------------------------- -----------= ----------------------------- + newidle_lb_count : = 30471 $ 0.08 $ + newidle_lb_balanced : = 28490 $ 0.08 $ + newidle_lb_failed : = 633 $ 3.67 $ + newidle_lb_imbalance_load : = 0 + newidle_lb_imbalance_util : = 0 + newidle_lb_imbalance_task : = 2040 + newidle_lb_imbalance_misfit : = 0 + newidle_lb_gained : = 1348 + newidle_lb_hot_gained : = 0 + newidle_lb_nobusyq : = 6 $ 387.17 $ + newidle_lb_nobusyg : = 26634 $ 0.09 $ + *newidle_lb_success_count : = 1348 + *newidle_lb_avg_pulled : = 1.00 + -----------------------------------------------------------------------= ----------------------------- + + Consider following line: + + newidle_lb_balanced : = 28490 $ 0.08 $ + + While profiling was active, the load-balancer found 28490 times the load + needs to be balanced on a newly idle CPU 0. Following value encapsulated + inside $ is average jiffies between two events (28490 / 24537 =3D 0.08). + + Next are active_load_balance() stats. alb did not trigger while the + profiling was active, hence it's all 0s. + + --------------------------------- ----= ----------------------------- + alb_count : = 0 + alb_failed : = 0 + alb_pushed : = 0 + -----------------------------------------------------------------------= ----------------------------- + + Next are sched_balance_exec() and sched_balance_fork() stats. They are + not used but we kept it in RFC just for legacy purpose. Unless opposed, + we plan to remove them in next revision. + + Next are wakeup statistics. For every domain, the report also shows + task-wakeup statistics. Example: + + ------------------------------------------ --------------= ----------------------------- + ttwu_wake_remote : = 1590 + ttwu_move_affine : = 84 + ttwu_move_balance : = 0 + -----------------------------------------------------------------------= ----------------------------- + + Same set of stats are reported for each CPU and each domain level. + + How to interpret the diff + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + The `perf sched stats diff` will also start with explaining the columns + present in the diff. Then it will show the diff in time in terms of + jiffies. The order of the values depends on the order of input data + files. It will take `perf.data.old` and `perf.data` respectively as the + defaults for comparison. Example: + + -----------------------------------------------------------------------= ----------------------------- + Time elapsed (in jiffies) : = 2009, 2001 + -----------------------------------------------------------------------= ----------------------------- + + Below is the sample representing the difference in cpu and domain stats= of + two runs. Here third column or the values enclosed in `|...|` shows the + percent change between the two. Second and fourth columns shows the + side-by-side representions of the corresponding fields from `perf sched + stats report`. + + -----------------------------------------------------------------------= ----------------------------- + CPU + -----------------------------------------------------------------------= ----------------------------- + DESC = COUNT1 COUNT2 PCT_CHANG> + -----------------------------------------------------------------------= ----------------------------- + yld_count : = 0, 0 | 0.00> + array_exp : = 0, 0 | 0.00> + sched_count : = 528533, 412573 | -21.94> + sched_goidle : = 193426, 146082 | -24.48> + ttwu_count : = 313134, 385975 | 23.26> + ttwu_local : = 1126, 1282 | 13.85> + rq_cpu_time : 825= 7200244, 8301250047 | 0.53> + run_delay : 472= 8347053, 3997100703 | -15.47> + pcount : = 335031, 266396 | -20.49> + -----------------------------------------------------------------------= ----------------------------- + + Below is the sample of domain stats diff: + + -----------------------------------------------------------------------= ----------------------------- + CPU , DOMAIN SMT + -----------------------------------------------------------------------= ----------------------------- + DESC = COUNT1 COUNT2 PCT_CHANG> + ----------------------------------------- -------------= ----------------------------- + busy_lb_count : = 122, 80 | -34.43> + busy_lb_balanced : = 115, 76 | -33.91> + busy_lb_failed : = 1, 3 | 200.00> + busy_lb_imbalance_load : = 35, 49 | 40.00> + busy_lb_imbalance_util : = 0, 0 | 0.00> + busy_lb_imbalance_task : = 0, 0 | 0.00> + busy_lb_imbalance_misfit : = 0, 0 | 0.00> + busy_lb_gained : = 7, 2 | -71.43> + busy_lb_hot_gained : = 0, 0 | 0.00> + busy_lb_nobusyq : = 0, 0 | 0.00> + busy_lb_nobusyg : = 115, 76 | -33.91> + *busy_lb_success_count : = 6, 1 | -83.33> + *busy_lb_avg_pulled : = 1.17, 2.00 | 71.43> + ----------------------------------------- -------------= ----------------------------- + idle_lb_count : = 568, 620 | 9.15> + idle_lb_balanced : = 462, 449 | -2.81> + idle_lb_failed : = 11, 21 | 90.91> + idle_lb_imbalance_load : = 0, 0 | 0.00> + idle_lb_imbalance_util : = 0, 0 | 0.00> + idle_lb_imbalance_task : = 115, 189 | 64.35> + idle_lb_imbalance_misfit : = 0, 0 | 0.00> + idle_lb_gained : = 103, 169 | 64.08> + idle_lb_hot_gained : = 0, 0 | 0.00> + idle_lb_nobusyq : = 0, 0 | 0.00> + idle_lb_nobusyg : = 462, 449 | -2.81> + *idle_lb_success_count : = 95, 150 | 57.89> + *idle_lb_avg_pulled : = 1.08, 1.13 | 3.92> + ---------------------------------------- -----------= ----------------------------- + newidle_lb_count : = 16961, 3155 | -81.40> + newidle_lb_balanced : = 15646, 2556 | -83.66> + newidle_lb_failed : = 397, 142 | -64.23> + newidle_lb_imbalance_load : = 0, 0 | 0.00> + newidle_lb_imbalance_util : = 0, 0 | 0.00> + newidle_lb_imbalance_task : = 1376, 655 | -52.40> + newidle_lb_imbalance_misfit : = 0, 0 | 0.00> + newidle_lb_gained : = 917, 457 | -50.16> + newidle_lb_hot_gained : = 0, 0 | 0.00> + newidle_lb_nobusyq : = 3, 1 | -66.67> + newidle_lb_nobusyg : = 14480, 2103 | -85.48> + *newidle_lb_success_count : = 918, 457 | -50.22> + *newidle_lb_avg_pulled : = 1.00, 1.00 | 0.11> + --------------------------------- ----= ----------------------------- + alb_count : = 0, 1 | 0.00> + alb_failed : = 0, 0 | 0.00> + alb_pushed : = 0, 1 | 0.00> + --------------------------------- -----= ----------------------------- + sbe_count : = 0, 0 | 0.00> + sbe_balanced : = 0, 0 | 0.00> + sbe_pushed : = 0, 0 | 0.00> + --------------------------------- -----= ----------------------------- + sbf_count : = 0, 0 | 0.00> + sbf_balanced : = 0, 0 | 0.00> + sbf_pushed : = 0, 0 | 0.00> + ------------------------------------------ --------------= ----------------------------- + ttwu_wake_remote : = 2031, 2914 | 43.48> + ttwu_move_affine : = 73, 124 | 69.86> + ttwu_move_balance : = 0, 0 | 0.00> + -----------------------------------------------------------------------= ----------------------------- + OPTIONS ------- +Applicable to {record|latency|map|replay|script} + -i:: --input=3D:: Input file name. (default: perf.data unless stdin is a fifo) --=20 2.43.0