From patchwork Wed Mar 13 10:55:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 780028 Delivered-To: patch@linaro.org Received: by 2002:adf:f741:0:b0:33e:7753:30bd with SMTP id z1csp112684wrp; Wed, 13 Mar 2024 03:56:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVOfdpvPs1pseyeTpQ/DFUxv11qOnFOg1CYWWOdFgY4bIIuNk6A7KiK+3F7YiaVpExCe3bUiCzzUYYc7xmqIsMl X-Google-Smtp-Source: AGHT+IGfUx637BCeU0X49xTmUYLnP9XDd3tR/pQ4XkfILs06U1U5K0DfnZnjMTOviqLCsnufCUVn X-Received: by 2002:a5b:b4b:0:b0:dcd:b624:3e55 with SMTP id b11-20020a5b0b4b000000b00dcdb6243e55mr1984676ybr.54.1710327397565; Wed, 13 Mar 2024 03:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710327397; cv=none; d=google.com; s=arc-20160816; b=0O/14Uj8qzrWSIAfnKCGSfYEZ5XoatrmnKA0dmDUdQuWvpK5A2H+RvgTgkyceMjPpu BR+HzCR2r2yhN2B2G9sxe368yVYBd8OH7qe7gmTn0PvjqzIZNVX2api4MHB3nQ9KWMIw K04nv30qFLR1KHoAs4Tg/URK7LWDvL8cnADpCboUAjmXDPLs+MjRd4SW//pwxL+4LPU5 oLGV2lpqwoIzC46aHlLRJXeyBdoUGauzbrZYi06WK6ZXncI9ds5aH9d9QxHQjbwmCcrd OZms9a54NnEk8ARBbymxMJ4Z4hATD5C3z6086joa08DgjsZ1c73PD8fPBGIxDTEge74K gwvA== 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=soYSMJfeLTvbBwxImuPxvWm5QbEE1JXCi8SjK5Hn4SE=; fh=SOx5jGRISimNYto+GAJnnbqozdA4y+bYXtSuueN6vdQ=; b=0xc+eAOFEDMIKWtZ0MpS+Fzlg1xKyxIHo02zpB2CCQJy3b4WgkMvHH+iNycniKaAvu Vk5ppuSboDBmU7zBPS4jHyGoS9DFirQxS46jIAxt9eaRum8B4/DjdYZvCcjF+5SBMdkV vZnOGSth27hHCL3PhXR3qxYvgdRiN40KxnBGc94sSH7xnYdoc9ZMDCaxLCK7j/6U+YfU c+gbvO0wpwSyoo+bsNgtmVpPt1zg2Varcf+TqNL1csKk/K1iv6pucbLb0VTb2ZGtcxFb +dAzNCDODAdXRmIM8k4HbWu3lKRPJQuybmizkn6KiVNn4dW9pQ/t8EDVNo3wyiDa65kH KDSw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HLQg16zC; 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 h11-20020ac8584b000000b0042ef395d52bsi9529815qth.257.2024.03.13.03.56.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Mar 2024 03:56:37 -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=HLQg16zC; 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 1rkMH2-0005TP-VW; Wed, 13 Mar 2024 06:55:52 -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 1rkMGw-0005Js-7k for qemu-devel@nongnu.org; Wed, 13 Mar 2024 06:55:47 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkMGq-0007BV-Gp for qemu-devel@nongnu.org; Wed, 13 Mar 2024 06:55:43 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33e82c720f8so6022927f8f.3 for ; Wed, 13 Mar 2024 03:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710327330; x=1710932130; 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=soYSMJfeLTvbBwxImuPxvWm5QbEE1JXCi8SjK5Hn4SE=; b=HLQg16zCAq2Cf15Um0tValJcl818D9x0mudZluzZSUN5R2log1KINrb1R6Mc8PXLrx cJ24uSwDTvaC8F0Ufqtp4so+Do82XlH2+HVuMGNPQs7Xpg/F9RiotTo7gfrVeTfFXTmc yMgDWnim+7Le4FzfysB6XXQB2GRgpNxlNFvi8tjEp7gGSfaDen+Ih4BDy02zz5SxRspP 0O05NN6jGf4KQEnaRXBSDQTgUqQFFDzVKqxVeENXeE/P1IFR8xueveO7+Ro++NX/2Bs5 Rp+3auUwDIgkloE8NlYptoLBuC/WJw6U6M9trM8OomWn9y2ppQlqjLsaBMr1oHwQpUXp De0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710327330; x=1710932130; 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=soYSMJfeLTvbBwxImuPxvWm5QbEE1JXCi8SjK5Hn4SE=; b=nY8O7t8cXndr65fyH4Wzdr35BtweIF5aRE77F8In3MYsZSkl/nq09l+o5Cg93x6laU F7iOOUwcGK0PAWlj7TwmVFZc6jCZa/xCHHD8DADbAsFrb4jl4POIDLLPhkf75akCXnee +ar0pb7MpfBCZDdUUq8KaqEZzOBUpbpjnjosEdq0Rce3tOIkzBlb3i1OMhRMJpJ+STdP hSyS1fTtn0i9mTshU1Ew7fCaM8YeD2DDu8cmRRd6XeSXh3Zo9n1QPXKdjlvT2F4avgtm 3neBzmjtz+0f7k+J0vNOd133BG/SWwITbNbctZ63BAouzwhlhR9VFuTPK/Pg5+nqrsy+ TcvQ== X-Gm-Message-State: AOJu0YxHUELJDSwQ3MmdWoOVOsEY4DNYwQ7CRaEPth5tqO0EgLdOoOKm 8FwgaDl5vAW+oLhC+LxMe8573MX8EeZ5S2PvT7XqJiTVljTfzMoleZIkNqjl3dnStGJ3LbOoKeI ifhs= X-Received: by 2002:a5d:4533:0:b0:33d:1f11:33c1 with SMTP id j19-20020a5d4533000000b0033d1f1133c1mr1431587wra.55.1710327330376; Wed, 13 Mar 2024 03:55:30 -0700 (PDT) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id w17-20020adfee51000000b0033e1be7f3d8sm11390338wro.70.2024.03.13.03.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 03:55:30 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexandre Iooss , Richard Henderson , Laurent Vivier , Thomas Huth , Pierrick Bouvier , Mahmoud Mandour , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [RFC PATCH 4/5] plugins: add time control API Date: Wed, 13 Mar 2024 14:55:03 +0400 Message-Id: <20240313105504.341875-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240313105504.341875-1-pierrick.bouvier@linaro.org> References: <20240313105504.341875-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x434.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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 From: Alex Bennée 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 --- include/qemu/qemu-plugin.h | 23 +++++++++++++++++++++++ plugins/api.c | 31 +++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 2 ++ 3 files changed, 56 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 337de25ece7..f2a0253e594 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -662,6 +662,29 @@ void qemu_plugin_register_vcpu_mem_inline_per_vcpu( qemu_plugin_u64 entry, 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() + * @time: time in nanoseconds + * + * This allows an appropriately authorised plugin (i.e. holding the + * time control handle) to move system time forward to @time. + * + * Start time is 0. + */ +void qemu_plugin_update_ns(const void *handle, int64_t time); + typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, diff --git a/plugins/api.c b/plugins/api.c index fdf6167655e..f8b2d09ad0c 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -39,6 +39,7 @@ #include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" +#include "qemu/timer.h" #include "tcg/tcg.h" #include "exec/exec-all.h" #include "exec/gdbstub.h" @@ -591,3 +592,33 @@ uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) } return total; } + +/* + * Time control + */ +static bool has_control; + +const void *qemu_plugin_request_time_control(void) +{ + if (!has_control) { + has_control = true; + return &has_control; + } + return NULL; +} + +static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data data) +{ + int64_t new_time = data.host_ulong; + qemu_clock_advance_virtual_time(new_time); +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ + if (handle == &has_control) { + /* Need to execute out of cpu_exec, so bql can be locked. */ + async_run_on_cpu(current_cpu, + advance_virtual_time__async, + RUN_ON_CPU_HOST_ULONG(new_time)); + } +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index aa0a77a319f..ca773d8d9fe 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -38,6 +38,7 @@ qemu_plugin_register_vcpu_tb_exec_cond_cb; qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_request_time_control; qemu_plugin_reset; qemu_plugin_scoreboard_free; qemu_plugin_scoreboard_find; @@ -51,5 +52,6 @@ qemu_plugin_u64_set; qemu_plugin_u64_sum; qemu_plugin_uninstall; + qemu_plugin_update_ns; qemu_plugin_vcpu_for_each; };