Re: [Qemu-devel] [PATCH 02/10] cpus: remove tcg_halt_cond global variable.

2015-08-29 Thread Paolo Bonzini


On 28/08/2015 16:36, Peter Maydell wrote:
 With this patch, code-wise tcg_halt_cond and tcg_cpu_thread
 are used in pretty much parallel ways (first call into
 qemu_tcg_init_vcpu() sets them up, all the rest just copy
 them into the CPU struct). The only difference is that one
 of them a static at file scope and the other one is a static
 at function scope. It seems a shame to not have them be
 exactly parallel...

Good point, this does the trick:

diff --git a/cpus.c b/cpus.c
index 105b914..054dd68 100644
--- a/cpus.c
+++ b/cpus.c
@@ -786,8 +786,6 @@ static unsigned iothread_requesting_mutex;
 
 static QemuThread io_thread;
 
-static QemuThread *tcg_cpu_thread;
-
 /* cpu creation */
 static QemuCond qemu_cpu_cond;
 /* system init */
@@ -1222,6 +1220,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu)
 {
 char thread_name[VCPU_THREAD_NAME_SIZE];
 static QemuCond *tcg_halt_cond;
+static QemuThread *tcg_cpu_thread;
 
 tcg_cpu_address_space_init(cpu, cpu-as);
 
Paolo



Re: [Qemu-devel] [PATCH 02/10] cpus: remove tcg_halt_cond global variable.

2015-08-28 Thread Peter Maydell
On 12 August 2015 at 17:40, Paolo Bonzini pbonz...@redhat.com wrote:
 From: KONRAD Frederic fred.kon...@greensocs.com

 This removes tcg_halt_cond global variable.
 We need one QemuCond per virtual cpu for multithread TCG.

 Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
 Message-Id: 1439220437-23957-9-git-send-email-fred.kon...@greensocs.com
 [Keep tcg_halt_cond for bisectability, while making it static. - Paolo]
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  cpus.c | 12 +---
  1 file changed, 5 insertions(+), 7 deletions(-)

 diff --git a/cpus.c b/cpus.c
 index 9224488..8884278 100644
 --- a/cpus.c
 +++ b/cpus.c
 @@ -813,7 +813,6 @@ static unsigned iothread_requesting_mutex;
  static QemuThread io_thread;

  static QemuThread *tcg_cpu_thread;
 -static QemuCond *tcg_halt_cond;


 @@ -1265,6 +1262,7 @@ void resume_all_vcpus(void)
  static void qemu_tcg_init_vcpu(CPUState *cpu)
  {
  char thread_name[VCPU_THREAD_NAME_SIZE];
 +static QemuCond *tcg_halt_cond;

  tcg_cpu_address_space_init(cpu, cpu-as);

With this patch, code-wise tcg_halt_cond and tcg_cpu_thread
are used in pretty much parallel ways (first call into
qemu_tcg_init_vcpu() sets them up, all the rest just copy
them into the CPU struct). The only difference is that one
of them a static at file scope and the other one is a static
at function scope. It seems a shame to not have them be
exactly parallel...

thanks
-- PMM



Re: [Qemu-devel] [PATCH 02/10] cpus: remove tcg_halt_cond global variable.

2015-08-13 Thread Paolo Bonzini


On 13/08/2015 15:05, Frederic Konrad wrote:


 This removes tcg_halt_cond global variable.
 We need one QemuCond per virtual cpu for multithread TCG.

 Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
 Message-Id: 1439220437-23957-9-git-send-email-fred.kon...@greensocs.com
 [Keep tcg_halt_cond for bisectability, while making it static. - Paolo]
 How does that help bisectability?

With your patch (08/19), QEMU will only wait on first_cpu-halt_cond but
will call broadcast on cpu-halt_cond.  Here I do the opposite: I wait
on cpu-halt_cond from some random CPU, but all of them point to the
same condvar tcg_halt_cond.

Paolo



Re: [Qemu-devel] [PATCH 02/10] cpus: remove tcg_halt_cond global variable.

2015-08-13 Thread Frederic Konrad

On 12/08/2015 18:40, Paolo Bonzini wrote:

From: KONRAD Frederic fred.kon...@greensocs.com

This removes tcg_halt_cond global variable.
We need one QemuCond per virtual cpu for multithread TCG.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
Message-Id: 1439220437-23957-9-git-send-email-fred.kon...@greensocs.com
[Keep tcg_halt_cond for bisectability, while making it static. - Paolo]

How does that help bisectability?

Fred

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
  cpus.c | 12 +---
  1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/cpus.c b/cpus.c
index 9224488..8884278 100644
--- a/cpus.c
+++ b/cpus.c
@@ -813,7 +813,6 @@ static unsigned iothread_requesting_mutex;
  static QemuThread io_thread;
  
  static QemuThread *tcg_cpu_thread;

-static QemuCond *tcg_halt_cond;
  
  /* cpu creation */

  static QemuCond qemu_cpu_cond;
@@ -933,15 +932,13 @@ static void qemu_wait_io_event_common(CPUState *cpu)
  cpu-thread_kicked = false;
  }
  
-static void qemu_tcg_wait_io_event(void)

+static void qemu_tcg_wait_io_event(CPUState *cpu)
  {
-CPUState *cpu;
-
  while (all_cpu_threads_idle()) {
 /* Start accounting real time to the virtual clock if the CPUs
are idle.  */
  qemu_clock_warp(QEMU_CLOCK_VIRTUAL);
-qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
+qemu_cond_wait(cpu-halt_cond, qemu_global_mutex);
  }
  
  while (iothread_requesting_mutex) {

@@ -1067,7 +1064,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
  
  /* wait for initial kick-off after machine start */

  while (first_cpu-stopped) {
-qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
+qemu_cond_wait(first_cpu-halt_cond, qemu_global_mutex);
  
  /* process any pending work */

  CPU_FOREACH(cpu) {
@@ -1088,7 +1085,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
  qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
  }
  }
-qemu_tcg_wait_io_event();
+qemu_tcg_wait_io_event(QTAILQ_FIRST(cpus));
  }
  
  return NULL;

@@ -1265,6 +1262,7 @@ void resume_all_vcpus(void)
  static void qemu_tcg_init_vcpu(CPUState *cpu)
  {
  char thread_name[VCPU_THREAD_NAME_SIZE];
+static QemuCond *tcg_halt_cond;
  
  tcg_cpu_address_space_init(cpu, cpu-as);
  





Re: [Qemu-devel] [PATCH 02/10] cpus: remove tcg_halt_cond global variable.

2015-08-13 Thread Frederic Konrad

On 13/08/2015 15:08, Paolo Bonzini wrote:


On 13/08/2015 15:05, Frederic Konrad wrote:


This removes tcg_halt_cond global variable.
We need one QemuCond per virtual cpu for multithread TCG.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
Message-Id: 1439220437-23957-9-git-send-email-fred.kon...@greensocs.com
[Keep tcg_halt_cond for bisectability, while making it static. - Paolo]

How does that help bisectability?

With your patch (08/19), QEMU will only wait on first_cpu-halt_cond but
will call broadcast on cpu-halt_cond.  Here I do the opposite: I wait
on cpu-halt_cond from some random CPU, but all of them point to the
same condvar tcg_halt_cond.

Paolo

Ok got it.

Fred



[Qemu-devel] [PATCH 02/10] cpus: remove tcg_halt_cond global variable.

2015-08-12 Thread Paolo Bonzini
From: KONRAD Frederic fred.kon...@greensocs.com

This removes tcg_halt_cond global variable.
We need one QemuCond per virtual cpu for multithread TCG.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
Message-Id: 1439220437-23957-9-git-send-email-fred.kon...@greensocs.com
[Keep tcg_halt_cond for bisectability, while making it static. - Paolo]
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/cpus.c b/cpus.c
index 9224488..8884278 100644
--- a/cpus.c
+++ b/cpus.c
@@ -813,7 +813,6 @@ static unsigned iothread_requesting_mutex;
 static QemuThread io_thread;
 
 static QemuThread *tcg_cpu_thread;
-static QemuCond *tcg_halt_cond;
 
 /* cpu creation */
 static QemuCond qemu_cpu_cond;
@@ -933,15 +932,13 @@ static void qemu_wait_io_event_common(CPUState *cpu)
 cpu-thread_kicked = false;
 }
 
-static void qemu_tcg_wait_io_event(void)
+static void qemu_tcg_wait_io_event(CPUState *cpu)
 {
-CPUState *cpu;
-
 while (all_cpu_threads_idle()) {
/* Start accounting real time to the virtual clock if the CPUs
   are idle.  */
 qemu_clock_warp(QEMU_CLOCK_VIRTUAL);
-qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
+qemu_cond_wait(cpu-halt_cond, qemu_global_mutex);
 }
 
 while (iothread_requesting_mutex) {
@@ -1067,7 +1064,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 
 /* wait for initial kick-off after machine start */
 while (first_cpu-stopped) {
-qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
+qemu_cond_wait(first_cpu-halt_cond, qemu_global_mutex);
 
 /* process any pending work */
 CPU_FOREACH(cpu) {
@@ -1088,7 +1085,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
 }
 }
-qemu_tcg_wait_io_event();
+qemu_tcg_wait_io_event(QTAILQ_FIRST(cpus));
 }
 
 return NULL;
@@ -1265,6 +1262,7 @@ void resume_all_vcpus(void)
 static void qemu_tcg_init_vcpu(CPUState *cpu)
 {
 char thread_name[VCPU_THREAD_NAME_SIZE];
+static QemuCond *tcg_halt_cond;
 
 tcg_cpu_address_space_init(cpu, cpu-as);
 
-- 
1.8.3.1