diff mbox series

[v2,2/9] cpus: Move do_run_on_cpu into softmmu/cpus.c

Message ID 20210723193444.133412-3-peterx@redhat.com (mailing list archive)
State New, archived
Headers show
Series memory: Sanity checks memory transaction when releasing BQL | expand

Commit Message

Peter Xu July 23, 2021, 7:34 p.m. UTC
It's only used by softmmu binaries not linux-user ones.  Make it static and
drop the definition in the header too.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 cpus-common.c         | 25 -------------------------
 include/hw/core/cpu.h | 12 ------------
 softmmu/cpus.c        | 26 ++++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 37 deletions(-)

Comments

David Hildenbrand July 27, 2021, 1:04 p.m. UTC | #1
On 23.07.21 21:34, Peter Xu wrote:
> It's only used by softmmu binaries not linux-user ones.  Make it static and
> drop the definition in the header too.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   cpus-common.c         | 25 -------------------------
>   include/hw/core/cpu.h | 12 ------------
>   softmmu/cpus.c        | 26 ++++++++++++++++++++++++++
>   3 files changed, 26 insertions(+), 37 deletions(-)
> 
> diff --git a/cpus-common.c b/cpus-common.c
> index d814b2439a..670826363f 100644
> --- a/cpus-common.c
> +++ b/cpus-common.c
> @@ -124,31 +124,6 @@ void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)
>       qemu_cpu_kick(cpu);
>   }
>   
> -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
> -                   QemuMutex *mutex)
> -{
> -    struct qemu_work_item wi;
> -
> -    if (qemu_cpu_is_self(cpu)) {
> -        func(cpu, data);
> -        return;
> -    }
> -
> -    wi.func = func;
> -    wi.data = data;
> -    wi.done = false;
> -    wi.free = false;
> -    wi.exclusive = false;
> -
> -    queue_work_on_cpu(cpu, &wi);
> -    while (!qatomic_mb_read(&wi.done)) {
> -        CPUState *self_cpu = current_cpu;
> -
> -        qemu_cond_wait(&qemu_work_cond, mutex);
> -        current_cpu = self_cpu;
> -    }
> -}
> -
>   void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
>   {
>       struct qemu_work_item *wi;
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index f62ae88524..711ecad62f 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -689,18 +689,6 @@ void qemu_cpu_kick(CPUState *cpu);
>    */
>   bool cpu_is_stopped(CPUState *cpu);
>   
> -/**
> - * do_run_on_cpu:
> - * @cpu: The vCPU to run on.
> - * @func: The function to be executed.
> - * @data: Data to pass to the function.
> - * @mutex: Mutex to release while waiting for @func to run.
> - *
> - * Used internally in the implementation of run_on_cpu.
> - */
> -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
> -                   QemuMutex *mutex);
> -
>   /**
>    * run_on_cpu:
>    * @cpu: The vCPU to run on.
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index 071085f840..52adc98d39 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -382,6 +382,32 @@ void qemu_init_cpu_loop(void)
>       qemu_thread_get_self(&io_thread);
>   }
>   
> +static void
> +do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
> +              QemuMutex *mutex)
> +{
> +    struct qemu_work_item wi;

You could do

struct qemu_work_item wi = {
     .func = func,
     .data = data,
};

instead of the separate initialization below.



> +
> +    if (qemu_cpu_is_self(cpu)) {
> +        func(cpu, data);
> +        return;
> +    }
> +
> +    wi.func = func;
> +    wi.data = data;
> +    wi.done = false;
> +    wi.free = false;
> +    wi.exclusive = false;
> +
> +    queue_work_on_cpu(cpu, &wi);
> +    while (!qatomic_mb_read(&wi.done)) {
> +        CPUState *self_cpu = current_cpu;
> +
> +        qemu_cond_wait(&qemu_work_cond, mutex);
> +        current_cpu = self_cpu;
> +    }
> +}

Reviewed-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/cpus-common.c b/cpus-common.c
index d814b2439a..670826363f 100644
--- a/cpus-common.c
+++ b/cpus-common.c
@@ -124,31 +124,6 @@  void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)
     qemu_cpu_kick(cpu);
 }
 
-void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
-                   QemuMutex *mutex)
-{
-    struct qemu_work_item wi;
-
-    if (qemu_cpu_is_self(cpu)) {
-        func(cpu, data);
-        return;
-    }
-
-    wi.func = func;
-    wi.data = data;
-    wi.done = false;
-    wi.free = false;
-    wi.exclusive = false;
-
-    queue_work_on_cpu(cpu, &wi);
-    while (!qatomic_mb_read(&wi.done)) {
-        CPUState *self_cpu = current_cpu;
-
-        qemu_cond_wait(&qemu_work_cond, mutex);
-        current_cpu = self_cpu;
-    }
-}
-
 void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
 {
     struct qemu_work_item *wi;
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index f62ae88524..711ecad62f 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -689,18 +689,6 @@  void qemu_cpu_kick(CPUState *cpu);
  */
 bool cpu_is_stopped(CPUState *cpu);
 
-/**
- * do_run_on_cpu:
- * @cpu: The vCPU to run on.
- * @func: The function to be executed.
- * @data: Data to pass to the function.
- * @mutex: Mutex to release while waiting for @func to run.
- *
- * Used internally in the implementation of run_on_cpu.
- */
-void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
-                   QemuMutex *mutex);
-
 /**
  * run_on_cpu:
  * @cpu: The vCPU to run on.
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 071085f840..52adc98d39 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -382,6 +382,32 @@  void qemu_init_cpu_loop(void)
     qemu_thread_get_self(&io_thread);
 }
 
+static void
+do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
+              QemuMutex *mutex)
+{
+    struct qemu_work_item wi;
+
+    if (qemu_cpu_is_self(cpu)) {
+        func(cpu, data);
+        return;
+    }
+
+    wi.func = func;
+    wi.data = data;
+    wi.done = false;
+    wi.free = false;
+    wi.exclusive = false;
+
+    queue_work_on_cpu(cpu, &wi);
+    while (!qatomic_mb_read(&wi.done)) {
+        CPUState *self_cpu = current_cpu;
+
+        qemu_cond_wait(&qemu_work_cond, mutex);
+        current_cpu = self_cpu;
+    }
+}
+
 void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
 {
     do_run_on_cpu(cpu, func, data, &qemu_global_mutex);