From patchwork Wed Mar 8 11:52:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 66164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp288481wrd; Wed, 8 Mar 2023 04:02:33 -0800 (PST) X-Google-Smtp-Source: AK7set+ZgRmqAjPDD4yHmemPOawmmvnguClX0UTlUCL269YOibtZ+j1BomAGYMkwOFMH/FV6K4Sc X-Received: by 2002:aa7:d342:0:b0:4ac:746e:2edf with SMTP id m2-20020aa7d342000000b004ac746e2edfmr15766164edr.9.1678276953802; Wed, 08 Mar 2023 04:02:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678276953; cv=none; d=google.com; s=arc-20160816; b=jEkHO+Q9OqGA7h9VxNfl7TPLXhs716AQtS9bYIK5ZKWx7QWFE9vs8jPhMFi+livjuK /mcKrarZGxEqo3POuektAeEt+Z+JHQBbDsTyPXF6/L/fhSjN2viD1WCKJ7v7ZVES7sKo dSgKj57EhoSA0PvbyCbDP/oCdwQ8gcVLNcait5824VK089kZXEeTfwfVqigKCZcR2it8 joE9auu8cf/jmc98OEyK1rHetSP4GenkyX5VS0Rea8GyVj48FAohIj6ezmN1+vxHQDSr oL9zJD5hHLO4gEGLiwK/9uVIVbwI8D536qbrM+QxOcjYMs+TF6cWKTS+AiN4LHJjo8Bp y1cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+A9t/k5/7IJWyVlnWrggh7bs4MxTVXI8dcp/KfXtdgg=; b=FvW3Uvvtez/EHdnnCpqD+PEjV/WSoFEGXgcRUIwD3yU6xI+gQdvOKXvZSsuux5GyTF XuAGcuuqaASom6l9QzOGIMD17ZtTuZhYAF/iGgLwciiT7vLtRAerN2uUlDIY8lUQ09WL z2CpEKFnVDoiyFpMam0MtQ/7mK8hsFzC7dc7hYOTtDI4B9eJJ2JcF//XD8bnN2J9hWbH jdeNBMk4Hz5tvNy36ZA1oJ2rs6+djoCCfR5Rsq6tsv/kHOYzWWQTBgX3jMP8OBqvbXu0 VNIaA+8mjxW7izmjR/jNv5kjVX058JvF2Dsa4e24h1ExoChAK2JEOfc1/93MsU4C9Ene Hn8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DuQdIWp3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a056402054600b004a981a53b39si1351786edx.326.2023.03.08.04.02.09; Wed, 08 Mar 2023 04:02:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DuQdIWp3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230362AbjCHLxj (ORCPT + 99 others); Wed, 8 Mar 2023 06:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230481AbjCHLx1 (ORCPT ); Wed, 8 Mar 2023 06:53:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C23494D280; Wed, 8 Mar 2023 03:53:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B327561758; Wed, 8 Mar 2023 11:53:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3F46C433A0; Wed, 8 Mar 2023 11:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678276390; bh=ItNl/VUdFsdbRrM3FYDQwEWNJZg7o1tpHGJGDk3Q3uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DuQdIWp3o2rCCF0WNC47R0nVaUQFAnWL/A5R99rxnkqvJBtyU0kfQxOwCLLHFjsZk bN9BYnebAVV2QRjWh8Fu/brb56KLp4LlrZDEwOGWU+z1TUS6AXOS30yO/tSIU4jfLp SjXYAr8wdzaIn21GDPOCvSWfpgudc6oImq/K1EdjsILTbPtsxTN5xEE+2y2U/eOLLL VQF3t9dIbPQdj3W5pSxdp5jmyUo2nNJPQsv63GQ4vyxGJLnMeSQ/c4wQ9DVtbtO9sU ZZ4xnmAEIu+E9EA+d0QdObBK5f55B7laDtW1SwT9Bb0FCht4F3Giq366viOoZ7WF+Z Qewp4S7u7uYBw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Zhen Lei , Arnd Bergmann , Masahiro Yamada Subject: [PATCH 7/8] scripts/kallsyms: decrease expand_symbol() / cleanup_symbol_name() calls Date: Wed, 8 Mar 2023 20:52:42 +0900 Message-Id: <20230308115243.82592-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308115243.82592-1-masahiroy@kernel.org> References: <20230308115243.82592-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759800935106844186?= X-GMAIL-MSGID: =?utf-8?q?1759800935106844186?= Currently, expand_symbol() is called many times to get the uncompressed symbol names for sorting, and also for adding comments. With the output order shuffled in the previous commit, the symbol data are now written in the following order: (1) kallsyms_num_syms (2) kallsyms_names <-- need compressed names (3) kallsyms_markers (4) kallsyms_token_table (5) kallsyms_token_index (6) kallsyms_addressed / kallsyms_offsets <-- need uncompressed names (for commenting) (7) kallsyms_relative_base (8) kallsyms_seq_of_names <-- need uncompressed names (for sorting) The compressed names are only needed by (2). Call expand_symbol() between (2) and (3) to restore the original symbol names. This requires just one expand_symbol() call for each symbol. Call cleanup_symbol_name() between (7) and (8) instead of during sorting. It is allowed to overwrite the ->sym field because (8) just outputs the index instead of the name of each symbol. Again, this requires just one cleanup_symbol_name() call for each symbol. This refactoring makes it ~30% faster. [Before] $ time scripts/kallsyms --all-symbols --absolute-percpu --base-relative \ .tmp_vmlinux.kallsyms2.syms >/dev/null real 0m1.027s user 0m1.010s sys 0m0.016s $ time scripts/kallsyms --all-symbols --absolute-percpu --base-relative \ .tmp_vmlinux.kallsyms2.syms >/dev/null real 0m0.717s user 0m0.717s sys 0m0.000s Signed-off-by: Masahiro Yamada --- scripts/kallsyms.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 5996f1e61bcf..937900823fa8 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -335,19 +335,10 @@ static int symbol_absolute(const struct sym_entry *s) return s->percpu_absolute; } -static char * s_name(char *buf) -{ - /* Skip the symbol type */ - return buf + 1; -} - static void cleanup_symbol_name(char *s) { char *p; - if (!lto_clang) - return; - /* * ASCII[.] = 2e * ASCII[0-9] = 30,39 @@ -366,16 +357,10 @@ static void cleanup_symbol_name(char *s) static int compare_names(const void *a, const void *b) { int ret; - char sa_namebuf[KSYM_NAME_LEN]; - char sb_namebuf[KSYM_NAME_LEN]; const struct sym_entry *sa = *(const struct sym_entry **)a; const struct sym_entry *sb = *(const struct sym_entry **)b; - expand_symbol(sa->sym, sa->len, sa_namebuf); - expand_symbol(sb->sym, sb->len, sb_namebuf); - cleanup_symbol_name(s_name(sa_namebuf)); - cleanup_symbol_name(s_name(sb_namebuf)); - ret = strcmp(s_name(sa_namebuf), s_name(sb_namebuf)); + ret = strcmp(sym_name(sa), sym_name(sb)); if (!ret) { if (sa->addr > sb->addr) return 1; @@ -464,6 +449,15 @@ static void write_src(void) } printf("\n"); + /* + * Now that we wrote out the compressed symbol names, restore the + * original names, which are needed in some of the later steps. + */ + for (i = 0; i < table_cnt; i++) { + expand_symbol(table[i]->sym, table[i]->len, buf); + strcpy((char *)table[i]->sym, buf); + } + output_label("kallsyms_markers"); for (i = 0; i < ((table_cnt + 255) >> 8); i++) printf("\t.long\t%u\n", markers[i]); @@ -520,8 +514,7 @@ static void write_src(void) table[i]->addr); exit(EXIT_FAILURE); } - expand_symbol(table[i]->sym, table[i]->len, buf); - printf("\t.long\t%#x /* %s */\n", (int)offset, buf); + printf("\t.long\t%#x /* %s */\n", (int)offset, table[i]->sym); } else if (!symbol_absolute(table[i])) { output_address(table[i]->addr); } else { @@ -536,6 +529,10 @@ static void write_src(void) printf("\n"); } + if (lto_clang) + for (i = 0; i < table_cnt; i++) + cleanup_symbol_name((char *)table[i]->sym); + sort_symbols_by_name(); output_label("kallsyms_seqs_of_names"); for (i = 0; i < table_cnt; i++)