Skip to contentSkip to conversation

x86/Intel: don't log bogus frequency range on Core/Core2 processors

PATCH In review Jan Beulich 2 participants 6 messages Feb 4, 2022 – Feb 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/Intel: don't log bogus frequency range on Core/Core2 processors

Models 0F and 17 don't have PLATFORM_INFO documented. While it exists on at least model 0F, the information there doesn't match the scheme used on newer models (I'm observing a range of 700 ... 600 MHz reported on a Xeon E5345).

Sadly the Enhanced Intel Core instance of the table entry is not self-
consistent: The numeric description of the low 3 bits doesn't match the subsequent more textual description in some of the cases; I'm using the former here.

Include the older Core model 0E as well as the two other Core2 models, none of which have respective MSR tables in the SDM.

Fixes f6b6517cd5db ("x86: retrieve and log CPU frequency information")

---
While the SDM table for the two models lists FSB_FREQ, I'm afraid its information is of little use here: If anything it could serve as a reference for the frequency determined by calibrate_APIC_clock().
---
RFC: I may want to rebase over Roger's addition of intel-family.h, but
first of all I wanted to see whether going this route is deemed acceptable at all.

xen/arch/x86/cpu/intel.c +20 -0
@@ -435,6 +435,26 @@ static void intel_log_freq(const struct
         if ( c->x86 == 6 )
             switch ( c->x86_model )
             {
+                static const unsigned short core_factors[] =
+                    { 26667, 13333, 20000, 16667, 33333, 10000, 40000 };
+
+            case 0x0e: /* Core */
+            case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */
+                /*
+                 * PLATFORM_INFO, while not documented for these, appears to
+                 * exist in at least some cases, but what it holds doesn't
+                 * match the scheme used by newer CPUs.  At a guess, the min
+                 * and max fields look to be reversed, while the scaling
+                 * factor is encoded in FSB_FREQ.
+                 */
+                if ( min_ratio > max_ratio )
+                    SWAP(min_ratio, max_ratio);
+                if ( rdmsr_safe(MSR_FSB_FREQ, msrval) ||
+                     (msrval &= 7) >= ARRAY_SIZE(core_factors) )
+                    return;
+                factor = core_factors[msrval];
+                break;
+
             case 0x1a: case 0x1e: case 0x1f: case 0x2e: /* Nehalem */
             case 0x25: case 0x2c: case 0x2f: /* Westmere */
                 factor = 13333;
#1 lore raw
Quoted 4 lines · Jan Beulich

Models 0F and 17 don't have PLATFORM_INFO documented. While it exists on at least model 0F, the information there doesn't match the scheme used on newer models (I'm observing a range of 700 ... 600 MHz reported on a Xeon E5345).

Maybe it would be best to limit ourselves to the models that have the MSR documented in the SDM?

Quoted 39 lines

Sadly the Enhanced Intel Core instance of the table entry is not self-
consistent: The numeric description of the low 3 bits doesn't match the subsequent more textual description in some of the cases; I'm using the former here.

Include the older Core model 0E as well as the two other Core2 models, none of which have respective MSR tables in the SDM.

Fixes f6b6517cd5db ("x86: retrieve and log CPU frequency information")

---
While the SDM table for the two models lists FSB_FREQ, I'm afraid its information is of little use here: If anything it could serve as a reference for the frequency determined by calibrate_APIC_clock().
---
RFC: I may want to rebase over Roger's addition of intel-family.h, but
first of all I wanted to see whether going this route is deemed acceptable at all.

xen/arch/x86/cpu/intel.c +13 -0
@@ -435,6 +435,26 @@ static void intel_log_freq(const struct
         if ( c->x86 == 6 )
             switch ( c->x86_model )
             {
+                static const unsigned short core_factors[] =
+                    { 26667, 13333, 20000, 16667, 33333, 10000, 40000 };
+
+            case 0x0e: /* Core */
+            case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */
+                /*
+                 * PLATFORM_INFO, while not documented for these, appears to
+                 * exist in at least some cases, but what it holds doesn't
+                 * match the scheme used by newer CPUs.  At a guess, the min
+                 * and max fields look to be reversed, while the scaling
+                 * factor is encoded in FSB_FREQ.
+                 */
+                if ( min_ratio > max_ratio )

xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct · line 460

Quoted 10 lines
xen/arch/x86/cpu/intel.c +7 -0
+                    SWAP(min_ratio, max_ratio);
+                if ( rdmsr_safe(MSR_FSB_FREQ, msrval) ||
+                     (msrval &= 7) >= ARRAY_SIZE(core_factors) )
+                    return;
+                factor = core_factors[msrval];
+                break;
+
             case 0x1a: case 0x1e: case 0x1f: case 0x2e: /* Nehalem */
             case 0x25: case 0x2c: case 0x2f: /* Westmere */
                 factor = 13333;

Seeing that the MSR is present on non documented models and has unknown behavior we might want to further sanity check that min < max before printing anything?

Thanks, Roger.

#2 lore raw
Quoted 8 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Models 0F and 17 don't have PLATFORM_INFO documented. While it exists on at least model 0F, the information there doesn't match the scheme used on newer models (I'm observing a range of 700 ... 600 MHz reported on a Xeon E5345).

Maybe it would be best to limit ourselves to the models that have the MSR documented in the SDM?

Well, yes, that's what I wasn't sure about: The information is used only for logging, so it's not the end of the world if we display something strange. We'd want to address such anomalies (like the one I did observe here) of course. But I wonder whether being entirely silent is really better.

Quoted 25 lines
Quoted 25 lines
xen/arch/x86/cpu/intel.c +19 -0
@@ -435,6 +435,26 @@ static void intel_log_freq(const struct
         if ( c->x86 == 6 )
             switch ( c->x86_model )
             {
+                static const unsigned short core_factors[] =
+                    { 26667, 13333, 20000, 16667, 33333, 10000, 40000 };
+
+            case 0x0e: /* Core */
+            case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */
+                /*
+                 * PLATFORM_INFO, while not documented for these, appears to
+                 * exist in at least some cases, but what it holds doesn't
+                 * match the scheme used by newer CPUs.  At a guess, the min
+                 * and max fields look to be reversed, while the scaling
+                 * factor is encoded in FSB_FREQ.
+                 */
+                if ( min_ratio > max_ratio )
+                    SWAP(min_ratio, max_ratio);
+                if ( rdmsr_safe(MSR_FSB_FREQ, msrval) ||
+                     (msrval &= 7) >= ARRAY_SIZE(core_factors) )
+                    return;
+                factor = core_factors[msrval];
+                break;
Quoted 8 lines

xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct · line 460

Quoted 4 lines
xen/arch/x86/cpu/intel.c +1 -0
+
             case 0x1a: case 0x1e: case 0x1f: case 0x2e: /* Nehalem */
             case 0x25: case 0x2c: case 0x2f: /* Westmere */
                 factor = 13333;

Seeing that the MSR is present on non documented models and has unknown behavior we might want to further sanity check that min < max before printing anything?

But I'm already swapping the two in the opposite case?

Jan

#3 lore raw
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Models 0F and 17 don't have PLATFORM_INFO documented. While it exists on at least model 0F, the information there doesn't match the scheme used on newer models (I'm observing a range of 700 ... 600 MHz reported on a Xeon E5345).

Quoted 8 lines
Quoted 2 lines

Maybe it would be best to limit ourselves to the models that have the MSR documented in the SDM?

Well, yes, that's what I wasn't sure about: The information is used only for logging, so it's not the end of the world if we display something strange. We'd want to address such anomalies (like the one I did observe here) of course. But I wonder whether being entirely silent is really better.

OK, let's add the quirk for Core/Core2 then.

Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
xen/arch/x86/cpu/intel.c +19 -0
@@ -435,6 +435,26 @@ static void intel_log_freq(const struct
         if ( c->x86 == 6 )
             switch ( c->x86_model )
             {
+                static const unsigned short core_factors[] =
+                    { 26667, 13333, 20000, 16667, 33333, 10000, 40000 };
+
+            case 0x0e: /* Core */
+            case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */
+                /*
+                 * PLATFORM_INFO, while not documented for these, appears to
+                 * exist in at least some cases, but what it holds doesn't
+                 * match the scheme used by newer CPUs.  At a guess, the min
+                 * and max fields look to be reversed, while the scaling
+                 * factor is encoded in FSB_FREQ.
+                 */
+                if ( min_ratio > max_ratio )
+                    SWAP(min_ratio, max_ratio);
+                if ( rdmsr_safe(MSR_FSB_FREQ, msrval) ||
+                     (msrval &= 7) >= ARRAY_SIZE(core_factors) )
+                    return;
+                factor = core_factors[msrval];
+                break;
Quoted 8 lines

xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct · line 460

Quoted 4 lines
xen/arch/x86/cpu/intel.c +1 -0
+
             case 0x1a: case 0x1e: case 0x1f: case 0x2e: /* Nehalem */
             case 0x25: case 0x2c: case 0x2f: /* Westmere */
                 factor = 13333;

Seeing that the MSR is present on non documented models and has unknown behavior we might want to further sanity check that min < max before printing anything?

Quoted 1 line

But I'm already swapping the two in the opposite case?

You are only doing the swapping for Core/Core2.

What I mean is that given the possible availability of MSR_INTEL_PLATFORM_INFO on undocumented platforms and the different semantics we should unconditionally check that the frequencies we are going to print are sane, and one easy check would be that min < max before printing.

Thanks, Roger.

#4 lore raw
Quoted 39 lines · Roger Pau Monné
Quoted 36 lines · Jan Beulich
Quoted 26 lines · Roger Pau Monné
Quoted 25 lines · Jan Beulich
xen/arch/x86/cpu/intel.c +19 -0
@@ -435,6 +435,26 @@ static void intel_log_freq(const struct
         if ( c->x86 == 6 )
             switch ( c->x86_model )
             {
+                static const unsigned short core_factors[] =
+                    { 26667, 13333, 20000, 16667, 33333, 10000, 40000 };
+
+            case 0x0e: /* Core */
+            case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */
+                /*
+                 * PLATFORM_INFO, while not documented for these, appears to
+                 * exist in at least some cases, but what it holds doesn't
+                 * match the scheme used by newer CPUs.  At a guess, the min
+                 * and max fields look to be reversed, while the scaling
+                 * factor is encoded in FSB_FREQ.
+                 */
+                if ( min_ratio > max_ratio )
+                    SWAP(min_ratio, max_ratio);
+                if ( rdmsr_safe(MSR_FSB_FREQ, msrval) ||
+                     (msrval &= 7) >= ARRAY_SIZE(core_factors) )
+                    return;
+                factor = core_factors[msrval];
+                break;
Quoted 8 lines

xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct · line 460

Quoted 4 lines
xen/arch/x86/cpu/intel.c +1 -0
+
             case 0x1a: case 0x1e: case 0x1f: case 0x2e: /* Nehalem */
             case 0x25: case 0x2c: case 0x2f: /* Westmere */
                 factor = 13333;

Seeing that the MSR is present on non documented models and has unknown behavior we might want to further sanity check that min < max before printing anything?

Quoted 1 line

But I'm already swapping the two in the opposite case?

Quoted 7 lines

You are only doing the swapping for Core/Core2.

What I mean is that given the possible availability of MSR_INTEL_PLATFORM_INFO on undocumented platforms and the different semantics we should unconditionally check that the frequencies we are going to print are sane, and one easy check would be that min < max before printing.

Oh, I see. Yes, I did consider this, but decided against because it would hide cases where we're not in line with reality. I might not have spotted the issue here if we would have had such a check in place already (maybe the too low number would have caught my attention, but the <high> ... <low> range logged was far more obviously wrong). (In any event, if such a change was to be made, I think it should be a separate patch.)

Jan

#5 lore raw
Quoted 48 lines · Jan Beulich
Quoted 39 lines · Roger Pau Monné
Quoted 36 lines · Jan Beulich
Quoted 26 lines · Roger Pau Monné
Quoted 25 lines · Jan Beulich
xen/arch/x86/cpu/intel.c +19 -0
@@ -435,6 +435,26 @@ static void intel_log_freq(const struct
         if ( c->x86 == 6 )
             switch ( c->x86_model )
             {
+                static const unsigned short core_factors[] =
+                    { 26667, 13333, 20000, 16667, 33333, 10000, 40000 };
+
+            case 0x0e: /* Core */
+            case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */
+                /*
+                 * PLATFORM_INFO, while not documented for these, appears to
+                 * exist in at least some cases, but what it holds doesn't
+                 * match the scheme used by newer CPUs.  At a guess, the min
+                 * and max fields look to be reversed, while the scaling
+                 * factor is encoded in FSB_FREQ.
+                 */
+                if ( min_ratio > max_ratio )
+                    SWAP(min_ratio, max_ratio);
+                if ( rdmsr_safe(MSR_FSB_FREQ, msrval) ||
+                     (msrval &= 7) >= ARRAY_SIZE(core_factors) )
+                    return;
+                factor = core_factors[msrval];
+                break;
Quoted 8 lines

xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct · line 460

Quoted 4 lines
xen/arch/x86/cpu/intel.c +1 -0
+
             case 0x1a: case 0x1e: case 0x1f: case 0x2e: /* Nehalem */
             case 0x25: case 0x2c: case 0x2f: /* Westmere */
                 factor = 13333;

Seeing that the MSR is present on non documented models and has unknown behavior we might want to further sanity check that min < max before printing anything?

Quoted 1 line

But I'm already swapping the two in the opposite case?

Quoted 7 lines

You are only doing the swapping for Core/Core2.

What I mean is that given the possible availability of MSR_INTEL_PLATFORM_INFO on undocumented platforms and the different semantics we should unconditionally check that the frequencies we are going to print are sane, and one easy check would be that min < max before printing.

Quoted 7 lines

Oh, I see. Yes, I did consider this, but decided against because it would hide cases where we're not in line with reality. I might not have spotted the issue here if we would have had such a check in place already (maybe the too low number would have caught my attention, but the <high> ... <low> range logged was far more obviously wrong). (In any event, if such a change was to be made, I think it should be a separate patch.)

My suggestion was to avoid printing both (max and min) if min > max, as there's obviously something wrong there. Maybe we could print unconditionally for debug builds, or print an error message otherwise to note that PLATFORM_INFO is present but the values calculated don't make sense?

In any case, this is just for informational purposes, so I don't really want to delay you anymore with this. If you think both options above are not worth it, feel free to take my Ack for this one:

Thanks, Roger.