From 042ba73fe7eb63872ee2d6ac86410052210c1f16 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Wed, 9 Mar 2016 00:07:00 -0600 Subject: objtool: Add several performance improvements Use hash tables for instruction and rela lookups (and keep the linked lists around for sequential access). Also cache the section struct for the "__func_stack_frame_non_standard" section. With this change, "objtool check net/wireless/nl80211.o" goes from: real 0m1.168s user 0m1.163s sys 0m0.005s to: real 0m0.059s user 0m0.042s sys 0m0.017s for a 20x speedup. With the same object, it should be noted that the memory heap usage grew from 8MB to 62MB. Reducing the memory usage is on the TODO list. Reported-by: Ingo Molnar Signed-off-by: Josh Poimboeuf Cc: Andrew Morton Cc: Andy Lutomirski Cc: Arnaldo Carvalho de Melo Cc: Arnaldo Carvalho de Melo Cc: Bernd Petrovitsch Cc: Borislav Petkov Cc: Chris J Arges Cc: Jiri Slaby Cc: Linus Torvalds Cc: Michal Marek Cc: Namhyung Kim Cc: Pedro Alves Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: live-patching@vger.kernel.org Link: http://lkml.kernel.org/r/dd0d8e1449506cfa7701b4e7ba73577077c44253.1457502970.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar --- tools/objtool/builtin-check.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'tools/objtool/builtin-check.c') diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index cf1e48dbfa97..bfeee227aaab 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -34,6 +34,8 @@ #include "arch.h" #include "warn.h" +#include + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define STATE_FP_SAVED 0x1 @@ -42,6 +44,7 @@ struct instruction { struct list_head list; + struct hlist_node hash; struct section *sec; unsigned long offset; unsigned int len, state; @@ -61,7 +64,8 @@ struct alternative { struct objtool_file { struct elf *elf; struct list_head insn_list; - struct section *rodata; + DECLARE_HASHTABLE(insn_hash, 16); + struct section *rodata, *whitelist; }; const char *objname; @@ -72,7 +76,7 @@ static struct instruction *find_insn(struct objtool_file *file, { struct instruction *insn; - list_for_each_entry(insn, &file->insn_list, list) + hash_for_each_possible(file->insn_hash, insn, hash, offset) if (insn->sec == sec && insn->offset == offset) return insn; @@ -111,14 +115,12 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file, */ static bool ignore_func(struct objtool_file *file, struct symbol *func) { - struct section *macro_sec; struct rela *rela; struct instruction *insn; /* check for STACK_FRAME_NON_STANDARD */ - macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard"); - if (macro_sec && macro_sec->rela) - list_for_each_entry(rela, ¯o_sec->rela->rela_list, list) + if (file->whitelist && file->whitelist->rela) + list_for_each_entry(rela, &file->whitelist->rela->rela_list, list) if (rela->sym->sec == func->sec && rela->addend == func->offset) return true; @@ -276,6 +278,7 @@ static int decode_instructions(struct objtool_file *file) return -1; } + hash_add(file->insn_hash, &insn->hash, insn->offset); list_add_tail(&insn->list, &file->insn_list); } } @@ -729,6 +732,7 @@ static int decode_sections(struct objtool_file *file) { int ret; + file->whitelist = find_section_by_name(file->elf, "__func_stack_frame_non_standard"); file->rodata = find_section_by_name(file->elf, ".rodata"); ret = decode_instructions(file); @@ -1091,6 +1095,7 @@ static void cleanup(struct objtool_file *file) free(alt); } list_del(&insn->list); + hash_del(&insn->hash); free(insn); } elf_close(file->elf); @@ -1125,6 +1130,7 @@ int cmd_check(int argc, const char **argv) } INIT_LIST_HEAD(&file.insn_list); + hash_init(file.insn_hash); ret = decode_sections(&file); if (ret < 0) -- cgit v1.2.3