Skip to contentSkip to conversation

xen/x86: public: add TSC defines for cpuid leaf 4

PATCH Superseded Krister Johansen 2 participants 15 messages Jan 24, 2023 – Jan 31, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/x86: public: add TSC defines for cpuid leaf 4

Cpuid leaf 4 contains information about how the state of the tsc, its mode, and some additional information. A commit that is queued for linux would like to use this to determine whether the tsc mode has been set to 'no emulation' in order to make some decisions about which clocksource is more reliable.

Expose this information in the public API headers so that they can subsequently be imported into linux and used there.

---
 xen/include/public/arch-x86/cpuid.h | 6 ++++++
 1 file changed, 6 insertions(+)
xen/include/public/arch-x86/cpuid.h +6 -0
index 7ecd16ae05..97dc970417 100644
@@ -71,6 +71,12 @@
  *             EDX: shift amount for tsc->ns conversion
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
+#define XEN_CPUID_TSC_EMULATED       (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE  (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT   (0)
+#define XEN_CPUID_TSC_MODE_EMULATE   (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE (2u)
 
 /*
  * Leaf 5 (0x40000x04)
Signature · 1 line
2.25.1
#1 lore raw

xen/include/public/arch-x86/cpuid.h line 79

Quoted 12 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +6 -0
@@ -71,6 +71,12 @@
  *             EDX: shift amount for tsc->ns conversion
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
+#define XEN_CPUID_TSC_EMULATED       (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE  (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT   (0)
+#define XEN_CPUID_TSC_MODE_EMULATE   (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE (2u)

This could do with a blank line between the two groups. You're also missing mode 3. Plus, as a formal remark, please follow patch submission rules: They are sent To: the list, with maintainers on Cc:.

Jan

#2 lore raw
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +3 -0
@@ -71,6 +71,12 @@
  *             EDX: shift amount for tsc->ns conversion
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
+#define XEN_CPUID_TSC_EMULATED       (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE  (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL (1u << 2)
Quoted 8 lines

xen/include/public/arch-x86/cpuid.h line 79

Quoted 3 lines
xen/include/public/arch-x86/cpuid.h +3 -0
+#define XEN_CPUID_TSC_MODE_DEFAULT   (0)
+#define XEN_CPUID_TSC_MODE_EMULATE   (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE (2u)

This could do with a blank line between the two groups. You're also missing mode 3. Plus, as a formal remark, please follow patch submission rules: They are sent To: the list, with maintainers on Cc:.

Thanks for the feedback. I'll make those changes.

My apologies for the breach etiquette, and thank you for the reminder about the norms. I'll correct the To: and CC: headers on the next go around.

-K

#3 lore raw

PATCH v2 1/1 xen/x86: public: add TSC defines for cpuid leaf 4

In reply to Krister Johansen

Cpuid leaf 4 contains information about how the state of the tsc, its mode, and some additional information. A commit that is queued for linux would like to use this to determine whether the tsc mode has been set to 'no emulation' in order to make some decisions about which clocksource is more reliable.

Expose this information in the public API headers so that they can subsequently be imported into linux and used there.

---
v2.1:
- Correct In-Reply-To header for proper threading
v2:
- Fix whitespace between comment and #defines (feedback from Jan Beulich)
- Add tsc mode 3: no emulate TSC_AUX (feedback from Jan Beulich)

---
 xen/include/public/arch-x86/cpuid.h | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/include/public/arch-x86/cpuid.h +8 -0
index 7ecd16ae05..090f7f0034 100644
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)
+
 /*
  * Leaf 5 (0x40000x04)
  * HVM-specific features
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#4 lore raw
Quoted 2 lines · Krister Johansen

v2:
- Fix whitespace between comment and #defines (feedback from Jan Beulich)

Hmm, ...

xen/include/public/arch-x86/cpuid.h line 81

Quoted 13 lines
xen/include/public/arch-x86/cpuid.h +7 -0
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)

... while I'm fine with the leading blank line, what my earlier comment was about really are the two separate blocks of #define-s (the flag bits and the modes). I'll take care of this while committing; with the adjustment

Jan

#5 lore raw
Quoted 24 lines · Jan Beulich
Quoted 2 lines · Krister Johansen

v2:
- Fix whitespace between comment and #defines (feedback from Jan Beulich)

Hmm, ...

xen/include/public/arch-x86/cpuid.h line 81

Quoted 13 lines
xen/include/public/arch-x86/cpuid.h +7 -0
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)

... while I'm fine with the leading blank line, what my earlier comment was about really are the two separate blocks of #define-s (the flag bits and the modes). I'll take care of this while committing; with the adjustment

Quoted 1 line

Sorry I miunderstood, and thanks for being willing to fix this up while committing.

-K

#6 lore raw
In reply to Krister Johansen

xen/include/public/arch-x86/cpuid.h line 81

Quoted 13 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +7 -0
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)

Actually I think we'd better stick to the names found in asm/time.h (and then replace their uses, dropping the #define-s there). If you agree, I'd be happy to make the adjustment while committing.

Jan

#7 lore raw
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +0 -0
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
Quoted 11 lines

xen/include/public/arch-x86/cpuid.h line 81

Quoted 7 lines
xen/include/public/arch-x86/cpuid.h +7 -0
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)

Actually I think we'd better stick to the names found in asm/time.h (and then replace their uses, dropping the #define-s there). If you agree, I'd be happy to make the adjustment while committing.

Just to confirm, this would be moving these:

   #define TSC_MODE_DEFAULT          0
   #define TSC_MODE_ALWAYS_EMULATE   1
   #define TSC_MODE_NEVER_EMULATE    2

To cpuid.h? I'm generally fine with this. I don't see anything in Linux that's using these names. The only question I have is whether we'd still want to prefix the names with XEN so that if they're pulled in to Linux it's clear that the define is Xen specific? E.g. something like this perhaps?

   #define XEN_TSC_MODE_DEFAULT          0
   #define XEN_TSC_MODE_ALWAYS_EMULATE   1
   #define XEN_TSC_MODE_NEVER_EMULATE    2

That does increase the number of files we'd need to touch to make the change, though. (And the other defines in that file all start with XEN_CPUID).

Though, if you mean doing it this way:

   #define XEN_CPUID_TSC_MODE_DEFAULT          0
   #define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE   1
   #define XEN_CPUID_TSC_MODE_NEVER_EMULATE    2

then no objection to that at all. Apologies for overlooking the naming overlap when I put this together the first time.

-K

#8 lore raw
Quoted 40 lines · Krister Johansen
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +0 -0
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
Quoted 11 lines

xen/include/public/arch-x86/cpuid.h line 81

Quoted 7 lines
xen/include/public/arch-x86/cpuid.h +7 -0
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)

Actually I think we'd better stick to the names found in asm/time.h (and then replace their uses, dropping the #define-s there). If you agree, I'd be happy to make the adjustment while committing.

Just to confirm, this would be moving these:

   #define TSC_MODE_DEFAULT          0
   #define TSC_MODE_ALWAYS_EMULATE   1
   #define TSC_MODE_NEVER_EMULATE    2

To cpuid.h? I'm generally fine with this. I don't see anything in Linux that's using these names. The only question I have is whether we'd still want to prefix the names with XEN so that if they're pulled in to Linux it's clear that the define is Xen specific? E.g. something like this perhaps?

   #define XEN_TSC_MODE_DEFAULT          0
   #define XEN_TSC_MODE_ALWAYS_EMULATE   1
   #define XEN_TSC_MODE_NEVER_EMULATE    2

That does increase the number of files we'd need to touch to make the change, though. (And the other defines in that file all start with XEN_CPUID).

Quoted 8 lines

Though, if you mean doing it this way:

   #define XEN_CPUID_TSC_MODE_DEFAULT          0
   #define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE   1
   #define XEN_CPUID_TSC_MODE_NEVER_EMULATE    2

then no objection to that at all. Apologies for overlooking the naming overlap when I put this together the first time.

Yes, it's the last variant you list that I was after. And I'd be okay to leave dropping the so far private constants to a separate follow-on patch.

Jan

#9 lore raw
Quoted 47 lines · Jan Beulich
Quoted 46 lines · Krister Johansen
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +0 -0
@@ -72,6 +72,14 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
Quoted 11 lines

xen/include/public/arch-x86/cpuid.h line 81

Quoted 7 lines
xen/include/public/arch-x86/cpuid.h +7 -0
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_EMULATE           (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE_TSC_AUX (3u)

Actually I think we'd better stick to the names found in asm/time.h (and then replace their uses, dropping the #define-s there). If you agree, I'd be happy to make the adjustment while committing.

Just to confirm, this would be moving these:

   #define TSC_MODE_DEFAULT          0
   #define TSC_MODE_ALWAYS_EMULATE   1
   #define TSC_MODE_NEVER_EMULATE    2

To cpuid.h? I'm generally fine with this. I don't see anything in Linux that's using these names. The only question I have is whether we'd still want to prefix the names with XEN so that if they're pulled in to Linux it's clear that the define is Xen specific? E.g. something like this perhaps?

   #define XEN_TSC_MODE_DEFAULT          0
   #define XEN_TSC_MODE_ALWAYS_EMULATE   1
   #define XEN_TSC_MODE_NEVER_EMULATE    2

That does increase the number of files we'd need to touch to make the change, though. (And the other defines in that file all start with XEN_CPUID).

Though, if you mean doing it this way:

   #define XEN_CPUID_TSC_MODE_DEFAULT          0
   #define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE   1
   #define XEN_CPUID_TSC_MODE_NEVER_EMULATE    2
Quoted 5 lines
Quoted 2 lines

then no objection to that at all. Apologies for overlooking the naming overlap when I put this together the first time.

Yes, it's the last variant you list that I was after. And I'd be okay to leave dropping the so far private constants to a separate follow-on patch.

Ok, thanks. I'll send you a v3 that makes these changes, unless you've already fixed this up and committed the v2. In that case, feel free to disregard.

-K

#10 lore raw

PATCH v3 1/1 xen/x86: public: add TSC defines for cpuid leaf 4

In reply to Jan Beulich

Cpuid leaf 4 contains information about how the state of the tsc, its mode, and some additional information. A commit that is queued for linux would like to use this to determine whether the tsc mode has been set to 'no emulation' in order to make some decisions about which clocksource is more reliable.

Expose this information in the public API headers so that they can subsequently be imported into linux and used there.

---
v3
- Additional formating cleanups (feedback from Jan Buelich)
- Ensure that TSC_MODE #defines match the names of those in time.h (feedback from Jan Buelich)
v2:
- Fix whitespace between comment and #defines (feedback from Jan Beulich)
- Add tsc mode 3: no emulate TSC_AUX (feedback from Jan Beulich)

---
 xen/include/public/arch-x86/cpuid.h | 9 +++++++++
 1 file changed, 9 insertions(+)
xen/include/public/arch-x86/cpuid.h +9 -0
index 7ecd16ae05..3fbd912dcd 100644
@@ -72,6 +72,15 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+
+#define XEN_CPUID_TSC_MODE_DEFAULT               (0)
+#define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE        (1u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE_TSC_AUX (3u)
+
 /*
  * Leaf 5 (0x40000x04)
  * HVM-specific features
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#11 lore raw
Quoted 4 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +0 -0
@@ -72,6 +72,15 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz

xen/include/public/arch-x86/cpuid.h line 82

Quoted 10 lines
xen/include/public/arch-x86/cpuid.h +8 -0
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+
+#define XEN_CPUID_TSC_MODE_DEFAULT               (0)
+#define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE        (1u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE_TSC_AUX (3u)

While perhaps it doesn't matter much with the mode no longer supported, I'd prefer if here we used the original name (PVRDTSCP) as well. Preferably with that adjustment (which once again I'd be happy to do while committing, albeit I'd like to wait with that until osstest is in a better mood again)

Jan

#12 lore raw

Hi Jan,

Quoted 21 lines · Jan Beulich
Quoted 4 lines · Krister Johansen
xen/include/public/arch-x86/cpuid.h +0 -0
@@ -72,6 +72,15 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz

xen/include/public/arch-x86/cpuid.h line 82

Quoted 10 lines
xen/include/public/arch-x86/cpuid.h +8 -0
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+
+#define XEN_CPUID_TSC_MODE_DEFAULT               (0)
+#define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE        (1u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE_TSC_AUX (3u)

While perhaps it doesn't matter much with the mode no longer supported, I'd prefer if here we used the original name (PVRDTSCP) as well. Preferably with that adjustment (which once again I'd be happy to do while committing, albeit I'd like to wait with that until osstest is in a better mood again)

Quoted 1 line

Thanks for the additional feedback. I'll send you a v4 that makes the requested modification.

-K

#13 lore raw

PATCH v4 1/1 xen/x86: public: add TSC defines for cpuid leaf 4

In reply to Jan Beulich

Cpuid leaf 4 contains information about how the state of the tsc, its mode, and some additional information. A commit that is queued for linux would like to use this to determine whether the tsc mode has been set to 'no emulation' in order to make some decisions about which clocksource is more reliable.

Expose this information in the public API headers so that they can subsequently be imported into linux and used there.

---
v4
- Rename TSC_MODE_NEVER_EMULATE_TSC_AUX to TSC_MODE_PVRDTSCP (feedback from Jan Buelich)
v3
- Additional formating cleanups (feedback from Jan Buelich)
- Ensure that TSC_MODE #defines match the names of those in time.h (feedback from Jan Buelich)
v2:
- Fix whitespace between comment and #defines (feedback from Jan Beulich)
- Add tsc mode 3: no emulate TSC_AUX (feedback from Jan Beulich)

---
 xen/include/public/arch-x86/cpuid.h | 9 +++++++++
 1 file changed, 9 insertions(+)
xen/include/public/arch-x86/cpuid.h +9 -0
index 7ecd16ae05..9d02f86564 100644
@@ -72,6 +72,15 @@
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
 
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+
+#define XEN_CPUID_TSC_MODE_DEFAULT               (0)
+#define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE        (1u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE         (2u)
+#define XEN_CPUID_TSC_MODE_PVRDTSCP              (3u)
+
 /*
  * Leaf 5 (0x40000x04)
  * HVM-specific features
Signature · 1 line
2.25.1
Reviewed-by on v4 1/1
#14 lore raw
Quoted 6 lines · Krister Johansen

Cpuid leaf 4 contains information about how the state of the tsc, its mode, and some additional information. A commit that is queued for linux would like to use this to determine whether the tsc mode has been set to 'no emulation' in order to make some decisions about which clocksource is more reliable.

Quoted 6 lines

Expose this information in the public API headers so that they can subsequently be imported into linux and used there.

As said:

Jan