From: "Carlos R. Mafra" <crmafra2@gmail.com>
To: "Darrick J. Wong" <djwong@us.ibm.com>
Cc: Adrian Bunk <bunk@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
mhoffman@lightlink.com, linux-kernel@vger.kernel.org,
lm-sensors@lm-sensors.org
Subject: Re: [PATCH v2] ibmaem: Fix 64-bit division on 32-bit platforms
Date: Thu, 15 May 2008 19:49:14 -0300 [thread overview]
Message-ID: <20080515224914.GA27674@beyonder.ift.unesp.br> (raw)
In-Reply-To: <20080515211809.GB7323@tree.beaverton.ibm.com>
On Thu 15.May'08 at 14:18:09 -0700, Darrick J. Wong wrote:
> > To avoid these kind of doubts may I suggest using the time
> > conversion definitions of include/linux/time.h?
> >
> > It would be much easier to understand the intention with
> > NSEC_PER_SEC, USEC_PER_SEC etc (comments would also help)
>
> Ok, here's an updated version that makes the conversions a bit clearer.
> Tested and run on i386/x86-64.
> ---
> ibmaem: Fix 64-bit division on 32-bit platforms
>
> Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
> ---
>
> drivers/hwmon/ibmaem.c | 9 ++++++---
> 1 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
> index 22fa7d6..3013492 100644
> --- a/drivers/hwmon/ibmaem.c
> +++ b/drivers/hwmon/ibmaem.c
> @@ -31,6 +31,8 @@
> #include <linux/idr.h>
> #include <linux/sched.h>
> #include <linux/platform_device.h>
> +#include <linux/math64.h>
> +#include <linux/time.h>
>
> #define REFRESH_INTERVAL (HZ)
> #define IPMI_TIMEOUT (30 * HZ)
> @@ -81,6 +83,7 @@
>
> #define AEM_DEFAULT_POWER_INTERVAL 1000
> #define AEM_MIN_POWER_INTERVAL 200
> +#define UJ_PER_MJ 1000L
>
> static DEFINE_IDR(aem_idr);
> static DEFINE_SPINLOCK(aem_idr_lock);
> @@ -841,7 +844,7 @@ static ssize_t aem_show_power(struct device *dev,
> {
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct aem_data *data = dev_get_drvdata(dev);
> - u64 before, after, time;
> + u64 before, after, delta, time;
> signed long leftover;
> struct timespec b, a;
>
> @@ -864,9 +867,9 @@ static ssize_t aem_show_power(struct device *dev,
> mutex_unlock(&data->lock);
>
> time = timespec_to_ns(&a) - timespec_to_ns(&b);
> - time /= 1000;
> + delta = (after - before) * UJ_PER_MJ;
>
> - return sprintf(buf, "%llu\n", (after - before) * 1000000000 / time);
> + return sprintf(buf, "%llu\n", div64_u64(delta * NSEC_PER_SEC, time));
> }
Thanks!
Wow...so the power unit really is uW, which is a nice precision!
prev parent reply other threads:[~2008-05-15 22:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-08 18:08 [PATCH v3] ibmaem: New driver for power/energy/temp meters in IBM System X hardware Darrick J. Wong
2008-05-08 23:34 ` Andrew Morton
2008-05-09 4:55 ` [PATCH] ibmaem: Fix 64-bit division on 32-bit platforms Darrick J. Wong
2008-05-14 22:27 ` Adrian Bunk
2008-05-14 23:11 ` Carlos R. Mafra
2008-05-15 21:18 ` [PATCH v2] " Darrick J. Wong
2008-05-15 22:49 ` Carlos R. Mafra [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080515224914.GA27674@beyonder.ift.unesp.br \
--to=crmafra2@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bunk@kernel.org \
--cc=djwong@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=mhoffman@lightlink.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox