From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleg Nesterov Subject: Re: [PATCH v1] kthread/smpboot: Serialize kthread parking against wakeup Date: Thu, 26 Apr 2018 18:18:20 +0200 Message-ID: <20180426161820.GA15391@redhat.com> References: <1524645199-5596-1-git-send-email-gkohli@codeaurora.org> <20180425200917.GZ4082@hirez.programming.kicks-ass.net> <20180426084131.GV4129@hirez.programming.kicks-ass.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20180426084131.GV4129@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org To: Peter Zijlstra 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 List-Id: linux-arm-msm@vger.kernel.org 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. ptrace_freeze_traced() and ptrace_unfreeze_traced() should be fine, but ptrace_stop() wants set_special_state() too, I think. > but ptrace always hurts my brain. mine too ;) > +/* > + * 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. Oleg.