From owner-svn-src-all@FreeBSD.ORG Thu Oct 15 14:18:35 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDC591065698; Thu, 15 Oct 2009 14:18:35 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9258A8FC17; Thu, 15 Oct 2009 14:18:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n9FEIZ6n075762; Thu, 15 Oct 2009 14:18:35 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n9FEIZdo075760; Thu, 15 Oct 2009 14:18:35 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200910151418.n9FEIZdo075760@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 15 Oct 2009 14:18:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r198132 - head/tools/tools/netrate/netsend X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Oct 2009 14:18:35 -0000 Author: luigi Date: Thu Oct 15 14:18:35 2009 New Revision: 198132 URL: http://svn.freebsd.org/changeset/base/198132 Log: A small change to avoid calling gettimeofday() too often (hardwired to once every 20us at most). I found out that on many machines round here, i could only get 300-400kpps with netsend even on loopback and a 'deny' rule in the firewall, while reducing the number of calls to gettimeofday() brings the value to 900kpps and more. This code is just a quick fix for the problem. Of course it could be done better, with proper getopt() parsing and the like, but since this applies to the entire program i'll postpone that to when i have more time. Reviewed by: rwatson MFC after: 1 month Modified: head/tools/tools/netrate/netsend/netsend.c Modified: head/tools/tools/netrate/netsend/netsend.c ============================================================================== --- head/tools/tools/netrate/netsend/netsend.c Thu Oct 15 13:34:45 2009 (r198131) +++ head/tools/tools/netrate/netsend/netsend.c Thu Oct 15 14:18:35 2009 (r198132) @@ -124,6 +124,9 @@ timing_loop(int s, struct timespec inter u_int32_t counter; long finishtime; long send_errors, send_calls; + /* do not call gettimeofday more than every 20us */ + long minres_ns = 20000; + int ic, gettimeofday_cycles; if (clock_getres(CLOCK_REALTIME, &tmptime) == -1) { perror("clock_getres"); @@ -132,8 +135,15 @@ timing_loop(int s, struct timespec inter if (timespec_ge(&tmptime, &interval)) fprintf(stderr, - "warning: interval less than resolution (%jd.%09ld)\n", + "warning: interval (%jd.%09ld) less than resolution (%jd.%09ld)\n", + (intmax_t)interval.tv_sec, interval.tv_nsec, (intmax_t)tmptime.tv_sec, tmptime.tv_nsec); + if (tmptime.tv_nsec < minres_ns) { + gettimeofday_cycles = minres_ns/(tmptime.tv_nsec + 1); + fprintf(stderr, + "calling time every %d cycles\n", gettimeofday_cycles); + } else + gettimeofday_cycles = 0; if (clock_gettime(CLOCK_REALTIME, &starttime) == -1) { perror("clock_gettime"); @@ -151,10 +161,14 @@ timing_loop(int s, struct timespec inter send_errors = send_calls = 0; counter = 0; waited = 0; + ic = gettimeofday_cycles; while (1) { timespec_add(&nexttime, &interval); - if (wait_time(nexttime, &tmptime, &waited) == -1) - return (-1); + if (--ic <= 0) { + ic = gettimeofday_cycles; + if (wait_time(nexttime, &tmptime, &waited) == -1) + return (-1); + } /* * We maintain and, if there's room, send a counter. Note * that even if the error is purely local, we still increment @@ -236,8 +250,9 @@ main(int argc, char *argv[]) /* * Specify an arbitrary limit. It's exactly that, not selected by - .* any particular strategy. '0' is a special value meaning "blast", + * any particular strategy. '0' is a special value meaning "blast", * and avoids the cost of a timing loop. + * XXX 0 is not actually implemented. */ rate = strtoul(argv[4], &dummy, 10); if (rate < 1 || *dummy != '\0')