Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751891AbdHHFHH (ORCPT ); Tue, 8 Aug 2017 01:07:07 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:38876 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750736AbdHHFHF (ORCPT ); Tue, 8 Aug 2017 01:07:05 -0400 From: Yafang Shao To: gregkh@linuxfoundation.org, jslaby@suse.com, mingo@redhat.com, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, laoar.shao@gmail.com Subject: [PATCH v2] scheduler: enhancement to show_state_filter Date: Tue, 8 Aug 2017 20:53:10 +0800 Message-Id: <1502196790-12585-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3142 Lines: 104 Sometimes we want to get tasks in TASK_RUNNING sepcifically, instead of dump all tasks. For example, when the loadavg are high, we want to dump tasks in TASK_RUNNING and TASK_UNINTERRUPTIBLE, which contribute to system load. But mostly there're lots of tasks in Sleep state, which occupies almost all of the kernel log buffer, even overflows it, that causes the useful messages get lost. Although we can enlarge the kernel log buffer, but that's not a good idea. So I made this change to make the show_state_filter more flexible, and then we can dump the tasks in TASK_RUNNING specifically. Signed-off-by: Yafang Shao --- drivers/tty/sysrq.c | 2 +- include/linux/sched.h | 1 + include/linux/sched/debug.h | 6 ++++-- kernel/sched/core.c | 7 ++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 3ffc1ce..86db51b 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -291,7 +291,7 @@ static void sysrq_handle_showstate(int key) static void sysrq_handle_showstate_blocked(int key) { - show_state_filter(TASK_UNINTERRUPTIBLE); + show_state_filter(TASK_UNINTERRUPTIBLE << 1); } static struct sysrq_key_op sysrq_showstate_blocked_op = { .handler = sysrq_handle_showstate_blocked, diff --git a/include/linux/sched.h b/include/linux/sched.h index 8337e2d..318f149 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -82,6 +82,7 @@ #define TASK_NOLOAD 1024 #define TASK_NEW 2048 #define TASK_STATE_MAX 4096 +#define TASK_ALL_BITS ((TASK_STATE_MAX << 1) - 1) #define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPNn" diff --git a/include/linux/sched/debug.h b/include/linux/sched/debug.h index e0eaee5..c844689 100644 --- a/include/linux/sched/debug.h +++ b/include/linux/sched/debug.h @@ -1,6 +1,8 @@ #ifndef _LINUX_SCHED_DEBUG_H #define _LINUX_SCHED_DEBUG_H +#include + /* * Various scheduler/task debugging interfaces: */ @@ -10,13 +12,13 @@ extern void dump_cpu_task(int cpu); /* - * Only dump TASK_* tasks. (0 for all tasks) + * Only dump TASK_* tasks. (TASK_ALL_BITS for all tasks) */ extern void show_state_filter(unsigned long state_filter); static inline void show_state(void) { - show_state_filter(0); + show_state_filter(TASK_ALL_BITS); } struct pt_regs; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0869b20..f9b9529 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5161,19 +5161,20 @@ void show_state_filter(unsigned long state_filter) */ touch_nmi_watchdog(); touch_all_softlockup_watchdogs(); - if (!state_filter || (p->state & state_filter)) + /* in case we want to set TASK_RUNNING specifically */ + if ((p->state != TASK_RUNNING ? p->state << 1 : 1) & state_filter) sched_show_task(p); } #ifdef CONFIG_SCHED_DEBUG - if (!state_filter) + if (state_filter == TASK_ALL_BITS) sysrq_sched_debug_show(); #endif rcu_read_unlock(); /* * Only show locks if all tasks are dumped: */ - if (!state_filter) + if (state_filter == TASK_ALL_BITS) debug_show_all_locks(); } -- 1.8.3.1