Skip to content

Commit

Permalink
hwmon: ibmaem: Use ktime_get_ns()
Browse files Browse the repository at this point in the history
Using the wall clock time for delta time calculations is wrong to
begin with because wall clock time can be set from userspace and NTP.
Such data wants to be based on clock monotonic.

The calculations also are done on a nanosecond basis. Use the
nanoseconds based interface right away.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Jean Delvare <jdelvare@suse.de>
Acked-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
  • Loading branch information
Thomas Gleixner authored and johnstultz-work committed Jul 23, 2014
1 parent 5eaaed4 commit d659f9b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions drivers/hwmon/ibmaem.c
Expand Up @@ -842,11 +842,10 @@ static ssize_t aem_show_power(struct device *dev,
struct aem_data *data = dev_get_drvdata(dev);
u64 before, after, delta, time;
signed long leftover;
struct timespec b, a;

mutex_lock(&data->lock);
update_aem_energy_one(data, attr->index);
getnstimeofday(&b);
time = ktime_get_ns();
before = data->energy[attr->index];

leftover = schedule_timeout_interruptible(
Expand All @@ -858,11 +857,10 @@ static ssize_t aem_show_power(struct device *dev,
}

update_aem_energy_one(data, attr->index);
getnstimeofday(&a);
time = ktime_get_ns() - time;
after = data->energy[attr->index];
mutex_unlock(&data->lock);

time = timespec_to_ns(&a) - timespec_to_ns(&b);
delta = (after - before) * UJ_PER_MJ;

return sprintf(buf, "%llu\n",
Expand Down

0 comments on commit d659f9b

Please sign in to comment.