From patchwork Wed Oct 11 13:54:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 115553 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp653522edb; Wed, 11 Oct 2017 06:55:02 -0700 (PDT) X-Google-Smtp-Source: AOwi7QB7/N/uk242YCxuzleBQt/qSWX5lPY8mDvFBi0ENyix8ZesAqC8JIQG9jjQxdRftDUycgk+ X-Received: by 10.101.69.76 with SMTP id x12mr8029301pgr.284.1507730101784; Wed, 11 Oct 2017 06:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507730101; cv=none; d=google.com; s=arc-20160816; b=fMMlLFxpvZa1VcTCmT9dnPAAn/cdkzzPdExGoDungKz8AFDUuFYPh6W/ZWa/A6Hqrm f8FfnQgzaoRiJxsQEgPO4zJ96hIFW8/eVgdI5dIcHZto0jU7HGNJqp7DmcTxf75IQuiv JP2AaHT2uh8A76XViS0xMS/mreDGjGRFMn3rUlU/OvvS7qCCiKtVougnXoBgQ7kFfAqJ EfWNkh6fQ624uUD2Hhqqxw1/RNexONjO/ndAnuLozj2bwKYGn9t8PDQs1gQhXypNnOnZ PY4obxDqA11fEmWDKRMqewYTX0ihTRHlKa5iCYTpmsjT/qJBjVT2wUVAyXzJybZRNmKF JIDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:message-id:date:subject:to:from:dkim-signature :arc-authentication-results; bh=uItQmLPuelA1kPacAKRXbykef01j/As6CiX1UIDUO+s=; b=a65XFZ+ZAi6l/OTkWOULf/EZ3PakoZ5IfNoe4FbxCzk6m/RAzDRHzoLA+6q4b7GOdK I76t/MDLRzOk1BumVW+86fxUtgiIGr+r9P2ZdYGOcqGD6t77EI8tqEPNwvFnil23BAT3 9a1BT62XABH4+f2dWYcWHNWclWGjucgNiUuXZSjzaFnb/oP8+nbk2P8TaeFAbME6DSGC Cy8ONXS5Qab5pC0RbNODLrwZN4eFEE6zZFY+m2YoVgBjXkaHAhUUUbgJYr+Qc42j7V7e WvXNmjBx9SY/G9E+zKInT5X5j3nWJ7ieXGtENdOA303hbvSfsuADeSj/0YiQ438R8gPf b34Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=dmLf5xf7; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id q17si5988214pgd.312.2017.10.11.06.55.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 06:55:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=dmLf5xf7; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=uItQmLPuelA1kPacAKRXbykef01j/As6CiX1UIDUO+s=; b=dmL f5xf7SwYt+jN46RyG+XLJcjhco5DKDQgM8CS9JIHRD67V1440pdBpP8Sv6bfUApfmRlm2L/l4eKib q05X4pCI8brLE+j9yqkdXu3CPFhkveEJTwFVuFOKa+dj4prqDdJoAzvWdEP5q1Zqbh/OvWN9PmdGh MnPW3SIsK3voowAfsLfiNWtXnxnFCsceDaKrYXVtPlrjJjrwNd3n2/x3GcFwyczSBZwxcIwEPQ5Ox sZ2s0XfmMAIh8zk4h/BI1VsRKk0k6EpHGcxSaoIvv5I2J+TZtEcXUDs73tFwYMBE3K8ZJbiuTMl1m 6b24G3QGJHWYQKTDwff9ioT9buXMtww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2HTK-00005T-Jr; Wed, 11 Oct 2017 13:54:54 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2HTF-0008L3-Lq for linux-mtd@lists.infradead.org; Wed, 11 Oct 2017 13:54:52 +0000 Received: from wuerfel.lan ([95.208.190.237]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MWAdl-1dnDb20fWL-00XN9c; Wed, 11 Oct 2017 15:54:21 +0200 From: Arnd Bergmann To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen Subject: [PATCH] mtd: cfi: convert inline functions to macros Date: Wed, 11 Oct 2017 15:54:10 +0200 Message-Id: <20171011135419.3492681-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:AJ1vGdDg34rD7dfcOCSJWs48QkPfhK3xOSk09N7UaFc3soBavaC F1pzrp8N+Oluocmj7jo4+H818zp7fdrBcyTBrZRCCd8dwCUqvLEnUuFfxDKWaSZRrvJwPUs zr1QWSWVe/8VZXhga2/dL/Q72ttwrvRCooqTcdiHwqo71aK+2Ok7scMQcvsGxIZYXBSg18z CCJ/4xJS5tdb1PuyS84xA== X-UI-Out-Filterresults: notjunk:1; V01:K0:vTvfS+POAA4=:UrrspnB1ZVb4O9ArkThUBZ g3s+XvFlWHwM1Yqi16v+1om2AyL19iXybZwGL66XjOhK9dN0GbDXdK1VW/I3ROUHVXB+8NKRI G1zj2viNLnb+fp1u1vquJfXgeKJeKbc2AQjdWepktWKYmN2ADZvp1YaIl38IC70g5+l4dhEux VRavF8CZKSdgy0WlQiTF+G7BFPCdF5nlAge1L+UNlpECgEyK4WZcgrlO3up8s8Rt/PQo/PiWP mqX3oKALiHVI95kscOyKj9B0NLQJGwy2XezKqJtvstExTZZBDgNdpavy7K+W31lPrMKY4tCiT TTF8MsvqQunMeQAGEjRbKW41aKT7onk4cxMB0yUpebr3cFIoR4r+CBmDXgxQQAcgoQye9rTOI mTdMjVFo7uJbNVk/2xBmN+qTpLSKCAvDPkmbIVYW3z2aRiueRHJIiPTnLQHqefD9gv90u80ID ygCbU5vP4Bhn/7ec35r5yQlyY4ayEtD7YPH/sutRZ4TYSjNXM3QTtElMmxc0Rvn8j0RcIEkaZ R75aWYJLz/FJLOWdCgXZBLVczyn+hOlG/b4rRxibgCLtJVJ1bMKQpppgbAmjaWRtRcjgkCeXE FaKTCxvDwUf85Nf5+GE8x3CzKx3UYa9kDiNpCZuFWMWtA7iQT5w9FIrBP5pfCZ5sHLGTn3o90 5s6+kwmvBDjWw4ZERz9b2UGlLJtJJ34eB4bolZvw+tqQIwuKDE69A9sVGUrb7767VuGan6+Rc uY/NLnNN6RSUx55PTx3ngvZZ2pEwzMFzuACjMA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171011_065450_131255_5EC10D0B X-CRM114-Status: GOOD ( 18.09 ) X-Spam-Score: -4.7 (----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-4.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [217.72.192.73 listed in list.dnswl.org] -2.8 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.72.192.73 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, stable@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org The map_word_() functions, dating back to linux-2.6.8, try to perform bitwise operations on a 'map_word' structure. This may have worked with compilers that were current then (gcc-3.4 or earlier), but end up being rather inefficient on any version I could try now (gcc-4.4 or higher). Specifically we hit a problem analyzed in gcc PR81715 where we fail to reuse the stack space for local variables. This can be seen immediately in the stack consumption for cfi_staa_erase_varsize() and other functions that (with CONFIG_KASAN) can be up to 2200 bytes. Changing the inline functions into macros brings this down to 1280 bytes. Without KASAN, the same problem exists, but the stack consumption is lower to start with, my patch shrinks it from 920 to 496 bytes on with arm-linux-gnueabi-gcc-5.4, and saves around 1KB in .text size for cfi_cmdset_0020.c, as it avoids copying map_word structures for each call to one of these helpers. With the latest gcc-8 snapshot, the problem is fixed in upstream gcc, but nobody uses that yet, so we should still work around it in mainline kernels and probably backport the workaround to stable kernels as well. We had a couple of other functions that suffered from the same gcc bug, and all of those had a simpler workaround involving dummy variables in the inline function. Unfortunately that did not work here, the macro hack was the best I could come up with. It would also be helpful to have someone to a little performance testing on the patch, to see how much it helps in terms of CPU utilitzation. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann --- include/linux/mtd/map.h | 130 +++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 69 deletions(-) -- 2.9.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h index 3aa56e3104bb..b5b43f94f311 100644 --- a/include/linux/mtd/map.h +++ b/include/linux/mtd/map.h @@ -270,75 +270,67 @@ void map_destroy(struct mtd_info *mtd); #define INVALIDATE_CACHED_RANGE(map, from, size) \ do { if (map->inval_cache) map->inval_cache(map, from, size); } while (0) - -static inline int map_word_equal(struct map_info *map, map_word val1, map_word val2) -{ - int i; - - for (i = 0; i < map_words(map); i++) { - if (val1.x[i] != val2.x[i]) - return 0; - } - - return 1; -} - -static inline map_word map_word_and(struct map_info *map, map_word val1, map_word val2) -{ - map_word r; - int i; - - for (i = 0; i < map_words(map); i++) - r.x[i] = val1.x[i] & val2.x[i]; - - return r; -} - -static inline map_word map_word_clr(struct map_info *map, map_word val1, map_word val2) -{ - map_word r; - int i; - - for (i = 0; i < map_words(map); i++) - r.x[i] = val1.x[i] & ~val2.x[i]; - - return r; -} - -static inline map_word map_word_or(struct map_info *map, map_word val1, map_word val2) -{ - map_word r; - int i; - - for (i = 0; i < map_words(map); i++) - r.x[i] = val1.x[i] | val2.x[i]; - - return r; -} - -static inline int map_word_andequal(struct map_info *map, map_word val1, map_word val2, map_word val3) -{ - int i; - - for (i = 0; i < map_words(map); i++) { - if ((val1.x[i] & val2.x[i]) != val3.x[i]) - return 0; - } - - return 1; -} - -static inline int map_word_bitsset(struct map_info *map, map_word val1, map_word val2) -{ - int i; - - for (i = 0; i < map_words(map); i++) { - if (val1.x[i] & val2.x[i]) - return 1; - } - - return 0; -} +#define map_word_equal(map, val1, val2) \ +({ \ + int i, ret = 1; \ + for (i = 0; i < map_words(map); i++) \ + if ((val1).x[i] != (val2).x[i]) { \ + ret = 0; \ + break; \ + } \ + ret; \ +}) + +#define map_word_and(map, val1, val2) \ +({ \ + map_word r; \ + int i; \ + for (i = 0; i < map_words(map); i++) \ + r.x[i] = (val1).x[i] & (val2).x[i]; \ + r; \ +}) + +#define map_word_clr(map, val1, val2) \ +({ \ + map_word r; \ + int i; \ + for (i = 0; i < map_words(map); i++) \ + r.x[i] = (val1).x[i] & ~(val2).x[i]; \ + r; \ +}) + +#define map_word_or(map, val1, val2) \ +({ \ + map_word r; \ + int i; \ + for (i = 0; i < map_words(map); i++) \ + r.x[i] = (val1).x[i] | (val2).x[i]; \ + r; \ +}) + +#define map_word_andequal(map, val1, val2, val3) \ +({ \ + int i, ret = 1; \ + for (i = 0; i < map_words(map); i++) { \ + if (((val1).x[i] & (val2).x[i]) != (val2).x[i]) { \ + ret = 0; \ + break; \ + } \ + } \ + ret; \ +}) + +#define map_word_bitsset(map, val1, val2) \ +({ \ + int i, ret = 0; \ + for (i = 0; i < map_words(map); i++) { \ + if ((val1).x[i] & (val2).x[i]) { \ + ret = 1; \ + break; \ + } \ + } \ + ret; \ +}) static inline map_word map_word_load(struct map_info *map, const void *ptr) {