From patchwork Thu May 30 22:06:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800212 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448110wrw; Thu, 30 May 2024 15:07:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWBQpTkkSjPxLhrG3jdGuW+1pRG9lm0yakGmeMK16nnyqmmDALTTq6zutc5djSnUcJ6S7vjifE6+Ty0Rv5viFSq X-Google-Smtp-Source: AGHT+IFccFR+gSJ0wjceD9ey3g1EBudwUncOZOQZTOfm5hhBo/nPz2uDoc+J3II9v50qTr7VhBO9 X-Received: by 2002:a05:6214:44a1:b0:6ad:62a2:4458 with SMTP id 6a1803df08f44-6aecd4cbabamr4765326d6.30.1717106847737; Thu, 30 May 2024 15:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106847; cv=none; d=google.com; s=arc-20160816; b=D2XgcQMUhTjiAQ0NTVypWYY3VnAQfUnlRBD0hnISc2wBzUGxvKxVpw8VVD16Xg/OCI UAtH1Np6Lq7W8sGKTQDU7DuGbqoaac+74WruP3CRkzCsFX8K914FghTB0RSXp+W4q/KA XQztYrL73I4mnfuYShTM0qo2qYY9iCnb/qG1u9FjvOjVW75Gk//7nrqzNw5KAzZKtmHH v7fZBiNsTHBGDGsUn1Tzl8qUy9lTSBhInca2lGnfVWY7mBEdhXiPcJud6gKvnrf5oPYO 9HF4BbSGTumfHEBKeTF5tCB/kN5+gGu2la79Zn8pUi/yU0Peq54BYa4UOLn7fdMbVz1U GuBQ== 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=Ps9gGFVUmKjmwMVRPVORIGLlgHUtsDCtUukvrncmBDcBK58jViz3NJsE25BTLmLSZ3 XE0EsGYUmeAIbrrgcJriPErqTol9YdgZ49S1C4Z51X/QADaQi7Tc0IMloV2Apyq9zEtj LVMidvPiUdqEAWeEeVmN97CC0L8bHzJnw+wOy62A+abh/1e+16ljyeDmBOlP5JzcJxSC 1/5Yv7hmiiuLnEEwFSHIj/gDyPrQhLYmDmotM3SAzDVHFQe3VdNOIKoSPWdi3aiqfW78 bWeFRFex6tsbFiUYs6gc60UvcpanQPwF6zaWyay30glk0UtPjrGlTYCeDa3J5EUHKpW1 9H6g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZEeT0b7m; 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 6a1803df08f44-6ae4b43ec6csi6023156d6.574.2024.05.30.15.07.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:27 -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=ZEeT0b7m; 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 1sCnuo-0007Kx-49; Thu, 30 May 2024 18:06:30 -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 1sCnul-0007Js-7N for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:27 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnui-0005EC-Vf for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:26 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1f48e9414e9so12617225ad.0 for ; Thu, 30 May 2024 15:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106781; x=1717711581; 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=ZEeT0b7mpooBMllfEc1/ONnb9aRY9RZqLznJIjbWNGyNNIplbMzO7RgtZErCDO/edS k5mcbInnuaglirtClHxx3rc3e/VmM2783E3Dwf3cHurOw4Uc5Q+FFHd9z0jMDKRfhEGq yivCmRP50DR8anfFyFDIGLnFOrJCoLBJjYqcaQQtt4tsrRKSE5dOkEEq9gxzRRo3xXsB vYbnbspUNku+etwEbIiHwJX+t5lDwzDc+aS94O5OgSUZ41CLNTIvfA+/J3nZs1oUUFj7 ItwmjEhvs1sVw0traBI4XIyI+ZGJ+PB+98806TFoQq6jL09OBsCpFdxJz0QVP7D0Urdp 389g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106781; x=1717711581; 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=opgSHlIhb6BG9tilGqhXJR12UyyY0DWIxUYyb4j4GTCBKDQeBSP30bT14GjuE6wWY2 Xd39WNHRi4KdWK5AgIAvtCQUjHgctKfjbO3R1jYKPdOS9Zst+nemxchd6aKNJAN0v7sH FvHXyhxJd8ZBsP3K0gMAd9EbgahGUtegSTW6Y6m0+7wXRVU74vz/b9vPDmJJ4DLzKa/v gXUOcx0Efxskaao+1n+eaZuvTOk+h3m3WR+4ub8YnVnb2zEgTSLcwZ+CyUp9+Ldy6epu 6iKcixaLbdco6ou64Mkovs0pC0tT1cdxFts1nrHObd+eq8k1sjDnS4P+H1ZuMQBh4GeU pisQ== X-Gm-Message-State: AOJu0YypQPNaLPJbVhRAFr11amFKd4QQx6066gQvQ0mkxjvocEjaaNzj 5kCHH5V2zI1/ue7sisHhiG5rdLeHXbIjJF8vs66xkSnSRLjjwUO4FawgrkRTqCrP9ReJIlMk/MJ AEEo= X-Received: by 2002:a17:902:e5d1:b0:1f3:620:c92 with SMTP id d9443c01a7336-1f6359934d1mr3142845ad.7.1717106781416; Thu, 30 May 2024 15:06:21 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323dde39sm2732615ad.167.2024.05.30.15.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:20 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 5/6] plugins: add time control API Date: Thu, 30 May 2024 15:06:09 -0700 Message-Id: <20240530220610.1245424-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530220610.1245424-1-pierrick.bouvier@linaro.org> References: <20240530220610.1245424-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x636.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. From: Alex Bennée Signed-off-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- 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 95703d8fec1..80b1637cede 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -661,6 +661,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 5a0a7f8c712..26822b69ea2 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" @@ -583,3 +584,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; };