From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jf45H-00067P-IG for qemu-devel@nongnu.org; Thu, 27 Mar 2008 22:12:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jf45E-00061G-KK for qemu-devel@nongnu.org; Thu, 27 Mar 2008 22:12:46 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf45E-000611-Eo for qemu-devel@nongnu.org; Thu, 27 Mar 2008 22:12:44 -0400 Received: from outgoing.csail.mit.edu ([128.30.2.149]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Jf45E-0006zy-6y for qemu-devel@nongnu.org; Thu, 27 Mar 2008 22:12:44 -0400 Date: Thu, 27 Mar 2008 22:12:43 -0400 (EDT) From: David Wentzlaff Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Sender: David Wentzlaff Subject: [Qemu-devel] [PATCH] BIOS delay_ms optimized away with BX_QEMU enabled Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: bochs-developers@lists.sourceforge.net Cc: qemu-devel@nongnu.org When performing SMP probing, smp_probe() waits for 10ms by executing delay_ms(10). When compiling the BIOS for QEMU (BX_QEMU defined), delay_ms() simply spins with a 'for' loop. Unfortunately rombios32.c is compiled with -O2 with the default Makefile and when utilizing current gcc's to compile this file (for instance gcc 4.1.2) this 'for' loop with no side-effects gets dead code eliminated as the compiler should when optimization is enabled. This has the side effect of the Bochs BIOS when running on QEMU to not wait any time during SMP probing. The solution to this problem is to have the 'for' loop perform some work that the compiler will not optimize away such as writing a local volatile variable. Attached is a patch which solves this problem. qemu-devel is CCed as this is primarily a problem specific to QEMU compiled BIOSs. Sincerely, David Wentzlaff Index: rombios32.c =================================================================== RCS file: /cvsroot/bochs/bochs/bios/rombios32.c,v retrieving revision 1.25 diff -d -u -r1.25 rombios32.c --- rombios32.c 26 Mar 2008 16:21:46 -0000 1.25 +++ rombios32.c 28 Mar 2008 02:07:14 -0000 @@ -359,8 +359,11 @@ int i, j; for(i = 0; i < n; i++) { #ifdef BX_QEMU + volatile int k; /* approximative ! */ - for(j = 0; j < 1000000; j++); + for(j = 0; j < 1000000; j++) { + k++; + } #else { int r1, r2;