Skip to contentSkip to conversation

Disable AIO for Mac OS X

PATCH In review Alexander Graf 3 participants 14 messages Jan 24, 2009 – Jan 25, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Disable AIO for Mac OS X

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

    while (async_ret == NOT_DONE) {
        qemu_aio_wait();
    }

So for the time being, let's simply disable aio for Mac OS X.

---
 configure |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
configure +1 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"
 audio_drv_list="coreaudio"
 audio_possible_drivers="coreaudio sdl fmod"
 OS_LDFLAGS="-framework CoreFoundation -framework IOKit"
+aio="no"
 ;;
 SunOS)
     solaris="yes"
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

    while (async_ret == NOT_DONE) {
        qemu_aio_wait();
    }

Are you using cocoa?

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Regards,

Anthony Liguori

Quoted 20 lines

So for the time being, let's simply disable aio for Mac OS X.

---
 configure |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
configure +1 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"
 audio_drv_list="coreaudio"
 audio_possible_drivers="coreaudio sdl fmod"
 OS_LDFLAGS="-framework CoreFoundation -framework IOKit"
+aio="no"
 ;;
 SunOS)
     solaris="yes"
#2 lore raw
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

   while (async_ret == NOT_DONE) {
       qemu_aio_wait();
   }

Are you using cocoa?

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

Alex

Quoted 29 lines

Regards,

Anthony Liguori

Quoted 20 lines

So for the time being, let's simply disable aio for Mac OS X.

---
configure | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"

audio_drv_list="coreaudio" audio_possible_drivers="coreaudio sdl fmod" OS_LDFLAGS="-framework CoreFoundation -framework IOKit" +aio="no"
;;
SunOS)
solaris="yes"

#3 lore raw
Quoted 13 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

   while (async_ret == NOT_DONE) {
       qemu_aio_wait();
   }
Quoted 7 lines
Quoted 1 line

Are you using cocoa?

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

My guess would be that the completion signal isn't being delivered. I'd start by disabling cocoa and then annotate things to see if the completion signal every makes it to the aio system.

Regards,

Anthony Liguori

Quoted 35 lines

Alex

Quoted 29 lines

Regards,

Anthony Liguori

Quoted 20 lines

So for the time being, let's simply disable aio for Mac OS X.

---
configure | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"

audio_drv_list="coreaudio" audio_possible_drivers="coreaudio sdl fmod" OS_LDFLAGS="-framework CoreFoundation -framework IOKit" +aio="no"
;;
SunOS)
solaris="yes"

#4 lore raw
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

  while (async_ret == NOT_DONE) {
      qemu_aio_wait();
  }

Are you using cocoa?

Quoted 7 lines
Quoted 5 lines

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

My guess would be that the completion signal isn't being delivered. I'd start by disabling cocoa and then annotate things to see if the completion signal every makes it to the aio system.

So disabling cocoa doesn't really help. I recompiled with cocoa=no and still have the same issue:

(gdb) thread apply all bt

Thread 1 (process 38766 thread 0x10b):

#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081526 in qemu_aio_wait () at aio.c:158
#2  0x00081055 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007fb29 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a398 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002b08d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x000442f9 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11da16 "cad", kernel_filename=0x0, kernel_cmdline=0x11d40c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000068d1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520

It's actually hanging in its first select() call.

Alex

Quoted 44 lines

Regards,

Anthony Liguori

Quoted 35 lines

Alex

Quoted 29 lines

Regards,

Anthony Liguori

Quoted 20 lines

So for the time being, let's simply disable aio for Mac OS X.

---
configure | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"

audio_drv_list="coreaudio" audio_possible_drivers="coreaudio sdl fmod" OS_LDFLAGS="-framework CoreFoundation -framework IOKit" +aio="no"
;;
SunOS)
solaris="yes"

#5 lore raw
Quoted 41 lines · Alexander Graf
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

  while (async_ret == NOT_DONE) {
      qemu_aio_wait();
  }

Are you using cocoa?

Quoted 7 lines
Quoted 5 lines

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

My guess would be that the completion signal isn't being delivered. I'd start by disabling cocoa and then annotate things to see if the completion signal every makes it to the aio system.

So disabling cocoa doesn't really help. I recompiled with cocoa=no and still have the same issue:

(gdb) thread apply all bt

Thread 1 (process 38766 thread 0x10b):

#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081526 in qemu_aio_wait () at aio.c:158
#2  0x00081055 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007fb29 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a398 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002b08d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x000442f9 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11da16 "cad", kernel_filename=0x0, kernel_cmdline=0x11d40c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000068d1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520
Quoted 1 line

It's actually hanging in its first select() call.

Is posix-aio init getting called? What is being passed to select? It's waiting for the signalfd to become readable and it's never becoming readable. That could be because you never get the completion signal.

FWIW, at this point, we could drop the signal entirely and just use a pipe for communication. Right now we use a signal that we catch and then write to a pipe from the signal handler. We did this because that's how posix-aio worked but since we don't use posix-aio anymore, we're no longer limited by that.

Regards,

Anthony Liguori

Quoted 47 lines

Alex

Quoted 44 lines

Regards,

Anthony Liguori

Quoted 35 lines

Alex

Quoted 29 lines

Regards,

Anthony Liguori

Quoted 20 lines

So for the time being, let's simply disable aio for Mac OS X.

---
configure | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"

audio_drv_list="coreaudio" audio_possible_drivers="coreaudio sdl fmod" OS_LDFLAGS="-framework CoreFoundation -framework IOKit" +aio="no"
;;
SunOS)
solaris="yes"

#6 lore raw
Quoted 42 lines · Anthony Liguori
Quoted 41 lines · Alexander Graf
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

 while (async_ret == NOT_DONE) {
     qemu_aio_wait();

}

Are you using cocoa?

Quoted 7 lines
Quoted 5 lines

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

My guess would be that the completion signal isn't being delivered. I'd start by disabling cocoa and then annotate things to see if the completion signal every makes it to the aio system.

So disabling cocoa doesn't really help. I recompiled with cocoa=no and still have the same issue:

(gdb) thread apply all bt

Thread 1 (process 38766 thread 0x10b):

#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081526 in qemu_aio_wait () at aio.c:158
#2  0x00081055 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007fb29 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a398 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002b08d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x000442f9 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11da16 "cad", kernel_filename=0x0, kernel_cmdline=0x11d40c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000068d1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520
Quoted 3 lines
Quoted 1 line

It's actually hanging in its first select() call.

Is posix-aio init getting called?

Yes, several times:

haruka:qemu alex$ ./i386-softmmu/qemu -vnc :0 -snapshot ~/Downloads/worms/worms-united.qcow2 posix_aio_init
AIO rd = 5
AIO wr= 6
posix_aio_init
posix_aio_init
posix_aio_init
posix_aio_init
posix_aio_init
add rd(5)...
selecting...

Quoted 1 line

What is being passed to select?

The AIO rd fd.

Quoted 2 lines

It's waiting for the signalfd to become readable and it's never
becoming readable. That could be because you never get the completion signal.

So who sends the signal?

Quoted 1 line

FWIW, at this point, we could drop the signal entirely and just use a pipe for communication. Right now we use a signal that we catch and then write to a pipe from the signal handler. We did this because that's how posix-aio worked but since we don't use posix-aio anymore, we're no longer limited by that.

Hum - sounds like more effort and more probable breakage than tracking this down ;-).

Alex

Quoted 54 lines

Regards,

Anthony Liguori

Quoted 47 lines

Alex

Quoted 44 lines

Regards,

Anthony Liguori

Quoted 35 lines

Alex

Quoted 29 lines

Regards,

Anthony Liguori

Quoted 20 lines

So for the time being, let's simply disable aio for Mac OS X.

---
configure | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index c3fbbbe..3e701b9 100755
@@ -259,6 +259,7 @@ cocoa="yes"

audio_drv_list="coreaudio" audio_possible_drivers="coreaudio sdl fmod" OS_LDFLAGS="-framework CoreFoundation -framework IOKit" +aio="no"
;;
SunOS)
solaris="yes"

#7 lore raw
Quoted 64 lines · Alexander Graf
Quoted 42 lines · Anthony Liguori
Quoted 41 lines · Alexander Graf
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

 while (async_ret == NOT_DONE) {
     qemu_aio_wait();

}

Are you using cocoa?

Quoted 7 lines
Quoted 5 lines

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

My guess would be that the completion signal isn't being delivered. I'd start by disabling cocoa and then annotate things to see if the completion signal every makes it to the aio system.

So disabling cocoa doesn't really help. I recompiled with cocoa=no and still have the same issue:

(gdb) thread apply all bt

Thread 1 (process 38766 thread 0x10b):

#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081526 in qemu_aio_wait () at aio.c:158
#2  0x00081055 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007fb29 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a398 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002b08d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x000442f9 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11da16 "cad", kernel_filename=0x0, kernel_cmdline=0x11d40c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000068d1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520
Quoted 3 lines
Quoted 1 line

It's actually hanging in its first select() call.

Is posix-aio init getting called?

Yes, several times:

haruka:qemu alex$ ./i386-softmmu/qemu -vnc :0 -snapshot ~/Downloads/worms/worms-united.qcow2 posix_aio_init
AIO rd = 5
AIO wr= 6
posix_aio_init
posix_aio_init
posix_aio_init
posix_aio_init
posix_aio_init
add rd(5)...
selecting...

Quoted 8 lines
Quoted 1 line

What is being passed to select?

The AIO rd fd.

Quoted 2 lines

It's waiting for the signalfd to become readable and it's never
becoming readable. That could be because you never get the completion signal.

So who sends the signal?

posix-aio-compat.c:aio_thread() ... kill(getpid(), )

I'd add a printf to see if the signal is getting sent (means op has completed) and then another one in block-raw-posix.c:aio_signal_handler() to see if we're receiving the signal.

If for some crazy reason the OS X port spawns another thread somewhere without masking SIGUSR2 correctly, it could be that the signal is getting lost.

Regards,

Anthony Liguori

Quoted 5 lines
Quoted 1 line

FWIW, at this point, we could drop the signal entirely and just use a pipe for communication. Right now we use a signal that we catch and then write to a pipe from the signal handler. We did this because that's how posix-aio worked but since we don't use posix-aio anymore, we're no longer limited by that.

Hum - sounds like more effort and more probable breakage than tracking this down ;-).

Alex

#8 lore raw

Good Morning :)

Quoted 69 lines · Anthony Liguori
Quoted 68 lines · Alexander Graf
Quoted 42 lines · Anthony Liguori
Quoted 41 lines · Alexander Graf
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Alexander Graf

While trying current svn, it looks like AIO support compiles on Mac OS X finally. Unfortunately it is broken and as soon as I want to run any image, it endless loops in block.c:1446 which is:

while (async_ret == NOT_DONE) {
    qemu_aio_wait();
}

Are you using cocoa?

Quoted 7 lines
Quoted 5 lines

Yep. Nothing else works for x86_64 on Mac OS X ;-). Well - except for vnc.

Quoted 1 line

I don't think the AIO code is broken here. I think something else is broken and disabling AIO hides the symptom. Can you dig more into this?

Hum - sounds like an idea. I'm open for hints on how to dig in here. I can disable cocoa for starters of course.

My guess would be that the completion signal isn't being delivered. I'd start by disabling cocoa and then annotate things to see if the completion signal every makes it to the aio system.

So disabling cocoa doesn't really help. I recompiled with cocoa=no and still have the same issue:

(gdb) thread apply all bt

Thread 1 (process 38766 thread 0x10b):

#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081526 in qemu_aio_wait () at aio.c:158
#2  0x00081055 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007fb29 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a398 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002b08d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x000442f9 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11da16 "cad", kernel_filename=0x0, kernel_cmdline=0x11d40c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000068d1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520
Quoted 3 lines
Quoted 1 line

It's actually hanging in its first select() call.

Is posix-aio init getting called?

Yes, several times:

haruka:qemu alex$ ./i386-softmmu/qemu -vnc :0 -snapshot ~/Downloads/worms/worms-united.qcow2 posix_aio_init
AIO rd = 5
AIO wr= 6
posix_aio_init
posix_aio_init
posix_aio_init
posix_aio_init
posix_aio_init
add rd(5)...
selecting...

Quoted 1 line

What is being passed to select?

The AIO rd fd.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

It's waiting for the signalfd to become readable and it's never becoming readable. That could be because you never get the completion signal.

So who sends the signal?

posix-aio-compat.c:aio_thread() ... kill(getpid(), )

I'd add a printf to see if the signal is getting sent (means op has completed) and then another one in block-raw-posix.c:aio_signal_handler() to see if we're receiving the signal.

The kill() is called, but we're never receiving the signal. Also when I kill -31 manually from the outside, the signal handler isn't invoked.

Quoted 1 line

If for some crazy reason the OS X port spawns another thread somewhere without masking SIGUSR2 correctly, it could be that the signal is getting lost.

Hm - according to gdb things look pretty normal, no?

(gdb) thread apply all bt

Thread 2 (process 804 thread 0x1003):

#0  0x91b3c3ae in __semwait_signal ()
#1  0x91b67326 in _pthread_cond_wait ()
#2  0x91b8c9f0 in pthread_cond_timedwait$UNIX2003 ()
#3  0x000157b5 in aio_thread (unused=0x0) at posix-aio-compat.c:52
#4  0x91b66095 in _pthread_start ()
#5  0x91b65f52 in thread_start ()

Thread 1 (process 804 thread 0x10b):

#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081443 in qemu_aio_wait () at aio.c:173
#2  0x00080ef5 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007f9c9 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a238 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002af2d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x00044199 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11d946 "cad", kernel_filename=0x0, kernel_cmdline=0x11d33c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000066e1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520

Alex

Quoted 12 lines

Regards,

Anthony Liguori

Quoted 5 lines
Quoted 1 line

FWIW, at this point, we could drop the signal entirely and just use a pipe for communication. Right now we use a signal that we catch and then write to a pipe from the signal handler. We did this because that's how posix-aio worked but since we don't use posix-aio anymore, we're no longer limited by that.

Hum - sounds like more effort and more probable breakage than tracking this down ;-).

Alex

#9 lore raw
Quoted 1 line · Alexander Graf

The kill() is called, but we're never receiving the signal. Also when I kill -31 manually from the outside, the signal handler isn't invoked.

Anyone know much about signal delivery in Darwin? Is there a way to do thread signaling directly?

Quoted 15 lines
Quoted 1 line

If for some crazy reason the OS X port spawns another thread somewhere without masking SIGUSR2 correctly, it could be that the signal is getting lost.

Hm - according to gdb things look pretty normal, no?

(gdb) thread apply all bt

Thread 2 (process 804 thread 0x1003):

#0  0x91b3c3ae in __semwait_signal ()
#1  0x91b67326 in _pthread_cond_wait ()
#2  0x91b8c9f0 in pthread_cond_timedwait$UNIX2003 ()
#3  0x000157b5 in aio_thread (unused=0x0) at posix-aio-compat.c:52
#4  0x91b66095 in _pthread_start ()
#5  0x91b65f52 in thread_start ()

Thread 1 (process 804 thread 0x10b):

Quoted 8 lines
#0  0x91b846f2 in select$DARWIN_EXTSN ()
#1  0x00081443 in qemu_aio_wait () at aio.c:173
#2  0x00080ef5 in bdrv_read_em (bs=0x4, sector_num=0, buf=0x4 <Address 0x4 out of bounds>, nb_sectors=4) at block.c:1447
#3  0x0007f9c9 in bdrv_guess_geometry (bs=0x806a00, pcyls=0xbfffdfcc, pheads=0xbfffdfc8, psecs=0xbfffdfc4) at block.c:773
#4  0x0002a238 in ide_init2 (ide_state=<value temporarily unavailable, due to optimizations>, hd0=0x806a00, hd1=0x0, irq=0x402a18) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:2844
#5  0x0002af2d in pci_piix3_ide_init (bus=0x4, hd_table=0xbfffeaf0, devfn=4, pic=0x402930) at /Users/alex/work/qemu-osx/qemu/hw/ide.c:3435
#6  0x00044199 in pc_init1 (ram_size=<value temporarily unavailable, due to optimizations>, vga_ram_size=8388608, boot_device=0x11d946 "cad", kernel_filename=0x0, kernel_cmdline=0x11d33c "", initrd_filename=0x0, pci_enabled=1, cpu_model=0x0) at /Users/alex/work/qemu-osx/qemu/hw/pc.c:1027
#7  0x000066e1 in main (argc=5, argv=0xbffff360, envp=0xbffff378) at /Users/alex/work/qemu-osx/qemu/vl.c:5520

Can you dump the sigmasks of each thread to see if they're blocking them correctly? Perhaps thread 2 is receiving the SIGUSR2 for some weird reason?

Maybe try a different signal. Maybe SIGUSR2 has some significance in Darwin.

Regards,

Anthony Liguori

Quoted 15 lines

Alex

Quoted 12 lines

Regards,

Anthony Liguori

Quoted 5 lines
Quoted 1 line

FWIW, at this point, we could drop the signal entirely and just use a pipe for communication. Right now we use a signal that we catch and then write to a pipe from the signal handler. We did this because that's how posix-aio worked but since we don't use posix-aio anymore, we're no longer limited by that.

Hum - sounds like more effort and more probable breakage than tracking this down ;-).

Alex

#10 lore raw
Quoted 6 lines · Anthony Liguori
Quoted 2 lines · Alexander Graf

The kill() is called, but we're never receiving the signal. Also when I kill -31 manually from the outside, the signal handler isn't invoked.

Anyone know much about signal delivery in Darwin? Is there a way to do thread signaling directly?

Try pthread_kill()? That should work on everything. Btw, a pipe might be faster.

-- Jamie

#11 lore raw
Quoted 10 lines · Jamie Lokier
Quoted 6 lines · Anthony Liguori
Quoted 2 lines · Alexander Graf

The kill() is called, but we're never receiving the signal. Also when I kill -31 manually from the outside, the signal handler isn't invoked.

Anyone know much about signal delivery in Darwin? Is there a way to do thread signaling directly?

Try pthread_kill()? That should work on everything. Btw, a pipe might be faster.

Yeah, writing to a pipe is going too be a much better overall solution.

Regards,

Anthony Liguori

Quoted 4 lines

-- Jamie

#12 lore raw
In reply to Jamie Lokier
Quoted 9 lines · Jamie Lokier
Quoted 6 lines · Anthony Liguori
Quoted 2 lines · Alexander Graf

The kill() is called, but we're never receiving the signal. Also when I kill -31 manually from the outside, the signal handler isn't invoked.

Anyone know much about signal delivery in Darwin? Is there a way to do thread signaling directly?

Try pthread_kill()? That should work on everything.

pthread_kill doesn't help, neither does SIGUSR1. I'll try out more later.

Alex

Quoted 4 lines

Btw, a pipe might be faster.

-- Jamie

#13 lore raw
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Jamie Lokier
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Alexander Graf

The kill() is called, but we're never receiving the signal. Also when I kill -31 manually from the outside, the signal handler isn't invoked.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Anyone know much about signal delivery in Darwin? Is there a way to do thread signaling directly?

Try pthread_kill()? That should work on everything.

pthread_kill doesn't help, neither does SIGUSR1. I'll try out more later.

Does this help?

Regards,

Anthony Liguori

Quoted 9 lines

Alex

Quoted 4 lines

Btw, a pipe might be faster.

-- Jamie

Subject: [PATCH] Do not use signals in posix-aio

The signal-select race forces us to use a file descriptor for posix-aio notification. Currently, we use a pipe and write to it from the signal handler because normal posix-aio does not provide file descriptor notification support.

Since we now emulation posix-aio on our own, we can clean things up and just use a file descriptor for notification.

N.B. This is almost certainly going to cause regressions until we fix the select loop to run in a separate thread since there will no longer be a signal that breaks us out of the TCG run loop. We need to hold off on applying this patch until that is fixed properly.

block-raw-posix.c +3 -17
index 4404eb1..cae4408 100644
@@ -511,20 +511,11 @@ static int posix_aio_flush(void *opaque)
 
 static PosixAioState *posix_aio_state;
 
-static void aio_signal_handler(int signum)
-{
-    if (posix_aio_state) {
-        char byte = 0;
-
-        write(posix_aio_state->wfd, &byte, sizeof(byte));
-    }
-
-    qemu_service_io();
-}
+/* FIXME need to fix the select() loop issue b/c this IO will not
+ * necessarily break out us out the TCG loop */
 
 static int posix_aio_init(void)
 {
-    struct sigaction act;
     PosixAioState *s;
     int fds[2];
     struct qemu_paioinit ai;
@@ -536,11 +527,6 @@ static int posix_aio_init(void)
     if (s == NULL)
         return -ENOMEM;
 
-    sigfillset(&act.sa_mask);
-    act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
-    act.sa_handler = aio_signal_handler;
-    sigaction(SIGUSR2, &act, NULL);
-
     s->first_aio = NULL;
     if (pipe(fds) == -1) {
         fprintf(stderr, "failed to create pipe\n");
@@ -579,7 +565,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs,
     if (!acb)
         return NULL;
     acb->aiocb.aio_fildes = s->fd;
-    acb->aiocb.ev_signo = SIGUSR2;
+    acb->aiocb.ev_fd = posix_aio_state->wfd;
     acb->aiocb.aio_buf = buf;
     if (nb_sectors < 0)
         acb->aiocb.aio_nbytes = -nb_sectors;
posix-aio-compat.c +10 -2
index f141cd9..4409899 100644
@@ -27,6 +27,15 @@ static int cur_threads = 0;
 static int idle_threads = 0;
 static TAILQ_HEAD(, qemu_paiocb) request_list;
 
+static void signal_fd(int fd)
+{
+    ssize_t len;
+    do {
+        char value = 1;
+        len = write(fd, &value, 1);
+    } while (len == -1 && errno == EINTR);
+}
+
 static void *aio_thread(void *unused)
 {
     sigset_t set;
@@ -92,9 +101,8 @@ static void *aio_thread(void *unused)
         pthread_mutex_lock(&lock);
         aiocb->ret = offset;
         idle_threads++;
+        signal_fd(aiocb->ev_fd);
         pthread_mutex_unlock(&lock);
-
-        kill(getpid(), aiocb->ev_signo);
     }
 
     idle_threads--;
posix-aio-compat.h +1 -1
index 0bc10f5..ec17bb6 100644
@@ -29,7 +29,7 @@ struct qemu_paiocb
     int aio_fildes;
     void *aio_buf;
     size_t aio_nbytes;
-    int ev_signo;
+    int ev_fd;
     off_t aio_offset;
 
     /* private */