From patchwork Wed Mar 13 10:55:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 780024 Delivered-To: patch@linaro.org Received: by 2002:adf:f741:0:b0:33e:7753:30bd with SMTP id z1csp112368wrp; Wed, 13 Mar 2024 03:55:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWyXO7wMpW8JV+fJULEhWJQ3ny2UGY/4dfa39lcFcPwwgfNdTKT0WvqP31zmbNJ4IImp7NqMuzWAfVCdK8FxdV5 X-Google-Smtp-Source: AGHT+IEhnWH00U0Vw1DMg84/hXqyjUFG4nwynIWFPV/M9Lkp8v8azfxRARy+PtpbcvjgWUnpw4GZ X-Received: by 2002:a05:620a:4711:b0:788:4ca4:7385 with SMTP id bs17-20020a05620a471100b007884ca47385mr4556836qkb.0.1710327341811; Wed, 13 Mar 2024 03:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710327341; cv=none; d=google.com; s=arc-20160816; b=R0uKm3ZpSYQyUv7VIkF6nz8r7kfLRgiCWsi6cK4o0uMc9CP7tOWb8Zzyb9NLgXbxJZ PCNyP2GCxz9nTpcZ1I9tjle2dRAvmat862QPqTh0wYkju11l2JEnWhRHxNMAJqtUCvpP mChfFLER0a5ruO2HERP6O7ZVDRQsuKbjVs2kWtN1wZ8bVCfDUYa2zn4MIX//suP7XvNk 2N9sqVBGOPwnf5IZzJhpjkgjL0h6k2KAmRbjcW3aTaE7YL0hNIwlxYImYXj7f6MiddnR SJGNBMFGWVdOeiD47IrRi4ELBoS0rkvJ4UZjD0U6YnA9ZZt3srU0s2R3ZJo0eryfEhS1 dXoQ== 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=5oT1XKXBFQsUGk4QG2qYw4iHv7mWal+0jdHBO1XvE/8=; fh=fsg4xfmjE5p4XOolzPqTZCZjTSVL+V5r+PL/27ikWVg=; b=r60/wvRW04IAFJ5ldmWKlG5anppZ3fPlK0vOc3MPIjOyQsaP9R+habgxOSpnKThNWv mzZKNR6vvrnoOhnltBDJjjvvj/aqN8H0kH4671kTKw9YitVZywN+cguNgL2dcm8qjhII G8Hc+yQhE1AMnKW4pasC0FPrjWmMNWtKkZU5oj2kBggsrEuIZT1W9NotklmxcCHTIANr LXu+GChQammlELWpvVIKQ2C8HEcYxR9HGtLr3bZmUs6DR9b+qfyfZHyaEtlPMyZO1VFM TbwiXX7DVv0FRRtOO8ISrZGVmArLz4foIUjWPkutIHNleET7wl3uAs5UpPXn2S487Nkd eXfQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VpaSVLka; 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 j20-20020a05620a0a5400b00788462cf110si9221525qka.618.2024.03.13.03.55.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Mar 2024 03:55:41 -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=VpaSVLka; 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 1rkMGj-0005CC-Js; Wed, 13 Mar 2024 06:55:33 -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 1rkMGb-00059F-VU for qemu-devel@nongnu.org; Wed, 13 Mar 2024 06:55:26 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkMGa-000796-20 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 06:55:25 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-513c847c24dso610598e87.1 for ; Wed, 13 Mar 2024 03:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710327321; x=1710932121; 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=5oT1XKXBFQsUGk4QG2qYw4iHv7mWal+0jdHBO1XvE/8=; b=VpaSVLkaOmbmm7LsPaZYn6MVTvDU1Mv73nm/9clRz68mIAeuy8Jm/Jjjw7Wydilsl+ KtrOeQN1uu6POuT6fOzXxE0LlqsatV9kZkMhk84U/Dq3oy7dHqAy6NCcmw2Ynxynsa/S MQZYTCcG8YVzIcXweCm10bqmvcCYRCPfdH06yA25HQzudCpc6c7KmhnCHb4hfeFmnhdJ vMHfZyJny2ZhVM+9aQCkck26uxsx839ekEKjasHRCdNX6IcyQOFSD2abqPMrW9KV3Zh3 7bUuOlh+9U46KsBdc/xMTFD+cfqur6qRLxb9np4XI6fy5rg0HBcMEuaIqYLRNunR/keb kJ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710327321; x=1710932121; 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=5oT1XKXBFQsUGk4QG2qYw4iHv7mWal+0jdHBO1XvE/8=; b=Sf07XxGJwMadPgFfTCdRoba5NI4fS0tQBhdc7xtdbwbD9HmzJLoMXFiuZXbYgHXD+M +5cB4mLN1Cxpbczt8aKF7M/T1O55t0kwUTbbPUdYokODXe+0er1TY9DQyoV5onfMUI/O xPNnXjqHq8+P6EULB0G187+g5mCbLHNul03EkEBmtjLUDqKAKieD7DDq114nSVAZfhfk HtiwLgyT4cDIdA4aSncwn58Ct3dGOy9BVBC8kWG2ARs9+a5izBVXK/jIGh7W6qQbSFCw mvM0JsAT2X0VZQhiIEnci887yJaQmnn4TE/ebp+Ipg8G2MxA8wPLPOobzPNW5rmJbkUx lvIA== X-Gm-Message-State: AOJu0Yxp86il+o8JrJP11z1He3kFEGX2CvpBe9AYSfztKEVTVotZC/ae n6FXPAJCZcww2DiHZGPbjfnVABbUyUbQ8ZrWm0gOOXjpWgQoa4KLfo1gOrERaADWgDSY1tkBF7p n4Gs= X-Received: by 2002:ac2:4c42:0:b0:513:2004:43e4 with SMTP id o2-20020ac24c42000000b00513200443e4mr4071069lfk.36.1710327321112; Wed, 13 Mar 2024 03:55:21 -0700 (PDT) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id w17-20020adfee51000000b0033e1be7f3d8sm11390338wro.70.2024.03.13.03.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 03:55:20 -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?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [RFC PATCH 1/5] sysemu: add set_virtual_time to accel ops Date: Wed, 13 Mar 2024 14:55:00 +0400 Message-Id: <20240313105504.341875-2-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::12c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lf1-x12c.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 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. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- 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 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) -/* 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 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); 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 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 68d161d96b7..03ba026667c 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 0bf25e6ca53..1a7957352b1 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -5,7 +5,7 @@ stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('cmos.c')) stub_ss.add(files('cpu-get-clock.c')) -stub_ss.add(files('cpus-get-virtual-clock.c')) +stub_ss.add(files('cpus-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c'))