From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757406AbbIURtO (ORCPT ); Mon, 21 Sep 2015 13:49:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39299 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753836AbbIURtL (ORCPT ); Mon, 21 Sep 2015 13:49:11 -0400 Date: Mon, 21 Sep 2015 19:46:11 +0200 From: Oleg Nesterov To: Peter Zijlstra Cc: Boqun Feng , "Paul E. McKenney" , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jonathan Corbet , Michal Hocko , David Howells , Linus Torvalds , Will Deacon Subject: Re: [PATCH] Documentation: Remove misleading examples of the barriers in wake_*() Message-ID: <20150921174611.GA28059@redhat.com> References: <1441674841-11498-1-git-send-email-boqun.feng@gmail.com> <20150909192822.GM4029@linux.vnet.ibm.com> <20150910021612.GC18494@fixme-laptop.cn.ibm.com> <20150910175557.GA20640@redhat.com> <20150917130125.GL3816@twins.programming.kicks-ass.net> <20150917170111.GA29215@redhat.com> <20150918064956.GQ3816@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150918064956.GQ3816@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/18, Peter Zijlstra wrote: > > the text is correct, right? Yes, it looks good to me and helpful. But damn. I forgot why exactly try_to_wake_up() needs rmb() after ->on_cpu check... It looks reasonable in any case, but I do not see any strong reason immediately. Say, p->sched_contributes_to_load = !!task_contributes_to_load(p); p->state = TASK_WAKING; we can actually do this before "while (p->on_cpu)", afaics. However we must not do this before the previous p->on_rq check. So perhaps this rmb() helps to ensure task_contributes_to_load() can't happen before p->on_rq check... As for "p->state = TASK_WAKING" we have the control dependency in both cases. But the modern fashion suggests to use _CTRL(). Although cpu_relax() should imply barrier(), but afaik this is not documented. In short, I got lost ;) Now I don't even understand why we do not need another rmb() between p->on_rq and p->on_cpu. Suppose a thread T does set_current_state(...); schedule(); it can be preempted in between, after that we have "on_rq && !on_cpu". Then it gets CPU again and calls schedule() which clears on_rq. What guarantees that if ttwu() sees on_rq == 0 cleared by schedule() then it can _not_ still see the old value of on_cpu == 0? Oleg.