On Fri, Jun 07, 2019 at 07:36:36PM -0500, Scott Cheloha wrote:
> [...]
> 
> > +
> > +static uint64_t
> > +mcx_timer(struct mcx_softc *sc)
> > +{
> > +   uint32_t hi, lo, ni;
> > +
> > +   hi = mcx_rd(sc, MCX_INTERNAL_TIMER_H);
> > +   for (;;) {
> > +           lo = mcx_rd(sc, MCX_INTERNAL_TIMER_L);
> > +           mcx_bar(sc, MCX_INTERNAL_TIMER_L, 8, BUS_SPACE_BARRIER_READ);
> > +           ni = mcx_rd(sc, MCX_INTERNAL_TIMER_H);
> > +
> > +           if (ni == hi)
> > +                   break;
> > +
> > +           hi = ni;
> > +   }
> > +
> > +   return (((uint64_t)hi << 32) | (uint64_t)lo);
> >  }
> 
> You could actually truncate this loop:
> 
>       for (ni = hi + 1; ni != hi; hi = ni) {
>               lo = mcx_rd(sc, MCX_INTERNAL_TIMER_L);
>               mcx_bar(sc, MCX_INTERNAL_TIMER_L, 8, BUS_SPACE_BARRIER_READ);
>               ni = mcx_rd(sc, MCX_INTERNAL_TIMER_H);
>       }
> 
> but maybe that's too clever :)

this is wrong, ignore this part, your loop is fine.

too clever indeed...

Reply via email to