From: Jiri Olsa <jolsa@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>,
Stephane Eranian <eranian@google.com>,
Andi Kleen <ak@linux.intel.com>, Ian Rogers <irogers@google.com>
Subject: Re: [PATCH 1/3] perf tools: Use /proc/<PID>/task/<TID>/status for synthesis
Date: Mon, 1 Feb 2021 00:00:29 +0100 [thread overview]
Message-ID: <YBc2jfTDcBjcL5kN@krava> (raw)
In-Reply-To: <20210129054901.1705483-2-namhyung@kernel.org>
On Fri, Jan 29, 2021 at 02:48:59PM +0900, Namhyung Kim wrote:
> To save memory usage, it needs to reduce number of entries in the proc
> filesystem. It's using /proc/<PID>/task directory to traverse threads
> in the process and then kernel creates /proc/<PID>/task/<TID> entries.
>
> After that it checks the thread info using the /proc/<TID>/status file
> rather than /proc/<PID>/task/<TID>/status. As far as I can see, they
> are the same and contain all the info we need.
>
> Using the latter eliminates the unnecessary /proc/<TID> entry. This
> can be useful especially a large number of threads are used in the
> system. In my experiment around 1KB of memory on average was saved
> for each thread (which is not a thread group leader).
>
> To do this, pass both pid and tid to perf_event_prepare_comm() if it
> knows them. In case it doesn't know, passing 0 as pid will do the old
> way.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/synthetic-events.c | 30 +++++++++++++++++++-----------
> 1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index 3a898520f05c..800522591dde 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -69,7 +69,7 @@ int perf_tool__process_synth_event(struct perf_tool *tool,
> * Assumes that the first 4095 bytes of /proc/pid/stat contains
> * the comm, tgid and ppid.
> */
> -static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
> +static int perf_event__get_comm_ids(pid_t pid, pid_t tid, char *comm, size_t len,
> pid_t *tgid, pid_t *ppid)
> {
> char bf[4096];
> @@ -81,7 +81,10 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
> *tgid = -1;
> *ppid = -1;
>
> - snprintf(bf, sizeof(bf), "/proc/%d/status", pid);
> + if (pid)
> + snprintf(bf, sizeof(bf), "/proc/%d/task/%d/status", pid, tid);
> + else
> + snprintf(bf, sizeof(bf), "/proc/%d/status", tid);
>
> fd = open(bf, O_RDONLY);
> if (fd < 0) {
> @@ -93,7 +96,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
> close(fd);
> if (n <= 0) {
> pr_warning("Couldn't get COMM, tigd and ppid for pid %d\n",
> - pid);
> + tid);
> return -1;
> }
> bf[n] = '\0';
> @@ -116,27 +119,32 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
> memcpy(comm, name, size);
> comm[size] = '\0';
> } else {
> - pr_debug("Name: string not found for pid %d\n", pid);
> + pr_debug("Name: string not found for pid %d\n", tid);
> }
>
> if (tgids) {
> tgids += 5; /* strlen("Tgid:") */
> *tgid = atoi(tgids);
> +
> + if (pid && pid != *tgid) {
> + pr_debug("Tgid: not match to given pid: %d vs %d\n",
> + pid, *tgid);
hm, could this actually happen in our case?
jirka
next prev parent reply other threads:[~2021-01-31 23:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 5:48 [PATCH v2 0/3] perf tools: Minor improvements in event synthesis Namhyung Kim
2021-01-29 5:48 ` [PATCH 1/3] perf tools: Use /proc/<PID>/task/<TID>/status for synthesis Namhyung Kim
2021-01-31 23:00 ` Jiri Olsa [this message]
2021-02-01 4:41 ` Namhyung Kim
2021-02-01 20:41 ` Jiri Olsa
2021-01-29 5:49 ` [PATCH 2/3] perf tools: Skip MMAP record synthesis for kernel threads Namhyung Kim
2021-01-31 22:48 ` Jiri Olsa
2021-02-01 4:54 ` Namhyung Kim
2021-02-01 20:32 ` Jiri Olsa
2021-01-29 5:49 ` [PATCH 3/3] perf tools: Use scandir() to iterate threads Namhyung Kim
2021-01-31 22:35 ` [PATCH v2 0/3] perf tools: Minor improvements in event synthesis Jiri Olsa
2021-02-01 4:35 ` Namhyung Kim
-- strict thread matches above, loose matches on Subject: below --
2021-02-02 9:01 [PATCHSET v3 " Namhyung Kim
2021-02-02 9:01 ` [PATCH 1/3] perf tools: Use /proc/<PID>/task/<TID>/status for synthesis Namhyung Kim
2020-12-21 7:00 [PATCH 0/3] perf tools: Minor improvements in event synthesis Namhyung Kim
2020-12-21 7:00 ` [PATCH 1/3] perf tools: Use /proc/<PID>/task/<TID>/status for synthesis Namhyung Kim
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=YBc2jfTDcBjcL5kN@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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