Re: [PATCH] IB/hfi1: Fix a wrapping test (make it less strict)

Jason Gunthorpe
2017-10-23T19:04:00Z

On Mon, Oct 23, 2017 at 02:33:46PM -0400, Doug Ledford wrote:
> > > > @@ -3781,7 +3781,7 @@ static int
> > > > __subn_get_opa_hfi1_cong_log(struct
> > > > opa_smp *smp, u32 am,
> > > > * required to wrap the counter are supposed to
> > > > * be zeroed (CA10-49 IBTA, release 1.2.1, V1).
> > > > */
> > > > - if ((u64)(ts - cce->timestamp) > (2 * UINT_MAX))
> > > > + if ((u64)(ts - cce->timestamp) > (2ULL *
> > > > UINT_MAX))

This is really weird looking. Both ts and cce->timestamp are s64, why
do the convoluted conversion to unsigned? And surely UINT_MAX is not
the right thing..

if ((ts - cce->timestamp)/2 > 0xFFFFFFFF)

?

ktime_get is defined to be monotonic, so ts - cce->timestamp should
never go negative.

Jason