Received: from eggs.gnu.org ([2001:4830:134:3::10]:41288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfP77-0006sO-R0 for qemu-devel@nongnu.org; Thu, 01 Sep 2016 06:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bfP72-0003Rm-PB for qemu-devel@nongnu.org; Thu, 01 Sep 2016 06:20:52 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33385) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfP72-0003Ri-HY for qemu-devel@nongnu.org; Thu, 01 Sep 2016 06:20:48 -0400 Received: by mail-wm0-x244.google.com with SMTP id w207so7697082wmw.0 for ; Thu, 01 Sep 2016 03:20:48 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 1 Sep 2016 12:20:15 +0200 Message-Id: <1472725227-10374-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v6 00/12] cpu-exec: Safe work in quiescent state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Sergey Fedorov , Sergey Fedorov , "Emilio G. Cota" This is not the code I promised at the beginning of the week. It's better, and not only in that this one works. :) Instead of reinventing the wheel and using the new wheel for linux-user's start_exclusive/end_exclusive, the linux-user/ code is moved to cpus-common.c and reused as the synchronization mechanism behind async_safe_run_on_cpu. The code works and actually satisfies our needs very well. The only disadvantage is that safe work items will run with a mutex taken; the mutex fits decently in QEMU's hierarchy however, sitting between the BQL and the tb_lock. For performance, the last patch changes it to avoid condition variables in the fast path. (There are still two memory barriers; if desired they could be merged with the ones in rcu_read_lock/rcu_read_unlock). I am including a formal model of the algorithm; together with new documentation in include/qom/cpu.h, it accounts for most of the added lines of code. Still, it is completely optional. Paolo Alex Bennée (1): cpus: pass CPUState to run_on_cpu helpers Paolo Bonzini (5): cpus-common: move CPU list management to common code cpus-common: move exclusive work infrastructure from linux-user cpus-common: always defer async_run_on_cpu work items cpus-common: Introduce async_safe_run_on_cpu() cpus-common: lock-free fast path for cpu_exec_start/end Sergey Fedorov (6): cpus: Move common code out of {async_, }run_on_cpu() cpus: Rename flush_queued_work() linux-user: Use QemuMutex and QemuCond linux-user: Add qemu_cpu_is_self() and qemu_cpu_kick() cpus-common: move CPU work item management to common code tcg: Make tb_flush() thread safe Makefile.target | 2 +- bsd-user/main.c | 30 +---- cpu-exec.c | 12 +- cpus-common.c | 314 +++++++++++++++++++++++++++++++++++++++++++++ cpus.c | 99 +------------- docs/tcg-exclusive.promela | 224 ++++++++++++++++++++++++++++++++ exec.c | 30 +---- hw/i386/kvm/apic.c | 3 +- hw/i386/kvmvapic.c | 6 +- hw/ppc/ppce500_spin.c | 31 ++--- hw/ppc/spapr.c | 6 +- hw/ppc/spapr_hcall.c | 17 +-- include/exec/cpu-all.h | 4 + include/exec/cpu-common.h | 2 + include/exec/exec-all.h | 11 -- include/exec/tb-context.h | 2 +- include/qom/cpu.h | 95 +++++++++++++- kvm-all.c | 21 +-- linux-user/main.c | 130 ++++++------------- target-i386/helper.c | 19 ++- target-i386/kvm.c | 6 +- target-s390x/cpu.c | 4 +- target-s390x/cpu.h | 7 +- target-s390x/kvm.c | 98 +++++++------- target-s390x/misc_helper.c | 4 +- translate-all.c | 38 ++++-- vl.c | 1 + 27 files changed, 814 insertions(+), 402 deletions(-) create mode 100644 cpus-common.c create mode 100644 docs/tcg-exclusive.promela -- 2.7.4