History

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

Masahiro Yamada committed 3 years ago

Commit dd1553b1 parent 404bad71 file · +15 −18Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/kallsyms.c+15−18
@@ -335,19 +335,10 @@ static int symbol_absolute(const struct sym_entry *s) · 334 unmodified lines
335 return s->percpu_absolute;335 return s->percpu_absolute;
336}336}
337 337
338static char * s_name(char *buf)
339{
340 /* Skip the symbol type */
341 return buf + 1;
342}
343
344static void cleanup_symbol_name(char *s)338static void cleanup_symbol_name(char *s)
345{339{
346 char *p;340 char *p;
347 341
348 if (!lto_clang)
349 return;
350
351 /*342 /*
352 * ASCII[.] = 2e343 * ASCII[.] = 2e
353 * ASCII[0-9] = 30,39344 * ASCII[0-9] = 30,39
@@ -366,16 +357,10 @@ static void cleanup_symbol_name(char *s) · 12 unmodified lines
366static int compare_names(const void *a, const void *b)357static int compare_names(const void *a, const void *b)
367{358{
368 int ret;359 int ret;
369 char sa_namebuf[KSYM_NAME_LEN];
370 char sb_namebuf[KSYM_NAME_LEN];
371 const struct sym_entry *sa = *(const struct sym_entry **)a;360 const struct sym_entry *sa = *(const struct sym_entry **)a;
372 const struct sym_entry *sb = *(const struct sym_entry **)b;361 const struct sym_entry *sb = *(const struct sym_entry **)b;
373 362
374 expand_symbol(sa->sym, sa->len, sa_namebuf);363 ret = strcmp(sym_name(sa), sym_name(sb));
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));
379 if (!ret) {364 if (!ret) {
380 if (sa->addr > sb->addr)365 if (sa->addr > sb->addr)
381 return 1;366 return 1;
@@ -464,6 +449,15 @@ static void write_src(void) · 82 unmodified lines
464 }449 }
465 printf("\n");450 printf("\n");
466 451
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
467 output_label("kallsyms_markers");461 output_label("kallsyms_markers");
468 for (i = 0; i < ((table_cnt + 255) >> 8); i++)462 for (i = 0; i < ((table_cnt + 255) >> 8); i++)
469 printf("\t.long\t%u\n", markers[i]);463 printf("\t.long\t%u\n", markers[i]);
@@ -520,8 +514,7 @@ static void write_src(void) · 50 unmodified lines
520 table[i]->addr);514 table[i]->addr);
521 exit(EXIT_FAILURE);515 exit(EXIT_FAILURE);
522 }516 }
523 expand_symbol(table[i]->sym, table[i]->len, buf);517 printf("\t.long\t%#x /* %s */\n", (int)offset, table[i]->sym);
524 printf("\t.long\t%#x /* %s */\n", (int)offset, buf);
525 } else if (!symbol_absolute(table[i])) {518 } else if (!symbol_absolute(table[i])) {
526 output_address(table[i]->addr);519 output_address(table[i]->addr);
527 } else {520 } else {
@@ -536,6 +529,10 @@ static void write_src(void) · 8 unmodified lines
536 printf("\n");529 printf("\n");
537 }530 }
538 531
532 if (lto_clang)
533 for (i = 0; i < table_cnt; i++)
534 cleanup_symbol_name((char *)table[i]->sym);
535
539 sort_symbols_by_name();536 sort_symbols_by_name();
540 output_label("kallsyms_seqs_of_names");537 output_label("kallsyms_seqs_of_names");
541 for (i = 0; i < table_cnt; i++)538 for (i = 0; i < table_cnt; i++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t