From owner-freebsd-current Sat Mar 25 18:23: 6 2000 Delivered-To: freebsd-current@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by hub.freebsd.org (Postfix) with ESMTP id A0C6237B7F7 for ; Sat, 25 Mar 2000 18:23:02 -0800 (PST) (envelope-from dillon@apollo.backplane.com) Received: (from dillon@localhost) by apollo.backplane.com (8.9.3/8.9.1) id SAA26218; Sat, 25 Mar 2000 18:23:01 -0800 (PST) (envelope-from dillon) Date: Sat, 25 Mar 2000 18:23:01 -0800 (PST) From: Matthew Dillon Message-Id: <200003260223.SAA26218@apollo.backplane.com> To: Alfred Perlstein Cc: freebsd-current@FreeBSD.ORG Subject: SMP syscall timing program (was Re: Why are all accesses to the cpl surrounded by a lock?) References: <200003250527.VAA19096@apollo.backplane.com> <20000325130447.I21029@fw.wintelcom.net> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG :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 /* * 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 #include #include #include #include #include #include #include #include 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