perf machine: Add threads__get_last_match function
authorJiri Olsa <jolsa@kernel.org>
Thu, 19 Jul 2018 14:33:42 +0000 (16:33 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 24 Jul 2018 17:53:31 +0000 (14:53 -0300)
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 <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Lukasz Odzioba <lukasz.odzioba@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20180719143345.12963-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/machine.c

index 22dbb6612b4123773ba29cc823788f74a4cb5753..df41aa1a4cf905d54d403f7bd71487974b996559 100644 (file)
@@ -408,23 +408,16 @@ out_err:
 }
 
 /*
- * Caller must eventually drop thread->refcnt returned with a successful
- * lookup/new thread inserted.
+ * 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 *____machine__findnew_thread(struct machine *machine,
-                                                 struct threads *threads,
-                                                 pid_t pid, pid_t tid,
-                                                 bool create)
+static struct thread*
+threads__get_last_match(struct threads *threads, struct machine *machine,
+                       int pid, int tid)
 {
-       struct rb_node **p = &threads->entries.rb_node;
-       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) {
@@ -435,6 +428,26 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
                threads->last_match = NULL;
        }
 
+       return NULL;
+}
+
+/*
+ * Caller must eventually drop thread->refcnt returned with a successful
+ * lookup/new thread inserted.
+ */
+static struct thread *____machine__findnew_thread(struct machine *machine,
+                                                 struct threads *threads,
+                                                 pid_t pid, pid_t tid,
+                                                 bool create)
+{
+       struct rb_node **p = &threads->entries.rb_node;
+       struct rb_node *parent = NULL;
+       struct thread *th;
+
+       th = threads__get_last_match(threads, machine, pid, tid);
+       if (th)
+               return th;
+
        while (*p != NULL) {
                parent = *p;
                th = rb_entry(parent, struct thread, rb_node);