All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Emilio G. Cota" <cota@braap.org>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [Qemu-devel] [RFC v4 01/71] cpu: convert queued work to a QSIMPLEQ
Date: Mon, 29 Oct 2018 15:39:29 +0000	[thread overview]
Message-ID: <874ld4ahji.fsf@linaro.org> (raw)
In-Reply-To: <20181025144644.15464-1-cota@braap.org>


Emilio G. Cota <cota@braap.org> writes:

> Instead of open-coding it.
>
> While at it, make sure that all accesses to the list are
> performed while holding the list's lock.
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>  include/qom/cpu.h |  6 +++---
>  cpus-common.c     | 25 ++++++++-----------------
>  cpus.c            | 14 ++++++++++++--
>  qom/cpu.c         |  1 +
>  4 files changed, 24 insertions(+), 22 deletions(-)
>
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index dc130cd307..53488b202f 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -315,8 +315,8 @@ struct qemu_work_item;
>   * @mem_io_pc: Host Program Counter at which the memory was accessed.
>   * @mem_io_vaddr: Target virtual address at which the memory was accessed.
>   * @kvm_fd: vCPU file descriptor for KVM.
> - * @work_mutex: Lock to prevent multiple access to queued_work_*.
> - * @queued_work_first: First asynchronous work pending.
> + * @work_mutex: Lock to prevent multiple access to @work_list.
> + * @work_list: List of pending asynchronous work.
>   * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
>   *                        to @trace_dstate).
>   * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
> @@ -357,7 +357,7 @@ struct CPUState {
>      sigjmp_buf jmp_env;
>
>      QemuMutex work_mutex;
> -    struct qemu_work_item *queued_work_first, *queued_work_last;
> +    QSIMPLEQ_HEAD(, qemu_work_item) work_list;

Would:

  QSIMPLEQ_HEAD(work_list, qemu_work_item);

be neater?

>
>      CPUAddressSpace *cpu_ases;
>      int num_ases;
> diff --git a/cpus-common.c b/cpus-common.c
> index 98dd8c6ff1..a2a6cd93a1 100644
> --- a/cpus-common.c
> +++ b/cpus-common.c
> @@ -107,7 +107,7 @@ void cpu_list_remove(CPUState *cpu)
>  }
>
>  struct qemu_work_item {
> -    struct qemu_work_item *next;
> +    QSIMPLEQ_ENTRY(qemu_work_item) node;
>      run_on_cpu_func func;
>      run_on_cpu_data data;
>      bool free, exclusive, done;
> @@ -116,13 +116,7 @@ struct qemu_work_item {
>  static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)
>  {
>      qemu_mutex_lock(&cpu->work_mutex);
> -    if (cpu->queued_work_first == NULL) {
> -        cpu->queued_work_first = wi;
> -    } else {
> -        cpu->queued_work_last->next = wi;
> -    }
> -    cpu->queued_work_last = wi;
> -    wi->next = NULL;
> +    QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node);
>      wi->done = false;
>      qemu_mutex_unlock(&cpu->work_mutex);
>
> @@ -314,17 +308,14 @@ void process_queued_cpu_work(CPUState *cpu)
>  {
>      struct qemu_work_item *wi;
>
> -    if (cpu->queued_work_first == NULL) {
> +    qemu_mutex_lock(&cpu->work_mutex);
> +    if (QSIMPLEQ_EMPTY(&cpu->work_list)) {
> +        qemu_mutex_unlock(&cpu->work_mutex);
>          return;
>      }
> -
> -    qemu_mutex_lock(&cpu->work_mutex);
> -    while (cpu->queued_work_first != NULL) {
> -        wi = cpu->queued_work_first;
> -        cpu->queued_work_first = wi->next;
> -        if (!cpu->queued_work_first) {
> -            cpu->queued_work_last = NULL;
> -        }
> +    while (!QSIMPLEQ_EMPTY(&cpu->work_list)) {
> +        wi = QSIMPLEQ_FIRST(&cpu->work_list);
> +        QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node);
>          qemu_mutex_unlock(&cpu->work_mutex);
>          if (wi->exclusive) {
>              /* Running work items outside the BQL avoids the following deadlock:
> diff --git a/cpus.c b/cpus.c
> index cce64874e6..6d86522031 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -88,9 +88,19 @@ bool cpu_is_stopped(CPUState *cpu)
>      return cpu->stopped || !runstate_is_running();
>  }
>
> +static inline bool cpu_work_list_empty(CPUState *cpu)
> +{
> +    bool ret;
> +
> +    qemu_mutex_lock(&cpu->work_mutex);
> +    ret = QSIMPLEQ_EMPTY(&cpu->work_list);
> +    qemu_mutex_unlock(&cpu->work_mutex);
> +    return ret;

This could just be:

  return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list)

> +}
> +
>  static bool cpu_thread_is_idle(CPUState *cpu)
>  {
> -    if (cpu->stop || cpu->queued_work_first) {
> +    if (cpu->stop || !cpu_work_list_empty(cpu)) {
>          return false;
>      }
>      if (cpu_is_stopped(cpu)) {
> @@ -1509,7 +1519,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
>              cpu = first_cpu;
>          }
>
> -        while (cpu && !cpu->queued_work_first && !cpu->exit_request) {
> +        while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
>
>              atomic_mb_set(&tcg_current_rr_cpu, cpu);
>              current_cpu = cpu;
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 20ad54d43f..c47169896e 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -373,6 +373,7 @@ static void cpu_common_initfn(Object *obj)
>      cpu->nr_threads = 1;
>
>      qemu_mutex_init(&cpu->work_mutex);
> +    QSIMPLEQ_INIT(&cpu->work_list);
>      QTAILQ_INIT(&cpu->breakpoints);
>      QTAILQ_INIT(&cpu->watchpoints);

Otherwise:

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

--
Alex Bennée

  parent reply	other threads:[~2018-10-29 15:40 UTC|newest]

Thread overview: 179+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-25 14:45 [Qemu-devel] [RFC v4 01/71] cpu: convert queued work to a QSIMPLEQ Emilio G. Cota
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 02/71] cpu: rename cpu->work_mutex to cpu->lock Emilio G. Cota
2018-10-29 15:22   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 03/71] cpu: introduce cpu_mutex_lock/unlock Emilio G. Cota
2018-10-26 14:40   ` Richard Henderson
2018-10-29 15:54   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 04/71] cpu: make qemu_work_cond per-cpu Emilio G. Cota
2018-10-26 14:45   ` Richard Henderson
2018-10-30 12:27   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 05/71] cpu: move run_on_cpu to cpus-common Emilio G. Cota
2018-10-29 16:34   ` Alex Bennée
2018-10-29 21:39     ` Emilio G. Cota
2018-10-30  8:28       ` Paolo Bonzini
2018-10-30 12:23         ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 06/71] cpu: introduce process_queued_cpu_work_locked Emilio G. Cota
2018-10-29 16:35   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 07/71] tcg-runtime: define helper_cpu_halted_set Emilio G. Cota
2018-10-26 14:57   ` Richard Henderson
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 08/71] ppc: convert to helper_cpu_halted_set Emilio G. Cota
2018-10-26 14:57   ` Richard Henderson
2018-10-31 11:35   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 09/71] cris: " Emilio G. Cota
2018-10-26 14:58   ` Richard Henderson
2018-10-31 11:42   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 10/71] hppa: " Emilio G. Cota
2018-10-26 14:58   ` Richard Henderson
2018-10-31 11:43   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 11/71] m68k: " Emilio G. Cota
2018-10-26 14:59   ` Richard Henderson
2018-10-31 11:43   ` Alex Bennée
2018-10-31 12:27   ` Laurent Vivier
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 12/71] alpha: " Emilio G. Cota
2018-10-26 15:00   ` Richard Henderson
2018-10-31 11:45   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 13/71] microblaze: " Emilio G. Cota
2018-10-26 15:00   ` Richard Henderson
2018-10-31 11:47   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 14/71] cpu: define cpu_halted helpers Emilio G. Cota
2018-10-31 12:04   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 15/71] tcg-runtime: convert to cpu_halted_set Emilio G. Cota
2018-10-26 15:01   ` Richard Henderson
2018-10-31 11:56   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 16/71] arm: convert to cpu_halted Emilio G. Cota
2018-10-25 14:45   ` Emilio G. Cota
2018-10-31 12:15   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 17/71] ppc: " Emilio G. Cota
2018-10-26 15:02   ` Richard Henderson
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 18/71] sh4: " Emilio G. Cota
2018-10-31 13:54   ` Alex Bennée
2018-10-31 16:26     ` Emilio G. Cota
2018-10-31 16:38       ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 19/71] i386: " Emilio G. Cota
2018-10-31 14:20   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 20/71] lm32: " Emilio G. Cota
2018-10-31 14:20   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 21/71] m68k: " Emilio G. Cota
2018-10-31 12:29   ` Laurent Vivier
2018-10-31 16:14   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 22/71] mips: " Emilio G. Cota
2018-10-31 14:22   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 23/71] riscv: " Emilio G. Cota
2018-10-26 15:03   ` Richard Henderson
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 24/71] s390x: " Emilio G. Cota
2018-10-31 16:13   ` Alex Bennée
2018-10-31 16:38     ` Emilio G. Cota
2018-10-31 16:56       ` Alex Bennée
2018-11-09 13:47         ` Cornelia Huck
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 25/71] sparc: " Emilio G. Cota
2018-10-31 16:13   ` Alex Bennée
2018-10-25 14:45 ` [Qemu-devel] [RFC v4 26/71] xtensa: " Emilio G. Cota
2018-10-31 16:13   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 27/71] gdbstub: " Emilio G. Cota
2018-10-31 16:14   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 28/71] openrisc: " Emilio G. Cota
2018-10-31 16:14   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 29/71] cpu-exec: " Emilio G. Cota
2018-10-26 15:04   ` Richard Henderson
2018-10-31 16:16   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 30/71] cpu: define cpu_interrupt_request helpers Emilio G. Cota
2018-10-26 15:07   ` Richard Henderson
2018-10-31 16:21   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 31/71] ppc: use cpu_reset_interrupt Emilio G. Cota
2018-10-31 16:21   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 32/71] exec: " Emilio G. Cota
2018-10-26 15:07   ` Richard Henderson
2018-10-31 16:33   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 33/71] i386: " Emilio G. Cota
2018-10-31 16:34   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 34/71] s390x: " Emilio G. Cota
2018-10-31 16:34   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 35/71] openrisc: " Emilio G. Cota
2018-10-31 16:35   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 36/71] arm: convert to cpu_interrupt_request Emilio G. Cota
2018-10-25 14:46   ` Emilio G. Cota
2018-10-26 13:39   ` Alex Bennée
2018-10-26 16:31     ` Emilio G. Cota
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 37/71] i386: " Emilio G. Cota
2018-10-26 15:08   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 38/71] i386/kvm: " Emilio G. Cota
2018-10-26 15:10   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 39/71] i386/hax-all: " Emilio G. Cota
2018-10-26 15:11   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 40/71] i386/whpx-all: " Emilio G. Cota
2018-10-26 15:12   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 41/71] i386/hvf: convert to cpu_request_interrupt Emilio G. Cota
2018-10-26 15:12   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 42/71] ppc: convert to cpu_interrupt_request Emilio G. Cota
2018-10-26 15:45   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 43/71] sh4: " Emilio G. Cota
2018-10-31 16:36   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 44/71] cris: " Emilio G. Cota
2018-10-31 16:36   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 45/71] hppa: " Emilio G. Cota
2018-10-31 16:36   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 46/71] lm32: " Emilio G. Cota
2018-10-31 16:36   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 47/71] m68k: " Emilio G. Cota
2018-10-31 12:32   ` Laurent Vivier
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 48/71] mips: " Emilio G. Cota
2018-10-26 15:45   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 49/71] nios: " Emilio G. Cota
2018-10-31 16:37   ` Alex Bennée
2018-10-31 16:38   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 50/71] s390x: " Emilio G. Cota
2018-10-31 16:39   ` Alex Bennée
2018-11-09 13:49   ` Cornelia Huck
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 51/71] alpha: " Emilio G. Cota
2018-10-31 16:39   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 52/71] moxie: " Emilio G. Cota
2018-10-31 16:39   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 53/71] sparc: " Emilio G. Cota
2018-10-31 16:40   ` Alex Bennée
2018-10-31 16:42   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 54/71] openrisc: " Emilio G. Cota
2018-10-31 16:43   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 55/71] unicore32: " Emilio G. Cota
2018-10-31 16:44   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 56/71] microblaze: " Emilio G. Cota
2018-10-31 16:44   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 57/71] accel/tcg: " Emilio G. Cota
2018-10-26 15:48   ` Richard Henderson
2018-10-31 16:46   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 58/71] cpu: call .cpu_has_work with the CPU lock held Emilio G. Cota
2018-10-26 15:48   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 59/71] cpu: introduce cpu_has_work_with_iothread_lock Emilio G. Cota
2018-10-26 15:51   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 60/71] ppc: convert to cpu_has_work_with_iothread_lock Emilio G. Cota
2018-10-26 15:53   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 61/71] mips: " Emilio G. Cota
2018-10-26 15:54   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 62/71] s390x: " Emilio G. Cota
2018-10-26 15:54   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 63/71] riscv: " Emilio G. Cota
2018-10-26 15:54   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 64/71] sparc: " Emilio G. Cota
2018-10-26 15:54   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 65/71] xtensa: " Emilio G. Cota
2018-10-26 15:54   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 66/71] cpu: protect most CPU state with cpu->lock Emilio G. Cota
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 67/71] cpus-common: release BQL earlier in run_on_cpu Emilio G. Cota
2018-10-26 15:59   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 68/71] cpu: add async_run_on_cpu_no_bql Emilio G. Cota
2018-10-26 16:00   ` Richard Henderson
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 69/71] cputlb: queue async flush jobs without the BQL Emilio G. Cota
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 70/71] cpus-common: move exclusive_idle higher in the file Emilio G. Cota
2018-10-26 16:06   ` Richard Henderson
2018-10-29 15:21   ` Alex Bennée
2018-10-25 14:46 ` [Qemu-devel] [RFC v4 71/71] cpus-common: wait on the CPU lock for exclusive work completion Emilio G. Cota
2018-10-29 15:31   ` Alex Bennée
2018-10-25 15:11 ` [Qemu-arm] [RFC v4 00/71] per-CPU locks Emilio G. Cota
2018-10-25 15:11   ` [Qemu-devel] " Emilio G. Cota
2018-10-27  9:14   ` [Qemu-arm] " Alex Bennée
2018-10-27  9:14     ` [Qemu-devel] " Alex Bennée
2018-10-29 15:47     ` Emilio G. Cota
2018-10-29 15:47       ` [Qemu-devel] " Emilio G. Cota
2018-10-29 16:00       ` Alex Bennée
2018-10-29 16:00         ` [Qemu-devel] " Alex Bennée
2018-10-29 15:39 ` Alex Bennée [this message]
2018-10-29 15:55   ` [Qemu-devel] [RFC v4 01/71] cpu: convert queued work to a QSIMPLEQ Emilio G. Cota

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874ld4ahji.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=cota@braap.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.