From owner-freebsd-hackers Sun Feb 3 8:17:29 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from prg.traveller.cz (prg.traveller.cz [193.85.2.77]) by hub.freebsd.org (Postfix) with ESMTP id BEC1237B404 for ; Sun, 3 Feb 2002 08:17:22 -0800 (PST) Received: from prg.traveller.cz (localhost [127.0.0.1]) by prg.traveller.cz (8.12.1[KQ-CZ](1)/8.12.1/pukvis) with ESMTP id g13GHLg7064706 for ; Sun, 3 Feb 2002 17:17:21 +0100 (CET) Received: from localhost (mime@localhost) by prg.traveller.cz (8.12.1[KQ-CZ](1)/pukvis) with ESMTP id g13GHLil064703 for ; Sun, 3 Feb 2002 17:17:21 +0100 (CET) Date: Sun, 3 Feb 2002 17:17:21 +0100 (CET) From: Michal Mertl To: hackers@freebsd.org Subject: unbelievable benchmark output Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 #include #include #include #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