S0ix support in Xen
Hi,
I have been looking into using S0ix with Xen. On systems with with 11th gen (Tiger Lake) Intel mobile CPUs or newer this is often the only supported suspend method, thus we want to support it in Qubes OS.
Below a summary of my current understanding of what's needed (and known unknowns). I would appreciate some feedback (what's missing, preferred solutions, etc.).
Note this topic is much above my previous experience with Xen and x86 power management internals, so sorry if I'm missing things that are obvious to you.
PIT timer: During some previous private discussion it was mentioned that the PIT timer that Xen initializes for IO-APIC testing prevents S0ix residency and therefore that part needs to be reworked. But if I'm reading the current code correctly Xen can already use the HPET timer instead, either with an automatic fallback if PIT is unavailable or by forcing it via hpet=legacy-replacement=1. Looking at the rest I think the PIT isn't used if Xen finds another clocksource. Did I miss something?
mwait idle driver: While mwait-idle.c share a lot of code with Linux's intel_idle.c and the imported code seems to have been updated (for example for Alder Lake) it only supports the CPUs with hardcoded cstates. Linux's code also has a code path to read the cstate config from ACPI if the driver doesn't has a hard coded config for the model. This is needed for example for Tiger Lake. For my current testing I added the values the Linux code reads from ACPI by hand. But that's of course no proper solution. How should this be handled in Xen (IIUC some ACPI things are handled by Xen and some by dom0)?
The debugging code in xen/arch/x86/acpi/cpu_idle.c (and maybe other places) need to learn about deeper package C states, for example for Tiger Lake.
In general having the power management debugging available that you have under plain Linux through /sys/kernel/debug/pmc_core, etc. would be nice. Some things are as easy as allowing some dom0 to read some MSRs. But didn't looked into it further, some functions might also be required more complex integration (like extending xenpm's functionality).
I'm not sure yet is what else in Xen needs to learn about S0ix. Running domains need to be halted, that can be handled by the toolstack. What other Xen internal things need to be aware of S0ix? Like avoiding unnecessary timer wakeups or similar. That's currently my biggest unknown and it would be great if someone with more insight and overview could give some hints here.
On my test system (NUC11TNHi5, Tiger Lake) I haven't seen it reaching cstates lower PC7 with Xen (so it can of course not reach S0ix residency). With plain Linux I got it working on that system although it was rather fiddly and probably something is fishy on the firmware side. After seeing it very occasionally not working under plain Linux I have installed a newer firmware version. With that Xen currently doesn't wake up after triggering s2idle in dom0. I'm currently looking into that and will follow up if I have more details on that part.
Thanks, Simon
Quoted 8 lines · Simon Gaiser
PIT timer: During some previous private discussion it was mentioned that the PIT timer that Xen initializes for IO-APIC testing prevents S0ix residency and therefore that part needs to be reworked. But if I'm reading the current code correctly Xen can already use the HPET timer instead, either with an automatic fallback if PIT is unavailable or by forcing it via hpet=legacy-replacement=1. Looking at the rest I think the PIT isn't used if Xen finds another clocksource. Did I miss something?
I think the concern was with calibrating the APIC clock against PIT, but as you say that connection has been cut. So I think there's no prereq work left there; Andrew may prove me wrong, though.
Quoted 9 lines
mwait idle driver: While
mwait-idle.cshare a lot of code with Linux'sintel_idle.cand the imported code seems to have been updated (for example for Alder Lake) it only supports the CPUs with hardcoded cstates. Linux's code also has a code path to read the cstate config from ACPI if the driver doesn't has a hard coded config for the model. This is needed for example for Tiger Lake. For my current testing I added the values the Linux code reads from ACPI by hand. But that's of course no proper solution. How should this be handled in Xen (IIUC some ACPI things are handled by Xen and some by dom0)?
Well, there's first of all some lack of understanding on my part: It hasn't become clear to me why Linux now has two CPU idle drivers consuming ACPI data (intel_idle and the purely ACPI-based one). If two are really needed, then I guess mwait-idle would need extending to also consume data passed up from Dom0, just like the ACPI-only driver in Xen does (and which doesn't do anything until such data was supplied).
Quoted 6 lines
I'm not sure yet is what else in Xen needs to learn about S0ix. Running domains need to be halted, that can be handled by the toolstack. What other Xen internal things need to be aware of S0ix? Like avoiding unnecessary timer wakeups or similar. That's currently my biggest unknown and it would be great if someone with more insight and overview could give some hints here.
I didn't think the higher-level-software side of things was different from S3. Instead I thought it's merely a matter of different interaction with hardware that's needed (which, as per above, includes avoiding certain things, i.e. in particular the PIT).
Jan
Simon Gaiser:
[...]
Quoted 8 lines
On my test system (NUC11TNHi5, Tiger Lake) I haven't seen it reaching cstates lower PC7 with Xen (so it can of course not reach S0ix residency). With plain Linux I got it working on that system although it was rather fiddly and probably something is fishy on the firmware side. After seeing it very occasionally not working under plain Linux I have installed a newer firmware version. With that Xen currently doesn't wake up after triggering s2idle in dom0. I'm currently looking into that and will follow up if I have more details on that part.
Solved the wakeup issue, see
https://lore.kernel.org/xen-devel/[email protected]/
(doesn't change the cstate it reaches)
Quoted 14 lines · Simon Gaiser
Hi,
I have been looking into using S0ix with Xen. On systems with with 11th gen (Tiger Lake) Intel mobile CPUs or newer this is often the only supported suspend method, thus we want to support it in Qubes OS.
Below a summary of my current understanding of what's needed (and known unknowns). I would appreciate some feedback (what's missing, preferred solutions, etc.).
Note this topic is much above my previous experience with Xen and x86 power management internals, so sorry if I'm missing things that are obvious to you.
Quoted 8 lines
PIT timer: During some previous private discussion it was mentioned that the PIT timer that Xen initializes for IO-APIC testing prevents S0ix residency and therefore that part needs to be reworked. But if I'm reading the current code correctly Xen can already use the HPET timer instead, either with an automatic fallback if PIT is unavailable or by forcing it via hpet=legacy-replacement=1. Looking at the rest I think the PIT isn't used if Xen finds another clocksource. Did I miss something?
Do you have some reference to documentation related to the S0ix states?
I would like to understand exactly what's required in terms of hardware devices the OS can use and still be able to enter such states.
Thanks, Roger.
Roger Pau Monné:
Quoted 25 lines · Simon Gaiser
Quoted 15 lines
Hi,
I have been looking into using S0ix with Xen. On systems with with 11th gen (Tiger Lake) Intel mobile CPUs or newer this is often the only supported suspend method, thus we want to support it in Qubes OS.
Below a summary of my current understanding of what's needed (and known unknowns). I would appreciate some feedback (what's missing, preferred solutions, etc.).
Note this topic is much above my previous experience with Xen and x86 power management internals, so sorry if I'm missing things that are obvious to you.
Quoted 8 lines
PIT timer: During some previous private discussion it was mentioned that the PIT timer that Xen initializes for IO-APIC testing prevents S0ix residency and therefore that part needs to be reworked. But if I'm reading the current code correctly Xen can already use the HPET timer instead, either with an automatic fallback if PIT is unavailable or by forcing it via hpet=legacy-replacement=1. Looking at the rest I think the PIT isn't used if Xen finds another clocksource. Did I miss something?
Quoted 6 lines
Do you have some reference to documentation related to the S0ix states?
I would like to understand exactly what's required in terms of hardware devices the OS can use and still be able to enter such states.
Unfortunately the documentation that I'm aware of is rather sparse. There are two blog posts by Intel [1] and [2] that are quite good when you are trying to get it working under Linux. [3] might be also useful for debugging.
But I'm not aware of an explicit and complete list of what is required to enter S0ix. You can deduct things from the blog posts or for example the names of the debug register fields, but yeah ...
Also [2] contains this gem:
Currently, only the NDA version of the Intel® SoC Watch tool can expose the IP Link Power State. [...] If you have any questions, please refer to your Intel representative.
Regarding what devices are active in S0ix the PCH datasheet [4] has a few additional pointers like:
USB 3.2 only works in S0. USB 2.0 survives S0ix and Sx states and provides early boot access.
If someone knows about more public docs, I'm all ear.
Simon
[1]: https://01.org/blogs/qwang59/2018/how-achieve-s0ix-states-linux
[2]: https://01.org/blogs/qwang59/2020/linux-s0ix-troubleshooting
[3]: https://01.org/blogs/2019/using-power-management-controller-drivers-debug-low-power-platform-states
[4]: https://cdrdv2.intel.com/v1/dl/getContent/631119