Skip to contentSkip to conversation

hwmon: fam15h_power: fix bogus values with current BIOSes

PATCH In review Andre Przywara 3 participants 4 messages Apr 9, 2012 – Apr 18, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hwmon: fam15h_power: fix bogus values with current BIOSes

Newer BKDG[1] versions recommend a different initialization value for the running average range register in the northbridge. This improves the power reading by avoiding counter saturations resulting in bogus values for anything below about 80% of TDP power consumption. Updated BIOSes will have this new value set up from the beginning, but meanwhile we correct this value ourselves.
This needs to be done on all northbridges, even on those where the driver itself does not register at.

This fixes the driver on all current machines to provide proper values for idle load.

Changes to v1:
- marking the function as __devinit
- marking the devices list as const
- fixing formatting of 4-bit hexadecimal numbers
- dumping the function's return value as it is not used

[1]
http://support.amd.com/us/Processor_TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdf
Chapter 3.8: D18F5xE0 Processor TDP Running Average (p. 452)

---
 drivers/hwmon/fam15h_power.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
drivers/hwmon/fam15h_power.c +40 -0
index b7494af..4c2f62c 100644
@@ -122,6 +122,39 @@ static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4)
 	return true;
 }
 
+/*
+ * Newer BKDG versions have an updated recommendation on how to properly
+ * initialize the running average range (was: 0xE, now: 0x9). This avoids
+ * counter saturations resulting in bogus power readings.
+ * We correct this value ourselves to cope with older BIOSes.
+ */
+static void __devinit tweak_runavg_range(struct pci_dev *pdev)
+{
+	u32 val;
+	const struct pci_device_id affected_device = {
+		PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) };
+
+	/*
+	 * let this quirk apply only to the current version of the
+	 * northbridge, since future versions may change the behavior
+	 */
+	if (!pci_match_id(&affected_device, pdev))
+		return;
+
+	pci_bus_read_config_dword(pdev->bus,
+		PCI_DEVFN(PCI_SLOT(pdev->devfn), 5),
+		REG_TDP_RUNNING_AVERAGE, &val);
+	if ((val & 0xf) != 0xe)
+		return;
+
+	val &= ~0xf;
+	val |=  0x9;
+	pci_bus_write_config_dword(pdev->bus,
+		PCI_DEVFN(PCI_SLOT(pdev->devfn), 5),
+		REG_TDP_RUNNING_AVERAGE, val);
+	return;
+}
+
 static void __devinit fam15h_power_init_data(struct pci_dev *f4,
 					     struct fam15h_power_data *data)
 {
@@ -155,6 +188,13 @@ static int __devinit fam15h_power_probe(struct pci_dev *pdev,
 	struct device *dev;
 	int err;
 
+	/*
+	 * though we ignore every other northbridge, we still have to
+	 * do the tweaking on _each_ node in MCM processors as the counters
+	 * are working hand-in-hand
+	 */
+	tweak_runavg_range(pdev);
+
 	if (!fam15h_power_is_internal_node0(pdev)) {
 		err = -ENODEV;
 		goto exit;
Signature · 8 lines
1.7.4.4



_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v2 1/1
#1 lore raw
Quoted 18 lines · Andre Przywara

Newer BKDG[1] versions recommend a different initialization value for the running average range register in the northbridge. This improves the power reading by avoiding counter saturations resulting in bogus values for anything below about 80% of TDP power consumption. Updated BIOSes will have this new value set up from the beginning, but meanwhile we correct this value ourselves.
This needs to be done on all northbridges, even on those where the driver itself does not register at.

This fixes the driver on all current machines to provide proper values for idle load.

Changes to v1:
- marking the function as __devinit
- marking the devices list as const
- fixing formatting of 4-bit hexadecimal numbers
- dumping the function's return value as it is not used

Quoted 5 lines

[1]
http://support.amd.com/us/Processor_TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdf
Chapter 3.8: D18F5xE0 Processor TDP Running Average (p. 452)

Minor comment below, otherwise

Jean, do you want to take it, or should I ?

Guenter

Quoted 33 lines
---
 drivers/hwmon/fam15h_power.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
drivers/hwmon/fam15h_power.c +21 -0
index b7494af..4c2f62c 100644
@@ -122,6 +122,39 @@ static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4)
 	return true;
 }
 
+/*
+ * Newer BKDG versions have an updated recommendation on how to properly
+ * initialize the running average range (was: 0xE, now: 0x9). This avoids
+ * counter saturations resulting in bogus power readings.
+ * We correct this value ourselves to cope with older BIOSes.
+ */
+static void __devinit tweak_runavg_range(struct pci_dev *pdev)
+{
+	u32 val;
+	const struct pci_device_id affected_device = {
+		PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) };
+
+	/*
+	 * let this quirk apply only to the current version of the
+	 * northbridge, since future versions may change the behavior
+	 */
+	if (!pci_match_id(&affected_device, pdev))
+		return;
+
+	pci_bus_read_config_dword(pdev->bus,
+		PCI_DEVFN(PCI_SLOT(pdev->devfn), 5),

drivers/hwmon/fam15h_power.c static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4) · line 155

Quoted 10 lines
drivers/hwmon/fam15h_power.c +10 -0
+		REG_TDP_RUNNING_AVERAGE, &val);
+	if ((val & 0xf) != 0xe)
+		return;
+
+	val &= ~0xf;
+	val |=  0x9;
+	pci_bus_write_config_dword(pdev->bus,
+		PCI_DEVFN(PCI_SLOT(pdev->devfn), 5),
+		REG_TDP_RUNNING_AVERAGE, val);
+	return;

This return statement is completely unnecessary. Really.

Quoted 23 lines
drivers/hwmon/fam15h_power.c +9 -0
+}
+
 static void __devinit fam15h_power_init_data(struct pci_dev *f4,
 					     struct fam15h_power_data *data)
 {
@@ -155,6 +188,13 @@ static int __devinit fam15h_power_probe(struct pci_dev *pdev,
 	struct device *dev;
 	int err;
 
+	/*
+	 * though we ignore every other northbridge, we still have to
+	 * do the tweaking on _each_ node in MCM processors as the counters
+	 * are working hand-in-hand
+	 */
+	tweak_runavg_range(pdev);
+
 	if (!fam15h_power_is_internal_node0(pdev)) {
 		err = -ENODEV;
 		goto exit;
Signature · 1 line
1.7.4.4
Signature · 8 lines
Guenter Roeck
Distinguished Engineer
PDU IP Systems

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Andre Przywara
Quoted 23 lines · Guenter Roeck
Quoted 22 lines · Andre Przywara

Newer BKDG[1] versions recommend a different initialization value for the running average range register in the northbridge. This improves the power reading by avoiding counter saturations resulting in bogus values for anything below about 80% of TDP power consumption. Updated BIOSes will have this new value set up from the beginning, but meanwhile we correct this value ourselves.
This needs to be done on all northbridges, even on those where the driver itself does not register at.

This fixes the driver on all current machines to provide proper values for idle load.

Changes to v1:
- marking the function as __devinit
- marking the devices list as const
- fixing formatting of 4-bit hexadecimal numbers
- dumping the function's return value as it is not used

[1]
http://support.amd.com/us/Processor_TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdf
Chapter 3.8: D18F5xE0 Processor TDP Running Average (p. 452)

Quoted 8 lines
Quoted 1 line

Minor comment below, otherwise

Jean, do you want to take it, or should I ?

ping ... unless I hear otherwise, I'll add this patch to my list of patches for the next -rc candidate.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

Acked-by on v2 1/1
#3 lore raw
In reply to Andre Przywara
Quoted 26 lines · Guenter Roeck
Quoted 25 lines · Guenter Roeck
Quoted 23 lines · Andre Przywara

Newer BKDG[1] versions recommend a different initialization value for the running average range register in the northbridge. This improves the power reading by avoiding counter saturations resulting in bogus values for anything below about 80% of TDP power consumption. Updated BIOSes will have this new value set up from the beginning, but meanwhile we correct this value ourselves.
This needs to be done on all northbridges, even on those where the driver itself does not register at.

This fixes the driver on all current machines to provide proper values for idle load.

Changes to v1:
- marking the function as __devinit
- marking the devices list as const
- fixing formatting of 4-bit hexadecimal numbers
- dumping the function's return value as it is not used

[1]
http://support.amd.com/us/Processor_TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdf
Chapter 3.8: D18F5xE0 Processor TDP Running Average (p. 452)

Quoted 8 lines
Quoted 6 lines

Minor comment below, otherwise

Jean, do you want to take it, or should I ?

ping ... unless I hear otherwise, I'll add this patch to my list of patches for the next -rc candidate.

Sorry for the long silence. Yes, please pick it, no problem.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors