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: 13695205 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 358E21802CE for ; Wed, 12 Jun 2024 15:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718206514; cv=none; b=B/dtTWUGg6dq7BxwtNgSgNcppJovSBrr9NyZ5/ji6cm4m5JgmxxzTiSwqglIKAa5p2FkDBfZ54IRquLADunxaIZJleimEF3ks1eUxzxmSVle8cbX763dqjwyeX0g95GmERmUSv9odP+pc38vrt+BLaLuThkjC//3PkynOBzFmaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718206514; c=relaxed/simple; bh=Gp+mWVvr9wUgAmIqXusqFN5Gr9bo+FXiMQp7zjtc+2I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=E7mgfpnOjbPQxrcl3TneTuqqR0MnAlYE7DLZgw2xbGKaUdd9ZA6dSFmTEqZxArHDk/vToIkQcpq2fu32toqyrQHwuD7ddTdZ+TTJXjEEQca3GHhAqfHXsQgFshUswEyIu8vtWR9rCqF1twRNfK+AMk85TTGTlkd5fO724A+AekI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=LMsR1Dmp; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LMsR1Dmp" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-57cad4475e0so1063556a12.1 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=vger.kernel.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=LMsR1Dmp3BLjf4yZXdYGbvxwKtQjCYIitb3eZm4GpXjc1Edjlu10hIklxR97WGk8qN SlO6qdmmSNWg4hcd7G8pmeLGbr8I+wmj/1TyCFGAPkY75WX7yHDJ3jwSN52JQrppgoCG Gpee4SMhsgrnhMrPJXLa3BJ3c65vdEEqJKQCb3TuTfcfDM6obWj/ZGtV5NE9GnudxITa jkzzTWxkXLGr2Y+WwrU6TLJgVNdRylZa4p9unkfkdH2UcAfX1cwdp539SIs0yAs4uZoC pg0RilLJzW1PSSQo6vj/tlNGXopAlB3A/TiN9qihVxGhl/SVYNEdVLwba7p7aM6S3BEe g+0w== 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=dCKbUJSn4j1NlIYLizNBX5XCbve6oq7O6TQOqLNAhtvCl3IMqiROWE8SGhLyTpSDdy hNrStU5Mc+PN/NL4TP90Pob3SKKm1G/pyiVEsTn0dWYh6WBIs4Q/ELMSe0Z4WNs4fWOO tsr/CA8iOco+eC3OLZfWK19t4O7Iw4u8uZ4sVcUhsQkTtqx2Ne7Xxbk93om+2ZaokBrX Yf6PxYvDNK4Igz7mgDud11DQe0LAy1kT5SXqt8U4Vax8pKFlMJlDqvZ4P9G8LDRY5RMq rXqziu84qKnBfhSvUcSrXPp2PvxWqXVRWb/b3yS2Lt0c/JGsLK8SxmfjNFPI+fK5DF5Z Jqdg== X-Forwarded-Encrypted: i=1; AJvYcCUPbsvLBDlANAb60EOZ0HKkezSOCQWAatEXHqixsEyoC8Db68YJrE9mmY20RI7fRtFNJnkGyA2dcZr59UMexbKOIioG X-Gm-Message-State: AOJu0Yzav0e2A3xAU4I5ou2dv1qvAxK4luTrxX9rIQMXGLWmWXZDaDi4 kLFhdvc4p+XJ1ICtyYHy46D3rD7RutKhO3TtQaWcKwTUeDNPEEkl/JQtiGsSezY= X-Google-Smtp-Source: AGHT+IGsdtBPKwbZSHTfhU4XunHG/iE49yO4AX8fP+I2Sl9JpV6jgSRYC4qfT9uG5LgYQNMMgN9Q4w== 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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> --- 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()