Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp12711imm; Mon, 4 Jun 2018 12:07:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKMEOi+8GtmuT0lIuvEnMXi4RIO2aasnntHquXpvYlydqWVlYXfeR0eQZxq5bHfmrkb3tPw X-Received: by 2002:a17:902:8348:: with SMTP id z8-v6mr6559210pln.239.1528139230519; Mon, 04 Jun 2018 12:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528139230; cv=none; d=google.com; s=arc-20160816; b=Poajvm5Is5HNHBTInc6DmB9R/HS2aEn9Ft1IThMwHc+kjeKCs3dQgpyqkOO6uYuLLk QM6Oh/l3PiPwfs0Kc5fhEgmmyWO/bLiOTjctFS3TZulLr9lK8ZT0eEwXQHohprglq035 JcEaHVECay9vjZIgJDHsdZl9Th8AhlG936pyLR9h1mqUsZD4+qR3GIGSYkiUxn/T/x6Z UFaQrjGZ4wgzplakltthwimHc7+vEXVsd3wVe1nGEdBMMzo659foU2ikij6dBEYulPco I7i8k4FF6oPzz/dAQDNYwp6l1Q0EbpoehQZAXVK9LpnaoXStrF6m7YhQip4xnaVLFJk3 zdew== 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:arc-authentication-results; bh=fFUxFWML+oDeh5dkhDQG5C6k999mqhXhgun8QUaWMYM=; b=YuVVAnhjiFO0ZtnEdaYg1H4oc61asezREU6/sxLBBR2BkCxMdU0esndXBfB60XuceG INB4XyTo87hlc//GT3Nq6yqfj3RXv6fMEBShXRjXorehTFFWpLxOJMOVqDSYr+7cA3ln 8wf5JCSyHjy/A41YuXDPfGyT7p5aXdcuizHZV0fl7TW+QyxamFxDYgTYnZTiHnENCYeY r74HwvTyVbLdDtKKen/zaVrsdMIyI9qZM0m1NutjoxLzHQU4OT28Z1RIE7qDJlHBhZYE nBeSyvxpgGENMdISpl1qnU2pGjFfAc6TFyOSEJv74RimpYyMWLf+cXzFiZnEWS10LK6e EpJw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10-v6si10485870pgu.626.2018.06.04.12.06.50; Mon, 04 Jun 2018 12:07:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751423AbeFDTGH (ORCPT + 99 others); Mon, 4 Jun 2018 15:06:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38664 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbeFDTGD (ORCPT ); Mon, 4 Jun 2018 15:06:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 209B1C036D; Mon, 4 Jun 2018 19:06:02 +0000 (UTC) Received: from treble (ovpn-122-112.rdu2.redhat.com [10.10.122.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0BBA600C0; Mon, 4 Jun 2018 19:05:59 +0000 (UTC) Date: Mon, 4 Jun 2018 14:05:52 -0500 From: Josh Poimboeuf To: Nadav Amit Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Alok Kataria , Christopher Li , Greg Kroah-Hartman , "H. Peter Anvin" , Ingo Molnar , Jan Beulich , Juergen Gross , Kate Stewart , Kees Cook , linux-sparse@vger.kernel.org, Peter Zijlstra , Philippe Ombredanne , Thomas Gleixner , virtualization@lists.linux-foundation.org, Linus Torvalds Subject: Re: [PATCH v2 0/9] x86: macrofying inline asm for better compilation Message-ID: <20180604190552.hm5e6zcabeyxt26u@treble> References: <20180604112131.59100-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180604112131.59100-1-namit@vmware.com> User-Agent: NeoMutt/20180323 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 04 Jun 2018 19:06:02 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 04, 2018 at 04:21:22AM -0700, Nadav Amit wrote: > This patch-set deals with an interesting yet stupid problem: kernel code > that does not get inlined despite its simplicity. There are several > causes for this behavior: "cold" attribute on __init, different function > optimization levels; conditional constant computations based on > __builtin_constant_p(); and finally large inline assembly blocks. > > This patch-set deals with the inline assembly problem. I separated these > patches from the others (that were sent in the RFC) for easier > inclusion. I also separated the removal of unnecessary new-lines which > would be sent separately. > > The problem with inline assembly is that inline assembly is often used > by the kernel for things that are other than code - for example, > assembly directives and data. GCC however is oblivious to the content of > the blocks and assumes their cost in space and time is proportional to > the number of the perceived assembly "instruction", according to the > number of newlines and semicolons. Alternatives, paravirt and other > mechanisms are affected, causing code not to be inlined, and degrading > compilation quality in general. > > The solution that this patch-set carries for this problem is to create > an assembly macro, and then call it from the inline assembly block. As > a result, the compiler sees a single "instruction" and assigns the more > appropriate cost to the code. > > To avoid uglification of the code, as many noted, the macros are first > precompiled into an assembly file, which is later assembled together > with the the C files. This also enables to avoid duplicate > implementation that was set before for the asm and C code. This can be > seen in the exception table changes. > > Overall this patch-set slightly increases the kernel size (my build was > done using my Ubuntu 18.04 config + localyesconfig for the record): > > text data bss dec hex filename > 18140829 10224724 2957312 31322865 1ddf2f1 ./vmlinux before > 18163608 10227348 2957312 31348268 1de562c ./vmlinux after (+0.1%) > > The number of static functions in the image is reduced by 379, but > actually inlining is even better, which does not always shows in these > numbers: a function may be inlined causing the calling function not to > be inlined. > > The Makefile stuff may not be too clean. Ideas for improvements are > welcome. > > v1->v2: * Compiling the macros into a separate .s file, improving > readability (Linus) > * Improving assembly formatting, applying most of the comments > according to my judgment (Jan) > * Adding exception-table, cpufeature and jump-labels > * Removing new-line cleanup; to be submitted separately How did you find these issues? Is there some way to find them automatically in the future? Perhaps with a GCC plugin? -- Josh