<div dir="auto">For humor<div dir="auto">#define RTE_CASTAWAY(x) ((void *)(uinptr_t)(x))</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 28, 2023, 12:29 PM Bruce Richardson <<a href="mailto:bruce.richardson@intel.com">bruce.richardson@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Aug 28, 2023 at 11:29:05AM +0200, David Marchand wrote:<br>
> On Fri, Aug 25, 2023 at 5:29 PM Bruce Richardson<br>
> <<a href="mailto:bruce.richardson@intel.com" target="_blank" rel="noreferrer">bruce.richardson@intel.com</a>> wrote:<br>
> ><br>
> > When doing a build for a system with WAITPKG support and a modern<br>
> > compiler, we get build errors for the "_umonitor" intrinsic, due to the<br>
> > casting away of the "volatile" on the parameter.<br>
> ><br>
> > ../lib/eal/x86/rte_power_intrinsics.c: In function 'rte_power_monitor':<br>
> > ../lib/eal/x86/rte_power_intrinsics.c:113:22: error: passing argument 1<br>
> > of '_umonitor' discards 'volatile' qualifier from pointer target type<br>
> > [-Werror=discarded-qualifiers]<br>
> >   113 |         _umonitor(pmc->addr);<br>
> >         |                   ~~~^~~~~~<br>
> ><br>
> > We can avoid this issue by using RTE_PTR_ADD(..., 0) to cast the pointer<br>
> > through "uintptr_t" and thereby remove the volatile without warning.<br>
> <br>
> As Morten, I prefer an explicit cast (keeping your comments) as it<br>
> seems we are exploiting an implementation detail of RTE_PTR_ADD.<br>
> <br>
<br>
Ok, I'll do a respin with explicit cast.<br>
<br>
> <br>
> > We also ensure comments are correct for each leg of the<br>
> > ifdef..else..endif block.<br>
> <br>
> Thanks.. I had fixed other places but I have missed this one.<br>
> <br>
> <br>
> ><br>
> > Fixes: 60943c04f3bc ("eal/x86: use intrinsics for power management")<br>
> > Cc: <a href="mailto:roretzla@linux.microsoft.com" target="_blank" rel="noreferrer">roretzla@linux.microsoft.com</a><br>
> ><br>
> > Signed-off-by: Bruce Richardson <<a href="mailto:bruce.richardson@intel.com" target="_blank" rel="noreferrer">bruce.richardson@intel.com</a>><br>
> > ---<br>
> >  lib/eal/x86/rte_power_intrinsics.c | 12 ++++++------<br>
> >  1 file changed, 6 insertions(+), 6 deletions(-)<br>
> ><br>
> > diff --git a/lib/eal/x86/rte_power_intrinsics.c b/lib/eal/x86/rte_power_intrinsics.c<br>
> > index 4066d1392e..4f0404bfb8 100644<br>
> > --- a/lib/eal/x86/rte_power_intrinsics.c<br>
> > +++ b/lib/eal/x86/rte_power_intrinsics.c<br>
> > @@ -103,15 +103,15 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc,<br>
> >         rte_spinlock_lock(&s->lock);<br>
> >         s->monitor_addr = pmc->addr;<br>
> ><br>
> > -       /*<br>
> > -        * we're using raw byte codes for now as only the newest compiler<br>
> > -        * versions support this instruction natively.<br>
> > -        */<br>
> > -<br>
> >         /* set address for UMONITOR */<br>
> >  #if defined(RTE_TOOLCHAIN_MSVC) || defined(__WAITPKG__)<br>
> > -       _umonitor(pmc->addr);<br>
> > +       /* use RTE_PTR_ADD to cast away "volatile" when using the intrinsic */<br>
> > +       _umonitor(RTE_PTR_ADD(pmc->addr, 0));<br>
> >  #else<br>
> > +       /*<br>
> > +        * we're using raw byte codes for compiler versions which<br>
> > +        * don't support this instruction natively.<br>
> > +        */<br>
> >         asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;"<br>
> >                         :<br>
> >                         : "D"(pmc->addr));<br>
> <br>
> Tested-by: David Marchand <<a href="mailto:david.marchand@redhat.com" target="_blank" rel="noreferrer">david.marchand@redhat.com</a>><br>
> <br>
> An additional question, would Intel CI catch such issue?<br>
> Or was it caught only because you are blessed with bleeding edge hw? :-)<br>
> <br>
Not sure. I would hope so, though.<br>
<br>
/Bruce<br>
</blockquote></div>