This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: us_delay() improvement
Jonathan Larmour <jifl@eCosCentric.com> writes:
> Nick Garnett wrote:
> > + if( usecs > usec_per_period/2 )
> > + slice = CYGNUM_KERNEL_COUNTERS_RTC_PERIOD/2;
> > + else if( CYGNUM_KERNEL_COUNTERS_RTC_PERIOD >= 0x7FFFFFFF/usec_per_period )
> > + slice = usecs * ticks_per_usec;
> > + else
> > + {
> > + slice = usecs*CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
> > + slice /= usec_per_period;
> > + }
>
> I've been thinking about this.... we get overflow if
> usecs*CYGNUM_KERNEL_COUNTERS_RTC_PERIOD overflows, which means that
> since usecs should be at most usec_per_period/2, we have to "play
> safe" if plugging usecs == usec_per_period/2 in to the multiplication
> would overflow, because that's the worst case.
>
> So we get the expression to test as:
>
> (usec_per_period/2)*CYGNUM_KERNEL_COUNTERS_RTC_PERIOD >= 0x7FFFFFFF
>
> which we reorganise to prevent overflow of this expression to become:
>
> CYGNUM_KERNEL_COUNTERS_RTC_PERIOD/2 >= 0x7FFFFFFF/usec_per_period
>
> which should be sufficient. The code as written will unnecessarily
> catch certain configurations I'd think.
Good point. I'd missed that implication. I'll make the change.
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts