From nobody Thu Nov 6 10:38:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154048847546740.725848684387984; Thu, 25 Oct 2018 10:27:55 -0700 (PDT) Received: from localhost ([::1]:56042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjQA-0003FO-WB for importer@patchew.org; Thu, 25 Oct 2018 13:27:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKh-0006hu-Eg for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKg-0000OT-4k for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37891) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKc-0000Dc-JC for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id AA3BC2222E; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:17 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 44BD8E4074; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=VVLOs12hxAzHgeFEt+gfeG+nAaTZ5tl4TIusAXlKp4Q=; b=Djk03 IYBmgLgdBxiLNiHUXl52l9QKljDyP8x3Bt/7NF3W814LrpCSyWyRMrZmEu41S7eK gUHwRMeONKj4gbu8dVP0vHq3f+qB73+vrtLZEVp9Eu9JngMmfsHfkXfY/9lgAWr3 AY98DT3BRwTdVw2the9NWso6tav8mk4I7qq9e0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=VVLOs12hxAzHgeFEt+gfeG+nAaTZ5 tl4TIusAXlKp4Q=; b=XSHSvgRdEfhp2QBLh5QZzWoQklmktgVzs25VAkiQHkf/e w4+nGF1oMqkyiYgwXLeFQ0V1h4Kd6lInF7FnftECQOJtLiM/o0NG7ux7GNAG/OVj hX1rDqafME58etKI3g7ar/s39cPUCdD/1iG6MD0BLGSuEiOcEKAk0xxZgaQ7Rfy6 7LCo8dTE89KEY50LEVYIbzOFzbWyFF5T4BvtJqSFNCmD0WGeFOLM6qhF/6qzo/LC aj+9hhBPDcbKfYPw3UNBoYo6rOE14HCIaLnjcbMbIMfpoIJuba3iLUIjzfaQQzht U9OPLnjh5t+zqc6A2xgZEqT/ne2AHxUoZzPPQO/vQ== X-ME-Sender: X-ME-Proxy: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:54 -0400 Message-Id: <20181025172057.20414-46-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 45/48] plugin: lockstep execution support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Emilio G. Cota --- include/qemu/plugin-api.h | 7 +++++++ include/qemu/plugin.h | 5 +++++ cpus.c | 1 + plugin.c | 35 +++++++++++++++++++++++++++++++++++ qemu-plugins.symbols | 3 +++ 5 files changed, 51 insertions(+) diff --git a/include/qemu/plugin-api.h b/include/qemu/plugin-api.h index 076353a2d2..5062e20e08 100644 --- a/include/qemu/plugin-api.h +++ b/include/qemu/plugin-api.h @@ -227,6 +227,13 @@ typedef int64_t (*qemu_plugin_clock_func_t)(void); bool qemu_plugin_register_virtual_clock(qemu_plugin_id_t id, qemu_plugin_clock_func_t clock); =20 +void qemu_plugin_enable_lockstep_execution(void); + +void qemu_plugin_register_lockstep_cb(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb); + +void qemu_plugin_end_time_slice(void); + /* returns -1 in user-mode */ int qemu_plugin_n_vcpus(void); =20 diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 617161329f..c19071bdbe 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -58,6 +58,7 @@ enum qemu_plugin_event { QEMU_PLUGIN_EV_VCPU_RESUME, QEMU_PLUGIN_EV_VCPU_SYSCALL, QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, + QEMU_PLUGIN_EV_LOCKSTEP, QEMU_PLUGIN_EV_FLUSH, QEMU_PLUGIN_EV_ATEXIT, QEMU_PLUGIN_EV_MAX, @@ -194,6 +195,7 @@ void qemu_plugin_atexit_cb(void); =20 void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr); int64_t plugin_get_clock(void); +void plugin_lockstep_cb(void); =20 #else /* !CONFIG_PLUGINS */ =20 @@ -237,6 +239,9 @@ static inline void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr) { } =20 +static inline void plugin_lockstep_cb(void) +{ } + int64_t plugin_get_clock(void); =20 #endif /* !CONFIG_PLUGINS */ diff --git a/cpus.c b/cpus.c index a446632a5c..8f490d1b11 100644 --- a/cpus.c +++ b/cpus.c @@ -1359,6 +1359,7 @@ static void lockstep_check_stop(CPUState *cpu) /* wake up all waiting cpus */ lockstep_ongoing_wakeup =3D true; n_lockstep_running_cpus =3D n_lockstep_cpus; + plugin_lockstep_cb(); qemu_mutex_unlock(&lockstep_lock); cpu_mutex_unlock(cpu); for (i =3D 0; i < n_lockstep_cpus; i++) { diff --git a/plugin.c b/plugin.c index 291767f2bb..117f303249 100644 --- a/plugin.c +++ b/plugin.c @@ -472,6 +472,7 @@ static void plugin_cb__simple(enum qemu_plugin_event ev) =20 switch (ev) { case QEMU_PLUGIN_EV_FLUSH: + case QEMU_PLUGIN_EV_LOCKSTEP: QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_simple_cb_t func =3D cb->f.simple; =20 @@ -1043,6 +1044,40 @@ int64_t plugin_get_clock(void) } #endif =20 +/* + * We manage the CPU state changes; the plugin will control the length of = the + * execution windows. + */ +void qemu_plugin_enable_lockstep_execution(void) +{ +#ifdef CONFIG_USER_ONLY + abort(); +#else + cpu_lockstep_enable(); +#endif +} + +void qemu_plugin_end_time_slice(void) +{ +#ifdef CONFIG_USER_ONLY + abort(); +#else + g_assert(current_cpu); + cpu_lockstep_request_stop(current_cpu); +#endif +} + +void qemu_plugin_register_lockstep_cb(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_LOCKSTEP, cb); +} + +void plugin_lockstep_cb(void) +{ + plugin_cb__simple(QEMU_PLUGIN_EV_LOCKSTEP); +} + static void __attribute__((__constructor__)) plugin_init(void) { int i; diff --git a/qemu-plugins.symbols b/qemu-plugins.symbols index 93587b07e1..a3268a40c7 100644 --- a/qemu-plugins.symbols +++ b/qemu-plugins.symbols @@ -1,5 +1,8 @@ { qemu_plugin_uninstall; + qemu_plugin_enable_lockstep_execution; + qemu_plugin_end_time_slice; + qemu_plugin_register_lockstep_cb; qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_exit_cb; qemu_plugin_register_vcpu_idle_cb; --=20 2.17.1