qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Emilio G. Cota" <cota@braap.org>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Aleksandar Markovic <amarkovic@wavecomp.com>,
	Alexander Graf <agraf@suse.de>,
	Alistair Francis <alistair23@gmail.com>,
	Andrzej Zaborowski <balrogg@gmail.com>,
	Anthony Green <green@moxielogic.com>,
	Artyom Tarasenko <atar4qemu@gmail.com>,
	Aurelien Jarno <aurelien@aurel32.net>,
	Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Chris Wulff <crwulff@gmail.com>,
	Cornelia Huck <cohuck@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	David Hildenbrand <david@redhat.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Fabien Chouteau <chouteau@adacore.com>,
	Guan Xuetao <gxt@mprc.pku.edu.cn>,
	James Hogan <jhogan@kernel.org>,
	Laurent Vivier <laurent@vivier.eu>, Marek Vasut <marex@denx.de>,
	Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
	Max Filippov <jcmvbkbc@gmail.com>, Michael Clark <mjc@sifive.com>,
	Michael Walle <michael@walle.cc>,
	Palmer Dabbelt <palmer@sifive.com>,
	Pavel Dovgalyuk <dovgaluk@ispras.ru>,
	Peter Maydell <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-s390x@nongnu.org,
	Sagar Karandikar <sagark@eecs.berkeley.edu>,
	Stafford Horne <shorne@gmail.com>
Subject: [Qemu-devel] [RFC v4 00/71] per-CPU locks
Date: Thu, 25 Oct 2018 11:11:03 -0400	[thread overview]
Message-ID: <20181025151103.GA19931@flamenco> (raw)
In-Reply-To: <20181025144644.15464-1-cota@braap.org>

[I forgot to add the cover letter to git send-email; here it is]

v3: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg04179.html

"Why is this an RFC?" See v3 link above. Also, see comment at
the bottom of this message regarding the last patch of this series.

Changes since v3:

- Add R-b's -- rth: thanks for all the reviews!

- Partially bring back the approach in the v1 series, that is,
  do not acquire the CPU mutex in cpu_interrupt_request; use
  atomic_read instead. The lock is not needed because of the
  OR+kick sequence; note that when we do not have the BQL
  (i.e. in MTTCG's CPU loop), we do have the lock while reading
  cpu_interrupt_request, so no writes can be missed there.
  This simplifies the calling code quite a bit, since we do
  not hold cpu_mutex across large portions of code (this is
  a very bad idea, e.g. could lead to deadlock for instance
  if we tried to queue work on another CPU).
  Setters still acquire the lock, since it's the cost is
  very similar to that of a locked atomic, and makes the
  code simpler.

- Use an intermediate interrupt_request variable wherever
  this is trivial to do. Whenever there's a chance that
  cpu->interrupt_request might have been updated between
  reads, just use cpu_interrupt_request to perform a load
  via atomic_read.

- Drop the BQL assert in run_on_cpu. Keep the guarantee that
  the queued work holds the BQL, though.

- Add a no_cpu_mutex_lock_held assert to run_on_cpu; note that
  acquiring CPU locks can only be done in CPU_FOREACH order,
  otherwise we might deadlock.

- Remove qemu_cpu_cond leftovers; it's superseded by cpu->cond.

- Export no_cpu_mutex_lock_held.

- Do not export process_queued_work_locked from cpus-common.c;
  at some point we need to drop cpu_mutex for other vCPUs to queue
  work on the current vCPU, and process_queued_work is a good
  place to do that. Add comment about this.

- Add helper_cpu_halted_set helper to tcg-runtime. Convert
  the TCG targets that were setting cpu->halted directly.

- Fix cpu_reset_interrupt in cpu_common_post_load, as reported
  by Richard.

- Fix a hang after making qemu_work_cond per-cpu. The hang can
  only happen between that commit and the commit that completes
  the transition to per-CPU locks. This would break bisect, so
  fix it. In addition, add a comment about it, and add a tiny
  patch to undo the fix once the transition is complete and the
  fix isn't needed any more.

- Fix a possible deadlock (acquiring the BQL *after* having
  acquired the CPU mutex) in cpu_reset_interrupt. This would break
  bisection until the transition to per-CPU locks, so fix it
  and add a comment about it to the commit log of the "cpu: define
  cpu_interrupt_request helpers" patch.

- Add cc->has_work_with_iothread_lock, as suggested by Paolo,
  and convert the targets that need it.

- Add a patch to reduce contention when doing exclusive work.
  In my tests I've only found aarch64 to benefit (very minimally)
  from this; for other targets this patch is perf-neutral.
  In aarch64, the problem is that frequent global TLB invalidations
  require frequent exclusive work; sync-profile points to unnecessary
  contention on cpu_list_lock, which all waiters wait on
  while the exclusive work completes. To fix this, make the
  waiters wait on their CPU lock, so that their wakeup is uncontended.
  The perf impact is that the scalability collapse due to exclusive
  work is mitigated, but not fixed.
  So I'm including this patch to raise awareness about the issue,
  but I don't feel strongly at all about merging it.

The series is checkpatch-clean (single warning about __COVERITY__).

You can fetch it from:
  https://github.com/cota/qemu/tree/cpu-lock-v4

Thanks,

		Emilio

  parent reply	other threads:[~2018-10-25 15:11 UTC|newest]

Thread overview: 173+ 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-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-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 ` Emilio G. Cota [this message]
2018-10-27  9:14   ` [Qemu-devel] [Qemu-arm] [RFC v4 00/71] per-CPU locks Alex Bennée
2018-10-29 15:47     ` Emilio G. Cota
2018-10-29 16:00       ` Alex Bennée
2018-10-29 15:39 ` [Qemu-devel] [RFC v4 01/71] cpu: convert queued work to a QSIMPLEQ Alex Bennée
2018-10-29 15:55   ` 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=20181025151103.GA19931@flamenco \
    --to=cota@braap.org \
    --cc=agraf@suse.de \
    --cc=alistair23@gmail.com \
    --cc=amarkovic@wavecomp.com \
    --cc=atar4qemu@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=balrogg@gmail.com \
    --cc=borntraeger@de.ibm.com \
    --cc=chouteau@adacore.com \
    --cc=cohuck@redhat.com \
    --cc=crwulff@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dovgaluk@ispras.ru \
    --cc=edgar.iglesias@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=green@moxielogic.com \
    --cc=gxt@mprc.pku.edu.cn \
    --cc=jcmvbkbc@gmail.com \
    --cc=jhogan@kernel.org \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=laurent@vivier.eu \
    --cc=marex@denx.de \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=michael@walle.cc \
    --cc=mjc@sifive.com \
    --cc=palmer@sifive.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sagark@eecs.berkeley.edu \
    --cc=shorne@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).