Support for Intel temperature sensors (DTS)
PATCH v4 1/4 x86/cpu-policy: define bits of leaf 6
In reply to Teddy AstieFrom: Jan Beulich <[email protected]>
... as far as we presently use them in the codebase.
---
I don't know to which extend Reviewed-by applies as I only applied Andrew's proposal.
xen/include/xen/lib/x86/cpu-policy.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
xen/include/xen/lib/x86/cpu-policy.h +26 -1
@@ -121,7 +121,32 @@ struct cpu_policy uint64_t :64, :64; /* Leaf 0x3 - PSN. */ uint64_t :64, :64; /* Leaf 0x4 - Structured Cache. */ uint64_t :64, :64; /* Leaf 0x5 - MONITOR. */ - uint64_t :64, :64; /* Leaf 0x6 - Therm/Perf. */ + +/* Leaf 0x6 - Therm/Perf. */ + bool :1, + turbo:1, + arat:1, + :1, + :1, + :1, + :1, + hwp:1, + hwp_notification:1, + hwp_activity_window:1, + hwp_epp:1, + hwp_plr:1, + :1, + hdc:1, + :1, + :1, + hwp_peci:1, + :1, + :1, + hw_feedback:1; + uint32_t :32; /* b */ + bool aperfmperf:1; + uint32_t :32; /* d */ + uint64_t :64, :64; /* Leaf 0x7 - Structured Features. */ uint64_t :64, :64; /* Leaf 0x8 - rsvd */ uint64_t :64, :64; /* Leaf 0x9 - DCA */
Signature · 10 lines
2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
v4 cover Support for Intel temperature sensors (DTS)
The idea here is to expose the DTS sensors through XENPF_resource_op and expose it for the user through xenpm.
v4:
- reuse original cpu-policy patch
- remove xenpm building on non-x86
- add changelog notes
- reviewed xc_resource_op return code handling
- only print missing MSR_TEMPERATURE_TARGET message once
- formatting changes
v3:
- use msr-index.h instead of adding defines to MSRs in xenpm
v2:
- moved userland part to xenpm
- use cpu policy infrastructure instead of inline cpuid_*
Jan Beulich (1):
x86/cpu-policy: define bits of leaf 6
Teddy Astie (3):
xenpm: Don't build outside of x86
x86/platform: Expose DTS sensors MSR
xenpm: Add get-intel-temp subcommand
CHANGELOG.md | 6 ++ tools/misc/Makefile | 2 +- tools/misc/xenpm.c | 113 ++++++++++++++++++++++++++- xen/arch/x86/include/asm/msr-index.h | 3 + xen/arch/x86/platform_hypercall.c | 6 ++ xen/include/xen/lib/x86/cpu-policy.h | 27 ++++++- 6 files changed, 154 insertions(+), 3 deletions(-)
Signature · 10 lines
2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v4 3/4 x86/platform: Expose DTS sensors MSR
Intel provide CPU sensors through "DTS" MSRs. As these MSR are core-specific (or package-specific), we can't reliably fetch them from Dom0 directly. Expose these MSR (if supported) through XENPF_resource_op so that it is accessible through hypercall.
--- xen/arch/x86/include/asm/msr-index.h | 3 +++ xen/arch/x86/platform_hypercall.c | 6 ++++++ xen/include/xen/lib/x86/cpu-policy.h | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/msr-index.h +3 -0
@@ -115,6 +115,9 @@#define MCU_OPT_CTRL_GDS_MIT_DIS (_AC(1, ULL) << 4)#define MCU_OPT_CTRL_GDS_MIT_LOCK (_AC(1, ULL) << 5) +#define MSR_TEMPERATURE_TARGET 0x000001a2 +#define MSR_PACKAGE_THERM_STATUS 0x000001b1 +#define MSR_FRED_RSP_SL0 0x000001cc#define MSR_FRED_RSP_SL1 0x000001cd#define MSR_FRED_RSP_SL2 0x000001ce
xen/arch/x86/platform_hypercall.c +6 -0
@@ -27,6 +27,7 @@#include <asm/current.h> #include <public/platform.h> #include <acpi/cpufreq/processor_perf.h> +#include <asm/cpu-policy.h> #include <asm/edd.h> #include <asm/microcode.h> #include <asm/mtrr.h>
@@ -86,6 +87,11 @@ static bool msr_read_allowed(unsigned int msr)case MSR_MCU_OPT_CTRL :return cpu_has_srbds_ctrl; + +case MSR_IA32_THERM_STATUS : +case MSR_TEMPERATURE_TARGET : +case MSR_PACKAGE_THERM_STATUS : +return host_cpu_policy.basic.dts; }if ( ppin_msr && msr == ppin_msr )
xen/include/xen/lib/x86/cpu-policy.h +1 -1
@@ -123,7 +123,7 @@ struct cpu_policy uint64_t :64, :64; /* Leaf 0x5 - MONITOR. *//* Leaf 0x6 - Therm/Perf. */ - bool :1, + bool dts:1, turbo:1, arat:1, :1,
Signature · 10 lines
2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v4 2/4 xenpm: Don't build outside of x86
In reply to Teddy Astiexenpm doesn't provide any interesting usable features outside of x86, skip building it if we are not x86.
--- CHANGELOG.md | 3 +++ tools/misc/Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
CHANGELOG.md +3 -0
@@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) deprecated in Xen 4.7 and noted not to work correctly with AMD CPUs from 2011 onwards. + - Removed xenpm on non-x86 platforms as it doesn't actually provide anything + useful outside of x86. + ## [4.21.0](https://xenbits.xenproject.org/gitweb/?p=xen.git;a=shortlog;h=RELEASE-4.21.0) - 2025-11-19 ### Changed
tools/misc/Makefile +1 -1
@@ -23,13 +23,13 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) += xen-mceinj INSTALL_SBIN-$(CONFIG_X86) += xen-memshare INSTALL_SBIN-$(CONFIG_X86) += xen-mfndump +INSTALL_SBIN-$(CONFIG_X86) += xenpm INSTALL_SBIN-$(CONFIG_X86) += xen-ucode INSTALL_SBIN-$(CONFIG_X86) += xen-vmtrace INSTALL_SBIN += xencov INSTALL_SBIN += xenhypfs INSTALL_SBIN += xenlockprof INSTALL_SBIN += xenperf -INSTALL_SBIN += xenpm INSTALL_SBIN += xenwatchdogd INSTALL_SBIN += xen-access INSTALL_SBIN += xen-livepatch
Signature · 10 lines
2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v4 4/4 xenpm: Add get-intel-temp subcommand
In reply to Teddy Astieget-intel-temp allows querying the per-core CPU temperature and per-package one on Intel processors (as usual Dom0 drivers cannot work due to misalignment between Dom0 vCPU and pCPUs).
--- CHANGELOG.md | 3 ++ tools/misc/xenpm.c | 113 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-)
CHANGELOG.md +3 -0
@@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Changed ### Added + - On x86: + - Introduce get-intel-temp to xenpm to query CPU temperatures on Intel + platforms. ### Removed - On x86:
tools/misc/xenpm.c +112 -1
147 lines not on this page · raw message
--
2.51.2
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v4 1/4] x86/cpu-policy: define bits of leaf 6
In reply to Teddy AstieQuoted 9 lines · Teddy Astie
From: Jan Beulich <[email protected]>
... as far as we presently use them in the codebase.
Signed-off-by Jan Beulich <[email protected]>Signed-off-by Teddy Astie <[email protected]>---
I don't know to which extend Reviewed-by applies as I only applied Andrew's proposal.
Which I pointed out has a latent weakness. I'm intending to submit a new version of my patch, but instead with the names change to better match the SDM (as was requested by Andrew in reply to a change later in that other series of mine).
Jan
Re: [PATCH v4 2/4] xenpm: Don't build outside of x86
In reply to Teddy AstieQuoted 9 lines · Teddy Astie
xenpm doesn't provide any interesting usable features outside of x86, skip building it if we are not x86.
Suggested-by Jan Beulich <[email protected]>Signed-off-by Teddy Astie <[email protected]>--- CHANGELOG.md | 3 +++ tools/misc/Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
Arm being what is mainly affected, I think you may have wanted to Cc Arm folks, for them to ack this (alongside Anthony).
CHANGELOG.md The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) · line 20
Quoted 8 lines
CHANGELOG.md +2
-0@@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) deprecated in Xen 4.7 and noted not to work correctly with AMD CPUs from 2011 onwards. + - Removed xenpm on non-x86 platforms as it doesn't actually provide anything + useful outside of x86.
Maybe add the word "tool" for those who don't recognize "xenpm" at the first glance?
Jan
Re: [PATCH v4 4/4] xenpm: Add get-intel-temp subcommand
In reply to Teddy AstieQuoted 41 lines · Teddy Astie
tools/misc/xenpm.c +37
-0@@ -1354,6 +1358,113 @@ void enable_turbo_mode(int argc, char *argv[]) errno, strerror(errno)); } +static int fetch_dts_temp (xc_interface *xch,uint32_t cpu,bool package,int *temp) +{ +xc_resource_entry_t entries[] = { + { .idx = package ?MSR_PACKAGE_THERM_STATUS :MSR_IA32_THERM_STATUS }, + { .idx =MSR_TEMPERATURE_TARGET }, + }; +struct xc_resource_op ops = { + .cpu = cpu, + .entries = entries, + .nr_entries =ARRAY_SIZE (entries), + }; +int tjmax; + +int ret =xc_resource_op (xch,1 , &ops); + +switch ( ret ) + { +case -1 : +/* xc_resource_op returns -1 in out of memory scenarios */ +return -ENOMEM ; +case 0 : +/* This CPU isn't online or can't query this MSR */ +return -ENODATA ; +case 1 : + { +/* +* The CPU doesn't support MSR_TEMPERATURE_TARGET, we assume it's 100 +* which is correct aside a few selected Atom CPUs. Check Linux +* kernel's coretemp.c for more information. +*/ +static bool has_reported_once = false; + +if ( !has_reported_once ) + { +fprintf (stderr,"MSR_TEMPERATURE_TARGET is not supported, assume " +"tjmax = 100, readings may be incorrect.\n" ); + has_reported_once = true;
tools/misc/xenpm.c void enable_turbo_mode(int argc, char *argv[]) · line 1407
Quoted 10 lines
tools/misc/xenpm.c +10
-0+ } + + tjmax =100 ; +break ; + } +case 2 : + { + tjmax = (entries[1 ].val >>16 ) &0xff ; +break ; + }
No need for figure braces here; you don't have ones either in cases further up where there are no new local variables. Instead a blank line between non-fall- through case blocks may be nice.
Jan
Re: [PATCH v4 3/4] x86/platform: Expose DTS sensors MSR
In reply to Teddy AstieQuoted 7 lines · Teddy Astie
Intel provide CPU sensors through "DTS" MSRs. As these MSR are core-specific (or package-specific), we can't reliably fetch them from Dom0 directly. Expose these MSR (if supported) through
XENPF_resource_opso that it is accessible through hypercall.Suggested-by Jan Beulich <[email protected]>Signed-off-by Teddy Astie <[email protected]>
I wonder though whether ...
xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 126
Quoted 8 lines
xen/include/xen/lib/x86/cpu-policy.h +1
-1@@ -123,7 +123,7 @@ struct cpu_policy uint64_t :64, :64; /* Leaf 0x5 - MONITOR. *//* Leaf 0x6 - Therm/Perf. */ - bool :1, + bool dts:1,
... we really want to go with the acronym here, when for other bits the plan now is to stay close to the SDM names.
Jan
Re: [PATCH v4 2/4] xenpm: Don't build outside of x86
In reply to Teddy AstieQuoted 5 lines · Teddy Astie
xenpm doesn't provide any interesting usable features outside of x86, skip building it if we are not x86.
Suggested-by Jan Beulich <[email protected]>Signed-off-by Teddy Astie <[email protected]>
Happy with that on the Arm side? Julien suggested so on #XenDevel.
For me, this seems fine:
Quoted 24 lines
--- CHANGELOG.md | 3 +++ tools/misc/Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)CHANGELOG.md +3
-0@@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) deprecated in Xen 4.7 and noted not to work correctly with AMD CPUs from 2011 onwards. + - Removed xenpm on non-x86 platforms as it doesn't actually provide anything + useful outside of x86. + ## [4.21.0](https://xenbits.xenproject.org/gitweb/?p=xen.git;a=shortlog;h=RELEASE-4.21.0) - 2025-11-19 ### Changedtools/misc/Makefile +0
-0
tools/misc/Makefile INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd · line 26
Quoted 4 lines
tools/misc/Makefile +1
-0@@ -23,13 +23,13 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) += xen-mceinj INSTALL_SBIN-$(CONFIG_X86) += xen-memshare INSTALL_SBIN-$(CONFIG_X86) += xen-mfndump +INSTALL_SBIN-$(CONFIG_X86) += xenpm
Nit: I would sort this by taking the dash - into account since we do so for the arch-common list, so xenpm would go after xen-vmtrace.
Quoted 10 lines
tools/misc/Makefile +0
-1INSTALL_SBIN-$(CONFIG_X86) += xen-ucode INSTALL_SBIN-$(CONFIG_X86) += xen-vmtrace INSTALL_SBIN += xencov INSTALL_SBIN += xenhypfs INSTALL_SBIN += xenlockprof INSTALL_SBIN += xenperf -INSTALL_SBIN += xenpm INSTALL_SBIN += xenwatchdogd INSTALL_SBIN += xen-access INSTALL_SBIN += xen-livepatch
Signature · 1 line
Anthony PERARD
Re: [PATCH v4 2/4] xenpm: Don't build outside of x86
Quoted 11 lines · Anthony PERARD
tools/misc/Makefile INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd · line 26
Quoted 7 lines · Teddy Astie
tools/misc/Makefile +1
-0@@ -23,13 +23,13 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) += xen-mceinj INSTALL_SBIN-$(CONFIG_X86) += xen-memshare INSTALL_SBIN-$(CONFIG_X86) += xen-mfndump +INSTALL_SBIN-$(CONFIG_X86) += xenpmNit: I would sort this by taking the dash
-into account since we do so for the arch-common list, so xenpm would go after xen-vmtrace.
Not really; imo it's coincidental that all present x86-only ones have a dash. I think this simply wants to ...
Quoted 7 lines
tools/misc/Makefile INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd · line 32
Quoted 7 lines
tools/misc/Makefile +0
-1INSTALL_SBIN-$(CONFIG_X86) += xen-ucode INSTALL_SBIN-$(CONFIG_X86) += xen-vmtrace INSTALL_SBIN += xencov INSTALL_SBIN += xenhypfs INSTALL_SBIN += xenlockprof INSTALL_SBIN += xenperf -INSTALL_SBIN += xenpm
... stay in its present place, merely becoming conditional.
Quoted 3 lines
tools/misc/Makefile INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd · line 35
Quoted 3 lines
tools/misc/Makefile +0
-0INSTALL_SBIN += xenwatchdogd INSTALL_SBIN += xen-access INSTALL_SBIN += xen-livepatch
The three entries with dashes quite likely were blindly added to the tail, without paying attention to sorting. Imo they want moving up into their respective positions.
Jan