Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp602493ybm; Wed, 27 May 2020 03:31:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRDK/mTZNt4vVR3iFt8M0fxQsC4V+f8I29X+MFA0Et4cFbceJKwx5TfxX/D6KZJi+4294K X-Received: by 2002:a17:906:944e:: with SMTP id z14mr5197228ejx.86.1590575500400; Wed, 27 May 2020 03:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590575500; cv=none; d=google.com; s=arc-20160816; b=WQj4sv3C1+h65Ux4LKvYkB4Ck0TesJSuDBy2VDiowrkjU9kWqGfEa2bxQlNho73sYa b5JiUxH2NOQO+RDbS0rcEsDVzoIQp5cKDoTg9TaXPthAbKL+e4nPP0KTfqrE75T5c7Oa 1GxRbMmpbovdt8uGDO0XyDj6LzHLv/tPO+4GalEL1vme/OByD+PbC/QrwmrNfpNll9fJ l1SAQPlDt9MToSpbZYJmJ+A4mFAbrgzOgIY6fLoQ7OcS+K83VTdLQwVaCDyxj76DSt9I l/+ncmf8FBeJN/MRmrIYeIsat3EeNNLDbWda2a7k/kIh3ZHzquhFYAl1m7TDMk8CMeam 8zRg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=zbcumbiOybyvrNPq+S8EAFFWXxgWspgqCp4xRwbHRuI=; b=SzjotmJ3NeMVnI0s0ubjfypDZ29X13HM9dSXmROpB6h44q0kLwW4NgyQo3q07DNQ0t hM3a2ulPSNN7JUJn7FqwBM+DPXV3q6sJbYrW7SfrebKygKvCYTghBtl2wsnzPaGy6/4G j/SUb6Waest5GpiWU534CBJxyZo0zh7rYRQcS6YIuCOpFA38JElUudgfLE4y8XKHBstM XMGq53mmh1sKLqeKD4eqCqAO+YynLxmSe5Eg9cn7TdgW9eO9Jt59Occ1JJVvu6cBuntP aubJpgwF1ZDLVfAkOqjPn02EzcuyTBkX3vAeGWg2BmO+v8au8ifimZ15rrO2fdc+hU5m 6LAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Bea7jtiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h3si1728265ejp.112.2020.05.27.03.31.17; Wed, 27 May 2020 03:31:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Bea7jtiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387647AbgE0HoW (ORCPT + 99 others); Wed, 27 May 2020 03:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387505AbgE0HoW (ORCPT ); Wed, 27 May 2020 03:44:22 -0400 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222C6C061A0F for ; Wed, 27 May 2020 00:44:22 -0700 (PDT) Received: by mail-ot1-x342.google.com with SMTP id b18so18514627oti.1 for ; Wed, 27 May 2020 00:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zbcumbiOybyvrNPq+S8EAFFWXxgWspgqCp4xRwbHRuI=; b=Bea7jtiqrCIc0QUDHNMwR2/RmhcvDSbjKzogX9URL8jhuKlzI1tMUuDG4lu1nwXb9U OBiy3Z8laAuU6iAzRHvTeAg8Qjj+V3GmrSyMCnW3huFjdKOVuQrHeBBOpCynX7XI2HFt F6glhFUfgn82+sxtWgiKD8V4N25tskGzEMWsK6V7+GoiLCh6NP/gS2T5rMrrchyG1AXB wHZTSxk4YieAizKmF+tWvWm3z5uYX7UYwt/cauqCI9j1JATKMHwuM6Un8Xsh8N5M3Tr9 BjMxiOEo6JJ7snQK3FtICT63NbA0Qlm4wddox+tShoGqA786uW1HE1Tf9klGWKQRhhjv tVvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zbcumbiOybyvrNPq+S8EAFFWXxgWspgqCp4xRwbHRuI=; b=lq3am0oamjvLiL5/rBjqwKvOLYy+pEJtYD+42Ops139wzDt+m05rKTumMEglJzya8E gy3mxAlEviOjtBA/cm5TtIuRQHBD46JHHena6Z5TMftqchCSA0RyzKRuwqbpF2VnIkRU KVd620M26fCOVkEYFXxL54p+pw5YiEeMgZ7XTD1M/jvji31tvCLrT0sTf0EcPrQiC6xW UmYyQq1aGxZUAUzDcEkUTsvD7M4LBTvfY1ifMuyH69o4PCwlrEX+S8v0POrd8G3z4/dR 6FXoXVsi5KhWPpx6EI8ghBis//fjSTyg21B6afu2S5H2WXRDGBTAxP9nJIb51WHiBUwf y8vA== X-Gm-Message-State: AOAM531pkGEAy10vFqJ55wOUE8wUrLxPnXr+a1lDeKOnFt7yKbbWpeZD HehiyN9tlw4KoQ1evOCzCQkne1uBGw+kIbH38gA5JHe0+VI= X-Received: by 2002:a9d:27a3:: with SMTP id c32mr3972097otb.233.1590565461246; Wed, 27 May 2020 00:44:21 -0700 (PDT) MIME-Version: 1.0 References: <20200521142047.169334-1-elver@google.com> <20200521142047.169334-10-elver@google.com> <20200526120245.GB27166@willie-the-truck> <20200526173312.GA30240@google.com> <20200527072248.GA9887@willie-the-truck> In-Reply-To: <20200527072248.GA9887@willie-the-truck> From: Marco Elver Date: Wed, 27 May 2020 09:44:09 +0200 Message-ID: Subject: Re: [PATCH -tip v3 09/11] data_race: Avoid nested statement expression To: Will Deacon Cc: Arnd Bergmann , Nick Desaulniers , "Paul E. McKenney" , Dmitry Vyukov , Alexander Potapenko , Andrey Konovalov , kasan-dev , LKML , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , clang-built-linux , Borislav Petkov 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, 27 May 2020 at 09:22, Will Deacon wrote: > > On Wed, May 27, 2020 at 01:10:00AM +0200, Arnd Bergmann wrote: > > On Tue, May 26, 2020 at 9:00 PM Arnd Bergmann wrote: > > > > > > On Tue, May 26, 2020 at 7:33 PM 'Marco Elver' via Clang Built Linux > > > wrote: > > > > On Tue, 26 May 2020, Marco Elver wrote: > > > > > On Tue, 26 May 2020 at 14:19, Arnd Bergmann wrote: > > > > > Note that an 'allyesconfig' selects KASAN and not KCSAN by default. > > > > > But I think that's not relevant, since KCSAN-specific code was removed > > > > > from ONCEs. In general though, it is entirely expected that we have a > > > > > bit longer compile times when we have the instrumentation passes > > > > > enabled. > > > > > > > > > > But as you pointed out, that's irrelevant, and the significant > > > > > overhead is from parsing and pre-processing. FWIW, we can probably > > > > > optimize Clang itself a bit: > > > > > https://github.com/ClangBuiltLinux/linux/issues/1032#issuecomment-633712667 > > > > > > > > Found that optimizing __unqual_scalar_typeof makes a noticeable > > > > difference. We could use C11's _Generic if the compiler supports it (and > > > > all supported versions of Clang certainly do). > > > > > > > > Could you verify if the below patch improves compile-times for you? E.g. > > > > on fs/ocfs2/journal.c I was able to get ~40% compile-time speedup. > > > > > > Yes, that brings both the preprocessed size and the time to preprocess it > > > with clang-11 back to where it is in mainline, and close to the speed with > > > gcc-10 for this particular file. > > > > > > I also cross-checked with gcc-4.9 and gcc-10 and found that they do see > > > the same increase in the preprocessor output, but it makes little difference > > > for preprocessing performance on gcc. > > > > Just for reference, I've tested this against a patch I made that completely > > shortcuts READ_ONCE() on anything but alpha (which needs the > > read_barrier_depends()): > > > > --- a/include/linux/compiler.h > > +++ b/include/linux/compiler.h > > @@ -224,18 +224,21 @@ void ftrace_likely_update(struct > > ftrace_likely_data *f, int val, > > * atomicity or dependency ordering guarantees. Note that this may result > > * in tears! > > */ > > -#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x)) > > +#define __READ_ONCE(x) (*(const volatile typeof(x) *)&(x)) > > > > +#ifdef CONFIG_ALPHA /* smp_read_barrier_depends is a NOP otherwise */ > > #define __READ_ONCE_SCALAR(x) \ > > ({ \ > > __unqual_scalar_typeof(x) __x = __READ_ONCE(x); \ > > smp_read_barrier_depends(); \ > > - (typeof(x))__x; \ > > + __x; \ > > }) > > +#else > > +#define __READ_ONCE_SCALAR(x) __READ_ONCE(x) > > +#endif > > Nice! FWIW, I'm planning to have Alpha override __READ_ONCE_SCALAR() > eventually, so that smp_read_barrier_depends() can disappear forever. I > just bit off more than I can chew for 5.8 :( > > However, '__unqual_scalar_typeof()' is still useful for > load-acquire/store-release on arm64, so we still need a better solution to > the build-time regression imo. I'm not fond of picking random C11 features > to accomplish that, but I also don't have any better ideas... We already use _Static_assert in the kernel, so it's not the first use of a C11 feature. > Is there any mileage in the clever trick from Rasmus? > > https://lore.kernel.org/r/6cbc8ae1-8eb1-a5a0-a584-2081fca1c4aa@rasmusvillemoes.dk Apparently that one only works with GCC 7 or newer, and is only properly defined behaviour since C11. It also relies on multiple _Pragma. I'd probably take the arguably much cleaner _Generic solution over that. ;-) I think given that Peter and Arnd already did some testing, and it works as intended, if you don't mind, I'll send a patch for the _Generic version. At least that'll give us a more optimized __unqual_scalar_typeof(). Any further optimizations to READ_ONCE() like you mentioned then become a little less urgent. Thanks, -- Marco