From patchwork Tue Aug 23 18:47:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 9296199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 446B7607F0 for ; Tue, 23 Aug 2016 18:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 371FA28C80 for ; Tue, 23 Aug 2016 18:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BB6D28CCE; Tue, 23 Aug 2016 18:59:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD34E28C80 for ; Tue, 23 Aug 2016 18:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754455AbcHWS7Y (ORCPT ); Tue, 23 Aug 2016 14:59:24 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:35608 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbcHWS7W (ORCPT ); Tue, 23 Aug 2016 14:59:22 -0400 Received: by mail-lf0-f67.google.com with SMTP id l89so8208278lfi.2 for ; Tue, 23 Aug 2016 11:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=NtP8QTztxyp6R4CUmBTQ5dAO0wGeut2y5vmrOjJoxLk=; b=tG4rlhIg/Oik6fJ4LdYixWbnqwEkNEb9XmJS1TXhdxcaaThpTl96QAQW+3MyJQ7pRb T/TSoZA5RbDgDtzHSAS2bO1uDjeiA4K1mdZakTGIxmJ0JXkDm1/bAg64w1WR1uIKKITL JawHV0D3Q65dGQkhMXsIC2pLaEt3KMCijYI5UxA2UATEB9+weUZz5QNY+mvq3myeMbxO o+98kTusOx9lmERHnSZHm/cR6xCYqH2rgAM22aLSFD+derp0KKDKZlQ/+eANLLYoxp7h OOEVpqx3IpRnOnL4xpbF70L6Z166Bq4t27DJBIOpn37mNynSuBmpCPtRg8zuUc197/ye q+aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=NtP8QTztxyp6R4CUmBTQ5dAO0wGeut2y5vmrOjJoxLk=; b=lb9L80AyKs/5ONsv3gW2p5enSifvwctDCPftk9EVHK1mo2pT28ujkesElvX409UxCD Ye4q3QzOPbL7vw2s5GtaagvkVijaZehWGC1Ty8JrGYN4cGvTvaYvlV1eHqbflhgOrmMN smlRCQC2eP907QygzL4MzaHNQEk/Zx+woEITkHB3WoNDH/oBwvol2izQBJikiKLq2plU kC9eSD+fHgGP22vNlOKIrGRo171OVJK2FB/XNEcWonUtWVFS/DL4EWCOJ7V6XfZEuPJE vC0oXBYsj4BqcoGzMrS5vRE2E/Xf18b7Kt6A9FSAVHxb3LNDNSzM96YUFkW6NOkicl9r 9uRA== X-Gm-Message-State: AEkoouubUPE10V46o4mn5CMbsOh0J9cx0ynXU1Gt7Elp+Hg8CZkwDT0lA/2/KptARU8VUQ== X-Received: by 10.25.228.203 with SMTP id x72mr6223649lfi.137.1471978037055; Tue, 23 Aug 2016 11:47:17 -0700 (PDT) Received: from p183.telecom.by (nat5-minsk-pool-46-53-217-92.telecom.by. [46.53.217.92]) by smtp.gmail.com with ESMTPSA id g11sm1104290lji.25.2016.08.23.11.47.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Aug 2016 11:47:16 -0700 (PDT) Date: Tue, 23 Aug 2016 21:47:24 +0300 From: Alexey Dobriyan To: mmarek@suse.com Cc: akpm@linux-foundation.org, linux-kbuild@vger.kernel.org Subject: [PATCH] fixdep: faster CONFIG_ search Message-ID: <20160823184724.GA11707@p183.telecom.by> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do you think kernel build is 100% dominated by gcc? You are wrong! One small utility called "fixdep" consistently manages to sneak into profile's first page (unless you have small monitor of course). The choke point is this clever code: for (; m < end; m++) { if (*m == INT_CONF) { p = (char *) m ; goto conf; } if (*m == INT_ONFI) { p = (char *) m-1; goto conf; } if (*m == INT_NFIG) { p = (char *) m-2; goto conf; } if (*m == INT_FIG_) { p = (char *) m-3; goto conf; } 4 branches per 4 characters is not fast. Use strstr(3), so that SSE2 etc can be used. With this patch, fixdep is so deep at the bottom, it is hard to find it. Signed-off-by: Alexey Dobriyan --- scripts/basic/fixdep.c | 67 ++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 39 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -82,8 +82,7 @@ * to date before even starting the recursive build, so it's too late * at this point anyway. * - * The algorithm to grep for "CONFIG_..." is bit unusual, but should - * be fast ;-) We don't even try to really parse the header files, but + * We don't even try to really parse the header files, but * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will * be picked up as well. It's not a problem with respect to * correctness, since that can only give too many dependencies, thus @@ -241,37 +240,22 @@ static void use_config(const char *m, int slen) print_config(m, slen); } -static void parse_config_file(const char *map, size_t len) +static void parse_config_file(const char *p) { - const int *end = (const int *) (map + len); - /* start at +1, so that p can never be < map */ - const int *m = (const int *) map + 1; - const char *p, *q; - - for (; m < end; m++) { - if (*m == INT_CONF) { p = (char *) m ; goto conf; } - if (*m == INT_ONFI) { p = (char *) m-1; goto conf; } - if (*m == INT_NFIG) { p = (char *) m-2; goto conf; } - if (*m == INT_FIG_) { p = (char *) m-3; goto conf; } - continue; - conf: - if (p > map + len - 7) - continue; - if (memcmp(p, "CONFIG_", 7)) - continue; + const char *q, *r; + + while ((p = strstr(p, "CONFIG_"))) { p += 7; - for (q = p; q < map + len; q++) { - if (!(isalnum(*q) || *q == '_')) - goto found; - } - continue; - - found: - if (!memcmp(q - 7, "_MODULE", 7)) - q -= 7; - if (q - p < 0) - continue; - use_config(p, q - p); + q = p; + while (*q && (isalnum(*q) || *q == '_')) + q++; + if (memcmp(q - 7, "_MODULE", 7) == 0) + r = q - 7; + else + r = q; + if (r > p) + use_config(p, r - p); + p = q; } } @@ -291,7 +275,7 @@ static void do_config_file(const char *filename) { struct stat st; int fd; - void *map; + char *map; fd = open(filename, O_RDONLY); if (fd < 0) { @@ -308,18 +292,23 @@ static void do_config_file(const char *filename) close(fd); return; } - map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if ((long) map == -1) { - perror("fixdep: mmap"); + map = malloc(st.st_size + 1); + if (!map) { + perror("fixdep: malloc"); close(fd); return; } + if (read(fd, map, st.st_size) != st.st_size) { + perror("fixdep: read"); + close(fd); + return; + } + map[st.st_size] = '\0'; + close(fd); - parse_config_file(map, st.st_size); - - munmap(map, st.st_size); + parse_config_file(map); - close(fd); + free(map); } /*