From: Tengda Wu <wutengda@huaweicloud.com>
To: Namhyung Kim <namhyung@kernel.org>, Song Liu <song@kernel.org>
Cc: 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>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH -next v3 1/2] perf stat: Support inherit events during fork() for bperf
Date: Thu, 10 Oct 2024 12:53:23 +0800 [thread overview]
Message-ID: <a98f599f-ea6e-4c7f-b39d-44e6cd2a9f20@huaweicloud.com> (raw)
In-Reply-To: <ZwcgZhOC_gq9kToT@google.com>
On 2024/10/10 8:31, Namhyung Kim wrote:
> On Wed, Oct 09, 2024 at 10:18:44AM -0700, Song Liu wrote:
>> On Sun, Sep 15, 2024 at 6:53 PM Tengda Wu <wutengda@huaweicloud.com> wrote:
>>>
>>> bperf has a nice ability to share PMUs, but it still does not support
>>> inherit events during fork(), resulting in some deviations in its stat
>>> results compared with perf.
>>>
>>> perf stat result:
>>> $ ./perf stat -e cycles,instructions -- ./perf test -w sqrtloop
>>>
>>> Performance counter stats for './perf test -w sqrtloop':
>>>
>>> 2,316,038,116 cycles
>>> 2,859,350,725 instructions
>>>
>>> 1.009603637 seconds time elapsed
>>>
>>> 1.004196000 seconds user
>>> 0.003950000 seconds sys
>>>
>>> bperf stat result:
>>> $ ./perf stat --bpf-counters -e cycles,instructions -- \
>>> ./perf test -w sqrtloop
>>>
>>> Performance counter stats for './perf test -w sqrtloop':
>>>
>>> 18,762,093 cycles
>>> 23,487,766 instructions
>>>
>>> 1.008913769 seconds time elapsed
>>>
>>> 1.003248000 seconds user
>>> 0.004069000 seconds sys
>>>
>>> In order to support event inheritance, two new bpf programs are added
>>> to monitor the fork and exit of tasks respectively. When a task is
>>> created, add it to the filter map to enable counting, and reuse the
>>> `accum_key` of its parent task to count together with the parent task.
>>> When a task exits, remove it from the filter map to disable counting.
>>>
>>> After support:
>>> $ ./perf stat --bpf-counters -e cycles,instructions -- \
>>> ./perf test -w sqrtloop
>>>
>>> Performance counter stats for './perf test -w sqrtloop':
>>>
>>> 2,316,252,189 cycles
>>> 2,859,946,547 instructions
>>>
>>> 1.009422314 seconds time elapsed
>>>
>>> 1.003597000 seconds user
>>> 0.004270000 seconds sys
>>>
>>> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
>>
>> The solution looks good to me. Question on the UI: do we always
>> want the inherit behavior from PID and TGID monitoring? If not,
>> maybe we should add a flag for it. (I think we do need the flag).
>
> I think it should depend on the value of attr.inherit. Maybe we can
> disable the autoload for !inherit.
>
Got it. The attr.inherit flag(related to --no-inherit in perf command)
is suitable for controlling inherit behavior. I will fix it. Thanks!
>>
>> One nitpick below.
>>
>> Thanks,
>> Song
>>
>> [...]
>>>
>>> +struct bperf_filter_value {
>>> + __u32 accum_key;
>>> + __u8 exited;
>>> +};
>> nit:
>> Can we use a special value of accum_key to replace exited==1
>> case?
>
> I'm not sure. I guess it still needs to use the accum_key to save the
> final value when exited = 1.
In theory, it is possible. The accum_key is currently only used to index value
in accum_readings map, so if the task is not being counted, the accum_key can
be set to an special value.
Due to accum_key is of u32 type, there are two special values to choose from: 0
or max_entries+1. I think the latter, max_entries+1, may be more suitable because
it can avoid memory waste in the accum_readings map and does not require too
many changes to bpf_counter.
Thanks for your kindly review!
Tengda
>
> Thanks,
> Namhyung
>
>>
>>> +
>>> #endif /* __BPERF_STAT_U_H */
>>> --
>>> 2.34.1
>>>
next prev parent reply other threads:[~2024-10-10 4:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-16 1:43 [PATCH -next v3 0/2] perf stat: Support inherit events for bperf Tengda Wu
2024-09-16 1:43 ` [PATCH -next v3 1/2] perf stat: Support inherit events during fork() " Tengda Wu
2024-10-09 17:18 ` Song Liu
2024-10-10 0:31 ` Namhyung Kim
2024-10-10 4:53 ` Tengda Wu [this message]
2024-10-11 3:07 ` Tengda Wu
2024-10-11 3:21 ` Song Liu
2024-09-16 1:43 ` [PATCH -next v3 2/2] perf test: Use sqrtloop workload to test bperf event Tengda Wu
2024-09-25 14:16 ` [PATCH -next v3 0/2] perf stat: Support inherit events for bperf Tengda Wu
2024-09-26 3:43 ` Namhyung Kim
2024-10-09 5:21 ` Namhyung Kim
2024-10-09 17:21 ` Song Liu
2024-10-10 0:22 ` 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=a98f599f-ea6e-4c7f-b39d-44e6cd2a9f20@huaweicloud.com \
--to=wutengda@huaweicloud.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.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;
as well as URLs for NNTP newsgroup(s).