From owner-freebsd-current@FreeBSD.ORG Tue Aug 20 02:49:06 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 97E204A7 for ; Tue, 20 Aug 2013 02:49:06 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2E0E72888 for ; Tue, 20 Aug 2013 02:49:06 +0000 (UTC) Received: by mail-wi0-f174.google.com with SMTP id j17so3815137wiw.1 for ; Mon, 19 Aug 2013 19:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=tenO2eYhvoVqVxbsSGBtEPeGIFRivB85+7BDq7AZtUI=; b=LpN0PHkjnIWRdmfnmpoAn02wI5Ak8sqPo3ShAoIbaWXugQGUtxcBjqmuPbqHhhfVry TtrWmo9Cx1X6ijmAAg/fADn49TMBYaoetgBZ8zc3UBWgYYvTywN9qO3fiL1q4pk71jrh FhYiVwOOfejCyk5WeStY0kEsiaIXZbEROB9Afkg1YGSef+pbjX6WHlJc6E6HFY7Wmc9r uvOaEAsCcmkPHat4kBaqSapNaRwsHUDIyjUEEX1PTpN1Y9OGDLDFWYRUsLGq+N9KilN6 mMYdoqUV8ciLSiS4UhfE/MXEg5Mfem3T0iZBTKuiy0aCwdnHpHIvSzQk01cIBX7SA3Mi aQaQ== MIME-Version: 1.0 X-Received: by 10.194.250.6 with SMTP id yy6mr11153015wjc.13.1376966944336; Mon, 19 Aug 2013 19:49:04 -0700 (PDT) Sender: adrian.chadd@gmail.com Received: by 10.217.116.136 with HTTP; Mon, 19 Aug 2013 19:49:04 -0700 (PDT) In-Reply-To: References: Date: Mon, 19 Aug 2013 19:49:04 -0700 X-Google-Sender-Auth: szaBWge10QLrLmRv44ktBvurh2c Message-ID: Subject: Re: Question about socket timeouts From: Adrian Chadd To: Vitja Makarov Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: freebsd-current X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list 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 02:49:06 -0000 Yes! Please file a PR! -adrian 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. > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >