sched/debug: Adjust newlines for better alignment
authorJoe Lawrence <joe.lawrence@redhat.com>
Mon, 19 Mar 2018 18:35:55 +0000 (14:35 -0400)
committerIngo Molnar <mingo@kernel.org>
Tue, 20 Mar 2018 08:30:09 +0000 (09:30 +0100)
Scheduler debug stats include newlines that display out of alignment
when prefixed by timestamps.  For example, the dmesg utility:

  % echo t > /proc/sysrq-trigger
  % dmesg
  ...
  [   83.124251]
  runnable tasks:
   S           task   PID         tree-key  switches  prio     wait-time
  sum-exec        sum-sleep
  -----------------------------------------------------------------------------------------------------------

At the same time, some syslog utilities (like rsyslog by default) don't
like the additional newlines control characters, saving lines like this
to /var/log/messages:

  Mar 16 16:02:29 localhost kernel: #012runnable tasks:#012 S           task   PID         tree-key ...
                                    ^^^^               ^^^^
Clean these up by moving newline characters to their own SEQ_printf
invocation.  This leaves the /proc/sched_debug unchanged, but brings the
entire output into alignment when prefixed:

  % echo t > /proc/sysrq-trigger
  % dmesg
  ...
  [   62.410368] runnable tasks:
  [   62.410368]  S           task   PID         tree-key  switches  prio     wait-time             sum-exec        sum-sleep
  [   62.410369] -----------------------------------------------------------------------------------------------------------
  [   62.410369]  I  kworker/u12:0     5      1932.215593       332   120         0.000000         3.621252         0.000000 0 0 /

and no escaped control characters from rsyslog in /var/log/messages:

  Mar 16 16:15:06 localhost kernel: runnable tasks:
  Mar 16 16:15:06 localhost kernel: S           task   PID         tree-key  ...

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1521484555-8620-3-git-send-email-joe.lawrence@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/sched/debug.c

index 50026aa2d81e7534459d314182260e0963551652..72c401b3b15ceadcf724176028f68ff1f7c82d8b 100644 (file)
@@ -501,12 +501,12 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
 {
        struct task_struct *g, *p;
 
-       SEQ_printf(m,
-       "\nrunnable tasks:\n"
-       " S           task   PID         tree-key  switches  prio"
-       "     wait-time             sum-exec        sum-sleep\n"
-       "-------------------------------------------------------"
-       "----------------------------------------------------\n");
+       SEQ_printf(m, "\n");
+       SEQ_printf(m, "runnable tasks:\n");
+       SEQ_printf(m, " S           task   PID         tree-key  switches  prio"
+                  "     wait-time             sum-exec        sum-sleep\n");
+       SEQ_printf(m, "-------------------------------------------------------"
+                  "----------------------------------------------------\n");
 
        rcu_read_lock();
        for_each_process_thread(g, p) {
@@ -527,9 +527,11 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
        unsigned long flags;
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-       SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
+       SEQ_printf(m, "\n");
+       SEQ_printf(m, "cfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
 #else
-       SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
+       SEQ_printf(m, "\n");
+       SEQ_printf(m, "cfs_rq[%d]:\n", cpu);
 #endif
        SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "exec_clock",
                        SPLIT_NS(cfs_rq->exec_clock));
@@ -595,9 +597,11 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
 void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
 {
 #ifdef CONFIG_RT_GROUP_SCHED
-       SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
+       SEQ_printf(m, "\n");
+       SEQ_printf(m, "rt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
 #else
-       SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
+       SEQ_printf(m, "\n");
+       SEQ_printf(m, "rt_rq[%d]:\n", cpu);
 #endif
 
 #define P(x) \
@@ -624,7 +628,8 @@ void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
 {
        struct dl_bw *dl_bw;
 
-       SEQ_printf(m, "\ndl_rq[%d]:\n", cpu);
+       SEQ_printf(m, "\n");
+       SEQ_printf(m, "dl_rq[%d]:\n", cpu);
 
 #define PU(x) \
        SEQ_printf(m, "  .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x))