From nobody Mon Nov 25 05:24:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717106872; cv=none; d=zohomail.com; s=zohoarc; b=IiZz5gSvfYGAhqpt21PPAsCPwvK/vX3V62Xg/Waqox/wz1zmyQQCUxvBfjiY6C3LhccLmUeIcWBXl6TVgDBS6oWn32M9M8GuvfRHIFF4es1qApnRngqtr9y2JoZf1eNXFkh7OLeYePm7acJOgqAEqyBfn/nQn39WuC/WZhs5Uds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717106872; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=V0eAnEgvAW0o/NF4J1A+axOTDsU9ayygb7e+nKl6WyIxiTLxINW65x7aq6PkF32NnC3YDVKtzSAB/rNPDupL5dVQGEub+frRIcQouEW9jTFm+3AxsYLaJxYAa67tM9ZHsTESphzhUGAdX+3n5FSFRmmtyl3v1YUc3COjmQXa/iU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717106872019663.2662423801897; Thu, 30 May 2024 15:07:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCnuj-0007JQ-1q; Thu, 30 May 2024 18:06:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCnuf-0007IN-DI for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:21 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnud-0005CS-AN for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:20 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1f6262c0a22so5284325ad.1 for ; Thu, 30 May 2024 15:06:17 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323dde39sm2732615ad.167.2024.05.30.15.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106775; x=1717711575; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=Pm2eh5lCD9p8QPEBbYWdh9t+NKmd2GzPG7Ocx1+USyLnQrGruRwa7qRat+VpBYqmN6 1aOEQkB8WrE1cTTs3wVUgDJvi8uvy+pcJv/o8Wgs9p69q1/29czYFSShTBD5eOW7jhjV Nw1irKV85k7Ae8aa8Xttdkr2GQuWM7ZmJQl/S08LqKrnGgZqEstSU62mchVD7832ZVRm ufkt3shshalZ/zKHMPPMnhWfeQ3IGOWLdyfJjQ439t09mSSNMxeIPNa/QENcK/97G2RO b1RwPF5eehal6hUSKSfWth4OUUSnfW3VL9sG3Hr65yjsWRzmEHQ7mhy4yGwgYXsj9B9A ho+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106775; x=1717711575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=K69IpgFHQolxwlvt2yz+9MX/vTFqMf2YIwsnESm/5FkrQjT9A7w9b3/0YiPtUOD3MB kfMuWY9RhjzsZwWZDRGhzZS6+X6Zzv1021aio69jW1cAxGqzHZdY1gudkd+eUuKYFiJB hxmMUDpWeg40nNn898HD+2qC5WRzRRiUf6NsvLQiCZYhUWjk9Hn2ijagCo6ote0MxqMf FEuYisuGicJYUbYmoG4MQw/zNp3BOFiXSjw7p23WriX2kgmlqHoDXpjCmN1o7906OpEQ 2tv5K1NRt3oCcqUUhUgiHbmvYd+lnIIJjY+FUOazic3hhWPiu1BGmyOxXaC3vp7y/WH7 GUNg== X-Gm-Message-State: AOJu0YwzWGqJhXElf34WonwzS+rKB/BzZ8rvV/FD4Nm9xrbzxXQmOXei chPA0KGftL4OegHRpPZ1TYMZbgjwHoMjBhQV45PcLf8z0BUtgj3P3bn+iisWUh+XOYYSoDq0Kar mBK8= X-Google-Smtp-Source: AGHT+IFJgq7IHkYgaMq+ZY9xjZiNSxP1WocFM5EPYdFKpLlJT88A2pEGM7b6yzZxiFY92wRf+PAB1A== X-Received: by 2002:a17:903:2409:b0:1f6:846:69a1 with SMTP id d9443c01a7336-1f61be7b12emr45302475ad.20.1717106775185; Thu, 30 May 2024 15:06:15 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/6] sysemu: add set_virtual_time to accel ops Date: Thu, 30 May 2024 15:06:05 -0700 Message-Id: <20240530220610.1245424-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530220610.1245424-1-pierrick.bouvier@linaro.org> References: <20240530220610.1245424-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717106872153100001 From: Alex Benn=C3=A9e We are about to remove direct calls to individual accelerators for this information and will need a central point for plugins to hook into time changes. From: Alex Benn=C3=A9e Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier --- include/sysemu/accel-ops.h | 18 +++++++++++++++++- include/sysemu/cpu-timers.h | 3 ++- ...et-virtual-clock.c =3D> cpus-virtual-clock.c} | 5 +++++ system/cpus.c | 11 +++++++++++ stubs/meson.build | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) rename stubs/{cpus-get-virtual-clock.c =3D> cpus-virtual-clock.c} (68%) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index ef91fc28bbd..a0886722305 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -20,7 +20,12 @@ typedef struct AccelOpsClass AccelOpsClass; DECLARE_CLASS_CHECKERS(AccelOpsClass, ACCEL_OPS, TYPE_ACCEL_OPS) =20 -/* cpus.c operations interface */ +/** + * struct AccelOpsClass - accelerator interfaces + * + * This structure is used to abstract accelerator differences from the + * core CPU code. Not all have to be implemented. + */ struct AccelOpsClass { /*< private >*/ ObjectClass parent_class; @@ -44,7 +49,18 @@ struct AccelOpsClass { =20 void (*handle_interrupt)(CPUState *cpu, int mask); =20 + /** + * @get_virtual_clock: fetch virtual clock + * @set_virtual_clock: set virtual clock + * + * These allow the timer subsystem to defer to the accelerator to + * fetch time. The set function is needed if the accelerator wants + * to track the changes to time as the timer is warped through + * various timer events. + */ int64_t (*get_virtual_clock)(void); + void (*set_virtual_clock)(int64_t time); + int64_t (*get_elapsed_ticks)(void); =20 /* gdbstub hooks */ diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h index d86738a378d..7bfa960fbd6 100644 --- a/include/sysemu/cpu-timers.h +++ b/include/sysemu/cpu-timers.h @@ -96,8 +96,9 @@ int64_t cpu_get_clock(void); =20 void qemu_timer_notify_cb(void *opaque, QEMUClockType type); =20 -/* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface= */ +/* get/set VIRTUAL clock and VM elapsed ticks via the cpus accel interface= */ int64_t cpus_get_virtual_clock(void); +void cpus_set_virtual_clock(int64_t new_time); int64_t cpus_get_elapsed_ticks(void); =20 #endif /* SYSEMU_CPU_TIMERS_H */ diff --git a/stubs/cpus-get-virtual-clock.c b/stubs/cpus-virtual-clock.c similarity index 68% rename from stubs/cpus-get-virtual-clock.c rename to stubs/cpus-virtual-clock.c index fd447d53f3c..af7c1a1d403 100644 --- a/stubs/cpus-get-virtual-clock.c +++ b/stubs/cpus-virtual-clock.c @@ -6,3 +6,8 @@ int64_t cpus_get_virtual_clock(void) { return cpu_get_clock(); } + +void cpus_set_virtual_clock(int64_t new_time) +{ + /* do nothing */ +} diff --git a/system/cpus.c b/system/cpus.c index f8fa78f33d4..d3640c95030 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -229,6 +229,17 @@ int64_t cpus_get_virtual_clock(void) return cpu_get_clock(); } =20 +/* + * Signal the new virtual time to the accelerator. This is only needed + * by accelerators that need to track the changes as we warp time. + */ +void cpus_set_virtual_clock(int64_t new_time) +{ + if (cpus_accel && cpus_accel->set_virtual_clock) { + cpus_accel->set_virtual_clock(new_time); + } +} + /* * return the time elapsed in VM between vm_start and vm_stop. Unless * icount is active, cpus_get_elapsed_ticks() uses units of the host CPU c= ycle diff --git a/stubs/meson.build b/stubs/meson.build index 3b9d42023cb..a1deafde08c 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -28,7 +28,7 @@ endif if have_block or have_ga stub_ss.add(files('replay-tools.c')) # stubs for hooks in util/main-loop.c, util/async.c etc. - stub_ss.add(files('cpus-get-virtual-clock.c')) + stub_ss.add(files('cpus-virtual-clock.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('graph-lock.c')) if linux_io_uring.found() --=20 2.39.2 From nobody Mon Nov 25 05:24:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717106866; cv=none; d=zohomail.com; s=zohoarc; b=Vo8uVPxDqc0dpq6fCq9A1A3qlCGUA74takvJPi+zdi/jvO95Em2NFpOiCrqk2OjwQcMLcSr0ysYwi3S0B1kf8eOeSitH1b6CrHxzwq3QBTTkYF4VpMewc5e1ewxMcdeVxgG85LIlQKDTvjoZ22ZOkWEMQaJjFFR35stBpWkM2SM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717106866; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; b=Tgw74uFn/UuBrGicJH4xZDS8CUKrkuhwZur8HqBbOgM3P7REb9AisDt/1e5QSLqKvaeCzwdmD19vXxgZ52pjrdvC+4oPhAbxPxlMbxi9W34TrMdXEBl4temV6FsswBp45CrljpPtQz1oqIS0pcsWYoWHHAHjsbDhXvObojqHAmI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717106866483694.1593629848373; Thu, 30 May 2024 15:07:46 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IHvXyuRMaWfcMFit2oU/D04NDtEBg7V53ewxmsrrRo11HAQLdnFXBVQBUELxvJuTTM0jDd4YQ== 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717106868136100003 From: Alex Benn=C3=A9e 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=C3=A9e Signed-off-by: Alex Benn=C3=A9e 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 *, c= onst char *), void qtest_server_inproc_recv(void *opaque, const char *buf); =20 int64_t qtest_get_virtual_clock(void); +void qtest_set_virtual_clock(int64_t count); #endif =20 #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, v= oid *data) =20 ops->create_vcpu_thread =3D dummy_start_vcpu_thread; ops->get_virtual_clock =3D qtest_get_virtual_clock; + ops->set_virtual_clock =3D qtest_set_virtual_clock; }; =20 static const TypeInfo qtest_accel_ops_type =3D { 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); } =20 -static void qtest_set_virtual_clock(int64_t count) +void qtest_set_virtual_clock(int64_t count) { qatomic_set_i64(&qtest_clock_counter, count); } =20 static void qtest_clock_warp(int64_t dest) { - int64_t clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + int64_t clock =3D cpus_get_virtual_clock(); AioContext *aio_context; assert(qtest_enabled()); aio_context =3D qemu_get_aio_context(); @@ -348,7 +348,7 @@ static void qtest_clock_warp(int64_t dest) QEMU_TIMER_ATTR_ALL); int64_t warp =3D qemu_soonest_timeout(dest - clock, deadline); =20 - qtest_set_virtual_clock(qtest_get_virtual_clock() + warp); + cpus_set_virtual_clock(cpus_get_virtual_clock() + warp); =20 qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); --=20 2.39.2 From nobody Mon Nov 25 05:24:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717106849; cv=none; d=zohomail.com; s=zohoarc; b=nq3mj8XQeAi8zkTobRX+4l7gqeJKoxWoXStY4rMpED25M5/SefTMKSBis8hR9CaFF0Ta6Fy4XKoCI6pS9hzdJl85tmQ9pYPQcm6slBXIyfYqJJ0pFN4DSFB+fRPO0giJfQdlJqk2jiYf6RAwb8WgEg8ww1AVbxns3A1iV2TGUT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717106849; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; b=h0YoqqhDO8eIa2VDibbAhVpwfQ0Gfqt3GKY9WtOCqC4RAYyeVtMrk4L0aHs6doCmBNUpdWhv17Z19rSWd3CNQOyggBG7wW6us7bc1AHtDtxmw4lHdjJ8uppxUM45M9pmYEPglxOaF22W2oFtlXME3Awr2ZkYXgRHKJijkBIEVQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717106849016684.2816729725339; Thu, 30 May 2024 15:07:29 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IG/jYyeQcZiuf9ljWFN1Dhgq28Tg4uZyMKl5U9NF8eHtRawR01z8X1ffEb4PuvzYy07oqh6rw== 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717106850117100004 From: Alex Benn=C3=A9e 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=C3=A9e Signed-off-by: Alex Benn=C3=A9e 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); =20 +/** + * 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); =20 /* * 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); } =20 -static void qtest_clock_warp(int64_t dest) -{ - int64_t clock =3D cpus_get_virtual_clock(); - AioContext *aio_context; - assert(qtest_enabled()); - aio_context =3D qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, - QEMU_TIMER_ATTR_ALL); - int64_t warp =3D 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 =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - } - qemu_clock_notify(QEMU_CLOCK_VIRTUAL); -} - static bool (*process_command_cb)(CharBackend *chr, gchar **words); =20 void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) @@ -755,7 +735,8 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) ns =3D 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, gch= ar **words) g_assert(words[1]); ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); g_assert(ret =3D=3D 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) } } =20 +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) =20 return progress; } + +int64_t qemu_clock_advance_virtual_time(int64_t dest) +{ + int64_t clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + AioContext *aio_context; + aio_context =3D qemu_get_aio_context(); + while (clock < dest) { + int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); + int64_t warp =3D 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 =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + } + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); + + return clock; +} --=20 2.39.2 From nobody Mon Nov 25 05:24:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171710686032936.54843530793096; Thu, 30 May 2024 15:07:40 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IF0Rdk9P1U6UuKgC0lg8hFnkqj6WatX1CepD5W4ec+rVHUVakkto5fjdubC2r7ejxLHoJ78gQ== 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1717106862133100007 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 ch= ar *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 =20 #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" =20 +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) } } =20 -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); =20 void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) --=20 2.39.2 From nobody Mon Nov 25 05:24:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717106848; cv=none; d=zohomail.com; s=zohoarc; b=ETSrtnyywuQLzJ1i5RXLKW5Vvr1UdilIsVc31ij2ezSOoFyiRD0rlKJLUDnjIZQBAXydykKUh8eWeltbcvF18OrxxpCGdJkSrB+JYUiM8f2V8yJBY0vWSh3SsMQXGvh0uGJBAdvMki14Li7oud88i0CtWa5++QU20Q1xy+mVIuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717106848; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=hWSi3h3QGzhfTN1K2H0rTrAVMhe2fLQIr+Srxs8ygYMAHkc3QvsJdEt6D3KHvFvBZO8aKaf2Dq4buaOzhyaNQLOtBAoG5xJw8oqp51GXzxpRoYo2lLGSo///rsSf4imEDYqPeEzxAqO/uiTMnWGPesrs4jshDfKkVS7K4SUtUnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717106848019551.0866751646391; Thu, 30 May 2024 15:07:28 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEA3toYJoWKwAsW1/f2O+GKOo6Rs8aShA58gsZNGoiCW+r4/wkuZv8MReQr9PDRQPpxEaaMVA== 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717106850082100003 From: Alex Benn=C3=A9e 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=C3=A9e Signed-off-by: Alex Benn=C3=A9e 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); =20 +/** + * 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_in= dex, 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 =3D true; + return &has_control; + } + return NULL; +} + +static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data dat= a) +{ + int64_t new_time =3D data.host_ulong; + qemu_clock_advance_virtual_time(new_time); +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ + if (handle =3D=3D &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; }; --=20 2.39.2 From nobody Mon Nov 25 05:24:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717106849; cv=none; d=zohomail.com; s=zohoarc; b=P22ypV1BsndaEl6dWYmDaXlriNyzZzhVDhHglwBdQGLC+Brz93WYcLuqxVYbwKOQBq0mZa/Ko7VnFCF76cjNFi1fRz89CO2Jd2ZlqUyl+kscst32c3TrkAywcPrcYs1yoVPzY2I9TOqlDZQ+fbTc/6+/hA4XsXTWBCiWzOOsH/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717106849; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3EC/ILC9E1z+FmTz2M5OzLffDsaNAiYhutjbzlwCvcM=; b=LGuRS6iCUW/cqjQ9K/WJj0Qkk3sY9ywOaGVBktHBmSuodLyJ8s7hEx0Jz2cUxE3iMzE4PWjGCYdQOU+VrhSClDjDvweNTD2NorkdMH4zqmkjRq8z9hpgL2YNZcu089IAR2N8rV6RgxvxNCssw/SJgMvITZsNes2xd8dB5QZIK1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717106849495376.73621860422134; Thu, 30 May 2024 15:07:29 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IHgLRH7MLZnB0Rir6NLOSnhOhKo/5dkTGYiRCRfn3SRx1dE9iyyeSEcctvRyPo5hwzyK50W3g== 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717106850164100005 Content-Type: text/plain; charset="utf-8" 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=3D$(./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=3D= $(($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 "c= onsole=3DttyS0" -plugin ./build/contrib/plugins/libips.so,ips=3D$((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 =3D 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 =3D 1000 * 1000 * 1000; /* ips per cor= e, 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 =3D 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 =3D (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 =3D now_ns() - vcpu->last_quantum_time; + uint64_t max_insn =3D num_insn_during(elapsed_ns); + + if (vcpu->quantum_insn >=3D max_insn) { + /* this vcpu ran faster than expected, so it has to sleep */ + uint64_t insn_advance =3D vcpu->quantum_insn - max_insn; + uint64_t time_advance_ns =3D time_for_insn(insn_advance); + int64_t sleep_us =3D time_advance_ns / 1000; + g_usleep(sleep_us); + } + + vcpu->total_insn +=3D vcpu->quantum_insn; + vcpu->quantum_insn =3D 0; + vcpu->last_quantum_time =3D now_ns(); + + /* based on total number of instructions, what should be the new time?= */ + int64_t new_virtual_time =3D 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 =3D new_virtual_time; + } + + g_mutex_unlock(&global_state_lock); +} + +static void vcpu_init(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + vcpu->total_insn =3D 0; + vcpu->quantum_insn =3D 0; + vcpu->last_quantum_time =3D now_ns(); +} + +static void vcpu_exit(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + update_system_time(vcpu); +} + +static void every_quantum_insn(unsigned int cpu_index, void *udata) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + g_assert(vcpu->quantum_insn >=3D 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 =3D qemu_plugin_tb_n_insns(tb); + qemu_plugin_u64 quantum_insn =3D + 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 ar= gc, + char **argv) +{ + for (int i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); + if (g_strcmp0(tokens[0], "ips") =3D=3D 0) { + max_insn_per_second =3D 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 =3D qemu_plugin_scoreboard_new(sizeof(vCPUTime)); + max_insn_per_quantum =3D max_insn_per_second / NUM_TIME_UPDATE_PER_SEC; + + time_handle =3D 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 +=3D hwprofile NAMES +=3D cache NAMES +=3D drcov +NAMES +=3D ips =20 ifeq ($(CONFIG_WIN32),y) SO_SUFFIX :=3D .dll --=20 2.39.2