From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE254606A322 for ; Wed, 2 Dec 2026 23:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=S3k6xNpc Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E59010EAEB; Wed, 2 Dec 2026 23:17:16 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BB6610E158 for ; Wed, 2 Dec 2026 23:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796253371; x=1827789371; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=LpyE/pKGyrQYPrP/M4NquL0531rc90/AuY4+05isV+Y=; b=S3k6xNpc0+dg5+1HIrEKgq2CalVbUWPRf19cNqK0UrL3uQMGIcLmHsRX WrqFYw5et4qkcyCQefiULHbWpdxoDJbN+2GTSdG2m5+vt5FcoiaJ3jdmy FWobrA0VEM3DL0kYJ1SH+Oeja9qXUeNoEe4Y4q1wAk79MEi2RcMazS9RG 2lShg4qocBqT6K3eCaYG7ONSWlnhoentX+hgQRrxEiXwW4Pb0ZdvhPIgE L3TRLYfbaZKj9E7nwiRnHMvhKyfLI/575KkRUpesETohD3fapfDoyj8M7 +xejTLYtUx2agnOQb4uSv12UkjJvJldHLVnDK1FlFqaZKhp5Ad87wKu9j A==; X-CSE-ConnectionGUID: 4bLjvrRfSmSyh/22aCKg/g== X-CSE-MsgGUID: 4+vSwnPdQcaS+cK3f5D4Yg== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5104227" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5104227" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:16:11 -0800 X-CSE-ConnectionGUID: EK2URsAqQQ2ztwQP/qHERw== X-CSE-MsgGUID: /jtyzmqGS7ONtghWKh+Vnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13480762" Received: from fmsmsx903.amr.corp.intel.com ([10.18.126.92]) by orviesa004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:16:10 -0800 Received: from FMSMSX902.amr.corp.intel.com (10.18.126.91) by fmsmsx903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 15:16:10 -0800 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by FMSMSX902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 15:16:10 -0800 Received: from PH8PR06CU001.outbound.protection.outlook.com (40.107.209.51) by edgegateway.intel.com (192.55.55.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 15:16:10 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F/oqqlWAsD/Lepfa0+uK9r13SjmLNdof3Oc+UCCB5Uhq3gSQstVspwDSjTk9l+f0xLi0sjrfwl2ENVMeQ3H/0KntUyu4cSsi4t/z93grKuDMt/5TI3R+A4VWxbJx9zk194dqed+HzlZLUTCRu2VNsWmehehafkyic0ZNs77hzlJNlJWaiVmLIrLKgoZu9+hCV50KP/SaHVUOS72bulNPxlc4AslpN/OfTDbl96hcqgJj75XM95o7aUJTtDEuYkhGKp19+QDI4uxCX5iqw0IPE3e3+vg6rIxBYJbQOazqxfWeTlnPbse5J2ao4ohFV+Mjg1wNplcrWDWhBT8e8J2bTQ== 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=LpyE/pKGyrQYPrP/M4NquL0531rc90/AuY4+05isV+Y=; b=zG5IrWuk0hC7yNN4VnnYHOUP4gekxcisT0zJFhyLOpHYl3PK7jNFD3gyAGYCKgOu5ry8a+6KmctqNf93MMWLFOJcab4RxFdfi+VDR3RtcJOFL+RxeAJKCEbYeIeq2giAknG93aejOD9eySnbnN+loE1Mijsxi/8MrXTYpNYXCx3Bta30ct3OQpjvU7SMpAjZgRZixDjWq7J8t5q+5OIoEgxeKu/Xltmy/RIwMfgIA7cxN75AQKndgPpF61120LXcRbRThw444fHMotoOEpCC+tlu8uxMH0KhtZVEbHmNQWilsdcTfrZvTcJ4TkgUM2K7VBSL8lxngEcPS8qYiEdWNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS3PR11MB619106.namprd11.prod.outlook.com (2603:10b6:8:43e::11) by SJ0PR11MB6743.namprd11.prod.outlook.com (2603:10b6:a03:47c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 23:16:02 +0000 Received: from DS3PR11MB619106.namprd11.prod.outlook.com ([fe80::3637:8d63:f875:b4ee]) by DS3PR11MB619106.namprd11.prod.outlook.com ([fe80::3637:8d63:f875:b4ee%7]) with mapi id 15.21.0688.010; Wed, 2 Dec 2026 23:16:02 +0000 Message-ID: Date: Wed, 2 Dec 2026 15:16:01 -0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] lib/xe/xe_gt: Add xe_gt_wait_c6_stable() To: Zongyao Bai , CC: References: <20261119005009.364632-1-zongyao.bai@intel.com> <20261119005009.364632-2-zongyao.bai@intel.com> Content-Language: en-US From: "Yao, Jia" In-Reply-To: <20261119005009.364632-2-zongyao.bai@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SJ0PR03CA0383.namprd03.prod.outlook.com (2603:10b6:a03:3a1::28) To DS3PR11MB619106.namprd11.prod.outlook.com (2603:10b6:8:43e::11) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PR11MB619106:EE_|SJ0PR11MB6743:EE_ X-MS-Office365-Filtering-Correlation-Id: a11b5f32-da98-4f82-70ae-08df50ca3b83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|42112799006|1800799024|366016|23010399003|376014|6133799003|4143699003|18002099003|22082099003|56012099006|261022105027099003|11063799006|10067099003|261021135927099003|261026140227099003|261102123227099003|261022075727099003|261026121527099003|261021121427099003|261009223027099003|261028144727099003; X-Microsoft-Antispam-Message-Info: 6urXmExoDAF9mAckZfIOc9B/mpPqI1oT6YN6b7bkPTs6wYZdRIrgYl7+NsyJtaBxjANvACtg7yBtVyjOgmgk+F98puRuaGrnTQO9p1M1l4sRB4P2m+ypmYmAlxbFGnWV/MIZkJYjCNziSZPZW7B2UlFeqG1VpNxJEqF7E7bbbkzO2/ZwFUmJe/EMskVyQhppg8SOd1Rs6WH3ivMhO1a2sHTCGq9Sb8JrNNbh7prXJOC+nrRpPdYMXx44j1HtjKHVRdWZcRGCoSZpTY36x19lulWPHoQybp7/4HUMhCWAjv+bEvIOMuDWtyCVxBV0IuyMt4o1a7mdx0tw0OJN326lUGfjn9pHVSvDsyi+STnI1MKZaEV2Ef6Xplb7ddguug00y5459CN8++brGNwWeAmPddhkLv3m6/0eVPASXH7sfrgMcSgL+mlNVV8UGkjxWouWxA8aZeZrQbw8RiMnR9wVmV9WutkNOoSMLYlIMceHJ8ca5zZv7OMt56sdPZfjXpVQ5Pb5prC7UtvlrIeBAmLM6Mixk2yeXjQtDETOA+Zr4FI6t2OKDOHiLQVEps3MsS199DODasBRgvITuW4Ny9fVfEJSrxUIzRycA8Td1yvmpp5cvRwkaYIcqCLMAnWTM4AxhE3B87BSIh3ORad4KI5cxg+GAjcr8dx622kLOGCyLqY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS3PR11MB619106.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(42112799006)(1800799024)(366016)(23010399003)(376014)(6133799003)(4143699003)(18002099003)(22082099003)(56012099006)(261022105027099003)(11063799006)(10067099003)(261021135927099003)(261026140227099003)(261102123227099003)(261022075727099003)(261026121527099003)(261021121427099003)(261009223027099003)(261028144727099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SWJtNkU3OEpZbVR4YTVPLzg5aXEvanJ5RVVpSzE0NEwybHBrMDY5MlJMTWlY?= =?utf-8?B?SDR3cFQ0NWhvbUFFY2hnLzUyZlo3aVNLeWg3N1Q0T2lzT3B0WkNaN3lVMzFx?= =?utf-8?B?NjRUVmFqU1ExUG1p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lRib1VLL2pMUzFv?= =?utf-8?B?K1pTWTdVWEh2TGVMTnVSWjhJUUZhT0M3b2Zlc2pXQ1NicGZHRDRJRDlZblNN?= =?utf-8?B?SGZZVVNCcnlNa2dkekQvd05EcTN0bzZvNWlTZ3IyY29Ub3dTRnlwdXN1bTh0?= =?utf-8?B?N3RpOGJpOWRDb2JDcWtYb2V5cEZ6akVUUVpmR0dyYlVPZTFDRU9xd0E4RUZn?= =?utf-8?B?WGtLN1E5c3RzbGx2cEJROWFjY0NYaUtiNC9kdjRYUHRoVGl0MHhnQVdLQTUy?= =?utf-8?B?UGtacVRhcDFNOU8zMlFWSjRkN1VXVXhTTHNJWFplajlBT0ViTjFwRzhBMGVR?= =?utf-8?B?TXZJdEl3YkhmQzVLV2VhcnVkbThiMUg4RThWRHMyeXlzenpWT25qNkxwSjlQ?= =?utf-8?B?d0Noa2NQSHN3TFRkUXJjL2pxRHRCbkg3VkRQaFFjczBtYk5JMVFzdz09?= X-Exchange-RoutingPolicyChecked: nU0bhSckFDLasIEefRK/0GgM86/JwBLti8Ki2Uxm2Gb4EM4kDCi+2bsvmR9oKIOM9RJDbz1g/lnVNOF5pC9wflv0COmfNPre05FkZAMT0xepqCRWygT4B1xpgjvMTG1FwFrxfeG4dYNTUCLWfMZpvNYNIFtO6OIHhONnLF6dbul0SHZ4plbs+UW28AF04yDBI2LruUnn+v1OydFmLVP/r49XRBBWQjQSLa3UNlsLW2+DTsUUJefPitbJgAJ43lAXl8JTNDZ9YuL1dt8pM2O7Y09fwRS6F/HfRi7V3mylsgfSN1bVMY+BOAho+HYSURYqwv6AlbHZncwBO3b9uBsRtw== X-MS-Exchange-CrossTenant-Network-Message-Id: a11b5f32-da98-4f82-70ae-08df50ca3b83 X-MS-Exchange-CrossTenant-AuthSource: DS3PR11MB619106.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 23:16:02.2991 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rGUgb3iNVQYt+OJfgdqSrbXwc3nGbZsz7LSmMWVjFpbSdVk++hFUYQktEX3+tayNGo5iaLFrcRwAscjTrq2rmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB6743 X-OriginatorOrg: intel.com X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "igt-dev" X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 LGTM. Reviewed-by: Jia Yao On 11/18/2026 4:50 PM, Zongyao Bai wrote: > xe_gt_is_in_c6() only reports the instantaneous GT idle state, so waiting > for it once (e.g. igt_wait(xe_gt_is_in_c6())) can succeed on a transient > visit to C6 while the GT is still woken up repeatedly by deferred work > of a previous test (such as the teardown of resources released at fd > close). > > Add xe_gt_wait_c6_stable() which requires the GT to stay in gt-c6 in > every 10ms sample during a window of @stable_ms and the idle residency > counter to advance by at least 95% of that window, restarting the window > otherwise, with an overall timeout. The window is measured conservatively > (bracketing the counter read with timestamps and allowing for the 1ms > truncation of the counter) so that being preempted does not cause a false > restart, hence @stable_ms must be at least 50. > > Signed-off-by: Zongyao Bai > --- > lib/xe/xe_gt.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ > lib/xe/xe_gt.h | 2 ++ > 2 files changed, 92 insertions(+) > > diff --git a/lib/xe/xe_gt.c b/lib/xe/xe_gt.c > index 1f0b77986..250b15f0c 100644 > --- a/lib/xe/xe_gt.c > +++ b/lib/xe/xe_gt.c > @@ -5,7 +5,10 @@ > > #include > #include > +#include > #include > +#include > +#include > > #include "igt_core.h" > #include "igt_debugfs.h" > @@ -230,6 +233,93 @@ bool xe_gt_is_in_c6(int fd, int gt) > return false; > } > > +/** > + * xe_gt_wait_c6_stable: > + * @fd: pointer to xe drm fd > + * @gt: gt number > + * @stable_ms: time in ms the GT has to stay in C6 without interruption, > + * at least 50 since the idle residency counter has 1ms resolution > + * @timeout_ms: maximum time in ms to wait for such a stable window > + * > + * Wait until @gt reports "gt-c6" in every sample (polled every 10ms) during > + * a window of at least @stable_ms and, additionally, the idle residency > + * counter advanced by at least 95% of that window. This is stronger than > + * xe_gt_is_in_c6(), which can be satisfied by a single transient visit to C6 > + * while the GT is still being woken up by deferred work (e.g. the teardown of > + * resources released by a previous test). Whenever the condition is violated > + * the window is restarted. > + * > + * Returns: true if a stable window was observed within @timeout_ms, false > + * otherwise. > + */ > +bool xe_gt_wait_c6_stable(int fd, int gt, unsigned int stable_ms, > + unsigned int timeout_ms) > +{ > + struct timespec t_begin, t_pre, t_post, t_win = {}; > + unsigned long res_win = 0, res; > + char state[16]; > + bool in_window = false, ret = false; > + int gt_fd; > + > + igt_assert(stable_ms >= 50); > + > + gt_fd = xe_sysfs_gt_open(fd, gt); > + igt_assert(gt_fd >= 0); > + > + clock_gettime(CLOCK_MONOTONIC, &t_begin); > + do { > + unsigned long elapsed; > + > + igt_assert(igt_sysfs_scanf(gt_fd, "gtidle/idle_status", "%15s", > + state) == 1); > + /* > + * Bracket the residency read with timestamps: the window > + * is measured from the end of the first read to the start > + * of the last one, so being preempted around the reads can > + * only make the check more lenient, never fail it. > + */ > + clock_gettime(CLOCK_MONOTONIC, &t_pre); > + igt_assert(igt_sysfs_scanf(gt_fd, "gtidle/idle_residency_ms", > + "%lu", &res) == 1); > + clock_gettime(CLOCK_MONOTONIC, &t_post); > + > + if (strcmp(state, "gt-c6")) { > + in_window = false; > + } else if (!in_window) { > + t_win = t_post; > + res_win = res; > + in_window = true; > + } else { > + elapsed = igt_time_elapsed(&t_win, &t_pre) * MSEC_PER_SEC; > + if (elapsed >= stable_ms) { > + /* +1: the counter is truncated to whole ms */ > + if ((res - res_win + 1) * 100 >= elapsed * 95) { > + ret = true; > + break; > + } > + /* C6 counter did not follow, start over */ > + t_win = t_post; > + res_win = res; > + } > + } > + > + usleep(10 * 1000); > + clock_gettime(CLOCK_MONOTONIC, &t_post); > + } while (igt_time_elapsed(&t_begin, &t_post) * MSEC_PER_SEC < timeout_ms); > + > + close(gt_fd); > + if (ret) > + igt_debug("GT%d C6 stable after %.0fms\n", gt, > + igt_time_elapsed(&t_begin, &t_post) * MSEC_PER_SEC); > + else > + igt_info("GT%d C6 NOT stable after %.0fms (timeout %ums)\n", gt, > + igt_time_elapsed(&t_begin, &t_post) * MSEC_PER_SEC, > + timeout_ms); > + errno = 0; > + > + return ret; > +} > + > /** > * xe_gt_dump_debug_info: > * @fd: open xe drm file descriptor > diff --git a/lib/xe/xe_gt.h b/lib/xe/xe_gt.h > index 9ef15d7dd..71402714d 100644 > --- a/lib/xe/xe_gt.h > +++ b/lib/xe/xe_gt.h > @@ -21,6 +21,8 @@ void xe_post_hang_ring(int fd, igt_hang_t arg); > int xe_gt_stats_get_count(int fd, int gt, const char *stat); > > bool xe_gt_is_in_c6(int fd, int gt); > +bool xe_gt_wait_c6_stable(int fd, int gt, unsigned int stable_ms, > + unsigned int timeout_ms); > bool xe_gt_dump_debug_info(int fd, int gt); > > int xe_gt_fill_engines_by_class(int fd, int gt, int class,