From patchwork Thu May 30 17:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800202 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp358981wrw; Thu, 30 May 2024 10:51:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW6sWLEodUgszMjCDKpmx8msOdBzqYIqSbFA/dw0JGxjPy2/SzqjL4vCOB/H2VDEkNTIgIJZREm4YnqIDUpmMxT X-Google-Smtp-Source: AGHT+IEqCMz4jPXYNl1PCGO3XCRepjTPcZf/XLpnRW+boPYFgM2qLZPW/AkwKf70ypjoylSWEBIp X-Received: by 2002:a05:622a:83:b0:43a:d063:c8d7 with SMTP id d75a77b69052e-43fe92abc1emr32757631cf.1.1717091504097; Thu, 30 May 2024 10:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717091504; cv=none; d=google.com; s=arc-20160816; b=uXvdkAi7z+bh5riR+aUZUcLaJHWYG+/UjmHw3X1T5og4hLk91rOj/Abl7Wrn6usFT3 RHZnrIuJHTa77SFsWC/OFE+1edXHAzcy5B3kwIdV3hRL9W4HAxUjT/NgXGCuqJbYy7cV GfBTKOmk0VbuKvXgfbOZNXfBpk0tYIBnJvyQxsG2WEO/gmtodfTGhIJF0dA2ajpDH3Ed ujp/XMB+M2wrxBh8gKzndRq7xlBbs1Hr/sUgM4hrALNsvKeCzhEHs8DmwXCxbQMAeWal 4hEod2MUbuFWjfwToE7+MG8Ma5oBkZ3svY1K4lFFV74I+A7XycNoU25cEhCta7aWHt/j f0wA== 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=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; fh=LKktwX56bxJWWOzcPT9ux4esRHG9xF8JYIpPYIK87W4=; b=JKqkBxjNZceAlL7WtA02MW3esoD8oXu8hVDZvsuMu0I3QrAQcEROVGQ3YizZkmLsGR iem1dMqbWJUJwPgE9dfzwkdk6cWUjtzMNXEQCYAWRNHDM7na/q4Id9oL3zXb72mFAz98 EAizJPpGPM62F91N0jozHxoNsX/N9lEhm+PzruPsuhGuWribfQRZ+OJxt/wrWJCO4ptB N2B1V79Q4d1KOI/5DH3TH7JFo8QMjAn9Ow7l25bSu7PsSwwEWdFWatjnesm657oXgiJb 4cykYkXOeb3odEaJ9gxjhG7wN9BjjDCi3rOG60ck5Ej6+JKj8iJh2evbo3QtK7Vrnmzb knuQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RbDEzbgv; 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 d75a77b69052e-43ff259d200si583001cf.562.2024.05.30.10.51.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 10:51:44 -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=RbDEzbgv; 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 1sCjuW-0003r3-8J; Thu, 30 May 2024 13:49:56 -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 1sCjuU-0003qi-2a for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:54 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCjuR-0002S5-L3 for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:53 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f4a52b9413so9981955ad.2 for ; Thu, 30 May 2024 10:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091390; x=1717696190; 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=RbDEzbgvE61wO2seG9hmbVbWr0KU02cr9ObQp4S8PW1llg4iWS2t8Zymkr0EG9RvhK tQSLK7//s6lEv8IlpK94eZlz2Mn5jKcKVYaKika3H2ZulevfXbbDFxG72UrKDH3JAbxs iEknsYDVaqu0pE9pha2lHzDjkt0nXQXNqsxzWEo551TwdqwUvbJCG5PGeZcy9mGRqtwV LY3A9VVK/rAepz/xii2zRFlha7wNTBw+L5VlpER3SLEUaFSqXtfD/7wB/VlmDCaUgDKv 0VEFzBKrmPP15im0sr38HRFvnf2pR8+/jmrgFBCF83BUqkYBpgbpuq/L+ik6J8RbSYxT la7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091390; x=1717696190; 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=D+Uw0MjeuUB8LlsKPNq6/DYZ8t5BtBhcRUNeQzdFbGxy5+JrzUwDIAVg5M5Mruj7yQ nKfIZwqVXRcylclaFxhQC7ys93qxJjLH7UNmvXVsOtnSD8iHWNWIXXtO3w/0v1+1fAhi R624yTGja84UseY5vDicfHTZIaUmN4FJXKazGADEkcEYAt/B0+mbkdBD2D/6nOF6K302 wB7qGiNiaInOWjonfHUFdeADRzLjltxH5wHfELOV2czgjQywhNKbrNZS0M8+7Neh+5WQ +evd94xOy1LVrdlbATADFvV7UXF+ixb9rxhdZ330aZY2z7XEpP41nxQvLnEsUu8vJ8US ta4w== X-Gm-Message-State: AOJu0YwV2hpsXD/fdQkc69mPUhav62uwLx+LhSsIKGfbDGyg298gQnMX E149+0CqAAKFIwFf1nJLvQzCfzce0QzOlvUzQo/jFehi8l9tU2C2s2kAOnQAcgsFsToTSWmTYo+ ktcA= X-Received: by 2002:a17:902:d4cc:b0:1f4:5f66:895 with SMTP id d9443c01a7336-1f61a2e44a4mr30894645ad.68.1717091389832; Thu, 30 May 2024 10:49:49 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323deb38sm590405ad.124.2024.05.30.10.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:49 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= Subject: [PATCH v2 1/6] sysemu: add set_virtual_time to accel ops Date: Thu, 30 May 2024 10:49:34 -0700 Message-Id: <20240530174939.749163-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x630.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. From: Alex Bennée Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Pierrick Bouvier --- 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 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(); } +/* + * 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 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()