Skip to contentSkip to conversation

ibmaem: New driver for power/energy/temp meters in IBM System X hardware

PATCH In review Darrick J. Wong 4 participants 7 messages May 8, 2008 – May 15, 2008 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ibmaem: New driver for power/energy/temp meters in IBM System X hardware

Hi all,

Here's v3 of the driver, with all the macros removed and aem1 expressed as a subset of aem2 functionality. Also some minor cleanups that people have asked for. I've given this a spin on a few x3650/qs22 (cell) systems and all seems to be working ok. Thanks to all who've sent me feedback. :)
---
This driver reads IBM Active Energy Manager energy/temperature/power sensors on IBM System X hardware.

---

 drivers/hwmon/Kconfig  |   14 +
 drivers/hwmon/Makefile |    1 
 drivers/hwmon/ibmaem.c | 1106 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1121 insertions(+), 0 deletions(-)
drivers/hwmon/Kconfig +14 -0
index 4dc76bc..00ff533 100644
@@ -330,6 +330,20 @@ config SENSORS_CORETEMP
 	  sensor inside your CPU. Supported all are all known variants
 	  of Intel Core family.
 
+config SENSORS_IBMAEM
+	tristate "IBM Active Energy Manager temperature/power sensors and control"
+	select IPMI_SI
+	depends on IPMI_HANDLER
+	help
+	  If you say yes here you get support for the temperature and
+	  power sensors and capping hardware in various IBM System X
+	  servers that support Active Energy Manager.  This includes
+	  the x3350, x3550, x3650, x3655, x3755, x3850 M2, x3950 M2,
+	  and certain HS2x/LS2x/QS2x blades.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ibmaem.
+
 config SENSORS_IBMPEX
 	tristate "IBM PowerExecutive temperature/power sensors"
 	select IPMI_SI
drivers/hwmon/Makefile +1 -0
index 3bdb05a..d098677 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_GL518SM)	+= gl518sm.o
 obj-$(CONFIG_SENSORS_GL520SM)	+= gl520sm.o
 obj-$(CONFIG_SENSORS_HDAPS)	+= hdaps.o
 obj-$(CONFIG_SENSORS_I5K_AMB)	+= i5k_amb.o
+obj-$(CONFIG_SENSORS_IBMAEM)	+= ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)	+= ibmpex.o
 obj-$(CONFIG_SENSORS_IT87)	+= it87.o
 obj-$(CONFIG_SENSORS_K8TEMP)	+= k8temp.o
drivers/hwmon/ibmaem.c new file +1106 -0

1,106 lines not on this page · raw message

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw
Quoted 2 lines · On Thu, 8 May 2008 11:08:59 -0700 "Darrick J. Wong" <[email protected]> wrote:

This driver reads IBM Active Energy Manager energy/temperature/power sensors on IBM System X hardware.

This driver is littered with 64-bit divides and doesn't link on i386. I'll make it depend on CONFIG_64BIT for now.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw

PATCH 1/1 ibmaem: Fix 64-bit division on 32-bit platforms

Quoted 2 lines · Andrew Morton

This driver is littered with 64-bit divides and doesn't link on i386. I'll make it depend on CONFIG_64BIT for now.

Oops, sorry, I didn't remember that one can't do 64-bit division on i386. The patch below fixes that.
---
ibmaem: Fix 64-bit division on 32-bit platforms

---

 drivers/hwmon/ibmaem.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/hwmon/ibmaem.c +4 -2
index 22fa7d6..f808ca3 100644
@@ -31,6 +31,7 @@
 #include <linux/idr.h>
 #include <linux/sched.h>
 #include <linux/platform_device.h>
+#include <linux/math64.h>
 
 #define REFRESH_INTERVAL	(HZ)
 #define IPMI_TIMEOUT		(30 * HZ)
@@ -864,9 +865,10 @@ static ssize_t aem_show_power(struct device *dev,
 	mutex_unlock(&data->lock);
 
 	time = timespec_to_ns(&a) - timespec_to_ns(&b);
-	time /= 1000;
+	time = div_u64(time, 1000);
 
-	return sprintf(buf, "%llu\n", (after - before) * 1000000000 / time);
+	return sprintf(buf, "%llu\n",
+		       div64_u64((after - before) * 1000000000, time));
 }
 
 /* Display energy use */

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw

Re: [PATCH] ibmaem: Fix 64-bit division on 32-bit platforms

Quoted 22 lines · Darrick J. Wong
Quoted 2 lines · Andrew Morton

This driver is littered with 64-bit divides and doesn't link on i386. I'll make it depend on CONFIG_64BIT for now.

Oops, sorry, I didn't remember that one can't do 64-bit division on i386. The patch below fixes that.
---
ibmaem: Fix 64-bit division on 32-bit platforms

---

 drivers/hwmon/ibmaem.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/hwmon/ibmaem.c +0 -0
index 22fa7d6..f808ca3 100644
...

drivers/hwmon/ibmaem.c static ssize_t aem_show_power(struct device *dev, · line 872

Quoted 10 lines
drivers/hwmon/ibmaem.c +3 -2
@@ -864,9 +865,10 @@ static ssize_t aem_show_power(struct device *dev,
...
 	time = timespec_to_ns(&a) - timespec_to_ns(&b);
-	time /= 1000;
+	time = div_u64(time, 1000);
 
-	return sprintf(buf, "%llu\n", (after - before) * 1000000000 / time);
+	return sprintf(buf, "%llu\n",
+		       div64_u64((after - before) * 1000000000, time));
 }
...

What are you actually trying to do here?

Converting mJ/ns to uJ/s?

Or do you want to convert mJ/ns to Watt in which case you should multiply "time" with 1000 instead of dividing it through 1000?

In any case you should only need one expensive 64bit division and you can fold the operation with 1000 into the second division.

cu
Adrian

Signature · 10 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw

Re: [PATCH] ibmaem: Fix 64-bit division on 32-bit platforms

Quoted 36 lines · Adrian Bunk
Quoted 22 lines · Darrick J. Wong
Quoted 2 lines · Andrew Morton

This driver is littered with 64-bit divides and doesn't link on i386. I'll make it depend on CONFIG_64BIT for now.

Oops, sorry, I didn't remember that one can't do 64-bit division on i386. The patch below fixes that.
---
ibmaem: Fix 64-bit division on 32-bit platforms

---

 drivers/hwmon/ibmaem.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/hwmon/ibmaem.c +0 -0
index 22fa7d6..f808ca3 100644
...

drivers/hwmon/ibmaem.c static ssize_t aem_show_power(struct device *dev, · line 872

Quoted 10 lines
drivers/hwmon/ibmaem.c +3 -2
@@ -864,9 +865,10 @@ static ssize_t aem_show_power(struct device *dev,
...
 	time = timespec_to_ns(&a) - timespec_to_ns(&b);
-	time /= 1000;
+	time = div_u64(time, 1000);
 
-	return sprintf(buf, "%llu\n", (after - before) * 1000000000 / time);
+	return sprintf(buf, "%llu\n",
+		       div64_u64((after - before) * 1000000000, time));
 }
...

What are you actually trying to do here?

Quoted 4 lines

Converting mJ/ns to uJ/s?

Or do you want to convert mJ/ns to Watt in which case you should multiply "time" with 1000 instead of dividing it through 1000?

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)

Quoted 2 lines

In any case you should only need one expensive 64bit division and you can fold the operation with 1000 into the second division.

I agree.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#5 lore raw

PATCH v2 1/1 ibmaem: Fix 64-bit division on 32-bit platforms

Quoted 5 lines

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

---

 drivers/hwmon/ibmaem.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/hwmon/ibmaem.c +6 -3
index 22fa7d6..3013492 100644
@@ -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));
 }
 
 /* Display energy use */

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#6 lore raw

Re: [PATCH v2] ibmaem: Fix 64-bit division on 32-bit platforms

Quoted 48 lines · Darrick J. Wong
Quoted 5 lines

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

---

 drivers/hwmon/ibmaem.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/hwmon/ibmaem.c +4 -1
index 22fa7d6..3013492 100644
@@ -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;
 

drivers/hwmon/ibmaem.c static ssize_t aem_show_power(struct device *dev, · line 873

Quoted 9 lines
drivers/hwmon/ibmaem.c +2 -2
@@ -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!

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors