Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5005986ybb; Tue, 24 Mar 2020 09:13:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvUJMC1OhYVlO3sW74kDTSJnQvMZC2KIj5pdc/J5RQ8SFETntiC8xCg/F3A9gyks3/YaMGW X-Received: by 2002:a9d:63c9:: with SMTP id e9mr9558891otl.65.1585066411877; Tue, 24 Mar 2020 09:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585066411; cv=none; d=google.com; s=arc-20160816; b=XiE87MRmmuV2e9mzqG63zrZKbK/IAye6Q6yW/UOq+8pJNVAlCGLIlKwIxqcyjGkn2c kqFa03Gb9ks2M4vjGr8IwLNOu9YN9qUrmVkH78v80WdK8D36rpdKKg6rS+UgKt2zqUMb bHlR0TSTJG0Ixk/HdfthPbfxG0X5Ih+lm0fv55vX519Igrr0F+/KZ1da8nV0rEL33anW x2mIGHfB1x/sSRvdY2KSv8AAR+tQaFCbwpKg+aP6h9lLwC5+z00KiZV8utj8MQnfIkTn oVsXmGzK9GXt0omh9jgn/WBhNGAGTbxU6xh1k+TD0EHavBW/YWXFqGqWyTS3kZnsysbt hP4A== 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=CKFnytJ32A9xrYvdfO7SF5LxPYVzgMvTqlQH12UtOoI=; b=qsdbwpZo8c66rE5fQy6AM/a8SO44mCp6JvrXR4Pfh9v4XPq99liquFE7rPeBZAwXnY O23SGWvztsmLxf8uUGitX6X5n/Z6yVaISNV0vtHYdgygnWwiNlMiUDWIqnvRUN1ak6hG jEwLwhXcSg0w9fDCKfLiUUzrSupEhfJ0hGfYke8S/9Rg+pZuJDWg7t7d3ThNPtuXbyth bsUmuOGuPoZElHPrT03hnkBvFS53nXknHx//QgmkM87Ka5WUaJIXkNgUiLm+SmkCSXAZ O5k5if2erDKZkGhtqiandhv4FGEIl5KxgjfTTMTa/LWFM0e33iXtF7ZiM0PTQRiHvkRs c4SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=2nu7eejO; 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 y15si8964674otk.125.2020.03.24.09.13.19; Tue, 24 Mar 2020 09:13:31 -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=merlin.20170209 header.b=2nu7eejO; 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 S1728916AbgCXQMZ (ORCPT + 99 others); Tue, 24 Mar 2020 12:12:25 -0400 Received: from merlin.infradead.org ([205.233.59.134]:36944 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728359AbgCXQLh (ORCPT ); Tue, 24 Mar 2020 12:11:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=CKFnytJ32A9xrYvdfO7SF5LxPYVzgMvTqlQH12UtOoI=; b=2nu7eejO4b543nxRb3z0wDYRy7 ZPcyveZxFERiFZusT0QbqBkoTOzS9yZToXHg5IFuYSPHc3Qh6fPFUwpWTAEM1oKrvaMTEkMjnfGwV 5Y4QCbBRRxZvxTdTeIZlxqwi7HltNn/eMA3jKLHRaaZUr2+3M9K7e1MhmBFcRes+9Iyvw7rj/dk1I 5Q6X1/pVPyyb35b8cLzHQpg4Rg76P8HN84g/r430QIihccUpkyKtVzNJaLnwqJCnwCWGWPEFZU75a drgwNZR55t0T326rl6UceFtkgkk549QFeodqqskvXA1HdoNP30IS6ek1clKoK1Q5oPjiZg6Hxrm6m ttMRBPjQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jGm9M-0006bm-Mu; Tue, 24 Mar 2020 16:11:32 +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 5E3063073E4; Tue, 24 Mar 2020 17:11:28 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 4DAB229A490F0; Tue, 24 Mar 2020 17:11:28 +0100 (CET) Message-Id: <20200324160924.861321325@infradead.org> User-Agent: quilt/0.65 Date: Tue, 24 Mar 2020 16:31:29 +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 16/26] objtool: Optimize find_rela_by_dest_range() 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 shows there is significant time in find_rela_by_dest(); this is because we have to iterate the address space per byte, looking for relocation entries. Optimize this by reducing the address space granularity. This reduces objtool on vmlinux.o runtime from 4.8 to 4.4 seconds. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- tools/objtool/elf.c | 15 +++++++++++---- tools/objtool/elf.h | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -215,7 +215,7 @@ struct symbol *find_symbol_by_name(struc struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec, unsigned long offset, unsigned int len) { - struct rela *rela; + struct rela *rela, *r = NULL; unsigned long o; if (!sec->rela) @@ -223,12 +223,19 @@ struct rela *find_rela_by_dest_range(str sec = sec->rela; - for (o = offset; o < offset + len; o++) { + for_offset_range(o, offset, offset + len) { hash_for_each_possible(elf->rela_hash, rela, hash, sec_offset_hash(sec, o)) { - if (rela->sec == sec && rela->offset == o) - return rela; + if (rela->sec != sec) + continue; + + if (rela->offset >= offset && rela->offset < offset + len) { + if (!r || rela->offset < r->offset) + r = rela; + } } + if (r) + return r; } return NULL; --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -83,9 +83,23 @@ struct elf { DECLARE_HASHTABLE(rela_hash, 20); }; +#define OFFSET_STRIDE_BITS 4 +#define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS) +#define OFFSET_STRIDE_MASK (~(OFFSET_STRIDE - 1)) + +#define for_offset_range(_offset, _start, _end) \ + for (_offset = ((_start) & OFFSET_STRIDE_MASK); \ + _offset <= ((_end) & OFFSET_STRIDE_MASK); \ + _offset += OFFSET_STRIDE) + static inline u32 sec_offset_hash(struct section *sec, unsigned long offset) { - u32 ol = offset, oh = offset >> 32, idx = sec->idx; + u32 ol, oh, idx = sec->idx; + + offset &= OFFSET_STRIDE_MASK; + + ol = offset; + oh = offset >> 32; __jhash_mix(ol, oh, idx);