From: Jason-JH Lin <jason-jh.lin@mediatek.com>
To: <igt-dev@lists.freedesktop.org>,
Karthik B S <karthik.b.s@intel.com>,
Swati Sharma <swati2.sharma@intel.com>,
Kamil Konieczny <kamil.konieczny@linux.intel.com>,
Ville Syrjala <ville.syrjala@linux.intel.com>,
Fei Shao <fshao@chromium.org>
Cc: Jani <jani.nikula@intel.com>,
Jason-JH Lin <jason-jh.lin@mediatek.com>,
Paul-PL Chen <paul-pl.chen@mediatek.com>,
Lancelot Wu <Lancelot.Wu@mediatek.com>,
Manasi Navare <navaremanasi@google.com>,
Gil Dekel <gildekel@google.com>, Yacoub <markyacoub@chromium.org>,
<Project_Global_Chrome_Upstream_Group@mediatek.com>
Subject: [PATCH i-g-t v3 1/2] lib/igt_pm: Add CPU idle state control for vblank timing stability
Date: Fri, 10 Jul 2026 17:52:47 +0800 [thread overview]
Message-ID: <20260710095358.2518446-2-jason-jh.lin@mediatek.com> (raw)
In-Reply-To: <20260710095358.2518446-1-jason-jh.lin@mediatek.com>
Add igt_pm_disable_cpu_deep_sleep() and igt_pm_enable_cpu_deep_sleep()
APIs to control deep CPU idle states (C-states) via sysfs. This prevents
IRQ latency spikes that affect vblank timestamp acquisition.
The functions control state1 and deeper states on all CPUs while keeping
state0 (WFI) unchanged, providing a balance between timing accuracy and
power efficiency.
Signed-off-by: Jason-JH Lin <jason-jh.lin@mediatek.com>
---
lib/igt_pm.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_pm.h | 2 ++
2 files changed, 77 insertions(+)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 64b15dd08302..7a8ad8ae3dea 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -1713,3 +1713,78 @@ unsigned int igt_read_pkgc_counter(int debugfs_root_fd)
return igt_get_dc_counter(str);
}
+
+static bool igt_pm_cpu_deep_sleep_control(bool disable)
+{
+ char cpu_path[256];
+ char state_path[512];
+ int cpu, state;
+ int count = 0;
+ FILE *fp;
+ const char *value = disable ? "1" : "0";
+ const char *action = disable ? "Disabled" : "Restored";
+
+ /* Control state1 and deeper for all CPUs */
+ for (cpu = 0; cpu < 256; cpu++) {
+ snprintf(cpu_path, sizeof(cpu_path),
+ "/sys/devices/system/cpu/cpu%d", cpu);
+
+ /* Check if CPU exists */
+ if (access(cpu_path, F_OK) != 0)
+ break;
+
+ /* Control state1 and deeper (keep state0 WFI unchanged) */
+ for (state = 1; state < 10; state++) {
+ snprintf(state_path, sizeof(state_path),
+ "%s/cpuidle/state%d/disable", cpu_path, state);
+
+ if (access(state_path, W_OK) != 0)
+ break;
+
+ /* Write '1' to disable, '0' to enable */
+ fp = fopen(state_path, "w");
+ if (fp) {
+ fprintf(fp, "%s", value);
+ fclose(fp);
+ count++;
+ }
+ }
+ }
+
+ if (count > 0)
+ igt_info("%s deep CPU idle states for %d CPU/state combinations\n",
+ action, count);
+ else
+ igt_warn("No CPU idle states found to control\n");
+
+ return count > 0;
+}
+
+/**
+ * igt_pm_disable_cpu_deep_sleep:
+ *
+ * Disables deep CPU idle states (C-states) to prevent IRQ latency spikes
+ * during vblank events. This is a system-wide operation that affects all CPUs.
+ *
+ * Disables state1 and deeper states while keeping state0 (WFI) unchanged
+ * to ensure stable vblank timing.
+ *
+ * Returns: true on success, false on failure
+ */
+bool igt_pm_disable_cpu_deep_sleep(void)
+{
+ return igt_pm_cpu_deep_sleep_control(true);
+}
+
+/**
+ * igt_pm_enable_cpu_deep_sleep:
+ *
+ * Re-enables deep CPU idle states (C-states) that were previously disabled
+ * by igt_pm_disable_cpu_deep_sleep(). This restores power-saving idle states.
+ *
+ * Returns: true on success, false on failure
+ */
+bool igt_pm_enable_cpu_deep_sleep(void)
+{
+ return igt_pm_cpu_deep_sleep_control(false);
+}
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index 6a33c6db22fb..c0e35dbe721e 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -114,5 +114,7 @@ bool igt_dc_state_wait_entry(int debugfs_fd, int dc_flag, int prev_dc_count);
const char *igt_dc_state_name(int dc_flag);
void igt_require_dc_counter(int debugfs_fd, int dc_flag);
unsigned int igt_read_pkgc_counter(int debugfs_root_fd);
+bool igt_pm_disable_cpu_deep_sleep(void);
+bool igt_pm_enable_cpu_deep_sleep(void);
#endif /* IGT_PM_H */
--
2.43.0
next prev parent reply other threads:[~2026-07-10 9:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 9:52 [PATCH i-g-t v3 0/2] Add CPU idle state control for accurate vblank timing Jason-JH Lin
2026-07-10 9:52 ` Jason-JH Lin [this message]
2026-07-13 12:08 ` [PATCH i-g-t v3 1/2] lib/igt_pm: Add CPU idle state control for vblank timing stability Kamil Konieczny
2026-07-14 7:53 ` Jason-JH Lin (林睿祥)
2026-07-14 16:37 ` Kamil Konieczny
2026-07-15 2:50 ` Jason-JH Lin (林睿祥)
2026-07-10 9:52 ` [PATCH i-g-t v3 2/2] tests/kms_setmode: Add basic-no-cpu-idle subtest Jason-JH Lin
2026-07-13 12:11 ` Kamil Konieczny
2026-07-14 7:55 ` Jason-JH Lin (林睿祥)
2026-07-10 10:37 ` ✓ Xe.CI.BAT: success for Add CPU idle state control for accurate vblank timing Patchwork
2026-07-10 10:49 ` ✓ i915.CI.BAT: " Patchwork
2026-07-10 18:55 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-07-11 13:42 ` ✗ i915.CI.Full: " 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=20260710095358.2518446-2-jason-jh.lin@mediatek.com \
--to=jason-jh.lin@mediatek.com \
--cc=Lancelot.Wu@mediatek.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=fshao@chromium.org \
--cc=gildekel@google.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
--cc=kamil.konieczny@linux.intel.com \
--cc=karthik.b.s@intel.com \
--cc=markyacoub@chromium.org \
--cc=navaremanasi@google.com \
--cc=paul-pl.chen@mediatek.com \
--cc=swati2.sharma@intel.com \
--cc=ville.syrjala@linux.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