From nobody Mon Nov 25 07:44:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717106872; cv=none; d=zohomail.com; s=zohoarc; b=IiZz5gSvfYGAhqpt21PPAsCPwvK/vX3V62Xg/Waqox/wz1zmyQQCUxvBfjiY6C3LhccLmUeIcWBXl6TVgDBS6oWn32M9M8GuvfRHIFF4es1qApnRngqtr9y2JoZf1eNXFkh7OLeYePm7acJOgqAEqyBfn/nQn39WuC/WZhs5Uds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717106872; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=V0eAnEgvAW0o/NF4J1A+axOTDsU9ayygb7e+nKl6WyIxiTLxINW65x7aq6PkF32NnC3YDVKtzSAB/rNPDupL5dVQGEub+frRIcQouEW9jTFm+3AxsYLaJxYAa67tM9ZHsTESphzhUGAdX+3n5FSFRmmtyl3v1YUc3COjmQXa/iU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717106872019663.2662423801897; Thu, 30 May 2024 15:07:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCnuj-0007JQ-1q; Thu, 30 May 2024 18:06:26 -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 1sCnuf-0007IN-DI for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:21 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnud-0005CS-AN for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:20 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1f6262c0a22so5284325ad.1 for ; Thu, 30 May 2024 15:06:17 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106775; x=1717711575; 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=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=Pm2eh5lCD9p8QPEBbYWdh9t+NKmd2GzPG7Ocx1+USyLnQrGruRwa7qRat+VpBYqmN6 1aOEQkB8WrE1cTTs3wVUgDJvi8uvy+pcJv/o8Wgs9p69q1/29czYFSShTBD5eOW7jhjV Nw1irKV85k7Ae8aa8Xttdkr2GQuWM7ZmJQl/S08LqKrnGgZqEstSU62mchVD7832ZVRm ufkt3shshalZ/zKHMPPMnhWfeQ3IGOWLdyfJjQ439t09mSSNMxeIPNa/QENcK/97G2RO b1RwPF5eehal6hUSKSfWth4OUUSnfW3VL9sG3Hr65yjsWRzmEHQ7mhy4yGwgYXsj9B9A ho+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106775; x=1717711575; 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=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=K69IpgFHQolxwlvt2yz+9MX/vTFqMf2YIwsnESm/5FkrQjT9A7w9b3/0YiPtUOD3MB kfMuWY9RhjzsZwWZDRGhzZS6+X6Zzv1021aio69jW1cAxGqzHZdY1gudkd+eUuKYFiJB hxmMUDpWeg40nNn898HD+2qC5WRzRRiUf6NsvLQiCZYhUWjk9Hn2ijagCo6ote0MxqMf FEuYisuGicJYUbYmoG4MQw/zNp3BOFiXSjw7p23WriX2kgmlqHoDXpjCmN1o7906OpEQ 2tv5K1NRt3oCcqUUhUgiHbmvYd+lnIIJjY+FUOazic3hhWPiu1BGmyOxXaC3vp7y/WH7 GUNg== X-Gm-Message-State: AOJu0YwzWGqJhXElf34WonwzS+rKB/BzZ8rvV/FD4Nm9xrbzxXQmOXei chPA0KGftL4OegHRpPZ1TYMZbgjwHoMjBhQV45PcLf8z0BUtgj3P3bn+iisWUh+XOYYSoDq0Kar mBK8= X-Google-Smtp-Source: AGHT+IFJgq7IHkYgaMq+ZY9xjZiNSxP1WocFM5EPYdFKpLlJT88A2pEGM7b6yzZxiFY92wRf+PAB1A== X-Received: by 2002:a17:903:2409:b0:1f6:846:69a1 with SMTP id d9443c01a7336-1f61be7b12emr45302475ad.20.1717106775185; Thu, 30 May 2024 15:06:15 -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=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/6] sysemu: add set_virtual_time to accel ops Date: Thu, 30 May 2024 15:06:05 -0700 Message-Id: <20240530220610.1245424-2-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x629.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717106872153100001 From: Alex Benn=C3=A9e 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=C3=A9e Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier --- include/sysemu/accel-ops.h | 18 +++++++++++++++++- include/sysemu/cpu-timers.h | 3 ++- ...et-virtual-clock.c =3D> 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 =3D> cpus-virtual-clock.c} (68%) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index ef91fc28bbd..a0886722305 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) =20 -/* 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 { =20 void (*handle_interrupt)(CPUState *cpu, int mask); =20 + /** + * @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); =20 /* gdbstub hooks */ diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h index d86738a378d..7bfa960fbd6 100644 --- a/include/sysemu/cpu-timers.h +++ b/include/sysemu/cpu-timers.h @@ -96,8 +96,9 @@ int64_t cpu_get_clock(void); =20 void qemu_timer_notify_cb(void *opaque, QEMUClockType type); =20 -/* 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); =20 #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 fd447d53f3c..af7c1a1d403 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 f8fa78f33d4..d3640c95030 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -229,6 +229,17 @@ int64_t cpus_get_virtual_clock(void) return cpu_get_clock(); } =20 +/* + * 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 c= ycle diff --git a/stubs/meson.build b/stubs/meson.build index 3b9d42023cb..a1deafde08c 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -28,7 +28,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() --=20 2.39.2