Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Mar 2000 18:23:01 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        freebsd-current@FreeBSD.ORG
Subject:   SMP syscall timing program (was Re: Why are all accesses to the cpl surrounded by a lock?)
Message-ID:  <200003260223.SAA26218@apollo.backplane.com>
References:  <200003250527.VAA19096@apollo.backplane.com> <20000325130447.I21029@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
:Otherwise right now your guess is as good as mine.
:
:As a side note, it seems silly that we do this:
:
:        MPLOCKED incl _cnt+V_SYSCALL
:        SYSCALL_LOCK
:        call    _syscall
:
:I think per-cpu statistics would be an interesting optimization,
:since you're testing all of this, have you been able to measure
:the getuid() loop with and without this (MPLOCKED incl _cnt+V_SYSCALL),
:especially with 2 processes doing a getuid() loop?
:
:-- 
:-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]

    Well, in my patch SYSCALL_LOCK is no longer called there so
    we can't move the incl and remove the MPLOCKED prefix.  A competing
    locked instruction costs around 200 nS.  I.E. it's expensive, which
    is why zone locks aren't a good idea and structural locks are.

    I've enclosed my syscall timing program.  I will also put it on
    my site.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>



/*
 * SMPTIME.C
 *
 *	cc smptime.c -o smptime -Wall -DOP=OPn
 *	./smptime NFORK
 *
 *	e.g.
 *
 *	cc smptime.c -o smptime -Wall -DOP=OP3
 *	./smptime 1
 *	./smptime 2
 */

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

void deltatime(struct timeval *tv1);
void FigureOutUseCount(void);

#define OP1 sigprocmask(SIG_BLOCK, &sset, &oset);
#define OP2 getpid()
#define OP3 getuid()		/* CLEAN OF MP LOCK */
#define OP4 __asm __volatile("addl $1,(%0)"::"r"(global_tmp):"memory")
#define OP5 __asm __volatile("lock; addl $1,(%0)"::"r"(global_tmp):"memory")
#define OP6
#ifndef OP
#error "Missing -DOP=OPn option to cc"
#endif

#define OPNAME(V)	#V

int *global_tmp;
int UseCount = 1;

int
main(int ac, char **av)
{
    int i;
    int count = 0;
    int nproc = 2;
    sigset_t sset;
    sigset_t oset;
    struct timeval tv1;

    if (ac == 2)
	nproc = strtol(av[1], NULL, 0);

    sigemptyset(&sset);
    sigemptyset(&oset);
    gettimeofday(&tv1, NULL);
    global_tmp = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0);

    FigureOutUseCount();

    for (i = 1; i < nproc; ++i) {
	if (fork() == 0) {
	    /*
	     * child
	     */
	    for (;;) {
		OP;
	    }
	    _exit(0);
	}
    }
    /*
     * parent
     */
    for (;;) {
	OP;
	if (++count == UseCount) {
	    deltatime(&tv1);
	    count = 0;
	}
    }
    return(0);
}

void
deltatime(struct timeval *tv1)
{
    struct timeval tv2;
    int usec;

    gettimeofday(&tv2, NULL);
    usec = tv2.tv_usec + 1000000 - tv1->tv_usec + 1000000 * (tv2.tv_sec - tv1->tv_sec - 1);
    *tv1 = tv2;
    printf("%d nsec/call\n", usec / (UseCount / 1000));
}


/*
 *  Time one second's worth of loops to get a baseline.
 */

jmp_buf TimeEnv;

void
sigAlrm(int sigNo)
{
    longjmp(TimeEnv, 1);
}

void
FigureOutUseCount(void)
{
    struct itimerval it;

    bzero(&it, sizeof(it));
    it.it_value.tv_sec = 1;

    signal(SIGALRM, sigAlrm);
    setitimer(ITIMER_REAL, &it, NULL);
    if (setjmp(TimeEnv) == 0) {
	for (;;) {
	    OP;
	    ++UseCount;
	}
	/* NOT REACHED */
    }
    signal(SIGALRM, SIG_IGN);
}



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




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