Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1561221ybb; Thu, 26 Mar 2020 03:10:34 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsA+igRj8AYYLw1HUdcohsKSrQtMiu6PQpR26d2gt50gg3Z/G+s+a8DMf1FdRCfGbLbqaEQ X-Received: by 2002:a05:6808:56:: with SMTP id v22mr1172591oic.116.1585217434037; Thu, 26 Mar 2020 03:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585217434; cv=none; d=google.com; s=arc-20160816; b=DCcq/+pBrIlE8EssW0RpmYzCFH70TNMvM+KJsEMNlIJP4qo4GeiGh/k/Y6x65SH5pZ envvpg6yvEta5RHTjfAeRCYyEBA/Beuvoi12YTNR0qdTWUhMKaXwRTE9K3jQXgJAu7Np 7btdZYmKxVe8e4iUM025fwg3zpCwUq+PweXvFnmXyECFcTzjwS+WGSTve44g8XauahvQ ASWGGT02qIXksbEO9ywD/XS0i9p3sSCPHLUu8UohsbPkyMbMZez9SKUpqax/uvhpHi52 fKFMu/uG9DeCBSieTNztLFQuaUbtiT47jJHk0MJWedMmWaWlCvN9n/8pLng3e0bGRr8O DAVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=syoXbqv2RuHzxlSiP8PRHOdGTkc2nUHXDOPIxbj9XfM=; b=kquEADoNFSuU4PxkqYpwjAWrsWhdJIM6H3MoBGvwA52NsY8FbwXnIWQaTgOELkKjte FUXp81OZqMy+7TbfNiOVru6zG2zPoNofHkf3xSqx8BIHmuxBrwJVKtRX4ChyPOJ/GxE9 cXBzHLJDMYehC7e5Lhy2Z237A6t5WGeorg8zZXXyMhCl9gEM1iZt0WDUqJXdvhHOFUXG 1Qzw4VMQsDp+OvlkvsxncBO+Ubg+bbKBas15Vm/6sxhx22ePbdi5JdeZjxslO60mDkkj +hXEnqmQ8YBar/QYeviSW5DChmSzWzj5thE5pqf97gxqG5gtLwphgUULO+u5xkY+XozT bWAg== 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 f23si813471oti.283.2020.03.26.03.10.21; Thu, 26 Mar 2020 03:10:34 -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 S1728154AbgCZKJc (ORCPT + 99 others); Thu, 26 Mar 2020 06:09:32 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50179 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgCZKIl (ORCPT ); Thu, 26 Mar 2020 06:08:41 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jHPRC-00046L-G7; Thu, 26 Mar 2020 11:08:34 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 0EFB11C0440; Thu, 26 Mar 2020 11:08:34 +0100 (CET) Date: Thu, 26 Mar 2020 10:08:33 -0000 From: "tip-bot2 for Peter Zijlstra" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/objtool] objtool: Optimize find_symbol_by_name() Cc: "Peter Zijlstra (Intel)" , Miroslav Benes , Josh Poimboeuf , x86 , LKML In-Reply-To: <20200324160924.676865656@infradead.org> References: <20200324160924.676865656@infradead.org> MIME-Version: 1.0 Message-ID: <158521731363.28353.8741952438283038310.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the core/objtool branch of tip: Commit-ID: cdb3d057a17d56363a831e486ea39e4c389a6cf9 Gitweb: https://git.kernel.org/tip/cdb3d057a17d56363a831e486ea39e4c389a6cf9 Author: Peter Zijlstra AuthorDate: Thu, 12 Mar 2020 10:17:38 +01:00 Committer: Peter Zijlstra CommitterDate: Wed, 25 Mar 2020 18:28:30 +01:00 objtool: Optimize find_symbol_by_name() Perf showed that find_symbol_by_name() takes time; add a symbol name hash. This shaves another second off of objtool on vmlinux.o runtime, down to 15 seconds. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Miroslav Benes Acked-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20200324160924.676865656@infradead.org --- tools/objtool/elf.c | 10 +++++----- tools/objtool/elf.h | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 07db4df..43abae7 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -203,13 +203,11 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset) struct symbol *find_symbol_by_name(struct elf *elf, const char *name) { - struct section *sec; struct symbol *sym; - list_for_each_entry(sec, &elf->sections, list) - list_for_each_entry(sym, &sec->symbol_list, list) - if (!strcmp(sym->name, name)) - return sym; + hash_for_each_possible(elf->symbol_name_hash, sym, name_hash, str_hash(name)) + if (!strcmp(sym->name, name)) + return sym; return NULL; } @@ -386,6 +384,7 @@ static int read_symbols(struct elf *elf) entry = &sym->sec->symbol_list; list_add(&sym->list, entry); hash_add(elf->symbol_hash, &sym->hash, sym->idx); + hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name)); } if (stats) @@ -524,6 +523,7 @@ struct elf *elf_read(const char *name, int flags) memset(elf, 0, sizeof(*elf)); hash_init(elf->symbol_hash); + hash_init(elf->symbol_name_hash); hash_init(elf->section_hash); hash_init(elf->section_name_hash); INIT_LIST_HEAD(&elf->sections); diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h index d18f466..3088d92 100644 --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -47,6 +47,7 @@ struct symbol { struct list_head list; struct rb_node node; struct hlist_node hash; + struct hlist_node name_hash; GElf_Sym sym; struct section *sec; char *name; @@ -77,6 +78,7 @@ struct elf { char *name; struct list_head sections; DECLARE_HASHTABLE(symbol_hash, 20); + DECLARE_HASHTABLE(symbol_name_hash, 20); DECLARE_HASHTABLE(section_hash, 16); DECLARE_HASHTABLE(section_name_hash, 16); };