select/poll/usleep precision on FreeBSD vs Linux vs OSX
Luigi Rizzo
rizzo at iet.unipi.it
Thu Mar 1 01:47:02 UTC 2012
On Thu, Mar 01, 2012 at 02:23:15AM +0100, Luigi Rizzo wrote:
> On Thu, Mar 01, 2012 at 11:33:46AM +1100, Bruce Evans wrote:
> > On Wed, 29 Feb 2012, Luigi Rizzo wrote:
> >
> > >I have always been annoyed by the fact that FreeBSD rounds timeouts
> > >in select/usleep/poll in very conservative ways, so i decided to
> > >try how other systems behave in this respect. Attached is a simple
> > >program that you should be able to compile and run on various OS
> > >and see what happens.
> >
> > Many are broken, indeed.
> >
> > The simple program isn't attached.
> ...
>
> > >
> > > | Actual timeout
> > > | select | poll | usleep|
> > > timeout | FBSD | Linux | OSX | FBSD | FBSD |
> > > usec | 9.0 | Vbox | 10.6 | 9.0 | 9.0 |
> > > --------+-------+-------+--------+-------+-------+
> > > 1 2000 99 6 0 2000
> > > 10 2000 109 15 0 2000
> > > 50 2000 149 66 0 2000
> > > 100 2000 196 133 0 2000
> > > 500 2000 597 617 0 2000
> > > 1000 2000 1103 1136 2000 2000
> > > 1001 3000 1103 1136 2000 3000 <---
> > > 1500 3000 1608 1631 2000 3000 <---
> > > 2000 3000 2096 2127 3000 3000
> > > 2001 4000 3000 4000 <---
> > > 3001 5000 4000 5000 <---
> > >
> > >Note how the rounding (poll has the timeout in milliseconds) affects
> >
> > You must have synced with timer interrupts to get the above. Timeouts
>
> yes i have -- the test code does almost nothing after returning from
> a select, on a system that does some amount of work times could be
> up to 1000us shorter. Still a huge error on short timeouts.
>
> I should also comment that these are average values on an otherwise
> idle system -- i will try to post a histogram of the actual values,
Below are the statistics of select() delays on my MacBook for
timeouts of 1-10-50-100-500-1000-1001 us
Interesting that some of the delays are actually up to 25us shorter
than they should, and the average is higher than the requested
value (tends to settle to 100-150us for large delays).
> ministat -n ~/d1 ~/d10 ~/d50 ~/d100 ~/d500 ~/d1000 ~/d1001
x /home/luigi/d1
+ /home/luigi/d10
* /home/luigi/d50
% /home/luigi/d100
# /home/luigi/d500
@ /home/luigi/d1000
O /home/luigi/d1001
N Min Max Median Avg Stddev
x 305202 0 943 7 6.553037 2.134
+ 130798 0 862 15 15.290815 2.6807354
* 30265 18 1002 66 66.083562 10.170399
% 14480 75 1072 137 138.12894 29.507796
# 3146 474 1098 656 635.87603 48.670018
@ 1750 987 1924 1158 1143.2394 48.220706
O 1748 986 2337 1159 1144.4102 53.547987
cheers
luigi
More information about the freebsd-arch
mailing list