Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (amd_energy) optimize accumulation interval

On a system with course grain resolution of energy unit (milli J) the
accumulation thread can be executed less frequently than on the system
with fine grain resolution(micro J).

This patch sets the accumulation thread interval to an optimum value
calculated based on the (energy unit) resolution supported by the
hardware (assuming a peak wattage of 240W).

Signed-off-by: Naveen Krishna Chatradhi <nchatrad@amd.com>
Link: https://lore.kernel.org/r/20200929105322.8919-3-nchatrad@amd.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Naveen Krishna Chatradhi and committed by
Guenter Roeck
514db2b4 6b0c0c83

+11 -9
+11 -9
drivers/hwmon/amd_energy.c
··· 46 46 struct mutex lock; 47 47 /* An accumulator for each core and socket */ 48 48 struct sensor_accumulator *accums; 49 + unsigned int timeout_ms; 49 50 /* Energy Status Units */ 50 - u64 energy_units; 51 + int energy_units; 51 52 int nr_cpus; 52 53 int nr_socks; 53 54 int core_id; ··· 216 215 static int energy_accumulator(void *p) 217 216 { 218 217 struct amd_energy_data *data = (struct amd_energy_data *)p; 218 + unsigned int timeout = data->timeout_ms; 219 219 220 220 while (!kthread_should_stop()) { 221 221 /* ··· 229 227 if (kthread_should_stop()) 230 228 break; 231 229 232 - /* 233 - * On a 240W system, with default resolution the 234 - * Socket Energy status register may wrap around in 235 - * 2^32*15.3 e-6/240 = 273.8041 secs (~4.5 mins) 236 - * 237 - * let us accumulate for every 100secs 238 - */ 239 - schedule_timeout(msecs_to_jiffies(100000)); 230 + schedule_timeout(msecs_to_jiffies(timeout)); 240 231 } 241 232 return 0; 242 233 } ··· 325 330 NULL); 326 331 if (IS_ERR(hwmon_dev)) 327 332 return PTR_ERR(hwmon_dev); 333 + 334 + /* 335 + * On a system with peak wattage of 250W 336 + * timeout = 2 ^ 32 / 2 ^ energy_units / 250 secs 337 + */ 338 + data->timeout_ms = 1000 * 339 + BIT(min(28, 31 - data->energy_units)) / 250; 328 340 329 341 data->wrap_accumulate = kthread_run(energy_accumulator, data, 330 342 "%s", dev_name(hwmon_dev));