mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 15:27:29 +00:00
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime management, we need to protect access to machine->threads from concurrent access. That happens in 'perf top', where a thread processes events, inserting and deleting entries from that rb_tree while another thread decays hist_entries, that end up dropping references and ultimately deleting threads from the rb_tree and releasing its resources when no further hist_entry (or other data structures, like in 'perf sched') references it. So the rule is the same for refcounts + protected trees in the kernel, get the tree lock, find object, bump the refcount, drop the tree lock, return, use object, drop the refcount if no more use of it is needed, keep it if storing it in some other data structure, drop when releasing that data structure. I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and "perf_event__preprocess_sample(&al)" with "addr_location__put(&al)". The addr_location__put() one is because as we return references to several data structures, we may end up adding more reference counting for the other data structures and then we'll drop it at addr_location__put() time. Acked-by: David Ahern <dsahern@gmail.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
e1ed3a5b87
commit
b91fc39f4a
29 changed files with 284 additions and 114 deletions
|
@ -122,6 +122,7 @@ int db_export__machine(struct db_export *dbe, struct machine *machine)
|
|||
int db_export__thread(struct db_export *dbe, struct thread *thread,
|
||||
struct machine *machine, struct comm *comm)
|
||||
{
|
||||
struct thread *main_thread;
|
||||
u64 main_thread_db_id = 0;
|
||||
int err;
|
||||
|
||||
|
@ -131,8 +132,6 @@ int db_export__thread(struct db_export *dbe, struct thread *thread,
|
|||
thread->db_id = ++dbe->thread_last_db_id;
|
||||
|
||||
if (thread->pid_ != -1) {
|
||||
struct thread *main_thread;
|
||||
|
||||
if (thread->pid_ == thread->tid) {
|
||||
main_thread = thread;
|
||||
} else {
|
||||
|
@ -144,14 +143,16 @@ int db_export__thread(struct db_export *dbe, struct thread *thread,
|
|||
err = db_export__thread(dbe, main_thread, machine,
|
||||
comm);
|
||||
if (err)
|
||||
return err;
|
||||
goto out_put;
|
||||
if (comm) {
|
||||
err = db_export__comm_thread(dbe, comm, thread);
|
||||
if (err)
|
||||
return err;
|
||||
goto out_put;
|
||||
}
|
||||
}
|
||||
main_thread_db_id = main_thread->db_id;
|
||||
if (main_thread != thread)
|
||||
thread__put(main_thread);
|
||||
}
|
||||
|
||||
if (dbe->export_thread)
|
||||
|
@ -159,6 +160,10 @@ int db_export__thread(struct db_export *dbe, struct thread *thread,
|
|||
machine);
|
||||
|
||||
return 0;
|
||||
|
||||
out_put:
|
||||
thread__put(main_thread);
|
||||
return err;
|
||||
}
|
||||
|
||||
int db_export__comm(struct db_export *dbe, struct comm *comm,
|
||||
|
@ -303,6 +308,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
/* FIXME: check refcounting for get_main_thread, that calls machine__find_thread... */
|
||||
main_thread = get_main_thread(al->machine, thread);
|
||||
if (main_thread)
|
||||
comm = machine__thread_exec_comm(al->machine, main_thread);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue