Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp532985ybi; Wed, 19 Jun 2019 03:47:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgE4AWvGP+exPifeHF6KoPbpFArnRUTvvwm4T6NyEZbkDgVjTbDX5DzLa+B2Rx4MIKVCu5 X-Received: by 2002:a62:2f04:: with SMTP id v4mr9109118pfv.14.1560941254042; Wed, 19 Jun 2019 03:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560941254; cv=none; d=google.com; s=arc-20160816; b=PddOQHjexIdO1aQwFaCzWV844yXzY5y5n2Oq+V63RPJo8pcY9i9ynxgSQDDoFlpR1y p3uN+1qrcup3BethRF/uKAF8sAzFbYa9y+g4SMElRwFvDBtyUeGYCuFn8U+uUpwoVfyC jumwnFmlXtSWhzVoCzLY07HP1kA9A6sB908vkdApwZcP7e+61gHiToq1quExSAGfOU0E CV6NCgL6Vp0mR3XXGfz1TEXGT9PQg8zbD90UCOsvDoXkW6I8jDk5YiwMDfo6NFqkhcUf sWIFptdrdcSfrnchHEb4S4hISM2WcaIkuOgks2PlGHzvJNRuJd+K1736LuH+LTKCCJ1z HBEw== 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; bh=U9nR8Wh0CdKiidPiISewnmk1WY9H1q+Ys3Mc5yu0EUw=; b=qQFF5qcMUzD8xIAKBIj/Uj7dHMwb/AN2TuESID0lhFqUcd3W88dJSA83GoQd1sSQKH Yu1/set13Q2/Z1pe7sat/LPAbXrpu0e6PAsyJ/EPn90v4H1GE8ia8q6xgkadjXzwhS+k lMA+Kizuh8ctexbmjEf0Z/BY4zJfte2FdMog3PxxagXw1W6gJQvy207IFhO5XxkyHajB SX7FmgSKH8/pqDikRUXIQmqlajQrKHw3pIuNQDJjgCYl0o+uQ4AwRHYHnCbpxpSOUbpB p8ggtlc5Pst0c4sm5BC3DYDinoB/s8PRX4ScZaD96y+aqK+1jlT/vMunt1FG+ZZ9gJyK mBDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oumpXBB4; 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 s21si10427754pfe.204.2019.06.19.03.47.18; Wed, 19 Jun 2019 03:47:34 -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=oumpXBB4; 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 S1731600AbfFSKrE (ORCPT + 99 others); Wed, 19 Jun 2019 06:47:04 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39829 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbfFSKrD (ORCPT ); Wed, 19 Jun 2019 06:47:03 -0400 Received: by mail-wr1-f68.google.com with SMTP id x4so2830333wrt.6 for ; Wed, 19 Jun 2019 03:47:02 -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=U9nR8Wh0CdKiidPiISewnmk1WY9H1q+Ys3Mc5yu0EUw=; b=oumpXBB462l2V+pxeBncy7QQoSPv9B0YeUJD4VIVz63VkWy296qqwaw4aTS5xDQ32s dBiK7Ky1y2Rf6Z1xEyrSqd7+u7uIQ0/7mz8B+yIyWOoN5gV1G054c+vUeiXD6YtJRlHL dSpmGTUHF/cR9QgFCmZi0OJBa2OiQOVHf/Tjg= 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=U9nR8Wh0CdKiidPiISewnmk1WY9H1q+Ys3Mc5yu0EUw=; b=F/65hdbv7S12u2HSkIJwd7W7K9ZNoIZHtx0jpQ5OkwKEqdnmUvgU91gv1eaaexIDbj oIduz9Tw1Li3jjKncm3Wu1GrAHCRK5ZrKI1VVP4PPnMteySa6WMnPu6blhun+qNamEo6 7On9rNt1dgbOcrpsgVr/QOHJf8Z55Sf/XFouhtSpFcie5BeGXKWtc9Cz2xPOSGhaLdas K2to6PtlVbRfW8zh7gsKt8uTZ0KUeaTSSJbNl76NYpW8TS/ukV3qvNkvmF9ci/gkQNHk rCfcfAtLIwdHOSBXBsStPZGjzv3+/L8O4fWK0G9JH2hYv0cQV4pUUDT+ZqeAnZi/vvaA vi7g== X-Gm-Message-State: APjAAAUTHDlbURrlGV+HwCz9M/zsH1mIvo/mXh3rU3JGJYkNf11yIVeE 1fjn/wf+yHFKXro6GGVj56knxQ== X-Received: by 2002:a5d:4ecc:: with SMTP id s12mr35697997wrv.157.1560941221782; Wed, 19 Jun 2019 03:47:01 -0700 (PDT) Received: from andrea (86.100.broadband17.iol.cz. [109.80.100.86]) by smtp.gmail.com with ESMTPSA id r131sm1275691wmf.4.2019.06.19.03.47.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jun 2019 03:47:01 -0700 (PDT) Date: Wed, 19 Jun 2019 12:46:55 +0200 From: Andrea Parri To: John Ogness Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , Sergey Senozhatsky Subject: Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation Message-ID: <20190619104655.GA6668@andrea> References: <20190607162349.18199-1-john.ogness@linutronix.de> <20190607162349.18199-2-john.ogness@linutronix.de> <20190618112237.GP3436@hirez.programming.kicks-ass.net> <87a7eebk71.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a7eebk71.fsf@linutronix.de> 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 > I would appreciate it if you could point out a source file that > documents its memory barriers the way you would like to see these memory > barriers documented. IMO, you could find some inspiration by looking at the memory barriers comments from: kernel/sched/core.c:try_to_wake_up() include/linux/wait.h:waitqueue_active() kernel/futex.c [header _and inline annotations] I'll detail a single example here, and then conclude with some general guidelines: --- [from kernel/sched/rt.c] static inline void rt_set_overload(struct rq *rq) { if (!rq->online) return; cpumask_set_cpu(rq->cpu, rq->rd->rto_mask); /* * Make sure the mask is visible before we set * the overload count. That is checked to determine * if we should look at the mask. It would be a shame * if we looked at the mask, but the mask was not * updated yet. * * Matched by the barrier in pull_rt_task(). */ smp_wmb(); atomic_inc(&rq->rd->rto_count); } static void pull_rt_task(struct rq *this_rq) { int this_cpu = this_rq->cpu, cpu; bool resched = false; struct task_struct *p; struct rq *src_rq; int rt_overload_count = rt_overloaded(this_rq); if (likely(!rt_overload_count)) return; /* * Match the barrier from rt_set_overloaded; this guarantees that if we * see overloaded we must also see the rto_mask bit. */ smp_rmb(); /* If we are the only overloaded CPU do nothing */ if (rt_overload_count == 1 && cpumask_test_cpu(this_rq->cpu, this_rq->rd->rto_mask)) return; [...] } --- Notice that the comments provide the following information: for _each_ memory barrier primitive, 1) the _memory accesses_ being ordered the store to ->rto_mask and the store to ->rto_count for the smp_wmb() the load from ->rto_count and the from ->rto_mask for the smp_rmb() 2) the _matching barrier_ (and its location) 3) an informal description of the _underlying guarantee(s)_ (c.f., "if we see overloaded we must also see the rto_mask bit"). One can provide this information by embedding some snippet/pseudo-code in its comments as illustrated in the examples pointed out above. I'd suggest to _not be stingy with memory barriers explanations: this eases/makes it possible the review itself as well as future changes or fixes to the implementation. FWIW (and as anticipated time ago in a private email), when I see code like this I tend to look elsewhere... ;-/ Thanks, Andrea