From patchwork Thu May 16 22:20:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 797267 Delivered-To: patch@linaro.org Received: by 2002:adf:e68e:0:b0:351:d90a:5487 with SMTP id r14csp500952wrm; Thu, 16 May 2024 15:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWUd8no27bb7G+UUjUnfIGDIbH/FRN05H43gzI715YPjIRR+RjyfY1j671Be90rjOXQpnlWGxF2V4YSdiElAwcU X-Google-Smtp-Source: AGHT+IEHE4YOJlJPTvWciWNzBB0o+RE5qDJ4/YhRDQCCnvyJqjUCfPxBs70pqpdyGHgiGq0Tfqbm X-Received: by 2002:a05:6808:1794:b0:3c9:6510:5908 with SMTP id 5614622812f47-3c99707221cmr26730352b6e.28.1715898112460; Thu, 16 May 2024 15:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715898112; cv=none; d=google.com; s=arc-20160816; b=fCa4PzV/l69KxZEsFTPHnPHUiSHtVWcnMVS7IRPBV2ekM7IpIiKahTm86OadW7YTar 9rIXofiKjZkta7Yz6AC2NLYTeII/EwQawhxWqjA2f3lDZ8OspJVMvRg/0TbttIybF9p2 HO+G6813DptyMJBxmN+80WGcjOQpBjttvOMMda1crqcrHiCxDUFyX9T4MY8zeUbmwPol Il4rp14tS6Xu8w8b0t8QCKf2VVKizKSVkLinaiNgQtqYJwgAmapiqYmaOl1Q+NmHOwxc KQPwnXiIzQRCPQhVGsh/tLe2HYsMUai/ivG8lJiwlZiDWMcw5cOHqZmpJLLFR8vdDcIO /TeA== 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=Y0Mdqs4rLLstx/rEbobrQf1vWZp7tESBgee9yE2s3+g=; fh=g/MPAHpMYE0ua/lb96iWG5PoNHzHglLQcSfHbMEd7k0=; b=cj19Cf7cpz7jtloFxEszOS9KSC3Hhdp1gkgQsKyYZGd/mM6uXPMJUp2c9EIqCo1P7h scin6jqJXEqVzA5s7UdKEas6eQ8ZwDSZFYOsppOSNHO5njdIsSlqqQkL1ObceaUMT6F2 +LclqRbsJylDCIi71u/iKZPH0NBUaXvypiD3c0ovYpkpmIlqu+kutm9p4H+8ae1QCKze qxDo5fLB+4TAhsb5yp8b+/ZDaNHuqctWHCHuZ6c6zjF0WQKQ9Iqg/sk5cKqfQ72ddVky DQ+mUROyMDrwqns6CG0OjR2wBkEmFipEkvaA6Fofg3S7iat0atdTEjiC3untjzris15E 7C3w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e4QLgFr0; 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 af79cd13be357-792bf33b561si1662141385a.477.2024.05.16.15.21.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 May 2024 15:21:52 -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=e4QLgFr0; 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 1s7jTS-0006iW-JV; Thu, 16 May 2024 18:21:19 -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 1s7jTK-0006bt-9D for qemu-devel@nongnu.org; Thu, 16 May 2024 18:21:13 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7jTG-0003BS-8h for qemu-devel@nongnu.org; Thu, 16 May 2024 18:21:09 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f44bcbaae7so774079b3a.2 for ; Thu, 16 May 2024 15:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715898063; x=1716502863; 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=Y0Mdqs4rLLstx/rEbobrQf1vWZp7tESBgee9yE2s3+g=; b=e4QLgFr0umY45MnXcK1dB//KIVNXr/4J54footaJ9HL2SOP0Mmr4YpYGaQwjjrgH3o FgEMPW0Yxl0FV74b0VjCfRIWypN0l2uuzbC9Y3h9jj3lET7MvsANdaZl+O4UnsX7+XZN KOctTQAnBl+7mi5OdVdDzywpb/TSIGCzmaigWVjj1H9Dt5N1XdWjzkU6kXr97EhvBxVT NoLavgyBtqgDMzu+ozLZJ0sZ17KZW2OHs5OdTexfeLOiTO54TfjEUKKIA0sO+P68zAq4 tIOWZEobqTH41xsdG0EwLSnWrhwnDiXMCM3uBGrOmRiO0C7v0jttvrCVXHN0A9L16+qo Nu2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715898063; x=1716502863; 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=Y0Mdqs4rLLstx/rEbobrQf1vWZp7tESBgee9yE2s3+g=; b=e+PKu4I/Fb6rlTH71ynUitL4UqQCK6bDXbwgj8kTQAbLsJweXhxmu0SY2Uw1lbLhet 66GGEzoAc8ibRtBhXRSrBaQ0X6qh4gHHxyytqm8nXMwTCj6ux5WWfPPcSnsc3SY6vbuK kjU+wwjGEcDoLz0PyZAna+0VVyclmfHngIbMs1CRHl55GTqJsEznfby/G6k+qPNBcXhB fYlDUhh3YkmevvSQiV4YpueceMM7iSPmouuKNkCuTJMBYgP+u0XJlrMxtudZgBAd97M/ rrUulmJ15ojqlEs60T8dZoGj+D9VIa8TbsH1lHIc3QUtajhkLbi9gGEjY3SopkcErWSH 7T0A== X-Gm-Message-State: AOJu0YyPXG6N9ZWR/L8dThA60R3KL292vMQ9tFhpvTWF7RhldjqUd3oc VKf66yc34j9UUzcoluwleOCrfTgLuFzwFKYQIfcWDh2/AiHobgiy9Nz8dn4Y6KRm9T8y8MsCHQM mb80= X-Received: by 2002:a05:6a00:3d07:b0:6ea:d740:62a4 with SMTP id d2e1a72fcca58-6f4e03466d2mr23816737b3a.25.1715898063609; Thu, 16 May 2024 15:21:03 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66476sm13589219b3a.28.2024.05.16.15.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 15:21:02 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Mahmoud Mandour , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/5] sysemu: add set_virtual_time to accel ops Date: Thu, 16 May 2024 15:20:43 -0700 Message-Id: <20240516222047.1853459-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240516222047.1853459-1-pierrick.bouvier@linaro.org> References: <20240516222047.1853459-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42e.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 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é --- 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 | 6 +++++- 5 files changed, 40 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 3b9d42023cb..672213b7482 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -3,6 +3,11 @@ # below, so that it is clear who needs the stubbed functionality. stub_ss.add(files('cpu-get-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')) +stub_ss.add(files('error-printf.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('is-daemonized.c')) @@ -28,7 +33,6 @@ 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('icount.c')) stub_ss.add(files('graph-lock.c')) if linux_io_uring.found()