From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
David Ahern <dsahern@gmail.com>,
Stephane Eranian <eranian@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Andi Kleen <andi@firstfloor.org>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 14/37] perf tools: Convert dead thread list into rbtree
Date: Wed, 24 Dec 2014 16:15:10 +0900 [thread overview]
Message-ID: <1419405333-27952-15-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1419405333-27952-1-git-send-email-namhyung@kernel.org>
Currently perf maintains dead threads in a linked list but this can be
a problem if someone needs to search from it. Convert it to a rbtree
like normal threads and it'll be used later with multi-file changes.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/machine.c | 59 +++++++++++++++++++++++++++++++++++++++--------
tools/perf/util/machine.h | 2 +-
tools/perf/util/thread.c | 1 +
tools/perf/util/thread.h | 11 ++++-----
4 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 15dd0a9691ce..582e011adc92 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -28,7 +28,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
dsos__init(&machine->kernel_dsos);
machine->threads = RB_ROOT;
- INIT_LIST_HEAD(&machine->dead_threads);
+ machine->dead_threads = RB_ROOT;
machine->last_match = NULL;
machine->vdso_info = NULL;
@@ -91,10 +91,21 @@ static void dsos__delete(struct dsos *dsos)
void machine__delete_dead_threads(struct machine *machine)
{
- struct thread *n, *t;
+ struct rb_node *nd = rb_first(&machine->dead_threads);
+
+ while (nd) {
+ struct thread *t = rb_entry(nd, struct thread, rb_node);
+ struct thread *pos;
+
+ nd = rb_next(nd);
+ rb_erase(&t->rb_node, &machine->dead_threads);
+
+ while (!list_empty(&t->node)) {
+ pos = list_first_entry(&t->node, struct thread, node);
+ list_del(&pos->node);
+ thread__delete(pos);
+ }
- list_for_each_entry_safe(t, n, &machine->dead_threads, node) {
- list_del(&t->node);
thread__delete(t);
}
}
@@ -106,8 +117,8 @@ void machine__delete_threads(struct machine *machine)
while (nd) {
struct thread *t = rb_entry(nd, struct thread, rb_node);
- rb_erase(&t->rb_node, &machine->threads);
nd = rb_next(nd);
+ rb_erase(&t->rb_node, &machine->threads);
thread__delete(t);
}
}
@@ -1236,13 +1247,36 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
static void machine__remove_thread(struct machine *machine, struct thread *th)
{
+ struct rb_node **p = &machine->dead_threads.rb_node;
+ struct rb_node *parent = NULL;
+ struct thread *pos;
+
machine->last_match = NULL;
rb_erase(&th->rb_node, &machine->threads);
+
+ th->dead = true;
+
/*
* We may have references to this thread, for instance in some hist_entry
- * instances, so just move them to a separate list.
+ * instances, so just move them to a separate list in rbtree.
*/
- list_add_tail(&th->node, &machine->dead_threads);
+ while (*p != NULL) {
+ parent = *p;
+ pos = rb_entry(parent, struct thread, rb_node);
+
+ if (pos->tid == th->tid) {
+ list_add_tail(&th->node, &pos->node);
+ return;
+ }
+
+ if (th->tid < pos->tid)
+ p = &(*p)->rb_left;
+ else
+ p = &(*p)->rb_right;
+ }
+
+ rb_link_node(&th->rb_node, parent, p);
+ rb_insert_color(&th->rb_node, &machine->dead_threads);
}
int machine__process_fork_event(struct machine *machine, union perf_event *event,
@@ -1649,7 +1683,7 @@ int machine__for_each_thread(struct machine *machine,
void *priv)
{
struct rb_node *nd;
- struct thread *thread;
+ struct thread *thread, *pos;
int rc = 0;
for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
@@ -1659,10 +1693,17 @@ int machine__for_each_thread(struct machine *machine,
return rc;
}
- list_for_each_entry(thread, &machine->dead_threads, node) {
+ for (nd = rb_first(&machine->dead_threads); nd; nd = rb_next(nd)) {
+ thread = rb_entry(nd, struct thread, rb_node);
rc = fn(thread, priv);
if (rc != 0)
return rc;
+
+ list_for_each_entry(pos, &thread->node, node) {
+ rc = fn(pos, priv);
+ if (rc != 0)
+ return rc;
+ }
}
return rc;
}
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index e8b7779a0a3f..4349946a38ff 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -30,7 +30,7 @@ struct machine {
bool comm_exec;
char *root_dir;
struct rb_root threads;
- struct list_head dead_threads;
+ struct rb_root dead_threads;
struct thread *last_match;
struct vdso_info *vdso_info;
struct dsos user_dsos;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 083fa0fcf316..b9c5c5d5e718 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -38,6 +38,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
thread->ppid = -1;
thread->cpu = -1;
INIT_LIST_HEAD(&thread->comm_list);
+ INIT_LIST_HEAD(&thread->node);
if (unwind__prepare_access(thread) < 0)
goto err_thread;
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 0b6dcd70bc8b..413f28cf689b 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -11,10 +11,8 @@
struct thread_stack;
struct thread {
- union {
- struct rb_node rb_node;
- struct list_head node;
- };
+ struct rb_node rb_node;
+ struct list_head node;
struct map_groups *mg;
pid_t pid_; /* Not all tools update this */
pid_t tid;
@@ -22,7 +20,8 @@ struct thread {
int cpu;
char shortname[3];
bool comm_set;
- bool dead; /* if set thread has exited */
+ bool exited; /* if set thread has exited */
+ bool dead; /* thread is in dead_threads list */
struct list_head comm_list;
int comm_len;
u64 db_id;
@@ -39,7 +38,7 @@ int thread__init_map_groups(struct thread *thread, struct machine *machine);
void thread__delete(struct thread *thread);
static inline void thread__exited(struct thread *thread)
{
- thread->dead = true;
+ thread->exited = true;
}
int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
--
2.1.3
next prev parent reply other threads:[~2014-12-24 7:22 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-24 7:14 [RFC/PATCHSET 00/37] perf tools: Speed-up perf report by using multi thread (v1) Namhyung Kim
2014-12-24 7:14 ` [PATCH 01/37] perf tools: Set attr.task bit for a tracking event Namhyung Kim
2014-12-31 11:25 ` Jiri Olsa
2014-12-24 7:14 ` [PATCH 02/37] perf record: Use a software dummy event to track task/mmap events Namhyung Kim
2014-12-26 16:27 ` David Ahern
2014-12-27 5:28 ` Namhyung Kim
2014-12-29 12:58 ` Adrian Hunter
2014-12-30 5:51 ` Namhyung Kim
2014-12-30 9:04 ` Adrian Hunter
2014-12-24 7:14 ` [PATCH 03/37] perf tools: Use perf_data_file__fd() consistently Namhyung Kim
2014-12-26 16:30 ` David Ahern
2014-12-27 5:30 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 04/37] perf tools: Add multi file interface to perf_data_file Namhyung Kim
2014-12-25 22:08 ` Jiri Olsa
2014-12-26 1:19 ` Namhyung Kim
2014-12-31 11:26 ` Jiri Olsa
2014-12-31 14:55 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 05/37] perf tools: Create separate mmap for dummy tracking event Namhyung Kim
2014-12-25 22:08 ` Jiri Olsa
2014-12-26 1:45 ` Namhyung Kim
2014-12-25 22:09 ` Jiri Olsa
2014-12-26 1:55 ` Namhyung Kim
2014-12-26 16:51 ` David Ahern
2014-12-27 5:32 ` Namhyung Kim
2014-12-29 13:44 ` Adrian Hunter
2014-12-30 5:57 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 06/37] perf tools: Introduce perf_evlist__mmap_multi() Namhyung Kim
2014-12-24 7:15 ` [PATCH 07/37] perf tools: Do not use __perf_session__process_events() directly Namhyung Kim
2014-12-31 11:33 ` Jiri Olsa
2014-12-24 7:15 ` [PATCH 08/37] perf tools: Handle multi-file session properly Namhyung Kim
2014-12-31 12:01 ` Jiri Olsa
2014-12-31 14:53 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 09/37] perf record: Add -M/--multi option for multi file recording Namhyung Kim
2014-12-24 7:15 ` [PATCH 10/37] perf report: Skip dummy tracking event Namhyung Kim
2014-12-24 7:15 ` [PATCH 11/37] perf tools: Introduce thread__comm_time() helpers Namhyung Kim
2014-12-26 17:00 ` David Ahern
2014-12-27 5:36 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 12/37] perf tools: Add a test case for thread comm handling Namhyung Kim
2014-12-24 7:15 ` [PATCH 13/37] perf tools: Use thread__comm_time() when adding hist entries Namhyung Kim
2014-12-25 22:53 ` Jiri Olsa
2014-12-26 2:10 ` Namhyung Kim
2014-12-24 7:15 ` Namhyung Kim [this message]
2014-12-25 23:05 ` [PATCH 14/37] perf tools: Convert dead thread list into rbtree Jiri Olsa
2014-12-26 2:26 ` Namhyung Kim
2014-12-26 17:14 ` David Ahern
2014-12-27 5:42 ` Namhyung Kim
2014-12-27 15:31 ` David Ahern
2014-12-28 13:24 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 15/37] perf tools: Introduce machine__find*_thread_time() Namhyung Kim
2014-12-27 16:33 ` David Ahern
2014-12-28 14:50 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 16/37] perf tools: Add a test case for timed thread handling Namhyung Kim
2014-12-31 14:17 ` Jiri Olsa
2014-12-31 15:32 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 17/37] perf tools: Maintain map groups list in a leader thread Namhyung Kim
2014-12-24 7:15 ` [PATCH 18/37] perf tools: Remove thread when map groups initialization failed Namhyung Kim
2014-12-28 0:45 ` David Ahern
2014-12-29 7:08 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 19/37] perf tools: Introduce thread__find_addr_location_time() and friends Namhyung Kim
2014-12-24 7:15 ` [PATCH 20/37] perf tools: Add a test case for timed map groups handling Namhyung Kim
2014-12-24 7:15 ` [PATCH 21/37] perf tools: Protect dso symbol loading using a mutex Namhyung Kim
2014-12-24 7:15 ` [PATCH 22/37] perf tools: Protect dso cache tree using dso->lock Namhyung Kim
2014-12-24 7:15 ` [PATCH 23/37] perf tools: Protect dso cache fd with a mutex Namhyung Kim
2014-12-24 7:15 ` [PATCH 24/37] perf session: Pass struct events stats to event processing functions Namhyung Kim
2014-12-24 7:15 ` [PATCH 25/37] perf hists: Pass hists struct to hist_entry_iter functions Namhyung Kim
2014-12-24 7:15 ` [PATCH 26/37] perf tools: Move BUILD_ID_SIZE definition to perf.h Namhyung Kim
2014-12-24 7:15 ` [PATCH 27/37] perf report: Parallelize perf report using multi-thread Namhyung Kim
2014-12-24 7:15 ` [PATCH 28/37] perf tools: Add missing_threads rb tree Namhyung Kim
2014-12-24 7:15 ` [PATCH 29/37] perf top: Always creates thread in the current task tree Namhyung Kim
2014-12-24 7:15 ` [PATCH 30/37] perf tools: Fix progress ui to support multi thread Namhyung Kim
2014-12-24 7:15 ` [PATCH 31/37] perf record: Show total size of multi file data Namhyung Kim
2014-12-24 7:15 ` [PATCH 32/37] perf report: Add --multi-thread option and config item Namhyung Kim
2014-12-24 7:15 ` [PATCH 33/37] perf tools: Add front cache for dso data access Namhyung Kim
2014-12-24 7:15 ` [PATCH 34/37] perf tools: Convert lseek + read to pread Namhyung Kim
2014-12-24 7:15 ` [PATCH 35/37] perf callchain: Save eh/debug frame offset for dwarf unwind Namhyung Kim
2014-12-24 7:15 ` [PATCH 36/37] perf tools: Add new perf data command Namhyung Kim
2014-12-24 7:15 ` [PATCH 37/37] perf data: Implement 'split' subcommand Namhyung Kim
2014-12-24 13:51 ` Arnaldo Carvalho de Melo
2014-12-24 14:14 ` Namhyung Kim
2014-12-24 14:45 ` Arnaldo Carvalho de Melo
2014-12-26 13:59 ` Jiri Olsa
2014-12-27 5:21 ` Namhyung Kim
2014-12-26 14:02 ` [RFC/PATCHSET 00/37] perf tools: Speed-up perf report by using multi thread (v1) Jiri Olsa
2014-12-27 5:23 ` Namhyung Kim
2015-01-05 18:48 ` Andi Kleen
2015-01-06 15:50 ` Stephane Eranian
2015-01-07 7:13 ` Namhyung Kim
2015-01-07 15:14 ` Stephane Eranian
2015-01-08 5:19 ` Namhyung Kim
2015-01-07 6:58 ` Namhyung Kim
2015-01-08 14:52 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1419405333-27952-15-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=andi@firstfloor.org \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®