Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5007762ybb; Tue, 24 Mar 2020 09:15:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv8cZgTd2RB/HqpF5Y5SEf/ZKa30rGcQtwi1LeNmvSGXLb17D52YhgU5+dPalJCLAyCDDeA X-Received: by 2002:a54:4e13:: with SMTP id a19mr4101500oiy.108.1585066515586; Tue, 24 Mar 2020 09:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585066515; cv=none; d=google.com; s=arc-20160816; b=acFrj5CT1qxuAUv6+r9c/ECuL+S/P5Qt29jCD4J/svnrt3Z9jZVLe9nrJZWqzCRrV9 cRRDVAPD+or9Ev7f4S/T8DW3midl0NdXkDucMrmBdJAaaCZ28Ne/mPhttqCxhavlzrCM +lKzcS/ikh3Xjw+EhGISAA6SV1XNaM6mPpSchZzBNMeHkuejm/x/H7BsxGSShyj1aiZD OnRRhYBCwHhYy6794z5lrMDIV6byMxM8i9ElVqU2QMulokUaDNeGC/+h6kXYfSkeIivT u2rPHYmofueY/kwPwYNTJqJlwRRckXwbffXJH6LaQTiDjL/NNwFQ8Ph5fKVRWABfg49k o+Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id:dkim-signature; bh=LNpyFY6b8XWj6ubZzravys+8EHpOltiuVP2rLApomHQ=; b=WBrl2VUDcYn2jTViQQHOxlg8KV3dYIaJUVsvBWG/KE67C0c/+p9+PvXSVf9l2+YL6W CU1ROWojHoZar8hPQUo6P8wV49oTM2phjcoykvWSyC4p5h0cA6alHSD969DzBhRAxSNY zJ3g3ytaWIAr/VIeDLDgxlwq60q9l8oxXyRP4tcojh57xV41DKOFrRv2kOSqq8N4V12c l7C31NL3ilZoL1gusTQtl9taRPbd52AoE3DwpNhZZ+XGhnf8IKfZ0FQ9gepvbbA2XVE5 o8glbOo12dxFHRKKhCBCfpKxYjynKv2wwmkK9f+J4Rs7AHSgKIyRhvKEwXqHioWqXY+c 1rVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nyEjpKqk; 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 i16si3394769otk.112.2020.03.24.09.15.02; Tue, 24 Mar 2020 09:15:15 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nyEjpKqk; 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 S1729037AbgCXQNF (ORCPT + 99 others); Tue, 24 Mar 2020 12:13:05 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:51014 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728341AbgCXQLg (ORCPT ); Tue, 24 Mar 2020 12:11:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=LNpyFY6b8XWj6ubZzravys+8EHpOltiuVP2rLApomHQ=; b=nyEjpKqkjfU4uWjTm1mR6VNJuY zSV5E1ASlhva1f5uBDpqzz1U4XAdN7t9w+oSs95jpeVvlFwOdR5MSu1+Qxiv0rcqkhe6LYOp0yAcV Xcetv4tn9uLaAEtqlN3ZxrqHK/EuC0VlirzzyLqrjOZUvxdp9wyB3dRufBHf0KWYY6j4wZetgC2lP kgcZ1QLZs911lz/zKeJrRukcoKzbWCmpR+O9yRUv01BpsUGE3QSl0rDXbI21wQwzhlZDQEvQEEZUt 8+75HiWNAwhw4Xh6EIhRp+5ixKS9Bnn2fYhmLKveMTBMmf0xG+VfbTgVM87Ne4vF08mnLtpllggvJ aPYOZD5Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jGm9M-0000C6-VN; Tue, 24 Mar 2020 16:11:33 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5E23B3072A4; Tue, 24 Mar 2020 17:11:28 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 43EFC29A490F1; Tue, 24 Mar 2020 17:11:28 +0100 (CET) Message-Id: <20200324160924.676865656@infradead.org> User-Agent: quilt/0.65 Date: Tue, 24 Mar 2020 16:31:26 +0100 From: Peter Zijlstra To: tglx@linutronix.de, jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, peterz@infradead.org, mhiramat@kernel.org, mbenes@suse.cz, brgerst@gmail.com Subject: [PATCH v3 13/26] objtool: Optimize find_symbol_by_name() References: <20200324153113.098167666@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) Acked-by: Josh Poimboeuf --- tools/objtool/elf.c | 10 +++++----- tools/objtool/elf.h | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -203,13 +203,11 @@ struct symbol *find_func_containing(stru 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, i 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); --- 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); };