Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp908270imm; Wed, 6 Jun 2018 07:42:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKvmJqcDmQthwpoXCeMZONMi7UZbUprOzcxFRo7Wkyg2YH2LPpp7mL12YsjPlBv7zNWmrrR X-Received: by 2002:a17:902:a416:: with SMTP id p22-v6mr3477093plq.228.1528296145948; Wed, 06 Jun 2018 07:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528296145; cv=none; d=google.com; s=arc-20160816; b=QSSdcGimpd7Ovqh1MRNRzsV5SncO7h4D3tPqbCPUtracy07CkIfe+DBuMVbMFkQLRN saG0fRvWhcjfYKEn7ZJXQ2GiZgckIdGSlOiiM8WBJ7r8V/54dVP6qQ0ex2F9Xsl63aXB nuOpaj8d+XDuQNH+melBcj7MRsiMs7YCGd99DGIwAeF6f529if/SWok0hVQP9eOmt5iy Eof40cn445xY0oe4vRBMnovsYWJPWL4HaPb9UwYKTvTxek5/kRKIS4D2JA7s51/06C0C ZD2Menoe9k/6m1eqi4Ws601cftdmwtPOY17Q8FrDOxTG7lOZs+PquIy0xGzXxQWMTjLw 6zag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Kg6J+eAfMSJ+icWE3YayqwlzQINso5rNiWmfktW6fHE=; b=TNmB0euWyxIGgV1lNRwz+a+CK79843bKgvkSU/V9lNSBrHwqBU36HVVgz06tOxSTvl /UNdIxU8zZc2TdFHpXzfvMQZ1g/u5C/LgEaZDC7l9rHR0x7zojCrHzIiJNlTJQI0Pgod 6kbMk0ZYQnQULt30sz4rjEdotl1RWjCbQBVhWVEC8n44nrhQjKUNelojgNy2liAv6uVX oU3nrNRnLOFZrmFV+bhIhAe5IzV91ktqPLJCqHtsDHobIBMMnD5HOoQdjv2iNlPAHgjJ KlYt7wJYdgVO644arjQslnVGRZVhIAfdARFagNQr7Gdy+QREes+q/b/LC077csG0V737 aY/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@profitbricks-com.20150623.gappssmtp.com header.s=20150623 header.b=zHj/8C0s; 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 c10-v6si22558175pll.275.2018.06.06.07.42.11; Wed, 06 Jun 2018 07:42:25 -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=@profitbricks-com.20150623.gappssmtp.com header.s=20150623 header.b=zHj/8C0s; 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 S1752149AbeFFOln (ORCPT + 99 others); Wed, 6 Jun 2018 10:41:43 -0400 Received: from mail-io0-f181.google.com ([209.85.223.181]:35415 "EHLO mail-io0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751994AbeFFOll (ORCPT ); Wed, 6 Jun 2018 10:41:41 -0400 Received: by mail-io0-f181.google.com with SMTP id u4-v6so7901498iof.2 for ; Wed, 06 Jun 2018 07:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Kg6J+eAfMSJ+icWE3YayqwlzQINso5rNiWmfktW6fHE=; b=zHj/8C0seokbi3iiO5e62RzAtyVYKU0GsyM5LTyO1pKIozJb0XMB5o4MpNdjN4OPsD zWbq5JEWAqGpW7DBBv0sp1/FjVa/sf1cBuKCg+zdWcaSxLelV3gfXMXJqEkCpoFrDhFi CDJ4CYLp+Lx23qdqaO31Rfq3Hx5/ly9cWmenBUhOnZzGe4Gc+5PZMsPnWqbzkCpJ/EkH A2qDGKl/mQxzmID6gZTObMEX4bx+4hhnsP6SMtfIjEioXblT1XtCzaEFRDARN4wM4N/M CQk4TMv8C+BreZZPgkXef+/NGbF3VElqr0eunn3bimeVX6ldzpUy3duGKGNj95isp+3F vYdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Kg6J+eAfMSJ+icWE3YayqwlzQINso5rNiWmfktW6fHE=; b=I39y5f7AgSqphwCrseGDUB6HDC+hpjvqSO0Ds2PvKNAgeZlRL64ORLYO1gqK/JkW5V zErBvvTrWmz+PNnVwfy67p8W+dEv5QfA+gpZQbE9rp5b5wS30E8TceeD/cCj4wfQr+uy pFDzynyUU+f4/aL3liZkayJGut3Ysg+7X7Am85GANsn1Kv76EsHFoXVYHMzMysDtA6/Q LZz3smZQAXd7m4hh0yo13pBHu49qdmqsNcfjqXLVyZuj054lQGeXVfqAwZbTDjAzZDQL 2e1TxtUr62QBcPiIEUdkzwqMRxfe2Yuj0fDUeQ5iL9HPXhJr+4ndIjU1glLt9J2Nk0+p XQKQ== X-Gm-Message-State: APt69E3uu1Nxg6MB9i+Mu+w6KtrOhR5jGjIyh0sojb2oOgJcscGJxBED TlUgL4lld2/ZLmCPiHnnxehQ8U5ryimWl+lsza+Kgg== X-Received: by 2002:a6b:1fc2:: with SMTP id f185-v6mr3383039iof.74.1528296100790; Wed, 06 Jun 2018 07:41:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:e719:0:0:0:0:0 with HTTP; Wed, 6 Jun 2018 07:41:20 -0700 (PDT) In-Reply-To: References: From: Roman Penyaev Date: Wed, 6 Jun 2018 16:41:20 +0200 Message-ID: Subject: Re: LKMM litmus test for Roman Penyaev's rcu-rr To: Alan Stern Cc: "Paul E. McKenney" , Linus Torvalds , Linux Kernel Mailing List , linux-arch , andrea.parri@amarulasolutions.com, Will Deacon , Peter Zijlstra , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 6, 2018 at 3:54 PM, Alan Stern wrote: > On Wed, 6 Jun 2018, Roman Penyaev wrote: > >> > Preserving the order of volatile accesses isn't sufficient. The >> > compiler is still allowed to translate >> > >> > r1 = READ_ONCE(x); >> > if (r1) { >> > ... >> > } >> > WRITE_ONCE(y, r2); >> > >> > into something resembling >> > >> > r1 = READ_ONCE(x); >> > WRITE_ONCE(y, r2); >> > if (r1) { >> > ... >> > } >> >> Hi Alan, >> >> According to the standard C99 Annex C "the controlling expression of >> a selection statement (if or switch)" are the sequence points, just >> like a volatile access (READ_ONCE or WRITE_ONCE). >> >> "5.1.2.3 Program execution" states: >> "At certain specified points in the execution sequence called sequence >> points, all side effects of previous evaluations shall be complete >> and no side effects of subsequent evaluations shall have taken place." >> >> So in the example we have 3 sequence points: "READ_ONCE", "if" and >> "WRITE_ONCE", which it seems can't be reordered. Am I mistaken >> interpreting standard? Could you please clarify. > > Well, for one thing, we're talking about C11, not C99. C11 is a n1570, ISO/IEC 9899:2011 ? (according to wiki). Found pdf on the web contains similar lines, so should not be any differences for that particular case. > For another, as far as I understand it, the standard means the program > should behave _as if_ the side effects are completed in the order > stated. It doesn't mean that the generated code has to behave that way > literally. Then I do not understand what are the differences between "side effects are completed" and "code generated". Abstract machine state should provide some guarantees between sequence points, e.g.: foo(); /* function call */ ------------| *a = 1; | *b = 12; | Compiler in his right to reorder. *c = 123; | ------------| boo(); /* function call */ compiler in his right to reorder memory accesses between foo() and boo() calls (foo and boo are sequence points, but memory accesses are not), but: foo(); /* function call */ *(volatile int *)a = 1; *(volatile int *)b = 12; *(volatile int *)c = 123; boo(); /* function call */ are all sequence points, so compiler can't reorder them. Where am I mistaken? > And in particular, the standard is referring to the > behavior of a single thread, not the interaction between multiple > concurrent threads. Yes, that is clear: we are talking about code reordering in one particular function in a single threaded environment. -- Roman