Received: by 10.192.165.148 with SMTP id m20csp3662307imm; Mon, 30 Apr 2018 04:21:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZokQwk1EpP5HSz4tzW7gIH6InoJoichULg4lKImBxEp4sC2wmkYnu5chn+8IoN/kKPQCG9Q X-Received: by 2002:a63:ba05:: with SMTP id k5-v6mr9735315pgf.39.1525087273544; Mon, 30 Apr 2018 04:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525087273; cv=none; d=google.com; s=arc-20160816; b=U5q97thKDvMBP8g0BAB7LB02jKE1fxjAWDB5OIBmm9c9YayXtb8UeaC6nP+4GptM6c snL0tr+T10EqYW3ncGaWtLh3MCkGfdxzs+c571FYGfmyQOnVxBRh0MZNtGCqmumtvqcw CLUp7eEEQOs9TVcDWxsM5PxUwODDWVu7T3dGLzL6OUxFqtvIhGHLz6uTaLZ+ze14Y2wK 7me3pz/uuUVD+pJme4tfYJgGZupCJYXJl9NM+39U8PDHMLdxj+Fwoksebysiqgs0s0GA Y8NkFx+pX+m9XViqTtqIJdCeZ0yOEbKOxbUw+oxKrp86konpa6h98uSrv/NCrFaPdaiw S78A== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=S0Fic7+tzbZPtwt7x23oEFpUoqb1SUA6LJ+b/VAxqMc=; b=i+mO2vaCsKqgu2IcOhBwVOZTm73dq3yVO3auS/7ksXrdkuQ46LK9vQY8SNQH4J0jak uvJHex66DOwR77YwlokrKEy+adWtwedECAnmKRQvzupdqyCWxLtyVoBUfiZ0NOTIWYgn iSeE9OkAzj4L4UXAHkrYjRpMmXQsokSgr0ZNqxdgz5GqgnzwRCgvwiJwrHaRt9fdwTXf rh/2ruoBGwEmswvCj3Dxz6WpT6HXYqjQ/QOSJoquAcuVVSL6K6w2yWtWgLx0dOAZLmyG 1v6FqDTq5nS3/VaN0hrDQexJ5K0bVaArLPwtgHgPY7lYIGUXCsXOu0catqAIMMWNPALx QfRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=DxafMxpe; 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 i27si7418301pfa.219.2018.04.30.04.20.59; Mon, 30 Apr 2018 04:21:13 -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=bombadil.20170209 header.b=DxafMxpe; 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 S1752994AbeD3LUh (ORCPT + 99 others); Mon, 30 Apr 2018 07:20:37 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:33334 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751064AbeD3LUg (ORCPT ); Mon, 30 Apr 2018 07:20:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=S0Fic7+tzbZPtwt7x23oEFpUoqb1SUA6LJ+b/VAxqMc=; b=DxafMxpemmwvU0DZbPxzuU2Jr /8se8JS3KiYF++zSiy2xqxFZqrWZw7i4zKzhDoIgfrCQSR+1LMgKSRiwrhJNHA4bMab7EOG+l1Msv Gpg+JXQ+Ep3UAxhyOvELpDMs2VnwyrbeWqAgJAAK3B+3AENo5CQUEByFHQXK/XDjTfif2R6tSrBg/ qdG1vJEc7G/rEVlvnXFlAMCPAoqDF512627Vd6X9JrfuHFw4Ge0Ab+L1Qun1M03M4ImzucQCoDNnx wffHCNzdeezeemO2TH1twmwnfDRyVMI2LQRHyPpBAvrbkKMvuOxMNZnmqsViR92qexH/ATYQEru3t bsaMR/d+w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fD6r9-0006QJ-35; Mon, 30 Apr 2018 11:20:31 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8E59B2029FD46; Mon, 30 Apr 2018 13:20:29 +0200 (CEST) Date: Mon, 30 Apr 2018 13:20:29 +0200 From: Peter Zijlstra To: Oleg Nesterov Cc: Gaurav Kohli , tglx@linutronix.de, mpe@ellerman.id.au, mingo@kernel.org, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neeraj Upadhyay , Will Deacon Subject: Re: [PATCH v1] kthread/smpboot: Serialize kthread parking against wakeup Message-ID: <20180430112029.GF4082@hirez.programming.kicks-ass.net> References: <1524645199-5596-1-git-send-email-gkohli@codeaurora.org> <20180425200917.GZ4082@hirez.programming.kicks-ass.net> <20180426084131.GV4129@hirez.programming.kicks-ass.net> <20180426161820.GA15391@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180426161820.GA15391@redhat.com> 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 Thu, Apr 26, 2018 at 06:18:20PM +0200, Oleg Nesterov wrote: > On 04/26, Peter Zijlstra wrote: > > > > For the others, I think we want to do something like the below. I still > > need to look at TASK_TRACED, which I suspect is also special, > > Yes, and TASK_STOPPED. I already did that one, right ;-) > > ptrace_freeze_traced() and ptrace_unfreeze_traced() should be fine, but > ptrace_stop() wants set_special_state() too, I think. Thanks for going through that, I'll update the patch. > > +/* > > + * set_special_state() should be used for those states when the blocking task > > + * can not use the regular condition based wait-loop. In that case we must > > + * serialize against wakeups such that any possible in-flight TASK_RUNNING stores > > + * will not collide with out state change. > > + */ > > +#define set_special_state(state_value) \ > > + do { \ > > + unsigned long flags; /* may shadow */ \ > > + raw_spin_lock_irqsave(¤t->pi_lock, flags); \ > > + current->state = (state_value); \ > > + raw_spin_unlock_irqrestore(¤t->pi_lock, flags); \ > > + } while (0) > > + > > Agreed. > > I thought that perhaps we can change ttwu_do_wakeup() cmpxchg() instead of > plain p->state = TASK_RUNNING, but this helper looks much more clear and simple. Aside from cmpxchg() slowing down the common fast path, that also would not work on architectures where cmpxchg() is not in fact atomic vs regular stores (and yes, sadly we still have those, PARISC and SPARC32 come to mind).