Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3b623b8 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf tools: Reference count struct thread

We need to do that to stop accumulating entries in the dead_threads
linked list, i.e. we were keeping references to threads in struct hists
that continue to exist even after a thread exited and was removed from
the machine threads rbtree.

We still keep the dead_threads list, but just for debugging, allowing us
to iterate at any given point over the threads that still are referenced
by things like struct hist_entry.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
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-3ejvfyed0r7ue61dkurzjux4@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2ed11312
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -831,7 +831,7 @@ static int thread_atoms_insert(struct perf_sched *sched, struct thread *thread)
		return -1;
		return -1;
	}
	}


	atoms->thread = thread;
	atoms->thread = thread__get(thread);
	INIT_LIST_HEAD(&atoms->work_list);
	INIT_LIST_HEAD(&atoms->work_list);
	__thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid);
	__thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid);
	return 0;
	return 0;
+6 −1
Original line number Original line Diff line number Diff line
@@ -1741,7 +1741,10 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
	} else
	} else
		ttrace->entry_pending = true;
		ttrace->entry_pending = true;


	trace->current = thread;
	if (trace->current != thread) {
		thread__put(trace->current);
		trace->current = thread__get(thread);
	}


	return 0;
	return 0;
}
}
@@ -2274,6 +2277,8 @@ next_event:
	}
	}


out_disable:
out_disable:
	thread__zput(trace->current);

	perf_evlist__disable(evlist);
	perf_evlist__disable(evlist);


	if (!err) {
	if (!err) {
+3 −3
Original line number Original line Diff line number Diff line
@@ -1467,7 +1467,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
		perf_hpp__set_user_width(symbol_conf.col_width_list_str);
		perf_hpp__set_user_width(symbol_conf.col_width_list_str);


	while (1) {
	while (1) {
		const struct thread *thread = NULL;
		struct thread *thread = NULL;
		const struct dso *dso = NULL;
		const struct dso *dso = NULL;
		int choice = 0,
		int choice = 0,
		    annotate = -2, zoom_dso = -2, zoom_thread = -2,
		    annotate = -2, zoom_dso = -2, zoom_thread = -2,
@@ -1754,13 +1754,13 @@ zoom_thread:
				pstack__remove(fstack, &browser->hists->thread_filter);
				pstack__remove(fstack, &browser->hists->thread_filter);
zoom_out_thread:
zoom_out_thread:
				ui_helpline__pop();
				ui_helpline__pop();
				browser->hists->thread_filter = NULL;
				thread__zput(browser->hists->thread_filter);
				perf_hpp__set_elide(HISTC_THREAD, false);
				perf_hpp__set_elide(HISTC_THREAD, false);
			} else {
			} else {
				ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
				ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
						   thread->comm_set ? thread__comm_str(thread) : "",
						   thread->comm_set ? thread__comm_str(thread) : "",
						   thread->tid);
						   thread->tid);
				browser->hists->thread_filter = thread;
				browser->hists->thread_filter = thread__get(thread);
				perf_hpp__set_elide(HISTC_THREAD, false);
				perf_hpp__set_elide(HISTC_THREAD, false);
				pstack__push(fstack, &browser->hists->thread_filter);
				pstack__push(fstack, &browser->hists->thread_filter);
			}
			}
+3 −2
Original line number Original line Diff line number Diff line
@@ -61,8 +61,9 @@ static int perf_event__exit_del_thread(struct perf_tool *tool __maybe_unused,


	if (thread) {
	if (thread) {
		rb_erase(&thread->rb_node, &machine->threads);
		rb_erase(&thread->rb_node, &machine->threads);
		machine->last_match = NULL;
		if (machine->last_match == thread)
		thread__delete(thread);
			thread__zput(machine->last_match);
		thread__put(thread);
	}
	}


	return 0;
	return 0;
+2 −0
Original line number Original line Diff line number Diff line
@@ -355,6 +355,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template,
			callchain_init(he->callchain);
			callchain_init(he->callchain);


		INIT_LIST_HEAD(&he->pairs.node);
		INIT_LIST_HEAD(&he->pairs.node);
		thread__get(he->thread);
	}
	}


	return he;
	return he;
@@ -941,6 +942,7 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)


void hist_entry__delete(struct hist_entry *he)
void hist_entry__delete(struct hist_entry *he)
{
{
	thread__zput(he->thread);
	zfree(&he->branch_info);
	zfree(&he->branch_info);
	zfree(&he->mem_info);
	zfree(&he->mem_info);
	zfree(&he->stat_acc);
	zfree(&he->stat_acc);
Loading