From owner-freebsd-current@FreeBSD.ORG Tue Aug 20 03:13:09 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A0AC3C24; Tue, 20 Aug 2013 03:13:09 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 644C82A54; Tue, 20 Aug 2013 03:13:08 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.6/8.14.6/NETPLEX) with ESMTP id r7K3D2Dc039343; Mon, 19 Aug 2013 23:13:02 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.1 (mail.netplex.net [204.213.176.9]); Mon, 19 Aug 2013 23:13:02 -0400 (EDT) Date: Mon, 19 Aug 2013 23:13:02 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Adrian Chadd Subject: Re: Question about socket timeouts In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Vitja Makarov , freebsd-current X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Daniel Eischen List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Aug 2013 03:13:09 -0000 On Mon, 19 Aug 2013, Adrian Chadd wrote: > Yes! Please file a PR! This sorta implies that both are acceptable (although, the Linux behavior seems more desirable). http://austingroupbugs.net/view.php?id=369 > On 19 August 2013 12:33, Vitja Makarov wrote: > >> Hi! >> >> Recently I was playing with small socket timeouts. setsockopt(2) >> SO_RCVTIMEO and found a problem with it: if timeout is small enough >> read(2) may return before timeout is actually expired. >> >> I was unable to reproduce this on linux box. >> >> I found that kernel uses a timer with 1/HZ precision so it converts >> time in microseconds to ticks that's ok linux does it as well. The >> problem is in details: freebsd uses floor() approach while linux uses >> ceil(): >> >> from FreeBSD's sys/kern/uipc_socket.c: >> val = (u_long)(tv.tv_sec * hz) + tv.tv_usec / tick; >> if (val == 0 && tv.tv_usec != 0) >> val = 1; /* at least one tick if tv > 0 */ >> >> from Linux's net/core/sock.c: >> *timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(1000000/HZ-1))/(1000000/HZ); >> >> So, for instance, we have a freebsd system running with kern.hz set >> 100 and set receive timeout to 25ms that is converted to 2 ticks which >> is 20ms. In my test program read(2) returns with EAGAIN set in >> 0.019ms. >> >> So the question is: is that a problem or not? >> >> -- >> vitja. -- DE