Received: by 10.192.165.148 with SMTP id m20csp4954130imm; Tue, 24 Apr 2018 11:06:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrZP3gy6LNysmOVzBjW74VtM4XZkgLpdtsnEMRd4qdBV+RT9XVhJB42CP9PuKgVCcPEghi3 X-Received: by 2002:a17:902:d913:: with SMTP id c19-v6mr1976064plz.229.1524593199080; Tue, 24 Apr 2018 11:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524593198; cv=none; d=google.com; s=arc-20160816; b=M0mKF4xiQaDvnEgIH2+2imO1QOdpbW0rTrWfzTOSnSla/WeZNbb9YGpELru4v5OHOw HQV3YVWF9nf8SSCri1P1Tlcq7RS1G4D8nn5p0uN89YA+f25ivLthptYRiLvzbnEXhCzg FrG/7NVo7fo3CiJb5L0iMxOBdj29+FdDIb8oyG37RHa1j15y8ihMUtJB4xOpCgT4cVn5 hdz/q6/2FeN9yYWnzUjJRQN9OGsUKLsF53G8oIYqLoFcNXjcVljjgCvkdtKcooffC74l G9axuk03cOtayB53atsCZl1343ji93qIBR32SCA6+C7QPN3s+neLAkyBSkwJ3ianEVVy IZ8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=AbY4e6qXzZtDENxT2CYr+kivT/RTpNjcFKstLVsD3+Y=; b=v3zAnwl7DSDPPenr2XuS5RClmnSZUyNbImQgXmJM6J9EL1FHkHt4gSxIM2XtivoAOJ h3NHdcI3FMV1rjQhkcIbPqd6LGTf2WmHSuMzF2JVuw7tYWe4DJ0SU3HNDtve4K5oZ96O 3rR0MFmNWzGG7AVMnTFr+lGD2bes0duKemgzPrbvJG/XZGgLsbqpmJaakWdJjolEj6ZJ DJunIddH81xFRsT+l3WTZvLswIsST62ZGtB+mKpsA+a8JnfGFRBVepXar2h8GIQ9aNj4 ejKCBwRLWykswj7IlBw5OISA9GPqmmAQE+sxa9iJqjgorBRQcBFBiuM+0Ni6Fcw5bVgl mALQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=X4XfFEC0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si13683543pfc.186.2018.04.24.11.06.24; Tue, 24 Apr 2018 11:06:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=X4XfFEC0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751518AbeDXSFU (ORCPT + 99 others); Tue, 24 Apr 2018 14:05:20 -0400 Received: from merlin.infradead.org ([205.233.59.134]:46520 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095AbeDXSFS (ORCPT ); Tue, 24 Apr 2018 14:05:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=AbY4e6qXzZtDENxT2CYr+kivT/RTpNjcFKstLVsD3+Y=; b=X4XfFEC0HyiylyKAx11oMsNgem oDjFzXNlzRXGxnMFVCvYxUhPu1HaOX/1ba437r89cbtc7ZytbUgCkZhNZRNh1ymmDpFoEAcY929jJ lcbN3oCm2HfIoZna2ikAda1WCAAs0rG7QFLuOVgBRIrO/mhqaxGgTipRu38uBJvKCHbqSr4r8acj1 tH7GPxHGvaMpkKSqijwnwf34sFJpGucQnwU1+1ymP/jQtZJ7lmVn37HnXLGTrKEqlcKPrd4bd4CCa ybQPAj81PJTMW6JtAXfM94sEcJLX44xWpx4uqray4xJT8Pfir2Q59UtngCmzOSlgeXmzKzWh5vzJ3 ZZORLLOw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fB2JO-0006oF-MM; Tue, 24 Apr 2018 18:05:06 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F19CA203BF989; Tue, 24 Apr 2018 20:05:04 +0200 (CEST) Date: Tue, 24 Apr 2018 20:05:04 +0200 From: Peter Zijlstra To: "Kohli, Gaurav" Cc: tglx@linutronix.de, mpe@ellerman.id.au, dzickus@redhat.com, mingo@kernel.org, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neeraj Upadhyay Subject: Re: [PATCH] kthread/smpboot: Serialize kthread parking against wakeup Message-ID: <20180424180504.GV4043@hirez.programming.kicks-ass.net> References: <1524562105-31026-1-git-send-email-gkohli@codeaurora.org> <3e823654-9701-9b01-43fc-1a29feb7a298@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3e823654-9701-9b01-43fc-1a29feb7a298@codeaurora.org> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 24, 2018 at 08:12:49PM +0530, Kohli, Gaurav wrote: > @@ -157,6 +156,7 @@ static int smpboot_thread_fn(void *data) > > ??????????????? if (!ht->thread_should_run(td->cpu)) { > > ??????????????????????? preempt_enable_no_resched(); > > +?????????????????????? set_current_state(TASK_INTERRUPTIBLE); > > ??????????????????????? schedule(); > > ??????????????? } else { > > ??????????????????????? __set_current_state(TASK_RUNNING); > > Please suggest if this approach is better. Bah, my brain isn't working... see below for the 'correct' version of your second patch. But this violates the normal pattern; see the comment near set_current_state(). That pattern ensures the thread either sees the wakeup condition or the actual wakeup. I'm thinking that with this patch there is a scenario where we'll miss both the kthread_should_park() and the actual wakeup and end up not doing anything. I do the like the end result, but I suspect it's buggy. --- kernel/smpboot.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kernel/smpboot.c b/kernel/smpboot.c index 5043e7433f4b..5bdf57f2ce68 100644 --- a/kernel/smpboot.c +++ b/kernel/smpboot.c @@ -109,10 +109,8 @@ static int smpboot_thread_fn(void *data) struct smp_hotplug_thread *ht = td->ht; while (1) { - set_current_state(TASK_INTERRUPTIBLE); preempt_disable(); if (kthread_should_stop()) { - __set_current_state(TASK_RUNNING); preempt_enable(); /* cleanup must mirror setup */ if (ht->cleanup && td->status != HP_THREAD_NONE) @@ -122,7 +120,6 @@ static int smpboot_thread_fn(void *data) } if (kthread_should_park()) { - __set_current_state(TASK_RUNNING); preempt_enable(); if (ht->park && td->status == HP_THREAD_ACTIVE) { BUG_ON(td->cpu != smp_processor_id()); @@ -139,7 +136,6 @@ static int smpboot_thread_fn(void *data) /* Check for state change setup */ switch (td->status) { case HP_THREAD_NONE: - __set_current_state(TASK_RUNNING); preempt_enable(); if (ht->setup) ht->setup(td->cpu); @@ -147,7 +143,6 @@ static int smpboot_thread_fn(void *data) continue; case HP_THREAD_PARKED: - __set_current_state(TASK_RUNNING); preempt_enable(); if (ht->unpark) ht->unpark(td->cpu); @@ -156,10 +151,10 @@ static int smpboot_thread_fn(void *data) } if (!ht->thread_should_run(td->cpu)) { + set_current_state(TASK_IDLE); preempt_enable_no_resched(); schedule(); } else { - __set_current_state(TASK_RUNNING); preempt_enable(); ht->thread_fn(td->cpu); }