From f8b2ebb532e0553b60ae5ad1b84d1d4f0c285752 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 19 Jul 2018 16:33:42 +0200 Subject: [PATCH] perf machine: Add threads__get_last_match function Separating threads::last_match cache read/check into separate threads__get_last_match function. This will be useful in following patch. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: David Ahern Cc: Kan Liang Cc: Lukasz Odzioba Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/20180719143345.12963-2-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 41 ++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 22dbb6612b41..df41aa1a4cf9 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -407,6 +407,30 @@ static void machine__update_thread_pid(struct machine *machine, goto out_put; } +/* + * Front-end cache - TID lookups come in blocks, + * so most of the time we dont have to look up + * the full rbtree: + */ +static struct thread* +threads__get_last_match(struct threads *threads, struct machine *machine, + int pid, int tid) +{ + struct thread *th; + + th = threads->last_match; + if (th != NULL) { + if (th->tid == tid) { + machine__update_thread_pid(machine, th, pid); + return thread__get(th); + } + + threads->last_match = NULL; + } + + return NULL; +} + /* * Caller must eventually drop thread->refcnt returned with a successful * lookup/new thread inserted. @@ -420,20 +444,9 @@ static struct thread *____machine__findnew_thread(struct machine *machine, struct rb_node *parent = NULL; struct thread *th; - /* - * Front-end cache - TID lookups come in blocks, - * so most of the time we dont have to look up - * the full rbtree: - */ - th = threads->last_match; - if (th != NULL) { - if (th->tid == tid) { - machine__update_thread_pid(machine, th, pid); - return thread__get(th); - } - - threads->last_match = NULL; - } + th = threads__get_last_match(threads, machine, pid, tid); + if (th) + return th; while (*p != NULL) { parent = *p;