From nobody Mon Nov 25 11:49:07 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=1715898126; cv=none; d=zohomail.com; s=zohoarc; b=V6psv/GY6dfvwW/rUBNvPoTbTBnHOc5aXkAsQTJXxbx2/AQUU3pDHM4kOwOlkT6rOL9OB9GvCyp09UmqO8Y6cM9PmbCrrqpwEi666AyNYoi3JryFEja4Vf/CpqJ9Z25+q3f4kj8DYVufGIZg+PFKaS9EedjOLMfzcEc4aZCU1i8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715898126; 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=i4r8M+Ho2ethkxiN2yuJrvpiAjkoen/RLNiEY1Q1RNE=; b=C8NSYq12SeeZnLSgqFGVnu93Mnj912cXGyaSxtn8RcTvgyozTLmUMZJDHRKMr5x+Lu0ByeykIdFJYFOi1xGZCkPGff63Fi8f0Kqf/IcZ0f4OwiNiv+AGyuI16PPBTsr6QVosj2zJ2v1ekgP0ZpfiLRzOu5if+W8OPV+xLurFXCU= 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 1715898126239118.48879134720755; Thu, 16 May 2024 15:22:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7jTS-0006ij-Kl; Thu, 16 May 2024 18:21:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s7jTL-0006dM-Lv for qemu-devel@nongnu.org; Thu, 16 May 2024 18:21:13 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7jTI-0003Bk-KE for qemu-devel@nongnu.org; Thu, 16 May 2024 18:21:11 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6f44b5e7f07so654318b3a.2 for ; Thu, 16 May 2024 15:21:08 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66476sm13589219b3a.28.2024.05.16.15.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 15:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715898067; x=1716502867; 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=i4r8M+Ho2ethkxiN2yuJrvpiAjkoen/RLNiEY1Q1RNE=; b=yllkz4Z3t/5N/UvDrAdPY03ObjGaXzGszBhGqxguy3F8cctC9fZnvuYrpC9/VfYX7A 8zuzYSapUEGzN66ctyo7QEuC1xCiftxXmfoRqBuX36qCA5c//dpLOSIRLq3EQkWN9cE1 b3k4IRBesAURKIYYf6uXxcXWfEBJ0siQWOdw50wmZU1oN1CQWKXP1jCNnkOhKJrBgvwh 6vWpwLPBfbGIX1uhTZ05oXNbwz8FhfMQIKsB7rxiKMsctrk+UC/dpxfr20+utxc+MXTz FIDe9peYLo0LVD5MDhEL79fb4FfR7HcTVxubzz7mEQQnLpc3+25pNMaiYppzGSfOx/Z7 3cMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715898067; x=1716502867; 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=i4r8M+Ho2ethkxiN2yuJrvpiAjkoen/RLNiEY1Q1RNE=; b=DqkMuq6/hSTFLjpKb41CWyJ4F1eqbD7KvwVMayBTnNR6ScsHUfvtYRMCQOnvCR4Jkf NZO/g54B0MXkEbcv401TxcY2/XjHL6ug80gDeW/Zz+Giw2c7bLS16/InlsrNyakGQvLw sMrMOmRZ9yw4K9Sp9LHMqZJSCZNTK5wX0u62ZQWiUMmFtZjo8AhxD8mn0G0qOKOIfQun VZ2H1XFIJsscWA10/7JrEXAFUXlanlAtqeDe80LTDRKJ//9ukHvG/h0rGhgUqSNo31Ms KMOodb29+H/X1C5p5lXKgYub1TI63J1/izB3FCXkBBi/0NStCEgtWXRUGECGVPejgu+c krcg== X-Gm-Message-State: AOJu0Yz2raHN3WWWT9LDac2tEhUFXEgy2a8evQXV6/pxZ1fN1HewOVyf 3QF9292DdMd4X1tytZjp3b4eK4uueh9xeZP0BE3czcKpIyJcUtdGoy91WXlZXBqQ8Ru+DLBjEsL Nkzc= X-Google-Smtp-Source: AGHT+IFExEtugXKM2HJ10zCxYL1Tbk3wMCc6nhFReI3PFCdVBfz1QgkfFJ8nfD9vQpWcKjeKiCVXTA== X-Received: by 2002:a05:6a00:1a8f:b0:6f0:be31:8577 with SMTP id d2e1a72fcca58-6f4e036b56dmr21338731b3a.22.1715898066762; Thu, 16 May 2024 15:21:06 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Richard Henderson , Pierrick Bouvier , Paolo Bonzini Subject: [PATCH 3/5] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time Date: Thu, 16 May 2024 15:20:45 -0700 Message-Id: <20240516222047.1853459-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240516222047.1853459-1-pierrick.bouvier@linaro.org> References: <20240516222047.1853459-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1715898128304100003 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 --- 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