From patchwork Fri Jun 5 15:01:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 481408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 02B901401DA for ; Sat, 6 Jun 2015 01:29:10 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0tUz-0003oe-9e; Fri, 05 Jun 2015 15:25:33 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0tUd-0002do-74 for linux-mtd@bombadil.infradead.org; Fri, 05 Jun 2015 15:25:11 +0000 Received: from cantor2.suse.de ([195.135.220.15] helo=mx2.suse.de) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0t8j-0002SR-7h for linux-mtd@lists.infradead.org; Fri, 05 Jun 2015 15:02:34 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A3611ADD8; Fri, 5 Jun 2015 15:01:58 +0000 (UTC) From: Petr Mladek To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Subject: [RFC PATCH 08/18] kthread: Allow to get struct kthread_iterant from task_struct Date: Fri, 5 Jun 2015 17:01:07 +0200 Message-Id: <1433516477-5153-9-git-send-email-pmladek@suse.cz> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1433516477-5153-1-git-send-email-pmladek@suse.cz> References: <1433516477-5153-1-git-send-email-pmladek@suse.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150605_160233_307093_46B5F0ED X-CRM114-Status: GOOD ( 16.05 ) X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.4.0 on casper.infradead.org summary: Content analysis details: (-6.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [195.135.220.15 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-nfs@vger.kernel.org, Borislav Petkov , Jiri Kosina , Richard Weinberger , Trond Myklebust , linux-kernel@vger.kernel.org, Steven Rostedt , Michal Hocko , Chris Mason , Petr Mladek , linux-mtd@lists.infradead.org, linux-api@vger.kernel.org, Linus Torvalds , live-patching@vger.kernel.org, Thomas Gleixner , "Paul E. McKenney" , David Woodhouse , Anna Schumaker X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org It is easy to make a mistake when one implements sleeping between kthread iterations. We will want to do it a more uniform way. For this we will want to set some flags in struct kthread_iterant from the current task (kthread). This patch adds the basic infrastructure to make it possible. Signed-off-by: Petr Mladek --- kernel/kthread.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/kthread.c b/kernel/kthread.c index e34f67cb8ecf..41fb6a43a1f1 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -44,6 +44,7 @@ struct kthread { void *data; struct completion parked; struct completion exited; + struct kthread_iterant *kti; }; enum KTHREAD_BITS { @@ -69,6 +70,11 @@ static struct kthread *to_live_kthread(struct task_struct *k) return NULL; } +static struct kthread_iterant *to_kthread_iterant(struct task_struct *k) +{ + return __to_kthread(k->vfork_done)->kti; +} + /** * kthread_stop_current - make the current kthread to terminate a safe way * @@ -199,6 +205,7 @@ static int kthread(void *_create) self.data = data; init_completion(&self.exited); init_completion(&self.parked); + self.kti = NULL; current->vfork_done = &self.exited; /* If user was SIGKILLed, I release the structure. */ @@ -421,9 +428,12 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data), */ static int kthread_iterant_fn(void *kti_ptr) { + struct kthread *kt = to_kthread(current); struct kthread_iterant *kti = kti_ptr; void *data = kti->data; + kt->kti = kti; + set_freezable(); if (kti->init)