From owner-freebsd-hackers@freebsd.org Wed Dec 14 09:51:52 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5CB06C76804 for ; Wed, 14 Dec 2016 09:51:52 +0000 (UTC) (envelope-from meka@tilda.center) Received: from mail.tilda.center (mail.tilda.center [188.226.130.133]) by mx1.freebsd.org (Postfix) with ESMTP id 2702B180B for ; Wed, 14 Dec 2016 09:51:51 +0000 (UTC) (envelope-from meka@tilda.center) Received: from hal9000.meka.no-ip.org (unknown [87.116.180.115]) by mail.tilda.center (Postfix) with ESMTPSA id EF7B75FF89; Wed, 14 Dec 2016 10:51:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tilda.center; s=mail; t=1481709079; bh=nUl6VpRHsVqy/zJOLJWQTZOmXiD2nPEXxJwovqAqDCA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RG2huOhEPrXIFT1vFs/tlvAsiMFvEIcR74pWya0qZi53weudswych4ea70M6ynUOP ZJVr+UqFWiZdenNoCjSDKC1EU+jBkIFt0EmaIAldg/7IT/DDufxBZ9yXAAMjgt55Le Xu3Mdv0yxUz+v5QL2N60Cba2Tdc0a2h6IrBWUDFA= Date: Wed, 14 Dec 2016 10:51:19 +0100 From: Goran =?utf-8?B?TWVracSH?= To: Konstantin Belousov Cc: freebsd-hackers@freebsd.org Subject: Re: How to use sem_timedwait? Message-ID: <20161214095118.4wmt2dtf2cmgangl@hal9000.meka.no-ip.org> References: <20161214074228.zh6q5zya2gszw4g6@hal9000.meka.no-ip.org> <20161214092437.GD94325@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="54aufmfj3s6lderl" Content-Disposition: inline In-Reply-To: <20161214092437.GD94325@kib.kiev.ua> User-Agent: NeoMutt/20161126 (1.7.1) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Dec 2016 09:51:52 -0000 --54aufmfj3s6lderl Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Wed, Dec 14, 2016 at 11:24:37AM +0200, Konstantin Belousov wrote: > Because this is how computers work. The declared resolution is the > resolution of the clock_gettime(2) call. While you tried to measure the > different actions: de-facto you scheduled a wakeup, then put the thread > to sleep, then thread was awaken. The system guarantees that the thread > is made runnable due to timeout not earlier than the interval specified. > After the thread is marked runnable, it should be selected for CPU, then > the syscall must complete which put thread to sleep, then userspace must > execute enough to call clock_gettime(), then it should return etc. > > You end up with 1.7ms difference between requested and actual wakeups in > this attempt, which is quite good. > > Note that system also does some micro-optimizations by trying to collapse > wakeups close enough to each other, which might also affect occurences > of wakeups. OK, that sounds logical, but I have a problem now. I need < 1ms precision on this. Is there a way to achieve it? Anyway, thanks for the clarification! Regards, meka --54aufmfj3s6lderl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE1WIFkXy2ZeMKjjKEWj1TknovrLYFAlhRFhMACgkQWj1Tknov rLY9ZQ/+NIketNBQ/lYgS7oZVh+3SqerDUwHlAZO3R6d47dLGo8WI7vUJtKkzOj5 rUtHCPuGWvA83Ib+eqyuVlAdlsr0BHwjMq0ASzgTwEZMDJwaggOILgkDwifBy0r3 HRMAcUMohlmgmBhsUcjIvA+2rl1ef0BDaQZB3KYMZpRIACFntd+g6FV720FIp15c M+WLcgYcu0Rp7tI1IMEHP3iJbSlWHOpHeFZ+Loj6Rw/sTahB+mqHrHDxsSXgrAT0 hPKnodFiBsuBvh5VxJ2ffNTNynZWeQkyii4rKR0WDO6kCeiFGzS3IwipGEdct13x /w/m1+omEjaIWdE1+4oFoovebTM+7g21oaNIvOTX2UX/cLTn24uPb4e8zwVeCKYb n6h2jCICnb6sOvxzUtcecLOYZxvYGcZwgYYyIXRJuBLpj3X4x1ulQcb3+5uj0+nm YZ9I29y1icgZvCY2YFX9FRIlhoSWUdrOsqYAx1FQLFwE2JdFbLLZY1FzR3oMx8WX L7TeIgrdDgwwqgTUVW+nYCVKjiWRHKOnyKrK14ALngdeB9onOSYn6mBu9mFvj3N1 QRYcBa+03TPyrYz+tZQI4CRQysx/5Y3WXb0P7sLxkaGZ3PFYUT32krZ9/xBm3gWu bl+Us3uABHVPlgoYntHagS9vU/np2ppTEjbNWxGKr1sk85PL3O0= =xzAu -----END PGP SIGNATURE----- --54aufmfj3s6lderl--