Skip to content

Commit dd1553b

Browse files
committed
scripts/kallsyms: decrease expand_symbol() / cleanup_symbol_name() calls
Currently, expand_symbol() is called many times to get the uncompressed symbol names for sorting, and also for adding comments. With the output order shuffled in the previous commit, the symbol data are now written in the following order: (1) kallsyms_num_syms (2) kallsyms_names <-- need compressed names (3) kallsyms_markers (4) kallsyms_token_table (5) kallsyms_token_index (6) kallsyms_addressed / kallsyms_offsets <-- need uncompressed names (for commenting) (7) kallsyms_relative_base (8) kallsyms_seq_of_names <-- need uncompressed names (for sorting) The compressed names are only needed by (2). Call expand_symbol() between (2) and (3) to restore the original symbol names. This requires just one expand_symbol() call for each symbol. Call cleanup_symbol_name() between (7) and (8) instead of during sorting. It is allowed to overwrite the ->sym field because (8) just outputs the index instead of the name of each symbol. Again, this requires just one cleanup_symbol_name() call for each symbol. This refactoring makes it ~30% faster. [Before] $ time scripts/kallsyms --all-symbols --absolute-percpu --base-relative \ .tmp_vmlinux.kallsyms2.syms >/dev/null real 0m1.027s user 0m1.010s sys 0m0.016s [After] $ time scripts/kallsyms --all-symbols --absolute-percpu --base-relative \ .tmp_vmlinux.kallsyms2.syms >/dev/null real 0m0.717s user 0m0.717s sys 0m0.000s Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 404bad7 commit dd1553b

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

scripts/kallsyms.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -335,19 +335,10 @@ static int symbol_absolute(const struct sym_entry *s)
335335
return s->percpu_absolute;
336336
}
337337

338-
static char * s_name(char *buf)
339-
{
340-
/* Skip the symbol type */
341-
return buf + 1;
342-
}
343-
344338
static void cleanup_symbol_name(char *s)
345339
{
346340
char *p;
347341

348-
if (!lto_clang)
349-
return;
350-
351342
/*
352343
* ASCII[.] = 2e
353344
* ASCII[0-9] = 30,39
@@ -366,16 +357,10 @@ static void cleanup_symbol_name(char *s)
366357
static int compare_names(const void *a, const void *b)
367358
{
368359
int ret;
369-
char sa_namebuf[KSYM_NAME_LEN];
370-
char sb_namebuf[KSYM_NAME_LEN];
371360
const struct sym_entry *sa = *(const struct sym_entry **)a;
372361
const struct sym_entry *sb = *(const struct sym_entry **)b;
373362

374-
expand_symbol(sa->sym, sa->len, sa_namebuf);
375-
expand_symbol(sb->sym, sb->len, sb_namebuf);
376-
cleanup_symbol_name(s_name(sa_namebuf));
377-
cleanup_symbol_name(s_name(sb_namebuf));
378-
ret = strcmp(s_name(sa_namebuf), s_name(sb_namebuf));
363+
ret = strcmp(sym_name(sa), sym_name(sb));
379364
if (!ret) {
380365
if (sa->addr > sb->addr)
381366
return 1;
@@ -464,6 +449,15 @@ static void write_src(void)
464449
}
465450
printf("\n");
466451

452+
/*
453+
* Now that we wrote out the compressed symbol names, restore the
454+
* original names, which are needed in some of the later steps.
455+
*/
456+
for (i = 0; i < table_cnt; i++) {
457+
expand_symbol(table[i]->sym, table[i]->len, buf);
458+
strcpy((char *)table[i]->sym, buf);
459+
}
460+
467461
output_label("kallsyms_markers");
468462
for (i = 0; i < ((table_cnt + 255) >> 8); i++)
469463
printf("\t.long\t%u\n", markers[i]);
@@ -520,8 +514,7 @@ static void write_src(void)
520514
table[i]->addr);
521515
exit(EXIT_FAILURE);
522516
}
523-
expand_symbol(table[i]->sym, table[i]->len, buf);
524-
printf("\t.long\t%#x /* %s */\n", (int)offset, buf);
517+
printf("\t.long\t%#x /* %s */\n", (int)offset, table[i]->sym);
525518
} else if (!symbol_absolute(table[i])) {
526519
output_address(table[i]->addr);
527520
} else {
@@ -536,6 +529,10 @@ static void write_src(void)
536529
printf("\n");
537530
}
538531

532+
if (lto_clang)
533+
for (i = 0; i < table_cnt; i++)
534+
cleanup_symbol_name((char *)table[i]->sym);
535+
539536
sort_symbols_by_name();
540537
output_label("kallsyms_seqs_of_names");
541538
for (i = 0; i < table_cnt; i++)

0 commit comments

Comments
 (0)