From: Peter Zijlstra <peterz@infradead.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>,
Kan Liang <kan.liang@linux.intel.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
bpf@vger.kernel.org
Subject: Re: [PATCH 2/3] perf/core: Set data->sample_flags in perf_prepare_sample()
Date: Wed, 11 Jan 2023 13:54:54 +0100 [thread overview]
Message-ID: <Y76xng1U6UYpIGaW@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CAM9d7ciVZCHk0YqpobfR+t0FPN_-tpnLgNbN981=EygkM_riDg@mail.gmail.com>
On Tue, Jan 10, 2023 at 12:06:00PM -0800, Namhyung Kim wrote:
> Another example, but in this case it's real, is ADDR. We cannot update
> the data->addr just because filtered_sample_type has PHYS_ADDR or
> DATA_PAGE_SIZE as it'd lose the original value.
Hmm, how about something like so?
/*
* if (flags & s) flags |= d; // without branches
*/
static __always_inline unsigned long
__cond_set(unsigned long flags, unsigned long s, unsigned long d)
{
return flags | (d * !!(flags & s));
}
Then:
fst = sample_type;
fst = __cond_set(fst, PERF_SAMPLE_CODE_PAGE_SIZE, PERF_SAMPLE_IP);
fst = __cond_set(fst, PERF_SAMPLE_DATA_PAGE_SIZE |
PERF_SAMPLE_PHYS_ADDR, PERF_SAMPLE_ADDR);
fst = __cond_set(fst, PERF_SAMPLE_STACK_USER, PERF_SAMPLE_REGS_USER);
fst &= ~data->sample_flags;
This way we express the implicit conditions by setting the required
sample data flags, then we mask those we already have set.
After the above something like:
if (fst & PERF_SAMPLE_ADDR) {
data->addr = 0;
data->sample_flags |= PERF_SAMPLE_ADDR;
}
if (fst & PERF_SAMPLE_PHYS_ADDR) {
data->phys_addr = perf_virt_to_phys(data->addr);
data->sample_flags |= PERF_SAMPLE_PHYS_ADDR;
}
if (fst & PERF_SAMPLE_DATA_PAGE_SIZE) {
data->data_page_size = perf_get_page_size(data->addr);
data->sample_flags |= PERF_SAMPLE_DATA_PAGE_SIZE;
}
And maybe something like:
#define __IF_SAMPLE_DATA(f_) ({ \
bool __f = fst & PERF_SAMPLE_##f_; \
if (__f) data->sample_flags |= PERF_SAMPLE_##f_;\
__f; })
#define IF_SAMPLE_DATA(f_) if (__IF_SAMPLE_DATA(f_))
Then we can write:
IF_SAMPLE_DATA(ADDR)
data->addr = 0;
IF_SAMPLE_DATA(PHYS_ADDR)
data->phys_addr = perf_virt_to_phys(data->addr);
IF_SAMPLE_DATA(DATA_PAGE_SIZE)
data->data_page_size = perf_get_page_size(data->addr);
But I didn't check code-gen for this last suggestion.
next prev parent reply other threads:[~2023-01-11 12:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-29 20:40 [PATCH 1/3] perf/core: Change the layout of perf_sample_data Namhyung Kim
2022-12-29 20:41 ` [PATCH 2/3] perf/core: Set data->sample_flags in perf_prepare_sample() Namhyung Kim
2023-01-09 12:14 ` Peter Zijlstra
2023-01-09 20:21 ` Namhyung Kim
2023-01-10 10:54 ` Peter Zijlstra
2023-01-10 11:10 ` Ingo Molnar
2023-01-10 19:00 ` Namhyung Kim
2023-01-10 10:55 ` Peter Zijlstra
2023-01-10 19:01 ` Namhyung Kim
2023-01-10 20:06 ` Namhyung Kim
2023-01-11 12:54 ` Peter Zijlstra [this message]
2023-01-11 16:45 ` Peter Zijlstra
2023-01-11 17:59 ` Namhyung Kim
2022-12-29 20:41 ` [PATCH 3/3] perf/core: Save calculated sample data size 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=Y76xng1U6UYpIGaW@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=ravi.bangoria@amd.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