From patchwork Wed Jun 12 15:35:03 2024 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: 803476 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:e87:b0:35b:5a80:51b4 with SMTP id dz7csp852517wrb; Wed, 12 Jun 2024 08:36:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVby9r/Pg0G2525eY/i2Pch86Qyq2w91HHsNDBjfatKYv6kfTN1Qzgi9OOCyvWSXOAznmHERNISOWO/uEul0onc X-Google-Smtp-Source: AGHT+IFDc3Og4Fz3IW+LkCWtszKO4JIjSigTyVdq6I4C3leB+EZtEDea8w/tdwcddNCvTB89qF9q X-Received: by 2002:a05:6214:5889:b0:6b0:6671:86a with SMTP id 6a1803df08f44-6b1a7ad4be4mr20659396d6.48.1718206615101; Wed, 12 Jun 2024 08:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718206615; cv=none; d=google.com; s=arc-20160816; b=oFaEpzS5xwcwywBAbFN32LJVZ2W+eD2OG8FBPoimpoav6OH3fYFnQyQLanfr0tkJY5 ofoBluFD3XqoyrfHowSg3e2WjEdUdL1y7AMg7MkA+djaipgeZSQaPspzdTOr+GhK6t1L tXbpcGkQRFE1y75nEW3AAyQhQYooScO6BmC2gLCKNdrkk+FaC1gtV6p75LAlmwfxTBI5 61BQ2I6vsenUzhtCbHNEPN9T3IvqX1omHvpuKmI8qbkZT2ed/wyRT3c7bxELdnuvfYRy 5Hm35/WWU0ysE6M7kaL/F8/H0o4GJsKCIZet/H8iETUGnC8d41//g1dGW3kCwp26Lfi5 jN5A== 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=dsboB6lxAe+MtT/jZcZKahSTlUXC5/PD/o+7xcfjrRg=; fh=czkAeDwyirGU0fHfBYIxDl8vJdhA5eGOYVGOtFKrHIY=; b=RkuO0AjPogxhoLMM0hzKeyDQqIYysEYi0ZBbPRmdCBn6tayYC0ctUx4Pv/8DI9fzWN bA2lCmqKCJVymFmCOSAw7GxJfrMfJHZ1RNTy6p5LZIKN+hfUGLbR4Ogw9lJuW01AyXFS hjS8GYXABbqQBWnnRPG6VdWJHFPhi6ik68iCGZ7ErNvYOSQrEsO0/u9M0o3xhEkI4nul tWzJC2+QcZBHJu7t+q0y1tfB2SE9JmHVXdTEKG5T8Hos++QRtbViuqc7JFtX4t3AoSpg oPM0LPz50qTo3evATmoyIVBz+C7LPqbj9QWqFWSyFgxIgCLcGlC0aLbyxT8k50eqYlES pVdQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="kwAc7/MF"; 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-6b065ed1712si121076056d6.107.2024.06.12.08.36.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Jun 2024 08:36:55 -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="kwAc7/MF"; 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 1sHQ0M-0000dk-HD; Wed, 12 Jun 2024 11:35:18 -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 1sHQ0J-0000Pk-Oe for qemu-devel@nongnu.org; Wed, 12 Jun 2024 11:35:15 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sHQ0G-0004JZ-25 for qemu-devel@nongnu.org; Wed, 12 Jun 2024 11:35:15 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-57ca81533d0so1710410a12.0 for ; Wed, 12 Jun 2024 08:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718206509; x=1718811309; 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=dsboB6lxAe+MtT/jZcZKahSTlUXC5/PD/o+7xcfjrRg=; b=kwAc7/MF4LpOAlYar3KWi/8D0FBM7+q+5MCZmYhKtmzjw/foli6ksvrJtZ8Kna0d6p rhbC/yWGpeT6R3h2vhqxmihVCNxfkZ44DKDUu9T2PbLymuxFSI4RZYNG7kdmWGMzi/Ic wZu4Qb+c0mlVf7Gyda/EdIkavsd+ShwJcsjw/dksEr2T5/wbUcUr03MpmPE3ytgBHcH7 hShMTJJDxz031JdqvU+14i3U8fBVwAFhlrUBcqKf8aXRHvIxMtrEDXjme4o1ctBx6TdP BZX01DLYOohXWDizuKwNsrrTP/+ST6nUMTlSDRWlYLoyBptzz4NmhqRdkh1sz1M1CEoI kJLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718206509; x=1718811309; 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=dsboB6lxAe+MtT/jZcZKahSTlUXC5/PD/o+7xcfjrRg=; b=ChB0AnjIluEiz42i25PjBa3Jjzn0exXXwaJLXztxLW6TUqkSBrpZlPa+5TXYW7s342 R7BFlRhZRbR//dep26gP3u6XBN8DcoO7o0VxssZi9ONEAijtzBQAlM8OzjXlCfhm5AvI 1vVwW2s4apIF+jZMoAVjvSoM0lv4oiP7eXkEfaMDPeThWyogLOfoIxEuDP4SKVYbDFZZ noePiLjE6oW3CoGSadG5iyL8eEziQpYiC4AWBKZaRWQ0tP+c2mRFWeoppdFgHyqvZpIg Rd2Zp3j350j9MewLtIJaADBA2ac/cbFC2Rhzds8+5S3eDNPBgsHyYqu8pl4suS3y5L2y rvzA== X-Gm-Message-State: AOJu0YzpkCL1EuX7Na8kPo/LadBiG3vKT304BEXfHrMDY2p8hbzViVKV O3W2Htjba3XEpD+PTRG+/roCRYShaYpCFbtfqoCLQG/FLaSF22AxxKFcEg9hT+k= X-Received: by 2002:a05:6402:1650:b0:57c:934f:4cae with SMTP id 4fb4d7f45d1cf-57cb4b99914mr28772a12.1.1718206509616; Wed, 12 Jun 2024 08:35:09 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c960e677asm2815309a12.62.2024.06.12.08.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 08:35:09 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 93B765F93F; Wed, 12 Jun 2024 16:35:08 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Ilya Leoshkevich , Daniel Henrique Barboza , Marcelo Tosatti , Paolo Bonzini , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mark Burton , qemu-s390x@nongnu.org, Peter Maydell , kvm@vger.kernel.org, Laurent Vivier , Halil Pasic , Christian Borntraeger , Alexandre Iooss , qemu-arm@nongnu.org, Alexander Graf , Nicholas Piggin , =?utf-8?q?Alex_Benn=C3=A9e?= , Marco Liebel , Thomas Huth , Roman Bolshakov , qemu-ppc@nongnu.org, Mahmoud Mandour , Cameron Esfahani , Jamie Iles , "Dr. David Alan Gilbert" , Richard Henderson Subject: [PATCH 4/9] sysemu: add set_virtual_time to accel ops Date: Wed, 12 Jun 2024 16:35:03 +0100 Message-Id: <20240612153508.1532940-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240612153508.1532940-1-alex.bennee@linaro.org> References: <20240612153508.1532940-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x533.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=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 We are about to remove direct calls to individual accelerators for this information and will need a central point for plugins to hook into time changes. From: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Pierrick Bouvier Signed-off-by: Alex Bennée Message-Id: <20240530220610.1245424-2-pierrick.bouvier@linaro.org> Reviewed-by: Richard Henderson --- include/sysemu/accel-ops.h | 18 +++++++++++++++++- include/sysemu/cpu-timers.h | 3 ++- ...et-virtual-clock.c => cpus-virtual-clock.c} | 5 +++++ system/cpus.c | 11 +++++++++++ stubs/meson.build | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) rename stubs/{cpus-get-virtual-clock.c => cpus-virtual-clock.c} (68%) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index ef91fc28bb..a088672230 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -20,7 +20,12 @@ typedef struct AccelOpsClass AccelOpsClass; DECLARE_CLASS_CHECKERS(AccelOpsClass, ACCEL_OPS, TYPE_ACCEL_OPS) -/* cpus.c operations interface */ +/** + * struct AccelOpsClass - accelerator interfaces + * + * This structure is used to abstract accelerator differences from the + * core CPU code. Not all have to be implemented. + */ struct AccelOpsClass { /*< private >*/ ObjectClass parent_class; @@ -44,7 +49,18 @@ struct AccelOpsClass { void (*handle_interrupt)(CPUState *cpu, int mask); + /** + * @get_virtual_clock: fetch virtual clock + * @set_virtual_clock: set virtual clock + * + * These allow the timer subsystem to defer to the accelerator to + * fetch time. The set function is needed if the accelerator wants + * to track the changes to time as the timer is warped through + * various timer events. + */ int64_t (*get_virtual_clock)(void); + void (*set_virtual_clock)(int64_t time); + int64_t (*get_elapsed_ticks)(void); /* gdbstub hooks */ diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h index d86738a378..7bfa960fbd 100644 --- a/include/sysemu/cpu-timers.h +++ b/include/sysemu/cpu-timers.h @@ -96,8 +96,9 @@ int64_t cpu_get_clock(void); void qemu_timer_notify_cb(void *opaque, QEMUClockType type); -/* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface */ +/* get/set VIRTUAL clock and VM elapsed ticks via the cpus accel interface */ int64_t cpus_get_virtual_clock(void); +void cpus_set_virtual_clock(int64_t new_time); int64_t cpus_get_elapsed_ticks(void); #endif /* SYSEMU_CPU_TIMERS_H */ diff --git a/stubs/cpus-get-virtual-clock.c b/stubs/cpus-virtual-clock.c similarity index 68% rename from stubs/cpus-get-virtual-clock.c rename to stubs/cpus-virtual-clock.c index fd447d53f3..af7c1a1d40 100644 --- a/stubs/cpus-get-virtual-clock.c +++ b/stubs/cpus-virtual-clock.c @@ -6,3 +6,8 @@ int64_t cpus_get_virtual_clock(void) { return cpu_get_clock(); } + +void cpus_set_virtual_clock(int64_t new_time) +{ + /* do nothing */ +} diff --git a/system/cpus.c b/system/cpus.c index f8fa78f33d..d3640c9503 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -229,6 +229,17 @@ int64_t cpus_get_virtual_clock(void) return cpu_get_clock(); } +/* + * Signal the new virtual time to the accelerator. This is only needed + * by accelerators that need to track the changes as we warp time. + */ +void cpus_set_virtual_clock(int64_t new_time) +{ + if (cpus_accel && cpus_accel->set_virtual_clock) { + cpus_accel->set_virtual_clock(new_time); + } +} + /* * return the time elapsed in VM between vm_start and vm_stop. Unless * icount is active, cpus_get_elapsed_ticks() uses units of the host CPU cycle diff --git a/stubs/meson.build b/stubs/meson.build index f15b48d01f..772a3e817d 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -29,7 +29,7 @@ endif if have_block or have_ga stub_ss.add(files('replay-tools.c')) # stubs for hooks in util/main-loop.c, util/async.c etc. - stub_ss.add(files('cpus-get-virtual-clock.c')) + stub_ss.add(files('cpus-virtual-clock.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('graph-lock.c')) if linux_io_uring.found()