Skip to content

Commit

Permalink
scripts: ftrace - move the nop-processing in ftrace_init to compile time
Browse files Browse the repository at this point in the history
When ftrace is enabled, ftrace_init will consume a period of
time, usually around 15~20ms. Approximately 60% of the time is
consumed by nop-processing. Moving the nop-processing to the
compile time can speed up the kernel boot process.

performance test:
        env:    Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
        method: before and after patching, compare the
                total time of ftrace_init(), and verify
                the functionality of ftrace.

        avg_time of ftrace_init:
                with patch: 7.114ms
                without patch: 15.763ms

Signed-off-by: Yinan Liu <yinan@linux.alibaba.com>
  • Loading branch information
Yinan Liu authored and intel-lab-lkp committed Sep 11, 2021
1 parent b629528 commit 54d68f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6261,6 +6261,10 @@ static int ftrace_process_locs(struct module *mod,
* until we are finished with it, and there's no
* reason to cause large interrupt latencies while we do it.
*/
#if defined CONFIG_X86 || defined CONFIG_X86_64 || defined CONFIG_ARM || defined CONFIG_ARM64
ret = 0;
goto out;
#endif
if (!mod)
local_irq_save(flags);
ftrace_update_code(mod, start_pg);
Expand Down
14 changes: 14 additions & 0 deletions scripts/recordmcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ static uint_t *sift_rel_mcount(uint_t *mlocp,
uint_t const recval,
unsigned const reltype)
{
Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff) + (void *)ehdr);
Elf_Shdr const *const shdr = &shdr0[w(relhdr->sh_info)];
uint_t *const mloc0 = mlocp;
Elf_Rel *mrelp = *mrelpp;
Elf_Sym const *sym0;
Expand All @@ -419,6 +421,7 @@ static uint_t *sift_rel_mcount(uint_t *mlocp,
get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);

for (t = nrel; t; --t) {
int ret = -1;
if (!mcountsym)
mcountsym = get_mcountsym(sym0, relp, str0);

Expand All @@ -436,6 +439,17 @@ static uint_t *sift_rel_mcount(uint_t *mlocp,
*mlocp++ = addend;

mrelp = (Elf_Rel *)(rel_entsize + (void *)mrelp);
/* convert mcount into nop */
if (make_nop)
ret = make_nop((void *)ehdr,
_w(shdr->sh_offset) + _w(relp->r_offset));
if (!ret) {
Elf_Rel rel;
rel = *(Elf_Rel *)relp;
Elf_r_info(&rel, Elf_r_sym(relp), rel_type_nop);
ulseek(fd_map, (void *)relp - (void *)ehdr, SEEK_SET);
uwrite(fd_map, &rel, sizeof(rel));
}
}
relp = (Elf_Rel const *)(rel_entsize + (void *)relp);
}
Expand Down

0 comments on commit 54d68f2

Please sign in to comment.