From: "Yao, Jia" <jia.yao@intel.com>
To: Zongyao Bai <zongyao.bai@intel.com>, <igt-dev@lists.freedesktop.org>
Cc: <shuicheng.lin@intel.com>
Subject: Re: [PATCH 1/3] lib/xe/xe_gt: Add xe_gt_wait_c6_stable()
Date: Wed, 2 Dec 2026 15:16:01 -0800 [thread overview]
Message-ID: <a9c7c245-931a-4d27-b6fe-9df2cc651c9c@intel.com> (raw)
In-Reply-To: <20261119005009.364632-2-zongyao.bai@intel.com>
LGTM.
Reviewed-by: Jia Yao <jia.yao@intel.com>
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 <zongyao.bai@intel.com>
> ---
> 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 <fcntl.h>
> #include <limits.h>
> +#include <string.h>
> #include <sys/stat.h>
> +#include <time.h>
> +#include <unistd.h>
>
> #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,
next prev parent reply other threads:[~2026-12-02 23:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 0:50 [PATCH 0/3] tests/intel/xe_pm_residency: Wait for a stable C6 before measuring residency Zongyao Bai
2026-11-19 0:50 ` [PATCH 1/3] lib/xe/xe_gt: Add xe_gt_wait_c6_stable() Zongyao Bai
2026-12-02 23:16 ` Yao, Jia [this message]
2026-11-19 0:50 ` [PATCH 2/3] tests/intel/xe_pm_residency: Wait for stable C6 before measuring Zongyao Bai
2026-12-02 23:14 ` Yao, Jia
2026-11-19 0:50 ` [PATCH 3/3] tests/intel/xe_pmu: Wait for stable C6 in gt-c6-idle Zongyao Bai
2026-12-02 23:16 ` Yao, Jia
2026-11-19 7:10 ` ✓ Xe.CI.BAT: success for tests/intel/xe_pm_residency: Wait for a stable C6 before measuring residency Patchwork
2026-11-19 13:06 ` ✓ i915.CI.BAT: " Patchwork
2026-11-20 10:20 ` ✓ Xe.CI.FULL: " Patchwork
2026-11-20 13:29 ` ✗ i915.CI.Full: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a9c7c245-931a-4d27-b6fe-9df2cc651c9c@intel.com \
--to=jia.yao@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=shuicheng.lin@intel.com \
--cc=zongyao.bai@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox