Skip to content

Commit 13e099d

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/debug: Fix printing large integers on 32-bit platforms
Some numbers like nr_running and nr_uninterruptible are fundamentally unsigned since its impossible to have a negative amount of tasks, yet we still print them as signed to easily recognise the underflow condition. rq->nr_uninterruptible has 'special' accounting and can in fact very easily become negative on a per-cpu basis. It was noted that since the P() macro assumes things are long long and the promotion of unsigned 'int/long' to long long on 32bit doesn't sign extend we print silly large numbers instead of the easier to read signed numbers. Therefore extend the P() macro to not require the sign extention. Reported-by: Diwakar Tundlam <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent e44bc5c commit 13e099d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kernel/sched/debug.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,14 @@ static void print_cpu(struct seq_file *m, int cpu)
260260
SEQ_printf(m, "\ncpu#%d\n", cpu);
261261
#endif
262262

263-
#define P(x) \
264-
SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x))
263+
#define P(x) \
264+
do { \
265+
if (sizeof(rq->x) == 4) \
266+
SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \
267+
else \
268+
SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
269+
} while (0)
270+
265271
#define PN(x) \
266272
SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
267273

0 commit comments

Comments
 (0)