Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4936693imm; Tue, 26 Jun 2018 03:12:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIAGTmP8mL866kglTYCSxvNxDa56LhMdNQYokbL5YyQmNzmn9sUynqkItld2Zxas3rAkO8x X-Received: by 2002:a17:902:9a01:: with SMTP id v1-v6mr992467plp.20.1530007958217; Tue, 26 Jun 2018 03:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530007958; cv=none; d=google.com; s=arc-20160816; b=pBrDCBxjRrm7fZ20yAHyifa4hmuBFcQy9gw6zBIM9B/yY6Fe10mMxsKg5AyTLx5UHK ezLCZ5XrX24/Ev/cJTedejPh/7n//xrc1JtjmltIaxDMviuWx8lJ9DgEW3HuC7MN+ZcY hfwSZAFV3W/xwUV4EXLGbjJ4PQQrezNtU1XKWr9IrwC1a6n80FaT8sjGZun9Wx0bTf0Z xe7g7gCHtejRUAOdHKvkNGRDpsfpEI/O8fjFtbIdVIxIqaYULFUBmWScdgsJX8W7qltm ag91asZ4VMv6/Cyl3HBzD2KcSZVvygOQ0U/f6me4ikrrbCgfyH12d+9qkzNkDUdi7GoR awWA== 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=9uBAwt5ccH1b2VM5tLOVDm7/pd6zQQ7fljz8UI9gqEM=; b=hMAyxm+9AbU9CayXSVzoZRIfwLS8S1RzXKChXfIKtG2vPfh3of+hzi3+gg333DFUN+ yD4FImkwxoiAX2j29TnVZJ/jY2AmWu4U7arnomlhN6m3SlRjY92pU5PPnqwDcQYXHf30 /H3TV1lXTdAVGemI/LK/DojOAgOiSmNkfqyz8EHrwVqyD/4mKJeiaH5VCkSZEPM4qOyU jqZkkhiwJzFV5iRJ0lbiWzfAs3xVP1yt6OMn8EXVplDZM2695I+KA8lC+bR3IPYrl+mS OeJCwljsO4KZ7QqfPjtcAVkbg0Lh2q9zrerei0iq1hpvlUJt4u869uq6t2i/rgtWAGYk zPrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pZEBtGdE; 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 194-v6si1171834pgf.651.2018.06.26.03.12.23; Tue, 26 Jun 2018 03:12: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=pass header.i=@amarulasolutions.com header.s=google header.b=pZEBtGdE; 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 S934283AbeFZKLd (ORCPT + 99 others); Tue, 26 Jun 2018 06:11:33 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:50419 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932629AbeFZKLc (ORCPT ); Tue, 26 Jun 2018 06:11:32 -0400 Received: by mail-wm0-f51.google.com with SMTP id e16-v6so1215618wmd.0 for ; Tue, 26 Jun 2018 03:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9uBAwt5ccH1b2VM5tLOVDm7/pd6zQQ7fljz8UI9gqEM=; b=pZEBtGdEuu/cCRxG4gQkQyLBELLSHygN+m3TAY0vV4Yveh+2KhHo7qVrFG4NcsUOTD PZ50NQUpToh4T03vlB4Xe+EPcZtGi6newCZWS37E5wI907XZOivYFlcfVaIWuuJ+Tyyd VDOEl0QzEaLD96MaNK6NlmkfiJrl0Axot3FrM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=9uBAwt5ccH1b2VM5tLOVDm7/pd6zQQ7fljz8UI9gqEM=; b=m+BXZe/PZeBubW6V0yWHcxRSWKO7FiW8lMHAD5nfmzi+e0g2vKwi1vRttJxUjZ+n2O HpvdwPQuadWC/WdXIUsg45hINgXu3XaB3WVV5xZfe82CDFG4smNtcvmzxTR+3102jrHx r/mn/R9geuHOF7De5vTsI6MRaXkFwr1plGBvZQFoNqhottuEBzOSXsZ+XJTaAIoFByXB F9IPOnkkvLDWNIJs65h9vojJTmM9rdSa5XgjFHQPP8VElrv7kDa/Mt53x660arhoDj03 ZRup4N2g7NypyExnq2DWdMa6BmlcDZCOsKpGyZjgIpXj42E50rCP8NC1lZJS5dbIaTC4 c7dg== X-Gm-Message-State: APt69E0z5TM612NyNCfQi1r3TtYkq4DKX0PQy8KTeFya4Qoo8TSkuKrL pgV+7s1ymxGh9RCeuEnRH1bFfw== X-Received: by 2002:a1c:f106:: with SMTP id p6-v6mr1075882wmh.68.1530007890973; Tue, 26 Jun 2018 03:11:30 -0700 (PDT) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id a12-v6sm1159680wrs.26.2018.06.26.03.11.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 03:11:30 -0700 (PDT) Date: Tue, 26 Jun 2018 12:11:28 +0200 From: Andrea Parri To: Alan Stern Cc: linux-kernel@vger.kernel.org, linux-doc@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 Message-ID: <20180626101127.GB8295@andrea> References: <1529918258-7295-1-git-send-email-andrea.parri@amarulasolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > -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.) Mmh, the fact is that that "before the task state is accessed" does want to include the LOAD from ->state to check for the task state (recall the pattern in [1])...; how about if I expand "in part." to "in particular"? > > > > > - 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. Sure, will fix in v2. Thanks, Andrea > > Alan >