Skip to contentSkip to conversation

lockstat - fix numerical output rounding error

PATCH Applied Joe Korty 2 participants 2 messages Aug 25, 2008 – Aug 26, 2008

lore
Share & tools
lore

Joe Korty

author
#0 lore raw

PATCH 1/1 lockstat - fix numerical output rounding error

Fix rounding error in /proc/lock_stat numerical output.

On occasion the two digit fractional part contains the three digit value '100'. This is due to a bug in the rounding algorithm which pushes values in the range '95..99' to '100' rather than to '00' + an increment to the integer part. For example,

- 123456.100 old display
+ 123457.00 new display

kernel/lockdep_proc.c +2 -1
Index: 2.6.26/kernel/lockdep_proc.c
===================================================================
@@ -406,8 +406,9 @@
 {
 	unsigned long rem;
 
+	nr += 5; /* for display rounding */
 	rem = do_div(nr, 1000); /* XXX: do_div_signed */
-	snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, ((int)rem+5)/10);
+	snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, (int)rem/10);
 }
 
 static void seq_time(struct seq_file *m, s64 time)
Applied
#1 lore raw
Quoted 9 lines · Joe Korty

Fix rounding error in /proc/lock_stat numerical output.

On occasion the two digit fractional part contains the three digit value '100'. This is due to a bug in the rounding algorithm which pushes values in the range '95..99' to '100' rather than to '00' + an increment to the integer part. For example,

- 123456.100 old display
+ 123457.00 new display

applied to tip/core/urgent - thanks Joe!

(btw., please include Signed-off-by lines in your patches in the future)

Ingo