Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason-JH Lin (林睿祥)" <Jason-JH.Lin@mediatek.com>
To: "karthik.b.s@intel.com" <karthik.b.s@intel.com>,
	"swati2.sharma@intel.com" <swati2.sharma@intel.com>,
	"jani.nikula@intel.com" <jani.nikula@intel.com>,
	"ville.syrjala@linux.intel.com" <ville.syrjala@linux.intel.com>,
	Project_Global_Chrome_Upstream_Group
	<Project_Global_Chrome_Upstream_Group@mediatek.com>,
	"gildekel@google.com" <gildekel@google.com>,
	"navaremanasi@google.com" <navaremanasi@google.com>,
	"igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>,
	"Paul-pl Chen (陳柏霖)" <Paul-pl.Chen@mediatek.com>,
	"kamil.konieczny@linux.intel.com"
	<kamil.konieczny@linux.intel.com>,
	"Lancelot Wu (吳瑋晟)" <Lancelot.Wu@mediatek.com>,
	"fshao@chromium.org" <fshao@chromium.org>,
	"markyacoub@chromium.org" <markyacoub@chromium.org>
Subject: Re: [PATCH i-g-t v3 1/2] lib/igt_pm: Add CPU idle state control for vblank timing stability
Date: Tue, 14 Jul 2026 07:53:39 +0000	[thread overview]
Message-ID: <f2ccf5de8b8f1ae3ec0d7198ef4ce29534f85afc.camel@mediatek.com> (raw)
In-Reply-To: <20260713120828.afnxibf3ct4hteea@kamilkon-DESK.igk.intel.com>

On Mon, 2026-07-13 at 14:08 +0200, Kamil Konieczny wrote:
> Hi Jason-JH,
> On 2026-07-10 at 17:52:47 +0800, Jason-JH Lin wrote:
> > 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)
> 
> Please do not use bool params. See below.
> 
> > +{
> > +	char cpu_path[256];
> > +	char state_path[512];
> > +	int cpu, state;
> > +	int count = 0;
> > +	FILE *fp;
> > +	const char *value = disable ? "1" : "0";
> 
> Pass it as param.
> 
> > +	const char *action = disable ? "Disabled" : "Restored";
> 
> Same here:
> 
> static bool igt_pm_cpu_deep_sleep_control(char *val, char *msg)
> 

OK, I'll modify it.

> > +
> > +	/* Control state1 and deeper for all CPUs */
> > +	for (cpu = 0; cpu < 256; cpu++) {
> 
> Should you read this '256' dynamically? Or make it a define or
> const int. Another idea below.
> 
> > +		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;
> 
> Why not just readdir and match files starting with "cpu%d"?

OK, I'll change to readdir instead of using a const int for cpu%d.

> 
> > +
> > +		/* 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");
> 
> Why warning here? What if by default idle states are turned off?
> Btw when you run this in exit proc, any warn is unexpected and
> useless.

OK, I'll remove the warning here.

> 
> > +
> > +	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_cpu_deep_sleep_control("1", "Disabled")
> 
> > +}
> > +
> > +/**
> > + * 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);
> 
> igt_pm_cpu_deep_sleep_control("0", "Enabled")
> 

I think we can use one parameter to make it simpler and reduce
confusion.

E,g.
igt_pm_cpu_deep_sleep_control("Enabled");

What do you think?

Regards,
Jason-JH Lin

> Regards,
> Kamil

  reply	other threads:[~2026-07-14  7: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 ` [PATCH i-g-t v3 1/2] lib/igt_pm: Add CPU idle state control for vblank timing stability Jason-JH Lin
2026-07-13 12:08   ` Kamil Konieczny
2026-07-14  7:53     ` Jason-JH Lin (林睿祥) [this message]
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=f2ccf5de8b8f1ae3ec0d7198ef4ce29534f85afc.camel@mediatek.com \
    --to=jason-jh.lin@mediatek.com \
    --cc=Lancelot.Wu@mediatek.com \
    --cc=Paul-pl.Chen@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=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