From nobody Fri Nov 29 19:28:28 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2080.outbound.protection.outlook.com [40.107.92.80]) (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 0138315B0F4; Mon, 16 Sep 2024 16:49:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505358; cv=fail; b=msIlOrqrQJeJbzU0yuJJeFEmGZwmQiI9fZWeIyZU6tzex2Ep1ggwkAx3o35vrUWE4LXdW1ekbFtO13Pl//phiLPbN0Ah6GuDSDRxxBAEASN3wNSnW4mDieBVeyVrWaDR51i0kA245vM3AFZNYfjiEOIb7B+BDmjI5AnWPN+KcTE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505358; c=relaxed/simple; bh=CQ0IfzsbVx1/yKQCqXkTv6nH1ZJOZw92LQlMezJO0Bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=loafDnfBPoCSHVwBFGiATGAUYDswZCJzY8SseHkwvGrj4x16Qlt6LTdOqWHsubSpgaLF1sQ6KWQGlPanZkWguhZbkcGYyc5ygOG9KqRnB1pfkCemMm7oTmhydHw0DtA3O3tOC10zYEAmjpRbg+ZPU5fLYxMdZe+zsA09ddd7T4s= 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=bSAbUvpD; arc=fail smtp.client-ip=40.107.92.80 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="bSAbUvpD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GZ2I3VArEkoieA+7vZnnzaxtjQETUZfUb6GQeZkpFY9UA/J4w3Jwzxm094Y8Gz46eHVeZ5fNdIM3n0qy2RQKmrv2R+crpcLxoCxtzaa5um94KnZ7a187R0/qt8y1MKfG0VH73Qs7TEuCVyYAJRzKzmba6aXgyWQ+EwQInuhLqd/JaRNAHo75XVSCjDYOXcdFt9IRX81aIg+DEaysgIOoerYtpilRGYeAsomnu7LsIKmNdYZT3cXKkibIuz9oAFKuTCnpsedY3GPC3p26RDYjNLABrlkP5ioY74EVEYMtLpHwQPzJ3LkJQuBb1EpzIUKhJtssxEAZHbnX+y0PEHTd0w== 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=1KLT1LS7u5Qo7XF6fUdLNTSLZj1eEKAV1XTMTB2yP/4=; b=pFg520lOO+KlyMRHi8QYfcGV7YJ4V867Zfy8Y38zwVSo7d+zUjUk++lwytQQ1eFmeDUPRE6lB4lbZcFXqd+zs+QLx20WXymm/78bP21aplWmjD2TOIC0WX7Q2+5+f8x4uFYedLRkHl+DQTYhsyjUu8olOJHbkBl1JdMpGS3mHCX/VybaWhYADW2EEhWgPZpHcsPttwasYdICJwkdUvGKU+lK2QQcpCiEVECjJBPFrl32RUhDAjylbQxiovlhg1vwZIY6H3Ege5TczobYWRCiUJ4GaaaOL4/nrJrkSGV64ueAF0xtaY+9NqzZ7wZxZTct4mgMRJY8sEvfsCExum5OiA== 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=1KLT1LS7u5Qo7XF6fUdLNTSLZj1eEKAV1XTMTB2yP/4=; b=bSAbUvpDXiLrS7dBPIqRaygxNoXPwv4Zu6/sz8KVs9jUVUjVrGYtfCOJb/3698TNFFypWVPRPnzN4EsZzlRfYZ6g5UJr+NTN+3cHqpXCaes6cdrxQFadZEdXTmFVZro1wSzW6tAVWyyVkAHqHVrsednvfEgeLWVTc9oftSqgFJo= Received: from SJ0PR13CA0209.namprd13.prod.outlook.com (2603:10b6:a03:2c3::34) by BY5PR12MB4321.namprd12.prod.outlook.com (2603:10b6:a03:204::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Mon, 16 Sep 2024 16:49:12 +0000 Received: from SJ1PEPF0000231D.namprd03.prod.outlook.com (2603:10b6:a03:2c3:cafe::ae) by SJ0PR13CA0209.outlook.office365.com (2603:10b6:a03:2c3::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Mon, 16 Sep 2024 16:49:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF0000231D.mail.protection.outlook.com (10.167.242.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 16:49:11 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 16 Sep 2024 11:48:59 -0500 From: Ravi Bangoria To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 1/5] sched/stats: Print domain name in /proc/schedstat Date: Mon, 16 Sep 2024 16:47:18 +0000 Message-ID: <20240916164722.1838-2-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240916164722.1838-1-ravi.bangoria@amd.com> References: <20240916164722.1838-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231D:EE_|BY5PR12MB4321:EE_ X-MS-Office365-Filtering-Correlation-Id: aabee691-7324-4ac4-06cb-08dcd66f7db3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sGLkMhXVp6RJ4E0MQSDS6M3d/z4PSdPOSCis7wI3B7NHOmReqRWqFX4XCaF2?= =?us-ascii?Q?xPnTTw9OcjMy6eBQZKCwbWt4zs+VLd1q74q7ByCzVttFaNkcZ1MI/2yAikaJ?= =?us-ascii?Q?DI8IF32kXFWxeID/fws3Z9U5zn2UO9ZjTAC3EOVoXl+Dvd+4eLtRnfYxnAGX?= =?us-ascii?Q?1I2rZ8HkyWkmdCkrJ476n+xtVobjr/UojAhycqWAcGgM7QcmYNpFdGLsAQBK?= =?us-ascii?Q?oGooPELQPnNrC7/RUv9RZZfp+tII6i1z3iVfwBilX9I8H1/kk4ZvMe+jPziE?= =?us-ascii?Q?XE015JV2j0Pn+jEgxgxsE6T0WroLaMD2s8WjROAYjUHidWjANfxTV2FeU99Q?= =?us-ascii?Q?z7uwbhGF99CrsHFUq+E0+Pzdu1HhOssrxyaktP874qrEkSEnKI9SQ+CzUXxi?= =?us-ascii?Q?5yavSpbEEhKjb+kKj8hOH5VJ5cuJrNnoPjCQ56YeHlTxTADAXclilB1AVCE2?= =?us-ascii?Q?7FtfnMeUloBudQcCItIjup3R0YhoGTn8osdz3KsaLt7lCwKdJq54OMuhavhG?= =?us-ascii?Q?iuzYatFfEo+5G3GzkYM45dIUCEqT0v+D0enYoP6GnMkqLSOF396HURF/Q7d3?= =?us-ascii?Q?vidS60jA9JQnQpX8NWUOru+XyJOxXblevQ/78TQ5SgZC1/Q1oaTNE5UV7yEU?= =?us-ascii?Q?vmflybLgb6p7YkKhzOA1o4qAh1/akexsgtJZEl2Dz5sjC3gnXyMXRc2/+kGm?= =?us-ascii?Q?c7uAFk6CzkpXycFdonVOs5M3gl7Dcz0dhM5IgGlqayKKv3Ssf6UfAQxjiDoB?= =?us-ascii?Q?+B/9b8u9bATU+DUJAgno9uJbrcRA3z8pWsHdnJDOWldKtKritKdt2xo0UMpk?= =?us-ascii?Q?RS+nmw45LZF37Z6EAvBhHI5lb84CUQMKlxzIsuy2RLjrtr5E5cKaZthlBoDh?= =?us-ascii?Q?159XTDKr6n/OQYNNo0Ygi4Vjp3EEwO2sxHUd1mjzhwgvYhKsH2yH03UX5ryz?= =?us-ascii?Q?gKmU9uJwGgSBth8hg0YV+vNj4OJdqEgm3xFZpMVW0wt/2twrgewpoV4aNpoQ?= =?us-ascii?Q?1eKX+cYP5uEmxYTcSqrNONlXVus2o/jjFrEh9blmcZGIwGqpnRrXiFs00Dj4?= =?us-ascii?Q?40g//2sqPNa3RKeBd/qwQ0i8+65nDpntz6BjaDrVgid6R735uaGzq8Yz0DWr?= =?us-ascii?Q?XF7aSUhdON9QLju9pWmKY5TcMe7jzVYtt7CKabUbMu/bYXPvAVB6yFG94TmL?= =?us-ascii?Q?ijuuYPTrlYKkAOqmcM/D4CalIF9Fa0MlRA0mbs/aX5p+5SwtMqQPybAJl+F5?= =?us-ascii?Q?LDPTJyDKfGxsbs018QuBkydSPfwKL/oISwEbgpwM384yxfPt4KDwtFa5cdhW?= =?us-ascii?Q?SChN0ZTj9D5p87S6IbOw2UL+IY8nlf2xs8rqemeTSwRtA5JdzXu8aa+VC/mq?= =?us-ascii?Q?IprWaaRa1T4Cey0beR6uvaGbAPuwyQ5n3xE7WUELK25KUrOQBQN3d0DDTSTQ?= =?us-ascii?Q?jduLfiqa8AkneDi2pSIxMsUnVHDD9HPf?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 16:49:11.6960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aabee691-7324-4ac4-06cb-08dcd66f7db3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4321 Content-Type: text/plain; charset="utf-8" From: K Prateek Nayak Currently, there does not exist a straightforward way to extract the names of the sched domains and match them to the per-cpu domain entry in /proc/schedstat other than looking at the debugfs files which are only visible after enabling "verbose" debug after commit 34320745dfc9 ("sched/debug: Put sched/domains files under the verbose flag") Since tools like `perf sched schedstat` require displaying per-domain information in user friendly manner, display the names of sched domain, alongside their level in /proc/schedstat if CONFIG_SCHED_DEBUG is enabled. Domain names also makes the /proc/schedstat data unambiguous when some of the cpus are offline. For example, on a 128 cpus AMD Zen3 machine where CPU0 and CPU64 are SMT siblings and CPU64 is offline: Before: cpu0 ... domain0 ... domain1 ... cpu1 ... domain0 ... domain1 ... domain2 ... After: cpu0 ... domain0:MC ... domain1:PKG ... cpu1 ... domain0:SMT ... domain1:MC ... domain2:PKG ... schedstat version has not been updated since this change merely adds additional information to the domain name field and does not add a new field altogether. Signed-off-by: K Prateek Nayak Signed-off-by: Ravi Bangoria Tested-by: James Clark --- Documentation/scheduler/sched-stats.rst | 8 ++++++-- kernel/sched/stats.c | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/scheduler/sched-stats.rst b/Documentation/schedu= ler/sched-stats.rst index 7c2b16c4729d..b60a3e7bc108 100644 --- a/Documentation/scheduler/sched-stats.rst +++ b/Documentation/scheduler/sched-stats.rst @@ -6,6 +6,8 @@ Version 16 of schedstats changed the order of definitions w= ithin '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. The size of the array is unchanged. +With CONFIG_SCHED_DEBUG enabled, the domain field can also print the +name of the corresponding sched domain. =20 Version 15 of schedstats dropped counters for some sched_yield: yld_exp_empty, yld_act_empty and yld_both_empty. Otherwise, it is @@ -71,9 +73,11 @@ Domain statistics ----------------- One of these is produced per domain for each cpu described. (Note that if CONFIG_SMP is not defined, *no* domains are utilized and these lines -will not appear in the output.) +will not appear in the output. [:] is an optional extension to the d= omain +field that prints the name of the corresponding sched domain. It can appea= r in +schedstat version 16 and above, and requires CONFIG_SCHED_DEBUG.) =20 -domain 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 = 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 +domain[:] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 = 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 =20 The first field is a bit mask indicating what cpus this domain operates ov= er. =20 diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c index eb0cdcd4d921..bd4ed737e894 100644 --- a/kernel/sched/stats.c +++ b/kernel/sched/stats.c @@ -138,7 +138,11 @@ static int show_schedstat(struct seq_file *seq, void *= v) for_each_domain(cpu, sd) { enum cpu_idle_type itype; =20 - seq_printf(seq, "domain%d %*pb", dcount++, + seq_printf(seq, "domain%d", dcount++); +#ifdef CONFIG_SCHED_DEBUG + seq_printf(seq, ":%s", sd->name); +#endif + seq_printf(seq, " %*pb", cpumask_pr_args(sched_domain_span(sd))); for (itype =3D 0; itype < CPU_MAX_IDLE_TYPES; itype++) { seq_printf(seq, " %u %u %u %u %u %u %u %u", --=20 2.46.0 From nobody Fri Nov 29 19:28:28 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2083.outbound.protection.outlook.com [40.107.220.83]) (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 DB34F15B15D; Mon, 16 Sep 2024 16:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505367; cv=fail; b=a+hIF/Tll6RuuCq16Jd4h20s2rB0pmCX0ikQUxms7w1TYfOUiavDxzri7Tb2+gEt6TsyaeONpLdpzWXRON4Vxf90boSM9bxgsq9ntH5F67lNFKHvZhtihNRembb8nSatIkTMcEVLkjMC49sApPKCAQQUvfpxwRQmeOIYN9Ybb6Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505367; c=relaxed/simple; bh=+6Np/n6ZF0VaY4Z3psw7PMQURsMjqw5PO+vg8hhp2qg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QG8thDGnvp+LBYZkaKziEL2Q9Wxc1PjBIAxKaLNGID5eY9SRpRQ2QYH+A5XlB1rPlpbOR6jWXwYHtejM+CfIODISyrQ1LcJDNQsaCgHfTqe0CNeLPBFhveJKy+JEK4HAvqv89kYry77rwC0WwGN1c3Y0sZKH5IoeQw66OlblQuQ= 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=KasvjDXl; arc=fail smtp.client-ip=40.107.220.83 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="KasvjDXl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f0vitkF/vwcJpqJrWhQhCWw0il0QhYbUh85Bg9Q6HFjIOMl7FrtK5rSBh1ZMmXbrdVF0YV4Y6hjYwtAzavu4eXuMZScHF/V83yqHkdl2Os+dXhwqOzAelZ0ronKtKg6ngCR7LIaHYhuS5PNj1v+H49WGwwGlMb+HAB1pkdJCIV494hWLSCnBnwkAZFPNUaCKnCXhKybzJmeYANM881mAfh3E3P/1iujdeIqjg2ObmA+scke4kkshmJYzJEReiyTb5B0xS6KUwxA1FHWRVEV1NTf+sTfwQYO7sGen8JzBQrX/a5tUDfu0iqHEnupTU0L70m4A2JAbMY2CrtD/whEdWw== 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=UrTCKjuaFH3//6fOqm9+1VCh2EmXVN41pRNoM8SFfxY=; b=GuyPhuyYeB+yjQ5JxROt5nU5LfwMypgIQBo0aRT9r0yznHyfTKQSZOCrLp9+4GCqIue7Q5jNIxcLg1pMxqMOam/EPHitBrDWaHI27/tXs+OY097wk7u9oWJOLlAG+CdEdrlYNhPX7cRdMqEm0Ua9PmvK7ny5JVH8owEcQ8PSvkMiyg7fUS+z+rGOHMW5LD8RmgMGkYkErRvfTJEGz1ClGNbNdXQ+LseQ6mwcd263QJ4BHpy2x2VBvPirtvTAaDB3lnMp1/XcXo+a6P0MrQzrImwdiFwyjTirkLoTCMYZj4xheduUkCyHfHHCUaURG93A4VTJDD9aiT2pkStwew3Seg== 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=UrTCKjuaFH3//6fOqm9+1VCh2EmXVN41pRNoM8SFfxY=; b=KasvjDXlxP0MqNSaRk2gmy21y+rprA9nxtv1uQ9uBMZciXUJbl/rRwJWw//95MiJ41w+u8NH8SAK7Uce+tlgClA4lMmKM/AVAE6baUcITWBNSiNbxgPguBkqApkjyfqP3CIZ/yUH31FTVZUs1aEMh0nuGXAUy2VGNX+ZXFWtDhg= Received: from SJ0PR13CA0136.namprd13.prod.outlook.com (2603:10b6:a03:2c6::21) by IA1PR12MB6188.namprd12.prod.outlook.com (2603:10b6:208:3e4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Mon, 16 Sep 2024 16:49:19 +0000 Received: from SJ1PEPF0000231B.namprd03.prod.outlook.com (2603:10b6:a03:2c6:cafe::95) by SJ0PR13CA0136.outlook.office365.com (2603:10b6:a03:2c6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Mon, 16 Sep 2024 16:49:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF0000231B.mail.protection.outlook.com (10.167.242.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 16:49:18 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 16 Sep 2024 11:49:09 -0500 From: Ravi Bangoria To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 2/5] perf sched stats: Add record and rawdump support Date: Mon, 16 Sep 2024 16:47:19 +0000 Message-ID: <20240916164722.1838-3-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240916164722.1838-1-ravi.bangoria@amd.com> References: <20240916164722.1838-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231B:EE_|IA1PR12MB6188:EE_ X-MS-Office365-Filtering-Correlation-Id: 6863df1f-7d64-4534-80ec-08dcd66f81b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?az6fWuaofZMEzjT3ECXBYVgmWD3Y0uRw8PDQpyUR0omiaM4NvxT2imn7OCHj?= =?us-ascii?Q?Wxxx5Ykfev9oduU5iRu3nBhmKctv4tYPFlQ+xZ+JlO/QN+18xeNEiUGnovFv?= =?us-ascii?Q?n0lqXGvn+UTBMBW359zym8PCeclSkenMubyzUxlFR2Txh8MDogwDa0TnNH5C?= =?us-ascii?Q?WsevL5x+zI86gs9YjO4ewpVyPfnP0LP1Og/7lnh+C9k4xLalpb6d5PpmLBLq?= =?us-ascii?Q?jnCacu8KZZuW88ZeiPfLGeJLEyeJHpqKxtYH6dDL07DDjhrfZ0993ESkdNe7?= =?us-ascii?Q?A155kR3bnQXE+P6hTX4V40TuHfOm7ck9WnWOio81P5QrGoEtBHo/Q0IcVgi6?= =?us-ascii?Q?JLzCuc+lHuWUEjI2d0oxizjT2niDDngsjJO+DlbTkCARWW+YpaRebJ7DGfxq?= =?us-ascii?Q?VFhviPkJc9lyb58klC5bR8+5wgZCn+4JF6TbmAsFIe/vTp383ryP1bE9KHlB?= =?us-ascii?Q?AbRfZ4Wtpdy1OARCEMio5VzIxYcO4Ur1mpjGtubP2aFpMtFt5lG0SvrFDh3e?= =?us-ascii?Q?m6sHHNVFBX8Zutg808A5rm4P9zH/0w4K3MapJr+dGyNJYwUTyfDeVYiu82On?= =?us-ascii?Q?5NcrqfyHgOxl85A3CpkyYDAPXlU04eu8ZKt+18LcNkNgWFYpptibEe5qpv9d?= =?us-ascii?Q?wxlhEm1o6L/5oshxtt12Ei8dpVYNLfkheEyNUX59kYVCkeL+CjhlaER/JTP1?= =?us-ascii?Q?qvOy36rkfZmMKwRDCFHal8MtIBCOCU83zZtJCItuGRcqgCVR/zEzzjJg7XZU?= =?us-ascii?Q?IYcpfjaKw/g5FxwSi6E4lbfTnrhkkwzj5TZogGN7GfGI1/wGKF4bj7/n5Inw?= =?us-ascii?Q?SQK94CSSmm/dwYg21M+X8Gjlw+rzUPKZv3wZWyMi7fgEP577DoRd0yvmvMJY?= =?us-ascii?Q?UEiXKlJr4UwEKgSsBhEzLC/YJxer/AQ2e/yauBcrO4J7pcaB49Q1HDlEbJhb?= =?us-ascii?Q?s0zrDVbVVJLWEONGU/QanzJURqC7uYExwGL4zLRi9Jqc10WTa+eHBF33XT3K?= =?us-ascii?Q?cF+1dnEoSHVXqKJYtgtw0ZD6O1m79Ss8sSFVvq+o+n4q8FNJNLYgJJ0bl6eX?= =?us-ascii?Q?jDEpr/dvQIg6eb3uT5hCRPgxG7iXG/Rkv6uaQWndzf9loinSQ0l6dWdLYW5K?= =?us-ascii?Q?dteONCX2UM7i8kHKX5LMO9Co9HCgvmjNMhE21xUHKuBuKbpC2D8ZggA4/Mc5?= =?us-ascii?Q?bHQpPt+1kA+PZfwbgt0Xk3xZSIME6EBg66JUshMJDjvNWwUahs8VtDfYMyJW?= =?us-ascii?Q?wygWoDA3Ts4yUvoI/J2/y8kGxhmjy6Hyb9WJLl6vF/gVNWB03+7v3pPtAGqv?= =?us-ascii?Q?W+7hEOjfIzdrmAYYEo8JVz1DrriqbMN2eS5rHrcMr9FEpVwZ6k8fH2y/CUjm?= =?us-ascii?Q?iF9kEOtRWWhaFIll5poGVkEPPY/wn40vl6YtvyGeEktL+tWUbEmEExH2Yt7A?= =?us-ascii?Q?AhI0WArTDQEYk3CgCryxWNCURPIlDxKh?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 16:49:18.4165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6863df1f-7d64-4534-80ec-08dcd66f81b4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6188 Content-Type: text/plain; charset="utf-8" From: Swapnil Sapkal 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. Signed-off-by: Swapnil Sapkal Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark --- tools/lib/perf/Documentation/libperf.txt | 2 + tools/lib/perf/Makefile | 2 +- tools/lib/perf/include/perf/event.h | 42 +++ .../lib/perf/include/perf/schedstat-cpu-v15.h | 13 + .../perf/include/perf/schedstat-domain-v15.h | 40 +++ tools/perf/builtin-inject.c | 2 + tools/perf/builtin-sched.c | 222 +++++++++++++++- tools/perf/util/event.c | 98 +++++++ tools/perf/util/event.h | 2 + tools/perf/util/session.c | 20 ++ tools/perf/util/synthetic-events.c | 249 ++++++++++++++++++ tools/perf/util/synthetic-events.h | 3 + tools/perf/util/tool.c | 20 ++ tools/perf/util/tool.h | 4 +- 14 files changed, 716 insertions(+), 3 deletions(-) create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v15.h create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v15.h diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index fcfb9499ef9c..39c78682ad2e 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -211,6 +211,8 @@ SYNOPSIS struct perf_record_time_conv; struct perf_record_header_feature; struct perf_record_compressed; + 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 3a9b2140aa04..ebbfea891a6a 100644 --- a/tools/lib/perf/Makefile +++ b/tools/lib/perf/Makefile @@ -187,7 +187,7 @@ install_lib: libs $(call do_install_mkdir,$(libdir_SQ)); \ 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 bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h = mmap.h schedstat-cpu-v15.h schedstat-domain-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 37bb7771d914..35be296d68d5 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -457,6 +457,44 @@ struct perf_record_compressed { char data[]; }; =20 +struct perf_record_schedstat_cpu_v15 { +#define CPU_FIELD(_type, _name, _ver) _type _name; +#include "schedstat-cpu-v15.h" +#undef CPU_FIELD +}; + +struct perf_record_schedstat_cpu { + struct perf_event_header header; + __u16 version; + __u64 timestamp; + __u32 cpu; + union { + struct perf_record_schedstat_cpu_v15 v15; + }; +}; + +struct perf_record_schedstat_domain_v15 { +#define DOMAIN_FIELD(_type, _name, _ver) _type _name; +#include "schedstat-domain-v15.h" +#undef DOMAIN_FIELD +}; + +#define DOMAIN_NAME_LEN 16 + +struct perf_record_schedstat_domain { + struct perf_event_header header; + __u16 version; + __u64 timestamp; + __u32 cpu; + __u16 domain; + char name[DOMAIN_NAME_LEN]; + union { + struct perf_record_schedstat_domain_v15 v15; + }; + __u16 nr_cpus; + __u8 cpu_mask[]; +}; + enum perf_user_event_type { /* above any possible kernel type */ PERF_RECORD_USER_TYPE_START =3D 64, PERF_RECORD_HEADER_ATTR =3D 64, @@ -478,6 +516,8 @@ enum perf_user_event_type { /* above any possible kerne= l type */ PERF_RECORD_HEADER_FEATURE =3D 80, PERF_RECORD_COMPRESSED =3D 81, PERF_RECORD_FINISHED_INIT =3D 82, + PERF_RECORD_SCHEDSTAT_CPU =3D 83, + PERF_RECORD_SCHEDSTAT_DOMAIN =3D 84, PERF_RECORD_HEADER_MAX }; =20 @@ -518,6 +558,8 @@ union perf_event { struct perf_record_time_conv time_conv; struct perf_record_header_feature feat; struct perf_record_compressed pack; + 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-cpu-v15.h b/tools/lib/pe= rf/include/perf/schedstat-cpu-v15.h new file mode 100644 index 000000000000..8e4355ee3705 --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-cpu-v15.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CPU_FIELD +CPU_FIELD(__u32, yld_count, v15) +CPU_FIELD(__u32, array_exp, v15) +CPU_FIELD(__u32, sched_count, v15) +CPU_FIELD(__u32, sched_goidle, v15) +CPU_FIELD(__u32, ttwu_count, v15) +CPU_FIELD(__u32, ttwu_local, v15) +CPU_FIELD(__u64, rq_cpu_time, v15) +CPU_FIELD(__u64, run_delay, v15) +CPU_FIELD(__u64, pcount, v15) +#endif diff --git a/tools/lib/perf/include/perf/schedstat-domain-v15.h b/tools/lib= /perf/include/perf/schedstat-domain-v15.h new file mode 100644 index 000000000000..422e713d617a --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-domain-v15.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef DOMAIN_FIELD +DOMAIN_FIELD(__u32, idle_lb_count, v15) +DOMAIN_FIELD(__u32, idle_lb_balanced, v15) +DOMAIN_FIELD(__u32, idle_lb_failed, v15) +DOMAIN_FIELD(__u32, idle_lb_imbalance, v15) +DOMAIN_FIELD(__u32, idle_lb_gained, v15) +DOMAIN_FIELD(__u32, idle_lb_hot_gained, v15) +DOMAIN_FIELD(__u32, idle_lb_nobusyq, v15) +DOMAIN_FIELD(__u32, idle_lb_nobusyg, v15) +DOMAIN_FIELD(__u32, busy_lb_count, v15) +DOMAIN_FIELD(__u32, busy_lb_balanced, v15) +DOMAIN_FIELD(__u32, busy_lb_failed, v15) +DOMAIN_FIELD(__u32, busy_lb_imbalance, v15) +DOMAIN_FIELD(__u32, busy_lb_gained, v15) +DOMAIN_FIELD(__u32, busy_lb_hot_gained, v15) +DOMAIN_FIELD(__u32, busy_lb_nobusyq, v15) +DOMAIN_FIELD(__u32, busy_lb_nobusyg, v15) +DOMAIN_FIELD(__u32, newidle_lb_count, v15) +DOMAIN_FIELD(__u32, newidle_lb_balanced, v15) +DOMAIN_FIELD(__u32, newidle_lb_failed, v15) +DOMAIN_FIELD(__u32, newidle_lb_imbalance, v15) +DOMAIN_FIELD(__u32, newidle_lb_gained, v15) +DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v15) +DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v15) +DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v15) +DOMAIN_FIELD(__u32, alb_count, v15) +DOMAIN_FIELD(__u32, alb_failed, v15) +DOMAIN_FIELD(__u32, alb_pushed, v15) +DOMAIN_FIELD(__u32, sbe_count, v15) +DOMAIN_FIELD(__u32, sbe_balanced, v15) +DOMAIN_FIELD(__u32, sbe_pushed, v15) +DOMAIN_FIELD(__u32, sbf_count, v15) +DOMAIN_FIELD(__u32, sbf_balanced, v15) +DOMAIN_FIELD(__u32, sbf_pushed, v15) +DOMAIN_FIELD(__u32, ttwu_wake_remote, v15) +DOMAIN_FIELD(__u32, ttwu_move_affine, v15) +DOMAIN_FIELD(__u32, ttwu_move_balance, v15) +#endif /* DOMAIN_FIELD */ diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d6989195a061..b6eca6e92390 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2530,6 +2530,8 @@ int cmd_inject(int argc, const char **argv) inject.tool.finished_init =3D perf_event__repipe_op2_synth; inject.tool.compressed =3D perf_event__repipe_op4_synth; inject.tool.auxtrace =3D perf_event__repipe_auxtrace; + 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.session =3D __perf_session__new(&data, &inject.tool, /*trace_event_repipe=3D*/inject.output.is_pipe); diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 5981cc51abc8..6ea0db05aa41 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -27,6 +27,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 @@ -54,6 +56,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; @@ -237,6 +240,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 */ @@ -3660,6 +3666,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) +{ + FILE *fp; + char ch; + + fp =3D fopen("/proc/sys/kernel/sched_schedstats", "w+"); + if (!fp) { + pr_err("Failed to open /proc/sys/kernel/sched_schedstats\n"); + 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) +{ + FILE *fp; + + fp =3D fopen("/proc/sys/kernel/sched_schedstats", "w"); + if (!fp) { + pr_err("Failed to open /proc/sys/kernel/sched_schedstats\n"); + 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 evlist *evlist; + struct target *target; + 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"); + 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_CPU_PMU_CAPS); + perf_header__set_feat(&session->header, HEADER_HYBRID_TOPOLOGY); + perf_header__set_feat(&session->header, HEADER_PMU_CAPS); + + 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. + */ + target =3D zalloc(sizeof(struct target)); + 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_target; + } + + if (cpu_list) { + user_requested_cpus =3D perf_cpu_map__new(cpu_list); + if (!user_requested_cpus) + goto out_target; + } + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_schedstat_event, + user_requested_cpus); + if (err < 0) + goto out_target; + + err =3D enable_sched_schedstats(&reset); + if (err < 0) + goto out_target; + + if (argc) + evlist__start_workload(evlist); + + /* wait for signal */ + pause(); + + if (reset) { + err =3D disable_sched_schedstat(); + if (err < 0) + goto out_target; + } + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_schedstat_event, + user_requested_cpus); + if (err < 0) + goto out_target; + + err =3D perf_session__write_header(session, evlist, fd, true); + +out_target: + free(target); +out: + if (!err) + fprintf(stderr, "[ perf sched stats: Wrote samples to %s ]\n", data.path= ); + else + fprintf(stderr, "[ perf sched stats: Failed !! ]\n"); + + close(fd); + perf_session__delete(session); + + return err; +} + static bool schedstat_events_exposed(void) { /* @@ -3835,6 +4030,12 @@ int cmd_sched(int argc, const char **argv) "analyze events only for given task priority(ies)"), 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 []", @@ -3852,9 +4053,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 @@ -3950,6 +4155,21 @@ int cmd_sched(int argc, const char **argv) return ret; =20 return 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 aac96d5d1917..c9bc8237e3fa 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -77,6 +77,8 @@ static const char *perf_event__names[] =3D { [PERF_RECORD_HEADER_FEATURE] =3D "FEATURE", [PERF_RECORD_COMPRESSED] =3D "COMPRESSED", [PERF_RECORD_FINISHED_INIT] =3D "FINISHED_INIT", + [PERF_RECORD_SCHEDSTAT_CPU] =3D "SCHEDSTAT_CPU", + [PERF_RECORD_SCHEDSTAT_DOMAIN] =3D "SCHEDSTAT_DOMAIN", }; =20 const char *perf_event__name(unsigned int id) @@ -550,6 +552,102 @@ 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; + __u16 version =3D cs->version; + size_t size =3D 0; + + size =3D fprintf(fp, "\ncpu%u ", cs->cpu); + +#define CPU_FIELD(_type, _name, _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 cpu_mask_len_2; + size_t cpu_mask_len; + size_t size =3D 0; + char *cpu_mask; + int idx; + int i, j; + bool low; + + if (ds->name[0]) + size =3D fprintf(fp, "\ndomain%u:%s ", ds->domain, ds->name); + else + size =3D fprintf(fp, "\ndomain%u ", ds->domain); + + cpu_mask_len =3D ((ds->nr_cpus + 3) >> 2); + cpu_mask_len_2 =3D cpu_mask_len + ((cpu_mask_len - 1) / 8); + + cpu_mask =3D zalloc(cpu_mask_len_2 + 1); + if (!cpu_mask) + return fprintf(fp, "Cannot allocate memory for cpumask\n"); + + idx =3D ((ds->nr_cpus + 7) >> 3) - 1; + + i =3D cpu_mask_len_2 - 1; + + low =3D true; + j =3D 1; + while (i >=3D 0) { + __u8 m; + + if (low) + m =3D ds->cpu_mask[idx] & 0xf; + else + m =3D (ds->cpu_mask[idx] & 0xf0) >> 4; + + if (m >=3D 0 && m <=3D 9) + m +=3D '0'; + else if (m >=3D 0xa && m <=3D 0xf) + m =3D m + 'a' - 10; + else if (m >=3D 0xA && m <=3D 0xF) + m =3D m + 'A' - 10; + + cpu_mask[i] =3D m; + + if (j =3D=3D 8 && i !=3D 0) { + cpu_mask[i - 1] =3D ','; + j =3D 0; + i--; + } + + if (!low) + idx--; + low =3D !low; + i--; + j++; + } + size +=3D fprintf(fp, "%s ", cpu_mask); + free(cpu_mask); + +#define DOMAIN_FIELD(_type, _name, _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 f8742e6230a5..96e7cd1d282d 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -360,6 +360,8 @@ size_t perf_event__fprintf_cgroup(union perf_event *eve= nt, FILE *fp); size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp); size_t perf_event__fprintf_bpf(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 dbaf07bf6c5f..a929a63e1827 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -691,6 +691,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 @@ -729,6 +743,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 @@ -1444,6 +1460,10 @@ static s64 perf_session__process_user_event(struct p= erf_session *session, return err; case PERF_RECORD_FINISHED_INIT: return tool->finished_init(session, event); + case PERF_RECORD_SCHEDSTAT_CPU: + return tool->schedstat_cpu(session, event); + case PERF_RECORD_SCHEDSTAT_DOMAIN: + return tool->schedstat_domain(session, event); default: return -EINVAL; } diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index a58444c4aed1..9d8450b6eda9 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2507,3 +2507,252 @@ int parse_synth_opt(char *synth) =20 return ret; } + +static union perf_event *__synthesize_schedstat_cpu(struct io *io, __u16 v= ersion, + int *cpu, __u64 timestamp) +{ + struct perf_record_schedstat_cpu *cs; + union perf_event *event; + size_t size; + char ch; + + size =3D sizeof(struct perf_record_schedstat_cpu); + 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->version =3D version; + cs->timestamp =3D timestamp; + cs->header.size =3D size; + + if (io__get_char(io) !=3D 'p' || io__get_char(io) !=3D 'u') + goto out_cpu; + + if (io__get_dec(io, (__u64 *)&cs->cpu) !=3D ' ') + goto out_cpu; + +#define CPU_FIELD(_type, _name, _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 + + *cpu =3D cs->cpu; + return event; + +out_cpu: + free(event); + return NULL; +} + +static size_t schedstat_sanitize_cpumask(char *cpu_mask, size_t cpu_mask_l= en) +{ + char *dst =3D cpu_mask; + char *src =3D cpu_mask; + int i =3D 0; + + for ( ; src < cpu_mask + cpu_mask_len; dst++, src++) { + while (*src =3D=3D ',') + src++; + + *dst =3D *src; + } + + for ( ; dst < src; dst++, i++) + *dst =3D '\0'; + + return cpu_mask_len - i; +} + +static union perf_event *__synthesize_schedstat_domain(struct io *io, __u1= 6 version, + int cpu, __u64 timestamp) +{ + struct perf_env env =3D { .total_mem =3D 0, }; + int nr_cpus_avail =3D perf_env__nr_cpus_avail(&env); + struct perf_record_schedstat_domain *ds; + union perf_event *event; + size_t d_name_len =3D 0; + char *d_name =3D NULL; + size_t cpu_mask_len =3D 0; + char *cpu_mask =3D NULL; + __u64 d_num; + size_t size; + int i =3D 0; + bool low; + char ch; + int idx; + + 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); + if (ch =3D=3D ':') { + if (io__getdelim(io, &d_name, &d_name_len, ' ') < 0 || !d_name_len) + return NULL; + d_name[d_name_len - 1] =3D '\0'; + d_name_len--; + } else if (ch !=3D ' ') { + return NULL; + } + + if (io__getdelim(io, &cpu_mask, &cpu_mask_len, ' ') < 0 || !cpu_mask_len) + goto out; + + cpu_mask[cpu_mask_len - 1] =3D '\0'; + cpu_mask_len--; + cpu_mask_len =3D schedstat_sanitize_cpumask(cpu_mask, cpu_mask_len); + + size =3D sizeof(struct perf_record_schedstat_domain) + ((nr_cpus_avail + = 7) >> 3); + size =3D PERF_ALIGN(size, sizeof(u64)); + event =3D zalloc(size); + + if (!event) + goto out_cpu_mask; + + 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; + if (d_name) + strncpy(ds->name, d_name, DOMAIN_NAME_LEN - 1); + ds->domain =3D d_num; + ds->nr_cpus =3D nr_cpus_avail; + + idx =3D ((nr_cpus_avail + 7) >> 3) - 1; + low =3D true; + for (i =3D cpu_mask_len - 1; i >=3D 0 && idx >=3D 0; i--) { + char mask =3D cpu_mask[i]; + + if (mask >=3D '0' && mask <=3D '9') + mask -=3D '0'; + else if (mask >=3D 'a' && mask <=3D 'f') + mask =3D mask - 'a' + 10; + else if (mask >=3D 'A' && mask <=3D 'F') + mask =3D mask - 'A' + 10; + + if (low) { + ds->cpu_mask[idx] =3D mask; + } else { + ds->cpu_mask[idx] |=3D (mask << 4); + idx--; + } + low =3D !low; + } + + free(d_name); + free(cpu_mask); + +#define DOMAIN_FIELD(_type, _name, _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; + return event; + +out_domain: + free(event); +out_cpu_mask: + free(cpu_mask); +out: + free(d_name); + return NULL; +} + +int perf_event__synthesize_schedstat(const struct perf_tool *tool, + perf_event__handler_t process, + struct perf_cpu_map *user_requested_cpus) +{ + union perf_event *event =3D NULL; + size_t line_len =3D 0; + char *line =3D NULL; + char bf[BUFSIZ]; + __u64 timestamp; + __u16 version; + struct io io; + int ret =3D -1; + int cpu =3D -1; + char ch; + + io.fd =3D open("/proc/schedstat", O_RDONLY, 0); + if (io.fd < 0) { + pr_err("Failed to open /proc/schedstat\n"); + 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 /proc/schedstat version: %s", 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 b9c936b5cfeb..eab914c238df 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -141,4 +141,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 3b7f390f26eb..9f81d720735f 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -230,6 +230,24 @@ static int perf_session__process_compressed_event_stub= (struct perf_session *sess return 0; } =20 +static int process_schedstat_cpu_stub(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; +} + +static int process_schedstat_domain_stub(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; +} + void perf_tool__init(struct perf_tool *tool, bool ordered_events) { tool->ordered_events =3D ordered_events; @@ -286,6 +304,8 @@ void perf_tool__init(struct perf_tool *tool, bool order= ed_events) tool->compressed =3D perf_session__process_compressed_event_stub; #endif tool->finished_init =3D process_event_op2_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 db1c7642b0d1..d289a5396b01 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -77,7 +77,9 @@ struct perf_tool { stat, stat_round, feature, - finished_init; + finished_init, + schedstat_cpu, + schedstat_domain; event_op4 compressed; event_op3 auxtrace; bool ordered_events; --=20 2.46.0 From nobody Fri Nov 29 19:28:28 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2065.outbound.protection.outlook.com [40.107.236.65]) (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 DB96315B98D; Mon, 16 Sep 2024 16:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505383; cv=fail; b=bYY5J2TrDpAy9Ec25TyOB9D8mF6cHrIQlMui7EXntbKTKOMs6veBlRclLR2vZexr5jMKvLuzFRg3oh9aTHQosCSxGsqExgRLzGa1VNd5F2huSHsX14VA35eM3lhnXp//Yf//Dx0QUMITlmgGvOt6H/1Mt6sy6+2PR5qQJoS+cYY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505383; c=relaxed/simple; bh=VYadq/pQdFtlHwvLBpwDZ4iuFVSbNlXLON2+RZOqemg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V5RYlx/pYdWZWBiZMb3CGSXvCQNIavYV9CNKBSlfsh0RIMxf0fdKGvKbha35ND9IKO7vpTW9xBILy7hswRuPStruYutm8ZudIXdvDPMNPRBBukylnxqSMOhJivZHzM48i1SyHIbam1c/jOwKcDA7AZ2wFEUwIg9DZeX5qHL5inU= 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=oxIbiDRk; arc=fail smtp.client-ip=40.107.236.65 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="oxIbiDRk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VkVelYa2SO2+Nz0NfTkN6s6pG+uQTWMk4d1yb1Mthfet8t/QEvCQwzIgG8WenEzK66QSB6FQlz/KozfX78Tz7cd+L5npW9bJTt1siF2cr2yqZeZpSqngxHvPQvTz+PiZSC3pc9kmfQLwnBe1BEE91oxyScmibBuXDpzUQaVymerAXR+oQ57D+A6LdIaOFNS6PjyFX4BbfverD2vzlXTVm+84l+cj1bepxi/SQF3aRJeoB9uLh0QIXbjbPQMMc+CfDNQPH5NUJ6XiqVwlnOa+QQx2yj/DqpwEEozxAudxMgSf+EzcyinDOiagsjAoV4/c3LQUpKaFS7rUiInGqncrFA== 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=EY0TYS50jFo4uHrm0lugMUIlpOgjCH8mTorv2Ukl500=; b=c2o2UIvwhod5J5lUJeTJElY1TXbDbwpjgnXY55+NT180yOdgLtMOGEBfdsqif+gqt/FZ5aTcw8ePk/CZ6qZixcs4QFAb2WmvCxq8ARLenZociXE1ZgZTIZoNwyfAP3tPfK4olWjVHvr9ZGQ5mLM03w/gze3WXUF5FrIpxp/OvTcSWeJqOMGI0DCwxGSFq/Tor4q6E/3aKUbOLThCBdAEB+34+GXAMHqDr/ItUVjb0gnYRpPX9XsSrwNuUXwnqKPG1EsbSGpBeRsRSgiw+jIE6rTSMzhxnJZSCjWntJ6mNEhFH+IHvun3JeSIJceo3RT2E9bYzmhVLI0I4rozjcnxdA== 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=EY0TYS50jFo4uHrm0lugMUIlpOgjCH8mTorv2Ukl500=; b=oxIbiDRkDYnAoM5fbhJPBl+gAXNI0bX5gBOGwaOwdDk6Pw5LYAMIK+SkE5aiyBzuRNTAPUppvJyRItJO9xChlOtdJGFBuCfoSonhzZM5ybztVdvLi/pNx9hQKl16BPpDhqaznpZuC/Yn4+oFveBAL140wWGbHnwMmMdypZTtP3w= Received: from BY3PR05CA0002.namprd05.prod.outlook.com (2603:10b6:a03:254::7) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Mon, 16 Sep 2024 16:49:27 +0000 Received: from SJ1PEPF0000231A.namprd03.prod.outlook.com (2603:10b6:a03:254:cafe::e3) by BY3PR05CA0002.outlook.office365.com (2603:10b6:a03:254::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Mon, 16 Sep 2024 16:49:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF0000231A.mail.protection.outlook.com (10.167.242.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 16:49:25 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 16 Sep 2024 11:49:17 -0500 From: Ravi Bangoria To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 3/5] perf sched stats: Add schedstat v16 support Date: Mon, 16 Sep 2024 16:47:20 +0000 Message-ID: <20240916164722.1838-4-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240916164722.1838-1-ravi.bangoria@amd.com> References: <20240916164722.1838-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231A:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: aa8cdeaa-b69e-4bdc-ce70-08dcd66f860a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?c22ivYHwxXQsWsPyujqSEPc7IEKne56znlTSkGqYAUbjU6ZMIH2J66VVWkGT?= =?us-ascii?Q?ZXzAHVsAm1W1tgMQLchjmQ3vkCKHohrjHCy8SBmVI/uKfd0r6REJ4sL2Lion?= =?us-ascii?Q?aQQh6W9f3v+nN6jfm2iUcfUPomXJTxASTDiweLc74AAtCnFNNZedlJKTHTzI?= =?us-ascii?Q?vktn3HI2ERKPPAdU9CjyCK2prHWZmCyU9t075WC8ogIiFBhqRwHw90DKF9L4?= =?us-ascii?Q?FVusAH8ewigb2ajPz21kBTUqNMA+slYlNHl2bdHaoENgke4qV3dyvXG/mF8i?= =?us-ascii?Q?1WGEX8lDJLIN8hY073A1ee2JP7K7XRoZ9JylEIWPRxfCFMXvIC8li3mJ/ycw?= =?us-ascii?Q?rcFxLhkIpsJhbNbyyQ9WsndKchO1jsXSWcS+ewPXDijWpNPNRMUj0L0R8htB?= =?us-ascii?Q?OlPpT/7P/Sgg2d6Xnvpfr0yQiN+yI+xKYTBMzD/l/PvTl/XRTpLuyY+Vc3x4?= =?us-ascii?Q?AoLf5nOX6cEzLoH3ydTw0a2kiX91KxrNg/IPp08xcdObg74g4ur9XTTic+TA?= =?us-ascii?Q?BlQYhdaNV5Ovms6yBQG8d/HxsK/14s/gJuRzbNA1VcqOIe684UAQCYbkO7WC?= =?us-ascii?Q?nnAK/O2kGR3ng5pLVlXXYCRoYSdeVh8Nvnv7PCgZmH4cn0d9c79puxb/PBZJ?= =?us-ascii?Q?OVs04NnT/uqhY4yyrmzuTnhp5dygr3YntaF3bu7JigVMgq2u04D2FRrIPeKQ?= =?us-ascii?Q?1lQUuXvB3wTOU7RM2mBq+sVIkSsErtplbgqFna/8WhNTcYnFXaY4k60IxVB+?= =?us-ascii?Q?jC2LUUfJPYkacOSv6uD3et2VTYNzgtps/Hr4TkmRNb6Aiav/Qb07UwS+fzM8?= =?us-ascii?Q?6GOGDeB/eFiWxHmm/4bckBKObF99G2UKnk1DDW+DjDnQ/coOn4ZT/HmgnL4U?= =?us-ascii?Q?DxlpzPRrUy1uvgJf/vBdy0U0UpFCxdqa7EKv3IVSB1rFararJ+rWm1ROaHkc?= =?us-ascii?Q?OdvKu9OjMhVcfvmp9Q/BI62y44bz5Ret4LosUYG1ewQdV+e4pUPOCo8HYkkz?= =?us-ascii?Q?k656fknYKeCwwl4GQ2hmlMUqexMHT5x4vpgW+OUoNRzxbrHy77dR3fk+VE9W?= =?us-ascii?Q?64dLyGd2Q9LiQlnVPnsgSKzct3KGWqRpeuQ0wS27DmfvPXly0wIYgeH+yD+H?= =?us-ascii?Q?aqhZ/WJCApvfS3i8HSTVHZSEeiHfeC5ZTIhJfm6H2FVCsngxD8EnaA13r/L0?= =?us-ascii?Q?9KcHb+by30mpzgtP8cqXdaMA8We5OZEe1+k0aQO7LuFG6/gakfZr/7RFWODm?= =?us-ascii?Q?UlOwBvr3qV8mmPe9Wuxdgc/caglbFPa8QClibaTjYg7iyZJAMOIJMuzmDAUP?= =?us-ascii?Q?jc2yRUAJkkcquuNS2okCPWbTZPgvT8KB+9ILvTBsoYiGat51XzKEZibjF+kc?= =?us-ascii?Q?eA8W+fTF75jDkVISsSp4e9/X9bxbmRMGnG2CQ8u9uEApz/zw+/NF00u2hUe+?= =?us-ascii?Q?CHcRy3KC8t991RlB76jW4vYEpmqu04mv?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 16:49:25.6930 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa8cdeaa-b69e-4bdc-ce70-08dcd66f860a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" From: Swapnil Sapkal /proc/schedstat file output is standardized with version number. Add support to record and raw dump v16 version layout. Signed-off-by: Swapnil Sapkal Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark --- tools/lib/perf/Makefile | 2 +- tools/lib/perf/include/perf/event.h | 14 +++++++ .../lib/perf/include/perf/schedstat-cpu-v16.h | 13 ++++++ .../perf/include/perf/schedstat-domain-v16.h | 40 +++++++++++++++++++ tools/perf/util/event.c | 6 +++ tools/perf/util/synthetic-events.c | 6 +++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tools/lib/perf/include/perf/schedstat-cpu-v16.h create mode 100644 tools/lib/perf/include/perf/schedstat-domain-v16.h diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile index ebbfea891a6a..de0f4ffd9e16 100644 --- a/tools/lib/perf/Makefile +++ b/tools/lib/perf/Makefile @@ -187,7 +187,7 @@ install_lib: libs $(call do_install_mkdir,$(libdir_SQ)); \ 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 schedstat-cpu-v15.h schedstat-domain-v15.h +HDRS :=3D bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h = mmap.h schedstat-cpu-v15.h schedstat-domain-v15.h schedstat-cpu-v16.h sched= stat-domain-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 35be296d68d5..c332d467c9c9 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -463,6 +463,12 @@ struct perf_record_schedstat_cpu_v15 { #undef CPU_FIELD }; =20 +struct perf_record_schedstat_cpu_v16 { +#define CPU_FIELD(_type, _name, _ver) _type _name; +#include "schedstat-cpu-v16.h" +#undef CPU_FIELD +}; + struct perf_record_schedstat_cpu { struct perf_event_header header; __u16 version; @@ -470,6 +476,7 @@ struct perf_record_schedstat_cpu { __u32 cpu; union { struct perf_record_schedstat_cpu_v15 v15; + struct perf_record_schedstat_cpu_v16 v16; }; }; =20 @@ -479,6 +486,12 @@ struct perf_record_schedstat_domain_v15 { #undef DOMAIN_FIELD }; =20 +struct perf_record_schedstat_domain_v16 { +#define DOMAIN_FIELD(_type, _name, _ver) _type _name; +#include "schedstat-domain-v16.h" +#undef DOMAIN_FIELD +}; + #define DOMAIN_NAME_LEN 16 =20 struct perf_record_schedstat_domain { @@ -490,6 +503,7 @@ struct perf_record_schedstat_domain { char name[DOMAIN_NAME_LEN]; union { struct perf_record_schedstat_domain_v15 v15; + struct perf_record_schedstat_domain_v16 v16; }; __u16 nr_cpus; __u8 cpu_mask[]; diff --git a/tools/lib/perf/include/perf/schedstat-cpu-v16.h b/tools/lib/pe= rf/include/perf/schedstat-cpu-v16.h new file mode 100644 index 000000000000..f3a55131a05a --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-cpu-v16.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CPU_FIELD +CPU_FIELD(__u32, yld_count, v16) +CPU_FIELD(__u32, array_exp, v16) +CPU_FIELD(__u32, sched_count, v16) +CPU_FIELD(__u32, sched_goidle, v16) +CPU_FIELD(__u32, ttwu_count, v16) +CPU_FIELD(__u32, ttwu_local, v16) +CPU_FIELD(__u64, rq_cpu_time, v16) +CPU_FIELD(__u64, run_delay, v16) +CPU_FIELD(__u64, pcount, v16) +#endif /* CPU_FIELD */ diff --git a/tools/lib/perf/include/perf/schedstat-domain-v16.h b/tools/lib= /perf/include/perf/schedstat-domain-v16.h new file mode 100644 index 000000000000..d6ef895c9d32 --- /dev/null +++ b/tools/lib/perf/include/perf/schedstat-domain-v16.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef DOMAIN_FIELD +DOMAIN_FIELD(__u32, busy_lb_count, v16) +DOMAIN_FIELD(__u32, busy_lb_balanced, v16) +DOMAIN_FIELD(__u32, busy_lb_failed, v16) +DOMAIN_FIELD(__u32, busy_lb_imbalance, v16) +DOMAIN_FIELD(__u32, busy_lb_gained, v16) +DOMAIN_FIELD(__u32, busy_lb_hot_gained, v16) +DOMAIN_FIELD(__u32, busy_lb_nobusyq, v16) +DOMAIN_FIELD(__u32, busy_lb_nobusyg, v16) +DOMAIN_FIELD(__u32, idle_lb_count, v16) +DOMAIN_FIELD(__u32, idle_lb_balanced, v16) +DOMAIN_FIELD(__u32, idle_lb_failed, v16) +DOMAIN_FIELD(__u32, idle_lb_imbalance, v16) +DOMAIN_FIELD(__u32, idle_lb_gained, v16) +DOMAIN_FIELD(__u32, idle_lb_hot_gained, v16) +DOMAIN_FIELD(__u32, idle_lb_nobusyq, v16) +DOMAIN_FIELD(__u32, idle_lb_nobusyg, v16) +DOMAIN_FIELD(__u32, newidle_lb_count, v16) +DOMAIN_FIELD(__u32, newidle_lb_balanced, v16) +DOMAIN_FIELD(__u32, newidle_lb_failed, v16) +DOMAIN_FIELD(__u32, newidle_lb_imbalance, v16) +DOMAIN_FIELD(__u32, newidle_lb_gained, v16) +DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v16) +DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v16) +DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v16) +DOMAIN_FIELD(__u32, alb_count, v16) +DOMAIN_FIELD(__u32, alb_failed, v16) +DOMAIN_FIELD(__u32, alb_pushed, v16) +DOMAIN_FIELD(__u32, sbe_count, v16) +DOMAIN_FIELD(__u32, sbe_balanced, v16) +DOMAIN_FIELD(__u32, sbe_pushed, v16) +DOMAIN_FIELD(__u32, sbf_count, v16) +DOMAIN_FIELD(__u32, sbf_balanced, v16) +DOMAIN_FIELD(__u32, sbf_pushed, v16) +DOMAIN_FIELD(__u32, ttwu_wake_remote, v16) +DOMAIN_FIELD(__u32, ttwu_move_affine, v16) +DOMAIN_FIELD(__u32, ttwu_move_balance, v16) +#endif /* DOMAIN_FIELD */ diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index c9bc8237e3fa..d138e4a5787c 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -566,6 +566,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 @@ -641,6 +644,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 9d8450b6eda9..73b2492a4cde 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2546,6 +2546,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 @@ -2667,6 +2669,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 @@ -2709,6 +2713,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 /proc/schedstat version: %s", line + 8); goto out_free_line; --=20 2.46.0 From nobody Fri Nov 29 19:28:28 2024 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2067.outbound.protection.outlook.com [40.107.102.67]) (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 9090515E5C8; Mon, 16 Sep 2024 16:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505388; cv=fail; b=K3rb5bliJovucqvO8J70i8DsP5AfuyBBlnzxyQ3sNNdDbagFQawYsetOv09EQ+JBXqd9bFtZP+f6VcziK4eIGZ1eHSnP6jj1nmoB7O5Td8yTmR6xyqOkYESgmjFWhYeTPP9YJZ2U4Ak2QwhJvCW77+xfO3kWRV0u/2g68WPfTXI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505388; c=relaxed/simple; bh=t1CLbjydD9FQeJtqZaPBvArlWRePaTdbIVgDIFd2bZg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UillWzf97Pg0+P5r347ByFJ6P35c/g2gSnBxRcUqTaEVFmx6Ey5E7Q/LyLwpCMYW82QasUezIajeltVcrbK7l3YFegShBD3LI40fY/ZffCfGinJmoIGRAz9aim+UmbsOD1E6aWKnBZmKxWEaTBcZVIhTd1UNBuuTEShUZf1OMLA= 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=fDQjSPwF; arc=fail smtp.client-ip=40.107.102.67 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="fDQjSPwF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xAGz5evikoGpzrDMwVNMKq043RDELmHERfdzqtOU36sZ9jKDlFXR6oo1+fEGAflXI08dsebdoPyTKCHemF+LTEREip33R2PcbIjxDy4wiKGXPD2VM6EhM9RZ74F1l5fdUbybBKmtTZ0bmwruFsBucjGipJG2OifpL8gZ1WwcjkmdldFOB9CxrBHhkkONKhcCjzs8UsiaCTdhlBhSBKk4flokDuC9kE8ZWDbZlGdF/gZGd/UCx1Xy4n5vJwsHNxwx9CXTWTksGuvaBehY6hBLLKW5I/q9rdY+G+znd+aSa8raUACnOkMRKQL0DuZnQnzYmNudCLtJ0Ky8d+kUjUc58g== 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=dqpccU0sUyCCbwZDg2Nbv+B+2eYjaKlyh7sUGtHGQTw=; b=ttx9sgkypGk5Ujrl3rZRgcOTr3T8Ghf2XzYiLPMERaqADH42QAqR1ppeMcO93bsoB35w9cP7BjFnyuOCh4pD4YORulUGYZS1B4gy3XZt09mOlu2BuhhKqGBdbTPJdOaVe4nS+WYojYsiYXxLf/eT7aUSXIG9WnqiUZf4J2ufxIptVQVd+BwZDjudJhRCMnB/SzAJRlcG95Q6esueCYILRPnP2cIbzqkPKW8GYU13+yqiYJiNNqES1PNZA3LIRjcumiE3+ItCBT2++fafxgEtTB3y0LeIkqM6K/uIuW6olWZGdw8awlr58iJ9s0VeBvhagI0lWqueUIODELbPCb1mmg== 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=dqpccU0sUyCCbwZDg2Nbv+B+2eYjaKlyh7sUGtHGQTw=; b=fDQjSPwFRFwZmynCCigZijXzi1OCGW98nl6ELsATKhOVEe2R1UYY4xpeiJssAZdMtsElrEmM6TLcQ8gV7llaLSd7dJILnir9Yq2uhmNJ55trvLpWfaMOk0p0vEf3GWMqThiEZBKiDFdNt1DFX0VaDYIbDSS7ITy1D4Clyje1owc= Received: from BY5PR03CA0013.namprd03.prod.outlook.com (2603:10b6:a03:1e0::23) by IA1PR12MB6329.namprd12.prod.outlook.com (2603:10b6:208:3e5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Mon, 16 Sep 2024 16:49:39 +0000 Received: from SJ1PEPF0000231C.namprd03.prod.outlook.com (2603:10b6:a03:1e0:cafe::2d) by BY5PR03CA0013.outlook.office365.com (2603:10b6:a03:1e0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.29 via Frontend Transport; Mon, 16 Sep 2024 16:49:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF0000231C.mail.protection.outlook.com (10.167.242.233) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 16:49:33 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 16 Sep 2024 11:49:25 -0500 From: Ravi Bangoria To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 4/5] perf sched stats: Add support for report subcommand Date: Mon, 16 Sep 2024 16:47:21 +0000 Message-ID: <20240916164722.1838-5-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240916164722.1838-1-ravi.bangoria@amd.com> References: <20240916164722.1838-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231C:EE_|IA1PR12MB6329:EE_ X-MS-Office365-Filtering-Correlation-Id: f0a227db-a28a-4bf8-69a5-08dcd66f8ad2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?d37B/UGKJHoQ6XtrvWSH3ZtNIEYjL23qtMHJiKiNhJmZVS7mWqIQ1DG+PCyu?= =?us-ascii?Q?GfZoccFxe6puuCUnRdtO4Htbmlm0nxLOl2yaN0ye9sS2J7xr2EU09kfKO5cG?= =?us-ascii?Q?umzPE3MpxxCNZ8zk4i6MjEgQ0Yz6mtaPFjjzVqmKVkHYh9VtoJzS/KUtuwRi?= =?us-ascii?Q?+3HwZD62J2cHqOCiOM6S9Xt/gV+7obwnoIUzJht4zEV1ZxGZWOgG5QwA7hU5?= =?us-ascii?Q?zsc/pIz/pAPjaQowOIl/8Oqspbt0L2NNu2Gd1IYCF5U1QGG8Jf8oRVKz3BOL?= =?us-ascii?Q?OUhGQ5hMF8pQunFvU2t3jHVV5slsKgd+hP/EKzDv/IChVtoLC1zh+dPfj+M0?= =?us-ascii?Q?PQZdTZqfVQSquO9+zwx3c6nMS0H5R9A+S0UgIzVV34qHhhR3l9qxPWNBuXNx?= =?us-ascii?Q?OsQrAXjf/wl30n/nhsSeFJhuUyeNkJdom9YXteeWqB/+NBefeRavqQ0Ja/Yw?= =?us-ascii?Q?mhu0ObnEpWzR4IdjlfvN/4dNhFzU8rTrK4bKW0SrxBRoVBPi0nIKoalrM4py?= =?us-ascii?Q?YR5Pa86sZq0/asxk+7Y6ePKBVRl1lb1d8moXdm8s2mn0pdU33xI9tfBz+DEa?= =?us-ascii?Q?+YDbCUvDAP4WK/rdaMHATaWGw6DWBLCwCjEWEcfFiobhrPzNfmFTj5AMwXcq?= =?us-ascii?Q?Q+oQSCB0ljW5ugKnlLrbvXnEzaecIsk6zr1h0mtPyKaQH3spU7QlCQkup2A4?= =?us-ascii?Q?1wE6TeiBCNkvSZVxX6wSNft52NYuirBFIZzceokEb/PbLMaLmX/xAzccFI7E?= =?us-ascii?Q?x52CGW0Dq2cL5uW3qheL5vK//BEIxBfQTLzcKQ8Ii9chZUMjLxHvsLJEy2VC?= =?us-ascii?Q?Evp3wie4v+tOtKR8HB+0FL5ZTGJW2EXq7xfq+S+DMPI7RX+uyM+EO3CZXX/o?= =?us-ascii?Q?5Hz5U3vIYWDeLRjMLaegalykbmYJ1npL+2fSunvKh/b2ZSyyGgZNNqK+NLkq?= =?us-ascii?Q?bzo+lwaHzGQ3w1Sv9wtiXgWTOcTyBt2/9quEi0mmf/c5ft6OpwaCU5EeTnII?= =?us-ascii?Q?mRLDaReWo5XaHFyK2eLV7a2xPY2PlgJHD0IcvDQsLQZCfv5XcQxnFpobzww8?= =?us-ascii?Q?McO5HDSbrp+w+Fv4ankEdiltb2W/58IqfneDc7hpkPm3OXRH23plaTeOcKkl?= =?us-ascii?Q?I8bDVywB3GG9yCiiJPEg/tOMocs5NdoEPRbklvmtmfB4aapL2tYH65/f9YK7?= =?us-ascii?Q?0QTm7L8FSeWiNq/y9fAzU2vHAMFRpEkzInQGKhCXuxNXRCy+DqDuMOTdcqnH?= =?us-ascii?Q?1nM7gqcUUdBt+tdghNXWGj8faj2Z6cadun8+cdJculHGGmRG6zMoAlAEceX5?= =?us-ascii?Q?2V9AN+H7B4qVrRjW4WcJVG4D56i9msVEkMJB0C1Fk7uE2tqT/Mm+IPVC2W+9?= =?us-ascii?Q?GO53xSUvgUxPP/s4DRmoxG73UsXCIMgwkAFauGAi+r1QbwEwR+k+jYYDdCRj?= =?us-ascii?Q?QUeiJ3ky9XJNYTccRcSqI995pM0LABlU?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 16:49:33.6339 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f0a227db-a28a-4bf8-69a5-08dcd66f8ad2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6329 Content-Type: text/plain; charset="utf-8" From: Swapnil Sapkal `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 # perf sched stats report Signed-off-by: Swapnil Sapkal Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark --- tools/lib/perf/include/perf/event.h | 8 +- .../lib/perf/include/perf/schedstat-cpu-v15.h | 27 +- .../lib/perf/include/perf/schedstat-cpu-v16.h | 27 +- .../perf/include/perf/schedstat-domain-v15.h | 153 ++++-- .../perf/include/perf/schedstat-domain-v16.h | 153 ++++-- tools/perf/builtin-sched.c | 475 +++++++++++++++++- tools/perf/util/event.c | 4 +- tools/perf/util/synthetic-events.c | 4 +- 8 files changed, 751 insertions(+), 100 deletions(-) diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/p= erf/event.h index c332d467c9c9..dca03b585766 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -458,13 +458,13 @@ struct perf_record_compressed { }; =20 struct perf_record_schedstat_cpu_v15 { -#define CPU_FIELD(_type, _name, _ver) _type _name; +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) _t= ype _name; #include "schedstat-cpu-v15.h" #undef CPU_FIELD }; =20 struct perf_record_schedstat_cpu_v16 { -#define CPU_FIELD(_type, _name, _ver) _type _name; +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) _t= ype _name; #include "schedstat-cpu-v16.h" #undef CPU_FIELD }; @@ -481,13 +481,13 @@ struct perf_record_schedstat_cpu { }; =20 struct perf_record_schedstat_domain_v15 { -#define DOMAIN_FIELD(_type, _name, _ver) _type _name; +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) _typ= e _name; #include "schedstat-domain-v15.h" #undef DOMAIN_FIELD }; =20 struct perf_record_schedstat_domain_v16 { -#define DOMAIN_FIELD(_type, _name, _ver) _type _name; +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) _typ= e _name; #include "schedstat-domain-v16.h" #undef DOMAIN_FIELD }; diff --git a/tools/lib/perf/include/perf/schedstat-cpu-v15.h b/tools/lib/pe= rf/include/perf/schedstat-cpu-v15.h index 8e4355ee3705..f1d7f8363f39 100644 --- a/tools/lib/perf/include/perf/schedstat-cpu-v15.h +++ b/tools/lib/perf/include/perf/schedstat-cpu-v15.h @@ -1,13 +1,22 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 #ifdef CPU_FIELD -CPU_FIELD(__u32, yld_count, v15) -CPU_FIELD(__u32, array_exp, v15) -CPU_FIELD(__u32, sched_count, v15) -CPU_FIELD(__u32, sched_goidle, v15) -CPU_FIELD(__u32, ttwu_count, v15) -CPU_FIELD(__u32, ttwu_local, v15) -CPU_FIELD(__u64, rq_cpu_time, v15) -CPU_FIELD(__u64, run_delay, v15) -CPU_FIELD(__u64, pcount, v15) +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 diff --git a/tools/lib/perf/include/perf/schedstat-cpu-v16.h b/tools/lib/pe= rf/include/perf/schedstat-cpu-v16.h index f3a55131a05a..ac58d68ec661 100644 --- a/tools/lib/perf/include/perf/schedstat-cpu-v16.h +++ b/tools/lib/perf/include/perf/schedstat-cpu-v16.h @@ -1,13 +1,22 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 #ifdef CPU_FIELD -CPU_FIELD(__u32, yld_count, v16) -CPU_FIELD(__u32, array_exp, v16) -CPU_FIELD(__u32, sched_count, v16) -CPU_FIELD(__u32, sched_goidle, v16) -CPU_FIELD(__u32, ttwu_count, v16) -CPU_FIELD(__u32, ttwu_local, v16) -CPU_FIELD(__u64, rq_cpu_time, v16) -CPU_FIELD(__u64, run_delay, v16) -CPU_FIELD(__u64, pcount, v16) +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 */ diff --git a/tools/lib/perf/include/perf/schedstat-domain-v15.h b/tools/lib= /perf/include/perf/schedstat-domain-v15.h index 422e713d617a..c1f782e08c1f 100644 --- a/tools/lib/perf/include/perf/schedstat-domain-v15.h +++ b/tools/lib/perf/include/perf/schedstat-domain-v15.h @@ -1,40 +1,121 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 #ifdef DOMAIN_FIELD -DOMAIN_FIELD(__u32, idle_lb_count, v15) -DOMAIN_FIELD(__u32, idle_lb_balanced, v15) -DOMAIN_FIELD(__u32, idle_lb_failed, v15) -DOMAIN_FIELD(__u32, idle_lb_imbalance, v15) -DOMAIN_FIELD(__u32, idle_lb_gained, v15) -DOMAIN_FIELD(__u32, idle_lb_hot_gained, v15) -DOMAIN_FIELD(__u32, idle_lb_nobusyq, v15) -DOMAIN_FIELD(__u32, idle_lb_nobusyg, v15) -DOMAIN_FIELD(__u32, busy_lb_count, v15) -DOMAIN_FIELD(__u32, busy_lb_balanced, v15) -DOMAIN_FIELD(__u32, busy_lb_failed, v15) -DOMAIN_FIELD(__u32, busy_lb_imbalance, v15) -DOMAIN_FIELD(__u32, busy_lb_gained, v15) -DOMAIN_FIELD(__u32, busy_lb_hot_gained, v15) -DOMAIN_FIELD(__u32, busy_lb_nobusyq, v15) -DOMAIN_FIELD(__u32, busy_lb_nobusyg, v15) -DOMAIN_FIELD(__u32, newidle_lb_count, v15) -DOMAIN_FIELD(__u32, newidle_lb_balanced, v15) -DOMAIN_FIELD(__u32, newidle_lb_failed, v15) -DOMAIN_FIELD(__u32, newidle_lb_imbalance, v15) -DOMAIN_FIELD(__u32, newidle_lb_gained, v15) -DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v15) -DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v15) -DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v15) -DOMAIN_FIELD(__u32, alb_count, v15) -DOMAIN_FIELD(__u32, alb_failed, v15) -DOMAIN_FIELD(__u32, alb_pushed, v15) -DOMAIN_FIELD(__u32, sbe_count, v15) -DOMAIN_FIELD(__u32, sbe_balanced, v15) -DOMAIN_FIELD(__u32, sbe_pushed, v15) -DOMAIN_FIELD(__u32, sbf_count, v15) -DOMAIN_FIELD(__u32, sbf_balanced, v15) -DOMAIN_FIELD(__u32, sbf_pushed, v15) -DOMAIN_FIELD(__u32, ttwu_wake_remote, v15) -DOMAIN_FIELD(__u32, ttwu_move_affine, v15) -DOMAIN_FIELD(__u32, ttwu_move_balance, v15) +#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("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("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("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("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("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("avg task pulled per successful lb attempt (cpu newly id= le)", "%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/lib/perf/include/perf/schedstat-domain-v16.h b/tools/lib= /perf/include/perf/schedstat-domain-v16.h index d6ef895c9d32..b8038048e662 100644 --- a/tools/lib/perf/include/perf/schedstat-domain-v16.h +++ b/tools/lib/perf/include/perf/schedstat-domain-v16.h @@ -1,40 +1,121 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 #ifdef DOMAIN_FIELD -DOMAIN_FIELD(__u32, busy_lb_count, v16) -DOMAIN_FIELD(__u32, busy_lb_balanced, v16) -DOMAIN_FIELD(__u32, busy_lb_failed, v16) -DOMAIN_FIELD(__u32, busy_lb_imbalance, v16) -DOMAIN_FIELD(__u32, busy_lb_gained, v16) -DOMAIN_FIELD(__u32, busy_lb_hot_gained, v16) -DOMAIN_FIELD(__u32, busy_lb_nobusyq, v16) -DOMAIN_FIELD(__u32, busy_lb_nobusyg, v16) -DOMAIN_FIELD(__u32, idle_lb_count, v16) -DOMAIN_FIELD(__u32, idle_lb_balanced, v16) -DOMAIN_FIELD(__u32, idle_lb_failed, v16) -DOMAIN_FIELD(__u32, idle_lb_imbalance, v16) -DOMAIN_FIELD(__u32, idle_lb_gained, v16) -DOMAIN_FIELD(__u32, idle_lb_hot_gained, v16) -DOMAIN_FIELD(__u32, idle_lb_nobusyq, v16) -DOMAIN_FIELD(__u32, idle_lb_nobusyg, v16) -DOMAIN_FIELD(__u32, newidle_lb_count, v16) -DOMAIN_FIELD(__u32, newidle_lb_balanced, v16) -DOMAIN_FIELD(__u32, newidle_lb_failed, v16) -DOMAIN_FIELD(__u32, newidle_lb_imbalance, v16) -DOMAIN_FIELD(__u32, newidle_lb_gained, v16) -DOMAIN_FIELD(__u32, newidle_lb_hot_gained, v16) -DOMAIN_FIELD(__u32, newidle_lb_nobusyq, v16) -DOMAIN_FIELD(__u32, newidle_lb_nobusyg, v16) -DOMAIN_FIELD(__u32, alb_count, v16) -DOMAIN_FIELD(__u32, alb_failed, v16) -DOMAIN_FIELD(__u32, alb_pushed, v16) -DOMAIN_FIELD(__u32, sbe_count, v16) -DOMAIN_FIELD(__u32, sbe_balanced, v16) -DOMAIN_FIELD(__u32, sbe_pushed, v16) -DOMAIN_FIELD(__u32, sbf_count, v16) -DOMAIN_FIELD(__u32, sbf_balanced, v16) -DOMAIN_FIELD(__u32, sbf_pushed, v16) -DOMAIN_FIELD(__u32, ttwu_wake_remote, v16) -DOMAIN_FIELD(__u32, ttwu_move_affine, v16) -DOMAIN_FIELD(__u32, ttwu_move_balance, v16) +#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("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("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("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("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("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("avg task pulled per successful lb attempt (cpu newly id= le)", "%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/builtin-sched.c b/tools/perf/builtin-sched.c index 6ea0db05aa41..cd465644fce5 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3855,6 +3855,470 @@ static int perf_sched__schedstat_record(struct perf= _sched *sched, return err; } =20 +struct schedstat_domain { + struct perf_record_schedstat_domain *domain_data; + struct schedstat_domain *next; +}; + +struct schedstat_cpu { + struct perf_record_schedstat_cpu *cpu_data; + struct schedstat_domain *domain_head; + struct schedstat_cpu *next; +}; + +struct schedstat_cpu *cpu_head =3D NULL, *cpu_tail =3D NULL, *cpu_second_p= ass =3D NULL; +struct schedstat_domain *domain_tail =3D NULL, *domain_second_pass =3D NUL= L; + +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 + } + +#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 + } +#undef DOMAIN_FIELD +} + +static void print_separator(size_t pre_dash_cnt, const char *s, size_t pos= t_dash_cnt) +{ + size_t i; + + for (i =3D 0; i < pre_dash_cnt; ++i) + printf("-"); + + printf("%s", s); + + for (i =3D 0; i < post_dash_cnt; ++i) + printf("-"); + + printf("\n"); +} + +static inline void print_cpu_stats(struct perf_record_schedstat_cpu *cs) +{ +#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 { \ + if (_is_pct) { \ + printf("%-60s: " _format " ( %3.2lf%% )\n", _desc, \ + cs->_ver._name, \ + CALC_PCT(cs->_ver._name, cs->_ver._pct_of)); \ + } else { \ + printf("%-60s: " _format "\n", _desc, cs->_ver._name); \ + } \ + } while (0); + + if (cs->version =3D=3D 15) { +#include + } else if (cs->version =3D=3D 16) { +#include + } + +#undef CPU_FIELD +#undef CALC_PCT +} + +static inline void print_domain_stats(struct perf_record_schedstat_domain = *ds, + __u64 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_separator(_pre_dash_cnt, _desc, _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 { \ + if (_is_jiffies) { \ + printf("%-65s: " _format " $ %11.2Lf $\n", _desc, \ + ds->_ver._name, \ + CALC_AVG(jiffies, ds->_ver._name)); \ + } else { \ + printf("%-65s: " _format "\n", _desc, ds->_ver._name); \ + } \ + } while (0); + +#define DERIVED_CNT_FIELD(_desc, _format, _x, _y, _z, _ver) \ + do { \ + printf("*%-64s: " _format "\n", _desc, \ + (ds->_ver._x) - (ds->_ver._y) - (ds->_ver._z)); \ + } while (0); + +#define DERIVED_AVG_FIELD(_desc, _format, _x, _y, _z, _w, _ver) \ + do { \ + printf("*%-64s: " _format "\n", _desc, CALC_AVG(ds->_ver._w, \ + ((ds->_ver._x) - (ds->_ver._y) - (ds->_ver._z)))); \ + } while (0); + + if (ds->version =3D=3D 15) { +#include + } else if (ds->version =3D=3D 16) { +#include + } + +#undef DERIVED_AVG_FIELD +#undef DERIVED_CNT_FIELD +#undef DOMAIN_FIELD +#undef CALC_AVG +#undef DOMAIN_CATEGORY +} + +static void print_domain_cpu_list(struct perf_record_schedstat_domain *ds) +{ + char bin[16][5] =3D {"0000", "0001", "0010", "0011", + "0100", "0101", "0110", "0111", + "1000", "1001", "1010", "1011", + "1100", "1101", "1110", "1111"}; + bool print_flag =3D false, low =3D true; + int cpu =3D 0, start, end, idx; + + idx =3D ((ds->nr_cpus + 7) >> 3) - 1; + + printf("<"); + while (idx >=3D 0) { + __u8 index; + + if (low) + index =3D ds->cpu_mask[idx] & 0xf; + else + index =3D (ds->cpu_mask[idx--] & 0xf0) >> 4; + + for (int i =3D 3; i >=3D 0; i--) { + if (!print_flag && bin[index][i] =3D=3D '1') { + start =3D cpu; + print_flag =3D true; + } else if (print_flag && bin[index][i] =3D=3D '0') { + end =3D cpu - 1; + print_flag =3D false; + if (start =3D=3D end) + printf("%d, ", start); + else + printf("%d-%d, ", start, end); + } + cpu++; + } + + low =3D !low; + } + + if (print_flag) { + if (start =3D=3D cpu-1) + printf("%d, ", start); + else + printf("%d-%d, ", start, cpu-1); + } + printf("\b\b>\n"); +} + +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 + } +#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 + } +#undef DOMAIN_FIELD +} + +/* FIXME: The code fails (segfaults) when one or ore cpus are offline. */ +static void show_schedstat_data(void) +{ + struct schedstat_domain *dptr =3D NULL, *tdptr =3D NULL, *dtail =3D NULL; + struct schedstat_cpu *cptr =3D cpu_head, *summary_head; + struct perf_record_schedstat_domain *ds =3D NULL; + struct perf_record_schedstat_cpu *cs =3D NULL; + __u64 jiffies =3D cptr->cpu_data->timestamp; + bool is_last =3D false, is_summary =3D true; + int cnt =3D 0; + + print_separator(100, "", 0); + printf("Time elapsed (in jiffies) : %11= llu\n", jiffies); + print_separator(100, "", 0); + + if (cptr) { + summary_head =3D zalloc(sizeof(*summary_head)); + summary_head->cpu_data =3D zalloc(sizeof(*cs)); + memcpy(summary_head->cpu_data, cptr->cpu_data, sizeof(*cs)); + summary_head->next =3D NULL; + summary_head->domain_head =3D NULL; + dptr =3D cptr->domain_head; + + while (dptr) { + size_t cpu_mask_size =3D (dptr->domain_data->nr_cpus + 7) >> 3; + + tdptr =3D zalloc(sizeof(*tdptr)); + tdptr->domain_data =3D zalloc(sizeof(*ds) + cpu_mask_size); + memcpy(tdptr->domain_data, dptr->domain_data, sizeof(*ds) + cpu_mask_si= ze); + + tdptr->next =3D NULL; + if (!dtail) { + summary_head->domain_head =3D tdptr; + dtail =3D tdptr; + } else { + dtail->next =3D tdptr; + dtail =3D dtail->next; + } + dptr =3D dptr->next; + } + } + + cptr =3D cpu_head; + while (cptr) { + if (!cptr->next) + is_last =3D true; + + cnt++; + summarize_schedstat_cpu(summary_head, cptr, cnt, is_last); + tdptr =3D summary_head->domain_head; + dptr =3D cptr->domain_head; + + while (tdptr) { + summarize_schedstat_domain(tdptr, dptr, cnt, is_last); + tdptr =3D tdptr->next; + dptr =3D dptr->next; + } + cptr =3D cptr->next; + } + + cptr =3D cpu_head; + summary_head->next =3D cptr; + cptr =3D summary_head; + while (cptr) { + cs =3D cptr->cpu_data; + printf("\n"); + print_separator(100, "", 0); + if (is_summary) + printf("CPU \n"); + else + printf("CPU %d\n", cs->cpu); + + print_separator(100, "", 0); + print_cpu_stats(cs); + print_separator(100, "", 0); + + dptr =3D cptr->domain_head; + + while (dptr) { + ds =3D dptr->domain_data; + if (is_summary) + if (ds->name[0]) + printf("CPU , DOMAIN %s\n", ds->name); + else + printf("CPU , DOMAIN %d\n", ds->domain); + else { + if (ds->name[0]) + printf("CPU %d, DOMAIN %s CPUS ", cs->cpu, ds->name); + else + printf("CPU %d, DOMAIN %d CPUS ", cs->cpu, ds->domain); + + print_domain_cpu_list(ds); + } + print_domain_stats(ds, jiffies); + print_separator(100, "", 0); + + dptr =3D dptr->next; + } + is_summary =3D false; + cptr =3D cptr->next; + } +} + +static int perf_sched__process_schedstat(struct perf_session *session __ma= ybe_unused, + union perf_event *event) +{ + static bool after_workload_flag; + 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(struct schedstat_cpu)); + + temp->cpu_data =3D zalloc(sizeof(struct perf_record_schedstat_cpu)); + memcpy(temp->cpu_data, &event->schedstat_cpu, + sizeof(struct perf_record_schedstat_cpu)); + temp->next =3D NULL; + temp->domain_head =3D NULL; + + if (cpu_head && temp->cpu_data->cpu =3D=3D initial_cpu) + after_workload_flag =3D true; + + if (!after_workload_flag) { + if (!cpu_head) { + initial_cpu =3D temp->cpu_data->cpu; + cpu_head =3D temp; + } else + cpu_tail->next =3D temp; + + cpu_tail =3D temp; + } else { + if (temp->cpu_data->cpu =3D=3D initial_cpu) { + cpu_second_pass =3D cpu_head; + cpu_head->cpu_data->timestamp =3D + temp->cpu_data->timestamp - cpu_second_pass->cpu_data->timestamp; + } else { + cpu_second_pass =3D cpu_second_pass->next; + } + domain_second_pass =3D cpu_second_pass->domain_head; + store_schedtstat_cpu_diff(temp); + } + } else if (event->header.type =3D=3D PERF_RECORD_SCHEDSTAT_DOMAIN) { + size_t cpu_mask_size =3D (event->schedstat_domain.nr_cpus + 7) >> 3; + struct schedstat_domain *temp =3D zalloc(sizeof(struct schedstat_domain)= ); + + temp->domain_data =3D zalloc(sizeof(struct perf_record_schedstat_domain)= + cpu_mask_size); + memcpy(temp->domain_data, &event->schedstat_domain, + sizeof(struct perf_record_schedstat_domain) + cpu_mask_size); + temp->next =3D NULL; + + if (!after_workload_flag) { + if (cpu_tail->domain_head =3D=3D NULL) { + cpu_tail->domain_head =3D temp; + domain_tail =3D temp; + } else { + domain_tail->next =3D temp; + domain_tail =3D temp; + } + } else { + store_schedstat_domain_diff(temp); + domain_second_pass =3D domain_second_pass->next; + } + } + + return 0; +} + +static void free_schedstat(void) +{ + struct schedstat_cpu *cptr =3D cpu_head, *tmp_cptr; + struct schedstat_domain *dptr =3D NULL, *tmp_dptr; + + while (cptr) { + tmp_cptr =3D cptr; + dptr =3D cptr->domain_head; + + while (dptr) { + tmp_dptr =3D dptr; + dptr =3D dptr->next; + free(tmp_dptr); + } + cptr =3D cptr->next; + free(tmp_cptr); + } +} + +static int perf_sched__schedstat_report(struct perf_sched *sched) +{ + struct perf_session *session; + struct perf_data data =3D { + .path =3D input_name, + .mode =3D PERF_DATA_MODE_READ, + }; + int err; + + if (cpu_list) { + user_requested_cpus =3D perf_cpu_map__new(cpu_list); + if (!user_requested_cpus) + return -EINVAL; + } + + 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); + } + + err =3D perf_session__process_events(session); + + perf_session__delete(session); + if (!err) { + setup_pager(); + show_schedstat_data(); + free_schedstat(); + } + return err; +} + static bool schedstat_events_exposed(void) { /* @@ -4031,6 +4495,8 @@ 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"), @@ -4054,7 +4520,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", @@ -4156,7 +4622,7 @@ int cmd_sched(int argc, const char **argv) =20 return 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, @@ -4168,6 +4634,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/event.c b/tools/perf/util/event.c index d138e4a5787c..0f14fe225be0 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -560,7 +560,7 @@ size_t perf_event__fprintf_schedstat_cpu(union perf_eve= nt *event, FILE *fp) =20 size =3D fprintf(fp, "\ncpu%u ", cs->cpu); =20 -#define CPU_FIELD(_type, _name, _ver) \ +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ size +=3D fprintf(fp, "%" PRIu64 " ", (unsigned long)cs->_ver._name); \ =20 if (version =3D=3D 15) { @@ -638,7 +638,7 @@ size_t perf_event__fprintf_schedstat_domain(union perf_= event *event, FILE *fp) size +=3D fprintf(fp, "%s ", cpu_mask); free(cpu_mask); =20 -#define DOMAIN_FIELD(_type, _name, _ver) \ +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ size +=3D fprintf(fp, "%" PRIu64 " ", (unsigned long)ds->_ver._name); \ =20 if (version =3D=3D 15) { diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 73b2492a4cde..24f9cb95d07d 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2535,7 +2535,7 @@ static union perf_event *__synthesize_schedstat_cpu(s= truct io *io, __u16 version if (io__get_dec(io, (__u64 *)&cs->cpu) !=3D ' ') goto out_cpu; =20 -#define CPU_FIELD(_type, _name, _ver) \ +#define CPU_FIELD(_type, _name, _desc, _format, _is_pct, _pct_of, _ver) \ do { \ __u64 _tmp; \ ch =3D io__get_dec(io, &_tmp); \ @@ -2658,7 +2658,7 @@ static union perf_event *__synthesize_schedstat_domai= n(struct io *io, __u16 vers free(d_name); free(cpu_mask); =20 -#define DOMAIN_FIELD(_type, _name, _ver) \ +#define DOMAIN_FIELD(_type, _name, _desc, _format, _is_jiffies, _ver) \ do { \ __u64 _tmp; \ ch =3D io__get_dec(io, &_tmp); \ --=20 2.46.0 From nobody Fri Nov 29 19:28:28 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2081.outbound.protection.outlook.com [40.107.93.81]) (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 A9416158545; Mon, 16 Sep 2024 16:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505389; cv=fail; b=iM76igPZwDGeE3kLPziWHswtweuwtjrPHr9heSvJMlzaw2ZvOfMwqpUVvFK1s42xaHML5MWnHQq20g6tXX+WVK/wXy1GYEz7bHw4/FvBsWn6ixTJqvdaGJSjgZ5a0Fl+fPFNf7LSYbY7EsnJc/xDszC1VUFsOMHJX6hGP9bUJh4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726505389; c=relaxed/simple; bh=lujTFRQjg9R6ZufJYgu4bwbEKRtDCVdPKcYTBVNey9k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uVka7N3/UXv0PshykSE0cjCxSGOfG/03roBucI4Ck36Cgn1qg2fXPv+MftyL8hnnFNKJJU6hsSFJAdIRiWq4YWEofuyNa78FTo0X8nTLxHeaXSF1xx7jYllAGE7klq+GMmpyRzATdD52RrsXGeksNWohVfnJ7NbwwobuQM7+Mt0= 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=hnBuBvD8; arc=fail smtp.client-ip=40.107.93.81 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="hnBuBvD8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MHchqQ6d8a0KBpXa9QUUd/PLbl/JpvhfvwRe+on0AsBzf5JTWN6zUZ7JnBVWMrLJmsaR4qZAxfZLjAG85I/00wfSQw8ypEATjrBXk5hiqC1eg1GlPcUIUEMIMYyPzpBGKmASF8gTqQ/B7iwfhDxlHZ3eeLhsW4EARsKqTN4EnYcZ/6LUV1iSX4BXbW+RKkuCEnkc/DiLvasi9IiUvyeqOSXBlCwnnn5h11wpSLUTFm2TyQtUusQAePU95MO/1U3AuBygCX/MCTTw+eMvbouAEJ61InZUUslWgL2ziphQLKLlKQOhxjrh1IA4ki1OWHqtOZDb82+taR/OmbcPaBrheg== 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=C4FuknXIPA/AzQ8XWz8rRWxh7WlgYLMFE13j2az6he8=; b=lWj6KhrtPXtVrDTCxBUp8TYfVlw8u82z2f0hmztJeMGw8RMYluHqE66iJ8a326xhHVHazbrHi4k3wJ6ow6ROzcZXVbyTvVeKNlKTa8DsiX3CPoNR7Lgi1ngPXXZ//oJzyheinRGXkhsgpaO0tvJqo4WcAU8QzBfYtrP82nnzM2P3SdLeFBiq6+h5XebTmkYk97HZl2lWzXUANZcYdlMoG8MWZzLwcsqAA5gMdiu/XYzguCuNwDkB95L1mn5bF9nwDBoyUrGEkee6xErb4h0GX39+/rs5rSilfFg+zHj3i1WTMtVt+36UAO1XmYibPfGhP4FotgyAbukONkuiQStfqg== 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=C4FuknXIPA/AzQ8XWz8rRWxh7WlgYLMFE13j2az6he8=; b=hnBuBvD8ntcTzphrIdGv5nTfkeDeP1a2gvZ2YoSiuEGtV3bimHILk2bmh46KxX2TJBMXw4AdjkuN6qsNm047B2VUFo2eA7hOiTQxl5oz4ryLiz8KowHm0DWctErp/8+vcG3NsTTyZV4P7bwlyj1Agyf18BuDeQAuwcx9B4uzZaA= Received: from SJ0PR13CA0128.namprd13.prod.outlook.com (2603:10b6:a03:2c6::13) by IA0PR12MB8424.namprd12.prod.outlook.com (2603:10b6:208:40c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Mon, 16 Sep 2024 16:49:41 +0000 Received: from SJ1PEPF0000231F.namprd03.prod.outlook.com (2603:10b6:a03:2c6:cafe::5a) by SJ0PR13CA0128.outlook.office365.com (2603:10b6:a03:2c6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23 via Frontend Transport; Mon, 16 Sep 2024 16:49: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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF0000231F.mail.protection.outlook.com (10.167.242.235) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 16:49:41 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 16 Sep 2024 11:49:33 -0500 From: Ravi Bangoria To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 5/5] perf sched stats: Add support for live mode Date: Mon, 16 Sep 2024 16:47:22 +0000 Message-ID: <20240916164722.1838-6-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240916164722.1838-1-ravi.bangoria@amd.com> References: <20240916164722.1838-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231F:EE_|IA0PR12MB8424:EE_ X-MS-Office365-Filtering-Correlation-Id: fce5aa9f-7e51-4d13-b1c2-08dcd66f8f35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?3vvvSzl0J7Ciw6KHq4rucPB8jGfpAMio+/xCU3T90vB6XlmFQrBr2ySLhdur?= =?us-ascii?Q?Hyd/9RIS0ajxQiay3nAJDp6l2z2Uesy5536tas9vTOl3dgESPhyHSCFzIIGU?= =?us-ascii?Q?lnXCY7URJwEmDD8oaYmRTBtBg0LKOQOyN1koFc84anQxlIlj7UbmXaNj3qbZ?= =?us-ascii?Q?xZ0qbCeG59s2LkX5Sz5vq1X4KWkQ6Qn9NEElQo6Vyy9XcQ45s179kFb57tz4?= =?us-ascii?Q?liDtB7Q0mLj86bga89e7e6SkumPAKxLieZshGte2jzgXavEHvloWj5rWClcG?= =?us-ascii?Q?QQBgaVSc40N6IsF1ehbXAeEzp/U3MM6XhJgxvBdxZiRdo26RnrxeXgyXPzNn?= =?us-ascii?Q?hU9mkPPg1o8Ee4ssXNp/X2A7YJs9KfCLwjV3WU1+cpmIJq6F/XB243LBEloQ?= =?us-ascii?Q?ce/pS6kenziGWJN6OLRyCJGE80rbZDLqUdrGN5zWFEqW2EXN9Oej9PIVgFZD?= =?us-ascii?Q?5HhtCLw1yfmg4iQpcA+kGizjSp/H7yy0SMw/FX56wNk6pjJsDwGWilaJXn3+?= =?us-ascii?Q?LSFw7e21YkiMbz3XQDA43y9txrjDHkxSWo39kbcyBK59NNCXJ9Yc7zQ21hfT?= =?us-ascii?Q?zU1eGWj7BCKw0uJjpNw5JDMgNN2Li3K1oqgkYkB7710EUtTh9+h7KUWpbATr?= =?us-ascii?Q?7hwSzRZzAj0S5HiDykfUDyTVBEpRqJ+IjMp+czcONxj53B2R5Ek5vqHJTuIE?= =?us-ascii?Q?jIyZLH7HzKWJcdzAgPiVyltabvBk16DL+PAByg2cVP3uPWWyH8lgVZzQtDKQ?= =?us-ascii?Q?vOrn6YVaRNTOPaS6bVQPnQc8zm69/lHh6H4gllDGADeSTmpsq4EMnZvTyedw?= =?us-ascii?Q?wfYHkZSgzFGuhmliCewcz3iAKt9UHWocyLWPzocrSiqzH/nxxMdBUYE00LKm?= =?us-ascii?Q?mOS8lSHaevdRzH7xPbB/eaUwI0sZCIf3Kb8N3Icqzb6ZY8BhR9HonFXjqQEm?= =?us-ascii?Q?c4OcK6ZHVroYajPluaJOIdOlqyKsfOnDPR3T7fawd/6Ar6Eh2bzVlDEGT7Ig?= =?us-ascii?Q?HXunjgI6Kj0xfyS/u7sGJ6lKwHFBdBRb0jGwXLQ61iPGQ5RfFNvs6gsup6QI?= =?us-ascii?Q?8BjBU2g0ucy35bah7xSMimTWjt0gv++IcX+M85ohTtTmqdyGp6QsWBas/o/f?= =?us-ascii?Q?yVeAOP4iaJuUIT9v0OFVot8gN4wEkAkZ5jqk0+xL4nt0h2TO+P/7yPgQ1ydN?= =?us-ascii?Q?puXYAIrZ8FLCiuo9ED58MKAxqv/NpUj5h0U8tQWSothiAVgfV8tobdXO6h5g?= =?us-ascii?Q?v3ECivLuX7BHwRZQJStL4OXoCQ+PCLTEYfFfWo/Pa1mimA7h+papk1SL3G3x?= =?us-ascii?Q?WyEuH49lAlopidaG/NuqE5BNrTzzZ6h3FvNslMz6iE/xWi9ooeLH7rh0sI0E?= =?us-ascii?Q?AdPdq6jhQnImI2zHkG9FlYEHrDkoaJ/2S9jMr4Ewp5copkc8QYkNpI7RMjI6?= =?us-ascii?Q?giZHzapVz0zD6sM81hAI7G0RS9EZc08x?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 16:49:41.0736 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fce5aa9f-7e51-4d13-b1c2-08dcd66f8f35 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8424 Content-Type: text/plain; charset="utf-8" From: Swapnil Sapkal 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 -- sleep 10 Signed-off-by: Swapnil Sapkal Co-developed-by: Ravi Bangoria Signed-off-by: Ravi Bangoria Tested-by: James Clark --- tools/perf/builtin-sched.c | 87 +++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index cd465644fce5..e888ae763eac 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -4319,6 +4319,91 @@ 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(NULL, event); +} + +static int perf_sched__schedstat_live(struct perf_sched *sched, + int argc, const char **argv) +{ + struct evlist *evlist; + struct target *target; + 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. + */ + target =3D zalloc(sizeof(struct target)); + 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_target; + } + + if (cpu_list) { + user_requested_cpus =3D perf_cpu_map__new(cpu_list); + if (!user_requested_cpus) + goto out_target; + } + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_event_live, + user_requested_cpus); + if (err < 0) + goto out_target; + + err =3D enable_sched_schedstats(&reset); + if (err < 0) + goto out_target; + + if (argc) + evlist__start_workload(evlist); + + /* wait for signal */ + pause(); + + if (reset) { + err =3D disable_sched_schedstat(); + if (err < 0) + goto out_target; + } + + err =3D perf_event__synthesize_schedstat(&(sched->tool), + process_synthesized_event_live, + user_requested_cpus); + if (err) + goto out_target; + + setup_pager(); + show_schedstat_data(); + free_schedstat(); +out_target: + free(target); + return err; +} + static bool schedstat_events_exposed(void) { /* @@ -4640,7 +4725,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); } --=20 2.46.0