qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] BIOS delay_ms optimized away with BX_QEMU enabled
@ 2008-03-28  2:12 David Wentzlaff
  2008-03-30 15:41 ` [Qemu-devel] Re: [Bochs-developers] " Kevin O'Connor
  0 siblings, 1 reply; 4+ messages in thread
From: David Wentzlaff @ 2008-03-28  2:12 UTC (permalink / raw)
  To: bochs-developers; +Cc: qemu-devel

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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [Bochs-developers] [PATCH] BIOS delay_ms optimized away with BX_QEMU enabled
  2008-03-28  2:12 [Qemu-devel] [PATCH] BIOS delay_ms optimized away with BX_QEMU enabled David Wentzlaff
@ 2008-03-30 15:41 ` Kevin O'Connor
  2008-03-30 16:48   ` Volker Ruppert
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin O'Connor @ 2008-03-30 15:41 UTC (permalink / raw)
  To: David Wentzlaff; +Cc: bochs-developers, qemu-devel

On Thu, Mar 27, 2008 at 10:12:43PM -0400, David Wentzlaff wrote:
> 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.

Hi David,

Do you know why QEMU uses different code for the delay?  What's wrong
with using inb(0x61) for both bochs and qemu?

Thanks,
-Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [Bochs-developers] [PATCH] BIOS delay_ms optimized away with BX_QEMU enabled
  2008-03-30 15:41 ` [Qemu-devel] Re: [Bochs-developers] " Kevin O'Connor
@ 2008-03-30 16:48   ` Volker Ruppert
  2008-03-30 17:07     ` [Qemu-devel] Re: [Bochs-developers] [PATCH] BIOS delay_ms optimized away with?BX_QEMU enabled Kevin O'Connor
  0 siblings, 1 reply; 4+ messages in thread
From: Volker Ruppert @ 2008-03-30 16:48 UTC (permalink / raw)
  To: bochs-developers; +Cc: Kevin O'Connor, David Wentzlaff, qemu-devel

Hi,

> On Thu, Mar 27, 2008 at 10:12:43PM -0400, David Wentzlaff wrote:
> > 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.
>
> Hi David,
>
> Do you know why QEMU uses different code for the delay?  What's wrong
> with using inb(0x61) for both bochs and qemu?

Bochs really supports the refresh toggle bit of port 0x61, but Qemu toggles on 
every read access. I have created a patch for Qemu that implements the 15 
usec toggle, but the Qemu developers haven't accepted it. They are not sure 
whether the refresh toggle bit exists on modern hardware.

--- /home/volker/qemu/hw/pcspk.c	2006-07-05 01:20:54.000000000 +0200
+++ ./hw/pcspk.c	2006-10-01 19:28:43.952247192 +0200
@@ -38,7 +38,7 @@
     unsigned int samples;
     unsigned int play_pos;
     int data_on;
-    int dummy_refresh_clock;
+    int refresh_clock;
 } PCSpkState;
 
 static const char *s_spk = "pcspk";
@@ -117,10 +117,10 @@
     PCSpkState *s = opaque;
     int out;
 
-    s->dummy_refresh_clock ^= (1 << 4);
+    s->refresh_clock = (((qemu_get_clock(vm_clock) / 15000) & 1) << 4);
     out = pit_get_out(s->pit, 2, qemu_get_clock(vm_clock)) << 5;
 
-    return pit_get_gate(s->pit, 2) | (s->data_on << 1) | 
s->dummy_refresh_clock | out;
+    return pit_get_gate(s->pit, 2) | (s->data_on << 1) | s->refresh_clock | 
out;
 }
 
 static void pcspk_ioport_write(void *opaque, uint32_t addr, uint32_t val)

--
Bye

Volker

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [Bochs-developers] [PATCH] BIOS delay_ms optimized away with?BX_QEMU enabled
  2008-03-30 16:48   ` Volker Ruppert
@ 2008-03-30 17:07     ` Kevin O'Connor
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin O'Connor @ 2008-03-30 17:07 UTC (permalink / raw)
  To: Volker Ruppert; +Cc: bochs-developers, David Wentzlaff, qemu-devel

On Sun, Mar 30, 2008 at 06:48:29PM +0200, Volker Ruppert wrote:
> > Do you know why QEMU uses different code for the delay?  What's wrong
> > with using inb(0x61) for both bochs and qemu?
> 
> Bochs really supports the refresh toggle bit of port 0x61, but Qemu toggles on 
> every read access. I have created a patch for Qemu that implements the 15 
> usec toggle, but the Qemu developers haven't accepted it. They are not sure 
> whether the refresh toggle bit exists on modern hardware.

Ughh.  The same delay mechanism is used in the int/15/86 handler even
on qemu.  See rombios.c:int15_function32().

Is there a better way to implement a usleep function?

Thanks for the info.
-Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-03-30 17:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-28  2:12 [Qemu-devel] [PATCH] BIOS delay_ms optimized away with BX_QEMU enabled David Wentzlaff
2008-03-30 15:41 ` [Qemu-devel] Re: [Bochs-developers] " Kevin O'Connor
2008-03-30 16:48   ` Volker Ruppert
2008-03-30 17:07     ` [Qemu-devel] Re: [Bochs-developers] [PATCH] BIOS delay_ms optimized away with?BX_QEMU enabled Kevin O'Connor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).