Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Jun 2001 10:14:59 -0700 (PDT)
From:      Matt Dillon <dillon@earth.backplane.com>
To:        Alfred Perlstein <bright@sneakerz.org>, Mike Silbersack <silby@FreeBSD.ORG>, cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG, jlemon@FreeBSD.ORG, bmilekic@FreeBSD.ORG
Subject:   Re: cvs commit: src/sys/netinet tcp_input.c tcp_output.c tcp_subr.c tcp_timer.c tcp_usrreq.c tcp_var.h
Message-ID:  <200106231714.f5NHExF72883@earth.backplane.com>
References:  <200106230321.f5N3Llv09510@freefall.freebsd.org> <20010623102801.F57058@sneakerz.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
    Here is a revised test program.  I try to match up the simulation a little
    more closely.  It should be fairly obvious from this script that if 
    the bzero() and the in_pseudo() call can be optimized out of 
    tcp_fillheaders(), the new code will leave the old bcopy() sitting in
    the dust.  And save memory as a nice side effect :-) (oops!  wasn't that
    the original idea of the commit? heh heh heh).

							-Matt


mobile:/home/dillon> ./mt
Test1 - bcopy 20x2 bytes        219.29 nS/loop
Test2 - manual load data         26.72 nS/loop
Test3 - man load w/ptrs          36.36 nS/loop
Test4 - mlptrs & bzero          162.36 nS/loop
Test5 - mlptrszer & call        184.24 nS/loop


/*
 * MEMTEST.C
 */

#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#define LOOPS	1000000

struct DBuf {
    int	x[5];
    int	y[5];
    char notonsamecacheline[256];
} DBuf, Template, Template2, *GlobPtr = &Template2;

static void showtimes(struct timeval *t1, struct timeval *t2, const char *str, int loops);
static void test1(void);
static void test2(void);
static void test3(struct DBuf *template);
static void test4(struct DBuf *template);
static void test5(struct DBuf *template);
static int simplecall(int a, int b, int c);

int
main(int ac, char **av)
{
    struct timeval tbeg;
    struct timeval tend;
    int i;

    test1();
    gettimeofday(&tend, NULL);
    gettimeofday(&tbeg, NULL);
    for (i = LOOPS; i; --i)
	test1();
    gettimeofday(&tend, NULL);
    showtimes(&tbeg, &tend, "Test1 - bcopy 20x2 bytes", LOOPS);

    test2();
    gettimeofday(&tend, NULL);
    gettimeofday(&tbeg, NULL);
    for (i = LOOPS; i; --i)
	test2();
    gettimeofday(&tend, NULL);
    showtimes(&tbeg, &tend, "Test2 - manual load data", LOOPS);

    test3(&Template);
    gettimeofday(&tend, NULL);
    gettimeofday(&tbeg, NULL);
    for (i = LOOPS; i; --i)
	test3(&Template);
    gettimeofday(&tend, NULL);
    showtimes(&tbeg, &tend, "Test3 - man load w/ptrs ", LOOPS);

    test4(&Template);
    gettimeofday(&tend, NULL);
    gettimeofday(&tbeg, NULL);
    for (i = LOOPS; i; --i)
	test4(&Template);
    gettimeofday(&tend, NULL);
    showtimes(&tbeg, &tend, "Test4 - mlptrs & bzero  ", LOOPS);

    test5(&Template);
    gettimeofday(&tend, NULL);
    gettimeofday(&tbeg, NULL);
    for (i = LOOPS; i; --i)
	test5(&Template);
    gettimeofday(&tend, NULL);
    showtimes(&tbeg, &tend, "Test5 - mlptrszer & call", LOOPS);

    return(0);
}

static void
showtimes(struct timeval *t1, struct timeval *t2, const char *str, int loops)
{
    long us;

    us = (t2->tv_usec + 1000000 - t1->tv_usec) + 
	    (t2->tv_sec - t1->tv_sec - 1) * 1000000;
    printf("%s\t%6.2f nS/loop\n", str, (double)us * 1000.0 / (double)loops);
}

static void
test1(void)
{
    bcopy(Template.x, DBuf.x, sizeof(DBuf.x));
    bcopy(Template.y, DBuf.y, sizeof(DBuf.y));
}

static void
test2(void)
{
    DBuf.x[0] = 0;
    DBuf.x[1] = 0;
    DBuf.x[2] = 0;
    DBuf.x[3] = 0;
    DBuf.x[4] = 0;

    DBuf.y[0] = 0;
    DBuf.y[1] = 0;
    DBuf.y[2] = 0;
    DBuf.y[3] = 0;
    DBuf.y[4] = 0;
}

static void
test3(struct DBuf *template)
{
    DBuf.x[0] = 0;
    DBuf.x[1] = GlobPtr->x[1];
    DBuf.x[2] = template->x[2];
    DBuf.x[3] = 0;
    DBuf.x[4] = 0;

    DBuf.y[0] = template->y[0];
    DBuf.y[1] = template->y[1];
    DBuf.y[2] = template->y[2];
    DBuf.y[3] = 5;
    DBuf.y[4] = 0;
}

static void
test4(struct DBuf *template)
{
    bzero(&DBuf.x, sizeof(DBuf.x));
    DBuf.x[0] = 0;
    DBuf.x[1] = GlobPtr->x[1];
    DBuf.x[2] = template->x[2];
    DBuf.x[3] = 0;
    DBuf.x[4] = 0;

    DBuf.y[0] = template->y[0];
    DBuf.y[1] = template->y[1];
    DBuf.y[2] = template->y[2];
    DBuf.y[3] = 5;
    DBuf.y[4] = 0;
}

static void
test5(struct DBuf *template)
{
    bzero(&DBuf.x, sizeof(DBuf.x));
    DBuf.x[0] = 0;
    DBuf.x[1] = GlobPtr->x[1];
    DBuf.x[2] = template->x[2];
    DBuf.x[3] = 0;
    DBuf.x[4] = 0;

    DBuf.y[0] = simplecall(1, 2, 3);
    DBuf.y[1] = template->y[1];
    DBuf.y[2] = template->y[2];
    DBuf.y[3] = 5;
    DBuf.y[4] = 0;
}

static int
simplecall(int a, int b, int c)
{
    return(a + b + c);
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106231714.f5NHExF72883>