Skip to content

per-CPU locks

Emilio G. Cota qemu-arm qemu-devel 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest73 patches 4 repliesIn review
  2. v673 patches 35 repliesSuperseded
  3. v573 patches 8 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v4 RFC71 patches101 repliesSuperseded
v3 RFC56 patches61 repliesSuperseded

Changes in v7 from the cover letter

- Rebase on master
- Add a cpu_halted_set call to arm code that wasn't there in v6

- Add R-b's and Ack's.

- Add comment to patch 3's log to explain why the bitmap is added there, even though it only gains a user at the end of the series.

- Fix "prevent deadlock" comments before assertions; use "enforce locking order" instead, which is more accurate.

- Add a few more comments, as suggested by Alex.

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/73cpu: convert queued work to a QSIMPLEQcpus-common.c cpus.c include/qom/cpu.h +1 more+24 -220 replies
2/73cpu: rename cpu->work_mutex to cpu->lockcpus-common.c cpus.c include/qom/cpu.h +1 more+14 -120 replies
3/73cpu: introduce cpu_mutex_lock/unlockcpus.c include/qom/cpu.h stubs/Makefile.objs +1 more+108 -20 replies
4/73cpu: make qemu_work_cond per-cpucpus-common.c cpus.c include/qom/cpu.h +1 more+63 -180 replies
5/73cpu: move run_on_cpu to cpus-commoncpus-common.c cpus.c include/qom/cpu.h+1 -160 replies
6/73cpu: introduce process_queued_cpu_work_lockedcpus-common.c+11 -60 replies
7/73cpu: make per-CPU locks an alias of the BQL in TCG rr modecpus-common.c cpus.c include/qom/cpu.h +2 more+86 -170 replies
8/73tcg-runtime: define helper_cpu_halted_setaccel/tcg/tcg-runtime.c accel/tcg/tcg-runtime.h+9 -00 replies
9/73ppc: convert to helper_cpu_halted_settarget/ppc/translate.c+2 -40 replies
10/73cris: convert to helper_cpu_halted_settarget/cris/translate.c+3 -20 replies
11/73hppa: convert to helper_cpu_halted_settarget/hppa/translate.c+1 -20 replies
12/73m68k: convert to helper_cpu_halted_settarget/m68k/translate.c+4 -50 replies
13/73alpha: convert to helper_cpu_halted_settarget/alpha/translate.c+2 -40 replies
14/73microblaze: convert to helper_cpu_halted_settarget/microblaze/translate.c+1 -30 replies
15/73cpu: define cpu_halted helpersinclude/qom/cpu.h+24 -00 replies
16/73tcg-runtime: convert to cpu_halted_setaccel/tcg/tcg-runtime.c+1 -10 replies
17/73arm: convert to cpu_haltedhw/arm/omap1.c hw/arm/pxa2xx_gpio.c hw/arm/pxa2xx_pic.c +3 more+9 -90 replies
18/73ppc: convert to cpu_haltedhw/ppc/e500.c hw/ppc/ppc.c hw/ppc/ppce500_spin.c +7 more+27 -230 replies
19/73sh4: convert to cpu_haltedtarget/sh4/op_helper.c+1 -10 replies
20/73i386: convert to cpu_haltedtarget/i386/cpu.c target/i386/cpu.h target/i386/hax-all.c +6 more+19 -190 replies
21/73lm32: convert to cpu_haltedtarget/lm32/op_helper.c+2 -20 replies
22/73m68k: convert to cpu_haltedtarget/m68k/op_helper.c+1 -10 replies
23/73mips: convert to cpu_haltedhw/mips/cps.c hw/misc/mips_itu.c target/mips/kvm.c +2 more+10 -100 replies
24/73riscv: convert to cpu_haltedtarget/riscv/op_helper.c+1 -10 replies
25/73s390x: convert to cpu_haltedhw/intc/s390_flic.c target/s390x/cpu.c target/s390x/excp_helper.c +2 more+22 -140 replies
26/73sparc: convert to cpu_haltedhw/sparc/leon3.c hw/sparc/sun4m.c hw/sparc64/sparc64.c +1 more+8 -80 replies
27/73xtensa: convert to cpu_haltedtarget/xtensa/cpu.c target/xtensa/exc_helper.c target/xtensa/helper.c+3 -30 replies
28/73gdbstub: convert to cpu_haltedgdbstub.c+2 -20 replies
29/73openrisc: convert to cpu_haltedtarget/openrisc/sys_helper.c+1 -10 replies
30/73cpu-exec: convert to cpu_haltedaccel/tcg/cpu-exec.c+21 -40 replies
31/73cpu: convert to cpu_haltedaccel/tcg/cpu-exec.c cpus.c qom/cpu.c+6 -60 replies
32/73cpu: define cpu_interrupt_request helpersinclude/qom/cpu.h qom/cpu.c+58 -60 replies
33/73ppc: use cpu_reset_interrupttarget/ppc/excp_helper.c+1 -10 replies
34/73exec: use cpu_reset_interruptexec.c+1 -10 replies
35/73i386: use cpu_reset_interrupttarget/i386/hax-all.c target/i386/hvf/x86hvf.c target/i386/kvm.c +3 more+25 -260 replies
36/73s390x: use cpu_reset_interrupttarget/s390x/excp_helper.c+1 -10 replies
37/73openrisc: use cpu_reset_interrupttarget/openrisc/sys_helper.c+1 -10 replies
38/73arm: convert to cpu_interrupt_requesttarget/arm/cpu.c target/arm/helper.c target/arm/machine.c+11 -130 replies
39/73i386: convert to cpu_interrupt_requesttarget/i386/cpu.c target/i386/helper.c target/i386/svm_helper.c+5 -50 replies
40/73i386/kvm: convert to cpu_interrupt_requesttarget/i386/kvm.c+35 -230 replies
41/73i386/hax-all: convert to cpu_interrupt_requesttarget/i386/hax-all.c+17 -130 replies
42/73i386/whpx-all: convert to cpu_interrupt_requesttarget/i386/whpx-all.c+24 -170 replies
43/73i386/hvf: convert to cpu_request_interrupttarget/i386/hvf/hvf.c target/i386/hvf/x86hvf.c+20 -140 replies
44/73ppc: convert to cpu_interrupt_requesthw/ppc/ppc.c target/ppc/kvm.c target/ppc/translate_init.inc.c+10 -100 replies
45/73sh4: convert to cpu_interrupt_requesttarget/sh4/cpu.c target/sh4/helper.c+2 -20 replies
46/73cris: convert to cpu_interrupt_requesttarget/cris/cpu.c target/cris/helper.c+4 -40 replies
47/73hppa: convert to cpu_interrupt_requesttarget/hppa/cpu.c+1 -10 replies
48/73lm32: convert to cpu_interrupt_requesttarget/lm32/cpu.c+1 -10 replies
49/73m68k: convert to cpu_interrupt_requesttarget/m68k/cpu.c+1 -10 replies
50/73mips: convert to cpu_interrupt_requesttarget/mips/cpu.c target/mips/kvm.c+5 -40 replies
51/73nios: convert to cpu_interrupt_requesttarget/nios2/cpu.c+1 -10 replies
52/73s390x: convert to cpu_interrupt_requesthw/intc/s390_flic.c target/s390x/cpu.c+2 -20 replies
53/73alpha: convert to cpu_interrupt_requesttarget/alpha/cpu.c+4 -40 replies
54/73moxie: convert to cpu_interrupt_requesttarget/moxie/cpu.c+1 -10 replies
55/73sparc: convert to cpu_interrupt_requesthw/sparc64/sparc64.c target/sparc/cpu.c+3 -30 replies
56/73openrisc: convert to cpu_interrupt_requesthw/openrisc/cputimer.c target/openrisc/cpu.c+3 -30 replies
57/73unicore32: convert to cpu_interrupt_requesttarget/unicore32/cpu.c target/unicore32/softmmu.c+2 -20 replies
58/73microblaze: convert to cpu_interrupt_requesttarget/microblaze/cpu.c+1 -10 replies
59/73accel/tcg: convert to cpu_interrupt_requestaccel/tcg/cpu-exec.c accel/tcg/tcg-all.c accel/tcg/translate-all.c+18 -110 replies
60/73cpu: convert to interrupt_requestqom/cpu.c+2 -20 replies
61/73cpu: call .cpu_has_work with the CPU lock heldinclude/qom/cpu.h+10 -20 replies
62/73cpu: introduce cpu_has_work_with_iothread_lockinclude/qom/cpu.h+34 -30 replies
63/73ppc: convert to cpu_has_work_with_iothread_locktarget/ppc/translate_init.inc.c+12 -40 replies
64/73mips: convert to cpu_has_work_with_iothread_locktarget/mips/cpu.c+3 -10 replies
65/73s390x: convert to cpu_has_work_with_iothread_locktarget/s390x/cpu.c+3 -10 replies
66/73riscv: convert to cpu_has_work_with_iothread_locktarget/riscv/cpu.c+4 -10 replies
67/73sparc: convert to cpu_has_work_with_iothread_locktarget/sparc/cpu.c+3 -10 replies
68/73xtensa: convert to cpu_has_work_with_iothread_locktarget/xtensa/cpu.c+3 -10 replies
69/73cpu: rename all_cpu_threads_idle to qemu_tcg_rr_all_cpu_threads_idlecpus.c+6 -40 replies
70/73cpu: protect CPU state with cpu->lock instead of the BQLcpus.c include/qom/cpu.h qom/cpu.c+225 -1050 replies
71/73cpus-common: release BQL earlier in run_on_cpucpus-common.c+5 -150 replies
72/73cpu: add async_run_on_cpu_no_bqlcpus-common.c include/qom/cpu.h+48 -50 replies
73/73cputlb: queue async flush jobs without the BQLaccel/tcg/cputlb.c+5 -50 replies

Reviews trailers per patch

All 73 patches have a Reviewed-by or Acked-by.

PatchRichard HendersonAlex BennéeDavid GibsonLaurent VivierPalmer DabbeltAlistair FrancisMark Cave-AylandPhilippe Mathieu-DaudéCornelia HuckDavid Hildenbrand
SeriesT-b
1/73R-b R-b
2/73R-b R-b
3/73R-b
4/73R-b R-b
5/73R-b R-b
6/73R-b R-b
7/73R-b R-b
8/73R-b R-b
9/73R-b R-b A-b
10/73R-b R-b
11/73R-b R-b
12/73R-b R-b R-b
13/73R-b R-b
14/73R-b R-b
15/73R-b R-b
16/73R-b R-b
17/73R-b R-b
18/73R-b A-b
19/73R-b R-b
20/73R-b R-b
21/73R-b R-b
22/73R-b R-b R-b
23/73R-b R-b
24/73R-b R-b R-b
25/73R-b R-b R-b
26/73R-b R-b R-b
27/73R-b R-b
28/73R-b R-b
29/73R-b R-b
30/73R-b R-b
31/73R-b R-b
32/73R-b R-b
33/73R-b R-b A-b R-b
34/73R-b R-b
35/73R-b R-b
36/73R-b R-b R-b R-b
37/73R-b R-b R-b
38/73R-b R-b
39/73R-b R-b
40/73R-b R-b
41/73R-b R-b
42/73R-b
43/73R-b
44/73R-b A-b
45/73R-b R-b
46/73R-b R-b
47/73R-b R-b
48/73R-b R-b
49/73R-b R-b
50/73R-b
51/73R-b R-b
52/73R-b R-b R-b
53/73R-b R-b
54/73R-b R-b
55/73R-b R-b R-b
56/73R-b R-b
57/73R-b R-b
58/73R-b R-b
59/73R-b R-b
60/73R-b R-b
61/73R-b R-b
62/73R-b R-b
63/73R-b A-b
64/73R-b
65/73R-b R-b
66/73R-b R-b R-b
67/73R-b A-b
68/73R-b
69/73R-b R-b
70/73R-b R-b
71/73R-b R-b
72/73R-b R-b
73/73R-b R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 10 reviewers.

Read the v7 thread

Cover letter [PATCH v7 00/73] per-CPU locks

v6: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg07650.html

All patches in the series have reviews now. Thanks everyone!

I've tested all patches with `make check-qtest -j' for all targets. The series is checkpatch-clean (just some warnings about __COVERITY__).

You can fetch the series from:
https://github.com/cota/qemu/tree/cpu-lock-v7

---
v6->v7:

- Rebase on master
- Add a cpu_halted_set call to arm code that wasn't there in v6

- Add R-b's and Ack's.

- Add comment to patch 3's log to explain why the bitmap is added there, even though it only gains a user at the end of the series.

- Fix "prevent deadlock" comments before assertions; use "enforce locking order" instead, which is more accurate.

- Add a few more comments, as suggested by Alex.

v6->v7 diff (before rebase) below.

Thanks,

Emilio
---

accel/tcg/cpu-exec.c +1 -1
index e4ae04f72c..a513457520 100644
@@ -435,7 +435,7 @@ static inline bool cpu_handle_halt_locked(CPUState *cpu)
             && replay_interrupt()) {
             X86CPU *x86_cpu = X86_CPU(cpu);
 
-            /* prevent deadlock; cpu_mutex must be acquired _after_ the BQL */
+            /* locking order: cpu_mutex must be acquired _after_ the BQL */
             cpu_mutex_unlock(cpu);
             qemu_mutex_lock_iothread();
             cpu_mutex_lock(cpu);
cpus.c +1 -1
index 4f17fe25bf..82a93f2a5a 100644
@@ -2062,7 +2062,7 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line)
 {
     QemuMutexLockFunc bql_lock = atomic_read(&qemu_bql_mutex_lock_func);
 
-    /* prevent deadlock with CPU mutex */
+    /* enforce locking order */
     g_assert(no_cpu_mutex_locked());
 
     g_assert(!qemu_mutex_iothread_locked());
include/qom/cpu.h +3 -1
index bb0729f969..726cb7b090 100644
@@ -322,7 +322,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.
- * @lock: Lock to prevent multiple access to per-CPU fields.
+ * @lock: Lock to prevent multiple access to per-CPU fields. Must be acquired
+ *        after the BQL.
  * @cond: Condition variable for per-CPU events.
  * @work_list: List of pending asynchronous work.
  * @halted: Nonzero if the CPU is in suspended state.
@@ -804,6 +805,7 @@ static inline bool cpu_has_work(CPUState *cpu)
     bool (*func)(CPUState *cpu);
     bool ret;
 
+    /* some targets require us to hold the BQL when checking for work */
     if (cc->has_work_with_iothread_lock) {
         if (qemu_mutex_iothread_locked()) {
             func = cc->has_work_with_iothread_lock;
target/i386/kvm.c +4 -0
index 3f3c670897..65a14deb2f 100644
@@ -3216,6 +3216,10 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
         qemu_mutex_lock_iothread();
     }
 
+    /*
+     * We might have cleared some bits in cpu->interrupt_request since reading
+     * it; read it again.
+     */
     interrupt_request = cpu_interrupt_request(cpu);
 
     /* Force the VCPU out of its inner loop to process any INIT requests