Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4114531imm; Mon, 25 Jun 2018 09:58:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLYf8gfB2WppQ/6xFwdHqOEftfp3RFy9g/A0xsQYPBXXnMozUVZ+xsJeA9KrziMTGLZ1zBz X-Received: by 2002:a63:6807:: with SMTP id d7-v6mr11080361pgc.7.1529945918886; Mon, 25 Jun 2018 09:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529945918; cv=none; d=google.com; s=arc-20160816; b=mgJX3I8xffVHfOGhZpHSx/oWntezedgUhfLIfGOqvF5doQSWYeSs8Ym9BWSFUg//j4 wZIF4SzSYHVyQ7CDgLOdnCMOTGdoXjqkdo3czgceClfWImNjCel/mrAXl7eL4wWb3nXY isw7OXfUQwX0FmCEJwgX4FXkYvFG4PYp9ksoJaLKnmg0oOMWDJrXj3XyZ6ZF7nGWuuAc EwxHOkJewQ227Ozqv9ou5AhjZUGZNwCstk9HjIPrjWNlEbOnVaPg4i9wm456VbTd2JXm 6VIwhUBpXeYW+0U9i0rgwrboUwy4UaVHNvFjq7xBGXAuv+9sNrNda4DaA0XmbS/MbWNW pzFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=Tkshs9qfMUxiGK5oY6SQp/7HqiwA/ZBX38Dppfe6ckA=; b=NhHvrJxqqLPo+STcUtUC5LL+5HAGqRRlFgOW7McU08qT/fkCX+iulweNGBb0w3Aa1Q 35WUAjLOBXjKI9xlhM2MUwpATY0xAtOscPK0sw+A6Mzw6r6rnqlk0E+kxTMkGMY86vF1 ShifdhF8xVDxKpX/AuJu1IPxScK4zaNqebmkcIBwh9W2x6l6QIbFmXPAWsMu2GzzvsjX MktI2Wq5pFodBN6g4wEcmoiOM14+oKrZgIvJhm4bcHHKahtKwFaXa2ZBr0vwC+x3oj3G +1qC3PNH007cy1WMto6d8LFua8Kz5STObO9c0t8FLuvExdbudHmC39k/ewu5GudF6dm/ Pz9g== ARC-Authentication-Results: i=1; mx.google.com; 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 g66-v6si8609289pgc.350.2018.06.25.09.58.24; Mon, 25 Jun 2018 09:58: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; 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 S933933AbeFYQ4R (ORCPT + 99 others); Mon, 25 Jun 2018 12:56:17 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:37336 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S933157AbeFYQ4P (ORCPT ); Mon, 25 Jun 2018 12:56:15 -0400 Received: (qmail 5020 invoked by uid 2102); 25 Jun 2018 12:56:14 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 25 Jun 2018 12:56:14 -0400 Date: Mon, 25 Jun 2018 12:56:14 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Andrea Parri cc: linux-kernel@vger.kernel.org, , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Jonathan Corbet , Ingo Molnar , Randy Dunlap Subject: Re: [PATCH] doc: Update wake_up() & co. memory-barrier guarantees In-Reply-To: <1529918258-7295-1-git-send-email-andrea.parri@amarulasolutions.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Jun 2018, Andrea Parri wrote: > Both the implementation and the users' expectation [1] for the various > wakeup primitives have evolved over time, but the documentation has not > kept up with these changes: brings it into 2018. > > [1] http://lkml.kernel.org/r/20180424091510.GB4064@hirez.programming.kicks-ass.net > > Suggested-by: Peter Zijlstra > Signed-off-by: Andrea Parri > [ aparri: Apply feedback from Alan Stern. ] > Cc: Alan Stern > Cc: Will Deacon > Cc: Peter Zijlstra > Cc: Boqun Feng > Cc: Nicholas Piggin > Cc: David Howells > Cc: Jade Alglave > Cc: Luc Maranget > Cc: "Paul E. McKenney" > Cc: Akira Yokosawa > Cc: Daniel Lustig > Cc: Jonathan Corbet > Cc: Ingo Molnar > Cc: Randy Dunlap > --- > Documentation/memory-barriers.txt | 43 ++++++++++++++++++++++++--------------- > kernel/sched/completion.c | 8 ++++---- > kernel/sched/core.c | 11 +++++----- > kernel/sched/wait.c | 24 ++++++++++------------ > 4 files changed, 47 insertions(+), 39 deletions(-) > > diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt > index a02d6bbfc9d0a..bf58fa1671b62 100644 > --- a/Documentation/memory-barriers.txt > +++ b/Documentation/memory-barriers.txt > @@ -2179,32 +2179,41 @@ or: > event_indicated = 1; > wake_up_process(event_daemon); > > -A write memory barrier is implied by wake_up() and co. if and only if they > -wake something up. The barrier occurs before the task state is cleared, and so > -sits between the STORE to indicate the event and the STORE to set TASK_RUNNING: > +A general memory barrier is executed by wake_up() if it wakes something up. > +If it doesn't wake anything up then a memory barrier may or may not be > +executed; you must not rely on it. The barrier occurs before the task state > +is accessed, in part., it sits between the STORE to indicate the event and > +the STORE to set TASK_RUNNING: Minor suggestion: Instead of "in part.", how about "that is"? (I generally find "in part." to be at least a little confusing, probably because "part" is itself a word and "in part" is a reasonably common phrase in English.) > > - CPU 1 CPU 2 > + CPU 1 (Sleeper) CPU 2 (Waker) > =============================== =============================== > set_current_state(); STORE event_indicated > smp_store_mb(); wake_up(); > - STORE current->state > - STORE current->state > - LOAD event_indicated > + STORE current->state ... > + > + LOAD event_indicated if ((LOAD task->state) & TASK_NORMAL) > + STORE task->state > > -To repeat, this write memory barrier is present if and only if something > -is actually awakened. To see this, consider the following sequence of > -events, where X and Y are both initially zero: > +where "task" is the thread being woken up and it equals CPU 1's current. Since "task" is in quotation marks, "current" should also be in quotation marks. Alan