From patchwork Mon Sep 25 14:48:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 726042 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2438437wrm; Mon, 25 Sep 2023 08:02:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHmwY1WeJIBS8IO6lHA30deKo1wNkZ+qtcQdTL4N7UhYCDCBlcQ6qWQZlGHcZz4sxj6N3B X-Received: by 2002:a0c:f051:0:b0:64f:4be7:b6c7 with SMTP id b17-20020a0cf051000000b0064f4be7b6c7mr5879442qvl.4.1695654142017; Mon, 25 Sep 2023 08:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695654141; cv=none; d=google.com; s=arc-20160816; b=ZzaOQOcXQWz0jDIvFa5L8iDDfREzZ8I2K0caXWB3duBGGofVT04NPpS3OZHE0eKXle O3+uWTfrFL4D5jn5X03XW4MORUFmYH9yq2afKa+WmFUHILgP5zkCc6YfOU81c5oodscG 4CAyi349t0efd1Bu2BO0Z/iUZKq+CB1OTh8IxZk6eZcPmwJLcv+zUVCUYVDyIc+6LPyl fVS/UvcGOQOgoVDTL0J/e+jI2Vdoqupbg+hfjJTIHBeZ4V2zD/qzTmtjzFX0Q0HkIt+c Yx25jfNITxs0Yb/WY3iit3rSMLvlefRHNs9ZTEfmddzN8QJVEeF3LlOLg+9H2oW0TaMj PztA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y3Mf9pXINv9MNziLLoU9Gq8z0X78btsM4rjGFmiQ41I=; fh=f1HG4YWa+ndoxgBhrv2wvoi5B5rsQCa0P0+M/9TAKns=; b=vhkOI7NMLZCp2NXfg0gMEqeTV8KZ1rcJtDHu0M7p+YwiyxI73w9wNLsWUw8Jyx8nro oQCb0CMAVGz/3wlL+Qu55bI6ecageKsLmhBniHljukdJMyoALo+vx7iDmWdvHayZ+2JA TeKUQocTz4Yr034snm3e4K7MvSnfK+yLY71iLoFhl095M+EUAyikq6hxshQrXtzld93A sS4mKli+gNiHGRLVHw9BI8kLJiSQjv3JA7gcNQtAo0tNnMxrNKUfIrASbrGzSffY2+Zm SpE7f15/ZwFtlAkbXbtVwISxJ7V4L1SP/48TTmq6tD6jeN5h0oW1uSSxiuhzFekz/Usc QiTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="u+F/DJ7q"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x15-20020a0ce0cf000000b006588d9d70a4si5597640qvk.483.2023.09.25.08.02.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Sep 2023 08:02:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="u+F/DJ7q"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkn3N-0000FH-6E; Mon, 25 Sep 2023 10:59:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkn35-0008KQ-5U for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:59:00 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkn2r-0002Ei-U2 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:58:55 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-405524e6769so26306285e9.1 for ; Mon, 25 Sep 2023 07:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695653924; x=1696258724; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y3Mf9pXINv9MNziLLoU9Gq8z0X78btsM4rjGFmiQ41I=; b=u+F/DJ7qlRZsnBL0Z1lVSZFqS3G03shccLStBwJcnNPogQ02GjWOXrfo1NqgHwDl4g 5DJWr0YtQMLKUCYLPH6DM1KWoJySXqbhzz0Yv1/kd6ZtjXTmhI3sBW/c1CoXVpl57MON RKgSSqgPxkrq52i61y3fX78wA+O/J6tG2Q+qHliT5jIWfNh+Qm5UApo7JsS6y2+dcIUM ECYy5m5buy9CM1KqXRzZsB41Cw0sU8yGilF6Wh9w0YeJp7k5x+2qkvAk9SBT1IHZFK9M dG36KnOYPWXCxRYbVeLqIBmDMor36/pWeqnk1Of4sHtP6ay59/PGYZjlKV/x00H3JrnM xAYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695653924; x=1696258724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y3Mf9pXINv9MNziLLoU9Gq8z0X78btsM4rjGFmiQ41I=; b=LJC6w8gTOs+8w6PVhRkxQ4Hy46dP1usaUfGm+FKsIGMbXxHq7qM04aV8L3kuoS71HO G0DJSXOFGF33h6lsvoevzI0+Ryzvuah215QWFLBK7Jhc3TjR+8iD+kexttv1ilfP/Z/e Vk9CuQkiq8H/ZqsrlHKA7ooG0fsI+hCl22XHwy1zv2+4KgLI1VdwdChr+E4IOZS4M8/8 7AJK1rImwFGlZm6xEYOM/oxX47SNvQqdBeRXGjO5UZOTnNR6T1Pa4rXC/cVYcT6XSxUX gcjXqXDMTBduVndNBu+Owd0ijqdwu7t026s8UXb/kyUuSS4WOrmQQ9uJq7xJFYZg4ypV j33w== X-Gm-Message-State: AOJu0Yz3xKKCn5qhuADuk3kee0PvglEyt7OZyPqp0OiDdccQ+OPJGbRm qv6aWEbQpvgT1yV9Vd6wbJ2nVA== X-Received: by 2002:a1c:4c12:0:b0:402:e68f:8a4f with SMTP id z18-20020a1c4c12000000b00402e68f8a4fmr5500650wmf.0.1695653923892; Mon, 25 Sep 2023 07:58:43 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id b12-20020a5d634c000000b0031773a8e5c4sm12054037wrw.37.2023.09.25.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:58:42 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B57851FFD5; Mon, 25 Sep 2023 15:48:58 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alistair Francis , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Marcin Juszkiewicz , John Snow , libvir-list@redhat.com, =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , qemu-s390x@nongnu.org, Song Gao , Daniel Henrique Barboza , Marcel Apfelbaum , Bastian Koppelmann , Liu Zhiwei , Weiwei Li , Nicholas Piggin , Radoslaw Biernacki , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Cleber Rosa , Paolo Bonzini , Mahmoud Mandour , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Richard Henderson , Bin Meng , Alexandre Iooss , Xiaojuan Yang , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Peter Maydell , qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Palmer Dabbelt , Ilya Leoshkevich , Laurent Vivier , Yoshinori Sato , Leif Lindholm , Beraldo Leal Subject: [RFC PATCH 30/31] plugins: add time control API Date: Mon, 25 Sep 2023 15:48:53 +0100 Message-Id: <20230925144854.1872513-31-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925144854.1872513-1-alex.bennee@linaro.org> References: <20230925144854.1872513-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Expose the ability to control time through the plugin API. Only one plugin can control time so it has to request control when loaded. There are probably more corner cases to catch here. Signed-off-by: Alex Bennée Message-Id: <20230519170454.2353945-8-alex.bennee@linaro.org> --- v2 - ifdef for SOFTMMU only - fix checkpatch warnings --- include/qemu/qemu-plugin.h | 19 +++++++++++++++++++ plugins/api.c | 28 ++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 2 ++ 3 files changed, 49 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..898385d92d 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -536,7 +536,26 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_op op, void *ptr, uint64_t imm); +/** + * qemu_plugin_request_time_control() - request the ability to control time + * + * This grants the plugin the ability to control system time. Only one + * plugin can control time so if multiple plugins request the ability + * all but the first will fail. + * + * Returns an opaque handle or NULL if fails + */ +const void *qemu_plugin_request_time_control(void); +/** + * qemu_plugin_update_ns() - update system emulation time + * @handle: opaque handle returned by qemu_plugin_request_time_control() + * @new_time_ns: time in nanoseconds + * + * This allows an appropriately authorised plugin (i.e. holding the + * time control handle) to move system time forward to @new_time_ns. + */ +void qemu_plugin_update_ns(const void *handle, int64_t new_time_ns); typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, diff --git a/plugins/api.c b/plugins/api.c index 5521b0ad36..a1d413dc2d 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -37,6 +37,7 @@ #include "qemu/osdep.h" #include "qemu/plugin.h" #include "qemu/log.h" +#include "qemu/timer.h" #include "tcg/tcg.h" #include "exec/exec-all.h" #include "exec/ram_addr.h" @@ -427,3 +428,30 @@ uint64_t qemu_plugin_entry_code(void) #endif return entry; } + +/* + * Time control + */ +#ifdef CONFIG_SOFTMMU +static bool has_control; +#endif + +const void *qemu_plugin_request_time_control(void) +{ +#ifdef CONFIG_SOFTMMU + if (!has_control) { + has_control = true; + return &has_control; + } +#endif + return NULL; +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ +#ifdef CONFIG_SOFTMMU + if (handle == &has_control) { + qemu_clock_advance_virtual_time(new_time); + } +#endif +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..91b882fecc 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -35,11 +35,13 @@ qemu_plugin_register_vcpu_tb_exec_cb; qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_request_time_control; qemu_plugin_reset; qemu_plugin_start_code; qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; qemu_plugin_tb_vaddr; qemu_plugin_uninstall; + qemu_plugin_update_ns; qemu_plugin_vcpu_for_each; };