From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 26 14:44:29 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 57D8816A4CE for ; Mon, 26 Jan 2004 14:44:29 -0800 (PST) Received: from sccrmhc13.comcast.net (sccrmhc13.comcast.net [204.127.202.64]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6429043D2F for ; Mon, 26 Jan 2004 14:44:24 -0800 (PST) (envelope-from julian@elischer.org) Received: from interjet.elischer.org ([24.7.73.28]) by comcast.net (sccrmhc13) with ESMTP id <2004012622442301600ge1eqe>; Mon, 26 Jan 2004 22:44:23 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id OAA79753; Mon, 26 Jan 2004 14:44:22 -0800 (PST) Date: Mon, 26 Jan 2004 14:44:21 -0800 (PST) From: Julian Elischer To: Steve Watt In-Reply-To: <200401262059.i0QKxdIi038551@wattres.Watt.COM> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: hackers@freebsd.org Subject: Re: send(2) does not block, send(2) man page wrong? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jan 2004 22:44:29 -0000 On Mon, 26 Jan 2004, Steve Watt wrote: > julian@elischer.org wrote: > >do what ping does (ping -f) > >when you get an ENOBUFS do a usleep for 1 mSec. > >and then send it again. you are correct, but I just meant that it requested to sleep 1mSec, not that the sleep actually WAS 1mSec. Making udp sockets block would break so many things since it was always this way since sockets were invented in BSD2.x > > So how, exactly, do you actually sleep for 1mSec? I recently did some > experiments using nanosleep(), and it seems that the minimum sleep time > is 2 / HZ. I.e. ask for 100nS, get 20mS (on a 10mS-ticking system). > > Mind you, that behavior is precisely aligned with what POSIX says should > happen, since nanosleep() is not allowed to return success before the > specified amount of time has expired, and you might be calling it 5nS > before the clock tick. But it does make doing correct Tx pacing a bit > more challenging. > > Tried the same thing with usleep(10000), same result of ~20mS per > sleep. > > Here's the program I tested that with. Same results on a 4.4-RELEASE > and a 5.2-RELEASE machine. > > Numbers from one run: > 4.4-REL: 1501 loops, 30.017931 elapsed, time per loop: 19998.622 us > 5.2-REL: 1501 loops, 30.016053 elapsed, time per loop: 19997.371 us > > - - - 8< - - - > > #include > #include > #include > > /* Seconds to count loops */ > #define RUNTIME 30 > > int > main(int argc, char **argv) > { > struct timespec start, now, end, delay, remain; > double ts, te; > long loops = 0; > int rv; > > clock_gettime(CLOCK_REALTIME, &start); > end.tv_sec = start.tv_sec + RUNTIME; > end.tv_nsec = start.tv_nsec; > > do { > delay.tv_sec = 0; > delay.tv_nsec = 10000; /* 10uS */ > > do { > rv = nanosleep(&delay, &remain); > delay = remain; > } while (rv < 0 && errno == EINTR); > > ++loops; > clock_gettime(CLOCK_REALTIME, &now); > } while ((now.tv_sec == end.tv_sec) ? > (now.tv_nsec < end.tv_nsec) : > (now.tv_sec < end.tv_sec)); > > te = now.tv_sec + (now.tv_nsec / 1000000000.); > ts = start.tv_sec + (start.tv_nsec / 1000000000.); > > printf("%d loops, %f elapsed, ", loops, te - ts); > printf("time per loop: %.3f us\n", ((te - ts) / loops) * 1000000.); > > return 0; > } > > > -- > Steve Watt KD6GGD PP-ASEL-IA ICBM: 121W 56' 57.8" / 37N 20' 14.9" > Internet: steve @ Watt.COM Whois: SW32 > Free time? There's no such thing. It just comes in varying prices... >