Date: Sun, 3 Feb 2002 17:17:21 +0100 (CET) From: Michal Mertl <mime@traveller.cz> To: hackers@freebsd.org Subject: unbelievable benchmark output Message-ID: <Pine.BSF.4.41.0202021843210.5132-100000@prg.traveller.cz>
next in thread | raw e-mail | index | archive | help
I wrote a simple program which does this: gettimeofday something (takes several seconds) gettimeofday print time elapsed Several runs of the program take about the same time but the time changes wildly when the executable is called differently. ------- ./xx/xxx 5 s xx/xxx 9 s and similar. It holds true on vastly different machines with current and stable. The only thing which I can think of that can be causing this is some memory alignment issue. It makes me a bit scared - if the filename or argv[0] make program load to different address than it can probaly mean that even normal programs can suffer significatnly from this. Alignment, which does gcc would probably be mostly useless than. Does the system care where is loads the program image at all? Compile the code below with gcc -O -march=pentiumpro and save the program to /tmp/x (1x) and /tmp/xxxxxxxxxxx (11x). cd /tmp; ./x shows me 0.490495 (with slight variations amongst runs) and ./xxxxxxxxxxx 1.016591. The real results depend on hw but they occur always with different differences in speed and the length of name of fast/slow programs. BTW: The program doesn't have to contain assembly it seems but with the program below the results are most visible. ---------- 8< -------- #include <sys/types.h> #include <sys/time.h> #include <stdio.h> #include <stdlib.h> #define NUMTESTS 10000000 static inline void atomic_add_64(volatile u_int64_t *p, u_int64_t v) { __asm __volatile ( " movl (%0),%%eax ; " " movl 4(%0),%%edx ; " " 1:movl (%1),%%ebx ; " " movl 4(%1),%%ecx ; " " addl %%eax,%%ebx ; " " adcl %%edx,%%ecx ; " " cmpxchg8b (%0) ; " " jnz 1b ; " "#atomic_add_64" : : "S" (p), /* 0 */ "D" (&v) /* 1 */ : "eax", "ebx", "ecx", "edx", "memory" ); } void difftimeval(struct timeval start, struct timeval *end) { if (end->tv_usec < start.tv_usec) { end->tv_usec += (1000000 - start.tv_usec); end->tv_sec--; } else end->tv_usec -= start.tv_usec; end->tv_sec -= start.tv_sec; } int main() { u_int64_t i, j; int k; struct timeval st, en; i = 0; j = 10; gettimeofday(&st, NULL); for (k = 0; k < NUMTESTS; k++) { atomic_add_64(&i, j); } gettimeofday(&en, NULL); difftimeval(st, &en); printf("%lu.%06lu\n", en.tv_sec, en.tv_usec); return (EXIT_SUCCESS); } --------- 8< ---- -- Michal Mertl mime@traveller.cz To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.41.0202021843210.5132-100000>