From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 26 12:59:42 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 B9CDE16A4CE for ; Mon, 26 Jan 2004 12:59:42 -0800 (PST) Received: from wattres.Watt.COM (wattres.watt.com [66.93.133.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id 62BCD43D31 for ; Mon, 26 Jan 2004 12:59:41 -0800 (PST) (envelope-from steve@Watt.COM) Received: (from steve@localhost) by wattres.Watt.COM (8.12.9/8.12.9) id i0QKxdIi038551; Mon, 26 Jan 2004 12:59:39 -0800 (PST) (envelope-from steve) Message-Id: <200401262059.i0QKxdIi038551@wattres.Watt.COM> X-Newsgroups: local.freebsd-hackers In-Reply-To: References: Organization: Watt Consultants, San Jose, CA, USA From: steve@Watt.COM (Steve Watt) Date: Mon, 26 Jan 2004 12:59:39 -0800 X-Mailer: Mail User's Shell (7.2.6 beta(5) jp(8) 11/23/00) To: hackers@freebsd.org cc: julian@elischer.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 20:59:42 -0000 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. 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...