Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3861853imm; Thu, 17 May 2018 16:33:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoKzxgGkuI4YLbszm6dFsr9Ubnvd8u5C+i4RRbC+OgO3zvHPPK+s9fkM2XQQYSD17tvGsAk X-Received: by 2002:a17:902:8303:: with SMTP id bd3-v6mr6996032plb.290.1526600008114; Thu, 17 May 2018 16:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526600008; cv=none; d=google.com; s=arc-20160816; b=ix7FHTSog2qhrzDxNA6vGHqiC67q04MtmxCSUrGGiZF9EgijGZR+v3KpChkAWLSom0 FDAYj6N1hrj8pX01WWBIOYYKFaG9eKg/l6d5CvvBdIR/jR/oBHZ/5OrX4WJA4/vGWe6j ooP4SQ9rq+lVldDAI36AKw0jlJUcb+OdASmQHeQ8GpDR0UHrQw2DJVmwEjgEj11gKhjT vAdu9mqJgLQAIN8+5jQ9qp0MYvxELndlnreaNC/VZRZnPJhyOYgCBuGPzjioai9Sp3mL StM/uKF6EZF5XhboA6Pswke1KEAKDL94Q46l6OF6knWnvUKP/MVGf+bskUZQLu1D5593 bJIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=lLdP3JgpcPXStnPsvkc5oGvWuhS0l+JqaxgsNGoHhgw=; b=DEOLUSN58jyAU1Ifalx35XQeS9FI9C7wKmcdYWr/s6bDPnCbsUb3wSd5RtJJNvA042 0Qf6H5jxQfaNthq7X84rQoHjOpmR02Mahu9XY5uH/hfAKY4bJ8jySzQE/p5Sl4cO8a9C Jh2Xaj8CDOs7JJODh2fw+gmPMHHN3i31Gi+dj5wqAp7vcp1PY/UlLoBRAEq93zRP6AC5 JV9LI+MKmpD6MCNK5hYN0ZqcvnmCIzfvlWW3aHN1GXQhqAyZGOruXCdufI72Vly/P9lH ITOwJrtPIdS+GTZ7oVXGKTUclKDvMR67JP4NLE07GL4SDdpUbUUPtPwOJg6ZBKyLBYnK AgEQ== 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 r26-v6si302152pgn.373.2018.05.17.16.32.41; Thu, 17 May 2018 16:33:28 -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 S1752188AbeEQX2o (ORCPT + 99 others); Thu, 17 May 2018 19:28:44 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:57881 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750924AbeEQX2k (ORCPT ); Thu, 17 May 2018 19:28:40 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 17 May 2018 16:28:39 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 336934010A; Thu, 17 May 2018 16:28:40 -0700 (PDT) From: Nadav Amit To: , CC: , Nadav Amit , Alok Kataria , Christopher Li , "H. Peter Anvin" , Ingo Molnar , Jan Beulich , Jonathan Corbet , Josh Poimboeuf , Juergen Gross , Kees Cook , , Peter Zijlstra , Randy Dunlap , Thomas Gleixner , Subject: [PATCH 0/6] Macrofying inline assembly for better compilation Date: Thu, 17 May 2018 09:13:56 -0700 Message-ID: <20180517161402.78089-1-namit@vmware.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. In addition, this patch-set removes unneeded new-lines from common x86 inline asm's, which "confuse" GCC heuristics. Overall this patch-set slightly increases the kernel size (my build was done using my localmodconfig + localyesconfig for the record): text data bss dec hex filename 18126699 10066728 2936832 31130259 1db0293 ./vmlinux before 18148888 10064016 2936832 31149736 1db4ea8 ./vmlinux after (+0.06%) The patch-set eliminates many of the static text symbols: Before: 40033 After: 39650 (-1%) A microbenchmark with a loop of page-fault and MADV_DONTNEED show 2% performance improvement with this patch-set (when PTI is off). Changes from RFC: - Better formatting [Jan] - i386 build problems [0-day] - Inline comments - Separating __builtin_constant_p() into a different future patch-set Cc: Alok Kataria Cc: Christopher Li Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jan Beulich Cc: Jonathan Corbet Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Kees Cook Cc: linux-sparse@vger.kernel.org Cc: Peter Zijlstra Cc: Randy Dunlap Cc: Thomas Gleixner Cc: virtualization@lists.linux-foundation.org Cc: x86@kernel.org Nadav Amit (6): x86: objtool: use asm macro for better compiler decisions x86: bug: prevent gcc distortions x86: alternative: macrofy locks for better inlining x86: prevent inline distortion by paravirt ops x86: refcount: prevent gcc distortions x86: removing unneeded new-lines arch/x86/include/asm/alternative.h | 34 +++++++++++---- arch/x86/include/asm/asm.h | 4 +- arch/x86/include/asm/bug.h | 56 ++++++++++++++++-------- arch/x86/include/asm/cmpxchg.h | 10 ++--- arch/x86/include/asm/paravirt_types.h | 63 +++++++++++++++++---------- arch/x86/include/asm/refcount.h | 62 ++++++++++++++++---------- arch/x86/include/asm/special_insns.h | 12 ++--- include/linux/compiler.h | 37 ++++++++++++---- 8 files changed, 183 insertions(+), 95 deletions(-) -- 2.17.0