Skip to content

Commit

Permalink
perf report: Add front-entry cache for lookups
Browse files Browse the repository at this point in the history
Before:

 Performance counter stats for './perf report -i perf.data.big':

     12453988058  instructions

 Performance counter stats for './perf report -i perf.data.big':

     12379566017  instructions

0.60% reduction.

Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed Jun 3, 2009
1 parent 44db76c commit eed4dcd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Documentation/perf_counter/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,30 @@ static int thread__set_comm(struct thread *self, const char *comm)
}

static struct rb_root threads;
static struct thread *last_match;

static struct thread *threads__findnew(pid_t pid)
{
struct rb_node **p = &threads.rb_node;
struct rb_node *parent = NULL;
struct thread *th;

/*
* Font-end cache - PID lookups come in blocks,
* so most of the time we dont have to look up
* the full rbtree:
*/
if (last_match && last_match->pid == pid)
return last_match;

while (*p != NULL) {
parent = *p;
th = rb_entry(parent, struct thread, rb_node);

if (th->pid == pid)
if (th->pid == pid) {
last_match = th;
return th;
}

if (pid < th->pid)
p = &(*p)->rb_left;
Expand All @@ -253,7 +264,9 @@ static struct thread *threads__findnew(pid_t pid)
if (th != NULL) {
rb_link_node(&th->rb_node, parent, p);
rb_insert_color(&th->rb_node, &threads);
last_match = th;
}

return th;
}

Expand Down

0 comments on commit eed4dcd

Please sign in to comment.