[SeaBIOS] [PATCH] Increase precision of usec timer calculation

Kevin O'Connor kevin at koconnor.net
Thu Nov 2 19:48:00 CET 2017


On Wed, Nov 01, 2017 at 12:37:25PM -0400, Stefan Berger wrote:
> On 11/01/2017 11:51 AM, Kevin O'Connor wrote:
> > On Wed, Nov 01, 2017 at 10:40:57AM -0400, Stefan Berger wrote:
> > > When timer_calc_usec() is used with large timeout falues, such as 60s,
> > > the function lacks precision and produces different results than when
> > > using timer_calc(time / 1000) for the same timeout. This patch fixes
> > > the precision issue by falling back to timer_calc(time / 1000) for
> > > usec values over one second.
> > Makes sense.  The code would need to use DIV_ROUND_UP though (it's
> > okay to go slightly longer, but it must not calculate a shorter time).
> > Also, I think the check should be extended to
> > nsleep/usleep/ndelay/udelay as well - see the patch below.
> > 
> > Is this needed for the current code, or is this only an issue for the
> > future TPM CRB patches?  I was planning to make a release this week -
> 
> I do see wrong calculations of course when using the usec function, but I am
> not running into actual timeouts (because the emulated device is fast). I
> think it also depends on the values of the timeouts and what bit patterns
> the values have and then what bits get lost during the calculation that it
> may or may not matter. For the general case I would say we have an active
> bug that, depending on timeout values, may cause unwanted behavior.

Ah, I missed that.  I committed the patch.  Unless anyone screams, I'm
going to push back the release a few days as well.

Thanks,
-Kevin



More information about the SeaBIOS mailing list