Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp547884ybh; Thu, 12 Mar 2020 06:52:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtUGrBT7zg2WD6Aalx++XBCXVm9Y0EtnmaBM949qm6t66imqzENJRn4KTHgAKf12sTlTa/4 X-Received: by 2002:a4a:3c4d:: with SMTP id p13mr4076886oof.44.1584021156202; Thu, 12 Mar 2020 06:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584021156; cv=none; d=google.com; s=arc-20160816; b=XRdHH5UyFyKBuoRYP0ZvZT3RfPdGaW/Pj9MhtCpSA4nFU8AsrGYMuWQt8E2l2Io6Y8 w9jngvIVgEePykm2bDXV6d225gDsNXPT0rPfj7x6R/Gb8YegUe2eGqiBjuuuDFZ+00A5 PMEjYmcSn5f5LBcrdHk4rMbc3kjFowBkasgOUM3HC9Q/7BvlKetFFG8idqEre09TQuuS 23UuuLoT6IlK5q74APzMNDvcGsOWWYoVTjcvA7fMPQAYP/lLqIBR+kIA15azbMrrkDEI 4XahqsCk3qG2qph0Nl6HlA+tWFs2U8Ithl+gaFKPcvlrGc1lqpTJBIn6vuaPUKeM7xPn KbkA== 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=Eo0gdSJQsnf3/CR3ZyWDPBQrlgYlqxkUT+8zjcJOBDQ=; b=Jk3tSDB5b5fxZDnPIGCq/yop+2ad6/AHFs+NLdZkDq3NuJq1TozOAGP5jChoQF1u1N tmWHorxHY+2eDItYMbV7fUQjn32lY35yG7t3Uum0HmgQ7Km+myStiBNaNztkQVVptYGI +r/MdyHoOAXvAmiK6ioUx2TZJnGMX3SISQ5tFzcbn/Rk8TF4897aZbO+ZBAyr9IOiGw9 2E5Ct2Yj8tARI5zIUVfXcSjvaVlQ7jcGhlj2GKIztU9SPUj/9bGnFN6qdxNNjyxyWJl8 HbZC9fErifqq7Ajq1pqAuEHmiC6IWrJ66hPq6Rh/TuwOyPc05iqTY0cooGTCjrqsspsK ih3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZaFSJ5hL; 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 v25si2737162oth.274.2020.03.12.06.52.23; Thu, 12 Mar 2020 06:52:36 -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=ZaFSJ5hL; 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 S1727533AbgCLNvp (ORCPT + 99 others); Thu, 12 Mar 2020 09:51:45 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:56992 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727456AbgCLNvl (ORCPT ); Thu, 12 Mar 2020 09:51:41 -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=Eo0gdSJQsnf3/CR3ZyWDPBQrlgYlqxkUT+8zjcJOBDQ=; b=ZaFSJ5hLPdmtgq/eD1zh9mmghw PfSQpK2gpU3Mrgx/KRHkmZuUEHwuWCAvV6/MAEkl7+JtqXpC9OUM8DK9yd6RX0HSQNbQ1x/OBbyp5 Rnh9kMqWufyiZ+mb98gdT5l2jPF6hdZuUDFBjWt8/VEEQPzHlFNijhLtGnQyQtT8c8V6y73BWXsjd UO5RNjY346B9t/bML48WK3IcYmQhh1++jkQxsuhMBDY3yeWwpop+YOSo+K28P5Uus2WVJiz1slZGu OvXhGPpOLG+kD9NbS4hHTwCZRsezUo3vVduq1aWKB29jq9lr7i5zkmTKxdlTlLKb7l0T9k64eUpT1 TODRdqqg==; 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 1jCOFN-0006Wb-WF; Thu, 12 Mar 2020 13:51:38 +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 44827305EEC; Thu, 12 Mar 2020 14:51:34 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 262522B92DA1B; Thu, 12 Mar 2020 14:51:34 +0100 (CET) Message-Id: <20200312135041.875820323@infradead.org> User-Agent: quilt/0.65 Date: Thu, 12 Mar 2020 14:41:15 +0100 From: Peter Zijlstra To: tglx@linutronix.de, jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, peterz@infradead.org Subject: [RFC][PATCH 08/16] Optimize find_section_by_name() References: <20200312134107.700205216@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 In order to avoid yet another linear search of (20k) sections, add a name based hash. This reduces objtool runtime on vmlinux.o by some 10s to around 35s. Signed-off-by: Peter Zijlstra (Intel) --- tools/objtool/elf.c | 9 ++++++++- tools/objtool/elf.h | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -22,11 +22,16 @@ #define MAX_NAME_LEN 128 +static inline u32 str_hash(const char *str) +{ + return jhash(str, strlen(str), 0); +} + struct section *find_section_by_name(struct elf *elf, const char *name) { struct section *sec; - list_for_each_entry(sec, &elf->sections, list) + hash_for_each_possible(elf->section_name_hash, sec, name_hash, str_hash(name)) if (!strcmp(sec->name, name)) return sec; @@ -193,6 +198,7 @@ static int read_sections(struct elf *elf sec->len = sec->sh.sh_size; hash_add(elf->section_hash, &sec->hash, sec->idx); + hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); } if (stats) @@ -433,6 +439,7 @@ struct elf *elf_read(const char *name, i hash_init(elf->symbol_hash); hash_init(elf->section_hash); + hash_init(elf->section_name_hash); INIT_LIST_HEAD(&elf->sections); elf->fd = open(name, flags); --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef LIBELF_USE_DEPRECATED # define elf_getshdrnum elf_getshnum @@ -26,6 +27,7 @@ struct section { struct list_head list; struct hlist_node hash; + struct hlist_node name_hash; GElf_Shdr sh; struct list_head symbol_list; struct list_head rela_list; @@ -73,6 +75,7 @@ struct elf { struct list_head sections; DECLARE_HASHTABLE(symbol_hash, 20); DECLARE_HASHTABLE(section_hash, 16); + DECLARE_HASHTABLE(section_name_hash, 16); };