perf tools: Use /proc/<PID>/task/<TID>/status for PERF_RECORD_ event synthesis
authorNamhyung Kim <namhyung@kernel.org>
Tue, 2 Feb 2021 09:01:16 +0000 (18:01 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 3 Feb 2021 16:10:44 +0000 (13:10 -0300)
commit30626e0844757b7b371353eb693354c4ccc5eb0e
tree8ab441606fce4dda526f2a9a1bcaa49822aec0f1
parentc3a9cdef61e6dcb0b757a7309072c1742d764d79
perf tools: Use /proc/<PID>/task/<TID>/status for PERF_RECORD_ event synthesis

To save memory usage, it needs to reduce the 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>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20210202090118.2008551-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/synthetic-events.c