Skip to contentSkip to conversation

linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends

PATCH In review Guenter Roeck 4 participants 9 messages Aug 31, 2012 – Sep 9, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

	DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

---
v4: Don't address negative divisors to improve chances for compile-time
optimization. Document DIV_ROUND_CLOSEST macro.

v3: Instead of adding a new macro, fix DIV_ROUND_CLOSEST.
This version works for negative dividend and divisor.

v2: v1 did not work if typeof(divisor) was an unsigned variable type
(which can obviously not be negative).
Rework to revert to DIV_ROUND_CLOSEST if the dividend is unsigned, or if it is signed but non-negative.

 include/linux/kernel.h |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
include/linux/kernel.h +10 -2
index 6043821..594b419 100644
@@ -82,10 +82,18 @@
 	__x - (__x % (y));				\
 }							\
 )
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors.
+ */
 #define DIV_ROUND_CLOSEST(x, divisor)(			\
 {							\
-	typeof(divisor) __divisor = divisor;		\
-	(((x) + ((__divisor) / 2)) / (__divisor));	\
+	typeof(x) __x = x;				\
+	typeof(divisor) __d = divisor;			\
+	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
+		(((__x) + ((__d) / 2)) / (__d)) :	\
+		(((__x) - ((__d) / 2)) / (__d));	\
 }							\
 )
 
Signature · 1 line
1.7.9.7
#1 lore raw
Quoted 14 lines · On Fri, 31 Aug 2012 08:02:19 -0700 Guenter Roeck <[email protected]> wrote:

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

	DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

...

include/linux/kernel.h +5 -0
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors.
+ */

include/linux/kernel.h line 97

Quoted 10 lines
include/linux/kernel.h +5 -2
 #define DIV_ROUND_CLOSEST(x, divisor)(			\
 {							\
-	typeof(divisor) __divisor = divisor;		\
-	(((x) + ((__divisor) / 2)) / (__divisor));	\
+	typeof(x) __x = x;				\
+	typeof(divisor) __d = divisor;			\
+	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
+		(((__x) + ((__d) / 2)) / (__d)) :	\
+		(((__x) - ((__d) / 2)) / (__d));	\
 }							\

Looks good to me. The patch causes no change in text size for kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems that the cc trickery is working.

I'll add it to my tree for testing - please merge this via your tree.

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

#2 lore raw
Quoted 32 lines · Andrew Morton
Quoted 14 lines · On Fri, 31 Aug 2012 08:02:19 -0700 Guenter Roeck <[email protected]> wrote:

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

	DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

...

include/linux/kernel.h +5 -0
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors.
+ */

include/linux/kernel.h line 97

Quoted 10 lines
include/linux/kernel.h +5 -2
 #define DIV_ROUND_CLOSEST(x, divisor)(			\
 {							\
-	typeof(divisor) __divisor = divisor;		\
-	(((x) + ((__divisor) / 2)) / (__divisor));	\
+	typeof(x) __x = x;				\
+	typeof(divisor) __d = divisor;			\
+	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
+		(((__x) + ((__d) / 2)) / (__d)) :	\
+		(((__x) - ((__d) / 2)) / (__d));	\
 }							\

Looks good to me. The patch causes no change in text size for kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems that the cc trickery is working.

Quoted 2 lines

I'll add it to my tree for testing - please merge this via your tree.

Will do.

Thanks,
Guenter

Acked-by
#3 lore raw
In reply to Andrew Morton

Hi Andrew, Guenter,

Quoted 21 lines · Andrew Morton
Quoted 18 lines · On Fri, 31 Aug 2012 08:02:19 -0700 Guenter Roeck <[email protected]> wrote:

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

	DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

...

include/linux/kernel.h +5 -2
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors.
+ */
 #define DIV_ROUND_CLOSEST(x, divisor)(			\
 {							\
-	typeof(divisor) __divisor = divisor;		\
-	(((x) + ((__divisor) / 2)) / (__divisor));	\
Quoted 8 lines

include/linux/kernel.h line 97

Quoted 6 lines
include/linux/kernel.h +5 -0
+	typeof(x) __x = x;				\
+	typeof(divisor) __d = divisor;			\
+	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
+		(((__x) + ((__d) / 2)) / (__d)) :	\
+		(((__x) - ((__d) / 2)) / (__d));	\
 }							\

Looks good to me.

My testing looks good too.

Quoted 3 lines

The patch causes no change in text size for kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems that the cc trickery is working.

Indeed. I looked for test size increase, and for my config, besides hwmon, I only spotted the following ones:

drivers/media/rc/mceusb.o
drivers/gpu/drm/i915/intel_pm.o
drivers/tty/serial/pch_uart.o

These don't look like hot paths, so I'd say we don't care. Plus the intel_pm one can probably be solved by using an unsigned int, I don't see why/how ia_freq could be negative (negative frequency anyone?) And for mceusb it can be solved easily by changing "1" to "1U".

For hwmon drivers, we typically only use DIV_ROUND_CLOSEST when the user changes a setting, this isn't a frequent event. Plus, this is exactly the case we are fixing here, as temperature limits, and to a lesser extent voltage limits, can be negative.

Quoted 1 line

I'll add it to my tree for testing - please merge this via your tree.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw
Quoted 33 lines · Jean Delvare

Hi Andrew, Guenter,

Quoted 21 lines · Andrew Morton
Quoted 18 lines · On Fri, 31 Aug 2012 08:02:19 -0700 Guenter Roeck <[email protected]> wrote:

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

	DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

...

include/linux/kernel.h +5 -2
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors.
+ */
 #define DIV_ROUND_CLOSEST(x, divisor)(			\
 {							\
-	typeof(divisor) __divisor = divisor;		\
-	(((x) + ((__divisor) / 2)) / (__divisor));	\
Quoted 8 lines

include/linux/kernel.h line 97

Quoted 6 lines
include/linux/kernel.h +5 -0
+	typeof(x) __x = x;				\
+	typeof(divisor) __d = divisor;			\
+	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
+		(((__x) + ((__d) / 2)) / (__d)) :	\
+		(((__x) - ((__d) / 2)) / (__d));	\
 }							\

Looks good to me.

Quoted 4 lines

My testing looks good too.

Thanks a lot!

Quoted 7 lines
Quoted 3 lines

The patch causes no change in text size for kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems that the cc trickery is working.

Indeed. I looked for test size increase, and for my config, besides hwmon, I only spotted the following ones:

Quoted 9 lines

drivers/media/rc/mceusb.o
drivers/gpu/drm/i915/intel_pm.o
drivers/tty/serial/pch_uart.o

These don't look like hot paths, so I'd say we don't care. Plus the intel_pm one can probably be solved by using an unsigned int, I don't see why/how ia_freq could be negative (negative frequency anyone?) And for mceusb it can be solved easily by changing "1" to "1U".

Yes, it helps a lot that the C trickery optimizes the changes away most of the time.

I'll let the patch rest in -next for a few more days before I send it to Linus.

Guenter

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

#5 lore raw
In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

        DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:

drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to limited range of data type
drivers/ide/ide-cd.c:1158: warning: comparison is always true due to limited range of data type
drivers/ide/ide-cd.c:1159: warning: comparison is always true due to limited range of data type

$ m68k-linux-gnu-gcc -v
Using built-in specs.
Target: m68k-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --disable-libssp --disable-werror
--enable-checking=release --program-prefix=m68k-linux-gnu-
--includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=m68k-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

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

#6 lore raw
Quoted 17 lines · Geert Uytterhoeven
Quoted 6 lines · Guenter Roeck

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

        DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:

drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to limited range of data type
drivers/ide/ide-cd.c:1158: warning: comparison is always true due to limited range of data type
drivers/ide/ide-cd.c:1159: warning: comparison is always true due to limited range of data type

Quoted 15 lines
$ m68k-linux-gnu-gcc -v
Using built-in specs.
Target: m68k-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --disable-libssp --disable-werror
--enable-checking=release --program-prefix=m68k-linux-gnu-
--includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=m68k-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)

Hi Gert,

The "always true" condition is on purpose to cause the compiler to optimize the expression away. I don't see the warnings myself, on none of the targets I am building (x86, ppc, arm, mips), but then I am using much more recent compiler versions. Odd is that you only see the warnings on "u16" and not elsewhere.

I don't immediately see the warnings with a more recent m68k compiler (4.6.3), nor with any other target (x86, ppc, arm, mips) in my nightly builds. Can you send me your configuration ?
Also, do you know where I can find the Ubuntu/Debian package for your compiler version, by any chance ?

Thanks,
Guenter

#7 lore raw

SGkgR8O8bnRlciwKCk9uIFN1biwgU2VwIDksIDIwMTIgYXQgNjoxNyBQTSwgR3VlbnRlciBSb2Vj ayA8bGludXhAcm9lY2stdXMubmV0PiB3cm90ZToKPiBPbiBTdW4sIFNlcCAwOSwgMjAxMiBhdCAw NDo1NzozNFBNICswMjAwLCBHZWVydCBVeXR0ZXJob2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lv dXIgY29tcGlsZXIKPiB2ZXJzaW9uLCBieSBhbnkgY2hhbmNlID8KCkl0J3Mgbm90IGZyb20gYW4g b2ZmaWNpYWwgYmluYXJ5IHBhY2thZ2UuIEkgYnVpbHQgdGhlIGNyb3NzLWNvbXBpbGVyCmZyb20g dGhlIHRoZW4KY3VycmVudCBnY2MgNC4xLjEtMjEgc291cmNlcyBpbiBVYnVudHUuCgpHcntvZXRq ZSxlZXRpbmd9cywKCiAgICAgICAgICAgICAgICAgICAgICAgIEdlZXJ0CgotLQpHZWVydCBVeXR0 ZXJob2V2ZW4gLS0gVGhlcmUncyBsb3RzIG9mIExpbnV4IGJleW9uZCBpYTMyIC0tIGdlZXJ0QGxp bnV4LW02OGsub3JnCgpJbiBwZXJzb25hbCBjb252ZXJzYXRpb25zIHdpdGggdGVjaG5pY2FsIHBl b3BsZSwgSSBjYWxsIG15c2VsZiBhIGhhY2tlci4gQnV0CndoZW4gSSdtIHRhbGtpbmcgdG8gam91 cm5hbGlzdHMgSSBqdXN0IHNheSAicHJvZ3JhbW1lciIgb3Igc29tZXRoaW5nIGxpa2UgdGhhdC4K ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtLSBMaW51cyBUb3J2YWxkcwoKX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29ycyBtYWls aW5nIGxpc3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0tc2Vuc29y cy5vcmcvbWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz

#8 lore raw
Quoted 48 lines · Geert Uytterhoeven

Hi Günter,

Quoted 33 lines · Guenter Roeck
Quoted 17 lines · Geert Uytterhoeven
Quoted 6 lines · Guenter Roeck

DIV_ROUND_CLOSEST returns a bad result for negative dividends:

        DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be negative (such as temperatures).

This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:

drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to limited range of data type
drivers/ide/ide-cd.c:1158: warning: comparison is always true due to limited range of data type
drivers/ide/ide-cd.c:1159: warning: comparison is always true due to limited range of data type

Quoted 15 lines
$ m68k-linux-gnu-gcc -v
Using built-in specs.
Target: m68k-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --disable-libssp --disable-werror
--enable-checking=release --program-prefix=m68k-linux-gnu-
--includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=m68k-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)
Quoted 7 lines

The "always true" condition is on purpose to cause the compiler to optimize the expression away. I don't see the warnings myself, on none of the targets I am building (x86, ppc, arm, mips), but then I am using much more recent compiler versions. Odd is that you only see the warnings on "u16" and not elsewhere.

I don't immediately see the warnings with a more recent m68k compiler (4.6.3), nor with any other target (x86, ppc, arm, mips) in my nightly builds.

I also don't see it in any of the linux-next builds of v3.6-rc5. So probably it's just
a gcc 4.1.2 issue...

Quoted 6 lines
Quoted 1 line

Can you send me your configuration ?

The ide-cd one shows up in any config that enables ide-cd, incl. defconfig and allmodconfig.
The mcp3021 one I only see in allmodconfig.

I tried both and did not see the problem. I agree, it does look like a compiler version problem.

Quoted 7 lines
Quoted 2 lines

Also, do you know where I can find the Ubuntu/Debian package for your compiler version, by any chance ?

It's not from an official binary package. I built the cross-compiler from the then
current gcc 4.1.1-21 sources in Ubuntu.

Ok.

Just in case you are interested, I installed the m68k cross-compiler from
deb http://www.freewrt.org/~tg/debs68k/ cross main

For my other targets, I use Yocto builds.

I think I'll let this go as false positive for now, unless there are problems with more recent compilers.

Thanks,
Guenter

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