diff mbox series

[RFC,v2,03/38] cpu: introduce cpu_in_exclusive_work_context()

Message ID 20181209193749.12277-4-cota@braap.org (mailing list archive)
State New, archived
Headers show
Series Plugin support | expand

Commit Message

Emilio Cota Dec. 9, 2018, 7:37 p.m. UTC
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 include/qom/cpu.h | 13 +++++++++++++
 cpus-common.c     |  2 ++
 2 files changed, 15 insertions(+)

Comments

Alex Bennée Jan. 24, 2019, 2:44 p.m. UTC | #1
Emilio G. Cota <cota@braap.org> writes:

> Suggested-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>  include/qom/cpu.h | 13 +++++++++++++
>  cpus-common.c     |  2 ++
>  2 files changed, 15 insertions(+)
>
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 772cc960fe..fab18089db 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -349,6 +349,7 @@ struct CPUState {
>      bool thread_kicked;
>      bool crash_occurred;
>      bool exit_request;
> +    bool in_exclusive_work_context;

I'm not sure if I meant this or in_exclusive_context and push the flag
into start/end_exclusive. But let's see how it shakes out:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>


>      uint32_t cflags_next_tb;
>      /* updates protected by BQL */
>      uint32_t interrupt_request;
> @@ -913,6 +914,18 @@ void async_run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func,
>   */
>  void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
>
> +/**
> + * cpu_in_exclusive_work_context()
> + * @cpu: The vCPU to check
> + *
> + * Returns true if @cpu is an exclusive work context, which has
> + * previously been queued via async_safe_run_on_cpu().
> + */
> +static inline bool cpu_in_exclusive_work_context(const CPUState *cpu)
> +{
> +    return cpu->in_exclusive_work_context;
> +}
> +
>  /**
>   * qemu_get_cpu:
>   * @index: The CPUState@cpu_index value of the CPU to obtain.
> diff --git a/cpus-common.c b/cpus-common.c
> index 232cb12c46..d6ea42c80c 100644
> --- a/cpus-common.c
> +++ b/cpus-common.c
> @@ -370,7 +370,9 @@ static void process_queued_cpu_work_locked(CPUState *cpu)
>                  qemu_mutex_unlock_iothread();
>              }
>              start_exclusive();
> +            cpu->in_exclusive_work_context = true;
>              wi->func(cpu, wi->data);
> +            cpu->in_exclusive_work_context = false;
>              end_exclusive();
>              if (has_bql) {
>                  qemu_mutex_lock_iothread();


--
Alex Bennée
diff mbox series

Patch

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 772cc960fe..fab18089db 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -349,6 +349,7 @@  struct CPUState {
     bool thread_kicked;
     bool crash_occurred;
     bool exit_request;
+    bool in_exclusive_work_context;
     uint32_t cflags_next_tb;
     /* updates protected by BQL */
     uint32_t interrupt_request;
@@ -913,6 +914,18 @@  void async_run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func,
  */
 void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
 
+/**
+ * cpu_in_exclusive_work_context()
+ * @cpu: The vCPU to check
+ *
+ * Returns true if @cpu is an exclusive work context, which has
+ * previously been queued via async_safe_run_on_cpu().
+ */
+static inline bool cpu_in_exclusive_work_context(const CPUState *cpu)
+{
+    return cpu->in_exclusive_work_context;
+}
+
 /**
  * qemu_get_cpu:
  * @index: The CPUState@cpu_index value of the CPU to obtain.
diff --git a/cpus-common.c b/cpus-common.c
index 232cb12c46..d6ea42c80c 100644
--- a/cpus-common.c
+++ b/cpus-common.c
@@ -370,7 +370,9 @@  static void process_queued_cpu_work_locked(CPUState *cpu)
                 qemu_mutex_unlock_iothread();
             }
             start_exclusive();
+            cpu->in_exclusive_work_context = true;
             wi->func(cpu, wi->data);
+            cpu->in_exclusive_work_context = false;
             end_exclusive();
             if (has_bql) {
                 qemu_mutex_lock_iothread();