From patchwork Tue Aug 22 01:54:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Shile (NSB - CN/Hangzhou)" X-Patchwork-Id: 9914091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 93544603FF for ; Tue, 22 Aug 2017 01:56:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8151F2881D for ; Tue, 22 Aug 2017 01:56:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75FCC28820; Tue, 22 Aug 2017 01:56:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 033C628824 for ; Tue, 22 Aug 2017 01:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754501AbdHVByo (ORCPT ); Mon, 21 Aug 2017 21:54:44 -0400 Received: from mail-db5eur01on0135.outbound.protection.outlook.com ([104.47.2.135]:20160 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754388AbdHVByn (ORCPT ); Mon, 21 Aug 2017 21:54:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector2-nokia-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RdVSm+iumsHYLB+orc5QTOGNPvjna7lTRmNB0w+H0NQ=; b=XkOGMkWGzE1gFfD5sf5VNJSRP7j7kCPt8/oc50xZTRDpZjEQOhgFHGbUqHw6LTP5Oqtdk3My7YeN7zfweZEkGg3ROEs5NvnnGfGEo2Ik7sPEEBY58uIG/2080uQ5K6gIwYQvt7y1gcRLJ8HK64ki3V4vDT6xNgtzxSwt+EpZz9Y= Received: from VI1PR0701MB2846.eurprd07.prod.outlook.com (10.173.71.141) by VI1PR0701MB2896.eurprd07.prod.outlook.com (10.173.72.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1385.4; Tue, 22 Aug 2017 01:54:39 +0000 Received: from VI1PR0701MB2846.eurprd07.prod.outlook.com ([fe80::f0de:3288:1364:c012]) by VI1PR0701MB2846.eurprd07.prod.outlook.com ([fe80::f0de:3288:1364:c012%18]) with mapi id 15.01.1385.008; Tue, 22 Aug 2017 01:54:39 +0000 From: "Zhang, Shile (NSB - CN/Hangzhou)" To: Imran Khan , "mingo@kernel.org" CC: "imrank140517@gmail.com" , "Luis R. Rodriguez" , Kees Cook , "Peter Zijlstra (Intel)" , Matt Fleming , Andrew Morton , Vegard Nossum , Tetsuo Handa , John Siddle , "open list" , "open list:PROC SYSCTL" Subject: RE: [PATCH] RFC: hung task: Check specific tasks for long uninterruptible sleep state Thread-Topic: [PATCH] RFC: hung task: Check specific tasks for long uninterruptible sleep state Thread-Index: AQHTGmftIm+BcDYYCUSz8Kt9Ox2CqaKPmstg Date: Tue, 22 Aug 2017 01:54:39 +0000 Message-ID: References: <1503311156-16919-1-git-send-email-kimran@codeaurora.org> In-Reply-To: <1503311156-16919-1-git-send-email-kimran@codeaurora.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=shile.zhang@nokia-sbell.com; x-originating-ip: [131.228.32.166] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR0701MB2896; 6:vVmb2huxq/7FS+fQxUt67Lkq8sev20vl1SD1ryIb8rBqy+5JoZ96QsotrduBvrnPEV4YzvUdDbfH/3Dy9+p9vGNuTrNH+iXHZdPzCbfFDITYw21aQI2/2F2K1doomPjdzqalar+XIiqnFM3w5bVTZQKoMrEECX8o2nz3yiL3PMKay1AxF7p+qmUKP3cUq0Jq9Pz7RZImQiTGEx8btpstRUlmElJ3dKOzx23HBDQU9B/2cdTsG7PN2/8vMK7IqIK3ck606m5CEZKlAjxAn/NhaGwweRF17vZoIvdZuzKY6wZHoPCOg+hw5Riw6BRg5IYIZknwPxGymEzz1ySq/M8Q7g==; 5:cRtantZB/0lnK1Mq26LJA376788tLTYx8kwshlAM8fp+KexSuy2OPHPHpikyBC9t0sWe1iRnLqfC1af8wmN9VH82naLVi/00HmiIik7ilml8TiySLPMkxTy9atnqVLyhCPbr00wYUiyLgoOd9/VH0g==; 24:MDmRlZqJVNvjOhX9EZjkzHF3fUbZeKKHcdAbu4ji0IlPaRsJGwxsm8eoXKEnF8Us7y1ICypZQ+KwWJMZkSKremgVnIsdHDyXN3FzFwHZhkk=; 7:HyYP+3lY1UJBTIz/e50HQqr4vadp/8TVAVafFqAgSFX3+k1rUaVtbwzljugt8/CJbYrKC6frFKsd8KXLV9p4XvMd05HM+Son+qP0IUvSBFtBQhZ+pRhnB7KspUFuXGIvaeCgoY5QC2KDIfEHnzG/On6ER0yBOpIeYP7qoqPb8TgQvpnpo+YUDsjh+H7Nn8EBZMUVKmb3qVvjlTp+JCiOMztrv93+xL0TsYDzFu5AVSs= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 7308d12a-ceb2-467e-03d7-08d4e900bfb3 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:VI1PR0701MB2896; x-ms-traffictypediagnostic: VI1PR0701MB2896: x-exchange-antispam-report-test: UriScan:(72170088055959)(9452136761055)(146099531331640); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123555025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0701MB2896; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0701MB2896; x-forefront-prvs: 04073E895A x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(39860400002)(189002)(13464003)(199003)(377454003)(2900100001)(5660300001)(3280700002)(478600001)(6436002)(99286003)(54906002)(53546010)(2906002)(229853002)(9686003)(3660700001)(55016002)(97736004)(3846002)(6116002)(102836003)(6506006)(2950100002)(105586002)(106356001)(101416001)(68736007)(33656002)(39060400002)(14454004)(25786009)(8936002)(74316002)(81156014)(7736002)(81166006)(305945005)(2501003)(66066001)(86362001)(7696004)(5250100002)(7416002)(4326008)(6246003)(76176999)(53936002)(189998001)(50986999)(54356999)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0701MB2896; H:VI1PR0701MB2846.eurprd07.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:0; LANG:en; received-spf: None (protection.outlook.com: nokia-sbell.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nokia-sbell.com X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Aug 2017 01:54:39.0597 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0701MB2896 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, Imran, I think a "unmonitored list" is better than "monitor list", because we want khungtaskd can find out the "unexpected" hung task, but not few in a list. Then, for the fg tasks, which can put it in the "unmonitored list", for the bg tasks, I think we can tweak the timeout to control the duration. Thanks! BR, Shile -----Original Message----- From: Imran Khan [mailto:kimran@codeaurora.org] Sent: Monday, August 21, 2017 6:26 PM To: mingo@kernel.org Cc: imrank140517@gmail.com; Imran Khan ; Luis R. Rodriguez ; Kees Cook ; Peter Zijlstra (Intel) ; Zhang, Shile (NSB - CN/Hangzhou) ; Matt Fleming ; Andrew Morton ; Vegard Nossum ; Tetsuo Handa ; John Siddle ; open list ; open list:PROC SYSCTL Subject: [PATCH] RFC: hung task: Check specific tasks for long uninterruptible sleep state khungtask by default monitors either all tasks or no tasks at all for long unterruptible sleeps. For Android like environments this arrangement is not optimal because on one hand it may be permissible to have some background(bg) task in uninterruptible sleep state for long duration while on the other hand it may not be permissible to have some foreground(fg) task like surfaceflinger in uninterruptible sleep state for long duration. So it would be good to have some arrangement so that few specified tasks can be monitored by khungtaskd, on a need basis. This change introduces a sysctl option, /proc/sys/kernel/ hung_task_check_selected, to enable monitoring of selected tasks using khungtask daemon. If this sysctl option is enabled then only the tasks specified in /proc/hung_task_monitor_list are monitored otherwise all tasks are monitored, just like the default case. Signed-off-by: Imran Khan --- include/linux/sched/sysctl.h | 1 + kernel/hung_task.c | 121 ++++++++++++++++++++++++++++++++++++++++++- kernel/sysctl.c | 8 +++ 3 files changed, 128 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h index 0f5ecd4..05892f1 100644 --- a/include/linux/sched/sysctl.h +++ b/include/linux/sched/sysctl.h @@ -10,6 +10,7 @@ extern unsigned int sysctl_hung_task_panic; extern unsigned long sysctl_hung_task_timeout_secs; extern int sysctl_hung_task_warnings; +extern int sysctl_hung_task_check_selected; extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 751593e..49f13fb 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -16,12 +16,28 @@ #include #include #include +#include +#include +#include #include #include #include /* + * Hung task that needs monitoring + */ +struct hung_task { + struct list_head list; + char comm[TASK_COMM_LEN]; +}; + +static struct hung_task *monitor_list; +int sysctl_hung_task_check_selected; + + + +/* * The number of tasks checked: */ int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; @@ -76,6 +92,92 @@ static int __init hung_task_panic_setup(char *str) .notifier_call = hung_task_panic, }; +static void hung_task_monitor_setup(void) +{ + monitor_list = kmalloc(sizeof(*monitor_list), GFP_KERNEL); + if (monitor_list) { + INIT_LIST_HEAD(&monitor_list->list); + memset(monitor_list->comm, 0, TASK_COMM_LEN); + } +} + + +static int hung_task_info_show(struct seq_file *m, void *v) +{ + struct hung_task *ht; + + ht = list_entry(v, struct hung_task, list); + seq_puts(m, ht->comm); + + return 0; +} + +static void *hung_task_info_start(struct seq_file *m, loff_t *pos) +{ + return seq_list_start_head(&monitor_list->list, *pos); +} + +static void *hung_task_info_next(struct seq_file *m, void *v, loff_t *pos) +{ + return seq_list_next(v, &monitor_list->list, pos); +} + +static void hung_task_info_stop(struct seq_file *m, void *v) +{ +} + +const struct seq_operations hung_task_info_op = { + .start = hung_task_info_start, + .next = hung_task_info_next, + .stop = hung_task_info_stop, + .show = hung_task_info_show +}; + +static int hung_task_info_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &hung_task_info_op); +} + +static ssize_t +hung_task_info_write(struct file *file, const char __user *buf, size_t count, + loff_t *offs) +{ + struct task_struct *g, *t; + struct hung_task *ht = kmalloc(sizeof(*ht), GFP_KERNEL); + + if (!ht) + return -ENOMEM; + + if (copy_from_user(ht->comm, buf, count)) + return -EFAULT; + ht->comm[count] = '\0'; + + for_each_process_thread(g, t) { + if (!strncmp(t->comm, ht->comm, strlen(t->comm))) { + list_add_tail(&ht->list, &monitor_list->list); + return count; + } + } + + pr_err("Non-existing task: %s can't be monitored\n", ht->comm); + return count; +} + +static const struct file_operations hung_task_info_operations = { + .open = hung_task_info_open, + .read = seq_read, + .write = hung_task_info_write, + .llseek = seq_lseek, + .release = seq_release, +}; + +static int __init proc_hung_task_info_init(void) +{ + proc_create("hung_task_monitor_list", 0644, NULL, + &hung_task_info_operations); + return 0; +} + static void check_hung_task(struct task_struct *t, unsigned long timeout) { unsigned long switch_count = t->nvcsw + t->nivcsw; @@ -167,6 +269,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) int max_count = sysctl_hung_task_check_count; int batch_count = HUNG_TASK_BATCHING; struct task_struct *g, *t; + struct hung_task *ht, *tmp; /* * If the system crashed already then all bets are off, @@ -186,9 +289,21 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) goto unlock; } /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ - if (t->state == TASK_UNINTERRUPTIBLE) - check_hung_task(t, timeout); + if (t->state == TASK_UNINTERRUPTIBLE) { + if (sysctl_hung_task_check_selected) { + list_for_each_entry_safe(ht, tmp, + &monitor_list->list, + list) + if (!strncmp(ht->comm, t->comm, + strlen(t->comm))) + /* Task belongs to the selected group */ + check_hung_task(t, timeout); + } else { + check_hung_task(t, timeout); + } + } } + unlock: rcu_read_unlock(); if (hung_task_show_lock) @@ -259,6 +374,8 @@ static int watchdog(void *dummy) static int __init hung_task_init(void) { atomic_notifier_chain_register(&panic_notifier_list, &panic_block); + hung_task_monitor_setup(); + proc_hung_task_info_init(); watchdog_task = kthread_run(watchdog, NULL, "khungtaskd"); return 0; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 6648fbb..ab45774 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1096,6 +1096,14 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .proc_handler = proc_dointvec_minmax, .extra1 = &neg_one, }, + { + .procname = "hung_task_check_selected", + .data = &sysctl_hung_task_check_selected, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &neg_one, + }, #endif #ifdef CONFIG_RT_MUTEXES {