diff options
author | Andre Przywara <andre.przywara@amd.com> | 2012-03-23 05:02:17 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2012-03-23 05:02:17 -0400 |
commit | 941a956b0e387b21f385f486c34ef67576775cfc (patch) | |
tree | 35d118d214a7c4d57ef1f8b085cafc9725255b75 /drivers/hwmon/fam15h_power.c | |
parent | fc0900cbda9243957d812cd6b4cc87965f9fe75f (diff) |
hwmon: (fam15h_power) Increase output resolution
On high CPU load the accumulating values in the running_avg_cap
register are very low (below 10), so averaging them too early leads
to unnecessary poor output resolution. Since we pretend to output
micro-Watt we better keep all the bits we have as long as possible.
Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/fam15h_power.c')
-rw-r--r-- | drivers/hwmon/fam15h_power.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c index 930370de5201..b7494af1e4a9 100644 --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c | |||
@@ -61,14 +61,14 @@ static ssize_t show_power(struct device *dev, | |||
61 | REG_TDP_RUNNING_AVERAGE, &val); | 61 | REG_TDP_RUNNING_AVERAGE, &val); |
62 | running_avg_capture = (val >> 4) & 0x3fffff; | 62 | running_avg_capture = (val >> 4) & 0x3fffff; |
63 | running_avg_capture = sign_extend32(running_avg_capture, 21); | 63 | running_avg_capture = sign_extend32(running_avg_capture, 21); |
64 | running_avg_range = val & 0xf; | 64 | running_avg_range = (val & 0xf) + 1; |
65 | 65 | ||
66 | pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), | 66 | pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), |
67 | REG_TDP_LIMIT3, &val); | 67 | REG_TDP_LIMIT3, &val); |
68 | 68 | ||
69 | tdp_limit = val >> 16; | 69 | tdp_limit = val >> 16; |
70 | curr_pwr_watts = tdp_limit + data->base_tdp - | 70 | curr_pwr_watts = (tdp_limit + data->base_tdp) << running_avg_range; |
71 | (s32)(running_avg_capture >> (running_avg_range + 1)); | 71 | curr_pwr_watts -= running_avg_capture; |
72 | curr_pwr_watts *= data->tdp_to_watts; | 72 | curr_pwr_watts *= data->tdp_to_watts; |
73 | 73 | ||
74 | /* | 74 | /* |
@@ -78,7 +78,7 @@ static ssize_t show_power(struct device *dev, | |||
78 | * scaling factor 1/(2^16). For conversion we use | 78 | * scaling factor 1/(2^16). For conversion we use |
79 | * (10^6)/(2^16) = 15625/(2^10) | 79 | * (10^6)/(2^16) = 15625/(2^10) |
80 | */ | 80 | */ |
81 | curr_pwr_watts = (curr_pwr_watts * 15625) >> 10; | 81 | curr_pwr_watts = (curr_pwr_watts * 15625) >> (10 + running_avg_range); |
82 | return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts); | 82 | return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts); |
83 | } | 83 | } |
84 | static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL); | 84 | static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL); |