linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Ian Rogers <irogers@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Nick Terrell <terrelln@fb.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>, Kajol Jain <kjain@linux.ibm.com>,
	Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
	Huacai Chen <chenhuacai@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	"Steinar H. Gunderson" <sesse@google.com>,
	Liam Howlett <liam.howlett@oracle.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Colin Ian King <colin.i.king@gmail.com>,
	Dmitrii Dolgov <9erthalion6@gmail.com>,
	Yang Jihong <yangjihong1@huawei.com>,
	Ming Wang <wangming01@loongson.cn>,
	James Clark <james.clark@arm.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Sean Christopherson <seanjc@google.com>,
	Leo Yan <leo.yan@linaro.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	German Gomez <german.gomez@arm.com>,
	Changbin Du <changbin.du@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Li Dong <lidong@vivo.com>,
	Sandipan Das <sandipan.das@amd.com>,
	liuwenyu <liuwenyu7@huawei.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v4 05/53] perf machine thread: Remove exited threads by default
Date: Mon, 6 Nov 2023 13:28:43 +0200	[thread overview]
Message-ID: <371634c4-756a-498c-a46d-7459a07075e0@intel.com> (raw)
In-Reply-To: <20231102175735.2272696-6-irogers@google.com>

On 2/11/23 19:56, Ian Rogers wrote:
> struct thread values hold onto references to mmaps, dsos, etc. When a
> thread exits it is necessary to clean all of this memory up by
> removing the thread from the machine's threads. Some tools require
> this doesn't happen, such as auxtrace events, perf report if offcpu
> events exist or if a task list is being generated, so add a
> symbol_conf value to make the behavior optional. When an exited thread
> is left in the machine's threads, mark it as exited.
> 
> This change relates to commit 40826c45eb0b ("perf thread: Remove
> notion of dead threads"). Dead threads were removed as they had a
> reference count of 0 and were difficult to reason about with the
> reference count checker. Here a thread is removed from threads when it
> exits, unless via symbol_conf the exited thread isn't remove and is
> marked as exited. Reference counting behaves as it normally does.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>

For auxtrace:

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/builtin-report.c   |  7 +++++++
>  tools/perf/util/machine.c     | 10 +++++++---
>  tools/perf/util/session.c     |  5 +++++
>  tools/perf/util/symbol_conf.h |  3 ++-
>  tools/perf/util/thread.h      | 14 ++++++++++++++
>  5 files changed, 35 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 9cb1da2dc0c0..121a2781323c 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -1426,6 +1426,13 @@ int cmd_report(int argc, const char **argv)
>  	if (ret < 0)
>  		goto exit;
>  
> +	/*
> +	 * tasks_mode require access to exited threads to list those that are in
> +	 * the data file. Off-cpu events are synthesized after other events and
> +	 * reference exited threads.
> +	 */
> +	symbol_conf.keep_exited_threads = true;
> +
>  	annotation_options__init(&report.annotation_opts);
>  
>  	ret = perf_config(report__config, &report);
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 90c750150b19..a985d004aa8d 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2157,9 +2157,13 @@ int machine__process_exit_event(struct machine *machine, union perf_event *event
>  	if (dump_trace)
>  		perf_event__fprintf_task(event, stdout);
>  
> -	if (thread != NULL)
> -		thread__put(thread);
> -
> +	if (thread != NULL) {
> +		if (symbol_conf.keep_exited_threads)
> +			thread__set_exited(thread, /*exited=*/true);
> +		else
> +			machine__remove_thread(machine, thread);
> +	}
> +	thread__put(thread);
>  	return 0;
>  }
>  
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 1e9aa8ed15b6..c6afba7ab1a5 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -115,6 +115,11 @@ static int perf_session__open(struct perf_session *session, int repipe_fd)
>  		return -1;
>  	}
>  
> +	if (perf_header__has_feat(&session->header, HEADER_AUXTRACE)) {
> +		/* Auxiliary events may reference exited threads, hold onto dead ones. */
> +		symbol_conf.keep_exited_threads = true;
> +	}
> +
>  	if (perf_data__is_pipe(data))
>  		return 0;
>  
> diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
> index 2b2fb9e224b0..6040286e07a6 100644
> --- a/tools/perf/util/symbol_conf.h
> +++ b/tools/perf/util/symbol_conf.h
> @@ -43,7 +43,8 @@ struct symbol_conf {
>  			disable_add2line_warn,
>  			buildid_mmap2,
>  			guest_code,
> -			lazy_load_kernel_maps;
> +			lazy_load_kernel_maps,
> +			keep_exited_threads;
>  	const char	*vmlinux_name,
>  			*kallsyms_name,
>  			*source_prefix,
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index e79225a0ea46..0df775b5c110 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -36,13 +36,22 @@ struct thread_rb_node {
>  };
>  
>  DECLARE_RC_STRUCT(thread) {
> +	/** @maps: mmaps associated with this thread. */
>  	struct maps		*maps;
>  	pid_t			pid_; /* Not all tools update this */
> +	/** @tid: thread ID number unique to a machine. */
>  	pid_t			tid;
> +	/** @ppid: parent process of the process this thread belongs to. */
>  	pid_t			ppid;
>  	int			cpu;
>  	int			guest_cpu; /* For QEMU thread */
>  	refcount_t		refcnt;
> +	/**
> +	 * @exited: Has the thread had an exit event. Such threads are usually
> +	 * removed from the machine's threads but some events/tools require
> +	 * access to dead threads.
> +	 */
> +	bool			exited;
>  	bool			comm_set;
>  	int			comm_len;
>  	struct list_head	namespaces_list;
> @@ -189,6 +198,11 @@ static inline refcount_t *thread__refcnt(struct thread *thread)
>  	return &RC_CHK_ACCESS(thread)->refcnt;
>  }
>  
> +static inline void thread__set_exited(struct thread *thread, bool exited)
> +{
> +	RC_CHK_ACCESS(thread)->exited = exited;
> +}
> +
>  static inline bool thread__comm_set(const struct thread *thread)
>  {
>  	return RC_CHK_ACCESS(thread)->comm_set;


  reply	other threads:[~2023-11-06 11:28 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02 17:56 [PATCH v4 00/53] Improvements to memory use Ian Rogers
2023-11-02 17:56 ` [PATCH v4 01/53] perf comm: Use regular mutex Ian Rogers
2023-11-05 17:31   ` Namhyung Kim
2023-11-05 21:35     ` Ian Rogers
2023-11-06  3:58       ` Namhyung Kim
2023-11-27 18:59         ` Ian Rogers
2023-11-27 21:53     ` Arnaldo Carvalho de Melo
2023-11-28  0:48       ` Arnaldo Carvalho de Melo
2023-11-02 17:56 ` [PATCH v4 02/53] perf record: Lazy load kernel symbols Ian Rogers
2023-11-05 17:34   ` Namhyung Kim
2023-11-06 11:00   ` Adrian Hunter
2023-11-08 16:01     ` Arnaldo Carvalho de Melo
2023-11-02 17:56 ` [PATCH v4 03/53] libperf: Lazily allocate mmap event copy Ian Rogers
2023-11-03  8:32   ` Guilherme Amadio
2023-11-03 15:48     ` Ian Rogers
2023-11-05 18:12       ` Namhyung Kim
2023-11-27 19:28         ` Ian Rogers
2023-11-02 17:56 ` [PATCH v4 04/53] perf mmap: Lazily initialize zstd streams Ian Rogers
2023-11-27 22:00   ` Arnaldo Carvalho de Melo
2023-11-28 17:14     ` Arnaldo Carvalho de Melo
2023-11-28 17:38       ` Arnaldo Carvalho de Melo
2023-11-28 17:55         ` Ian Rogers
2023-11-28 20:29           ` Arnaldo Carvalho de Melo
2023-11-02 17:56 ` [PATCH v4 05/53] perf machine thread: Remove exited threads by default Ian Rogers
2023-11-06 11:28   ` Adrian Hunter [this message]
2023-11-08 16:04     ` Arnaldo Carvalho de Melo
2023-11-02 17:56 ` [PATCH v4 06/53] tools api fs: Switch filename__read_str to use io.h Ian Rogers
2023-11-06  3:53   ` Namhyung Kim
2023-11-27 20:26     ` Ian Rogers
2023-11-02 17:56 ` [PATCH v4 07/53] tools api fs: Avoid reading whole file for a 1 byte bool Ian Rogers
2023-11-06  3:55   ` Namhyung Kim
2023-11-27 20:41     ` Ian Rogers
2023-11-02 17:56 ` [PATCH v4 08/53] tools lib api: Add io_dir an allocation free readdir alternative Ian Rogers
2023-11-02 17:56 ` [PATCH v4 09/53] perf maps: Switch modules tree walk to io_dir__readdir Ian Rogers
2023-11-02 17:56 ` [PATCH v4 10/53] perf record: Be lazier in allocating lost samples buffer Ian Rogers
2023-11-27 22:03   ` Arnaldo Carvalho de Melo
2023-11-27 22:23     ` Ian Rogers
2023-11-02 17:56 ` [PATCH v4 11/53] perf pmu: Switch to io_dir__readdir Ian Rogers
2023-11-02 17:56 ` [PATCH v4 12/53] perf bpf: Don't synthesize BPF events when disabled Ian Rogers
2023-11-08 16:14   ` Arnaldo Carvalho de Melo
2023-11-08 23:03     ` Song Liu
2023-11-09 16:10       ` Arnaldo Carvalho de Melo
2023-11-02 17:56 ` [PATCH v4 13/53] perf header: Switch mem topology to io_dir__readdir Ian Rogers
2023-11-02 17:56 ` [PATCH v4 14/53] perf events: Remove scandir in thread synthesis Ian Rogers
2023-11-02 17:56 ` [PATCH v4 15/53] perf map: Simplify map_ip/unmap_ip and make map size smaller Ian Rogers
2023-11-02 17:56 ` [PATCH v4 16/53] perf maps: Move symbol maps functions to maps.c Ian Rogers
2023-11-02 17:56 ` [PATCH v4 17/53] perf thread: Add missing RC_CHK_EQUAL Ian Rogers
2023-11-02 17:57 ` [PATCH v4 18/53] perf maps: Add maps__for_each_map to call a function on each entry Ian Rogers
2023-11-02 17:57 ` [PATCH v4 19/53] perf maps: Add remove maps function to remove a map based on callback Ian Rogers
2023-11-02 17:57 ` [PATCH v4 20/53] perf debug: Expose debug file Ian Rogers
2023-11-02 17:57 ` [PATCH v4 21/53] perf maps: Refactor maps__fixup_overlappings Ian Rogers
2023-11-02 17:57 ` [PATCH v4 22/53] perf maps: Do simple merge if given map doesn't overlap Ian Rogers
2023-11-02 17:57 ` [PATCH v4 23/53] perf maps: Rename clone to copy from Ian Rogers
2023-11-02 17:57 ` [PATCH v4 24/53] perf maps: Add maps__load_first Ian Rogers
2023-11-02 17:57 ` [PATCH v4 25/53] perf maps: Add find next entry to give entry after the given map Ian Rogers
2023-11-02 17:57 ` [PATCH v4 26/53] perf maps: Reduce scope of map_rb_node and maps internals Ian Rogers
2023-11-02 17:57 ` [PATCH v4 27/53] perf maps: Fix up overlaps during fixup_end Ian Rogers
2023-11-02 17:57 ` [PATCH v4 28/53] perf maps: Switch from rbtree to lazily sorted array for addresses Ian Rogers
2023-11-02 17:57 ` [PATCH v4 29/53] perf maps: Get map before returning in maps__find Ian Rogers
2023-11-02 17:57 ` [PATCH v4 30/53] perf maps: Get map before returning in maps__find_by_name Ian Rogers
2023-11-02 17:57 ` [PATCH v4 31/53] perf maps: Get map before returning in maps__find_next_entry Ian Rogers
2023-11-02 17:57 ` [PATCH v4 32/53] perf maps: Hide maps internals Ian Rogers
2023-11-02 17:57 ` [PATCH v4 33/53] perf maps: Locking tidy up of nr_maps Ian Rogers
2023-11-02 17:57 ` [PATCH v4 34/53] perf dso: Reorder variables to save space in struct dso Ian Rogers
2023-11-02 17:57 ` [PATCH v4 35/53] perf report: Sort child tasks by tid Ian Rogers
2023-11-02 17:57 ` [PATCH v4 36/53] perf trace: Ignore thread hashing in summary Ian Rogers
2023-11-02 17:57 ` [PATCH v4 37/53] perf machine: Move fprintf to for_each loop and a callback Ian Rogers
2023-11-02 17:57 ` [PATCH v4 38/53] perf threads: Move threads to its own files Ian Rogers
2023-11-02 17:57 ` [PATCH v4 39/53] perf threads: Switch from rbtree to hashmap Ian Rogers
2023-11-02 17:57 ` [PATCH v4 40/53] perf threads: Reduce table size from 256 to 8 Ian Rogers
2023-11-02 17:57 ` [PATCH v4 41/53] perf dsos: Attempt to better abstract dsos internals Ian Rogers
2023-11-02 17:57 ` [PATCH v4 42/53] perf dsos: Tidy reference counting and locking Ian Rogers
2023-11-02 17:57 ` [PATCH v4 43/53] perf dsos: Add dsos__for_each_dso Ian Rogers
2023-11-02 17:57 ` [PATCH v4 44/53] perf dso: Move dso functions out of dsos Ian Rogers
2023-11-02 17:57 ` [PATCH v4 45/53] perf dsos: Switch more loops to dsos__for_each_dso Ian Rogers
2023-11-02 17:57 ` [PATCH v4 46/53] perf dsos: Switch backing storage to array from rbtree/list Ian Rogers
2023-11-02 17:57 ` [PATCH v4 47/53] perf dsos: Remove __dsos__addnew Ian Rogers
2023-11-02 17:57 ` [PATCH v4 48/53] perf dsos: Remove __dsos__findnew_link_by_longname_id Ian Rogers
2023-11-02 17:57 ` [PATCH v4 49/53] perf dsos: Switch hand code to bsearch Ian Rogers
2023-11-02 17:57 ` [PATCH v4 50/53] perf dso: Add reference count checking and accessor functions Ian Rogers
2023-11-02 17:57 ` [PATCH v4 51/53] perf dso: Reference counting related fixes Ian Rogers
2023-11-02 17:57 ` [PATCH v4 52/53] perf dso: Use container_of to avoid a pointer in dso_data Ian Rogers
2023-11-02 17:57 ` [PATCH v4 53/53] perf env: Avoid recursively taking env->bpf_progs.lock Ian Rogers

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=371634c4-756a-498c-a46d-7459a07075e0@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=9erthalion6@gmail.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=changbin.du@huawei.com \
    --cc=chenhuacai@kernel.org \
    --cc=colin.i.king@gmail.com \
    --cc=german.gomez@arm.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kjain@linux.ibm.com \
    --cc=kprateek.nayak@amd.com \
    --cc=leo.yan@linaro.org \
    --cc=liam.howlett@oracle.com \
    --cc=lidong@vivo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=liuwenyu7@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=sandipan.das@amd.com \
    --cc=seanjc@google.com \
    --cc=sesse@google.com \
    --cc=terrelln@fb.com \
    --cc=vincent.whitchurch@axis.com \
    --cc=wangming01@loongson.cn \
    --cc=yangjihong1@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).