From e8b4b33b8973fd53473af2e8c550de1cb4c5e24c Mon Sep 17 00:00:00 2001 From: Ondrej Čerman Date: Sun, 16 Feb 2020 15:52:13 +0100 Subject: Fixed wrong readings when energy counter overflow occurs, FIX #17 --- src/ss/msr.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/ss/msr.c b/src/ss/msr.c index f64c534..61fcc15 100644 --- a/src/ss/msr.c +++ b/src/ss/msr.c @@ -125,18 +125,24 @@ void msr_update() { core_eng_a[i] = get_core_energy(i); } - package_power = (package_eng_a - package_eng_b) * energy_unit / MESUREMENT_TIME; - if (package_power < package_power_min) - package_power_min = package_power; - if (package_power > package_power_max) - package_power_max = package_power; + if (package_eng_a >= package_eng_b) { + package_power = (package_eng_a - package_eng_b) * energy_unit / MESUREMENT_TIME; + + if (package_power < package_power_min) + package_power_min = package_power; + if (package_power > package_power_max) + package_power_max = package_power; + } for (i = 0; i < cores; i++) { - core_power[i] = (core_eng_a[i] - core_eng_b[i]) * energy_unit / MESUREMENT_TIME; - if (core_power[i] < core_power_min[i]) - core_power_min[i] = core_power[i]; - if (core_power[i] > core_power_max[i]) - core_power_max[i] = core_power[i]; + if (core_eng_a[i] >= core_eng_b[i]) { + core_power[i] = (core_eng_a[i] - core_eng_b[i]) * energy_unit / MESUREMENT_TIME; + + if (core_power[i] < core_power_min[i]) + core_power_min[i] = core_power[i]; + if (core_power[i] > core_power_max[i]) + core_power_max[i] = core_power[i]; + } } } -- cgit v1.2.3-70-g09d2