[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241108192043.GA22801@noisy.programming.kicks-ass.net>
Date: Fri, 8 Nov 2024 20:20:43 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Colton Lewis <coltonlewis@...gle.com>
Cc: kvm@...r.kernel.org, oliver.upton@...ux.dev, seanjc@...gle.com,
mingo@...hat.com, acme@...nel.org, namhyung@...nel.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
kan.liang@...ux.intel.com, will@...nel.org, linux@...linux.org.uk,
catalin.marinas@....com, mpe@...erman.id.au, npiggin@...il.com,
christophe.leroy@...roup.eu, naveen@...nel.org, hca@...ux.ibm.com,
gor@...ux.ibm.com, agordeev@...ux.ibm.com,
borntraeger@...ux.ibm.com, svens@...ux.ibm.com, tglx@...utronix.de,
bp@...en8.de, dave.hansen@...ux.intel.com, x86@...nel.org,
hpa@...or.com, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linuxppc-dev@...ts.ozlabs.org, linux-s390@...r.kernel.org
Subject: Re: [PATCH v7 4/5] x86: perf: Refactor misc flag assignments
On Fri, Nov 08, 2024 at 07:01:16PM +0000, Colton Lewis wrote:
> Peter Zijlstra <peterz@...radead.org> writes:
>
> > On Thu, Nov 07, 2024 at 07:03:35PM +0000, Colton Lewis wrote:
> > > Break the assignment logic for misc flags into their own respective
> > > functions to reduce the complexity of the nested logic.
>
> > > Signed-off-by: Colton Lewis <coltonlewis@...gle.com>
> > > Reviewed-by: Oliver Upton <oliver.upton@...ux.dev>
> > > ---
> > > arch/x86/events/core.c | 32 +++++++++++++++++++++++--------
> > > arch/x86/include/asm/perf_event.h | 2 ++
> > > 2 files changed, 26 insertions(+), 8 deletions(-)
>
> > > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> > > index d19e939f3998..9fdc5fa22c66 100644
> > > --- a/arch/x86/events/core.c
> > > +++ b/arch/x86/events/core.c
> > > @@ -3011,16 +3011,35 @@ unsigned long
> > > perf_arch_instruction_pointer(struct pt_regs *regs)
> > > return regs->ip + code_segment_base(regs);
> > > }
>
> > > +static unsigned long common_misc_flags(struct pt_regs *regs)
> > > +{
> > > + if (regs->flags & PERF_EFLAGS_EXACT)
> > > + return PERF_RECORD_MISC_EXACT_IP;
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
> > > +{
> > > + unsigned long guest_state = perf_guest_state();
> > > + unsigned long flags = common_misc_flags(regs);
>
> > This is double common_misc and makes no sense
>
> I'm confused what you mean. Are you referring to starting with
> common_misc_flags in both perf_arch_misc_flags and
> perf_arch_guest_misc_flags so possibly the common_msic_flags are set
> twice?
>
> That seems like a good thing that common flags are set wherever they
> apply. You can't guarantee where perf_arch_guest_misc_flags may be
> called in the future.
I got confused by perf_arch_misc_flags() calling common_misc_flags()
twice. It is in fact worse, because afaict all of
perf_arch_guest_misc_flags() is 'common'.
Isn't the below more or less what you want?
static unsigned long misc_flags(struct pt_regs *regs)
{
unsigned long flags = 0;
if (regs->flags & PERF_EFLAGS_EXACT)
flags |= PERF_RECORD_MISC_EXACT_IP;
return flags;
}
static unsigned long native_flags(struct pt_regs *regs)
{
unsigned long flags = 0;
if (user_mode(regs))
flags |= PERF_RECORD_MISC_USER;
else
flags |= PERF_RECORD_MISC_KERNEL;
return flags;
}
static unsigned long guest_flags(struct pt_regs *regs)
{
unsigned long guest_state = perf_guest_state();
unsigned long flags = 0;
if (guest_state & PERF_GUEST_ACTIVE) {
if (guest_state & PERF_GUEST_USER)
flags |= PERF_RECORD_MISC_GUEST_USER;
else
flags |= PERF_RECORD_MISC_GUEST_KERNEL;
}
return flags;
}
unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
{
unsigned long flags;
flags = misc_flags(regs);
flags |= guest_flags(regs);
return flags;
}
unsigned long perf_arch_misc_flags(struct pt_regs *regs)
{
unsigned long flags;
unsigned long guest;
flags = misc_flags(regs);
guest = guest_flags(regs);
if (guest)
flags |= guest;
else
flags |= native_flags(regs);
return flags;
}
Note how both perf_arch*() functions end up calling both misc and guest.
Powered by blists - more mailing lists