All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex
@ 2018-02-14  8:49 Zihan Yang
  2018-02-14 10:13 ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Zihan Yang @ 2018-02-14  8:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Zihan Yang, Paolo Bonzini, Peter Crosthwaite, Richard Henderson

change the mutex member in RAMList structure from QemuMutex to CompatGMutex.
qemu_mutex_init() is just deleted instead of being replaced with g_mutex_init()
because there is no need to do initialize a mutex that is statically allocated.

Signed-off-by: Zihan Yang <whois.zihan.yang@gmail.com>
---
 exec.c                 | 5 ++---
 include/exec/ramlist.h | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/exec.c b/exec.c
index e8d7b33..90cdd05 100644
--- a/exec.c
+++ b/exec.c
@@ -1423,12 +1423,12 @@ void qemu_flush_coalesced_mmio_buffer(void)
 
 void qemu_mutex_lock_ramlist(void)
 {
-    qemu_mutex_lock(&ram_list.mutex);
+    g_mutex_lock(&ram_list.mutex);
 }
 
 void qemu_mutex_unlock_ramlist(void)
 {
-    qemu_mutex_unlock(&ram_list.mutex);
+    g_mutex_unlock(&ram_list.mutex);
 }
 
 void ram_block_dump(Monitor *mon)
@@ -3331,7 +3331,6 @@ void cpu_register_map_client(QEMUBH *bh)
 
 void cpu_exec_init_all(void)
 {
-    qemu_mutex_init(&ram_list.mutex);
     /* The data structures we set up here depend on knowing the page size,
      * so no more changes can be made after this point.
      * In an ideal world, nothing we did before we had finished the
diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h
index 2e2ac6c..24be5e4 100644
--- a/include/exec/ramlist.h
+++ b/include/exec/ramlist.h
@@ -45,7 +45,7 @@ typedef struct {
 } DirtyMemoryBlocks;
 
 typedef struct RAMList {
-    QemuMutex mutex;
+    CompatGMutex mutex;
     RAMBlock *mru_block;
     /* RCU-enabled, writes protected by the ramlist lock. */
     QLIST_HEAD(, RAMBlock) blocks;
-- 
2.7.4

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

* Re: [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex
  2018-02-14  8:49 [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex Zihan Yang
@ 2018-02-14 10:13 ` Paolo Bonzini
  2018-02-14 11:43   ` Zihan Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2018-02-14 10:13 UTC (permalink / raw)
  To: Zihan Yang, qemu-devel; +Cc: Peter Crosthwaite, Richard Henderson

On 14/02/2018 09:49, Zihan Yang wrote:
> change the mutex member in RAMList structure from QemuMutex to CompatGMutex.
> qemu_mutex_init() is just deleted instead of being replaced with g_mutex_init()
> because there is no need to do initialize a mutex that is statically allocated.
> 
> Signed-off-by: Zihan Yang <whois.zihan.yang@gmail.com>

I'm not sure what is the advantage of this change.  QEMU is more or less
uniformly using QemuMutex and QemuCond.

Paolo

> ---
>  exec.c                 | 5 ++---
>  include/exec/ramlist.h | 2 +-
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index e8d7b33..90cdd05 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1423,12 +1423,12 @@ void qemu_flush_coalesced_mmio_buffer(void)
>  
>  void qemu_mutex_lock_ramlist(void)
>  {
> -    qemu_mutex_lock(&ram_list.mutex);
> +    g_mutex_lock(&ram_list.mutex);
>  }
>  
>  void qemu_mutex_unlock_ramlist(void)
>  {
> -    qemu_mutex_unlock(&ram_list.mutex);
> +    g_mutex_unlock(&ram_list.mutex);
>  }
>  
>  void ram_block_dump(Monitor *mon)
> @@ -3331,7 +3331,6 @@ void cpu_register_map_client(QEMUBH *bh)
>  
>  void cpu_exec_init_all(void)
>  {
> -    qemu_mutex_init(&ram_list.mutex);
>      /* The data structures we set up here depend on knowing the page size,
>       * so no more changes can be made after this point.
>       * In an ideal world, nothing we did before we had finished the
> diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h
> index 2e2ac6c..24be5e4 100644
> --- a/include/exec/ramlist.h
> +++ b/include/exec/ramlist.h
> @@ -45,7 +45,7 @@ typedef struct {
>  } DirtyMemoryBlocks;
>  
>  typedef struct RAMList {
> -    QemuMutex mutex;
> +    CompatGMutex mutex;
>      RAMBlock *mru_block;
>      /* RCU-enabled, writes protected by the ramlist lock. */
>      QLIST_HEAD(, RAMBlock) blocks;
> 

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

* Re: [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex
  2018-02-14 10:13 ` Paolo Bonzini
@ 2018-02-14 11:43   ` Zihan Yang
  2018-02-14 12:11     ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Zihan Yang @ 2018-02-14 11:43 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

> I'm not sure what is the advantage of this change.  QEMU is more or less
> uniformly using QemuMutex and QemuCond.

I see. QEMU uses some glib functions, like g_new, g_free, g_hash_table ,
g_assert and g_poll, so I thought there was a trend for making more use of
glib.
I get the point now.


2018-02-14 18:13 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:

> On 14/02/2018 09:49, Zihan Yang wrote:
> > change the mutex member in RAMList structure from QemuMutex to
> CompatGMutex.
> > qemu_mutex_init() is just deleted instead of being replaced with
> g_mutex_init()
> > because there is no need to do initialize a mutex that is statically
> allocated.
> >
> > Signed-off-by: Zihan Yang <whois.zihan.yang@gmail.com>
>
> I'm not sure what is the advantage of this change.  QEMU is more or less
> uniformly using QemuMutex and QemuCond.
>
> Paolo
>
> > ---
> >  exec.c                 | 5 ++---
> >  include/exec/ramlist.h | 2 +-
> >  2 files changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/exec.c b/exec.c
> > index e8d7b33..90cdd05 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -1423,12 +1423,12 @@ void qemu_flush_coalesced_mmio_buffer(void)
> >
> >  void qemu_mutex_lock_ramlist(void)
> >  {
> > -    qemu_mutex_lock(&ram_list.mutex);
> > +    g_mutex_lock(&ram_list.mutex);
> >  }
> >
> >  void qemu_mutex_unlock_ramlist(void)
> >  {
> > -    qemu_mutex_unlock(&ram_list.mutex);
> > +    g_mutex_unlock(&ram_list.mutex);
> >  }
> >
> >  void ram_block_dump(Monitor *mon)
> > @@ -3331,7 +3331,6 @@ void cpu_register_map_client(QEMUBH *bh)
> >
> >  void cpu_exec_init_all(void)
> >  {
> > -    qemu_mutex_init(&ram_list.mutex);
> >      /* The data structures we set up here depend on knowing the page
> size,
> >       * so no more changes can be made after this point.
> >       * In an ideal world, nothing we did before we had finished the
> > diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h
> > index 2e2ac6c..24be5e4 100644
> > --- a/include/exec/ramlist.h
> > +++ b/include/exec/ramlist.h
> > @@ -45,7 +45,7 @@ typedef struct {
> >  } DirtyMemoryBlocks;
> >
> >  typedef struct RAMList {
> > -    QemuMutex mutex;
> > +    CompatGMutex mutex;
> >      RAMBlock *mru_block;
> >      /* RCU-enabled, writes protected by the ramlist lock. */
> >      QLIST_HEAD(, RAMBlock) blocks;
> >
>
>

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

* Re: [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex
  2018-02-14 11:43   ` Zihan Yang
@ 2018-02-14 12:11     ` Paolo Bonzini
  2018-02-16  9:13       ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2018-02-14 12:11 UTC (permalink / raw)
  To: Zihan Yang; +Cc: qemu-devel

On 14/02/2018 12:43, Zihan Yang wrote:
> 
>> I'm not sure what is the advantage of this change.  QEMU is more or less
>> uniformly using QemuMutex and QemuCond.
> 
> I see. QEMU uses some glib functions, like g_new, g_free, g_hash_table ,
> g_assert and g_poll, so I thought there was a trend for making more use
> of glib.
> I get the point now.

There are some plans about using priority inheritance mutexes for
QemuMutex.  GLib does not support anymore pluggable thread functions, so
we are stuck with our own implementation.

Paolo

> 2018-02-14 18:13 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com
> <mailto:pbonzini@redhat.com>>:
> 
>     On 14/02/2018 09:49, Zihan Yang wrote:
>     > change the mutex member in RAMList structure from QemuMutex to CompatGMutex.
>     > qemu_mutex_init() is just deleted instead of being replaced with g_mutex_init()
>     > because there is no need to do initialize a mutex that is statically allocated.
>     >
>     > Signed-off-by: Zihan Yang <whois.zihan.yang@gmail.com <mailto:whois.zihan.yang@gmail.com>>
> 
>     I'm not sure what is the advantage of this change.  QEMU is more or less
>     uniformly using QemuMutex and QemuCond.
> 
>     Paolo
> 
>     > ---
>     >  exec.c                 | 5 ++---
>     >  include/exec/ramlist.h | 2 +-
>     >  2 files changed, 3 insertions(+), 4 deletions(-)
>     >
>     > diff --git a/exec.c b/exec.c
>     > index e8d7b33..90cdd05 100644
>     > --- a/exec.c
>     > +++ b/exec.c
>     > @@ -1423,12 +1423,12 @@ void qemu_flush_coalesced_mmio_buffer(void)
>     >
>     >  void qemu_mutex_lock_ramlist(void)
>     >  {
>     > -    qemu_mutex_lock(&ram_list.mutex);
>     > +    g_mutex_lock(&ram_list.mutex);
>     >  }
>     >
>     >  void qemu_mutex_unlock_ramlist(void)
>     >  {
>     > -    qemu_mutex_unlock(&ram_list.mutex);
>     > +    g_mutex_unlock(&ram_list.mutex);
>     >  }
>     >
>     >  void ram_block_dump(Monitor *mon)
>     > @@ -3331,7 +3331,6 @@ void cpu_register_map_client(QEMUBH *bh)
>     >
>     >  void cpu_exec_init_all(void)
>     >  {
>     > -    qemu_mutex_init(&ram_list.mutex);
>     >      /* The data structures we set up here depend on knowing the
>     page size,
>     >       * so no more changes can be made after this point.
>     >       * In an ideal world, nothing we did before we had finished the
>     > diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h
>     > index 2e2ac6c..24be5e4 100644
>     > --- a/include/exec/ramlist.h
>     > +++ b/include/exec/ramlist.h
>     > @@ -45,7 +45,7 @@ typedef struct {
>     >  } DirtyMemoryBlocks;
>     >
>     >  typedef struct RAMList {
>     > -    QemuMutex mutex;
>     > +    CompatGMutex mutex;
>     >      RAMBlock *mru_block;
>     >      /* RCU-enabled, writes protected by the ramlist lock. */
>     >      QLIST_HEAD(, RAMBlock) blocks;
>     >
> 
> 

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

* Re: [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex
  2018-02-14 12:11     ` Paolo Bonzini
@ 2018-02-16  9:13       ` Peter Maydell
  2018-02-20 12:14         ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2018-02-16  9:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zihan Yang, QEMU Developers

On 14 February 2018 at 12:11, Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 14/02/2018 12:43, Zihan Yang wrote:
>>
>>> I'm not sure what is the advantage of this change.  QEMU is more or less
>>> uniformly using QemuMutex and QemuCond.
>>
>> I see. QEMU uses some glib functions, like g_new, g_free, g_hash_table ,
>> g_assert and g_poll, so I thought there was a trend for making more use
>> of glib.
>> I get the point now.
>
> There are some plans about using priority inheritance mutexes for
> QemuMutex.  GLib does not support anymore pluggable thread functions, so
> we are stuck with our own implementation.

Should we remove the entry
"Change QemuMutex and QemuCond to CompatGMutex and CompatGCond (these are
 the same as GMutex and GCond, just with a different type). With this change,
 qemu_mutex_init/qemu_cond_init becomes optional for global variables."
from https://wiki.qemu.org/Contribute/BiteSizedTasks then?

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex
  2018-02-16  9:13       ` Peter Maydell
@ 2018-02-20 12:14         ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2018-02-20 12:14 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Zihan Yang, QEMU Developers

On 16/02/2018 10:13, Peter Maydell wrote:
> On 14 February 2018 at 12:11, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> On 14/02/2018 12:43, Zihan Yang wrote:
>>>
>>>> I'm not sure what is the advantage of this change.  QEMU is more or less
>>>> uniformly using QemuMutex and QemuCond.
>>>
>>> I see. QEMU uses some glib functions, like g_new, g_free, g_hash_table ,
>>> g_assert and g_poll, so I thought there was a trend for making more use
>>> of glib.
>>> I get the point now.
>>
>> There are some plans about using priority inheritance mutexes for
>> QemuMutex.  GLib does not support anymore pluggable thread functions, so
>> we are stuck with our own implementation.
> 
> Should we remove the entry
> "Change QemuMutex and QemuCond to CompatGMutex and CompatGCond (these are
>  the same as GMutex and GCond, just with a different type). With this change,
>  qemu_mutex_init/qemu_cond_init becomes optional for global variables."
> from https://wiki.qemu.org/Contribute/BiteSizedTasks then?

Yes, good idea.

Paolo

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

end of thread, other threads:[~2018-02-20 12:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14  8:49 [Qemu-devel] [PATCH] RAMList: replace QemuMutex with CompatGMutex Zihan Yang
2018-02-14 10:13 ` Paolo Bonzini
2018-02-14 11:43   ` Zihan Yang
2018-02-14 12:11     ` Paolo Bonzini
2018-02-16  9:13       ` Peter Maydell
2018-02-20 12:14         ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.