Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2667856imm; Sun, 7 Oct 2018 09:06:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV61rHmtbFxYMsJnzS3ydb6rgnrk1w8CO2rmuBuKQwH5FjXkbLma6DVj6pN82yu+hNyEmzZxg X-Received: by 2002:a65:5188:: with SMTP id h8-v6mr17896486pgq.288.1538928386729; Sun, 07 Oct 2018 09:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538928386; cv=none; d=google.com; s=arc-20160816; b=wd0lzqA/PdqzS7QKVX1MeJUEHZU3Al3APa4Nr7hi27ahDHB8Yjy6Jk0yZ2d7heCF/g UVk6dE53JJfPXYla4h0ZKjHJ8Ri0HybZK27aPzXX7xOOKq5swD1maW+6fkxQKDV0biAI qCbQj+Ewb/S2ZWjpO8hyaaPmSsYgZ/BosbSAUB6qbJOtHnPxv+mlfMK3Ws9ylRxGCTx6 rlRjb3fZ9XQwkthuwaO7mKQ5oWDMeYNQbTNZToGxXW9MjnYjiUjFiBG3D75haL8RWuuW wbAlBPEwzTCsEOExdXO5AgZoiWMjv5ybeilMwb8hJhYIrMokAigc5oD+k7LVt9l9qkhj impA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=AG47P6kNTEcO1KjM4GZKqNQKaNQFh+3qzI4fJ5nID80=; b=EEmWMxG0Wh42cvTm19SEKncIBOL4zex6eCvBdNt6gA65pXDm8n8Zwzq2SeFwQuMe/S 8/dSoiPh9Kwx9ix7AlocTcJQx/rcY9EyU4yih5MR4qeNFlP98rDzE742lTiOjy7fZmL1 pjHFpe1GkMkCMCth/ROKUlMwWVsTCghBsDmbf+5NsQGPN1fpLma2H3dZOPue/EoVz82h IuJ4yVuXlbUrfEZRKX1zbSKoDkoEjV/Y/UimlzbSc2SHFb8jyKK6dgUwIEybUy85iLmm qexOs50kVQUjTpUxaXJydqyKk9BKyJ8/hG0Hek2x5omCK7o53xSAO3UQrFG7gtoTIvMr Txew== 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 k26-v6si15062568pfe.36.2018.10.07.09.05.55; Sun, 07 Oct 2018 09:06:26 -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 S1728139AbeJGXBN (ORCPT + 99 others); Sun, 7 Oct 2018 19:01:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:42554 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726448AbeJGXBN (ORCPT ); Sun, 7 Oct 2018 19:01:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 150A8AF87; Sun, 7 Oct 2018 15:53:28 +0000 (UTC) Date: Sun, 7 Oct 2018 15:53:26 +0000 (UTC) From: Michael Matz To: Segher Boessenkool cc: Borislav Petkov , gcc@gcc.gnu.org, Richard Biener , Nadav Amit , Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, Masahiro Yamada , Sam Ravnborg , Alok Kataria , Christopher Li , Greg Kroah-Hartman , "H. Peter Anvin" , Jan Beulich , Josh Poimboeuf , Juergen Gross , Kate Stewart , Kees Cook , linux-sparse@vger.kernel.org, Peter Zijlstra , Philippe Ombredanne , Thomas Gleixner , virtualization@lists.linux-foundation.org, Linus Torvalds , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org Subject: Re: PROPOSAL: Extend inline asm syntax with size spec In-Reply-To: <20181007132228.GJ29268@gate.crashing.org> Message-ID: References: <20181003213100.189959-1-namit@vmware.com> <20181007091805.GA30687@zn.tnic> <20181007132228.GJ29268@gate.crashing.org> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) 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 Hi Segher, On Sun, 7 Oct 2018, Segher Boessenkool wrote: > On Sun, Oct 07, 2018 at 11:18:06AM +0200, Borislav Petkov wrote: > > this is an attempt to see whether gcc's inline asm heuristic when > > estimating inline asm statements' cost for better inlining can be > > improved. > > GCC already estimates the *size* of inline asm, and this is required > *for correctness*. So any workaround that works against this will only > end in tears. You're right and wrong. GCC can't even estimate the size of mildly complicated inline asms right now, so your claim of it being necessary for correctness can't be true in this absolute form. I know what you try to say, but still, consider inline asms like this: insn1 .section bla insn2 .previous or invoke_asm_macro foo,bar in both cases GCCs size estimate will be wrong however you want to count it. This is actually the motivating example for the kernel guys, the games they play within their inline asms make the estimates be wildly wrong to a point it interacts with the inliner. > So I guess the real issue is that the inline asm size estimate for x86 > isn't very good (since it has to be pessimistic, and x86 insns can be > huge)? No, see above, even if we were to improve the size estimates (e.g. based on some average instruction size) the kernel examples would still be off because they switch sections back and forth, use asm macros and computed .fill directives and maybe further stuff. GCC will never be able to accurately calculate these sizes (without an built-in assembler which hopefully noone proposes). So, there is a case for extending the inline-asm facility to say "size is complicated here, assume this for inline decisions". > > Now, Richard suggested doing something like: > > > > 1) inline asm ("...") > > What would the semantics of this be? The size of the inline asm wouldn't be counted towards the inliner size limits (or be counted as "1"). > I don't like 2) either. But 1) looks interesting, depends what its > semantics would be? "Don't count this insn's size for inlining decisions", > maybe? TBH, I like the inline asm (...) suggestion most currently, but what if we want to add more attributes to asms? We could add further special keywords to the clobber list: asm ("...." : : : "cc,memory,inline"); sure, it might seem strange to "clobber" inline, but if we reinterpret the clobber list as arbitrary set of attributes for this asm, it'd be fine. > Another option is to just force inlining for those few functions where > GCC currently makes an inlining decision you don't like. Or are there > more than a few? I think the examples I saw from Boris were all indirect inlines: static inline void foo() { asm("large-looking-but-small-asm"); } static void bar1() { ... foo() ... } static void bar2() { ... foo() ... } void goo (void) { bar1(); } // bar1 should have been inlined So, while the immediate asm user was marked as always inline that in turn caused users of it to become non-inlined. I'm assuming the kernel guys did proper measurements that they _really_ get some non-trivial speed benefit by inlining bar1/bar2, but for some reasons (I didn't inquire) didn't want to mark them all as inline as well. Ciao, Michael.