From: Adrian Hunter <adrian.hunter@intel.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users <linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH 3/4] perf record: Save DSO build-ID for synthesizing
Date: Wed, 21 Sep 2022 13:11:53 +0300 [thread overview]
Message-ID: <7e0b9116-7e1f-fc4c-5528-ce5a3e565fa3@intel.com> (raw)
In-Reply-To: <c288baa5-abb1-c34c-713c-b9d11873d34a@intel.com>
On 21/09/22 10:26, Adrian Hunter wrote:
> On 20/09/22 21:30, Namhyung Kim wrote:
>> On Tue, Sep 20, 2022 at 7:00 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>>>
>>> On 16/09/22 20:59, Namhyung Kim wrote:
>>>> When synthesizing MMAP2 with build-id, it'd read the same file repeatedly as
>>>> it has no idea if it's done already. Maintain a dsos to check that and skip
>>>> the file access if possible.
>>>>
>>>> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>>>> ---
>>>> tools/perf/util/synthetic-events.c | 49 +++++++++++++++++++++++++-----
>>>> 1 file changed, 42 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
>>>> index 9d4f5dacd154..e6978b2dee8f 100644
>>>> --- a/tools/perf/util/synthetic-events.c
>>>> +++ b/tools/perf/util/synthetic-events.c
>>>> @@ -4,6 +4,7 @@
>>>> #include "util/data.h"
>>>> #include "util/debug.h"
>>>> #include "util/dso.h"
>>>> +#include "util/dsos.h"
>>>> #include "util/event.h"
>>>> #include "util/evlist.h"
>>>> #include "util/machine.h"
>>>> @@ -47,12 +48,25 @@
>>>>
>>>> unsigned int proc_map_timeout = DEFAULT_PROC_MAP_PARSE_TIMEOUT;
>>>>
>>>> +static bool synth_init_done;
>>>> +static struct dsos synth_dsos;
>>>> +
>>>> void perf_event__synthesize_start(void)
>>>> {
>>>> + if (synth_init_done)
>>>> + return;
>>>> +
>>>> + dsos__init(&synth_dsos);
>>>> +
>>>> + synth_init_done = true;
>>>> }
>>>>
>>>> void perf_event__synthesize_stop(void)
>>>> {
>>>> + if (!synth_init_done)
>>>> + return;
>>>> +
>>>> + dsos__exit(&synth_dsos);
>>>> }
>>>>
>>>> int perf_tool__process_synth_event(struct perf_tool *tool,
>>>> @@ -374,26 +388,47 @@ static bool read_proc_maps_line(struct io *io, __u64 *start, __u64 *end,
>>>> static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event,
>>>> bool is_kernel)
>>>> {
>>>> - struct build_id bid;
>>>> + struct build_id _bid, *bid = &_bid;
>>>> + struct dso *dso = NULL;
>>>> + struct dso_id id;
>>>> int rc;
>>>>
>>>> - if (is_kernel)
>>>> - rc = sysfs__read_build_id("/sys/kernel/notes", &bid);
>>>> - else
>>>> - rc = filename__read_build_id(event->filename, &bid) > 0 ? 0 : -1;
>>>> + if (is_kernel) {
>>>> + rc = sysfs__read_build_id("/sys/kernel/notes", bid);
>>>> + goto out;
>>>> + }
>>>> +
>>>> + id.maj = event->maj;
>>>> + id.min = event->min;
>>>> + id.ino = event->ino;
>>>> + id.ino_generation = event->ino_generation;
>>>>
>>>
>>> There might be some paths missing perf_event__synthesize_start()
>>> e.g. perf trace
>>> So it would probably be safer to use lazy initialization for
>>> synth_dsos.
>>
>> I thought about that too, but it'd need a cleanup routine at the end
>> anyway. So I ended up having a pair of start/stop routines.
>>
>>>
>>> Also, callers of perf_record_mmap2__read_build_id() have a struct
>>> machine so I wonder about putting synth_dsos in struct machine ?
>>> Or even just using machine->dsos ?
>>
>> My intention was to use minimal info from struct dso - name, id and
>> build-id. But as it already uses dsos/dso routines, it's not much
>> different from using the existing machine->dsos.
>>
>> So yeah, I think it's good to reuse the existing one as it'd benefit
>> the build-id processing at the end. Will change.
>>
>> Thanks,
>> Namhyung
>>
>>
>>>
>>>> + dso = dsos__findnew_id(&synth_dsos, event->filename, &id);
>>>> + if (dso && dso->has_build_id) {
>>>> + bid = &dso->bid;
>>>> + rc = 0;
>>>> + goto out;
>>>> + }
>
> Also I guess the dsos optimization could be a separate patch ?
Disregard that - I thought there were other changes too.
next prev parent reply other threads:[~2022-09-21 10:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 17:58 [PATCH 0/4] perf tools: Fix MMAP2 build-ID synthesis in namespaces (v1) Namhyung Kim
2022-09-16 17:58 ` [PATCH 1/4] perf tools: Move dsos functions to util/dsos.c Namhyung Kim
2022-09-20 13:51 ` Adrian Hunter
2022-09-20 17:49 ` Namhyung Kim
2022-09-16 17:59 ` [PATCH 2/4] perf tools: Add perf_event__synthesize_{start,stop}() Namhyung Kim
2022-09-20 13:50 ` Adrian Hunter
2022-09-20 18:17 ` Namhyung Kim
2022-09-16 17:59 ` [PATCH 3/4] perf record: Save DSO build-ID for synthesizing Namhyung Kim
2022-09-20 13:59 ` Adrian Hunter
2022-09-20 18:30 ` Namhyung Kim
2022-09-21 7:26 ` Adrian Hunter
2022-09-21 10:11 ` Adrian Hunter [this message]
2022-09-16 17:59 ` [PATCH 4/4] perf tools: Honor namespace when synthesizing build-id Namhyung Kim
2022-09-20 13:36 ` Adrian Hunter
2022-09-20 18:31 ` 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=7e0b9116-7e1f-fc4c-5528-ce5a3e565fa3@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--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
all inboxes | Powered by JetHome®