Source-Changes-HG archive

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

[src/trunk]: src/sys This is the "kttcp" network throughput testing pseudo-de...



details:   https://anonhg.NetBSD.org/src/rev/b3ce951e5fb6
branches:  trunk
changeset: 533376:b3ce951e5fb6
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jun 28 23:27:13 2002 +0000

description:
This is the "kttcp" network throughput testing pseudo-device.  From
the block comment at the top of the file:

      This module provides kernel support for testing network
      throughput from the perspective of the kernel.  It is
      similar in spirit to the classic ttcp network benchmark
      program, the main difference being that with kttcp, the
      kernel is the source and sink of the data.

      Testing like this is useful for a few reasons:

      1. This allows us to know what kind of performance we can
         expect from network applications that run in the kernel
         space, such as the NFS server or the NFS client.  These
         applications don't have to move the data to/from userspace,
         and so benchmark programs which run in userspace don't
         give us an accurate model.

      2. Since data received is just thrown away, the receiver
         is very fast.  This can provide better exercise for the
         sender at the other end.

      3. Since the NetBSD kernel currently uses a run-to-completion
         scheduling model, kttcp provides a benchmark model where
         preemption of the benchmark program is not an issue.

There is a companion "kttcp" user program which uses the kttcp
pseudo-device.

Largely written by Frank van der Linden, with some modifications
from me.

diffstat:

 sys/conf/files    |    6 +-
 sys/dev/Makefile  |    4 +-
 sys/dev/kttcp.c   |  634 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/kttcpio.h |   58 ++++
 4 files changed, 699 insertions(+), 3 deletions(-)

diffs (truncated from 737 to 300 lines):

diff -r 5c767313b8c1 -r b3ce951e5fb6 sys/conf/files
--- a/sys/conf/files    Fri Jun 28 22:45:21 2002 +0000
+++ b/sys/conf/files    Fri Jun 28 23:27:13 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.538 2002/06/28 22:32:58 drochner Exp $
+#      $NetBSD: files,v 1.539 2002/06/28 23:27:13 thorpej Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -921,6 +921,10 @@
 defpseudo irip:                isdndev, ifnet
 defpseudo ippp:                isdndev, sppp, ifnet
 
+# KTTCP network throughput testing pseudo-device
+defpseudo kttcp
+file   dev/kttcp.c                     kttcp           needs-flag
+
 #
 # File systems
 #
diff -r 5c767313b8c1 -r b3ce951e5fb6 sys/dev/Makefile
--- a/sys/dev/Makefile  Fri Jun 28 22:45:21 2002 +0000
+++ b/sys/dev/Makefile  Fri Jun 28 23:27:13 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.10 2001/12/04 21:43:44 augustss Exp $
+#      $NetBSD: Makefile,v 1.11 2002/06/28 23:27:14 thorpej Exp $
 
 SUBDIR=        ata dec hpc i2o ic ir isa ofw pci pckbc pcmcia raidframe \
        sbus scsipi sun tc usb vme wscons 
@@ -7,6 +7,6 @@
 INCSDIR= /usr/include/dev
 
 # Only install includes which are used by userland
-INCS=  ccdvar.h md.h vndvar.h
+INCS=  ccdvar.h kttcpio.h md.h vndvar.h
 
 .include <bsd.kinc.mk>
diff -r 5c767313b8c1 -r b3ce951e5fb6 sys/dev/kttcp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/kttcp.c   Fri Jun 28 23:27:13 2002 +0000
@@ -0,0 +1,634 @@
+/*     $NetBSD: kttcp.c,v 1.1 2002/06/28 23:27:14 thorpej Exp $        */
+
+/*
+ * Copyright (c) 2002 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden and Jason R. Thorpe for
+ * Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed for the NetBSD Project by
+ *     Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * kttcp.c --
+ *
+ *     This module provides kernel support for testing network
+ *     throughput from the perspective of the kernel.  It is
+ *     similar in spirit to the classic ttcp network benchmark
+ *     program, the main difference being that with kttcp, the
+ *     kernel is the source and sink of the data.
+ *
+ *     Testing like this is useful for a few reasons:
+ *
+ *     1. This allows us to know what kind of performance we can
+ *        expect from network applications that run in the kernel
+ *        space, such as the NFS server or the NFS client.  These
+ *        applications don't have to move the data to/from userspace,
+ *        and so benchmark programs which run in userspace don't
+ *        give us an accurate model.
+ *
+ *     2. Since data received is just thrown away, the receiver
+ *        is very fast.  This can provide better exercise for the
+ *        sender at the other end.
+ *
+ *     3. Since the NetBSD kernel currently uses a run-to-completion
+ *        scheduling model, kttcp provides a benchmark model where
+ *        preemption of the benchmark program is not an issue.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/conf.h>
+#include <sys/systm.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/resourcevar.h>
+#include <sys/signal.h>
+#include <sys/socketvar.h>
+#include <sys/socket.h>
+#include <sys/mbuf.h>
+#include <sys/mount.h>
+#include <sys/syscallargs.h>
+
+#include <dev/kttcpio.h>
+
+static int kttcp_send(struct proc *p, struct kttcp_io_args *);
+static int kttcp_recv(struct proc *p, struct kttcp_io_args *);
+static int kttcp_sosend(struct socket *, unsigned long long,
+                       unsigned long long *, struct proc *, int);
+static int kttcp_soreceive(struct socket *, unsigned long long,
+                          unsigned long long *, struct proc *, int *);
+
+void   kttcpattach(int);
+
+cdev_decl(kttcp);
+
+void
+kttcpattach(int count)
+{
+       /* Do nothing. */
+}
+
+int
+kttcpopen(dev_t dev, int flags, int fmt, struct proc *p)
+{
+
+       /* Always succeeds. */
+       return (0);
+}
+
+int
+kttcpclose(dev_t dev, int flags, int fmt, struct proc *p)
+{
+
+       /* Always succeeds. */
+       return (0);
+}
+
+int
+kttcpioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+       int error;
+
+       if ((flag & FWRITE) == 0)
+               return EPERM;
+
+       switch (cmd) {
+       case KTTCP_IO_SEND:
+               error = kttcp_send(p, (struct kttcp_io_args *) data);
+               break;
+
+       case KTTCP_IO_RECV:
+               error = kttcp_recv(p, (struct kttcp_io_args *) data);
+               break;
+
+       default:
+               return EINVAL;
+       }
+
+       return error;
+}
+
+static int
+kttcp_send(struct proc *p, struct kttcp_io_args *kio)
+{
+       struct file *fp;
+       int error;
+       struct timeval t0, t1;
+       unsigned long long len, done;
+
+       if (kio->kio_totalsize >= KTTCP_MAX_XMIT)
+               return EINVAL;
+
+       fp = fd_getfile(p->p_fd, kio->kio_socket);
+       if (fp == NULL)
+               return EBADF;
+       if (fp->f_type != DTYPE_SOCKET)
+               return EFTYPE;
+
+       len = kio->kio_totalsize;
+       microtime(&t0);
+       do {
+               error = kttcp_sosend((struct socket *)fp->f_data, len,
+                   &done, p, 0);
+               len -= done;
+       } while (error == 0 && len > 0);
+       microtime(&t1);
+       if (error != 0)
+               return error;
+       timersub(&t1, &t0, &kio->kio_elapsed);
+
+       kio->kio_bytesdone = kio->kio_totalsize - len;
+
+       return 0;
+}
+
+static int
+kttcp_recv(struct proc *p, struct kttcp_io_args *kio)
+{
+       struct file *fp;
+       int error;
+       struct timeval t0, t1;
+       unsigned long long len, done;
+
+       if (kio->kio_totalsize > KTTCP_MAX_XMIT)
+               return EINVAL;
+
+       fp = fd_getfile(p->p_fd, kio->kio_socket);
+       if (fp == NULL || fp->f_type != DTYPE_SOCKET)
+               return EBADF;
+       len = kio->kio_totalsize;
+       microtime(&t0);
+       do {
+               error = kttcp_soreceive((struct socket *)fp->f_data,
+                   len, &done, p, NULL);
+               len -= done;
+       } while (error == 0 && len > 0 && done > 0);
+       microtime(&t1);
+       if (error == EPIPE)
+               error = 0;
+       if (error != 0)
+               return error;
+       timersub(&t1, &t0, &kio->kio_elapsed);
+
+       kio->kio_bytesdone = kio->kio_totalsize - len;
+
+       return 0;
+}
+
+#define SBLOCKWAIT(f)   (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
+
+/*
+ * Slightly changed version of sosend()
+ */
+static int
+kttcp_sosend(struct socket *so, unsigned long long slen,
+            unsigned long long *done, struct proc *p, int flags)
+{
+       struct mbuf **mp, *m, *top;
+       long space, len, mlen;
+       int error, s, dontroute, atomic;
+       long long resid;
+
+       atomic = sosendallatonce(so);
+       resid = slen;
+       top = NULL;
+       /*
+        * In theory resid should be unsigned.
+        * However, space must be signed, as it might be less than 0
+        * if we over-committed, and we must use a signed comparison
+        * of space and resid.  On the other hand, a negative resid
+        * causes us to loop sending 0-length segments to the protocol.
+        */
+       if (resid < 0) {
+               error = EINVAL;
+               goto out;
+       }
+       dontroute =
+           (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
+           (so->so_proto->pr_flags & PR_ATOMIC);
+       p->p_stats->p_ru.ru_msgsnd++;
+#define        snderr(errno)   { error = errno; splx(s); goto release; }
+
+ restart:
+       if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))) != 0)
+               goto out;
+       do {
+               s = splsoftnet();
+               if (so->so_state & SS_CANTSENDMORE)
+                       snderr(EPIPE);
+               if (so->so_error) {
+                       error = so->so_error;
+                       so->so_error = 0;
+                       splx(s);
+                       goto release;
+               }
+               if ((so->so_state & SS_ISCONNECTED) == 0) {
+                       if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
+                               if ((so->so_state & SS_ISCONFIRMING) == 0)
+                                       snderr(ENOTCONN);



Home | Main Index | Thread Index | Old Index