From patchwork Thu May 30 22:06:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800217 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448271wrw; Thu, 30 May 2024 15:07:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU95aAMdMNIFxlM42mNac074KwX0T+SPkXhc8wGcd41ePcc7Wm967HmIB1sSoX/qFC8UHCGv94V154T/hbFNQ8w X-Google-Smtp-Source: AGHT+IE+cjzjMsItos1RveKe6rvj9QisygGmUAGEBEp8wd3kcD56Crdr/PVMzLoB61vViW48jzLZ X-Received: by 2002:a05:620a:4048:b0:790:ea3e:61cf with SMTP id af79cd13be357-794eaec5f50mr576992285a.15.1717106871716; Thu, 30 May 2024 15:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106871; cv=none; d=google.com; s=arc-20160816; b=RDdoTqZtmmYVyyOg0Xm2e2blFhDtH7+qXQrxpArAhoNDTaUv+MZKzSm3/nm51Ma05D AzFkZuOxvVMzM7Tsnys6AZ3RJaZVwEcC8wXDd89Mf3z9KCQpZ0L7hPUXM63zts0JihTT 3XysaLhpKq1hL4mI1vwD4P7mNht49oUa/b5ZhjJY3HATDChWc/2iCV435ixbEL5l9WeE cCscbFgK4wqty9ApyovRTlyLK6kQcJTUf7uPg4HpvxJ17whYKdxOFEjIQAmwjYzXoiHp bMmJMUi1Vkt7hQo2tB/ApJY8T2/X9Nx9SM4odJxQJ4UtIyAk0pQ4YFnFuw1HJTcrE4RM 9SOQ== 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=kvMBieaVLTH0ne+hDW3CZjEP2sON4TJh1Qp15Wc+QYk=; b=cPZQkWfUQoUCeXx1yg1QaTexHKRfmGmLvcG3Kf69ADeEpTnSGZCWMtsSsm0Jzcc73Y YHsVaKyKGRtySUrTl8yS3duzSbIKKUgAfBnZtiJGtNEXuOd/zSLB2jwDxaAZ75CxCLe/ 32k0esqvNKYfLeHcR5CYKr4qyQcTknRsz47yTE78YuWAN9QMLTJQ2/+p38I5BMpnChPw bMgUBAqt6bdIXBXjqT+iaAu9SNjeH7H3UIbXRdvWyeUFXkebhIbxMLm3XYWWfX1JnO7Q D8ttlIQaM8b/Jyr9YtxmkMmnyR3aHsyPyE/PAe0V9JmiGodpYQoPIcD4ZDZ9wBKqeYfK Pi7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pm2eh5lC; 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-794f32ad07bsi53881085a.693.2024.05.30.15.07.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:51 -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=Pm2eh5lC; 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 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) 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-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) 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-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 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+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() From patchwork Thu May 30 22:06:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800216 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448242wrw; Thu, 30 May 2024 15:07:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVSDV9etyrK3HM+IT3kNxKY/Y0NZ2mjw75zO6cPiM9HBscM21W3Vt3RpoOJWJQSXlA5z5LY1KcnfdQBlYp0vBGB X-Google-Smtp-Source: AGHT+IGxwgkrt6//JXHeXUCK8JShlr8lZ++WPS50WXZoa/X6ZnZJRR8h+ShrsptSLSTcIueNsBUi X-Received: by 2002:a54:4782:0:b0:3c8:3490:4a05 with SMTP id 5614622812f47-3d1e35ced2emr62765b6e.50.1717106866161; Thu, 30 May 2024 15:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106866; cv=none; d=google.com; s=arc-20160816; b=rtl+Rz9w8H6SPnhu5RJn7O2e4r0PMEFQtFlM6pSr50D3cx1fgIq2zrY31KNxIQ9Q+Q 2IRVkqrPx+vW3C9hvmXHMXHcktCkRk4Q9jMp7Qco4JFs6k1pv8DTqSY3ReHiAl8AmcTc qMhLViJ7cvPe+uoWmJI/UyOMcOPpU/ha0IqV+n7mtkwLT1Tix2p1Do22HNxwNmqOY9Hy G16yqeO3lADL+jyJ4xZHYCSmUEhRWJAXXoxyHLEDVHV/sX2M9Ydpt+JzPoAd55cHcwpi Eq7eN0sJESQPx9OW6U1B/uTaxbWzf5+4ewqtuI6Upd+8qcg0qpVVwm3eQbIHNYGmpwFZ 5iyg== 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=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=W6zeNKJFSQyhE48IVdP8RtJ3hLUUdp93+eBynq+suOv2cHZ1KhDI4Hwz0rsPrf36fG w4AFVvs4DCNjslUq36WgqNVIQb68i03WQ0/K5NuE3IxUU2ehrVDqrZ4L29JNP/WP3XuG KKvgWeBZgsBWtsGfCQ+hdzjg7iyDAaRtOYgtfiNFrLdP4n+RoKp+JiRSa3tW9UuvN+92 pTrY7vxR4eEM8R0P6RYZb6kb/z7EnkMsyleT3arDOMU3sS2gk5WBGlHJkiio07IWapaL Ai8jiWWK57Tje2HjNMLo4VpfQSgLEJyNsmOffRSYJPlFHgdr2OXAitQmvg1dvDVSf/WR tZpA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uXfmLAvb; 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-43ff257e356si5742561cf.410.2024.05.30.15.07.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:46 -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=uXfmLAvb; 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 1sCnul-0007Jq-3N; Thu, 30 May 2024 18:06:27 -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 1sCnug-0007Ie-Fp for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:22 -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-0005Ct-Ao for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:22 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1f3469382f2so10771695ad.0 for ; Thu, 30 May 2024 15:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106777; x=1717711577; 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=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; b=uXfmLAvbTG40rlfp+Eh/ZyZwWXGLjQUitwuIdTbO+qU5NsQtjxGol0+tTVzyCjgus9 cqP36pTPTuDTqHyKxNVM1HvmkM4J8Woq2BYWxxt0zI4t2AhfW36vkWusFGICZ7+4bpyJ 3Q1MQBoaNzxQud6ruEzgdPkhFCGRuKT7xvs+We7MbiIolProzftjngoLwSXACQHYIhvg Rj0XJ+wdn8XaDCb5tLqsQmaYdzAVSD6+Jp+TsDZZwl/YRrGL0o2XKU0Es7UzVNuXbies qOKPh6W+Htog3oDVdQdnrgMlhJLM47w1zpqkgXsAYX2ybci8O+wjvxSBDS/ct4s7aZnc XkzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106777; x=1717711577; 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=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; b=t6vBFCSu8+Tk+9eW0+LyNGoUseHmqLcktmJszhqYVGPMMndaAd7SSAQM1naG2zHpzE SUou6ZQ6KImq6kcCK3r2ZVDO/RkjdKx1+AtoH1isDcG2a0zVHINwTGMp/8RKN7XZcXLb 2yxkhFzbD4k6jmZr3mA8bfs4apLwQ1xl6bx+WhEzul4At/6OM+fZntyuBLv4TOQZGLgo JIQ6OX6toK+2M5YP9nYFhwfUX2pDXMyln7MnzWEwy2AjXEwiwuQTPnFtgdnmPB2aJYh7 QK4tRcsfSFhMhWCE0eC6UqX4zndBbE7r1DXbOSpIx2t7j8ZgpioxjyGV0hm8eOs9JnV8 oFxw== X-Gm-Message-State: AOJu0YzFpmtsAroPagB1tgJReiGDgNP6W6ItschZKgftifQN13jxkZtx uc3xVxPtNntpRMzIbfSvaaQe/94a2fc6koQPEfnMeBGnFDSHhgeFG7suSLms8/zde0JX06py+7x qsiI= X-Received: by 2002:a17:902:d490:b0:1f4:8738:64f9 with SMTP id d9443c01a7336-1f63702772amr1916035ad.39.1717106776896; Thu, 30 May 2024 15:06:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); 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_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 2/6] qtest: use cpu interface in qtest_clock_warp Date: Thu, 30 May 2024 15:06:06 -0700 Message-Id: <20240530220610.1245424-3-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée This generalises the qtest_clock_warp code to use the AccelOps handlers for updating its own sense of time. This will make the next patch which moves the warp code closer to pure code motion. From: Alex Bennée Signed-off-by: Alex Bennée Acked-by: Thomas Huth Signed-off-by: Pierrick Bouvier --- include/sysemu/qtest.h | 1 + accel/qtest/qtest.c | 1 + system/qtest.c | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index b5d5fd34637..45f3b7e1df5 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -36,6 +36,7 @@ void qtest_server_set_send_handler(void (*send)(void *, const char *), void qtest_server_inproc_recv(void *opaque, const char *buf); int64_t qtest_get_virtual_clock(void); +void qtest_set_virtual_clock(int64_t count); #endif #endif diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c index f6056ac8361..53182e6c2ae 100644 --- a/accel/qtest/qtest.c +++ b/accel/qtest/qtest.c @@ -52,6 +52,7 @@ static void qtest_accel_ops_class_init(ObjectClass *oc, void *data) ops->create_vcpu_thread = dummy_start_vcpu_thread; ops->get_virtual_clock = qtest_get_virtual_clock; + ops->set_virtual_clock = qtest_set_virtual_clock; }; static const TypeInfo qtest_accel_ops_type = { diff --git a/system/qtest.c b/system/qtest.c index 6da58b3874e..ee8b139e982 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -332,14 +332,14 @@ int64_t qtest_get_virtual_clock(void) return qatomic_read_i64(&qtest_clock_counter); } -static void qtest_set_virtual_clock(int64_t count) +void qtest_set_virtual_clock(int64_t count) { qatomic_set_i64(&qtest_clock_counter, count); } static void qtest_clock_warp(int64_t dest) { - int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + int64_t clock = cpus_get_virtual_clock(); AioContext *aio_context; assert(qtest_enabled()); aio_context = qemu_get_aio_context(); @@ -348,7 +348,7 @@ static void qtest_clock_warp(int64_t dest) QEMU_TIMER_ATTR_ALL); int64_t warp = qemu_soonest_timeout(dest - clock, deadline); - qtest_set_virtual_clock(qtest_get_virtual_clock() + warp); + cpus_set_virtual_clock(cpus_get_virtual_clock() + warp); qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); From patchwork Thu May 30 22:06:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800213 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448117wrw; Thu, 30 May 2024 15:07:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVkFGtE16+ogxPsbzwUFftBHWP3eE/OE44zKQPgrOVM0iVK/AVf+4EWMvN+AOzuYJ6t/nW7wRNCU3Bz+1Yh3Fyd X-Google-Smtp-Source: AGHT+IH49TRSNaWkf3f9KnXcgJmkOOVUcOsa2GwxB9FP2ZwykXjkvGopuRsPt4Qqoy9bK3QT2a8h X-Received: by 2002:a05:620a:841b:b0:792:be53:8b46 with SMTP id af79cd13be357-794f5c87ad7mr979985a.30.1717106848741; Thu, 30 May 2024 15:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106848; cv=none; d=google.com; s=arc-20160816; b=V2JD2mQSLDJSuZkY+fyHirZi4neLg/6SR2aVYtLd+hZUGxyQw9ssj/EqHTu6cIAcFs 4Vx4E8Mr6tpyaLL5DtcsO/ZL+k0B8pU6x9oHQXj47VurMD/0fwHh9oms3uFvWPU3D6FJ PsoHiSX6nF78S6d5aO2T70vF+tzObrJWCBvei7WDOcd0+6vu35MHLtO1WibgZJ8qEJ6m 0HDrfPYg2sZ/nPQpUQlOydnfB5HrdTHKBgvMmuzCDREecvnOlpkTAr+DE3GBnlGL0F2g ye3/ALJCmXJ1tyDr6EKCkLKE+I+yEW/hsYZknRg+fHK4VM9NT0w4m1XphvCkkiJhVJxN tI9A== 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=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=YrTaG8Uhi1PNUfUi6ls/PWgezunbCmqqSuc8U/MqOSD42ICGN3ERRlZ0vWWyCizFtw CoIOoqDyVMgPRhmOwH7dLo66r6maqVxyljPlQcwvzC6X2XAYCPa7VRZCStmrBD0hIqQr 3POhonu37K+1doIFU3dPmlV/7FwCciArBWh48Grm2ue97gVddq2iKHJPS4fQAqweBnxe vhg2Ea4LyybaJglsz3FDfBHhfmp+xsgDNB5Ut31SECmkEIyCOIBUuL5SdBi5DzX6yVzo dupDiQaAgx4cpFzNmWe9IuSrjX5HxAgL9AuvBn6Zu2dp3sOJZJWuvAUILeXPbGlkr9yh 6YIg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cwL+wbds; 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-794f2f04dc0si68024985a.78.2024.05.30.15.07.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:28 -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=cwL+wbds; 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 1sCnul-0007Jv-E6; Thu, 30 May 2024 18:06:27 -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 1sCnug-0007Ik-U1 for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:23 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnuf-0005DX-5i for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:22 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1f63642ab8aso556065ad.3 for ; Thu, 30 May 2024 15:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106778; x=1717711578; 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=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; b=cwL+wbdsiMMdfG4vFT4bZ64FgOC49kUbA2Q3E1odcm31DaSuc8FmqsOP/I+oKtP/2m iUmcoZzOmh6FTWToGXKSfSyKeFX1QggbrBcggbXuVJN6xP8hI6kmVGPb4NS80Yr96kg/ V+MQvvpl+OQ/Y1qTv2/dHUfXXvO56qRAhTdavL5R+qR1MeSSUkpIs+tKe/fc7hctcoi6 T0FSG3QDkKpefHpAjlEqwmFAF/yhHfuQbkP0+OyoumCnPu/VDzBngnCnMRVDWKwkF4ya U5S08BfydzmhociadMM4vwKODiunNcXyRFJ2BHwoAjhc/Z/maDDhMQbDrCQrvZrZ8/kh e1qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106778; x=1717711578; 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=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; b=cDJHAisPUJ3l4RuTLe/p0Fghv/1ultxn8NNUcvtAGKeMvpK1tRfZlD6g881yn8h84I AtEquz8T+4zG7YF6A+4oT/LCDejfSrl9CSLkldwDSvLjQq+dJ7QU3hJpE4AZumWhUfYL iWxi90fJlpND2OpwOABq10P8EMa8721rb4N+LDErkJF2yEWOW3T76n5lKXv2p3kzFFBa EQQRrabbm69i9eNmALXBMMqhQvmzP5TNd3O3trvIQw4HmZOkjS8h+INnwSmQVnl8R/3h GkBJS/fulmMoMy9lqkzdiWJLIRI2YQr0q4vp1ggt1TWzK6PrKQkFPg5IEU9gAsbv2Sps FZIw== X-Gm-Message-State: AOJu0Yw65ZMYcJuWY52pPWLF3AlaLI7maDhGAgyzKGORZjsevdxgYYjj Me6Znx61oRyua5vympHrmCVGuO6dfJJbtYFfzU50N88cLH/8PJcarny6F5ZSAicn5eIlTfy0rla Xtd8= X-Received: by 2002:a17:902:d50b:b0:1f2:f182:f617 with SMTP id d9443c01a7336-1f636ff45aemr1485665ad.10.1717106778496; Thu, 30 May 2024 15:06:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:17 -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_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 3/6] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time Date: Thu, 30 May 2024 15:06:07 -0700 Message-Id: <20240530220610.1245424-4-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 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x631.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 Move the key functionality of moving time forward into the clock sub-system itself. This will allow us to plumb in time control into plugins. From: Alex Bennée Signed-off-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- include/qemu/timer.h | 15 +++++++++++++++ system/qtest.c | 25 +++---------------------- util/qemu-timer.c | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 9a366e551fb..910587d8293 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -245,6 +245,21 @@ bool qemu_clock_run_timers(QEMUClockType type); */ bool qemu_clock_run_all_timers(void); +/** + * qemu_clock_advance_virtual_time(): advance the virtual time tick + * @target: target time in nanoseconds + * + * This function is used where the control of the flow of time has + * been delegated to outside the clock subsystem (be it qtest, icount + * or some other external source). You can ask the clock system to + * return @early at the first expired timer. + * + * Time can only move forward, attempts to reverse time would lead to + * an error. + * + * Returns: new virtual time. + */ +int64_t qemu_clock_advance_virtual_time(int64_t dest); /* * QEMUTimerList diff --git a/system/qtest.c b/system/qtest.c index ee8b139e982..e6f6b4e62d5 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -337,26 +337,6 @@ void qtest_set_virtual_clock(int64_t count) qatomic_set_i64(&qtest_clock_counter, count); } -static void qtest_clock_warp(int64_t dest) -{ - int64_t clock = cpus_get_virtual_clock(); - AioContext *aio_context; - assert(qtest_enabled()); - aio_context = qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, - QEMU_TIMER_ATTR_ALL); - int64_t warp = qemu_soonest_timeout(dest - clock, deadline); - - cpus_set_virtual_clock(cpus_get_virtual_clock() + warp); - - qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); - timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); - clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - } - qemu_clock_notify(QEMU_CLOCK_VIRTUAL); -} - static bool (*process_command_cb)(CharBackend *chr, gchar **words); void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) @@ -755,7 +735,8 @@ static void qtest_process_command(CharBackend *chr, gchar **words) ns = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, QEMU_TIMER_ATTR_ALL); } - qtest_clock_warp(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns); + qemu_clock_advance_virtual_time( + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); @@ -781,7 +762,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words) g_assert(words[1]); ret = qemu_strtoi64(words[1], NULL, 0, &ns); g_assert(ret == 0); - qtest_clock_warp(ns); + qemu_clock_advance_virtual_time(ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 6a0de33dd2b..213114be68c 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -645,6 +645,11 @@ int64_t qemu_clock_get_ns(QEMUClockType type) } } +static void qemu_virtual_clock_set_ns(int64_t time) +{ + return cpus_set_virtual_clock(time); +} + void init_clocks(QEMUTimerListNotifyCB *notify_cb) { QEMUClockType type; @@ -675,3 +680,24 @@ bool qemu_clock_run_all_timers(void) return progress; } + +int64_t qemu_clock_advance_virtual_time(int64_t dest) +{ + int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + AioContext *aio_context; + aio_context = qemu_get_aio_context(); + while (clock < dest) { + int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); + int64_t warp = qemu_soonest_timeout(dest - clock, deadline); + + qemu_virtual_clock_set_ns(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + warp); + + qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); + timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); + clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + } + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); + + return clock; +} From patchwork Thu May 30 22:06:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800215 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448203wrw; Thu, 30 May 2024 15:07:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUa2VSl+pLdeUjvXt+d9slK6mEfX+4C/f0JNbVS5WLpE2ygzUNW7zwpuG+v8h336hptStGkXc2mBkZxC11JuH7k X-Google-Smtp-Source: AGHT+IG1ncqJDogn5bmjyPI5mgVY1MobCKblS+Nam+DiNMo+DZFU2AeKklvnHKFfuzTjtgkS7qW6 X-Received: by 2002:a05:6808:419a:b0:3c9:67a5:3aef with SMTP id 5614622812f47-3d1e35cbaedmr54167b6e.49.1717106860116; Thu, 30 May 2024 15:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106860; cv=none; d=google.com; s=arc-20160816; b=WQmxgamKcTTEMdwkO7LC6EKdCGgK8chqg8rjGauNgUiNKn218aEKDNZEA5T4ML7ZTZ H5ksEXs8/+MvLDbHGbXX3oO+lyLXHIH1+lw0p2hbrNYMPdhcQ+t2RnJ/sW8LmyNCkBuX q/sNuXsX5ovQBGext88iBm+aLCz40SNM2yE45JrLkMSuEBez6Q/vfaVx4js1oY1LBnQs SwzdpWi7ifULkVyxFvMH5icny/UHi6NE9NZRB1ClIZTxaxutQ96+J3Hv9cWt9tMbuAwF Iy5wshKJPzWjhWL+Ezlbj4zQ9fY0fx1pmFnXM50ZwJyUtGF/RiuxSF7K4zgqZQtP8HOC Qy6g== 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=ChXWvUNOD02yoYequIGCuEzpK9HfTXZtOpXCWQ0j1Uw=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=UytWDLI6VEEOCeb5z124lt/bRe5PesmFeTEyoi+ESBUkoV31O3/hw9ybKGsBpIYbgH lQ5acqS3xEw0bb6Op/i6Y9ENYNLYRCAqTjBVAfXJLxsYTou9YWsHXPax5jiIMLj9StCM 3PyS/S6HPImsItOa5+e/Wc1c0jO00b7dkHOXaWyK0N728USFD//Q/PwTE6ueH+eQGH0t XVti2jfF9rzEFrsi2pj1zkrNdcV87qqybhhe3D+LhCxi0jdFw6ETW+5GGVnMVOSDVkPL GAFTDK4WpraOatNkiO3hWFK02N6pEo0KNVRuOeSmxp/XG8qAtvisjYUdlUAM1CX5LQto MsZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iQAQLne5; 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=fail (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-43ff2466ce9si5767521cf.303.2024.05.30.15.07.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:40 -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=fail header.i=@linaro.org header.s=google header.b=iQAQLne5; 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=fail (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 1sCnul-0007Jr-6V; Thu, 30 May 2024 18:06:27 -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 1sCnuh-0007JI-RA for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:24 -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 1sCnug-0005Do-9I for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:23 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f480624d04so12583455ad.2 for ; Thu, 30 May 2024 15:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106779; x=1717711579; 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=ChXWvUNOD02yoYequIGCuEzpK9HfTXZtOpXCWQ0j1Uw=; b=iQAQLne5GUbCraZ+irpqq4BuCF31pf2NcnWdp5vi5DcF8ciI1/63knMmHtH+bbQ++m jwS0KFSJO+v7bz07wTdu6VYy/Zvus4MNYQHKSIm8+mSFGS7FDtGAHKmLxDZyebiJJKl9 kfA3BDWJ7XmKfC0fiCs7agwQa3GBt8sKUdRgWrcuElwfA0BpzlTcDX5sl+iYLtixUaBa LufN81fVRsIwB6u2mNEfOtTEtQS4a23xbi3tlBTtFubSc/8fQ5OXLMiU7Ui8B/uQEyDc ZIcJd/c+Xj07AJIvkFboyoQvIVZObCbPeln3wsrm9Cus0tXg0v537w+GC268ZegBUx8L Nh3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106779; x=1717711579; 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=ChXWvUNOD02yoYequIGCuEzpK9HfTXZtOpXCWQ0j1Uw=; b=wgj2VjEYKVC1vTy4h4TPDl52+qhqjX1gOj5jiJPHd/HykZzSQocJVybVkx5i4VZn8N UrdGyYyWrWd2sNcQn9i+zeemqw+exNDrL+VKa7sFqf1WuX6wfr1jEnbibBI2iukHglkI lqugz9eKA6xBppfypZ45fbOkbm4ELB+mw7bCbTOoEwheosStnkxMZ4hERnT/hqV7u6Fc eVsoQ9ZO0+OjuVAz69yaJu41VctDWhJIvLmgA3t005EvlHs7Mt6ffC89LnAUWtenPkMl PvBQQ1L1JYpZiFnCNINhKvZyKNv9UgMWw8ZFewdj37Nb6eeo8KTS+sT24DOJTbvaAX05 EazA== X-Gm-Message-State: AOJu0YyyZYgbOKncqkjoasZezp6hvanOz3hP3Pjzgq/BZ2rSpaJgPz6z 1c6M3+JkR4UAon/jEgMSmYYl2E5Jz4HluyyVdunAf7eBeKRaTwoXl2dMz2LyeIHE8YDtnMxq8Kw cBRY= X-Received: by 2002:a17:903:181:b0:1f4:befa:7a79 with SMTP id d9443c01a7336-1f637019aa8mr1075925ad.27.1717106779563; Thu, 30 May 2024 15:06:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:19 -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_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 4/6] qtest: move qtest_{get, set}_virtual_clock to accel/qtest/qtest.c Date: Thu, 30 May 2024 15:06:08 -0700 Message-Id: <20240530220610.1245424-5-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 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 Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- include/sysemu/qtest.h | 3 --- accel/qtest/qtest.c | 12 ++++++++++++ system/qtest.c | 12 ------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 45f3b7e1df5..c161d751650 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -34,9 +34,6 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** void qtest_server_set_send_handler(void (*send)(void *, const char *), void *opaque); void qtest_server_inproc_recv(void *opaque, const char *buf); - -int64_t qtest_get_virtual_clock(void); -void qtest_set_virtual_clock(int64_t count); #endif #endif diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c index 53182e6c2ae..bf14032d294 100644 --- a/accel/qtest/qtest.c +++ b/accel/qtest/qtest.c @@ -24,6 +24,18 @@ #include "qemu/main-loop.h" #include "hw/core/cpu.h" +static int64_t qtest_clock_counter; + +static int64_t qtest_get_virtual_clock(void) +{ + return qatomic_read_i64(&qtest_clock_counter); +} + +static void qtest_set_virtual_clock(int64_t count) +{ + qatomic_set_i64(&qtest_clock_counter, count); +} + static int qtest_init_accel(MachineState *ms) { return 0; diff --git a/system/qtest.c b/system/qtest.c index e6f6b4e62d5..ba210780ec0 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -325,18 +325,6 @@ static void qtest_irq_handler(void *opaque, int n, int level) } } -static int64_t qtest_clock_counter; - -int64_t qtest_get_virtual_clock(void) -{ - return qatomic_read_i64(&qtest_clock_counter); -} - -void qtest_set_virtual_clock(int64_t count) -{ - qatomic_set_i64(&qtest_clock_counter, count); -} - static bool (*process_command_cb)(CharBackend *chr, gchar **words); void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) From patchwork Thu May 30 22:06:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800212 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448110wrw; Thu, 30 May 2024 15:07:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWBQpTkkSjPxLhrG3jdGuW+1pRG9lm0yakGmeMK16nnyqmmDALTTq6zutc5djSnUcJ6S7vjifE6+Ty0Rv5viFSq X-Google-Smtp-Source: AGHT+IFccFR+gSJ0wjceD9ey3g1EBudwUncOZOQZTOfm5hhBo/nPz2uDoc+J3II9v50qTr7VhBO9 X-Received: by 2002:a05:6214:44a1:b0:6ad:62a2:4458 with SMTP id 6a1803df08f44-6aecd4cbabamr4765326d6.30.1717106847737; Thu, 30 May 2024 15:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106847; cv=none; d=google.com; s=arc-20160816; b=D2XgcQMUhTjiAQ0NTVypWYY3VnAQfUnlRBD0hnISc2wBzUGxvKxVpw8VVD16Xg/OCI UAtH1Np6Lq7W8sGKTQDU7DuGbqoaac+74WruP3CRkzCsFX8K914FghTB0RSXp+W4q/KA XQztYrL73I4mnfuYShTM0qo2qYY9iCnb/qG1u9FjvOjVW75Gk//7nrqzNw5KAzZKtmHH v7fZBiNsTHBGDGsUn1Tzl8qUy9lTSBhInca2lGnfVWY7mBEdhXiPcJud6gKvnrf5oPYO 9HF4BbSGTumfHEBKeTF5tCB/kN5+gGu2la79Zn8pUi/yU0Peq54BYa4UOLn7fdMbVz1U GuBQ== 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=Ps9gGFVUmKjmwMVRPVORIGLlgHUtsDCtUukvrncmBDcBK58jViz3NJsE25BTLmLSZ3 XE0EsGYUmeAIbrrgcJriPErqTol9YdgZ49S1C4Z51X/QADaQi7Tc0IMloV2Apyq9zEtj LVMidvPiUdqEAWeEeVmN97CC0L8bHzJnw+wOy62A+abh/1e+16ljyeDmBOlP5JzcJxSC 1/5Yv7hmiiuLnEEwFSHIj/gDyPrQhLYmDmotM3SAzDVHFQe3VdNOIKoSPWdi3aiqfW78 bWeFRFex6tsbFiUYs6gc60UvcpanQPwF6zaWyay30glk0UtPjrGlTYCeDa3J5EUHKpW1 9H6g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZEeT0b7m; 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 6a1803df08f44-6ae4b43ec6csi6023156d6.574.2024.05.30.15.07.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:27 -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=ZEeT0b7m; 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 1sCnuo-0007Kx-49; Thu, 30 May 2024 18:06:30 -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 1sCnul-0007Js-7N for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:27 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnui-0005EC-Vf for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:26 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1f48e9414e9so12617225ad.0 for ; Thu, 30 May 2024 15:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106781; x=1717711581; 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=ZEeT0b7mpooBMllfEc1/ONnb9aRY9RZqLznJIjbWNGyNNIplbMzO7RgtZErCDO/edS k5mcbInnuaglirtClHxx3rc3e/VmM2783E3Dwf3cHurOw4Uc5Q+FFHd9z0jMDKRfhEGq yivCmRP50DR8anfFyFDIGLnFOrJCoLBJjYqcaQQtt4tsrRKSE5dOkEEq9gxzRRo3xXsB vYbnbspUNku+etwEbIiHwJX+t5lDwzDc+aS94O5OgSUZ41CLNTIvfA+/J3nZs1oUUFj7 ItwmjEhvs1sVw0traBI4XIyI+ZGJ+PB+98806TFoQq6jL09OBsCpFdxJz0QVP7D0Urdp 389g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106781; x=1717711581; 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=opgSHlIhb6BG9tilGqhXJR12UyyY0DWIxUYyb4j4GTCBKDQeBSP30bT14GjuE6wWY2 Xd39WNHRi4KdWK5AgIAvtCQUjHgctKfjbO3R1jYKPdOS9Zst+nemxchd6aKNJAN0v7sH FvHXyhxJd8ZBsP3K0gMAd9EbgahGUtegSTW6Y6m0+7wXRVU74vz/b9vPDmJJ4DLzKa/v gXUOcx0Efxskaao+1n+eaZuvTOk+h3m3WR+4ub8YnVnb2zEgTSLcwZ+CyUp9+Ldy6epu 6iKcixaLbdco6ou64Mkovs0pC0tT1cdxFts1nrHObd+eq8k1sjDnS4P+H1ZuMQBh4GeU pisQ== X-Gm-Message-State: AOJu0YypQPNaLPJbVhRAFr11amFKd4QQx6066gQvQ0mkxjvocEjaaNzj 5kCHH5V2zI1/ue7sisHhiG5rdLeHXbIjJF8vs66xkSnSRLjjwUO4FawgrkRTqCrP9ReJIlMk/MJ AEEo= X-Received: by 2002:a17:902:e5d1:b0:1f3:620:c92 with SMTP id d9443c01a7336-1f6359934d1mr3142845ad.7.1717106781416; Thu, 30 May 2024 15:06:21 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:20 -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_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 5/6] plugins: add time control API Date: Thu, 30 May 2024 15:06:09 -0700 Message-Id: <20240530220610.1245424-6-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 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x636.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 Expose the ability to control time through the plugin API. Only one plugin can control time so it has to request control when loaded. There are probably more corner cases to catch here. From: Alex Bennée Signed-off-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 23 +++++++++++++++++++++++ plugins/api.c | 31 +++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 2 ++ 3 files changed, 56 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 95703d8fec1..80b1637cede 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -661,6 +661,29 @@ void qemu_plugin_register_vcpu_mem_inline_per_vcpu( qemu_plugin_u64 entry, uint64_t imm); +/** + * qemu_plugin_request_time_control() - request the ability to control time + * + * This grants the plugin the ability to control system time. Only one + * plugin can control time so if multiple plugins request the ability + * all but the first will fail. + * + * Returns an opaque handle or NULL if fails + */ +const void *qemu_plugin_request_time_control(void); + +/** + * qemu_plugin_update_ns() - update system emulation time + * @handle: opaque handle returned by qemu_plugin_request_time_control() + * @time: time in nanoseconds + * + * This allows an appropriately authorised plugin (i.e. holding the + * time control handle) to move system time forward to @time. + * + * Start time is 0. + */ +void qemu_plugin_update_ns(const void *handle, int64_t time); + typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, diff --git a/plugins/api.c b/plugins/api.c index 5a0a7f8c712..26822b69ea2 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -39,6 +39,7 @@ #include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" +#include "qemu/timer.h" #include "tcg/tcg.h" #include "exec/exec-all.h" #include "exec/gdbstub.h" @@ -583,3 +584,33 @@ uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) } return total; } + +/* + * Time control + */ +static bool has_control; + +const void *qemu_plugin_request_time_control(void) +{ + if (!has_control) { + has_control = true; + return &has_control; + } + return NULL; +} + +static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data data) +{ + int64_t new_time = data.host_ulong; + qemu_clock_advance_virtual_time(new_time); +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ + if (handle == &has_control) { + /* Need to execute out of cpu_exec, so bql can be locked. */ + async_run_on_cpu(current_cpu, + advance_virtual_time__async, + RUN_ON_CPU_HOST_ULONG(new_time)); + } +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index aa0a77a319f..ca773d8d9fe 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -38,6 +38,7 @@ qemu_plugin_register_vcpu_tb_exec_cond_cb; qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_request_time_control; qemu_plugin_reset; qemu_plugin_scoreboard_free; qemu_plugin_scoreboard_find; @@ -51,5 +52,6 @@ qemu_plugin_u64_set; qemu_plugin_u64_sum; qemu_plugin_uninstall; + qemu_plugin_update_ns; qemu_plugin_vcpu_for_each; }; From patchwork Thu May 30 22:06:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800214 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp448120wrw; Thu, 30 May 2024 15:07:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWzR6GIAQqjalPmx6XfpnlGiIn71YyOgOMy5/+UQAo6Rd4ow8nCKCUHcSiZl46aMT5SBhUk/yAZ4xGzIw0GTnry X-Google-Smtp-Source: AGHT+IF1E7BPPH/f2Z9wwSbYembldZjkoKAZua7PMd/uy8Y+sr5bJE1e26aNWiM5a9tFOSNWbTtE X-Received: by 2002:a05:6870:71c8:b0:24f:f23e:dd50 with SMTP id 586e51a60fabf-2508bc51dbcmr215299fac.57.1717106849190; Thu, 30 May 2024 15:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106849; cv=none; d=google.com; s=arc-20160816; b=aj4zNOjz5YRxdu11EgqGAdYtQIJM3ll/ctEpcttf5uXHmZW+uu6L+MSYQiHGGw/qfc Y7MkHoy2DShU6/ti1QgFZs7WtZ7QSL5hEjhF1M4c834fVN7yGUadzpc2Vfa9tIS/gd/1 Dr8GcztFevpYqD9pGQBspk4wo51bt4THvILZBnlKw/04b/S0D0PJtyjDA90PPrkowSQc 1wHWJ4zJuwW72hTLCPfNBzmwNKuUscmIA/0Jd6CqN3OmU9ZEYpMAE5nYC1a5a0C+Caxe Zc9+TQjkE5JGRm/RBhLJ2rIkV4G+EIYJxvblR5apSCyyK65+luleUn9I3UGYvMZneHNe KgXg== 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=3EC/ILC9E1z+FmTz2M5OzLffDsaNAiYhutjbzlwCvcM=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=OFDHir5pl8d3sJZ6ofrnzi65+SM3jnmBhILyGacqdRC4hs/rkKbWyrnGBqDbbN04Pe iyKuLLVj+C5BNC6GA5M8pi0VQ7B11kXwLs8WmsK/PXYa988u1JT0eiYonkdxc1pBJRu7 o4R9hMiVhX9zTGfL5nkRv7HDJrQkJ0l0f4DPwfNOWGI0cJ5alg6RHtOn5nVpIutFAvb2 PmnCCibG/2xiAqfzPUMkbVUYX8VTOahKebJ/Ehk0Yfku8MHIOD/VNH9hZk2fg54MQjyW JWLuPWIIjvfN/HuCvgJ9duQiCJ/fyfmvGGoSjup8YYGxksK1j9IvdC3biZLUf1awmPOG c9pw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MgdCbOPQ; 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-794f2f1738dsi65941485a.170.2024.05.30.15.07.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:29 -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=MgdCbOPQ; 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 1sCnuq-0007Lu-C7; Thu, 30 May 2024 18:06:32 -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 1sCnum-0007KV-Sr for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:28 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnuk-0005EN-Io for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:28 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1f4a0050b9aso3138915ad.2 for ; Thu, 30 May 2024 15:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106783; x=1717711583; 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=3EC/ILC9E1z+FmTz2M5OzLffDsaNAiYhutjbzlwCvcM=; b=MgdCbOPQJioOn9zobO0FZqGGjuVsT/bxlALyd+wDzV8CF+i89/ia2BybWljuS8kn1j 0VTnVfjMQwVsE+dQkavNfSAFYzGA2x0KZXl25txoYKL6UL4edHYu36w4qb73UrmvG8iO YHNlN5jwELjOPjh1p47bp93Dpo5LPxmca/IY2jVepTM3EpsegF7BwpqjRBiboXMSD8Tt kiZzGUA00sBe6PRcU75FgVz9ZTz8gKd6HbxSbt03BFK/ft8MmPGaLzT9O1q+GqcdqjIN tz7MbVMcO5t21GFt0aB4NribxtzFACWkYr0/0I9oDmkiodzsbQZvsTOBt8ebcjtxiyqN 6UXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106783; x=1717711583; 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=3EC/ILC9E1z+FmTz2M5OzLffDsaNAiYhutjbzlwCvcM=; b=vzHPEQkwmRd40HmjKP/tkyyUrQFXbAsBLpFUlll4ydmhAU7lgl183YgrKf52djs5YV /8CuWe9ehf0YN354hk01/DZP+irxhnS5tnJe31fWBX/aUvLSwu5SBAN5iucVaYjfo7gF Yb0KQMjOFfHzdociHUL1AxUmnGVzKVhkRBShpzK1I6Jv9Dtv2rJ8+aJS1GwiHXPCu80e tDTUJf6PAwZ61SOaWXkkpMDqIA8JQWtxXjpsEyOcQ5PuU8L759iYLKyCNUSbAr6r62Q9 Yq+WXy4TSqTNByv27isesLJOOkzKbfW0cz0ePdcZYKPrMOjwip9huqk5S94NueFTmLlj fSXg== X-Gm-Message-State: AOJu0YxS3qlVpypwm7cCTx0tFbMsYNgn3sOxafy9eWw+pFYT3gngaMuI cYlIjzo4nYG++22mEERNplj3bvkW2TL6hkX7qSsTVohzUqJBuDrtKe98dKTd9O0eKH+GqBBacO4 L3ak= X-Received: by 2002:a17:902:e5c9:b0:1f4:75e8:2e9c with SMTP id d9443c01a7336-1f636fd22cemr1915875ad.11.1717106783300; Thu, 30 May 2024 15:06:23 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:22 -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_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 6/6] contrib/plugins: add ips plugin example for cost modeling Date: Thu, 30 May 2024 15:06:10 -0700 Message-Id: <20240530220610.1245424-7-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 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62f.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 This plugin uses the new time control interface to make decisions about the state of time during the emulation. The algorithm is currently very simple. The user specifies an ips rate which applies per core. If the core runs ahead of its allocated execution time the plugin sleeps for a bit to let real time catch up. Either way time is updated for the emulation as a function of total executed instructions with some adjustments for cores that idle. Examples -------- Slow down execution of /bin/true: $ num_insn=$(./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so -d plugin /bin/true |& grep total | sed -e 's/.*: //') $ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips.so,ips=$(($num_insn/4)) /bin/true real 4.000s Boot a Linux kernel simulating a 250MHz cpu: $ /build/qemu-system-x86_64 -kernel /boot/vmlinuz-6.1.0-21-amd64 -append "console=ttyS0" -plugin ./build/contrib/plugins/libips.so,ips=$((250*1000*1000)) -smp 1 -m 512 check time until kernel panic on serial0 Tested in system mode by booting a full debian system, and using: $ sysbench cpu run Performance decrease linearly with the given number of ips. Signed-off-by: Pierrick Bouvier --- contrib/plugins/ips.c | 164 +++++++++++++++++++++++++++++++++++++++ contrib/plugins/Makefile | 1 + 2 files changed, 165 insertions(+) create mode 100644 contrib/plugins/ips.c diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c new file mode 100644 index 00000000000..db77729264b --- /dev/null +++ b/contrib/plugins/ips.c @@ -0,0 +1,164 @@ +/* + * ips rate limiting plugin. + * + * This plugin can be used to restrict the execution of a system to a + * particular number of Instructions Per Second (ips). This controls + * time as seen by the guest so while wall-clock time may be longer + * from the guests point of view time will pass at the normal rate. + * + * This uses the new plugin API which allows the plugin to control + * system time. + * + * Copyright (c) 2023 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +/* how many times do we update time per sec */ +#define NUM_TIME_UPDATE_PER_SEC 10 +#define NSEC_IN_ONE_SEC (1000 * 1000 * 1000) + +static GMutex global_state_lock; + +static uint64_t max_insn_per_second = 1000 * 1000 * 1000; /* ips per core, per second */ +static uint64_t max_insn_per_quantum; /* trap every N instructions */ +static int64_t virtual_time_ns; /* last set virtual time */ + +static const void *time_handle; + +typedef struct { + uint64_t total_insn; + uint64_t quantum_insn; /* insn in last quantum */ + int64_t last_quantum_time; /* time when last quantum started */ +} vCPUTime; + +struct qemu_plugin_scoreboard *vcpus; + +/* return epoch time in ns */ +static int64_t now_ns(void) +{ + return g_get_real_time() * 1000; +} + +static uint64_t num_insn_during(int64_t elapsed_ns) +{ + double num_secs = elapsed_ns / (double) NSEC_IN_ONE_SEC; + return num_secs * (double) max_insn_per_second; +} + +static int64_t time_for_insn(uint64_t num_insn) +{ + double num_secs = (double) num_insn / (double) max_insn_per_second; + return num_secs * (double) NSEC_IN_ONE_SEC; +} + +static void update_system_time(vCPUTime *vcpu) +{ + int64_t elapsed_ns = now_ns() - vcpu->last_quantum_time; + uint64_t max_insn = num_insn_during(elapsed_ns); + + if (vcpu->quantum_insn >= max_insn) { + /* this vcpu ran faster than expected, so it has to sleep */ + uint64_t insn_advance = vcpu->quantum_insn - max_insn; + uint64_t time_advance_ns = time_for_insn(insn_advance); + int64_t sleep_us = time_advance_ns / 1000; + g_usleep(sleep_us); + } + + vcpu->total_insn += vcpu->quantum_insn; + vcpu->quantum_insn = 0; + vcpu->last_quantum_time = now_ns(); + + /* based on total number of instructions, what should be the new time? */ + int64_t new_virtual_time = time_for_insn(vcpu->total_insn); + + g_mutex_lock(&global_state_lock); + + /* Time only moves forward. Another vcpu might have updated it already. */ + if (new_virtual_time > virtual_time_ns) { + qemu_plugin_update_ns(time_handle, new_virtual_time); + virtual_time_ns = new_virtual_time; + } + + g_mutex_unlock(&global_state_lock); +} + +static void vcpu_init(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu = qemu_plugin_scoreboard_find(vcpus, cpu_index); + vcpu->total_insn = 0; + vcpu->quantum_insn = 0; + vcpu->last_quantum_time = now_ns(); +} + +static void vcpu_exit(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu = qemu_plugin_scoreboard_find(vcpus, cpu_index); + update_system_time(vcpu); +} + +static void every_quantum_insn(unsigned int cpu_index, void *udata) +{ + vCPUTime *vcpu = qemu_plugin_scoreboard_find(vcpus, cpu_index); + g_assert(vcpu->quantum_insn >= max_insn_per_quantum); + update_system_time(vcpu); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n_insns = qemu_plugin_tb_n_insns(tb); + qemu_plugin_u64 quantum_insn = + qemu_plugin_scoreboard_u64_in_struct(vcpus, vCPUTime, quantum_insn); + /* count (and eventually trap) once per tb */ + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, quantum_insn, n_insns); + qemu_plugin_register_vcpu_tb_exec_cond_cb( + tb, every_quantum_insn, + QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_COND_GE, + quantum_insn, max_insn_per_quantum, NULL); +} + +static void plugin_exit(qemu_plugin_id_t id, void *udata) +{ + qemu_plugin_scoreboard_free(vcpus); +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int argc, + char **argv) +{ + for (int i = 0; i < argc; i++) { + char *opt = argv[i]; + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); + if (g_strcmp0(tokens[0], "ips") == 0) { + max_insn_per_second = g_ascii_strtoull(tokens[1], NULL, 10); + if (!max_insn_per_second && errno) { + fprintf(stderr, "%s: couldn't parse %s (%s)\n", + __func__, tokens[1], g_strerror(errno)); + return -1; + } + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + vcpus = qemu_plugin_scoreboard_new(sizeof(vCPUTime)); + max_insn_per_quantum = max_insn_per_second / NUM_TIME_UPDATE_PER_SEC; + + time_handle = qemu_plugin_request_time_control(); + g_assert(time_handle); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_register_vcpu_exit_cb(id, vcpu_exit); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index 0b64d2c1e3a..449ead11305 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -27,6 +27,7 @@ endif NAMES += hwprofile NAMES += cache NAMES += drcov +NAMES += ips ifeq ($(CONFIG_WIN32),y) SO_SUFFIX := .dll