Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src use getmicrouptime(9) rather than microtime(9) for TIME_WAIT...



details:   https://anonhg.NetBSD.org/src/rev/33715d4989d3
branches:  trunk
changeset: 764909:33715d4989d3
user:      drochner <drochner%NetBSD.org@localhost>
date:      Wed May 11 15:08:59 2011 +0000

description:
use getmicrouptime(9) rather than microtime(9) for TIME_WAIT duration
calculation, because this doesn't get confused by system time changes,
and uses less CPU cycles
reviewed by dyoung

diffstat:

 sys/netinet/tcp_vtw.c   |   6 +++---
 usr.bin/netstat/inet.c  |   7 +++++--
 usr.bin/netstat/inet6.c |   7 +++++--
 usr.bin/netstat/vtw.c   |  17 +++++++++++++++--
 usr.bin/netstat/vtw.h   |   1 +
 5 files changed, 29 insertions(+), 9 deletions(-)

diffs (136 lines):

diff -r 7d12abe6d180 -r 33715d4989d3 sys/netinet/tcp_vtw.c
--- a/sys/netinet/tcp_vtw.c     Wed May 11 14:52:48 2011 +0000
+++ b/sys/netinet/tcp_vtw.c     Wed May 11 15:08:59 2011 +0000
@@ -77,7 +77,7 @@
 #include <machine/stdarg.h>
 #include <netinet/tcp_vtw.h>
 
-__KERNEL_RCSID(0, "$NetBSD: tcp_vtw.c,v 1.2 2011/05/06 12:52:43 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_vtw.c,v 1.3 2011/05/11 15:08:59 drochner Exp $");
 
 #define db_trace(__a, __b)     do { } while (/*CONSTCOND*/0)
 
@@ -1430,7 +1430,7 @@
 
        /* mark expiration
         */
-       microtime(&vtw->expire);
+       getmicrouptime(&vtw->expire);
 
        /* Move expiration into the future.
         */
@@ -1516,7 +1516,7 @@
        struct timeval now;
        int i, cnt = 0;
 
-       microtime(&now);
+       getmicrouptime(&now);
 
        db_trace(KTR_VTW, (arg, "vtk: tick - now %8.8x:%8.8x"
                           , now.tv_sec, now.tv_usec));
diff -r 7d12abe6d180 -r 33715d4989d3 usr.bin/netstat/inet.c
--- a/usr.bin/netstat/inet.c    Wed May 11 14:52:48 2011 +0000
+++ b/usr.bin/netstat/inet.c    Wed May 11 15:08:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet.c,v 1.97 2011/05/03 23:36:26 dyoung Exp $ */
+/*     $NetBSD: inet.c,v 1.98 2011/05/11 15:08:59 drochner Exp $       */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.97 2011/05/03 23:36:26 dyoung Exp $");
+__RCSID("$NetBSD: inet.c,v 1.98 2011/05/11 15:08:59 drochner Exp $");
 #endif
 #endif /* not lint */
 
@@ -343,7 +343,10 @@
        }
 end:
        if (istcp) {
+               struct timeval t;
+               timebase(&t);
                gettimeofday(&now, NULL);
+               timersub(&now, &t, &now);
                show_vtw_v4(print_vtw_v4);
        }
 }
diff -r 7d12abe6d180 -r 33715d4989d3 usr.bin/netstat/inet6.c
--- a/usr.bin/netstat/inet6.c   Wed May 11 14:52:48 2011 +0000
+++ b/usr.bin/netstat/inet6.c   Wed May 11 15:08:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet6.c,v 1.56 2011/05/04 00:55:19 dyoung Exp $        */
+/*     $NetBSD: inet6.c,v 1.57 2011/05/11 15:08:59 drochner Exp $      */
 /*     BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp   */
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c     8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.56 2011/05/04 00:55:19 dyoung Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.57 2011/05/11 15:08:59 drochner Exp $");
 #endif
 #endif /* not lint */
 
@@ -397,7 +397,10 @@
        }
 end:
        if (istcp) {
+               struct timeval t;
+               timebase(&t);
                gettimeofday(&now, NULL);
+               timersub(&now, &t, &now);
                show_vtw_v6(print_vtw_v6);
        }
 }
diff -r 7d12abe6d180 -r 33715d4989d3 usr.bin/netstat/vtw.c
--- a/usr.bin/netstat/vtw.c     Wed May 11 14:52:48 2011 +0000
+++ b/usr.bin/netstat/vtw.c     Wed May 11 15:08:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vtw.c,v 1.5 2011/05/10 04:40:16 enami Exp $    */
+/*     $NetBSD: vtw.c,v 1.6 2011/05/11 15:08:59 drochner Exp $ */
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: vtw.c,v 1.5 2011/05/10 04:40:16 enami Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.6 2011/05/11 15:08:59 drochner Exp $");
 #endif
 #endif /* not lint */
 
@@ -167,6 +167,19 @@
        return NULL;
 }
 
+void
+timebase(struct timeval *tv)
+{
+       void *p;
+       struct bintime timebasebin;
+
+       p = lookup("timebasebin");
+       if (!p)
+               return;
+       snarf(p, &timebasebin, sizeof(timebasebin));
+       bintime2timeval(&timebasebin, tv);
+}
+
 static void 
 process_vtw(const vtw_ctl_t * ctl, void (*print)(const vtw_t *))
 {
diff -r 7d12abe6d180 -r 33715d4989d3 usr.bin/netstat/vtw.h
--- a/usr.bin/netstat/vtw.h     Wed May 11 14:52:48 2011 +0000
+++ b/usr.bin/netstat/vtw.h     Wed May 11 15:08:59 2011 +0000
@@ -4,5 +4,6 @@
 void show_vtw_stats(void);
 void show_vtw_v4(void (*)(const vtw_t *));
 void show_vtw_v6(void (*)(const vtw_t *));
+void timebase(struct timeval *);
 
 #endif /* _NETSTAT_VTW_H */



Home | Main Index | Thread Index | Old Index