Commit cddcef60 authored by Jiri Olsa's avatar Jiri Olsa

perf tools: Share map_groups among threads of the same group

Sharing map groups within all process threads. This way
there's only one copy of mmap info and it's reachable
from any thread within the process.
Original-patch-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1397490723-1992-5-git-send-email-jolsa@redhat.comSigned-off-by: default avatarJiri Olsa <jolsa@kernel.org>
parent a26ca671
...@@ -316,6 +316,17 @@ static struct thread *__machine__findnew_thread(struct machine *machine, ...@@ -316,6 +316,17 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
rb_link_node(&th->rb_node, parent, p); rb_link_node(&th->rb_node, parent, p);
rb_insert_color(&th->rb_node, &machine->threads); rb_insert_color(&th->rb_node, &machine->threads);
machine->last_match = th; machine->last_match = th;
/*
* We have to initialize map_groups separately
* after rb tree is updated.
*
* The reason is that we call machine__findnew_thread
* within thread__init_map_groups to find the thread
* leader and that would screwed the rb tree.
*/
if (thread__init_map_groups(th, machine))
return NULL;
} }
return th; return th;
......
...@@ -8,6 +8,22 @@ ...@@ -8,6 +8,22 @@
#include "debug.h" #include "debug.h"
#include "comm.h" #include "comm.h"
int thread__init_map_groups(struct thread *thread, struct machine *machine)
{
struct thread *leader;
pid_t pid = thread->pid_;
if (pid == thread->tid) {
thread->mg = map_groups__new();
} else {
leader = machine__findnew_thread(machine, pid, pid);
if (leader)
thread->mg = map_groups__get(leader->mg);
}
return thread->mg ? 0 : -1;
}
struct thread *thread__new(pid_t pid, pid_t tid) struct thread *thread__new(pid_t pid, pid_t tid)
{ {
char *comm_str; char *comm_str;
...@@ -15,10 +31,6 @@ struct thread *thread__new(pid_t pid, pid_t tid) ...@@ -15,10 +31,6 @@ struct thread *thread__new(pid_t pid, pid_t tid)
struct thread *thread = zalloc(sizeof(*thread)); struct thread *thread = zalloc(sizeof(*thread));
if (thread != NULL) { if (thread != NULL) {
thread->mg = map_groups__new();
if (thread->mg == NULL)
goto out_free;
thread->pid_ = pid; thread->pid_ = pid;
thread->tid = tid; thread->tid = tid;
thread->ppid = -1; thread->ppid = -1;
...@@ -40,8 +52,6 @@ struct thread *thread__new(pid_t pid, pid_t tid) ...@@ -40,8 +52,6 @@ struct thread *thread__new(pid_t pid, pid_t tid)
return thread; return thread;
err_thread: err_thread:
map_groups__delete(thread->mg);
out_free:
free(thread); free(thread);
return NULL; return NULL;
} }
...@@ -126,9 +136,26 @@ void thread__insert_map(struct thread *thread, struct map *map) ...@@ -126,9 +136,26 @@ void thread__insert_map(struct thread *thread, struct map *map)
map_groups__insert(thread->mg, map); map_groups__insert(thread->mg, map);
} }
static int thread__clone_map_groups(struct thread *thread,
struct thread *parent)
{
int i;
/* This is new thread, we share map groups for process. */
if (thread->pid_ == parent->pid_)
return 0;
/* But this one is new process, copy maps. */
for (i = 0; i < MAP__NR_TYPES; ++i)
if (map_groups__clone(thread->mg, parent->mg, i) < 0)
return -ENOMEM;
return 0;
}
int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp) int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp)
{ {
int i, err; int err;
if (parent->comm_set) { if (parent->comm_set) {
const char *comm = thread__comm_str(parent); const char *comm = thread__comm_str(parent);
...@@ -140,13 +167,8 @@ int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp) ...@@ -140,13 +167,8 @@ int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp)
thread->comm_set = true; thread->comm_set = true;
} }
for (i = 0; i < MAP__NR_TYPES; ++i)
if (map_groups__clone(thread->mg, parent->mg, i) < 0)
return -ENOMEM;
thread->ppid = parent->tid; thread->ppid = parent->tid;
return thread__clone_map_groups(thread, parent);
return 0;
} }
void thread__find_cpumode_addr_location(struct thread *thread, void thread__find_cpumode_addr_location(struct thread *thread,
......
...@@ -30,6 +30,7 @@ struct machine; ...@@ -30,6 +30,7 @@ struct machine;
struct comm; struct comm;
struct thread *thread__new(pid_t pid, pid_t tid); struct thread *thread__new(pid_t pid, pid_t tid);
int thread__init_map_groups(struct thread *thread, struct machine *machine);
void thread__delete(struct thread *thread); void thread__delete(struct thread *thread);
static inline void thread__exited(struct thread *thread) static inline void thread__exited(struct thread *thread)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment