From 7df7fc34a30c4dbde5d2e35e6bee7aff30bb88e3 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Wed, 13 Jun 2007 06:17:48 +0000 Subject: [PATCH] Unbreak high resolution profiling a little: use dummy asms to prevent timing loops being optimized away. Once apon a time, gcc promised not to optimize away timing loops, but gcc started optimizing away the call to a null function in the timing loop here some time between gcc-3.3.3 and gcc-3.4.6, and it started optimizing away the timing loop itself some time between gcc-3.4.6 and gcc-4.2. --- sys/libkern/mcount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/libkern/mcount.c b/sys/libkern/mcount.c index d967fe8bb254..e26f6fab3428 100644 --- a/sys/libkern/mcount.c +++ b/sys/libkern/mcount.c @@ -268,18 +268,23 @@ mexitcount(selfpc) } } +#ifndef __GNUCLIKE_ASM +#error "This file uses null asms to prevent timing loops being optimized away." +#endif + void empty_loop() { int i; for (i = 0; i < CALIB_SCALE; i++) - ; + __asm __volatile(""); } void nullfunc() { + __asm __volatile(""); } void