From owner-freebsd-arch@FreeBSD.ORG Thu Mar 1 01:47:02 2012 Return-Path: Delivered-To: arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 41DE3106564A for ; Thu, 1 Mar 2012 01:47:02 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 068428FC08 for ; Thu, 1 Mar 2012 01:47:00 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id E4EF37300A; Thu, 1 Mar 2012 03:05:15 +0100 (CET) Date: Thu, 1 Mar 2012 03:05:15 +0100 From: Luigi Rizzo To: Bruce Evans Message-ID: <20120301020515.GA14996@onelab2.iet.unipi.it> References: <20120229194042.GA10921@onelab2.iet.unipi.it> <20120301071145.O879@besplex.bde.org> <20120301012315.GB14508@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120301012315.GB14508@onelab2.iet.unipi.it> User-Agent: Mutt/1.4.2.3i Cc: arch@FreeBSD.org Subject: Re: select/poll/usleep precision on FreeBSD vs Linux vs OSX X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Mar 2012 01:47:02 -0000 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