Skip to contentSkip to conversation

Introduce hard dependency on glib

RFC In review Anthony Liguori 22 participants 101 messages Jan 24, 2011 – Feb 11, 2011 1 message not in the archive Kbuild

lore
Share & tools
lore
#0 lore raw

cover Introduce hard dependency on glib

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

On the other hand, while GObjects are uglier and require a lot of template code, there's more than enough structure that I think it can guide us into a much better object model implementation.

There is some ugliness. GLib does not abstract signals because they're very
non-portable but QEMU makes extensive use of signaling. I don't think it's a major issue but some of the ugliness in this series is due to that fact.

This series is only lightly tested but also mostly mechanical. I'm pretty confused by the way tcg_halt_cond and friends works so I'm fairly sure I broke that (for non-threaded TCG).

#1 lore raw

PATCH 1/7 io-thread: make sure to initialize qemu_work_cond and qemu_cpu_cond

cpus.c +3 -1
index 0309189..9cf7e6e 100644
@@ -412,8 +412,10 @@ int qemu_init_main_loop(void)
     if (ret)
         return ret;
 
-    qemu_cond_init(&qemu_pause_cond);
+    qemu_cond_init(&qemu_cpu_cond);
     qemu_cond_init(&qemu_system_cond);
+    qemu_cond_init(&qemu_pause_cond);
+    qemu_cond_init(&qemu_work_cond);
     qemu_mutex_init(&qemu_fair_mutex);
     qemu_mutex_init(&qemu_global_mutex);
     qemu_mutex_lock(&qemu_global_mutex);
Signature · 1 line
1.7.0.4
#2 lore raw

[Qemu-devel] Re: [PATCH 1/7] io-thread: make sure to initialize qemu_work_cond and qemu_cpu_cond

Quoted 8 lines · Anthony Liguori
cpus.c +0 -0
index 0309189..9cf7e6e 100644
@@ -412,8 +412,10 @@ int qemu_init_main_loop(void)
     if (ret)

cpus.c int qemu_init_main_loop(void) · line 421

Quoted 10 lines
cpus.c +3 -1
         return ret;
 
-    qemu_cond_init(&qemu_pause_cond);
+    qemu_cond_init(&qemu_cpu_cond);
     qemu_cond_init(&qemu_system_cond);
+    qemu_cond_init(&qemu_pause_cond);
+    qemu_cond_init(&qemu_work_cond);
     qemu_mutex_init(&qemu_fair_mutex);
     qemu_mutex_init(&qemu_global_mutex);
     qemu_mutex_lock(&qemu_global_mutex);

Please merge this independently of the glib patches. It's apparently harmless only by chance so far.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#3 lore raw

Re: [Qemu-devel] Re: [PATCH 1/7] io-thread: make sure to initialize qemu_work_cond and qemu_cpu_cond

Quoted 12 lines · Jan Kiszka
Quoted 10 lines · Anthony Liguori
cpus.c +0 -0
index 0309189..9cf7e6e 100644
@@ -412,8 +412,10 @@ int qemu_init_main_loop(void)
      if (ret)
          return ret;
 
Quoted 12 lines

cpus.c int qemu_init_main_loop(void) · line 421

Quoted 9 lines
cpus.c +3 -1
-    qemu_cond_init(&qemu_pause_cond);
+    qemu_cond_init(&qemu_cpu_cond);
      qemu_cond_init(&qemu_system_cond);
+    qemu_cond_init(&qemu_pause_cond);
+    qemu_cond_init(&qemu_work_cond);
      qemu_mutex_init(&qemu_fair_mutex);
      qemu_mutex_init(&qemu_global_mutex);
      qemu_mutex_lock(&qemu_global_mutex);

Please merge this independently of the glib patches. It's apparently harmless only by chance so far.

Plan is to merge the first and second patch of the series right after 0.14.0 is released.

Regards,

Anthony Liguori

Quoted 4 lines

Thanks,
Jan

#4 lore raw

PATCH 2/7 Enable I/O thread and VNC threads by default

In reply to Anthony Liguori

Leave the disable options for now to help with testing but these will be removed once we're confident in the thread implementations.

Disabled code bit rots. These have been in tree long enough that we need to either commit to making them work or just remove them entirely.

configure +5 -2
index d68f862..d5ac074 100755
@@ -124,7 +124,7 @@ vnc_tls=""
 vnc_sasl=""
 vnc_jpeg=""
 vnc_png=""
-vnc_thread="no"
+vnc_thread="yes"
 xen=""
 linux_aio=""
 attr=""
@@ -161,7 +161,7 @@ darwin_user="no"
 bsd_user="no"
 guest_base=""
 uname_release=""
-io_thread="no"
+io_thread="yes"
 mixemu="no"
 kerneldir=""
 aix="no"
@@ -699,6 +699,8 @@ for opt do
   ;;
   --enable-io-thread) io_thread="yes"
   ;;
+  --disable-io-thread) io_thread="no"
+  ;;
   --disable-blobs) blobs="no"
   ;;
   --kerneldir=*) kerneldir="$optarg"
@@ -901,6 +903,7 @@ echo "  --enable-linux-aio       enable Linux AIO support"
 echo "  --disable-attr           disables attr and xattr support"
 echo "  --enable-attr            enable attr and xattr support"
 echo "  --enable-io-thread       enable IO thread"
+echo "  --disable-io-thread      disable IO thread"
 echo "  --disable-blobs          disable installing provided firmware blobs"
 echo "  --kerneldir=PATH         look for kernel includes in PATH"
 echo "  --enable-docs            enable documentation build"
Signature · 1 line
1.7.0.4
#5 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 6 lines · Anthony Liguori

Leave the disable options for now to help with testing but these will be removed once we're confident in the thread implementations.

Disabled code bit rots. These have been in tree long enough that we need to either commit to making them work or just remove them entirely.

I/O thread disables icount apparently.

I'm not really sure why. Marcelo, do you know the reason qemu_calculate_timeout returns a fixed value in the I/O thread regardless of icount?

Regards,

Anthony Liguori

Quoted 42 lines
configure +5 -2
index d68f862..d5ac074 100755
@@ -124,7 +124,7 @@ vnc_tls=""
  vnc_sasl=""
  vnc_jpeg=""
  vnc_png=""
-vnc_thread="no"
+vnc_thread="yes"
  xen=""
  linux_aio=""
  attr=""
@@ -161,7 +161,7 @@ darwin_user="no"
  bsd_user="no"
  guest_base=""
  uname_release=""
-io_thread="no"
+io_thread="yes"
  mixemu="no"
  kerneldir=""
  aix="no"
@@ -699,6 +699,8 @@ for opt do
    ;;
    --enable-io-thread) io_thread="yes"
    ;;
+  --disable-io-thread) io_thread="no"
+  ;;
    --disable-blobs) blobs="no"
    ;;
    --kerneldir=*) kerneldir="$optarg"
@@ -901,6 +903,7 @@ echo "  --enable-linux-aio       enable Linux AIO support"
  echo "  --disable-attr           disables attr and xattr support"
  echo "  --enable-attr            enable attr and xattr support"
  echo "  --enable-io-thread       enable IO thread"
+echo "  --disable-io-thread      disable IO thread"
  echo "  --disable-blobs          disable installing provided firmware blobs"
  echo "  --kerneldir=PATH         look for kernel includes in PATH"
  echo "  --enable-docs            enable documentation build"
#6 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Anthony Liguori

Leave the disable options for now to help with testing but these will be removed once we're confident in the thread implementations.

Disabled code bit rots. These have been in tree long enough that we need to either commit to making them work or just remove them entirely.

Quoted 5 lines

I/O thread disables icount apparently.

I'm not really sure why. Marcelo, do you know the reason qemu_calculate_timeout returns a fixed value in the I/O thread regardless of icount?

Hi,

The following commit hopefully fixed that issue.

commit 225d02cd1a34d5d87e8acefbf8e244a5d12f5f8c

Author: Edgar E. Iglesias <[email protected]>
Date:   Sun Jan 23 04:44:51 2011 +0100

Avoid deadlock whith iothread and icount

When using the iothread together with icount, make sure the qemu_icount counter makes forward progress when the vcpu is idle to avoid deadlocks.

See http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg01602.html
for more info.

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Also, although -icount & iothread no longer deadlocks, icount still sometimes performs incredibly slow with the io-thread (compared to non-io-thread qemu). In particular when not using -icount auto but a fixed ticks per insn values. Sometimes it's so slow I thought it actually deadlocked, but no it was crawling :) I haven't had time to look at it any closer but I hope to do soon.

These issues should be fixable though, so I'm not arguing against enabling it per default. Just mentioning what I've seen FYI..

Cheers

#7 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 46 lines · Edgar E. Iglesias
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Anthony Liguori

Leave the disable options for now to help with testing but these will be removed once we're confident in the thread implementations.

Disabled code bit rots. These have been in tree long enough that we need to either commit to making them work or just remove them entirely.

Quoted 5 lines

I/O thread disables icount apparently.

I'm not really sure why. Marcelo, do you know the reason qemu_calculate_timeout returns a fixed value in the I/O thread regardless of icount?

Hi,

The following commit hopefully fixed that issue.

commit 225d02cd1a34d5d87e8acefbf8e244a5d12f5f8c

Author: Edgar E. Iglesias <[email protected]>
Date:   Sun Jan 23 04:44:51 2011 +0100

Avoid deadlock whith iothread and icount

When using the iothread together with icount, make sure the qemu_icount counter makes forward progress when the vcpu is idle to avoid deadlocks.

See http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg01602.html
for more info.

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Also, although -icount & iothread no longer deadlocks, icount still sometimes performs incredibly slow with the io-thread (compared to non-io-thread qemu). In particular when not using -icount auto but a fixed ticks per insn values. Sometimes it's so slow I thought it actually deadlocked, but no it was crawling :) I haven't had time to look at it any closer but I hope to do soon.

Quoted 2 lines

These issues should be fixable though, so I'm not arguing against enabling it per default. Just mentioning what I've seen FYI..

Right, remember seeing 20% added overhead for network copy with TCG on the initial iothread merge. One can argue its due to the added overhead of locking/signalling between vcpu and iothread, where neither can run in parallel (while in kvm mode they can). But its just handwaving until detailed information is gathered on specific cases...

#8 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 32 lines · Marcelo Tosatti
Quoted 31 lines · Edgar E. Iglesias
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Anthony Liguori

Leave the disable options for now to help with testing but these will be removed once we're confident in the thread implementations.

Disabled code bit rots. These have been in tree long enough that we need to either commit to making them work or just remove them entirely.

Quoted 5 lines

I/O thread disables icount apparently.

I'm not really sure why. Marcelo, do you know the reason qemu_calculate_timeout returns a fixed value in the I/O thread regardless of icount?

Hi,

The following commit hopefully fixed that issue.

commit 225d02cd1a34d5d87e8acefbf8e244a5d12f5f8c

Author: Edgar E. Iglesias <[email protected]>
Date:   Sun Jan 23 04:44:51 2011 +0100

Avoid deadlock whith iothread and icount

When using the iothread together with icount, make sure the qemu_icount counter makes forward progress when the vcpu is idle to avoid deadlocks.

Quoted 7 lines
Quoted 7 lines

See http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg01602.html
for more info.

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Can you recall what was the test ?

Quoted 7 lines
Quoted 7 lines

Also, although -icount & iothread no longer deadlocks, icount still sometimes performs incredibly slow with the io-thread (compared to non-io-thread qemu). In particular when not using -icount auto but a fixed ticks per insn values. Sometimes it's so slow I thought it actually deadlocked, but no it was crawling :) I haven't had time to look at it any closer but I hope to do soon.

Quoted 5 lines
Quoted 2 lines

These issues should be fixable though, so I'm not arguing against enabling it per default. Just mentioning what I've seen FYI..

Right, remember seeing 20% added overhead for network copy with TCG on the initial iothread merge.

This is not the case anymore, network transfer speed is comparable. Probably due to SIG_IPI delivery being reliable, which was fixed later.

#9 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 5 lines · Marcelo Tosatti
Quoted 4 lines
Quoted 4 lines

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Quoted 8 lines

Can you recall what was the test ?

Quoted 6 lines
Quoted 6 lines

Also, although -icount & iothread no longer deadlocks, icount still sometimes performs incredibly slow with the io-thread (compared to non-io-thread qemu). In particular when not using -icount auto but a fixed ticks per insn values. Sometimes it's so slow I thought it actually deadlocked, but no it was crawling :) I haven't had time to look at it any closer but I hope to do soon.

Edgar, please give the attached patch a try with fixed icount value. The calculation for next event makes no sense for iothread timeout, only for vcpu context.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

These issues should be fixable though, so I'm not arguing against enabling it per default. Just mentioning what I've seen FYI..

Right, remember seeing 20% added overhead for network copy with TCG on the initial iothread merge.

This is not the case anymore, network transfer speed is comparable. Probably due to SIG_IPI delivery being reliable, which was fixed later.

Is there any other issue that prevents turning CONFIG_IOTHREAD on by default?

cpus.c +1 -1
index 9c50a34..2280db1 100644
@@ -748,7 +748,7 @@ static void qemu_tcg_wait_io_event(void)
     CPUState *env;
 
     while (!any_cpu_has_work())
-        qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, 1000);
+        qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, qemu_calculate_timeout());
 
     qemu_mutex_unlock(&qemu_global_mutex);
 
vl.c +1 -1
index 837be97..dbd81a1 100644
@@ -1323,7 +1323,7 @@ void main_loop_wait(int nonblocking)
     if (nonblocking)
         timeout = 0;
     else {
-        timeout = qemu_calculate_timeout();
+        timeout = 1000;
         qemu_bh_update_timeout(&timeout);
     }
 
#10 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 2 lines · Marcelo Tosatti

Is there any other issue that prevents turning CONFIG_IOTHREAD on by default?

I think Windows support.

Signal support is actually easy because we can "hack" the IPI as "suspend the VCPU thread+do work in the iothread context+resume the VCPU thread" (the IPI handler doesn't longjmp).

Threading primitives support is tricky but not hard (there is lots of code around, especially if you can make assumptions such as "always hold the mutex while signaling a cond. variable").

Paolo

#11 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 6 lines · Paolo Bonzini
Quoted 2 lines · Marcelo Tosatti

Is there any other issue that prevents turning CONFIG_IOTHREAD on by default?

I think Windows support.

Quoted 7 lines

Signal support is actually easy because we can "hack" the IPI as "suspend the VCPU thread+do work in the iothread context+resume the VCPU thread" (the IPI handler doesn't longjmp).

Threading primitives support is tricky but not hard (there is lots of code around, especially if you can make assumptions such as "always hold the mutex while signaling a cond. variable").

!CONFIG_IOTHREAD code is doomed to bitrot once we switch to default iothread mode. So if Windows support is not converted to a threading model with moderate differences to POSIX, it will likely bitrot a well. Therefore, conversion should be started rather sooner than later (by someone interested in that platform).

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#12 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 17 lines · Jan Kiszka
Quoted 7 lines · Paolo Bonzini
Quoted 3 lines · Marcelo Tosatti

Is there any other issue that prevents turning CONFIG_IOTHREAD on by default?

I think Windows support.

Quoted 8 lines

Signal support is actually easy because we can "hack" the IPI as "suspend the VCPU thread+do work in the iothread context+resume the VCPU thread" (the IPI handler doesn't longjmp).

Threading primitives support is tricky but not hard (there is lots of code around, especially if you can make assumptions such as "always hold the mutex while signaling a cond. variable").

Quoted 6 lines

!CONFIG_IOTHREAD code is doomed to bitrot once we switch to default iothread mode. So if Windows support is not converted to a threading model with moderate differences to POSIX, it will likely bitrot a well. Therefore, conversion should be started rather sooner than later (by someone interested in that platform).

As far as I'm concerned, Windows support is already deprecated as noone has stepped up to enhance it or support for a number of years now. We shouldn't remove existing code that supports it or refuse to take reasonable patches but if enabling IO thread by default breaks it, so be it.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#13 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 25 lines · Anthony Liguori
Quoted 17 lines · Jan Kiszka
Quoted 7 lines · Paolo Bonzini
Quoted 3 lines · Marcelo Tosatti

Is there any other issue that prevents turning CONFIG_IOTHREAD on by default?

I think Windows support.

Quoted 8 lines

Signal support is actually easy because we can "hack" the IPI as "suspend the VCPU thread+do work in the iothread context+resume the VCPU thread" (the IPI handler doesn't longjmp).

Threading primitives support is tricky but not hard (there is lots of code around, especially if you can make assumptions such as "always hold the mutex while signaling a cond. variable").

Quoted 6 lines

!CONFIG_IOTHREAD code is doomed to bitrot once we switch to default iothread mode. So if Windows support is not converted to a threading model with moderate differences to POSIX, it will likely bitrot a well. Therefore, conversion should be started rather sooner than later (by someone interested in that platform).

Quoted 5 lines

As far as I'm concerned, Windows support is already deprecated as noone has stepped up to enhance it or support for a number of years now. We shouldn't remove existing code that supports it or refuse to take reasonable patches but if enabling IO thread by default breaks it, so be it.

As far as I see, Blue Swirl and Stefan Weil are regularly committing fixes for win32. Stefan Weil is also providing win32 binaries on his website [1]. I wouldn't call that deprecated.

[1] http://qemu.weilnetz.de/

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#14 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 8 lines · Aurelien Jarno
Quoted 6 lines · Anthony Liguori

As far as I'm concerned, Windows support is already deprecated as noone has stepped up to enhance it or support for a number of years now. We shouldn't remove existing code that supports it or refuse to take reasonable patches but if enabling IO thread by default breaks it, so be it.

Quoted 4 lines

As far as I see, Blue Swirl and Stefan Weil are regularly committing fixes for win32. Stefan Weil is also providing win32 binaries on his website [1]. I wouldn't call that deprecated.

Occasional compile fixes is a long way from something that is regularly tested and well maintained.

Win32 still doesn't have a proper AIO implementation which is probably close to a 4 year old FIXME.

Regards,

Anthony Liguori

Quoted 3 lines

[1] http://qemu.weilnetz.de/

#15 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 14 lines · Anthony Liguori
Quoted 8 lines · Aurelien Jarno
Quoted 6 lines · Anthony Liguori

As far as I'm concerned, Windows support is already deprecated as noone has stepped up to enhance it or support for a number of years now. We shouldn't remove existing code that supports it or refuse to take reasonable patches but if enabling IO thread by default breaks it, so be it.

Quoted 4 lines

As far as I see, Blue Swirl and Stefan Weil are regularly committing fixes for win32. Stefan Weil is also providing win32 binaries on his website [1]. I wouldn't call that deprecated.

Quoted 6 lines

Occasional compile fixes is a long way from something that is regularly tested and well maintained.

Win32 still doesn't have a proper AIO implementation which is probably close to a 4 year old FIXME.

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#16 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

Paolo

#17 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 9 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#18 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 18 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

Quoted 4 lines

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

We should probably get rid of KVM support in QEMU, so if someone has an idea for a cool TCG feature that can't be supported in KVM, it's the moment to submit it. We can add it with #ifdef, and in one year just ask for KVM support removal.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#19 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 23 lines · Aurelien Jarno
Quoted 21 lines · Jan Kiszka
Quoted 11 lines · Paolo Bonzini
Quoted 3 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

Quoted 7 lines
Quoted 5 lines

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept,

IOTHREAD is actually just as necessary for TCG as it is for KVM. Otherwise, you have a signal select race that cannot be avoided.

QEMU has never "supported" Windows. It happens to compile on Windows, but historically the Windows build has been non-functional for long periods of time and is still missing basic features (like AIO).

Regards,

Anthony Liguori

Quoted 10 lines

it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

We should probably get rid of KVM support in QEMU, so if someone has an idea for a cool TCG feature that can't be supported in KVM, it's the moment to submit it. We can add it with #ifdef, and in one year just ask for KVM support removal.

#20 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 3 lines · Anthony Liguori
Quoted 1 line

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept,

QEMU has never "supported" Windows.

I think both assertions are false.

What's true is that the Win32 port has never evolved beyond "barely functional", at least by the standards with which QEMU is judged under Linux.

Paolo

#21 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 24 lines · Aurelien Jarno
Quoted 18 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

Quoted 4 lines

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Quoted 4 lines

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#22 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 28 lines · Jan Kiszka
Quoted 18 lines · Aurelien Jarno
Quoted 17 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

Quoted 8 lines
Quoted 4 lines

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

Quoted 5 lines

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#23 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 35 lines · Aurelien Jarno
Quoted 28 lines · Jan Kiszka
Quoted 18 lines · Aurelien Jarno
Quoted 17 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

Quoted 8 lines
Quoted 4 lines

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

Quoted 5 lines

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

Quoted 7 lines

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

I'm not talking about virtualization here. I'm talking about usable emulation of today's (!) embedded multi-core platforms. It matters a lot if your test roundtrip for booting into a SMP guest and running some apps is a few 10 seconds, a few minutes or even not practically working. Ever tried to boot a 16 core VM in emulation mode? I did, for fun. I just hope I'll never depend on this for work.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#24 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 42 lines · Jan Kiszka
Quoted 33 lines · Aurelien Jarno
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Aurelien Jarno
Quoted 21 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Quoted 9 lines
Quoted 4 lines

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

Quoted 7 lines

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

Quoted 6 lines

I'm not talking about virtualization here. I'm talking about usable emulation of today's (!) embedded multi-core platforms. It matters a lot if your test roundtrip for booting into a SMP guest and running some apps is a few 10 seconds, a few minutes or even not practically working. Ever tried to boot a 16 core VM in emulation mode? I did, for fun. I just hope I'll never depend on this for work.

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#25 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 50 lines · Aurelien Jarno
Quoted 42 lines · Jan Kiszka
Quoted 33 lines · Aurelien Jarno
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Aurelien Jarno
Quoted 21 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Quoted 9 lines
Quoted 4 lines

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

Quoted 7 lines

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

Quoted 6 lines

I'm not talking about virtualization here. I'm talking about usable emulation of today's (!) embedded multi-core platforms. It matters a lot if your test roundtrip for booting into a SMP guest and running some apps is a few 10 seconds, a few minutes or even not practically working. Ever tried to boot a 16 core VM in emulation mode? I did, for fun. I just hope I'll never depend on this for work.

Quoted 3 lines

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

I guess his point here really is that soon SMP is commodity. Most new ARM cores move to SMP by default, MIPS is there already and even embedded PPC is multi-core for a while now. Sure, you can work around things by only emulating a single core at times, but it's not always good enough - especially if you're working on interrupt handling code.

Either way, the whole discussion is moot. We either do support Windows or we don't. Most of the developers don't even have windows machines, so it's very hard for them to do it - even less so do they have windows programming knowledge. So what we really need is for someone to implement the thread infrastructure and aio support on windows and then all is great (until the next big infrastructure feature of course).

If only the Android people wouldn't simply fork every project out there, but work upstream, we'd probably have quite a few folks happy to support windows from that crowd, as they depend on it heavily.

Alex

#26 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno

Introducing IOTHREAD made !CONFIG_IOTHREAD platforms second class citizens. I think you'd like people to provide full support when they introduce new features.

This is a good motivator to use glib and have a unified code path for TCG/KVM and Linux/Windows. Yes it will require some work and some optimization, but at the end we'll have better host platform parity and a simpler main loop for TCG/KVM to interact with.

Stefan

#27 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 4 lines · Stefan Hajnoczi

Introducing IOTHREAD made !CONFIG_IOTHREAD platforms second class citizens. I think you'd like people to provide full support when they introduce new features.

I think you really pointed the problem here. We should probably add a feature that will make KVM second class citizen so that people can understand what it means.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#28 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 8 lines · Aurelien Jarno
Quoted 3 lines · Stefan Hajnoczi

Introducing IOTHREAD made !CONFIG_IOTHREAD platforms second class citizens. I think you'd like people to provide full support when they introduce new features.

I think you really pointed the problem here. We should probably add a feature that will make KVM second class citizen so that people can understand what it means.

I actually don't think introducing IOTHREAD made Windows a second class citizen, since it was left as a non-default choice for years. People care about IOTHREAD now only because (after years) there is serious thought about making it the default.

I'm sure that if you add such a killer feature that is TCG-only, KVM people will try to support it in a shorter timeframe.

Paolo

#29 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 9 lines · Aurelien Jarno
Quoted 4 lines · Stefan Hajnoczi

Introducing IOTHREAD made !CONFIG_IOTHREAD platforms second class citizens. I think you'd like people to provide full support when they introduce new features.

I think you really pointed the problem here. We should probably add a feature that will make KVM second class citizen so that people can understand what it means.

There are people out there who already thought loudly about forking or rewriting those QEMU bits required for KVM support just to make "life easier". I already disagreed on this, and I continue to do so as both use cases nicely benefit from each other.

KVM is driving QEMU features today that would otherwise have taken years to show up, if at all. On the other side, all those bits related to the cross-arch platform emulation of non-x86 helps and will continue to help KVM support on those archs as well (we already have it on PPC, we'll see on ARM and likely more in the future).

So, please let's stop this useless finger pointing, on both sides. KVM and QEMU is a symbiosis. Unfortunately, this is not (yet?) the case for POSIX vs. Windows hosts.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#30 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 11 lines · Aurelien Jarno
Quoted 5 lines · Stefan Hajnoczi

Introducing IOTHREAD made !CONFIG_IOTHREAD platforms second class citizens. I think you'd like people to provide full support when they introduce new features.

I think you really pointed the problem here. We should probably add a feature that will make KVM second class citizen so that people can understand what it means.

Aurelien,

Have you actually run QEMU on Windows and tried to use it to do something useful?

As an exercise, walk through the various releases of QEMU and compare how well it works on Windows to any Unix platform. Windows support in QEMU has always been a second class citizen.

If someone is willing to stand up and properly maintain it, I'm all for doing whatever we can to be supportive of that person but as of right now, that doesn't exist.

Regards,

Anthony Liguori

#31 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Aurelien Jarno
Quoted 5 lines · Stefan Hajnoczi

Introducing IOTHREAD made !CONFIG_IOTHREAD platforms second class citizens. I think you'd like people to provide full support when they introduce new features.

I think you really pointed the problem here. We should probably add a feature that will make KVM second class citizen so that people can understand what it means.

Quoted 8 lines

Aurelien,

Have you actually run QEMU on Windows and tried to use it to do something useful?

As an exercise, walk through the various releases of QEMU and compare how well it works on Windows to any Unix platform. Windows support in QEMU has always been a second class citizen.

I never tried to get it working on windows, but I know some people using it there. We should just don't ignore them. Maybe it's not perfect, but it is enough for those people.

Quoted 3 lines

If someone is willing to stand up and properly maintain it, I'm all for doing whatever we can to be supportive of that person but as of right now, that doesn't exist.

There are regular patches for windows support, Stefan Weil is producing builds regularly. Maybe it doesn't have all the features, but people are making sure it basically works.

Now you want to break that because the *new* feature you want to introduce is not supported on windows. I insist on the fact it is a new feature simply because it was *disabled* by default. So I don't buy the argument about "that person don't exist".

Send a call for help on that subject, give the people some time to come with a solution (let's put a deadline), and then if nobody appears we can definitely consider Windows support as dead. But it should not be done arbitrary.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#32 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Anthony Liguori
Quoted 4 lines · Anthony Liguori

Aurelien,

Have you actually run QEMU on Windows and tried to use it to do something useful?

I'm not Aurelian, but we do use QEMU on win32 as part of Nokia Qt SDK. While it is second class in many ways compared to Linux QEMU (or even OS X), it is still quite useful for us.

Riku

#33 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 50 lines · Aurelien Jarno
Quoted 42 lines · Jan Kiszka
Quoted 33 lines · Aurelien Jarno
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Aurelien Jarno
Quoted 21 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Quoted 9 lines
Quoted 4 lines

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

Quoted 7 lines

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

Quoted 6 lines

I'm not talking about virtualization here. I'm talking about usable emulation of today's (!) embedded multi-core platforms. It matters a lot if your test roundtrip for booting into a SMP guest and running some apps is a few 10 seconds, a few minutes or even not practically working. Ever tried to boot a 16 core VM in emulation mode? I did, for fun. I just hope I'll never depend on this for work.

Quoted 3 lines

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

That's too nearsighted. SMP will be commodity on practically _any_ arch within the next years. And if QEMU doesn't keep up with it, feature and performance-wise, it will loose market share.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#34 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 49 lines · Jan Kiszka
Quoted 48 lines · Aurelien Jarno
Quoted 47 lines · Jan Kiszka
Quoted 33 lines · Aurelien Jarno
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Aurelien Jarno
Quoted 21 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Quoted 9 lines
Quoted 4 lines

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

Quoted 7 lines

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

I'm not talking about virtualization here. I'm talking about usable emulation of today's (!) embedded multi-core platforms. It matters a lot if your test roundtrip for booting into a SMP guest and running some apps is a few 10 seconds, a few minutes or even not practically working. Ever tried to boot a 16 core VM in emulation mode? I did, for fun. I just hope I'll never depend on this for work.

Quoted 8 lines
Quoted 3 lines

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

That's too nearsighted. SMP will be commodity on practically _any_ arch within the next years. And if QEMU doesn't keep up with it, feature and performance-wise, it will loose market share.

Oh commercial arguments now. I am looking for something that answer my needs, not about market share.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#35 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 54 lines · Aurelien Jarno
Quoted 53 lines · Jan Kiszka
Quoted 51 lines · Aurelien Jarno
Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Aurelien Jarno
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Aurelien Jarno
Quoted 21 lines · Jan Kiszka
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Aurelien Jarno

I forget to remember when we decided that AIO should be implemented on any host OS. Any pointer?

To be fair, I/O-heavy workloads are almost unusable without AIO. For Window targets, they also crash under SMP due to the Windows AP watchdog. But then TCG and SMP do not go very well together anyway.

However, I think deprecating Win32 support would be a very bad idea.

It would be too early at this point.

But if Windows is once the only reason to keep tons of hardly tested code paths around or to invest significant additional effort to change logic or interfaces in this area, than I would prefer that step. I'm hacking on IOTHREAD vs. !IOTHREAD for some weeks now, and all those subtle differences are really a PITA and source of various breakages.

People interested in that platform should finally realize that its fate is coupled to reducing the #ifdefs as well as the design differences we see right now and even more in the future.

Quoted 9 lines
Quoted 4 lines

The guilty here is IOTHREAD. Windows support predates IOTHREAD concept, it's just that people who introduce IOTHREAD didn't care about Windows support at all and added these #ifdef. Disabling Windows support because of that is not fair.

The TCG execution model won't scale long-term. It's already a main to boot a quad or just dual core VM, even more when your host has at least as many real cores. I'm sure we'll see multi-threaded TCG CPUs in the future, and the iothread will just be one of 7, 17 or 257 threads.

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

Quoted 8 lines
Quoted 2 lines

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

I'm not talking about virtualization here. I'm talking about usable emulation of today's (!) embedded multi-core platforms. It matters a lot if your test roundtrip for booting into a SMP guest and running some apps is a few 10 seconds, a few minutes or even not practically working. Ever tried to boot a 16 core VM in emulation mode? I did, for fun. I just hope I'll never depend on this for work.

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

Quoted 8 lines
Quoted 4 lines

That's too nearsighted. SMP will be commodity on practically _any_ arch within the next years. And if QEMU doesn't keep up with it, feature and performance-wise, it will loose market share.

Oh commercial arguments now. I am looking for something that answer my needs, not about market share.

"Market share" simply means user base, for commercial or for hobby, academic, whatever use. QEMU has a nice position here ATM. Even commercial competitors can help continuously comparing their solutions with QEMU (I once enjoyed such a product presentation). However, time does not stand still.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#36 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 4 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

This can be fixed by running TCG in a separate thread than select() and sending a signal to the TCG VCPU when select() returns (effectively SIGIO in userspace).

This is exactly what the I/O thread does.

Regards,

Anthony Liguori

#37 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 11 lines · Anthony Liguori
Quoted 4 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

A race condition ? Looks like you are describing a dead-lock.

But the dead lock doesn't happen because of the timer which periodically exits from TCG. Hence the performance issue.

Quoted 3 lines

This can be fixed by running TCG in a separate thread than select() and sending a signal to the TCG VCPU when select() returns (effectively SIGIO in userspace).

This is exactly what the I/O thread does.

(Nobody was able to make it working on Windows - or nobody was interested in ?)

Tristan.

#38 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 17 lines · Tristan Gingold
Quoted 11 lines · Anthony Liguori
Quoted 4 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

A race condition ? Looks like you are describing a dead-lock.

Quoted 9 lines

But the dead lock doesn't happen because of the timer which periodically exits from TCG. Hence the performance issue.

Quoted 3 lines

This can be fixed by running TCG in a separate thread than select() and sending a signal to the TCG VCPU when select() returns (effectively SIGIO in userspace).

This is exactly what the I/O thread does.

(Nobody was able to make it working on Windows - or nobody was interested in ?)

Given the I/O thread is disabled by default, my guess is that nobody really see an interest in looking at that.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#39 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 2 lines · Aurelien Jarno

Given the I/O thread is disabled by default, my guess is that nobody really see an interest in looking at that.

I had started looking at it in my free time. I stopped because the thread pool series were continuously changing the QemuThread APIs. I can resume looking at it.

Paolo

#40 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 14 lines · Aurelien Jarno
Quoted 12 lines · Tristan Gingold
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

A race condition ? Looks like you are describing a dead-lock.

But the dead lock doesn't happen because of the timer which periodically exits from TCG. Hence the performance issue.

With dynticks, you don't always have a periodic timer (unless the guest has a periodic timer enabled). There's a good bit of early startup code that runs without a periodic timer enabled.

Now that said, we never truly sleep forever. We'll set something like a 5 second timeout. But 5 seconds might as well be forever and this is certainly a giant hack.

Regards,

Anthony Liguori

Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

This can be fixed by running TCG in a separate thread than select() and sending a signal to the TCG VCPU when select() returns (effectively SIGIO in userspace).

This is exactly what the I/O thread does.

(Nobody was able to make it working on Windows - or nobody was interested in ?)

Given the I/O thread is disabled by default, my guess is that nobody really see an interest in looking at that.

#41 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 4 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

Quoted 9 lines

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

In practice you will get a signal when the next timer event expire. I agree it's suboptimal, but it works, and has been like that for here.

Having that fixed through an I/O thread is actually quite nice, however it should not be done ignoring all the *current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

And now, I don't buy the argument "it's been there for years", it was *disabled* by default.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#42 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 4 lines · Aurelien Jarno

however
it should not be done ignoring all the*current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Let's also enumerate them.

Quoted 2 lines

And now, I don't buy the argument "it's been there for years", it was *disabled* by default.

It was disabled by default only because it is most useful for KVM and people were using qemu-kvm's iothread.

Paolo

#43 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 10 lines · Paolo Bonzini
Quoted 4 lines · Aurelien Jarno

however
it should not be done ignoring all the*current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Let's also enumerate them.

From what I know:

- performance regression in TCG mode
- windows support

I am going to look again at the first one tonight to provide some numbers.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#44 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 11 lines · Aurelien Jarno
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Aurelien Jarno

however
it should not be done ignoring all the*current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Let's also enumerate them.

From what I know:
- performance regression in TCG mode

I setup an x86_64 guest on an x86_64 host (Intel Xeon E5345). Nothing was running except the standard daemons and the CPU governor was set to "performance" on all CPU. I then compared the network performance using netperf in default mode, through a tap interface and a virtio nic. I got the following results (quite reproducible, std below 0.5):
- without IO thread: 107.36 MB/s
- with IO thread: 89.93 MB/s

I haven't redone the tests I have done two weeks ago on MIPS, ARM, PowerPC and SH4 (using different emulated network cards: smc91c111, rtl8139, e1000, virtio), but it was roughly the same slow down, except on ARM where it was more important.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#45 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 13 lines · Aurelien Jarno
Quoted 11 lines · Aurelien Jarno
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Aurelien Jarno

however
it should not be done ignoring all the*current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Let's also enumerate them.

From what I know:
- performance regression in TCG mode

Quoted 8 lines

I setup an x86_64 guest on an x86_64 host (Intel Xeon E5345). Nothing was running except the standard daemons and the CPU governor was set to "performance" on all CPU. I then compared the network performance using netperf in default mode, through a tap interface and a virtio nic. I got the following results (quite reproducible, std below 0.5):
- without IO thread: 107.36 MB/s
- with IO thread: 89.93 MB/s

And the same test on the code from september 2009:
- without IO thread: 141.8 MB/s

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#46 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 28 lines · Aurelien Jarno
Quoted 17 lines · Aurelien Jarno
Quoted 9 lines · Aurelien Jarno
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Aurelien Jarno

however
it should not be done ignoring all the*current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Quoted 6 lines
Quoted 3 lines

Let's also enumerate them.

From what I know:
- performance regression in TCG mode

Quoted 9 lines

I setup an x86_64 guest on an x86_64 host (Intel Xeon E5345). Nothing was running except the standard daemons and the CPU governor was set to "performance" on all CPU. I then compared the network performance using netperf in default mode, through a tap interface and a virtio nic. I got the following results (quite reproducible, std below 0.5):
- without IO thread: 107.36 MB/s
- with IO thread: 89.93 MB/s

Quoted 3 lines

And the same test on the code from september 2009:
- without IO thread: 141.8 MB/s

virtio-net is super finicky regarding mitigation strategies and their relationship to the I/O thread. Different benchmarks will behave differently. virtio-blk is probably a better device to test as you'll get much more consistent results across different type of I/O patterns.

Regards,

Anthony Liguori

#47 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 21 lines · Anthony Liguori
Quoted 20 lines · Aurelien Jarno
Quoted 19 lines · Aurelien Jarno
Quoted 10 lines · Aurelien Jarno
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Aurelien Jarno

however
it should not be done ignoring all the*current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Let's also enumerate them.

From what I know:
- performance regression in TCG mode

I setup an x86_64 guest on an x86_64 host (Intel Xeon E5345). Nothing was running except the standard daemons and the CPU governor was set to "performance" on all CPU. I then compared the network performance using netperf in default mode, through a tap interface and a virtio nic. I got the following results (quite reproducible, std below 0.5):
- without IO thread: 107.36 MB/s
- with IO thread: 89.93 MB/s

Quoted 7 lines
Quoted 2 lines

And the same test on the code from september 2009:
- without IO thread: 141.8 MB/s

virtio-net is super finicky regarding mitigation strategies and their relationship to the I/O thread. Different benchmarks will behave differently. virtio-blk is probably a better device to test as you'll get much more consistent results across different type of I/O patterns.

netperf server on guest, RHEL5.4 guest (e1000), uq/master branch, TCG:

iothread: 236MB/s
no iothread: 215MB/s

Also noticed scp was slightly faster with iothread earlier this week, don't remember numbers.

#48 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 16 lines · Aurelien Jarno
Quoted 14 lines · Anthony Liguori
Quoted 5 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Quoted 8 lines
Quoted 5 lines

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

In practice you will get a signal when the next timer event expire. I agree it's suboptimal, but it works, and has been like that for here.

During early boot up before the periodic timer is enabled can cause quite a noticable issue here.

I think it's cris specifically that does polling I/O in the early startup before any periodic timer is enabled.

Quoted 5 lines

Having that fixed through an I/O thread is actually quite nice, however it should not be done ignoring all the *current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Yes, agree 100%.

Quoted 3 lines

And now, I don't buy the argument "it's been there for years", it was *disabled* by default.

Yeah, I think we need to enable it by default and commit to fixing all of the outstanding issues.

I think we've fixed all that we're aware of but we probably won't find the rest unless we enable it universally.

Regards,

Anthony Liguori

#49 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 38 lines · Anthony Liguori
Quoted 16 lines · Aurelien Jarno
Quoted 14 lines · Anthony Liguori
Quoted 5 lines · Aurelien Jarno

Yes, it's slow. But is it a problem? You assume that people use QEMU only for emulating SMP platforms. This is a wrong assumption. Beside the x86 target, only sparc really supports SMP emulation.

It's *not* just about performance.

TCG requires a signal to break out of a tight chained TB loop. If you have a guest in a tight loop waiting for something external (like polling on a in-memory flag), the device emulation will not get to run until a signal is fired.

Quoted 8 lines
Quoted 5 lines

Unless you set SIGIO on every file descriptor that selects polls on (and you can't because there are a number that just don't support SIGIO), then you have a race condition.

In practice you will get a signal when the next timer event expire. I agree it's suboptimal, but it works, and has been like that for here.

During early boot up before the periodic timer is enabled can cause quite a noticable issue here.

I think it's cris specifically that does polling I/O in the early startup before any periodic timer is enabled.

Quoted 5 lines

Having that fixed through an I/O thread is actually quite nice, however it should not be done ignoring all the *current* drawbacks of the iothread mode. We know them (at least for some of them), so let's try to solve them.

Quoted 8 lines

Yes, agree 100%.

Quoted 3 lines

And now, I don't buy the argument "it's been there for years", it was *disabled* by default.

Yeah, I think we need to enable it by default and commit to fixing all of the outstanding issues.

So the strategy is let's break everything and wait for the maintainer to fix that? This strategy doesn't work, we have seen for example that with the SeaBIOS switch. While it brings nice features, it has broken the isapc machine. And it's still not fixed...

Also this strategy doesn't scale, then the maintainers are spending their time fixing bugs introduced because others didn't care. Resources are not unlimited, especially for those doing that on their free time.

Quoted 2 lines

I think we've fixed all that we're aware of but we probably won't find the rest unless we enable it universally.

I agree that we are going to discover bugs, and it's normal. QEMU is quite complex and it's not possible to test every combination. That said we are already aware of some bugs, why not fix them, or at least try to fix them? For example we haven't fixed the performance regression with TCG (at least it wasn't the case two weeks ago).

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#50 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 5 lines · Aurelien Jarno

So the strategy is let's break everything and wait for the maintainer to fix that? This strategy doesn't work, we have seen for example that with the SeaBIOS switch. While it brings nice features, it has broken the isapc machine. And it's still not fixed...

The fundamental problem is that poorly thought out features have been committed in the past. isapc is a good example of this.

You can't just remove a chipset but leave an ISA bus implementation and expect things to just keep working. Even the early ISA-only systems had a chipset that firmware interfaced with.

Quoted 4 lines

Also this strategy doesn't scale, then the maintainers are spending their time fixing bugs introduced because others didn't care. Resources are not unlimited, especially for those doing that on their free time.

So are you suggesting that every half baked feature should hold up any other future developments? I think the real problem is exactly the opposite of what you describe. Why should we waste finite resources keeping something like Windows support limping along?

We need to do a better job of not adding features that there is no serious intention of every supporting in a meaningful way. I think the recent discussion of w64 is a good example of this. I can't imagine trying to support w64 in QEMU until someone actually makes w32 work in a reasonable way.

Quoted 9 lines
Quoted 3 lines

I think we've fixed all that we're aware of but we probably won't find the rest unless we enable it universally.

I agree that we are going to discover bugs, and it's normal. QEMU is quite complex and it's not possible to test every combination. That said we are already aware of some bugs, why not fix them, or at least try to fix them? For example we haven't fixed the performance regression with TCG (at least it wasn't the case two weeks ago).

If there are known issues, yes, let's fix them before enabling it.

Regards,

Anthony Liguori

#51 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 24 lines · Anthony Liguori
Quoted 5 lines · Aurelien Jarno

So the strategy is let's break everything and wait for the maintainer to fix that? This strategy doesn't work, we have seen for example that with the SeaBIOS switch. While it brings nice features, it has broken the isapc machine. And it's still not fixed...

The fundamental problem is that poorly thought out features have been committed in the past. isapc is a good example of this.

You can't just remove a chipset but leave an ISA bus implementation and expect things to just keep working. Even the early ISA-only systems had a chipset that firmware interfaced with.

Quoted 4 lines

Also this strategy doesn't scale, then the maintainers are spending their time fixing bugs introduced because others didn't care. Resources are not unlimited, especially for those doing that on their free time.

So are you suggesting that every half baked feature should hold up any other future developments? I think the real problem is exactly the opposite of what you describe. Why should we waste finite resources keeping something like Windows support limping along?

Quoted 5 lines

We need to do a better job of not adding features that there is no serious intention of every supporting in a meaningful way. I think the recent discussion of w64 is a good example of this. I can't imagine trying to support w64 in QEMU until someone actually makes w32 work in a reasonable way.

Yes, we should at least leave people time to find a solution. If nobody comes with a solution, let's consider it deprecated.

Quoted 12 lines
Quoted 9 lines
Quoted 3 lines

I think we've fixed all that we're aware of but we probably won't find the rest unless we enable it universally.

I agree that we are going to discover bugs, and it's normal. QEMU is quite complex and it's not possible to test every combination. That said we are already aware of some bugs, why not fix them, or at least try to fix them? For example we haven't fixed the performance regression with TCG (at least it wasn't the case two weeks ago).

If there are known issues, yes, let's fix them before enabling it.

So please look at this TCG performance regression instead of talking about enabling this just after the release. I don't consider TCG a half baked feature, for people who forgot about that it's the original QEMU mode.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#52 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 25 lines · Aurelien Jarno
Quoted 24 lines · Anthony Liguori
Quoted 5 lines · Aurelien Jarno

So the strategy is let's break everything and wait for the maintainer to fix that? This strategy doesn't work, we have seen for example that with the SeaBIOS switch. While it brings nice features, it has broken the isapc machine. And it's still not fixed...

The fundamental problem is that poorly thought out features have been committed in the past.  isapc is a good example of this.

You can't just remove a chipset but leave an ISA bus implementation and expect things to just keep working.  Even the early ISA-only systems had a chipset that firmware interfaced with.

Quoted 4 lines

Also this strategy doesn't scale, then the maintainers are spending their time fixing bugs introduced because others didn't care. Resources are not unlimited, especially for those doing that on their free time.

So are you suggesting that every half baked feature should hold up any other future developments?  I think the real problem is exactly the opposite of what you describe.  Why should we waste finite resources keeping something like Windows support limping along?

Quoted 8 lines
Quoted 5 lines

We need to do a better job of not adding features that there is no serious intention of every supporting in a meaningful way.  I think the recent discussion of w64 is a good example of this.  I can't imagine trying to support w64 in QEMU until someone actually makes w32 work in a reasonable way.

Yes, we should at least leave people time to find a solution. If nobody comes with a solution, let's consider it deprecated.

I think win32 situation is somewhat similar (but not nearly as bad as) to kqemu's. It was useful for some users, but there were no maintenance and when it got in the way, it was removed because nobody could fix it.

But I'd prefer a solution where somebody steps up as Windows maintainer. I'm also doing regular mingw32 builds but otherwise not much.

#53 lore raw

Re: [Qemu-devel] [PATCH 2/7] Enable I/O thread and VNC threads by default

Am 09.02.2011 18:13, schrieb Blue Swirl:

Quoted 9 lines

I think win32 situation is somewhat similar (but not nearly as bad as) to kqemu's. It was useful for some users, but there were no maintenance and when it got in the way, it was removed because nobody could fix it.

But I'd prefer a solution where somebody steps up as Windows maintainer. I'm also doing regular mingw32 builds but otherwise not much.

VNC threads can be compiled for W32, too.
A short test of the resulting executable was successful, no problems.

The patch is available here:
http://repo.or.cz/w/qemu/ar7.git/commitdiff/aabf11dc0a938b84d76d7c147cbf0445d7bee297

I decided to create a new directory structure hosts/w32, so files can be moved from the root to hosts/posix, hosts/w32, or hosts/xxx. Include chains reduce code modifications and conditional compilations. And people who don't want to see w32 support can remove it easily :-)

Supporting I/O threads for W32 will be possible, too.

I don't think that W32 support is a big problem. It never was. Some of the real problems were already named in the previous mails.

Regards,
Stefan Weil

#54 lore raw

Re: [Qemu-devel] [PATCH 2/7] Enable I/O thread and VNC threads by default

Quoted 7 lines · Stefan Weil

I decided to create a new directory structure hosts/w32, so files can be moved from the root to hosts/posix, hosts/w32, or hosts/xxx. Include chains reduce code modifications and conditional compilations. And people who don't want to see w32 support can remove it easily :-)

Supporting I/O threads for W32 will be possible, too.

I have patches for Win32 iothread, I'm just posting the series split into multiple pieces.

Paolo

#55 lore raw

Re: [Qemu-devel] [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Stefan Weil
Quoted 82 lines · Stefan Weil

The patch is available here:
http://repo.or.cz/w/qemu/ar7.git/commitdiff/aabf11dc0a938b84d76d7c147cbf0445d7bee297

hosts/w32/include/signal.h new file +20 -0
new file mode 100644
index 0000000..e45f03c
@@ -0,0 +1,20 @@
+/*
+ * QEMU w32 support
+ *
+ * Copyright (C) 2011 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef WIN32_SIGNAL_H
+#define WIN32_SIGNAL_H
+
+#include_next <signal.h>
+#include <sys/types.h>    /* sigset_t */
+
+int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);
+int sigfillset(sigset_t *set);
+
+#endif /* WIN32_SIGNAL_H */
hosts/w32/include/time.h new file +31 -0
new file mode 100644
index 0000000..0b997d3
@@ -0,0 +1,31 @@
+/*
+ * QEMU w32 support
+ *
+ * Copyright (C) 2011 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#if !defined(W32_TIME_H)
+#define W32_TIME_H
+
+#include_next <time.h>
+
+#ifndef HAVE_STRUCT_TIMESPEC
+#define HAVE_STRUCT_TIMESPEC 1
+struct timespec {
+        long tv_sec;
+        long tv_nsec;
+};
+#endif /* HAVE_STRUCT_TIMESPEC */
+
+typedef enum {
+  CLOCK_REALTIME = 0
+} clockid_t;
+
+int clock_getres (clockid_t clock_id, struct timespec *res);
+int clock_gettime(clockid_t clock_id, struct timespec *pTimespec);
+
+#endif /* W32_TIME_H */
os-win32.c +8 -0
index b214e6a..7778366 100644
@@ -36,6 +36,45 @@
 /***********************************************************/
 /* Functions missing in mingw */
 
+#if defined(CONFIG_THREAD)
+
+int clock_gettime(clockid_t clock_id, struct timespec *pTimespec)
+{
+  int result = 0;
+  if (clock_id == CLOCK_REALTIME && pTimespec != 0) {
+    DWORD t = GetTickCount();
+    const unsigned cps = 1000;

os-win32.c line 56

Quoted 10 lines
os-win32.c +10 -0
+    struct timespec ts;
+    ts.tv_sec  = t / cps;
+    ts.tv_nsec = (t % cps) * (1000000000UL / cps);
+    *pTimespec = ts;
+  } else {
+    errno = EINVAL;
+    result = -1;
+  }
+  return result;
+}

Why is this needed? The only user of clock_gettime in the POSIX case is using CLOCK_MONOTONIC, and actually has a Win32 version already.

Quoted 7 lines
os-win32.c +7 -0
+int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset)
+{
+    /* Dummy, do nothing. */
+    return EINVAL;
+}
+
+int sigfillset(sigset_t *set)

os-win32.c line 73

Quoted 10 lines
os-win32.c +10 -0
+{
+    int result = 0;
+    if (set) {
+        *(set) = (sigset_t)(-1);
+    } else {
+        errno = EINVAL;
+        result = -1;
+    }
+    return result;
+}

Instead of these, it's better to provide a Win32 implementation of mutexes and condvars. I'll submit it next week hopefully.

Paolo

#56 lore raw

Re: [Qemu-devel] [PATCH 2/7] Enable I/O thread and VNC threads by default

Am 10.02.2011 10:54, schrieb Paolo Bonzini:

Quoted 4 lines · Stefan Weil
Quoted 3 lines

The patch is available here:
http://repo.or.cz/w/qemu/ar7.git/commitdiff/aabf11dc0a938b84d76d7c147cbf0445d7bee297

[snip]

Quoted 20 lines
Quoted 20 lines
os-win32.c +12 -0
index b214e6a..7778366 100644
@@ -36,6 +36,45 @@
 /***********************************************************/
 /* Functions missing in mingw */
 
+#if defined(CONFIG_THREAD)
+
+int clock_gettime(clockid_t clock_id, struct timespec *pTimespec)
+{
+  int result = 0;
+  if (clock_id == CLOCK_REALTIME && pTimespec != 0) {
+    DWORD t = GetTickCount();
+    const unsigned cps = 1000;
+    struct timespec ts;
+    ts.tv_sec  = t / cps;
+    ts.tv_nsec = (t % cps) * (1000000000UL / cps);
+    *pTimespec = ts;
Quoted 8 lines

os-win32.c line 56

Quoted 6 lines
os-win32.c +6 -0
+  } else {
+    errno = EINVAL;
+    result = -1;
+  }
+  return result;
+}

Why is this needed? The only user of clock_gettime in the POSIX case is using CLOCK_MONOTONIC, and actually has a Win32 version already.

qemu-thread.c uses clock_gettime(CLOCK_REALTIME, ...)

Quoted 21 lines
Quoted 8 lines
os-win32.c +7 -0
+int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset)
+{
+    /* Dummy, do nothing. */
+    return EINVAL;
+}
+
+int sigfillset(sigset_t *set)

os-win32.c line 73

Quoted 10 lines
os-win32.c +10 -0
+{
+    int result = 0;
+    if (set) {
+        *(set) = (sigset_t)(-1);
+    } else {
+        errno = EINVAL;
+        result = -1;
+    }
+    return result;
+}

Instead of these, it's better to provide a Win32 implementation of mutexes and condvars. I'll submit it next week hopefully.

Quoted 1 line

Paolo

That's good news. My patch was only a quick hack to make threaded VNC work.

Thanks,
Stefan

#57 lore raw

[Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Aurelien Jarno
Quoted 7 lines · Aurelien Jarno

And what's the issue with that? People don't always look for performance when using QEMU. They even often try to emulate old machines (and non x86 ones), which anyway only have one CPU. This won't change in 5 years, the only thing is that those machines will be 5 years older.

People have to keep in mind that QEMU doesn't mean only virtualization and doesn't mean only x86.

AFAIU nobody is proposing to rip linux-user or TCG, just to improve its implementation.

You just as well have to understand that AIO means fewer Windows blue screens of death and not only better performance.

Paolo

#58 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Marcelo Tosatti
Quoted 8 lines · Marcelo Tosatti
Quoted 7 lines · Marcelo Tosatti
Quoted 4 lines
Quoted 4 lines

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Can you recall what was the test ?

It's also something I've seen using network transfer in guest. IIRC the biggest slowdown was using the smc91c111 card under qemu-system-arm where it was about 20% slower. Other cards on other architectures (I remember testing powerpc, mips and sh4) are more in the 5 to 10 % area.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#59 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Marcelo Tosatti
Quoted 15 lines · Marcelo Tosatti
Quoted 5 lines · Marcelo Tosatti
Quoted 4 lines
Quoted 4 lines

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Quoted 8 lines

Can you recall what was the test ?

Quoted 6 lines
Quoted 6 lines

Also, although -icount & iothread no longer deadlocks, icount still sometimes performs incredibly slow with the io-thread (compared to non-io-thread qemu). In particular when not using -icount auto but a fixed ticks per insn values. Sometimes it's so slow I thought it actually deadlocked, but no it was crawling :) I haven't had time to look at it any closer but I hope to do soon.

Quoted 3 lines

Edgar, please give the attached patch a try with fixed icount value. The calculation for next event makes no sense for iothread timeout, only for vcpu context.

Thanks Marcelo, this patch fixes the problems I was seeing here.

Cheers

Quoted 26 lines
cpus.c +1 -1
index 9c50a34..2280db1 100644
@@ -748,7 +748,7 @@ static void qemu_tcg_wait_io_event(void)
     CPUState *env;
 
     while (!any_cpu_has_work())
-        qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, 1000);
+        qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, qemu_calculate_timeout());
 
     qemu_mutex_unlock(&qemu_global_mutex);
 
vl.c +1 -1
index 837be97..dbd81a1 100644
@@ -1323,7 +1323,7 @@ void main_loop_wait(int nonblocking)
     if (nonblocking)
         timeout = 0;
     else {
-        timeout = qemu_calculate_timeout();
+        timeout = 1000;
         qemu_bh_update_timeout(&timeout);
     }
 
#61 lore raw

Re: [Qemu-devel] Re: [PATCH 2/7] Enable I/O thread and VNC threads by default

In reply to Marcelo Tosatti
Quoted 36 lines · Marcelo Tosatti
Quoted 35 lines · Marcelo Tosatti
Quoted 34 lines · Edgar E. Iglesias
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Anthony Liguori

Leave the disable options for now to help with testing but these will be removed once we're confident in the thread implementations.

Disabled code bit rots. These have been in tree long enough that we need to either commit to making them work or just remove them entirely.

Quoted 5 lines

I/O thread disables icount apparently.

I'm not really sure why. Marcelo, do you know the reason qemu_calculate_timeout returns a fixed value in the I/O thread regardless of icount?

Hi,

The following commit hopefully fixed that issue.

commit 225d02cd1a34d5d87e8acefbf8e244a5d12f5f8c

Author: Edgar E. Iglesias <[email protected]>
Date:   Sun Jan 23 04:44:51 2011 +0100

Avoid deadlock whith iothread and icount

When using the iothread together with icount, make sure the qemu_icount counter makes forward progress when the vcpu is idle to avoid deadlocks.

See http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg01602.html
for more info.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

One more thing I didn't mention on the email-thread or on IRC is that last time I checked, qemu with io-thread was performing significantly slower than non io-thread builds. That was with TCG emulation (not kvm). Somewhere between 5 - 10% slower, IIRC.

Can you recall what was the test ?

Hi, didn't see this until now..

IIRC, the test was booting a CRIS linux guest.

Cheers

#62 lore raw

cover vnc: the lost parts

In reply to Anthony Liguori

Hi Anthony,
If you want to enable vnc threaded server by default, you should really merge these two lost patchs :).
Thanks,

Corentin Chary (1):
vnc: qemu can die if the client is disconnected while updating screen

Yoshiaki Tamura (1):
vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2()

 ui/vnc-jobs-async.c |    4 ++++
 vl.c                |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.3.4
#63 lore raw

PATCH 1/2 vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2()

In reply to Anthony Liguori

From: Yoshiaki Tamura <[email protected]>

Currently qemu_set_fd_handler2() is only setting ioh->deleted upon deleting. This may cause a crash when a read handler calls qemu_set_fd_handler2() to delete handlers, but a write handler is still invoked from main_loop_wait(). Because main_loop_wait() checks handlers before calling, setting NULL upon deleting will protect handlers being called if already deleted.

One example is the new threaded vnc server. When an error occurs in the context of a read handler, it'll releases resources and deletes handlers. However, because the write handler still exists, it'll be called, and then crashes because of lack of resources. This patch fixes it.

---
 vl.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
vl.c +2 -0
index 14255c4..7a26bea 100644
@@ -1037,6 +1037,8 @@ int qemu_set_fd_handler2(int fd,
         QLIST_FOREACH(ioh, &io_handlers, next) {
             if (ioh->fd == fd) {
                 ioh->deleted = 1;
+                ioh->fd_read = NULL;
+                ioh->fd_write = NULL;
                 break;
             }
         }
Signature · 1 line
1.7.3.4
#64 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2()

Quoted 9 lines · Corentin Chary

From: Yoshiaki Tamura <[email protected]>

Currently qemu_set_fd_handler2() is only setting ioh->deleted upon deleting.  This may cause a crash when a read handler calls qemu_set_fd_handler2() to delete handlers, but a write handler is still invoked from main_loop_wait().  Because main_loop_wait() checks handlers before calling, setting NULL upon deleting will protect handlers being called if already deleted.

Quoted 5 lines

One example is the new threaded vnc server.  When an error occurs in the context of a read handler, it'll releases resources and deletes handlers.  However, because the write handler still exists, it'll be called, and then crashes because of lack of resources.  This patch fixes it.

Does this case still happen with qemu.git/master? In November I sent a patch to check for deleted handlers:

commit 0290b57bdfec83ca78b6d119ea9847bb17943328

Author: Stefan Hajnoczi <[email protected]>
Date:   Wed Nov 3 14:29:44 2010 +0000

Delete IOHandlers after potentially running them

Since commit 4bed9837309e58d208183f81d8344996744292cf an .fd_read() handler that deletes its IOHandler is exposed to .fd_write() being called on the deleted IOHandler.

This patch fixes deletion so that .fd_read() and .fd_write() are never called on an IOHandler that is marked for deletion.

So I don't think Yoshi's patch is necessary anymore?

Stefan

#65 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2()

Quoted 30 lines · Stefan Hajnoczi
Quoted 9 lines · Corentin Chary

From: Yoshiaki Tamura <[email protected]>

Currently qemu_set_fd_handler2() is only setting ioh->deleted upon deleting.  This may cause a crash when a read handler calls qemu_set_fd_handler2() to delete handlers, but a write handler is still invoked from main_loop_wait().  Because main_loop_wait() checks handlers before calling, setting NULL upon deleting will protect handlers being called if already deleted.

Quoted 5 lines

One example is the new threaded vnc server.  When an error occurs in the context of a read handler, it'll releases resources and deletes handlers.  However, because the write handler still exists, it'll be called, and then crashes because of lack of resources.  This patch fixes it.

Does this case still happen with qemu.git/master?  In November I sent a patch to check for deleted handlers:

commit 0290b57bdfec83ca78b6d119ea9847bb17943328
Author: Stefan Hajnoczi <[email protected]>
Date:   Wed Nov 3 14:29:44 2010 +0000

   Delete IOHandlers after potentially running them

   Since commit 4bed9837309e58d208183f81d8344996744292cf an .fd_read() handler that deletes its IOHandler is exposed to .fd_write() being called on the deleted IOHandler.

Quoted 7 lines

   This patch fixes deletion so that .fd_read() and .fd_write() are never called on an IOHandler that is marked for deletion.

So I don't think Yoshi's patch is necessary anymore?

Ho I didn't see that one.
It's probably not necessary, but it stills make sense to apply this patch since there is
absolutly no reasons to keep the old value in fd_read and fd_write when the user explicitly asked to set them to NULL.

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net
#66 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2()

Quoted 37 lines · Corentin Chary
Quoted 36 lines · Stefan Hajnoczi
Quoted 9 lines · Corentin Chary

From: Yoshiaki Tamura <[email protected]>

Currently qemu_set_fd_handler2() is only setting ioh->deleted upon deleting.  This may cause a crash when a read handler calls qemu_set_fd_handler2() to delete handlers, but a write handler is still invoked from main_loop_wait().  Because main_loop_wait() checks handlers before calling, setting NULL upon deleting will protect handlers being called if already deleted.

Quoted 5 lines

One example is the new threaded vnc server.  When an error occurs in the context of a read handler, it'll releases resources and deletes handlers.  However, because the write handler still exists, it'll be called, and then crashes because of lack of resources.  This patch fixes it.

Does this case still happen with qemu.git/master?  In November I sent a patch to check for deleted handlers:

commit 0290b57bdfec83ca78b6d119ea9847bb17943328
Author: Stefan Hajnoczi <[email protected]>
Date:   Wed Nov 3 14:29:44 2010 +0000

   Delete IOHandlers after potentially running them

   Since commit 4bed9837309e58d208183f81d8344996744292cf an .fd_read() handler that deletes its IOHandler is exposed to .fd_write() being called on the deleted IOHandler.

   This patch fixes deletion so that .fd_read() and .fd_write() are never called on an IOHandler that is marked for deletion.

Quoted 7 lines
Quoted 1 line

So I don't think Yoshi's patch is necessary anymore?

Ho I didn't see that one.
It's probably not necessary, but it stills make sense to apply this patch since there is
absolutly no reasons to keep the old value in fd_read and fd_write when the user explicitly asked to set them to NULL.

That's true, I don't see a good reason why we shouldn't clear them. The only minor advantage to keeping them is that it helps when debugging QEMU - you can identify the fd handler by its fd_read/fd_write function pointers easily.

Stefan

#67 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2()

2011/1/25 Stefan Hajnoczi <[email protected]>:

Quoted 47 lines
Quoted 37 lines · Corentin Chary
Quoted 36 lines · Stefan Hajnoczi
Quoted 9 lines · Corentin Chary

From: Yoshiaki Tamura <[email protected]>

Currently qemu_set_fd_handler2() is only setting ioh->deleted upon deleting.  This may cause a crash when a read handler calls qemu_set_fd_handler2() to delete handlers, but a write handler is still invoked from main_loop_wait().  Because main_loop_wait() checks handlers before calling, setting NULL upon deleting will protect handlers being called if already deleted.

Quoted 5 lines

One example is the new threaded vnc server.  When an error occurs in the context of a read handler, it'll releases resources and deletes handlers.  However, because the write handler still exists, it'll be called, and then crashes because of lack of resources.  This patch fixes it.

Does this case still happen with qemu.git/master?  In November I sent a patch to check for deleted handlers:

commit 0290b57bdfec83ca78b6d119ea9847bb17943328
Author: Stefan Hajnoczi <[email protected]>
Date:   Wed Nov 3 14:29:44 2010 +0000

   Delete IOHandlers after potentially running them

   Since commit 4bed9837309e58d208183f81d8344996744292cf an .fd_read() handler that deletes its IOHandler is exposed to .fd_write() being called on the deleted IOHandler.

   This patch fixes deletion so that .fd_read() and .fd_write() are never called on an IOHandler that is marked for deletion.

Quoted 7 lines
Quoted 1 line

So I don't think Yoshi's patch is necessary anymore?

Ho I didn't see that one.
It's probably not necessary, but it stills make sense to apply this patch since there is
absolutly no reasons to keep the old value in fd_read and fd_write when the user explicitly asked to set them to NULL.

Quoted 4 lines

That's true, I don't see a good reason why we shouldn't clear them. The only minor advantage to keeping them is that it helps when debugging QEMU - you can identify the fd handler by its fd_read/fd_write function pointers easily.

Well, since I posted the patch in August, I won't get surprised even the bug might be fixed due to other patches :) Regardless of that, I don't see the patch is doing something incorrect either. If some codes were relying on unset values, that should be wrong.

Yoshi

Quoted 4 lines

Stefan

#68 lore raw

PATCH 2/2 vnc: qemu can die if the client is disconnected while updating screen

In reply to Anthony Liguori

From: Corentin Chary <[email protected]>

agraf reported that qemu_mutex_destroy(vs->output_mutex) was failing in vnc_disconnect_finish() when the vnc client was disconnected while updating the screen.

It's because vnc_worker_thread_loop() tries to unlock the mutex while not locked.

---
 ui/vnc-jobs-async.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
ui/vnc-jobs-async.c +4 -0
index 6e9cf08..0b5d750 100644
@@ -227,6 +227,10 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
         if (job->vs->csock == -1) {
             vnc_unlock_display(job->vs->vd);
+            /* output mutex must be locked before going to
+             * disconnected:
+             */
+            vnc_lock_output(job->vs);
             goto disconnected;
         }
 
Signature · 1 line
1.7.3.4
#69 lore raw

PATCH 3/7 Add support for glib based threading and convert qemu thread to use it

In reply to Anthony Liguori

GLib is an extremely common library that has a portable thread implementation along with tons of other goodies.

GLib and GObject have a fantastic amount of infrastructure we can leverage in QEMU including an object oriented programming infrastructure.

Short term, it has a very nice thread pool implementation that we could leverage in something like virtio-9p.

Makefile +2 -0
index 6d601ee..bf24d1b 100644
@@ -104,6 +104,8 @@ audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
 
 QEMU_CFLAGS+=$(CURL_CFLAGS)
 
+QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
 ui/cocoa.o: ui/cocoa.m
 
 ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
Makefile.objs +2 -0
index c3e52c5..283e62a 100644
@@ -316,3 +316,5 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
+vl.o: QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
Makefile.target +1 -0
index e15b1c4..2c1c90e 100644
@@ -204,6 +204,7 @@ QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
+QEMU_CFLAGS += $(GLIB_CFLAGS)
 
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
configure +12 -0
index d5ac074..820fde9 100755
@@ -1658,6 +1658,17 @@ EOF
 fi
 
 ##########################################
+# glib support probe
+if $pkg_config --modversion gthread-2.0 > /dev/null 2>&1 ; then
+    glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
+    glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
+    libs_softmmu="$glib_libs $libs_softmmu"
+else
+    echo "glib-2.0 required to compile QEMU"
+    exit 1
+fi
+
+##########################################
 # kvm probe
 if test "$kvm" != "no" ; then
     cat > $TMPC <<EOF
@@ -2677,6 +2688,7 @@ if test "$bluez" = "yes" ; then
   echo "CONFIG_BLUEZ=y" >> $config_host_mak
   echo "BLUEZ_CFLAGS=$bluez_cflags" >> $config_host_mak
 fi
+echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
 if test "$xen" = "yes" ; then
   echo "CONFIG_XEN=y" >> $config_host_mak
 fi
qemu-thread.c +68 -109

251 lines not on this page · raw message

qemu-thread.h +6 -5
index 19bb30c..dc22a60 100644
@@ -1,18 +1,19 @@
 #ifndef __QEMU_THREAD_H
 #define __QEMU_THREAD_H 1
-#include "semaphore.h"
-#include "pthread.h"
+#include <glib.h>
+#include <pthread.h>
 
 struct QemuMutex {
-    pthread_mutex_t lock;
+    GStaticMutex lock;
 };
 
 struct QemuCond {
-    pthread_cond_t cond;
+    GCond *cond;
 };
 
 struct QemuThread {
-    pthread_t thread;
+    GThread *thread;
+    pthread_t tid;
 };
 
 typedef struct QemuMutex QemuMutex;
vl.c +4 -0
index 0292184..bbe0931 100644
@@ -165,6 +165,8 @@ int main(int argc, char **argv)
 
 #include "ui/qemu-spice.h"
 
+#include <glib.h>
+
 //#define DEBUG_NET
 //#define DEBUG_SLIRP
 
@@ -1918,6 +1920,8 @@ int main(int argc, char **argv, char **envp)
     atexit(qemu_run_exit_notifiers);
     error_set_progname(argv[0]);
 
+    g_thread_init(NULL);
+
     init_clocks();
 
     qemu_cache_utils_init(envp);
Signature · 1 line
1.7.0.4
#70 lore raw

Re: [Qemu-devel] [PATCH 3/7] Add support for glib based threading and convert qemu thread to use it

Quoted 81 lines · Anthony Liguori

GLib is an extremely common library that has a portable thread implementation along with tons of other goodies.

GLib and GObject have a fantastic amount of infrastructure we can leverage in QEMU including an object oriented programming infrastructure.

Short term, it has a very nice thread pool implementation that we could leverage in something like virtio-9p.

Makefile +2 -0
index 6d601ee..bf24d1b 100644
@@ -104,6 +104,8 @@ audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
 
 QEMU_CFLAGS+=$(CURL_CFLAGS)
 
+QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
 ui/cocoa.o: ui/cocoa.m
 
 ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
Makefile.objs +2 -0
index c3e52c5..283e62a 100644
@@ -316,3 +316,5 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
+vl.o: QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
Makefile.target +1 -0
index e15b1c4..2c1c90e 100644
@@ -204,6 +204,7 @@ QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
+QEMU_CFLAGS += $(GLIB_CFLAGS)
 
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
configure +12 -0
index d5ac074..820fde9 100755
@@ -1658,6 +1658,17 @@ EOF
 fi
 
 ##########################################
+# glib support probe
+if $pkg_config --modversion gthread-2.0 > /dev/null 2>&1 ; then
+    glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
+    glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
+    libs_softmmu="$glib_libs $libs_softmmu"
+else
+    echo "glib-2.0 required to compile QEMU"
+    exit 1
+fi
+
+##########################################
 # kvm probe
 if test "$kvm" != "no" ; then
     cat > $TMPC <<EOF
@@ -2677,6 +2688,7 @@ if test "$bluez" = "yes" ; then
   echo "CONFIG_BLUEZ=y" >> $config_host_mak
   echo "BLUEZ_CFLAGS=$bluez_cflags" >> $config_host_mak
 fi
+echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
 if test "$xen" = "yes" ; then
   echo "CONFIG_XEN=y" >> $config_host_mak
 fi
qemu-thread.c +0 -0
index fbc78fe..2c521ab 100644

qemu-thread.c line 19

Quoted 10 lines
qemu-thread.c +0 -7
@@ -10,183 +10,142 @@
  * See the COPYING file in the top-level directory.
  *
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
-#include <signal.h>
-#include <stdint.h>
-#include <string.h>

Why removing <signal.h>?

Quoted 184 lines
qemu-thread.c +45 -88
-#include "qemu-thread.h"
 
-static void error_exit(int err, const char *msg)
-{
-    fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
-    exit(1);
-}
+#include "qemu-common.h"
+#include "qemu-thread.h"
 
 void qemu_mutex_init(QemuMutex *mutex)
 {
-    int err;
-
-    err = pthread_mutex_init(&mutex->lock, NULL);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_init(&mutex->lock);
 }
 
 void qemu_mutex_destroy(QemuMutex *mutex)
 {
-    int err;
-
-    err = pthread_mutex_destroy(&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_free(&mutex->lock);
 }
 
 void qemu_mutex_lock(QemuMutex *mutex)
 {
-    int err;
-
-    err = pthread_mutex_lock(&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_lock(&mutex->lock);
 }
 
 int qemu_mutex_trylock(QemuMutex *mutex)
 {
-    return pthread_mutex_trylock(&mutex->lock);
-}
-
-static void timespec_add_ms(struct timespec *ts, uint64_t msecs)
-{
-    ts->tv_sec = ts->tv_sec + (long)(msecs / 1000);
-    ts->tv_nsec = (ts->tv_nsec + ((long)msecs % 1000) * 1000000);
-    if (ts->tv_nsec >= 1000000000) {
-        ts->tv_nsec -= 1000000000;
-        ts->tv_sec++;
-    }
-}
-
-int qemu_mutex_timedlock(QemuMutex *mutex, uint64_t msecs)
-{
-    int err;
-    struct timespec ts;
-
-    clock_gettime(CLOCK_REALTIME, &ts);
-    timespec_add_ms(&ts, msecs);
-
-    err = pthread_mutex_timedlock(&mutex->lock, &ts);
-    if (err && err != ETIMEDOUT)
-        error_exit(err, __func__);
-    return err;
+    return g_static_mutex_trylock(&mutex->lock);
 }
 
 void qemu_mutex_unlock(QemuMutex *mutex)
 {
-    int err;
-
-    err = pthread_mutex_unlock(&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_unlock(&mutex->lock);
 }
 
 void qemu_cond_init(QemuCond *cond)
 {
-    int err;
-
-    err = pthread_cond_init(&cond->cond, NULL);
-    if (err)
-        error_exit(err, __func__);
+    cond->cond = g_cond_new();
 }
 
 void qemu_cond_destroy(QemuCond *cond)
 {
-    int err;
-
-    err = pthread_cond_destroy(&cond->cond);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_free(cond->cond);
 }
 
 void qemu_cond_signal(QemuCond *cond)
 {
-    int err;
-
-    err = pthread_cond_signal(&cond->cond);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_signal(cond->cond);
 }
 
 void qemu_cond_broadcast(QemuCond *cond)
 {
-    int err;
-
-    err = pthread_cond_broadcast(&cond->cond);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_broadcast(cond->cond);
 }
 
 void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex)
 {
-    int err;
-
-    err = pthread_cond_wait(&cond->cond, &mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_wait(cond->cond, g_static_mutex_get_mutex(&mutex->lock));
 }
 
 int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs)
 {
-    struct timespec ts;
-    int err;
+    GTimeVal abs_time;
+
+    assert(cond->cond != NULL);
 
-    clock_gettime(CLOCK_REALTIME, &ts);
-    timespec_add_ms(&ts, msecs);
+    g_get_current_time(&abs_time);
+    g_time_val_add(&abs_time, msecs * 1000); /* MSEC to USEC */
 
-    err = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts);
-    if (err && err != ETIMEDOUT)
-        error_exit(err, __func__);
-    return err;
+    return g_cond_timed_wait(cond->cond,
+                             g_static_mutex_get_mutex(&mutex->lock), &abs_time);
+}
+
+struct trampoline_data
+{
+    QemuThread *thread;
+    void *(*startfn)(void *);
+    void *opaque;
+    QemuMutex lock;
+};
+
+static gpointer thread_trampoline(gpointer data)
+{
+    struct trampoline_data *td = data;
+    gpointer retval;
+
+    td->thread->tid = pthread_self();
+    qemu_mutex_unlock(&td->lock);
+
+    retval = td->startfn(td->opaque);
+    qemu_free(td);
+
+    return retval;
 }
 
 void qemu_thread_create(QemuThread *thread,
-                       void *(*start_routine)(void*),
-                       void *arg)
+                        void *(*start_routine)(void*),
+                        void *arg)
 {
-    int err;
+    struct trampoline_data *td = qemu_malloc(sizeof(*td));
+    sigset_t set, old;
 
-    /* Leave signal handling to the iothread.  */

qemu-thread.c line 117

Quoted 10 lines
qemu-thread.c +7 -1
-    sigset_t set, oldset;
+    td->startfn = start_routine;
+    td->opaque = arg;
+    td->thread = thread;
+    qemu_mutex_init(&td->lock);
+
+    /* on behalf of the new thread */
+    qemu_mutex_lock(&td->lock);
 
     sigfillset(&set);

If it is still in use here? This simply doesn't build:

qemu-thread.c: In function ‘q_thread_create_nosignal’:
qemu-thread.c:34: error: implicit declaration of function ‘sigfillset’ qemu-thread.c:34: error: nested extern declaration of ‘sigfillset’ qemu-thread.c:35: error: implicit declaration of function ‘pthread_sigmask’ qemu-thread.c:35: error: nested extern declaration of ‘pthread_sigmask’ qemu-thread.c:35: error: ‘SIG_SETMASK’ undeclared (first use in this function) qemu-thread.c:35: error: (Each undeclared identifier is reported only once qemu-thread.c:35: error: for each function it appears in.) qemu-thread.c: In function ‘qemu_sthread_create’:
qemu-thread.c:80: error: ‘SIG_SETMASK’ undeclared (first use in this function) qemu-thread.c: In function ‘qemu_sthread_signal’:
qemu-thread.c:96: error: implicit declaration of function ‘pthread_kill’ qemu-thread.c:96: error: nested extern declaration of ‘pthread_kill’

Quoted 103 lines
qemu-thread.c +16 -13
-    pthread_sigmask(SIG_SETMASK, &set, &oldset);
-    err = pthread_create(&thread->thread, NULL, start_routine, arg);
-    if (err)
-        error_exit(err, __func__);
+    pthread_sigmask(SIG_SETMASK, &set, &old);
+    thread->thread = g_thread_create(thread_trampoline, td, TRUE, NULL);
+    pthread_sigmask(SIG_SETMASK, &old, NULL);
+
+    /* we're transfering ownership of this lock to the thread so we no
+     * longer hold it here */
 
-    pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+    qemu_mutex_lock(&td->lock);
+    /* validate tid */
+    qemu_mutex_unlock(&td->lock);
+
+    qemu_mutex_destroy(&td->lock);
 }
 
 void qemu_thread_signal(QemuThread *thread, int sig)
 {
-    int err;
-
-    err = pthread_kill(thread->thread, sig);
-    if (err)
-        error_exit(err, __func__);
+    pthread_kill(thread->tid, sig);
 }
 
 void qemu_thread_self(QemuThread *thread)
 {
-    thread->thread = pthread_self();
+    thread->thread = g_thread_self();
+    thread->tid = pthread_self();
 }
 
 int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
 {
-   return pthread_equal(thread1->thread, thread2->thread);
+    return (thread1->thread == thread2->thread);
 }
 
 void qemu_thread_exit(void *retval)
 {
-    pthread_exit(retval);
+    g_thread_exit(retval);
 }
qemu-thread.h +6 -5
index 19bb30c..dc22a60 100644
@@ -1,18 +1,19 @@
 #ifndef __QEMU_THREAD_H
 #define __QEMU_THREAD_H 1
-#include "semaphore.h"
-#include "pthread.h"
+#include <glib.h>
+#include <pthread.h>
 
 struct QemuMutex {
-    pthread_mutex_t lock;
+    GStaticMutex lock;
 };
 
 struct QemuCond {
-    pthread_cond_t cond;
+    GCond *cond;
 };
 
 struct QemuThread {
-    pthread_t thread;
+    GThread *thread;
+    pthread_t tid;
 };
 
 typedef struct QemuMutex QemuMutex;
vl.c +4 -0
index 0292184..bbe0931 100644
@@ -165,6 +165,8 @@ int main(int argc, char **argv)
 
 #include "ui/qemu-spice.h"
 
+#include <glib.h>
+
 //#define DEBUG_NET
 //#define DEBUG_SLIRP
 
@@ -1918,6 +1920,8 @@ int main(int argc, char **argv, char **envp)
     atexit(qemu_run_exit_notifiers);
     error_set_progname(argv[0]);
 
+    g_thread_init(NULL);
+
     init_clocks();
 
     qemu_cache_utils_init(envp);
Signature · 1 line
1.7.0.4
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#71 lore raw

Re: [Qemu-devel] [PATCH 3/7] Add support for glib based threading and convert qemu thread to use it

Quoted 87 lines · Aurelien Jarno
Quoted 85 lines · Anthony Liguori

GLib is an extremely common library that has a portable thread implementation along with tons of other goodies.

GLib and GObject have a fantastic amount of infrastructure we can leverage in QEMU including an object oriented programming infrastructure.

Short term, it has a very nice thread pool implementation that we could leverage in something like virtio-9p.

Makefile +2 -0
index 6d601ee..bf24d1b 100644
@@ -104,6 +104,8 @@ audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
 
  QEMU_CFLAGS+=$(CURL_CFLAGS)
 
+QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
  ui/cocoa.o: ui/cocoa.m
 
  ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
Makefile.objs +2 -0
index c3e52c5..283e62a 100644
@@ -316,3 +316,5 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
  vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
+vl.o: QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
Makefile.target +1 -0
index e15b1c4..2c1c90e 100644
@@ -204,6 +204,7 @@ QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
  QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
  QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
  QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
+QEMU_CFLAGS += $(GLIB_CFLAGS)
 
  # xen backend driver support
  obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
configure +12 -0
index d5ac074..820fde9 100755
@@ -1658,6 +1658,17 @@ EOF
  fi
 
  ##########################################
+# glib support probe
+if $pkg_config --modversion gthread-2.0>  /dev/null 2>&1 ; then
+    glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
+    glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
+    libs_softmmu="$glib_libs $libs_softmmu"
+else
+    echo "glib-2.0 required to compile QEMU"
+    exit 1
+fi
+
+##########################################
  # kvm probe
  if test "$kvm" != "no" ; then
      cat>  $TMPC<<EOF
@@ -2677,6 +2688,7 @@ if test "$bluez" = "yes" ; then
    echo "CONFIG_BLUEZ=y">>  $config_host_mak
    echo "BLUEZ_CFLAGS=$bluez_cflags">>  $config_host_mak
  fi
+echo "GLIB_CFLAGS=$glib_cflags">>  $config_host_mak
  if test "$xen" = "yes" ; then
    echo "CONFIG_XEN=y">>  $config_host_mak
  fi
qemu-thread.c +0 -1
index fbc78fe..2c521ab 100644
@@ -10,183 +10,142 @@
   * See the COPYING file in the top-level directory.
   *
   */
-#include<stdlib.h>
Quoted 9 lines

qemu-thread.c line 13

Quoted 7 lines
qemu-thread.c +0 -6
-#include<stdio.h>
-#include<errno.h>
-#include<time.h>
-#include<signal.h>
-#include<stdint.h>
-#include<string.h>
 

Why removing<signal.h>?

It looked like unnecessary includes crept in so I remove them all. It still built for me but apparently not for you. I'll update accordingly.

Maybe we should put signal.h in qemu-common.h?

Regards,

Anthony Liguori

Quoted 318 lines
Quoted 185 lines
qemu-thread.c +45 -89
-#include "qemu-thread.h"
 
-static void error_exit(int err, const char *msg)
-{
-    fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
-    exit(1);
-}
+#include "qemu-common.h"
+#include "qemu-thread.h"
 
  void qemu_mutex_init(QemuMutex *mutex)
  {
-    int err;
-
-    err = pthread_mutex_init(&mutex->lock, NULL);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_init(&mutex->lock);
  }
 
  void qemu_mutex_destroy(QemuMutex *mutex)
  {
-    int err;
-
-    err = pthread_mutex_destroy(&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_free(&mutex->lock);
  }
 
  void qemu_mutex_lock(QemuMutex *mutex)
  {
-    int err;
-
-    err = pthread_mutex_lock(&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_lock(&mutex->lock);
  }
 
  int qemu_mutex_trylock(QemuMutex *mutex)
  {
-    return pthread_mutex_trylock(&mutex->lock);
-}
-
-static void timespec_add_ms(struct timespec *ts, uint64_t msecs)
-{
-    ts->tv_sec = ts->tv_sec + (long)(msecs / 1000);
-    ts->tv_nsec = (ts->tv_nsec + ((long)msecs % 1000) * 1000000);
-    if (ts->tv_nsec>= 1000000000) {
-        ts->tv_nsec -= 1000000000;
-        ts->tv_sec++;
-    }
-}
-
-int qemu_mutex_timedlock(QemuMutex *mutex, uint64_t msecs)
-{
-    int err;
-    struct timespec ts;
-
-    clock_gettime(CLOCK_REALTIME,&ts);
-    timespec_add_ms(&ts, msecs);
-
-    err = pthread_mutex_timedlock(&mutex->lock,&ts);
-    if (err&&  err != ETIMEDOUT)
-        error_exit(err, __func__);
-    return err;
+    return g_static_mutex_trylock(&mutex->lock);
  }
 
  void qemu_mutex_unlock(QemuMutex *mutex)
  {
-    int err;
-
-    err = pthread_mutex_unlock(&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_static_mutex_unlock(&mutex->lock);
  }
 
  void qemu_cond_init(QemuCond *cond)
  {
-    int err;
-
-    err = pthread_cond_init(&cond->cond, NULL);
-    if (err)
-        error_exit(err, __func__);
+    cond->cond = g_cond_new();
  }
 
  void qemu_cond_destroy(QemuCond *cond)
  {
-    int err;
-
-    err = pthread_cond_destroy(&cond->cond);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_free(cond->cond);
  }
 
  void qemu_cond_signal(QemuCond *cond)
  {
-    int err;
-
-    err = pthread_cond_signal(&cond->cond);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_signal(cond->cond);
  }
 
  void qemu_cond_broadcast(QemuCond *cond)
  {
-    int err;
-
-    err = pthread_cond_broadcast(&cond->cond);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_broadcast(cond->cond);
  }
 
  void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex)
  {
-    int err;
-
-    err = pthread_cond_wait(&cond->cond,&mutex->lock);
-    if (err)
-        error_exit(err, __func__);
+    g_cond_wait(cond->cond, g_static_mutex_get_mutex(&mutex->lock));
  }
 
  int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs)
  {
-    struct timespec ts;
-    int err;
+    GTimeVal abs_time;
+
+    assert(cond->cond != NULL);
 
-    clock_gettime(CLOCK_REALTIME,&ts);
-    timespec_add_ms(&ts, msecs);
+    g_get_current_time(&abs_time);
+    g_time_val_add(&abs_time, msecs * 1000); /* MSEC to USEC */
 
-    err = pthread_cond_timedwait(&cond->cond,&mutex->lock,&ts);
-    if (err&&  err != ETIMEDOUT)
-        error_exit(err, __func__);
-    return err;
+    return g_cond_timed_wait(cond->cond,
+                             g_static_mutex_get_mutex(&mutex->lock),&abs_time);
+}
+
+struct trampoline_data
+{
+    QemuThread *thread;
+    void *(*startfn)(void *);
+    void *opaque;
+    QemuMutex lock;
+};
+
+static gpointer thread_trampoline(gpointer data)
+{
+    struct trampoline_data *td = data;
+    gpointer retval;
+
+    td->thread->tid = pthread_self();
+    qemu_mutex_unlock(&td->lock);
+
+    retval = td->startfn(td->opaque);
+    qemu_free(td);
+
+    return retval;
  }
 
  void qemu_thread_create(QemuThread *thread,
-                       void *(*start_routine)(void*),
-                       void *arg)
+                        void *(*start_routine)(void*),
+                        void *arg)
  {
-    int err;
+    struct trampoline_data *td = qemu_malloc(sizeof(*td));
+    sigset_t set, old;
 
-    /* Leave signal handling to the iothread.  */
-    sigset_t set, oldset;

qemu-thread.c line 124

Quoted 10 lines
qemu-thread.c +7 -0
+    td->startfn = start_routine;
+    td->opaque = arg;
+    td->thread = thread;
+    qemu_mutex_init(&td->lock);
+
+    /* on behalf of the new thread */
+    qemu_mutex_lock(&td->lock);
 
      sigfillset(&set);
 

If it is still in use here? This simply doesn't build:

qemu-thread.c: In function ‘q_thread_create_nosignal’:
qemu-thread.c:34: error: implicit declaration of function ‘sigfillset’ qemu-thread.c:34: error: nested extern declaration of ‘sigfillset’ qemu-thread.c:35: error: implicit declaration of function ‘pthread_sigmask’ qemu-thread.c:35: error: nested extern declaration of ‘pthread_sigmask’ qemu-thread.c:35: error: ‘SIG_SETMASK’ undeclared (first use in this function) qemu-thread.c:35: error: (Each undeclared identifier is reported only once qemu-thread.c:35: error: for each function it appears in.) qemu-thread.c: In function ‘qemu_sthread_create’:
qemu-thread.c:80: error: ‘SIG_SETMASK’ undeclared (first use in this function) qemu-thread.c: In function ‘qemu_sthread_signal’:
qemu-thread.c:96: error: implicit declaration of function ‘pthread_kill’ qemu-thread.c:96: error: nested extern declaration of ‘pthread_kill’

Quoted 104 lines
qemu-thread.c +16 -13
-    pthread_sigmask(SIG_SETMASK,&set,&oldset);
-    err = pthread_create(&thread->thread, NULL, start_routine, arg);
-    if (err)
-        error_exit(err, __func__);
+    pthread_sigmask(SIG_SETMASK,&set,&old);
+    thread->thread = g_thread_create(thread_trampoline, td, TRUE, NULL);
+    pthread_sigmask(SIG_SETMASK,&old, NULL);
+
+    /* we're transfering ownership of this lock to the thread so we no
+     * longer hold it here */
 
-    pthread_sigmask(SIG_SETMASK,&oldset, NULL);
+    qemu_mutex_lock(&td->lock);
+    /* validate tid */
+    qemu_mutex_unlock(&td->lock);
+
+    qemu_mutex_destroy(&td->lock);
  }
 
  void qemu_thread_signal(QemuThread *thread, int sig)
  {
-    int err;
-
-    err = pthread_kill(thread->thread, sig);
-    if (err)
-        error_exit(err, __func__);
+    pthread_kill(thread->tid, sig);
  }
 
  void qemu_thread_self(QemuThread *thread)
  {
-    thread->thread = pthread_self();
+    thread->thread = g_thread_self();
+    thread->tid = pthread_self();
  }
 
  int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
  {
-   return pthread_equal(thread1->thread, thread2->thread);
+    return (thread1->thread == thread2->thread);
  }
 
  void qemu_thread_exit(void *retval)
  {
-    pthread_exit(retval);
+    g_thread_exit(retval);
  }
qemu-thread.h +6 -5
index 19bb30c..dc22a60 100644
@@ -1,18 +1,19 @@
  #ifndef __QEMU_THREAD_H
  #define __QEMU_THREAD_H 1
-#include "semaphore.h"
-#include "pthread.h"
+#include<glib.h>
+#include<pthread.h>
 
  struct QemuMutex {
-    pthread_mutex_t lock;
+    GStaticMutex lock;
  };
 
  struct QemuCond {
-    pthread_cond_t cond;
+    GCond *cond;
  };
 
  struct QemuThread {
-    pthread_t thread;
+    GThread *thread;
+    pthread_t tid;
  };
 
  typedef struct QemuMutex QemuMutex;
vl.c +4 -0
index 0292184..bbe0931 100644
@@ -165,6 +165,8 @@ int main(int argc, char **argv)
 
  #include "ui/qemu-spice.h"
 
+#include<glib.h>
+
  //#define DEBUG_NET
  //#define DEBUG_SLIRP
 
@@ -1918,6 +1920,8 @@ int main(int argc, char **argv, char **envp)
      atexit(qemu_run_exit_notifiers);
      error_set_progname(argv[0]);
 
+    g_thread_init(NULL);
+
      init_clocks();
 
      qemu_cache_utils_init(envp);
Signature · 1 line
1.7.0.4
#72 lore raw

[Qemu-devel] Re: [PATCH 3/7] Add support for glib based threading and convert qemu thread to use it

In reply to Anthony Liguori

qemu-thread.c line 34

Quoted 4 lines · Anthony Liguori
  int qemu_mutex_trylock(QemuMutex *mutex)
  {
qemu-thread.c +1 -1
-    return pthread_mutex_trylock(&mutex->lock);
+    return g_static_mutex_trylock(&mutex->lock);

This is missing a !

Paolo

#73 lore raw

[Qemu-devel] Re: [PATCH 3/7] Add support for glib based threading and convert qemu thread to use it

Quoted 7 lines · Paolo Bonzini

qemu-thread.c line 34

Quoted 4 lines · Anthony Liguori
  int qemu_mutex_trylock(QemuMutex *mutex)
  {
qemu-thread.c +1 -1
-    return pthread_mutex_trylock(&mutex->lock);
+    return g_static_mutex_trylock(&mutex->lock);

This is missing a !

Good catch.

Regards,

Anthony Liguori

Quoted 2 lines

Paolo

#74 lore raw

PATCH 4/7 Get rid of QemuMutex and teach its callers about GStaticMutex

In reply to Anthony Liguori
cpus.c +38 -29
index 9cf7e6e..0f8e33b 100644
@@ -321,8 +321,8 @@ void vm_stop(int reason)
 
 #include "qemu-thread.h"
 
-QemuMutex qemu_global_mutex;
-static QemuMutex qemu_fair_mutex;
+GStaticMutex qemu_global_mutex;
+static GStaticMutex qemu_fair_mutex;
 
 static QemuThread io_thread;
 
@@ -416,9 +416,9 @@ int qemu_init_main_loop(void)
     qemu_cond_init(&qemu_system_cond);
     qemu_cond_init(&qemu_pause_cond);
     qemu_cond_init(&qemu_work_cond);
-    qemu_mutex_init(&qemu_fair_mutex);
-    qemu_mutex_init(&qemu_global_mutex);
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_init(&qemu_fair_mutex);
+    g_static_mutex_init(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
 
     qemu_thread_self(&io_thread);
 
@@ -454,7 +454,8 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
     while (!wi.done) {
         CPUState *self_env = cpu_single_env;
 
-        qemu_cond_wait(&qemu_work_cond, &qemu_global_mutex);
+        qemu_cond_wait(&qemu_work_cond,
+                       g_static_mutex_get_mutex(&qemu_global_mutex));
         cpu_single_env = self_env;
     }
 }
@@ -490,19 +491,20 @@ static void qemu_tcg_wait_io_event(void)
     CPUState *env;
 
     while (!any_cpu_has_work())
-        qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, 1000);
+        qemu_cond_timedwait(tcg_halt_cond,
+                            g_static_mutex_get_mutex(&qemu_global_mutex), 1000);
 
-    qemu_mutex_unlock(&qemu_global_mutex);
+    g_static_mutex_unlock(&qemu_global_mutex);
 
     /*
      * Users of qemu_global_mutex can be starved, having no chance
      * to acquire it since this path will get to it first.
      * So use another lock to provide fairness.
      */
-    qemu_mutex_lock(&qemu_fair_mutex);
-    qemu_mutex_unlock(&qemu_fair_mutex);
+    g_static_mutex_lock(&qemu_fair_mutex);
+    g_static_mutex_unlock(&qemu_fair_mutex);
 
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         qemu_wait_io_event_common(env);
@@ -551,12 +553,12 @@ static void qemu_kvm_eat_signal(CPUState *env, int timeout)
     sigaddset(&waitset, SIGBUS);
 
     do {
-        qemu_mutex_unlock(&qemu_global_mutex);
+        g_static_mutex_unlock(&qemu_global_mutex);
 
         r = sigtimedwait(&waitset, &siginfo, &ts);
         e = errno;
 
-        qemu_mutex_lock(&qemu_global_mutex);
+        g_static_mutex_lock(&qemu_global_mutex);
 
         if (r == -1 && !(e == EAGAIN || e == EINTR)) {
             fprintf(stderr, "sigtimedwait: %s\n", strerror(e));
@@ -585,7 +587,8 @@ static void qemu_kvm_eat_signal(CPUState *env, int timeout)
 static void qemu_kvm_wait_io_event(CPUState *env)
 {
     while (!cpu_has_work(env))
-        qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000);
+        qemu_cond_timedwait(env->halt_cond,
+                            g_static_mutex_get_mutex(&qemu_global_mutex), 1000);
 
     qemu_kvm_eat_signal(env, 0);
     qemu_wait_io_event_common(env);
@@ -597,7 +600,7 @@ static void *kvm_cpu_thread_fn(void *arg)
 {
     CPUState *env = arg;
 
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
     qemu_thread_self(env->thread);
     if (kvm_enabled())
         kvm_init_vcpu(env);
@@ -610,7 +613,8 @@ static void *kvm_cpu_thread_fn(void *arg)
 
     /* and wait for machine initialization */
     while (!qemu_system_ready)
-        qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100);
+        qemu_cond_timedwait(&qemu_system_cond,
+                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
 
     while (1) {
         if (cpu_can_run(env))
@@ -629,14 +633,15 @@ static void *tcg_cpu_thread_fn(void *arg)
     qemu_thread_self(env->thread);
 
     /* signal CPU creation */
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
     for (env = first_cpu; env != NULL; env = env->next_cpu)
         env->created = 1;
     qemu_cond_signal(&qemu_cpu_cond);
 
     /* and wait for machine initialization */
     while (!qemu_system_ready)
-        qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100);
+        qemu_cond_timedwait(&qemu_system_cond,
+                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
 
     while (1) {
         cpu_exec_all();
@@ -737,22 +742,22 @@ static sigset_t block_io_signals(void)
 void qemu_mutex_lock_iothread(void)
 {
     if (kvm_enabled()) {
-        qemu_mutex_lock(&qemu_fair_mutex);
-        qemu_mutex_lock(&qemu_global_mutex);
-        qemu_mutex_unlock(&qemu_fair_mutex);
+        g_static_mutex_lock(&qemu_fair_mutex);
+        g_static_mutex_lock(&qemu_global_mutex);
+        g_static_mutex_unlock(&qemu_fair_mutex);
     } else {
-        qemu_mutex_lock(&qemu_fair_mutex);
-        if (qemu_mutex_trylock(&qemu_global_mutex)) {
+        g_static_mutex_lock(&qemu_fair_mutex);
+        if (g_static_mutex_trylock(&qemu_global_mutex)) {
             qemu_thread_signal(tcg_cpu_thread, SIG_IPI);
-            qemu_mutex_lock(&qemu_global_mutex);
+            g_static_mutex_lock(&qemu_global_mutex);
         }
-        qemu_mutex_unlock(&qemu_fair_mutex);
+        g_static_mutex_unlock(&qemu_fair_mutex);
     }
 }
 
 void qemu_mutex_unlock_iothread(void)
 {
-    qemu_mutex_unlock(&qemu_global_mutex);
+    g_static_mutex_unlock(&qemu_global_mutex);
 }
 
 static int all_vcpus_paused(void)
@@ -779,7 +784,8 @@ void pause_all_vcpus(void)
     }
 
     while (!all_vcpus_paused()) {
-        qemu_cond_timedwait(&qemu_pause_cond, &qemu_global_mutex, 100);
+        qemu_cond_timedwait(&qemu_pause_cond,
+                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
         penv = first_cpu;
         while (penv) {
             qemu_cpu_kick(penv);
@@ -810,7 +816,9 @@ static void tcg_init_vcpu(void *_env)
         qemu_cond_init(env->halt_cond);
         qemu_thread_create(env->thread, tcg_cpu_thread_fn, env);
         while (env->created == 0)
-            qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100);
+            qemu_cond_timedwait(&qemu_cpu_cond,
+                                g_static_mutex_get_mutex(&qemu_global_mutex),
+                                100);
         tcg_cpu_thread = env->thread;
         tcg_halt_cond = env->halt_cond;
     } else {
@@ -826,7 +834,8 @@ static void kvm_start_vcpu(CPUState *env)
     qemu_cond_init(env->halt_cond);
     qemu_thread_create(env->thread, kvm_cpu_thread_fn, env);
     while (env->created == 0)
-        qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100);
+        qemu_cond_timedwait(&qemu_cpu_cond,
+                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
 }
 
 void qemu_init_vcpu(void *_env)
qemu-thread.c +11 -37

97 lines not on this page · raw message

qemu-thread.h +2 -14
index dc22a60..dec6848 100644
@@ -3,10 +3,6 @@
 #include <glib.h>
 #include <pthread.h>
 
-struct QemuMutex {
-    GStaticMutex lock;
-};
-
 struct QemuCond {
     GCond *cond;
 };
@@ -16,23 +12,15 @@ struct QemuThread {
     pthread_t tid;
 };
 
-typedef struct QemuMutex QemuMutex;
 typedef struct QemuCond QemuCond;
 typedef struct QemuThread QemuThread;
 
-void qemu_mutex_init(QemuMutex *mutex);
-void qemu_mutex_destroy(QemuMutex *mutex);
-void qemu_mutex_lock(QemuMutex *mutex);
-int qemu_mutex_trylock(QemuMutex *mutex);
-int qemu_mutex_timedlock(QemuMutex *mutex, uint64_t msecs);
-void qemu_mutex_unlock(QemuMutex *mutex);
-
 void qemu_cond_init(QemuCond *cond);
 void qemu_cond_destroy(QemuCond *cond);
 void qemu_cond_signal(QemuCond *cond);
 void qemu_cond_broadcast(QemuCond *cond);
-void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
-int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs);
+void qemu_cond_wait(QemuCond *cond, GMutex *mutex);
+int qemu_cond_timedwait(QemuCond *cond, GMutex *mutex, uint64_t msecs);
 
 void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
ui/vnc-jobs-async.c +7 -7
index 6e9cf08..48f567e 100644
@@ -50,7 +50,7 @@
 
 struct VncJobQueue {
     QemuCond cond;
-    QemuMutex mutex;
+    GStaticMutex mutex;
     QemuThread thread;
     Buffer buffer;
     bool exit;
@@ -67,12 +67,12 @@ static VncJobQueue *queue;
 
 static void vnc_lock_queue(VncJobQueue *queue)
 {
-    qemu_mutex_lock(&queue->mutex);
+    g_static_mutex_lock(&queue->mutex);
 }
 
 static void vnc_unlock_queue(VncJobQueue *queue)
 {
-    qemu_mutex_unlock(&queue->mutex);
+    g_static_mutex_unlock(&queue->mutex);
 }
 
 VncJob *vnc_job_new(VncState *vs)
@@ -152,7 +152,7 @@ void vnc_jobs_join(VncState *vs)
 {
     vnc_lock_queue(queue);
     while (vnc_has_job_locked(vs)) {
-        qemu_cond_wait(&queue->cond, &queue->mutex);
+        qemu_cond_wait(&queue->cond, g_static_mutex_get_mutex(&queue->mutex));
     }
     vnc_unlock_queue(queue);
 }
@@ -195,7 +195,7 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
     vnc_lock_queue(queue);
     while (QTAILQ_EMPTY(&queue->jobs) && !queue->exit) {
-        qemu_cond_wait(&queue->cond, &queue->mutex);
+        qemu_cond_wait(&queue->cond, g_static_mutex_get_mutex(&queue->mutex));
     }
     /* Here job can only be NULL if queue->exit is true */
     job = QTAILQ_FIRST(&queue->jobs);
@@ -275,7 +275,7 @@ static VncJobQueue *vnc_queue_init(void)
     VncJobQueue *queue = qemu_mallocz(sizeof(VncJobQueue));
 
     qemu_cond_init(&queue->cond);
-    qemu_mutex_init(&queue->mutex);
+    g_static_mutex_init(&queue->mutex);
     QTAILQ_INIT(&queue->jobs);
     return queue;
 }
@@ -283,7 +283,7 @@ static VncJobQueue *vnc_queue_init(void)
 static void vnc_queue_clear(VncJobQueue *q)
 {
     qemu_cond_destroy(&queue->cond);
-    qemu_mutex_destroy(&queue->mutex);
+    g_static_mutex_free(&queue->mutex);
     buffer_free(&queue->buffer);
     qemu_free(q);
     queue = NULL; /* Unset global queue */
ui/vnc-jobs.h +5 -5
index b8dab81..f4cc262 100644
@@ -50,7 +50,7 @@ void vnc_stop_worker_thread(void);
 static inline int vnc_trylock_display(VncDisplay *vd)
 {
 #ifdef CONFIG_VNC_THREAD
-    return qemu_mutex_trylock(&vd->mutex);
+    return g_static_mutex_trylock(&vd->mutex);
 #else
     return 0;
 #endif
@@ -59,28 +59,28 @@ static inline int vnc_trylock_display(VncDisplay *vd)
 static inline void vnc_lock_display(VncDisplay *vd)
 {
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_lock(&vd->mutex);
+    g_static_mutex_lock(&vd->mutex);
 #endif
 }
 
 static inline void vnc_unlock_display(VncDisplay *vd)
 {
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_unlock(&vd->mutex);
+    g_static_mutex_unlock(&vd->mutex);
 #endif
 }
 
 static inline void vnc_lock_output(VncState *vs)
 {
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_lock(&vs->output_mutex);
+    g_static_mutex_lock(&vs->output_mutex);
 #endif
 }
 
 static inline void vnc_unlock_output(VncState *vs)
 {
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_unlock(&vs->output_mutex);
+    g_static_mutex_unlock(&vs->output_mutex);
 #endif
 }
 
ui/vnc.c +3 -3
index 495d6d6..4efd684 100644
@@ -1046,7 +1046,7 @@ static void vnc_disconnect_finish(VncState *vs)
     vnc_unlock_output(vs);
 
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_destroy(&vs->output_mutex);
+    g_static_mutex_free(&vs->output_mutex);
 #endif
     qemu_free(vs);
 }
@@ -2386,7 +2386,7 @@ static void vnc_connect(VncDisplay *vd, int csock)
     vs->as.endianness = 0;
 
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_init(&vs->output_mutex);
+    g_static_mutex_init(&vs->output_mutex);
 #endif
 
     QTAILQ_INSERT_HEAD(&vd->clients, vs, next);
@@ -2448,7 +2448,7 @@ void vnc_display_init(DisplayState *ds)
         exit(1);
 
 #ifdef CONFIG_VNC_THREAD
-    qemu_mutex_init(&vs->mutex);
+    g_static_mutex_init(&vs->mutex);
     vnc_start_worker_thread();
 #endif
 
ui/vnc.h +2 -2
index 4f895be..5c6a676 100644
@@ -108,7 +108,7 @@ struct VncDisplay
     kbd_layout_t *kbd_layout;
     int lock_key_sync;
 #ifdef CONFIG_VNC_THREAD
-    QemuMutex mutex;
+    GStaticMutex mutex;
 #endif
 
     QEMUCursor *cursor;
@@ -244,7 +244,7 @@ struct VncState
 #ifndef CONFIG_VNC_THREAD
     VncJob job;
 #else
-    QemuMutex output_mutex;
+    GStaticMutex output_mutex;
 #endif
 
     /* Encoding specific, if you add something here, don't forget to
Signature · 1 line
1.7.0.4
#75 lore raw

[Qemu-devel] Re: [PATCH 4/7] Get rid of QemuMutex and teach its callers about GStaticMutex

Quoted 18 lines · Anthony Liguori
cpus.c +2 -2
index 9cf7e6e..0f8e33b 100644
@@ -321,8 +321,8 @@ void vm_stop(int reason)
 
 #include "qemu-thread.h"
 
-QemuMutex qemu_global_mutex;
-static QemuMutex qemu_fair_mutex;
+GStaticMutex qemu_global_mutex;
+static GStaticMutex qemu_fair_mutex;
 
 static QemuThread io_thread;
 

cpus.c int qemu_init_main_loop(void) · line 422

Quoted 10 lines
cpus.c +3 -3
@@ -416,9 +416,9 @@ int qemu_init_main_loop(void)
     qemu_cond_init(&qemu_system_cond);
     qemu_cond_init(&qemu_pause_cond);
     qemu_cond_init(&qemu_work_cond);
-    qemu_mutex_init(&qemu_fair_mutex);
-    qemu_mutex_init(&qemu_global_mutex);
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_init(&qemu_fair_mutex);
+    g_static_mutex_init(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
 

Just replacing our own abstraction with glib's looks like a step in the wrong direction. From a first glance at that library and its semantics it has at least two major drawbacks:

- Error handling of things like g_mutex_lock or g_cond_wait is, well, very "simplistic". Once we start to use more sophisticated locking, more bugs will occur here, and we will need more support than glib is able to provide (or can you control error handling elsewhere?).

- GMutex is not powerful enough for optional things like PI mutexes - which is required once we want to schedule parts of qemu with RT priorities (I did it, it works surprisingly well).

The same concerns apply to other abstractions glib provides for threading and synchronization. One may work around them, but that will break abstractions again.

Glib seems to fit standard use case quite comfortably but fails in more advanced scenarios qemu is already useable for (just lacking a few additional lines of code).

In short: we need full POSIX where available.

Jan

#76 lore raw

Re: [Qemu-devel] Re: [PATCH 4/7] Get rid of QemuMutex and teach its callers about GStaticMutex

Quoted 35 lines · Jan Kiszka
Quoted 19 lines · Anthony Liguori
cpus.c +2 -2
index 9cf7e6e..0f8e33b 100644
@@ -321,8 +321,8 @@ void vm_stop(int reason)
 
  #include "qemu-thread.h"
 
-QemuMutex qemu_global_mutex;
-static QemuMutex qemu_fair_mutex;
+GStaticMutex qemu_global_mutex;
+static GStaticMutex qemu_fair_mutex;
 
  static QemuThread io_thread;
 
@@ -416,9 +416,9 @@ int qemu_init_main_loop(void)
      qemu_cond_init(&qemu_system_cond);

cpus.c int qemu_init_main_loop(void) · line 423

Quoted 10 lines
cpus.c +3 -3
      qemu_cond_init(&qemu_pause_cond);
      qemu_cond_init(&qemu_work_cond);
-    qemu_mutex_init(&qemu_fair_mutex);
-    qemu_mutex_init(&qemu_global_mutex);
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_init(&qemu_fair_mutex);
+    g_static_mutex_init(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
 
 

Just replacing our own abstraction with glib's looks like a step in the wrong direction. From a first glance at that library and its semantics it has at least two major drawbacks:

Quoted 9 lines

- Error handling of things like g_mutex_lock or g_cond_wait is, well, very "simplistic". Once we start to use more sophisticated locking, more bugs will occur here, and we will need more support than glib is able to provide (or can you control error handling elsewhere?).

- GMutex is not powerful enough for optional things like PI mutexes - which is required once we want to schedule parts of qemu with RT priorities (I did it, it works surprisingly well).

One of the nice design characteristics of glib/gobject/gtk is that it cohabitates well with other APIs.

Nothing stops you from using pthread mutex directly if you really need to. It makes you less portable, but sometimes it's a price that has to be paid for functionality.

Quoted 10 lines

The same concerns apply to other abstractions glib provides for threading and synchronization. One may work around them, but that will break abstractions again.

Glib seems to fit standard use case quite comfortably but fails in more advanced scenarios qemu is already useable for (just lacking a few additional lines of code).

In short: we need full POSIX where available.

If the problem we have is that we have such advanced use of threading and locking in QEMU such that the glib API is not enough and we find ourselves constantly calling into the pthread's API directly, then that's a wonderful problem to have.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#77 lore raw

Re: [Qemu-devel] Re: [PATCH 4/7] Get rid of QemuMutex and teach its callers about GStaticMutex

Quoted 46 lines · Anthony Liguori
Quoted 35 lines · Jan Kiszka
Quoted 19 lines · Anthony Liguori
cpus.c +2 -2
index 9cf7e6e..0f8e33b 100644
@@ -321,8 +321,8 @@ void vm_stop(int reason)
 
  #include "qemu-thread.h"
 
-QemuMutex qemu_global_mutex;
-static QemuMutex qemu_fair_mutex;
+GStaticMutex qemu_global_mutex;
+static GStaticMutex qemu_fair_mutex;
 
  static QemuThread io_thread;
 
@@ -416,9 +416,9 @@ int qemu_init_main_loop(void)
      qemu_cond_init(&qemu_system_cond);

cpus.c int qemu_init_main_loop(void) · line 423

Quoted 10 lines
cpus.c +3 -3
      qemu_cond_init(&qemu_pause_cond);
      qemu_cond_init(&qemu_work_cond);
-    qemu_mutex_init(&qemu_fair_mutex);
-    qemu_mutex_init(&qemu_global_mutex);
-    qemu_mutex_lock(&qemu_global_mutex);
+    g_static_mutex_init(&qemu_fair_mutex);
+    g_static_mutex_init(&qemu_global_mutex);
+    g_static_mutex_lock(&qemu_global_mutex);
 
 

Just replacing our own abstraction with glib's looks like a step in the wrong direction. From a first glance at that library and its semantics it has at least two major drawbacks:

Quoted 9 lines

- Error handling of things like g_mutex_lock or g_cond_wait is, well, very "simplistic". Once we start to use more sophisticated locking, more bugs will occur here, and we will need more support than glib is able to provide (or can you control error handling elsewhere?).

- GMutex is not powerful enough for optional things like PI mutexes - which is required once we want to schedule parts of qemu with RT priorities (I did it, it works surprisingly well).

Quoted 6 lines

One of the nice design characteristics of glib/gobject/gtk is that it cohabitates well with other APIs.

Nothing stops you from using pthread mutex directly if you really need to. It makes you less portable, but sometimes it's a price that has to be paid for functionality.

I'm not talking about adding new PI mutexes, I'm talking about effectively reverting this patch as I need to initializes the existing ones with PI enabled in the attributes. Or replacing g_mutex_* with wrappers again to add real error handling. Really, glib is too primitive here.

Jan

#78 lore raw

PATCH 5/7 threads: get rid of QemuCond and teach callers about GCond

In reply to Anthony Liguori
cpu-defs.h +1 -1
index 8d4bf86..9343824 100644
@@ -204,7 +204,7 @@ typedef struct CPUWatchpoint {
     uint32_t stop;   /* Stop request */                                 \
     uint32_t stopped; /* Artificially stopped */                        \
     struct QemuThread *thread;                                          \
-    struct QemuCond *halt_cond;                                         \
+    struct _GCond *halt_cond;                                           \
     struct qemu_work_item *queued_work_first, *queued_work_last;        \
     const char *cpu_model_str;                                          \
     struct KVMState *kvm_state;                                         \
cpus.c +66 -42

202 lines not on this page · raw message

qemu-thread.c +0 -37
index df17eb4..748da5e 100644
@@ -14,43 +14,6 @@
 #include "qemu-common.h"
 #include "qemu-thread.h"
 
-void qemu_cond_init(QemuCond *cond)
-{
-    cond->cond = g_cond_new();
-}
-
-void qemu_cond_destroy(QemuCond *cond)
-{
-    g_cond_free(cond->cond);
-}
-
-void qemu_cond_signal(QemuCond *cond)
-{
-    g_cond_signal(cond->cond);
-}
-
-void qemu_cond_broadcast(QemuCond *cond)
-{
-    g_cond_broadcast(cond->cond);
-}
-
-void qemu_cond_wait(QemuCond *cond, GMutex *mutex)
-{
-    g_cond_wait(cond->cond, mutex);
-}
-
-int qemu_cond_timedwait(QemuCond *cond, GMutex *mutex, uint64_t msecs)
-{
-    GTimeVal abs_time;
-
-    assert(cond->cond != NULL);
-
-    g_get_current_time(&abs_time);
-    g_time_val_add(&abs_time, msecs * 1000); /* MSEC to USEC */
-
-    return g_cond_timed_wait(cond->cond, mutex, &abs_time);
-}
-
 struct trampoline_data
 {
     QemuThread *thread;
qemu-thread.h +0 -12
index dec6848..2c99c94 100644
@@ -3,25 +3,13 @@
 #include <glib.h>
 #include <pthread.h>
 
-struct QemuCond {
-    GCond *cond;
-};
-
 struct QemuThread {
     GThread *thread;
     pthread_t tid;
 };
 
-typedef struct QemuCond QemuCond;
 typedef struct QemuThread QemuThread;
 
-void qemu_cond_init(QemuCond *cond);
-void qemu_cond_destroy(QemuCond *cond);
-void qemu_cond_signal(QemuCond *cond);
-void qemu_cond_broadcast(QemuCond *cond);
-void qemu_cond_wait(QemuCond *cond, GMutex *mutex);
-int qemu_cond_timedwait(QemuCond *cond, GMutex *mutex, uint64_t msecs);
-
 void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
ui/vnc-jobs-async.c +8 -8
index 48f567e..0c2b1a0 100644
@@ -49,7 +49,7 @@
 */
 
 struct VncJobQueue {
-    QemuCond cond;
+    GCond *cond;
     GStaticMutex mutex;
     QemuThread thread;
     Buffer buffer;
@@ -108,7 +108,7 @@ void vnc_job_push(VncJob *job)
         qemu_free(job);
     } else {
         QTAILQ_INSERT_TAIL(&queue->jobs, job, next);
-        qemu_cond_broadcast(&queue->cond);
+        g_cond_broadcast(queue->cond);
     }
     vnc_unlock_queue(queue);
 }
@@ -152,7 +152,7 @@ void vnc_jobs_join(VncState *vs)
 {
     vnc_lock_queue(queue);
     while (vnc_has_job_locked(vs)) {
-        qemu_cond_wait(&queue->cond, g_static_mutex_get_mutex(&queue->mutex));
+        g_cond_wait(queue->cond, g_static_mutex_get_mutex(&queue->mutex));
     }
     vnc_unlock_queue(queue);
 }
@@ -195,7 +195,7 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
     vnc_lock_queue(queue);
     while (QTAILQ_EMPTY(&queue->jobs) && !queue->exit) {
-        qemu_cond_wait(&queue->cond, g_static_mutex_get_mutex(&queue->mutex));
+        g_cond_wait(queue->cond, g_static_mutex_get_mutex(&queue->mutex));
     }
     /* Here job can only be NULL if queue->exit is true */
     job = QTAILQ_FIRST(&queue->jobs);
@@ -265,7 +265,7 @@ disconnected:
     vnc_lock_queue(queue);
     QTAILQ_REMOVE(&queue->jobs, job, next);
     vnc_unlock_queue(queue);
-    qemu_cond_broadcast(&queue->cond);
+    g_cond_broadcast(queue->cond);
     qemu_free(job);
     return 0;
 }
@@ -274,7 +274,7 @@ static VncJobQueue *vnc_queue_init(void)
 {
     VncJobQueue *queue = qemu_mallocz(sizeof(VncJobQueue));
 
-    qemu_cond_init(&queue->cond);
+    queue->cond = g_cond_new();
     g_static_mutex_init(&queue->mutex);
     QTAILQ_INIT(&queue->jobs);
     return queue;
@@ -282,7 +282,7 @@ static VncJobQueue *vnc_queue_init(void)
 
 static void vnc_queue_clear(VncJobQueue *q)
 {
-    qemu_cond_destroy(&queue->cond);
+    g_cond_free(queue->cond);
     g_static_mutex_free(&queue->mutex);
     buffer_free(&queue->buffer);
     qemu_free(q);
@@ -327,5 +327,5 @@ void vnc_stop_worker_thread(void)
     queue->exit = true;
     vnc_unlock_queue(queue);
     vnc_jobs_clear(NULL);
-    qemu_cond_broadcast(&queue->cond);
+    g_cond_broadcast(queue->cond);
 }
Signature · 1 line
1.7.0.4
#79 lore raw

PATCH 6/7 Teach vnc server to use GThread directly

In reply to Anthony Liguori
qemu-thread.c +25 -0
index 748da5e..6d0c51e 100644
@@ -14,6 +14,31 @@
 #include "qemu-common.h"
 #include "qemu-thread.h"
 
+#ifdef _WIN32
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error)
+{
+    return g_thread_create(func, data, joinable, NULL);
+}
+#else
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error)
+{
+    GThread *tid;
+    sigset_t set, old;
+
+    sigfillset(&set);
+    pthread_sigmask(SIG_SETMASK, &set, &old);
+    tid = g_thread_create(func, data, joinable, error);
+    pthread_sigmask(SIG_SETMASK, &old, NULL);
+    return tid;
+}
+#endif
+
 struct trampoline_data
 {
     QemuThread *thread;
qemu-thread.h +5 -0
index 2c99c94..ec7fabd 100644
@@ -10,6 +10,11 @@ struct QemuThread {
 
 typedef struct QemuThread QemuThread;
 
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error);
+
 void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
ui/vnc-jobs-async.c +4 -4
index 0c2b1a0..2df245d 100644
@@ -51,7 +51,7 @@
 struct VncJobQueue {
     GCond *cond;
     GStaticMutex mutex;
-    QemuThread thread;
+    GThread *thread;
     Buffer buffer;
     bool exit;
     QTAILQ_HEAD(, VncJob) jobs;
@@ -289,11 +289,11 @@ static void vnc_queue_clear(VncJobQueue *q)
     queue = NULL; /* Unset global queue */
 }
 
-static void *vnc_worker_thread(void *arg)
+static gpointer vnc_worker_thread(gpointer arg)
 {
     VncJobQueue *queue = arg;
 
-    qemu_thread_self(&queue->thread);
+    queue->thread = g_thread_self();
 
     while (!vnc_worker_thread_loop(queue)) ;
     vnc_queue_clear(queue);
@@ -308,7 +308,7 @@ void vnc_start_worker_thread(void)
         return ;
 
     q = vnc_queue_init();
-    qemu_thread_create(&q->thread, vnc_worker_thread, q);
+    q->thread = q_thread_create_nosignal(vnc_worker_thread, q, FALSE, NULL);
     queue = q; /* Set global queue */
 }
 
Signature · 1 line
1.7.0.4
#80 lore raw

Re: [Qemu-devel] [PATCH 6/7] Teach vnc server to use GThread directly

qemu-thread.c line 21

Quoted 5 lines · Anthony Liguori
qemu-thread.c +5 -0
+#ifdef _WIN32
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error)

Let's not introduce a new naming convention, qemu_* is the norm.

Stefan

#81 lore raw

PATCH 7/7 Rename QemuThread to QemuSThread to indicate that it is not a generic thread

In reply to Anthony Liguori

This is an abstraction to support signalable threads. Signaling is inheritedly non-portable so this type of thread should only be used when absolutely necessary. I think the current users are the only users that should ever need to exist so strongly discourage future use.

cpu-defs.h +1 -1
index 9343824..ed2a209 100644
@@ -203,7 +203,7 @@ typedef struct CPUWatchpoint {
     uint32_t created;                                                   \
     uint32_t stop;   /* Stop request */                                 \
     uint32_t stopped; /* Artificially stopped */                        \
-    struct QemuThread *thread;                                          \
+    struct QemuSThread *thread;                                          \
     struct _GCond *halt_cond;                                           \
     struct qemu_work_item *queued_work_first, *queued_work_last;        \
     const char *cpu_model_str;                                          \
cpus.c +17 -17
index bc7363f..eebfe11 100644
@@ -324,9 +324,9 @@ void vm_stop(int reason)
 GStaticMutex qemu_global_mutex;
 static GStaticMutex qemu_fair_mutex;
 
-static QemuThread io_thread;
+static QemuSThread io_thread;
 
-static QemuThread *tcg_cpu_thread;
+static QemuSThread *tcg_cpu_thread;
 static GCond *tcg_halt_cond;
 
 static int qemu_system_ready;
@@ -420,7 +420,7 @@ int qemu_init_main_loop(void)
     g_static_mutex_init(&qemu_global_mutex);
     g_static_mutex_lock(&qemu_global_mutex);
 
-    qemu_thread_self(&io_thread);
+    qemu_sthread_self(&io_thread);
 
     return 0;
 }
@@ -609,7 +609,7 @@ static void *kvm_cpu_thread_fn(void *arg)
     CPUState *env = arg;
 
     g_static_mutex_lock(&qemu_global_mutex);
-    qemu_thread_self(env->thread);
+    qemu_sthread_self(env->thread);
     if (kvm_enabled())
         kvm_init_vcpu(env);
 
@@ -642,7 +642,7 @@ static void *tcg_cpu_thread_fn(void *arg)
     CPUState *env = arg;
 
     tcg_init_ipi();
-    qemu_thread_self(env->thread);
+    qemu_sthread_self(env->thread);
 
     /* signal CPU creation */
     g_static_mutex_lock(&qemu_global_mutex);
@@ -671,17 +671,17 @@ void qemu_cpu_kick(void *_env)
 {
     CPUState *env = _env;
     g_cond_broadcast(env->halt_cond);
-    qemu_thread_signal(env->thread, SIG_IPI);
+    qemu_sthread_signal(env->thread, SIG_IPI);
 }
 
 int qemu_cpu_self(void *_env)
 {
     CPUState *env = _env;
-    QemuThread this;
+    QemuSThread this;
 
-    qemu_thread_self(&this);
+    qemu_sthread_self(&this);
 
-    return qemu_thread_equal(&this, env->thread);
+    return qemu_sthread_equal(&this, env->thread);
 }
 
 static void cpu_signal(int sig)
@@ -764,7 +764,7 @@ void qemu_mutex_lock_iothread(void)
     } else {
         g_static_mutex_lock(&qemu_fair_mutex);
         if (g_static_mutex_trylock(&qemu_global_mutex)) {
-            qemu_thread_signal(tcg_cpu_thread, SIG_IPI);
+            qemu_sthread_signal(tcg_cpu_thread, SIG_IPI);
             g_static_mutex_lock(&qemu_global_mutex);
         }
         g_static_mutex_unlock(&qemu_fair_mutex);
@@ -830,9 +830,9 @@ static void tcg_init_vcpu(void *_env)
     CPUState *env = _env;
     /* share a single thread for all cpus with TCG */
     if (!tcg_cpu_thread) {
-        env->thread = qemu_mallocz(sizeof(QemuThread));
+        env->thread = qemu_mallocz(sizeof(QemuSThread));
         env->halt_cond = g_cond_new();
-        qemu_thread_create(env->thread, tcg_cpu_thread_fn, env);
+        qemu_sthread_create(env->thread, tcg_cpu_thread_fn, env);
         while (env->created == 0) {
             GTimeVal t;
             g_get_current_time(&t);
@@ -850,9 +850,9 @@ static void tcg_init_vcpu(void *_env)
 
 static void kvm_start_vcpu(CPUState *env)
 {
-    env->thread = qemu_mallocz(sizeof(QemuThread));
+    env->thread = qemu_mallocz(sizeof(QemuSThread));
     env->halt_cond = g_cond_new();
-    qemu_thread_create(env->thread, kvm_cpu_thread_fn, env);
+    qemu_sthread_create(env->thread, kvm_cpu_thread_fn, env);
     while (env->created == 0) {
         GTimeVal t;
         g_get_current_time(&t);
@@ -887,10 +887,10 @@ static void qemu_system_vmstop_request(int reason)
 
 void vm_stop(int reason)
 {
-    QemuThread me;
-    qemu_thread_self(&me);
+    QemuSThread me;
+    qemu_sthread_self(&me);
 
-    if (!qemu_thread_equal(&me, &io_thread)) {
+    if (!qemu_sthread_equal(&me, &io_thread)) {
         qemu_system_vmstop_request(reason);
         /*
          * FIXME: should not return to device code in case
qemu-thread.c +6 -6
index 6d0c51e..7ba4950 100644
@@ -41,7 +41,7 @@ GThread *q_thread_create_nosignal(GThreadFunc func,
 
 struct trampoline_data
 {
-    QemuThread *thread;
+    QemuSThread *thread;
     void *(*startfn)(void *);
     void *opaque;
     GStaticMutex lock;
@@ -61,7 +61,7 @@ static gpointer thread_trampoline(gpointer data)
     return retval;
 }
 
-void qemu_thread_create(QemuThread *thread,
+void qemu_sthread_create(QemuSThread *thread,
                         void *(*start_routine)(void*),
                         void *arg)
 {
@@ -91,23 +91,23 @@ void qemu_thread_create(QemuThread *thread,
     g_static_mutex_free(&td->lock);
 }
 
-void qemu_thread_signal(QemuThread *thread, int sig)
+void qemu_sthread_signal(QemuSThread *thread, int sig)
 {
     pthread_kill(thread->tid, sig);
 }
 
-void qemu_thread_self(QemuThread *thread)
+void qemu_sthread_self(QemuSThread *thread)
 {
     thread->thread = g_thread_self();
     thread->tid = pthread_self();
 }
 
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
+int qemu_sthread_equal(QemuSThread *thread1, QemuSThread *thread2)
 {
     return (thread1->thread == thread2->thread);
 }
 
-void qemu_thread_exit(void *retval)
+void qemu_sthread_exit(void *retval)
 {
     g_thread_exit(retval);
 }
qemu-thread.h +28 -14

52 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#82 lore raw
In reply to Anthony Liguori
Quoted 5 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

Quoted 7 lines

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- IO library
- rich data structure support

These are where GLib shines.

Quoted 1 line

- INI parser

Not compatible with our config files anyway.

Quoted 1 line

- JSON parser

I think our JSON parser is much better than JsonGlib (which isn't anyway a part of GLib proper).

Quoted 4 lines

- generic type system
- object oriented infrastructure
- module system
- introspection to enable support for dynamic language bindings

See below.

Quoted 3 lines

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I am not sure how these other bits will look like and maybe it won't make sense at all, but it doesn't matter. The bits you posted are already a step in the right direction IMHO, and the same goes for converting the I/O loop to GMainLoop if you can pull that :) and using glib's thread pool.

(Regarding GMainLoop, my main worry is that we'd have to reinvent a lot of GSources to integrate properly with slirp, with QEMU's multiple clocks, and so on. And GSources are black magic...).

I'd also add to the benefits a good multi-threaded memory allocator.

A small qualm I have is that glib (and GNOME in general) is one of the hardest pieces of free software to contribute to in my experience. I have patches which had multiple acks and are still languishing after a year or so. Still not an excuse for NIH.

Paolo

#83 lore raw
Quoted 16 lines · Paolo Bonzini
Quoted 5 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

Quoted 7 lines

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- IO library
- rich data structure support

These are where GLib shines.

Quoted 7 lines
Quoted 1 line

- INI parser

Not compatible with our config files anyway.

Quoted 1 line

- JSON parser

I think our JSON parser is much better than JsonGlib (which isn't anyway a part of GLib proper).

Not sure how much either of these matter, but we should at least drop QObject and convert our JSON parser to use GValues such that we can treat the JSON parser as a stand alone component.

Quoted 7 lines
Quoted 4 lines

- generic type system
- object oriented infrastructure
- module system
- introspection to enable support for dynamic language bindings

See below.

Quoted 7 lines
Quoted 3 lines

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I am not sure how these other bits will look like and maybe it won't make sense at all, but it doesn't matter. The bits you posted are already a step in the right direction IMHO, and the same goes for converting the I/O loop to GMainLoop if you can pull that :) and using glib's thread pool.

(Regarding GMainLoop, my main worry is that we'd have to reinvent a lot of GSources to integrate properly with slirp, with QEMU's multiple clocks, and so on. And GSources are black magic...).

I've been thinking about this myself. I think slirp is probably best handled as a GSource as much as I don't want to do it. I don't see another option.

We can't use the g_timeout_source directly because the interval is milliseconds. Since our clock mechanisms all use signals to generate clock events, I think we can tie it all to a pipe() and just use a GIOChannel to generate events. Obviously, implementing a GSource is the best long term approach but I think there's a reasonable short term one.

Regards,

Anthony Liguori

Quoted 6 lines

I'd also add to the benefits a good multi-threaded memory allocator.

A small qualm I have is that glib (and GNOME in general) is one of the hardest pieces of free software to contribute to in my experience. I have patches which had multiple acks and are still languishing after a year or so. Still not an excuse for NIH.

Paolo

#84 lore raw
Quoted 8 lines · Anthony Liguori
Quoted 4 lines
Quoted 1 line

- JSON parser

I think our JSON parser is much better than JsonGlib (which isn't anyway a part of GLib proper).

Not sure how much either of these matter, but we should at least drop QObject and convert our JSON parser to use GValues such that we can treat the JSON parser as a stand alone component.

Not too nice actually, as GHashTable and GArrays are not GValues.

Quoted 3 lines

I've been thinking about this myself. I think slirp is probably best handled as a GSource as much as I don't want to do it. I don't see another option.

Yes. Track the previous bitmap of fd's and add/remove pollfd's when they appear into (resp. disappear from) the bitmap.

Note that the glib main loop can be quadratic in the number of file descriptors BTW.

Quoted 2 lines

We can't use the g_timeout_source directly because the interval is milliseconds.

Our deadlines are rounded to milliseconds anyway. However, with an iothread you really do not need signals anymore. The dynticks code maps pretty well to a GSource.

Quoted 2 lines

Obviously, implementing a GSource is the
best long term approach but I think there's a reasonable short term one.

Or yet another unfinished transition.

Paolo "let's do it in Vala then"

#85 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Anthony Liguori
Quoted 4 lines
Quoted 1 line

- JSON parser

I think our JSON parser is much better than JsonGlib (which isn't anyway a part of GLib proper).

Not sure how much either of these matter, but we should at least drop QObject and convert our JSON parser to use GValues such that we can treat the JSON parser as a stand alone component.

Not too nice actually, as GHashTable and GArrays are not GValues.

It might be worth considering (the fairly newly introduced) GVariant, rather than GValue. The GVariant code was designed and is used for (de)serializing DBus messages in GLib. As such I'd imagine it would be fairly well suited to handling serialization of other RPC messages like our own JSON.

Regards,
Daniel

#86 lore raw
Quoted 5 lines · Daniel P. Berrange

It might be worth considering (the fairly newly introduced) GVariant, rather than GValue. The GVariant code was designed and is used for (de)serializing DBus messages in GLib. As such I'd imagine it would be fairly well suited to handling serialization of other RPC messages like our own JSON.

Good hint, thanks.

Paolo

#87 lore raw
In reply to Anthony Liguori
Quoted 32 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

On the other hand, while GObjects are uglier and require a lot of template code, there's more than enough structure that I think it can guide us into a much better object model implementation.

Quoted 8 lines

There is some ugliness. GLib does not abstract signals because they're very
non-portable but QEMU makes extensive use of signaling. I don't think it's a major issue but some of the ugliness in this series is due to that fact.

This series is only lightly tested but also mostly mechanical. I'm pretty confused by the way tcg_halt_cond and friends works so I'm fairly sure I broke that (for non-threaded TCG).

Just to share where this is going, attached patch removes the posix-aio thread pool and replaces it with a GThreadPool.

Need to do a lot of functional and performance testing before making a change like this so I'll keep this in a separate series, but thought it might be interesting.

Regards,

Anthony Liguori

Quoted 1 line

From 5fdc51b2aac307c0219e1489b80bc18e9a3db0d1 Mon Sep 17 00:00:00 2001

From: Anthony Liguori <[email protected]>
Date: Mon, 24 Jan 2011 18:19:08 -0600
Subject: [PATCH 8/7] posix-aio: convert to glib based thread pool

This removes the custom pthread based thread pool in favor of a GThreadPool. I believe this patch implements all of the necessary functionality but it needs quite a lot more testing and performance analysis.

One thing I'm sure will break--we used to deliver a signal on every I/O completion. This just slows down the I/O path. The reason we did this was because at the time, I believe Cris depended on that signal to break out of QEMU because it did I/O without a periodic timer installed.

At this point in time, I think any architecture that requires signals needs to do so with a periodic timer or some other mechanism.

configure +1 -0
index 820fde9..1af6b44 100755
@@ -1663,6 +1663,7 @@ if $pkg_config --modversion gthread-2.0 > /dev/null 2>&1 ; then
     glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
     glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
     libs_softmmu="$glib_libs $libs_softmmu"
+    libs_tools="$glib_libs $libs_tools"
 else
     echo "glib-2.0 required to compile QEMU"
     exit 1
posix-aio-compat.c +166 -359

661 lines not on this page · raw message

qemu-tool.c +8 -0
index 392e1c9..ca9c711 100644
@@ -111,3 +111,11 @@ int qemu_set_fd_handler2(int fd,
 {
     return 0;
 }
+
+int qemu_set_fd_handler(int fd,
+                        IOHandler *fd_read,
+                        IOHandler *fd_write,
+                        void *opaque)
+{
+    return 0;
+}
Signature · 1 line
1.7.0.4
#88 lore raw
Quoted 59 lines · Anthony Liguori
Quoted 32 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

On the other hand, while GObjects are uglier and require a lot of template code, there's more than enough structure that I think it can guide us into a much better object model implementation.

Quoted 8 lines

There is some ugliness. GLib does not abstract signals because they're very
non-portable but QEMU makes extensive use of signaling. I don't think it's a major issue but some of the ugliness in this series is due to that fact.

This series is only lightly tested but also mostly mechanical. I'm pretty confused by the way tcg_halt_cond and friends works so I'm fairly sure I broke that (for non-threaded TCG).

Just to share where this is going, attached patch removes the posix-aio thread pool and replaces it with a GThreadPool.

Need to do a lot of functional and performance testing before making a change like this so I'll keep this in a separate series, but thought it might be interesting.

Regards,

Anthony Liguori

From 5fdc51b2aac307c0219e1489b80bc18e9a3db0d1 Mon Sep 17 00:00:00 2001
From: Anthony Liguori <[email protected]>
Date: Mon, 24 Jan 2011 18:19:08 -0600
Subject: [PATCH 8/7] posix-aio: convert to glib based thread pool

Quoted 8 lines

This removes the custom pthread based thread pool in favor of a GThreadPool. I believe this patch implements all of the necessary functionality but it needs quite a lot more testing and performance analysis.

One thing I'm sure will break--we used to deliver a signal on every I/O completion. This just slows down the I/O path. The reason we did this was because at the time, I believe Cris depended on that signal to break out of QEMU because it did I/O without a periodic timer installed.

Hi Anthony,

I have no memory of any such issues. Anyway, if you've got a tree a can clone, I'll be happy to give it a go and let you know if CRIS works ok. There's also a bootable CRIS linux guest image on the wiki's download page if you wan't to try yourself.

Cheers

#89 lore raw
In reply to Anthony Liguori
Quoted 14 lines · Anthony Liguori

This series introduces a hard dependency on glib.  The initial use is portable threads but I see this as just the beginning.  Glib/Gobject offer many nice things including:

 - portable threads
 - rich data structure support
 - INI parser
 - JSON parser
 - generic type system
 - object oriented infrastructure
 - IO library
 - module system
 - introspection to enable support for dynamic language bindings

Quoted 8 lines

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance.  Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I've spent the past few months working on C++ integration for QEMU.  I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

I like this direction much more than rewriting everything in C++. We can replace some of the homebrew stuff with widely used glib implementations. We get new functionality like hash tables and balanced trees for free.

Even just moving to a solid event loop and I/O handlers is a win.

Stefan

#90 lore raw
In reply to Anthony Liguori
Quoted 4 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

Somehow this idea crossed my mind as well while thinking about the io handler issue. Why limit yourself to steal ideas from glib if we can just use the library instead?

Quoted 4 lines

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

Quoted 9 lines

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

Even if we only offload some portability issues to glib and use the gmainloop we'll have a net win I suspect. Using gmainloop will make it alot easier to integrate third party libs which quite often offer glib integration. We could easily use avahi to announce our vnc server via mdns/zeroconf/bonjour for example. Also I'd be tempted to just rewrite pulseaudio support using the glib support in pulse.

Turn all qemu internals into gobjects is certainly non-trivial, especially managing the transition phase. But nevertheless it probably is worth the effort long-term as glib has all sorts of language bindings.

<dream>
So we could do all the high-level stuff such as config parsing in a high-level language some day. </dream>

Quoted 4 lines

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

Agree. I doubt switching to C++ will fly. But using glib has pretty good chances to be a big success long-term.

I think we should get 0.14 out of the door before starting to work on that though ;)

cheers,
Gerd

#91 lore raw
Quoted 31 lines · Gerd Hoffmann
Quoted 4 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

Somehow this idea crossed my mind as well while thinking about the io handler issue. Why limit yourself to steal ideas from glib if we can just use the library instead?

Quoted 4 lines

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

Quoted 9 lines

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

Even if we only offload some portability issues to glib and use the gmainloop we'll have a net win I suspect. Using gmainloop will make it alot easier to integrate third party libs which quite often offer glib integration. We could easily use avahi to announce our vnc server via mdns/zeroconf/bonjour for example. Also I'd be tempted to just rewrite pulseaudio support using the glib support in pulse.

Quoted 4 lines

Turn all qemu internals into gobjects is certainly non-trivial, especially managing the transition phase. But nevertheless it probably is worth the effort long-term as glib has all sorts of language bindings.

If your internals are all properly designed & encapsulated GObjects and you enable GObject Introspection, you'll get direct access from non-C languages more or less for free these days. You won't have to actually write language bindings for any of your objects - worst case there is a completely automatic code generator, but for most dynamic languages not even that is required anymore in GObject.

Of course getting QEMU internals to be properly encapsulated objects is a non-trivial task, but it can continue to be done incrementally of course, and using a more structured object system would help to enforce rigourous design practice in this respect.

Quoted 4 lines

<dream>
So we could do all the high-level stuff such as config parsing in a high-level language some day.
</dream>

Or if really crazy, you could write new devices in Javascript :-) Could be useful for rapid prototyping of new ideas at least.

Regards,
Daniel

#92 lore raw
In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann
Quoted 4 lines

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

Agree. I doubt switching to C++ will fly. But using glib has pretty good chances to be a big success long-term.

Why is everyone so pessimistic on switching to C++?

Anthony: considering that you have direct experience on trying to do this, why are you convinced it is not going to work?

I am asking because I have always found the glib GObject stuff a little ugly compared to well written C++ code (of course you can write ugly code in any language if you want to).

#93 lore raw
Quoted 7 lines · Stefano Stabellini
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

Quoted 9 lines
Quoted 4 lines

Agree. I doubt switching to C++ will fly. But using glib has pretty good chances to be a big success long-term.

Why is everyone so pessimistic on switching to C++?

Anthony: considering that you have direct experience on trying to do this, why are you convinced it is not going to work?

I'm not ruling out C++ altogether but at this stage, I can't see an incremental transition to C++ working all that well.

I tried to isolate the device models and have a well defined interface between the C and C++ code but the trouble is that if you want the C++ side of things to be Good C++ code, you end up having to replace large chunks of QEMU code.

It's possible that I just took the wrong approach.

My end goal is not C++, it's to improve the device model. I haven't tried doing it with GObject yet but before we even get there, there's a lot of good we can do with glib.

Regards,

Anthony Liguori

Quoted 4 lines

I am asking because I have always found the glib GObject stuff a little ugly compared to well written C++ code (of course you can write ugly code in any language if you want to).

#94 lore raw
Quoted 3 lines · Anthony Liguori

My end goal is not C++, it's to improve the device model. I haven't tried doing it with GObject yet but before we even get there, there's a lot of good we can do with glib.

I certainly agree with this.

#95 lore raw
In reply to Anthony Liguori
Quoted 32 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

On the other hand, while GObjects are uglier and require a lot of template code, there's more than enough structure that I think it can guide us into a much better object model implementation.

Quoted 7 lines

There is some ugliness. GLib does not abstract signals because they're very
non-portable but QEMU makes extensive use of signaling. I don't think it's a major issue but some of the ugliness in this series is due to that fact.

This series is only lightly tested but also mostly mechanical. I'm pretty confused by the way tcg_halt_cond and friends works so I'm fairly sure I broke that (for non-threaded TCG).

This patch series indeed doesn't work at all on TCG. The CPU emulation never starts and the processed is only killable with -9. Surprisingly it works with io_thread disabled, while without this patch series, QEMU both work with and without io_thread (maybe with some overhead, but at least it works).

That's a pitty given the main loop is critical for TCG, and I am really fearing regressions or slowdown that we should detect before going to far in this direction.

Note that contrary to KVM, it's easy to test TCG as you don't need any extension on your CPU. The same images can be used.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#96 lore raw
Quoted 48 lines · Aurelien Jarno
Quoted 32 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

On the other hand, while GObjects are uglier and require a lot of template code, there's more than enough structure that I think it can guide us into a much better object model implementation.

Quoted 8 lines

There is some ugliness. GLib does not abstract signals because they're very
non-portable but QEMU makes extensive use of signaling. I don't think it's a major issue but some of the ugliness in this series is due to that fact.

This series is only lightly tested but also mostly mechanical. I'm pretty confused by the way tcg_halt_cond and friends works so I'm fairly sure I broke that (for non-threaded TCG).

This patch series indeed doesn't work at all on TCG. The CPU emulation never starts and the processed is only killable with -9. Surprisingly it works with io_thread disabled, while without this patch series, QEMU both work with and without io_thread (maybe with some overhead, but at least it works).

Quoted 7 lines

That's a pitty given the main loop is critical for TCG, and I am really fearing regressions or slowdown that we should detect before going to far in this direction.

Note that contrary to KVM, it's easy to test TCG as you don't need any extension on your CPU. The same images can be used.

Yeah, it's fixable and I will fix it. I'm still trying to understand the I/O thread interactions with TCG.

Regards,

Anthony Liguori

A message that is not in the archive (sent off-list or not yet received): [email protected]

#98 lore raw
Quoted 25 lines · Daniel Veillard
Quoted 19 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're digging ourselves deeper into the NIH hole. I think it's time we look at something radical to let us borrow more code from existing projects instead of reinventing everything through trial and error.

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

Quoted 4 lines

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

Quoted 7 lines

Hum, one of the reason I tried to avoid glib dependancies on my own
libraries code is the behaviour on memory allocation error, unless that changed (unlikely) or my recollection is wrong (more likely) glib does a direct exit() on memory allocation errors. This might be fine for QEmu as a standalone program but may turn a disaster if standalone libraries are made out of it and expected for reuse say by libvirt(d).

We have independently done the same thing in QEMU and as such would face the same "problem" either way.

Quite a debate could be had on the merits of this. For QEMU, we made this decision for practical purposes. We did not handle malloc failures consistently so adopting a consistent behavior eliminated the possibility of NULL pointer dereferences which are exploitable.

Regards,

Anthony Liguori

Quoted 8 lines

I just want to raise that point as it's a rather fundamental decision
of the glib/Gnome stack, which was a fine decision to take in the context of writing GUI framework, but is really a poor one for implementing low level or server infrastructure,

Daniel

#99 lore raw
Quoted 43 lines · Anthony Liguori
Quoted 34 lines · Daniel Veillard
Quoted 24 lines · Anthony Liguori

Both the recent I/O loop and threadlet series have me concerned that we're
digging ourselves deeper into the NIH hole.  I think it's time we look at something radical to let us borrow more code from existing projects instead of
reinventing everything through trial and error.

This series introduces a hard dependency on glib.  The initial use is portable
threads but I see this as just the beginning.  Glib/Gobject offer many nice
things including:

 - portable threads
 - rich data structure support
 - INI parser
 - JSON parser
 - generic type system
 - object oriented infrastructure
 - IO library
 - module system
 - introspection to enable support for dynamic language bindings

Quoted 6 lines

I see this series as the first step, followed by converting the I/O loop to
a GMainLoop instance.  Once we're there, we can start making deeper use of
GObjects including converting QDev to a GObject hierarchy.

Quoted 7 lines

  Hum, one of the reason I tried to avoid glib dependancies on my own libraries code is the behaviour on memory allocation error, unless that changed (unlikely) or my recollection is wrong (more likely) glib does a direct exit() on memory allocation errors. This might be fine for QEmu as a standalone program but may turn a disaster if standalone libraries are made out of it and expected for reuse say by libvirt(d).

Quoted 7 lines

We have independently done the same thing in QEMU and as such would face the same "problem" either way.

Quite a debate could be had on the merits of this.  For QEMU, we made this decision for practical purposes.  We did not handle malloc failures consistently so adopting a consistent behavior eliminated the possibility of NULL pointer dereferences which are exploitable.

Both g_malloc() and g_try_malloc() are available where g_try_malloc() returns NULL on failure. g_malloc() matches qemu_malloc() exit behavior today but in the future it would be possible to use g_try_malloc() for proper out-of-memory handling.

But I think you're pointing out that glib uses g_malloc() internally. That is a design flaw and basically makes g_try_malloc() useless.

Stefan

#100 lore raw
Quoted 9 lines · Stefan Hajnoczi

Both g_malloc() and g_try_malloc() are available where g_try_malloc() returns NULL on failure. g_malloc() matches qemu_malloc() exit behavior today but in the future it would be possible to use g_try_malloc() for proper out-of-memory handling.

But I think you're pointing out that glib uses g_malloc() internally. That is a design flaw and basically makes g_try_malloc() useless.

No. glib cannot be used for applications that want to handle malloc() robustly.

But I've never met an application that does so it doesn't really bother me.

Regards,

Anthony LIguori

Quoted 2 lines

Stefan

#101 lore raw
In reply to Anthony Liguori

Hi,

just a few thoughts from a qemu novice...

Quoted 14 lines · Anthony Liguori

This series introduces a hard dependency on glib. The initial use is portable threads but I see this as just the beginning. Glib/Gobject offer many nice things including:

- portable threads
- rich data structure support
- INI parser
- JSON parser
- generic type system
- object oriented infrastructure
- IO library
- module system
- introspection to enable support for dynamic language bindings

Quoted 3 lines

I see this series as the first step, followed by converting the I/O loop to a GMainLoop instance. Once we're there, we can start making deeper use of GObjects including converting QDev to a GObject hierarchy.

My personal experience with the GMainLoop is that it adds a lot of processing overhead compared to hand-written code. However, this is from a few years back and was on an embedded system, and I don't have numbers to back up my claim... Looking at the GMainLoop code I'd say it's not written for high performance, but on the plus side it handles cases like recursive invocation and adding/removing event sources to another thread's GMainLoop.

Anyway, in case you expect high performance you might want to benchmark it against something like libevent.

Quoted 5 lines

I've spent the past few months working on C++ integration for QEMU. I'm more convinced than ever that we desperately in need of structured object oriented mechanisms to be successful but am pretty strongly convinced that incremental additional of C++ is not going to be successful.

Quoted 7 lines

On the other hand, while GObjects are uglier and require a lot of template code, there's more than enough structure that I think it can guide us into a much better object model implementation.

There is some ugliness. GLib does not abstract signals because they're very
non-portable but QEMU makes extensive use of signaling. I don't think it's a major issue but some of the ugliness in this series is due to that fact.

I found working with GObjects by writing C code manually extremely error prone and boring. However, I hear Vala
is the new way if you're determined to use GObject:
http://live.gnome.org/Vala
(Note that I haven't used Vala myself, and this is not a recommendation for Vala; what I want to say is: if Vala doesn't work for you you'll have a lot of fun with GObject.)

Regarding dynamic language bindings: One side effect of that is that all arguments and return values from g_signal_emit() signal handlers are marshaled via an elaborate scheme just in case there might be a script language binding in the mix. Again, this is clearly not written for high performance. I'm not sure this is relevant for qemu, but you might want to take a look at Glib sources and do some benchmarks before using to avoid unpleasant surprises.

Johannes