Commit 9fd49328fc2a1cbfea542bcbcf004b5c81dc495b

Authored by Steven Rostedt
Committed by Steven Rostedt
1 parent 71babb2705

ftrace: Sort all function addresses, not just per page

Instead of just sorting the ip's of the functions per ftrace page,
sort the entire list before adding them to the ftrace pages.

This will allow the bsearch algorithm to be sped up as it can
also sort by pages, not just records within a page.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Showing 2 changed files with 23 additions and 13 deletions Side-by-side Diff

include/asm-generic/vmlinux.lds.h
... ... @@ -486,8 +486,8 @@
486 486 CPU_DISCARD(init.data) \
487 487 MEM_DISCARD(init.data) \
488 488 KERNEL_CTORS() \
489   - *(.init.rodata) \
490 489 MCOUNT_REC() \
  490 + *(.init.rodata) \
491 491 FTRACE_EVENTS() \
492 492 TRACE_SYSCALLS() \
493 493 DEV_DISCARD(init.rodata) \
kernel/trace/ftrace.c
... ... @@ -3666,17 +3666,29 @@
3666 3666 return 0;
3667 3667 }
3668 3668  
3669   -static void ftrace_swap_recs(void *a, void *b, int size)
  3669 +static int ftrace_cmp_ips(const void *a, const void *b)
3670 3670 {
3671   - struct dyn_ftrace *reca = a;
3672   - struct dyn_ftrace *recb = b;
3673   - struct dyn_ftrace t;
  3671 + const unsigned long *ipa = a;
  3672 + const unsigned long *ipb = b;
3674 3673  
3675   - t = *reca;
3676   - *reca = *recb;
3677   - *recb = t;
  3674 + if (*ipa > *ipb)
  3675 + return 1;
  3676 + if (*ipa < *ipb)
  3677 + return -1;
  3678 + return 0;
3678 3679 }
3679 3680  
  3681 +static void ftrace_swap_ips(void *a, void *b, int size)
  3682 +{
  3683 + unsigned long *ipa = a;
  3684 + unsigned long *ipb = b;
  3685 + unsigned long t;
  3686 +
  3687 + t = *ipa;
  3688 + *ipa = *ipb;
  3689 + *ipb = t;
  3690 +}
  3691 +
3680 3692 static int ftrace_process_locs(struct module *mod,
3681 3693 unsigned long *start,
3682 3694 unsigned long *end)
... ... @@ -3693,6 +3705,9 @@
3693 3705 if (!count)
3694 3706 return 0;
3695 3707  
  3708 + sort(start, count, sizeof(*start),
  3709 + ftrace_cmp_ips, ftrace_swap_ips);
  3710 +
3696 3711 pg = ftrace_allocate_pages(count);
3697 3712 if (!pg)
3698 3713 return -ENOMEM;
... ... @@ -3739,11 +3754,6 @@
3739 3754  
3740 3755 /* These new locations need to be initialized */
3741 3756 ftrace_new_pgs = pg;
3742   -
3743   - /* Make each individual set of pages sorted by ips */
3744   - for (; pg; pg = pg->next)
3745   - sort(pg->records, pg->index, sizeof(struct dyn_ftrace),
3746   - ftrace_cmp_recs, ftrace_swap_recs);
3747 3757  
3748 3758 /*
3749 3759 * We only need to disable interrupts on start up