From patchwork Fri May 19 17:04:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683907 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1052683wrt; Fri, 19 May 2023 10:06:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nhmzaT31ZTHP3KdlmO+K4mrbfyN4OiaixA0DSnbffKJMijAo988WxopvJooyG6m3ADa0u X-Received: by 2002:a05:7500:e3a3:b0:108:7016:58f0 with SMTP id qs35-20020a057500e3a300b00108701658f0mr185369gab.35.1684515989674; Fri, 19 May 2023 10:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684515989; cv=none; d=google.com; s=arc-20160816; b=iqwGCMh912QvGkTYlj95T11D3s1BWfy3B+N7K+V3mm3/vpCuKpBlGqAJHH2nxsSk1K X3FZ+rDbFsxqHN0lumoXk87Jr5aCstG/XiDnymB0oT+AAVWJOJRbBN9JEG7llX07evXA zue+alds6KdI7WBUn0eFPkZf1PT2W9KYa3AbgduDHyxK2v37824IZhkn2GlqSu978EKH BuRIudjokjW9gcxZS4oQ/1ye58NGyopgz2Ipd8wcf0T68t2Q0WX2rKBQxU0kaDJ9PFsj +zX28MRamegTEPuKgG6jgE6eWckCWYTJ611RVvbqfNcIT+vatVzvpbKkNYb1q1ogNZTp M0Ng== 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=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=JFrHUECH6Z8Yj8ANK93BsFY6L4spzVwMLYv+3KcJA9Wn0h6TdiI4Cf7Ipx//urnRDL RgCapvv/9fYNqc76jBKO1ZMF0iWCue6oqzB/AOkhjffb/altmTFf1df5IlhQbaJ9I3qw iHjp3l9Ha6n1QFJHCXz2VEKzFauY9iPFZPPU+esfYYRDz4RIXP2/P1m41qNmbTKy5PLl MmmRDHWdXwL/+QYImlxwnd9HHUCddJA7xELmWx8AmFWMXIRJQJlzZFTWbYtcQxDLGIPm tPf4XpJ/bvfsjJCTte2IA9Webrn3Yuun1chRn5Jlm3oqxTzedm6JtkghzrmbX1qUFa9W mrwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EuQ57wgt; 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 oo16-20020a05620a531000b007577c70d297si2809098qkn.479.2023.05.19.10.06.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:06: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=EuQ57wgt; 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 1q03Xf-0002Ip-Hn; Fri, 19 May 2023 13:05:23 -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 1q03XQ-0002CV-I4 for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:10 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XI-0005Us-2T for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:08 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f41d087a84so7781615e9.1 for ; Fri, 19 May 2023 10:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515898; x=1687107898; 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=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=EuQ57wgtlJ90JbZ1ILULSt5wVq8/gCXRuY1wabUom2lkgbqajWQbhB0ztsk5u8tXQl cW1rMl3Z+rLQRiDwUus7v4kYUbd75xgtj7poLYWYRgbJd5NysHEHjrBp54UpkfSQ9lXF wCoxDZVMqi/7mO6d6iZzIAkfswUMyRPr7DSChGmOxzcCjxd5RAvE7EHlKpM63EGj+3sc RGtLIDP157QJ3owUJj9SqTjV2W0qpH4yh5ocGspIgtsygMJpQLuUn7tJ+ytKE37ysR37 u/BcTRrRBmuSudvTEZzH9HbLtcrbDFJ2zKBLtDhWHsymocmCoP20inGCi52jMhy9o+wT iS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515898; x=1687107898; 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=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=hISNl2JHZwLo6y5/wte2h1rZiD07nEY4b+6HbwLtItMVz85udFEdztx+VOVmPbenoa yBhJvXZ1tHPu7x8FWpKNvdRYEwRszOvP5WCIJDhrHKI1Pbcldlyl8PW/oI8NBOv6EfX1 YMqlCMzE/9bqUGhekESG9MpRXqJoFfHtJKANobCE8x3gEpg24oq6TxuMsHQmgRdxZ8lr JY+pN2vXJP15Y6kzH5lSl0KxK7HQxU3G3voXDQQDuE8oobUaWEPyWH9UrI7oW9pV0TF0 UqVFcFypG+lIQRB7m65Kdhf0FkfbxHU7yaX3YkHRlVMtMnAlOvt97eiXGJxlnOaYEQVS NC9A== X-Gm-Message-State: AC+VfDz4Ok2eHrGuu/DgZMtwzYUZgBGi+qttYRL25teuSyzaFnkn9OIp uQhHJ2peJurYp8SckZs3J7aGGA== X-Received: by 2002:a05:600c:230e:b0:3f4:2610:5cc5 with SMTP id 14-20020a05600c230e00b003f426105cc5mr1990264wmo.5.1684515898329; Fri, 19 May 2023 10:04:58 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id n7-20020a7bcbc7000000b003f318be9442sm2948436wmi.40.2023.05.19.10.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 876961FFC1; Fri, 19 May 2023 18:04:55 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [RFC PATCH 6/8] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time Date: Fri, 19 May 2023 18:04:52 +0100 Message-Id: <20230519170454.2353945-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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=unavailable 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 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. Signed-off-by: Alex Bennée --- include/qemu/timer.h | 15 +++++++++++++++ softmmu/qtest.c | 24 ++---------------------- util/qemu-timer.c | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index ee071e07d1..9a1a42a400 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/softmmu/qtest.c b/softmmu/qtest.c index 34bc9e1f49..3cd6c11f5a 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -336,26 +336,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)) @@ -732,7 +712,7 @@ 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)); @@ -758,7 +738,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 6a0de33dd2..213114be68 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; +}