From nobody Thu Nov 6 03:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539861180857190.35005902099385; Thu, 18 Oct 2018 04:13:00 -0700 (PDT) Received: from localhost ([::1]:41676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD6Ed-0006Op-DH for importer@patchew.org; Thu, 18 Oct 2018 07:12:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD69H-0002dA-ST for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD69E-0008WC-HD for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:27 -0400 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]:42571) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD69E-0008TW-4K for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:24 -0400 Received: by mail-lf1-x144.google.com with SMTP id s10-v6so22221256lfc.9 for ; Thu, 18 Oct 2018 04:07:20 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id u77-v6sm4575811lja.37.2018.10.18.04.07.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 04:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6s46CLkP3WBKP3BFUmSls4Dh8c0Fi5LlejOEvPYz+to=; b=qSw08/nPRO0N/WJU10dG91r+fhZMopO/GUA5IjO8hZx6WRPo1ioTquxxag0Iy4iRmb J7Kg3doNDW0NllPJh/lvHQDZqMIC2/zvicdipEXI7953Zz1XaN+SQc+M/lST/xMYgeh1 D/6xlJ1CEtxYSAYcsNDHcW4z8tScrSe/WVCNKJDnHz6E1q2+zTSrZ9vXNHC+ITgf5zTp pVXyVXiUZeO6i9GDbqEbnc6QO72W/8PjVL2lhSTvzaGXcqwPbIikqoIovvIC3IQL3J3F YEt/OZc3oJ6lBz+GUF0N/EvrYZuJlTlN78nI0O3b7ZJd8XBFWmm8Kn01WsBW3XmKKXhb MLMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6s46CLkP3WBKP3BFUmSls4Dh8c0Fi5LlejOEvPYz+to=; b=pCPBY7elgl0vMYsYtSXW39LWHvJz7xxwoGMzKe7q7OfEVAdG6r1m1YMH/bS4WgoyVb hOkwvnNKPAlrl0tGRg8ZuJNiVk6NTG6heBNw4OYM9/x/w1oWf1aDKXPChoi5NfSRbHzR jqg2uP3KZFDK2pWYJCyrstKi/JMxil2YZozCitxV9s1m7P530wXADAb0tXuBYa+3P8qp ZJtl4ThN03zj1qIejnCKRoTdzkqIm8sn7aI9HvQ5b0AcRKVf2+otA/bokZasKJyabXxg P6XVv+LsybE8N2PwfUei4IgL6+ktmgzfBRjsf3dxGt99MMnFaJNQkGno0EMV12gpIGCq CCcg== X-Gm-Message-State: ABuFfogqJrUg73ntzFuexmgTDxPcgb2hapQiMQOsBOXW7BnIunFfIOWo Y/bitZDHhOrYQLHdXL3QdbTU2er7LqE= X-Google-Smtp-Source: ACcGV62eFiVyOl+XmcCbaJTv241kYzaec0T471SsWaRwdlMjjwBchB+DDhklnGYZy16dbKIHxqJCUA== X-Received: by 2002:a19:4411:: with SMTP id r17-v6mr19384981lfa.87.1539860838618; Thu, 18 Oct 2018 04:07:18 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 17:04:28 +0600 Message-Id: <18b1e7c8f155fe26976f91be06bde98eef6f8751.1539860473.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::144 Subject: [Qemu-devel] [PATCH v3 1/4] Revert some patches from recent [PATCH v6] "Fixing record/replay and adding reverse debugging" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Gerd Hoffmann , Pavel Dovgalyuk , Samuel Thibault , Paolo Bonzini , Artem Pisarenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" That patch series introduced new virtual clock type for use in external sub= systems. It breaks desired behavior in non-record/replay usage scenarios. This reverts commit 87f4fe7653baf55b5c2f2753fe6003f473c07342. This reverts commit 775a412bf83f6bc0c5c02091ee06cf649b34c593. This reverts commit 9888091404a702d7ec79d51b088d994b9fc121bd. Signed-off-by: Artem Pisarenko --- include/qemu/timer.h | 9 --------- slirp/ip6_icmp.c | 7 +++---- ui/input.c | 8 ++++---- util/qemu-timer.c | 2 -- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index a005ed2..39ea907 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -42,14 +42,6 @@ * In icount mode, this clock counts nanoseconds while the virtual * machine is running. It is used to increase @QEMU_CLOCK_VIRTUAL * while the CPUs are sleeping and thus not executing instructions. - * - * @QEMU_CLOCK_VIRTUAL_EXT: virtual clock for external subsystems - * - * The virtual clock only runs during the emulation. It stops - * when the virtual machine is stopped. The timers for this clock - * do not recorded in rr mode, therefore this clock could be used - * for the subsystems that operate outside the guest core. - * */ =20 typedef enum { @@ -57,7 +49,6 @@ typedef enum { QEMU_CLOCK_VIRTUAL =3D 1, QEMU_CLOCK_HOST =3D 2, QEMU_CLOCK_VIRTUAL_RT =3D 3, - QEMU_CLOCK_VIRTUAL_EXT =3D 4, QEMU_CLOCK_MAX } QEMUClockType; =20 diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 3f41187..ee333d0 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -17,7 +17,7 @@ static void ra_timer_handler(void *opaque) { Slirp *slirp =3D opaque; timer_mod(slirp->ra_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + NDP_Interval); + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); ndp_send_ra(slirp); } =20 @@ -27,10 +27,9 @@ void icmp6_init(Slirp *slirp) return; } =20 - slirp->ra_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL_EXT, - ra_timer_handler, slirp); + slirp->ra_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, ra_timer_handler,= slirp); timer_mod(slirp->ra_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + NDP_Interval); + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); } =20 void icmp6_cleanup(Slirp *slirp) diff --git a/ui/input.c b/ui/input.c index dd7f6d7..51b1019 100644 --- a/ui/input.c +++ b/ui/input.c @@ -271,7 +271,7 @@ static void qemu_input_queue_process(void *opaque) item =3D QTAILQ_FIRST(queue); switch (item->type) { case QEMU_INPUT_QUEUE_DELAY: - timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EX= T) + timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + item->delay_ms); return; case QEMU_INPUT_QUEUE_EVENT: @@ -301,7 +301,7 @@ static void qemu_input_queue_delay(struct QemuInputEven= tQueueHead *queue, queue_count++; =20 if (start_timer) { - timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + item->delay_ms); } } @@ -448,8 +448,8 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) } =20 if (!kbd_timer) { - kbd_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL_EXT, - qemu_input_queue_process, &kbd_queue); + kbd_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_pr= ocess, + &kbd_queue); } if (queue_count < queue_limit) { qemu_input_queue_delay(&kbd_queue, kbd_timer, diff --git a/util/qemu-timer.c b/util/qemu-timer.c index eb60d8f..86bfe84 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -496,7 +496,6 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) =20 switch (timer_list->clock->type) { case QEMU_CLOCK_REALTIME: - case QEMU_CLOCK_VIRTUAL_EXT: break; default: case QEMU_CLOCK_VIRTUAL: @@ -598,7 +597,6 @@ int64_t qemu_clock_get_ns(QEMUClockType type) return get_clock(); default: case QEMU_CLOCK_VIRTUAL: - case QEMU_CLOCK_VIRTUAL_EXT: if (use_icount) { return cpu_get_icount(); } else { --=20 2.7.4 From nobody Thu Nov 6 03:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539860947469611.1598574194364; Thu, 18 Oct 2018 04:09:07 -0700 (PDT) Received: from localhost ([::1]:41650 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD6An-0003nq-Ok for importer@patchew.org; Thu, 18 Oct 2018 07:09:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD69H-0002dB-SQ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD69E-0008WQ-K9 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:27 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:41803) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD69E-0008UD-4H; Thu, 18 Oct 2018 07:07:24 -0400 Received: by mail-lj1-x244.google.com with SMTP id u21-v6so27276164lja.8; Thu, 18 Oct 2018 04:07:22 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id u77-v6sm4575811lja.37.2018.10.18.04.07.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 04:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=doBqB47Dn6qW+3T0ZbRTc0cFO0cqA89/v0/IUjyVU6w=; b=cSlIn5zfTWE1mNk6vSYXbX1cowA/vxLJEKHXJV9i0/SRc9Em9XUWCm+BpB+gZ7qJz5 pc18hA+4ghB8S8dTfvK9D/ff+DBiqs2213S0qIJE77clGAjh+DCfYIZHwzFZ2NZt+2Nf CyiiS2Ku23ERu+F9VmxQlCZEHKZO6s0jxbr3JabXHdkmywE7MxLgbNus7FU2bUvH6Pf8 W5wEACYEcPTbg6KZzKEyz9azC1TIQSN931ml1B0g30ojxIvmSvT8OnCPuja6HjPmZcT+ y3HfIUBJK5n40Kt4JZnyEUiHsvMv83m+F37VfKYjkoHPS5UGB+hfanGaFyfQi9pbIZhn ns3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=doBqB47Dn6qW+3T0ZbRTc0cFO0cqA89/v0/IUjyVU6w=; b=oEmq2SzMUuI/ea2qidIgLdseOlTR8NpbT4oVg14Ynn8XLvnofx7G66jIuXf2aizXVe wRh2cA34oG/JJ5JaXWx8Q7HFsONr5Z8OAdRJ3QcTI2bE50cp9N9xk/jHzHQ9KZaJjDUz kblmTifXRInYJR0UHCzxM1shL1foN9vTv8oMmEnrqHIzCsG9+77z6pJS5jQesnC9OP6E uNvFXM69tVDhS7Ha5AQ3gyyvw++uvXHB444sro64pG9YB8La/LrwyAQNFsybRerOpE7S q9q/tqiIpKEn5wpQwYTUBd/HsXZnI3fnvX0/US7y5CIPVrFSMR6jTvfKfU6BfJyWqhe3 exZQ== X-Gm-Message-State: ABuFfojMZ/nq4cgYvye/+Oqdndl4S3bjzGjSyf4rbEOgefe71ErmXDCC bxB/kTplrOuTg8Wt3Jr/aR1SPcalAKs= X-Google-Smtp-Source: ACcGV638Sm1SXJ0q9rmkh+BfjKFvUcvTuDd1eri2rRQ4JPwsTk4hCvR2ou7cqXIx7HBC6VkZll5r4w== X-Received: by 2002:a2e:5215:: with SMTP id g21-v6mr19379752ljb.144.1539860840601; Thu, 18 Oct 2018 04:07:20 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 17:04:29 +0600 Message-Id: <71d3b9366dc8e7f0dab1f290d5944cb84e3cc876.1539860473.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 Subject: [Qemu-devel] [PATCH v3 2/4] Introduce attributes to qemu timer subsystem X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Pavel Dovgalyuk , "open list:Block I/O path" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Artem Pisarenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Attributes are simple flags, associated with individual timers for their wh= ole lifetime. They intended to be used to mark individual timers for special handling by = various qemu features which have integration into qemu-timer. New/init functions family in timer interface updated and refactored (new 'a= ttribute' argument added, timer_list replaced with timer_list_group+type co= mbinations, comments improved to avoid info duplication). Also existing aio interface extended with attribute-enabled variants of fun= ctions, which create/initialize timers. Signed-off-by: Artem Pisarenko Reviewed-by: Stefan Hajnoczi --- Notes: v3: - attributes has been properly incapsulated to qemu-timer (as suggested= by Stefan Hajnoczi) - attributes definition and docs refactored to avoid extra enum and use= simple macros with explicit bit positions (as suggested by Stefan Hajnoczi= and Paolo Bonzini) - fixed old "QEMU_TIMER_ATTR(id)" notation (in comments) left from init= ial patch version =20 v2: - timer creation/initialize functions reworked and and their unnecessar= y variants removed (as Paolo Bonzini suggested) - also their comments improved to avoid info duplication include/block/aio.h | 59 ++++++++++++++++++++++--- include/qemu/timer.h | 110 +++++++++++++++++++++++-------------------= ---- tests/ptimer-test-stubs.c | 13 ++++-- util/qemu-timer.c | 13 ++++-- 4 files changed, 125 insertions(+), 70 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index f08630c..0ca25df 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -388,6 +388,32 @@ struct LinuxAioState *aio_setup_linux_aio(AioContext *= ctx, Error **errp); struct LinuxAioState *aio_get_linux_aio(AioContext *ctx); =20 /** + * aio_timer_new_with_attrs: + * @ctx: the aio context + * @type: the clock type + * @scale: the scale + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR_ values + * to assign + * @cb: the callback to call on timer expiry + * @opaque: the opaque pointer to pass to the callback + * + * Allocate a new timer (with attributes) attached to the context @ctx. + * The function is responsible for memory allocation. + * + * The preferred interface is aio_timer_init or aio_timer_init_with_attrs. + * Use that unless you really need dynamic memory allocation. + * + * Returns: a pointer to the new timer + */ +static inline QEMUTimer *aio_timer_new_with_attrs(AioContext *ctx, + QEMUClockType type, + int scale, int attribute= s, + QEMUTimerCB *cb, void *o= paque) +{ + return timer_new_full(&ctx->tlg, type, scale, attributes, cb, opaque); +} + +/** * aio_timer_new: * @ctx: the aio context * @type: the clock type @@ -396,10 +422,7 @@ struct LinuxAioState *aio_get_linux_aio(AioContext *ct= x); * @opaque: the opaque pointer to pass to the callback * * Allocate a new timer attached to the context @ctx. - * The function is responsible for memory allocation. - * - * The preferred interface is aio_timer_init. Use that - * unless you really need dynamic memory allocation. + * See aio_timer_new_with_attrs for details. * * Returns: a pointer to the new timer */ @@ -407,7 +430,29 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx= , QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(ctx->tlg.tl[type], scale, cb, opaque); + return timer_new_full(&ctx->tlg, type, scale, 0, cb, opaque); +} + +/** + * aio_timer_init_with_attrs: + * @ctx: the aio context + * @ts: the timer + * @type: the clock type + * @scale: the scale + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR_ values + * to assign + * @cb: the callback to call on timer expiry + * @opaque: the opaque pointer to pass to the callback + * + * Initialise a new timer (with attributes) attached to the context @ctx. + * The caller is responsible for memory allocation. + */ +static inline void aio_timer_init_with_attrs(AioContext *ctx, + QEMUTimer *ts, QEMUClockType = type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) +{ + timer_init_full(ts, &ctx->tlg, type, scale, attributes, cb, opaque); } =20 /** @@ -420,14 +465,14 @@ static inline QEMUTimer *aio_timer_new(AioContext *ct= x, QEMUClockType type, * @opaque: the opaque pointer to pass to the callback * * Initialise a new timer attached to the context @ctx. - * The caller is responsible for memory allocation. + * See aio_timer_init_with_attrs for details. */ static inline void aio_timer_init(AioContext *ctx, QEMUTimer *ts, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - timer_init_tl(ts, ctx->tlg.tl[type], scale, cb, opaque); + timer_init_full(ts, &ctx->tlg, type, scale, 0, cb, opaque); } =20 /** diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 39ea907..d45aded 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -52,6 +52,16 @@ typedef enum { QEMU_CLOCK_MAX } QEMUClockType; =20 +/** + * QEMU Timer attributes: + * + * An individual timer may be given one or multiple attributes when initia= lized. + * Each attribute corresponds to one bit. Attributes modify the processing + * of timers when they fire. + * + * No attributes defined currently. + */ + typedef struct QEMUTimerList QEMUTimerList; =20 struct QEMUTimerListGroup { @@ -67,6 +77,7 @@ struct QEMUTimer { QEMUTimerCB *cb; void *opaque; QEMUTimer *next; + int attributes; int scale; }; =20 @@ -418,22 +429,28 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup= *tlg); */ =20 /** - * timer_init_tl: + * timer_init_full: * @ts: the timer to be initialised - * @timer_list: the timer list to attach the timer to + * @timer_list_group: (optional) the timer list group to attach the timer = to + * @type: the clock type to use * @scale: the scale value for the timer + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR_ values + * to assign * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Initialise a new timer and associate it with @timer_list. + * Initialise a timer with the given scale and attributes, + * and associate it with timer list for given clock @type in @timer_list_g= roup + * (or default timer list group, if NULL). * The caller is responsible for allocating the memory. * * You need not call an explicit deinit call. Simply make * sure it is not on a list with timer_del. */ -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque); +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType t= ype, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque); =20 /** * timer_init: @@ -445,14 +462,12 @@ void timer_init_tl(QEMUTimer *ts, * * Initialize a timer with the given scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init(QEMUTimer *ts, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - timer_init_tl(ts, main_loop_tlg.tl[type], scale, cb, opaque); + timer_init_full(ts, &main_loop_tlg, type, scale, 0, cb, opaque); } =20 /** @@ -464,9 +479,7 @@ static inline void timer_init(QEMUTimer *ts, QEMUClockT= ype type, int scale, * * Initialize a timer with nanosecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_ns(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -483,9 +496,7 @@ static inline void timer_init_ns(QEMUTimer *ts, QEMUClo= ckType type, * * Initialize a timer with microsecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_us(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -502,9 +513,7 @@ static inline void timer_init_us(QEMUTimer *ts, QEMUClo= ckType type, * * Initialize a timer with millisecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -513,27 +522,38 @@ static inline void timer_init_ms(QEMUTimer *ts, QEMUC= lockType type, } =20 /** - * timer_new_tl: - * @timer_list: the timer list to attach the timer to + * timer_new_full: + * @timer_list_group: (optional) the timer list group to attach the timer = to + * @type: the clock type to use * @scale: the scale value for the timer + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR_ values + * to assign * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Create a new timer and associate it with @timer_list. + * Create a new timer with the given scale and attributes, + * and associate it with timer list for given clock @type in @timer_list_g= roup + * (or default timer list group, if NULL). * The memory is allocated by the function. * * This is not the preferred interface unless you know you - * are going to call timer_free. Use timer_init instead. + * are going to call timer_free. Use timer_init or timer_init_full instead. + * + * The default timer list has one special feature: in icount mode, + * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is + * not true of other timer lists, which are typically associated + * with an AioContext---each of them runs its timer callbacks in its own + * AioContext thread. * * Returns: a pointer to the timer */ -static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, - int scale, - QEMUTimerCB *cb, - void *opaque) +static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_gro= up, + QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { QEMUTimer *ts =3D g_malloc0(sizeof(QEMUTimer)); - timer_init_tl(ts, timer_list, scale, cb, opaque); + timer_init_full(ts, timer_list_group, type, scale, attributes, cb, opa= que); return ts; } =20 @@ -544,21 +564,16 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *= timer_list, * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Create a new timer and associate it with the default - * timer list for the clock type @type. - * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. + * Create a new timer with the given scale, + * and associate it with the default timer list for the clock type @type. + * See timer_new_full for details. * * Returns: a pointer to the timer */ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(main_loop_tlg.tl[type], scale, cb, opaque); + return timer_new_full(&main_loop_tlg, type, scale, 0, cb, opaque); } =20 /** @@ -569,12 +584,7 @@ static inline QEMUTimer *timer_new(QEMUClockType type,= int scale, * * Create a new timer with nanosecond scale on the default timer list * associated with the clock. - * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -590,14 +600,9 @@ static inline QEMUTimer *timer_new_ns(QEMUClockType ty= pe, QEMUTimerCB *cb, * @cb: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. - * * Create a new timer with microsecond scale on the default timer list * associated with the clock. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -613,14 +618,9 @@ static inline QEMUTimer *timer_new_us(QEMUClockType ty= pe, QEMUTimerCB *cb, * @cb: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. - * * Create a new timer with millisecond scale on the default timer list * associated with the clock. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c index ca5cc3b..54b3fd2 100644 --- a/tests/ptimer-test-stubs.c +++ b/tests/ptimer-test-stubs.c @@ -34,14 +34,19 @@ int64_t ptimer_test_time_ns; int use_icount =3D 1; bool qtest_allowed; =20 -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType t= ype, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { - ts->timer_list =3D timer_list; + if (!timer_list_group) { + timer_list_group =3D &main_loop_tlg; + } + ts->timer_list =3D timer_list_group->tl[type]; ts->cb =3D cb; ts->opaque =3D opaque; ts->scale =3D scale; + ts->attributes =3D attributes; ts->expire_time =3D -1; } =20 diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 86bfe84..04527a3 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -339,14 +339,19 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t ti= meout) } =20 =20 -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType t= ype, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { - ts->timer_list =3D timer_list; + if (!timer_list_group) { + timer_list_group =3D &main_loop_tlg; + } + ts->timer_list =3D timer_list_group->tl[type]; ts->cb =3D cb; ts->opaque =3D opaque; ts->scale =3D scale; + ts->attributes =3D attributes; ts->expire_time =3D -1; } =20 --=20 2.7.4 From nobody Thu Nov 6 03:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539861025544708.6863221396876; Thu, 18 Oct 2018 04:10:25 -0700 (PDT) Received: from localhost ([::1]:41664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD6C8-0004fb-EV for importer@patchew.org; Thu, 18 Oct 2018 07:10:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD69I-0002dG-1T for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD69E-000052-S4 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:27 -0400 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]:33806) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD69E-0008VY-IE for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:24 -0400 Received: by mail-lj1-x242.google.com with SMTP id j17-v6so27323468lja.1 for ; Thu, 18 Oct 2018 04:07:24 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id u77-v6sm4575811lja.37.2018.10.18.04.07.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 04:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=NMAcGNcsZRW44ZhP62Qq/LgejL46qx5h1Hr+BVKdt+s=; b=qY3iWXcGMNzMMsuZR4qvZcJW9dpbV3roWobbxAsRYadonR+SE6W/nz5eOtpuOSs017 8ssMc1cgAIfwpOD72y1F4ky392tQeU2nYl5uxsttO47cRMlG/N8WljUAA4qGu6Q9tvaj QxWdnG1nMFdCmN0637jhc/3hyZphUQL4ojJ8uIlzcX6OjdTijJsmvfGoz4RJXVRyX6K8 fHjRB2Bit7RG6wycKoQRRrMdXNBi3hYxMCaPs0S0PeyCJgbkaTh4CUG9DEsfRfsV+Wbf 1tGt5YUbz9eeWb8BvpmV0s2BYs0YgB1xUQjVllwPmbj5REq0kNX6wcEtHdbC3NV0Z/Xg a+uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=NMAcGNcsZRW44ZhP62Qq/LgejL46qx5h1Hr+BVKdt+s=; b=k1j+28TzHax6qnMw3p1Ho4dmiwul1mb8kQx0S+RwtSUdpVKwM/Br3873BrmGBXLpXR ALjWeou6h+jLMBoiyI0YWFN7SjMs0eI1RXknqp04C1s5rG8jAcmtgJyvO20w65uz4q/v ekyWYrMWa8rhYKE6pk8AesEi86UZz6fJXaXdGIVpIVH7Xs+unfdZd1/65YMG2XXy9TAd 6yqpTsKbQg63lNwyG5JWs0q63UI6KtHs3IlfOeFzFCiHvP915rK1PSH6lACYp2q2rxYc HC8RRKeVkiE7wbeV/BCoYdDHWaYJtxuKHeBqeYbdQUKQ8BM7d5+fNqkArKrw8mmnWfRg kZhg== X-Gm-Message-State: ABuFfog4QsJVad58aB8rcUBiHQ5daitrWjPq2ryCaUGy6ynaNj86mBa3 0Vz/37JXn/5oLe1v0twUK1o49aHB9TA= X-Google-Smtp-Source: ACcGV605XjmIvoRd9H4t0p/zOXNsLaJOJo+ATTva0BnosgRyUpoZoA3b9Mhe34cgXSGD21fyTVeY0A== X-Received: by 2002:a2e:2bd5:: with SMTP id r82-v6mr19421107ljr.63.1539860842625; Thu, 18 Oct 2018 04:07:22 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 17:04:30 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::242 Subject: [Qemu-devel] [PATCH v3 3/4] Restores record/replay behavior related to special virtual clock processing for timers used in external subsystems. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Gerd Hoffmann , Pavel Dovgalyuk , Samuel Thibault , Paolo Bonzini , Artem Pisarenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Adds EXTERNAL attribute definition to qemu timers subsystem and assigns it = to virtual clock timers, used in slirp (ICMP IPv6) and ui (key queue). Virtual clock processing in rr mode reimplemented using this attribute. Fixes: 87f4fe7653baf55b5c2f2753fe6003f473c07342 Fixes: 775a412bf83f6bc0c5c02091ee06cf649b34c593 Fixes: 9888091404a702d7ec79d51b088d994b9fc121bd Signed-off-by: Artem Pisarenko --- include/qemu/timer.h | 11 ++++++++++- slirp/ip6_icmp.c | 4 +++- ui/input.c | 5 +++-- util/qemu-timer.c | 50 +++++++++++++++++++++++++++++++++++++++++++-----= -- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index d45aded..dc0fd14 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -2,6 +2,7 @@ #define QEMU_TIMER_H =20 #include "qemu-common.h" +#include "qemu/bitops.h" #include "qemu/notify.h" #include "qemu/host-utils.h" =20 @@ -59,9 +60,17 @@ typedef enum { * Each attribute corresponds to one bit. Attributes modify the processing * of timers when they fire. * - * No attributes defined currently. + * The following attributes are available: + * + * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem + * + * Timers with this attribute do not recorded in rr mode, therefore it cou= ld be + * used for the subsystems that operate outside the guest core. Applicable= only + * with virtual clock type. */ =20 +#define QEMU_TIMER_ATTR_EXTERNAL BIT(0) + typedef struct QEMUTimerList QEMUTimerList; =20 struct QEMUTimerListGroup { diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index ee333d0..cd1e0b9 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -27,7 +27,9 @@ void icmp6_init(Slirp *slirp) return; } =20 - slirp->ra_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, ra_timer_handler,= slirp); + slirp->ra_timer =3D timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, + SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, + ra_timer_handler, slirp); timer_mod(slirp->ra_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); } diff --git a/ui/input.c b/ui/input.c index 51b1019..7c9a410 100644 --- a/ui/input.c +++ b/ui/input.c @@ -448,8 +448,9 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) } =20 if (!kbd_timer) { - kbd_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_pr= ocess, - &kbd_queue); + kbd_timer =3D timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, + SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, + qemu_input_queue_process, &kbd_queue); } if (queue_count < queue_limit) { qemu_input_queue_delay(&kbd_queue, kbd_timer, diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 04527a3..e2746cf 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -489,6 +489,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) bool progress =3D false; QEMUTimerCB *cb; void *opaque; + bool need_replay_checkpoint =3D false; =20 if (!atomic_read(&timer_list->active_timers)) { return false; @@ -504,8 +505,15 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) break; default: case QEMU_CLOCK_VIRTUAL: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { - goto out; + if (replay_mode !=3D REPLAY_MODE_NONE) { + /* Checkpoint for virtual clock is redundant in cases where + * it's being triggered with only non-EXTERNAL timers, because + * these timers don't change guest state directly. + * Since it has conditional dependence on specific timers, it = is + * subject to race conditions and requires special handling. + * See below. + */ + need_replay_checkpoint =3D true; } break; case QEMU_CLOCK_HOST: @@ -520,13 +528,38 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) break; } =20 + /* + * Extract expired timers from active timers list and and process them. + * + * In rr mode we need "filtered" checkpointing for virtual clock. + * Checkpoint must be replayed before any non-EXTERNAL timer has been + * processed and only one time (virtual clock value stays same). But t= hese + * timers may appear in the timers list while it being processed, so t= his + * must be checked until we finally decide that "no timers left - we a= re + * done". + */ current_time =3D qemu_clock_get_ns(timer_list->clock->type); - for(;;) { - qemu_mutex_lock(&timer_list->active_timers_lock); - ts =3D timer_list->active_timers; + qemu_mutex_lock(&timer_list->active_timers_lock); + while ((ts =3D timer_list->active_timers)) { if (!timer_expired_ns(ts, current_time)) { + /* No expired timers left. + * (If rr checkpoint was needed, it either already handled, + * or may be skipped.) */ + break; + } + if (need_replay_checkpoint + && !(ts->attributes & QEMU_TIMER_ATTR_EXTERNAL)) { + /* once we got here, checkpoint clock only once */ + need_replay_checkpoint =3D false; qemu_mutex_unlock(&timer_list->active_timers_lock); - break; + if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + goto out; + } + qemu_mutex_lock(&timer_list->active_timers_lock); + /* it's better to start over again, + * just in case if timer list was modified + */ + continue; } =20 /* remove timer from the list before calling the callback */ @@ -535,12 +568,15 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) ts->expire_time =3D -1; cb =3D ts->cb; opaque =3D ts->opaque; - qemu_mutex_unlock(&timer_list->active_timers_lock); =20 /* run the callback (the timer list can be modified) */ + qemu_mutex_unlock(&timer_list->active_timers_lock); cb(opaque); + qemu_mutex_lock(&timer_list->active_timers_lock); + progress =3D true; } + qemu_mutex_unlock(&timer_list->active_timers_lock); =20 out: qemu_event_set(&timer_list->timers_done_ev); --=20 2.7.4 From nobody Thu Nov 6 03:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539860937812612.4250836856282; Thu, 18 Oct 2018 04:08:57 -0700 (PDT) Received: from localhost ([::1]:41649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD6Ah-0003iO-Vd for importer@patchew.org; Thu, 18 Oct 2018 07:08:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD69H-0002d8-SM for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD69G-00006B-9M for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:27 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:36418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD69F-00005J-Vo for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:07:26 -0400 Received: by mail-lj1-x244.google.com with SMTP id p89-v6so27320152ljb.3 for ; Thu, 18 Oct 2018 04:07:25 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id u77-v6sm4575811lja.37.2018.10.18.04.07.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 04:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4eCGmlouvi724H+D2HVuSLbDo32hSMqys1/wXarPzAQ=; b=YxMUkNK0RSadI3f6NNTV+uXQPHDfT9tAvlhVOaFK19sSysUc8vcd/fTBtr9TINKl/b AKpe0sgX3tVk1zVvE0umFFlFHTQlsb29ZBqKCGErQXZgfaF1mOywnhVLHrB+WJGqzJyZ WfYwucqPfRJehvAvXzPRdkW003M8Bb+v2WRkiDhoignqs+Ew9XKxhgnVZNhIB7EGpsqn pFe86W7qVzlHx5nr1+PD9ySk3vXJsKaFaowqaCozGpIfi36vIqnayNA/yMZWLCE3kQ/7 +5VyOnEoAbxjzOawCoumfGeMDrDBnBswpi3dxkFokVU3ikUtKgpRxL3kuCyEMd0Bk2Wa WjFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=4eCGmlouvi724H+D2HVuSLbDo32hSMqys1/wXarPzAQ=; b=DPZVcE9eNLB47kLjWoOt9bS33P88YvOou4jCJz9M8tzxKabslXmWbcciws7Op2pFdQ N65xn9J0LNck9kFV6iYijMFHYXydp9MSikA5UwqYwAxDJFvhhoq2HelY4Ydi8sC4NpRD e6mmFxjojJy0Cv8hnAhTZeabAYO4EpxhFJNIM127P4TL5EJ30Uh9AfnAMWpE4mxo/cy3 uDpRHnI1DyK+BYjKyC7vnG13fsFxlT5AA87hueU5uemM9Gu29C1k+C9GMUqFyPEdkwUh IxSFbuZeMlu8odmLSZ9a/GzcW/cNwPzZNC7znjXde0g0rkO70xK9uR/1BLs+EOxB8TwH vQuQ== X-Gm-Message-State: ABuFfoicqPWowm1LPiGQxKwT09L4lM8q/fcZzppNquTC/23cqse+Imkx 9ZCQJu9pCpUn+q5Dmpb1kAWIxj8Ht88= X-Google-Smtp-Source: ACcGV63lon/HUwhn+r4bugEmewaSrIGOrnsgYmpFYqgw3k/0KzpD0bvWwwxSZykrwrE9asfcfldu+A== X-Received: by 2002:a2e:1b9c:: with SMTP id c28-v6mr19290501ljf.73.1539860844243; Thu, 18 Oct 2018 04:07:24 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 17:04:31 +0600 Message-Id: <3a396555c19468ce89788cc6deabbfef4ab56035.1539860473.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 Subject: [Qemu-devel] [PATCH v3 4/4] Optimize record/replay checkpointing for all clocks it applies to X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko , Pavel Dovgalyuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Removes redundant checkpoints in replay log when there are no expired timer= s in timers list, associated with corresponding clock (i.e. no rr events as= sociated with current clock value). This also improves performance in rr mode. Signed-off-by: Artem Pisarenko --- Notes: v3: - fixed compiler warning caused non-debug build to fail include/qemu/timer.h | 2 +- util/qemu-timer.c | 62 +++++++++++++++++++++++++-----------------------= ---- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index dc0fd14..bff8dac 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -65,7 +65,7 @@ typedef enum { * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem * * Timers with this attribute do not recorded in rr mode, therefore it cou= ld be - * used for the subsystems that operate outside the guest core. Applicable= only + * used for the subsystems that operate outside the guest core. Relevant o= nly * with virtual clock type. */ =20 diff --git a/util/qemu-timer.c b/util/qemu-timer.c index e2746cf..216d107 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -490,6 +490,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) QEMUTimerCB *cb; void *opaque; bool need_replay_checkpoint =3D false; + ReplayCheckpoint replay_checkpoint_id; =20 if (!atomic_read(&timer_list->active_timers)) { return false; @@ -500,43 +501,40 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) goto out; } =20 - switch (timer_list->clock->type) { - case QEMU_CLOCK_REALTIME: - break; - default: - case QEMU_CLOCK_VIRTUAL: - if (replay_mode !=3D REPLAY_MODE_NONE) { - /* Checkpoint for virtual clock is redundant in cases where - * it's being triggered with only non-EXTERNAL timers, because - * these timers don't change guest state directly. - * Since it has conditional dependence on specific timers, it = is - * subject to race conditions and requires special handling. - * See below. - */ + if (replay_mode !=3D REPLAY_MODE_NONE) { + /* Postpone actual checkpointing to timer list processing + * to properly check if we actually need it. + */ + switch (timer_list->clock->type) { + case QEMU_CLOCK_VIRTUAL: need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_VIRTUAL; + break; + case QEMU_CLOCK_HOST: + need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_HOST; + break; + case QEMU_CLOCK_VIRTUAL_RT: + need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_VIRTUAL_RT; + break; + default: + break; } - break; - case QEMU_CLOCK_HOST: - if (!replay_checkpoint(CHECKPOINT_CLOCK_HOST)) { - goto out; - } - break; - case QEMU_CLOCK_VIRTUAL_RT: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) { - goto out; - } - break; } =20 /* - * Extract expired timers from active timers list and and process them. + * Extract expired timers from active timers list and and process them, + * taking into account checkpointing required in rr mode. * - * In rr mode we need "filtered" checkpointing for virtual clock. - * Checkpoint must be replayed before any non-EXTERNAL timer has been - * processed and only one time (virtual clock value stays same). But t= hese - * timers may appear in the timers list while it being processed, so t= his - * must be checked until we finally decide that "no timers left - we a= re - * done". + * Checkpoint must be replayed before any timer has been processed + * and only one time. But new timers may appear in the timers list whi= le + * it's being processed, so this must be checked until we finally deci= de + * that "no timers left - we are done" (to avoid skipping checkpoint d= ue to + * possible races). + * Also checkpoint for virtual clock is redundant in cases where it's = being + * triggered with only non-EXTERNAL timers, because these timers don't + * change guest state directly. */ current_time =3D qemu_clock_get_ns(timer_list->clock->type); qemu_mutex_lock(&timer_list->active_timers_lock); @@ -552,7 +550,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) /* once we got here, checkpoint clock only once */ need_replay_checkpoint =3D false; qemu_mutex_unlock(&timer_list->active_timers_lock); - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + if (!replay_checkpoint(replay_checkpoint_id)) { goto out; } qemu_mutex_lock(&timer_list->active_timers_lock); --=20 2.7.4 From nobody Thu Nov 6 03:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539865033222283.7914974682046; Thu, 18 Oct 2018 05:17:13 -0700 (PDT) Received: from localhost ([::1]:42085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD7Ec-0006Du-SW for importer@patchew.org; Thu, 18 Oct 2018 08:17:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD7DU-0005v4-SJ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 08:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD7DR-0008NM-KB for qemu-devel@nongnu.org; Thu, 18 Oct 2018 08:15:52 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:37155) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD7DR-0008Mr-Au for qemu-devel@nongnu.org; Thu, 18 Oct 2018 08:15:49 -0400 Received: by mail-lj1-x243.google.com with SMTP id 63-v6so27505300ljs.4 for ; Thu, 18 Oct 2018 05:15:49 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id m132-v6sm4411092lfg.24.2018.10.18.05.15.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 05:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zBKtik/mNJs4k8FUPhknWoYsOBOYA2YhwltksNlLWoI=; b=Zn7qY7C08wSKetVp1nF//632uA56Qokuky9Nadvr7Il5FRleDjkOPQZPEdPsXaAToA Ca34l5qjSbOasAh5ec2xeiE/nrK93KC7931qKD0tSFrIyJDG8yrQtspc9uRGUKsRnJJX f3B6nacKKOkiOnq1z+xUTtDfxb8gCOg9p4lnF204wFG4ttaY/QFL8QfacE1BDkvjFtn+ 9UPz3jNozjpQfzd1bdh1A38Oc25CD42IuAht/Ztke4j7JaQ9NY5mOPYUIlcjpB/hOHdS 1m7VVZvRLkGu6lApuwU14RlkvTYu0TwrREqrJ84IoINouLyl72fDQbkM/VYY6spAc8rk n3Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zBKtik/mNJs4k8FUPhknWoYsOBOYA2YhwltksNlLWoI=; b=gwt27qZ8e3k3JDaSfYF0OeT9P9VBM4DkfI9169ULIatayYdQBWegxpzMV9haT6TqCX z9CHCgTEEWCydPa0JuZEWnU5stzujQWINarlTjEj/dL+WRlsEnmkfBQ6DLM8acFMwXuX i/xg9ilyY9281oMenKkB8aVigDWLtPADj1WJc/Qc6yog4KSuP+TQwxF9zaaqwxN8dza5 RYHPCWgdWr7loQRg1woC3iQNP2nnogH3wk5mcfHZmt7u1xZXRk+T46sP8zWMMqanlrP6 g8MrVXeuqHrtfyGGjBDlAP2rK0zb/7jBcbT1UeTUYy63TAuuCyZVuAPu+1k22Y5T52Sv DJAA== X-Gm-Message-State: ABuFfogEyvxMGluwbAlC65v5ENDrx60q9W3hl85nMBZaGtAp544EtpCP kfxw0PruTdjHnSdXhSAiTuth2o0zMXU= X-Google-Smtp-Source: ACcGV639tsXyRtFWuel3J3C5qeg0k/TIxRIAqqwZegM/QpCgZND/GgvpYuDgQoLkwSH4oQROkEVY3A== X-Received: by 2002:a2e:7217:: with SMTP id n23-v6mr15019149ljc.71.1539864947047; Thu, 18 Oct 2018 05:15:47 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 18:15:30 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 Subject: [Qemu-devel] [PATCH v3 4/4] Optimize record/replay checkpointing for all clocks it applies to X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko , Pavel Dovgalyuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Removes redundant checkpoints in replay log when there are no expired timer= s in timers list, associated with corresponding clock (i.e. no rr events as= sociated with current clock value). This also improves performance in rr mode. Signed-off-by: Artem Pisarenko --- Oops and again oops. Now it finally should be fine... v3: - fixed compiler warning caused non-debug build to fail include/qemu/timer.h | 2 +- util/qemu-timer.c | 62 +++++++++++++++++++++++++-----------------------= ---- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index dc0fd14..bff8dac 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -65,7 +65,7 @@ typedef enum { * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem * * Timers with this attribute do not recorded in rr mode, therefore it cou= ld be - * used for the subsystems that operate outside the guest core. Applicable= only + * used for the subsystems that operate outside the guest core. Relevant o= nly * with virtual clock type. */ =20 diff --git a/util/qemu-timer.c b/util/qemu-timer.c index e2746cf..47205fe 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -490,6 +490,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) QEMUTimerCB *cb; void *opaque; bool need_replay_checkpoint =3D false; + ReplayCheckpoint replay_checkpoint_id =3D (ReplayCheckpoint)-1; =20 if (!atomic_read(&timer_list->active_timers)) { return false; @@ -500,43 +501,40 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) goto out; } =20 - switch (timer_list->clock->type) { - case QEMU_CLOCK_REALTIME: - break; - default: - case QEMU_CLOCK_VIRTUAL: - if (replay_mode !=3D REPLAY_MODE_NONE) { - /* Checkpoint for virtual clock is redundant in cases where - * it's being triggered with only non-EXTERNAL timers, because - * these timers don't change guest state directly. - * Since it has conditional dependence on specific timers, it = is - * subject to race conditions and requires special handling. - * See below. - */ + if (replay_mode !=3D REPLAY_MODE_NONE) { + /* Postpone actual checkpointing to timer list processing + * to properly check if we actually need it. + */ + switch (timer_list->clock->type) { + case QEMU_CLOCK_VIRTUAL: need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_VIRTUAL; + break; + case QEMU_CLOCK_HOST: + need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_HOST; + break; + case QEMU_CLOCK_VIRTUAL_RT: + need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_VIRTUAL_RT; + break; + default: + break; } - break; - case QEMU_CLOCK_HOST: - if (!replay_checkpoint(CHECKPOINT_CLOCK_HOST)) { - goto out; - } - break; - case QEMU_CLOCK_VIRTUAL_RT: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) { - goto out; - } - break; } =20 /* - * Extract expired timers from active timers list and and process them. + * Extract expired timers from active timers list and and process them, + * taking into account checkpointing required in rr mode. * - * In rr mode we need "filtered" checkpointing for virtual clock. - * Checkpoint must be replayed before any non-EXTERNAL timer has been - * processed and only one time (virtual clock value stays same). But t= hese - * timers may appear in the timers list while it being processed, so t= his - * must be checked until we finally decide that "no timers left - we a= re - * done". + * Checkpoint must be replayed before any timer has been processed + * and only one time. But new timers may appear in the timers list whi= le + * it's being processed, so this must be checked until we finally deci= de + * that "no timers left - we are done" (to avoid skipping checkpoint d= ue to + * possible races). + * Also checkpoint for virtual clock is redundant in cases where it's = being + * triggered with only non-EXTERNAL timers, because these timers don't + * change guest state directly. */ current_time =3D qemu_clock_get_ns(timer_list->clock->type); qemu_mutex_lock(&timer_list->active_timers_lock); @@ -552,7 +550,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) /* once we got here, checkpoint clock only once */ need_replay_checkpoint =3D false; qemu_mutex_unlock(&timer_list->active_timers_lock); - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + if (!replay_checkpoint(replay_checkpoint_id)) { goto out; } qemu_mutex_lock(&timer_list->active_timers_lock); --=20 2.7.4 From nobody Thu Nov 6 03:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15398615087751.5994568926543025; Thu, 18 Oct 2018 04:18:28 -0700 (PDT) Received: from localhost ([::1]:41711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD6Jv-0000Ll-0u for importer@patchew.org; Thu, 18 Oct 2018 07:18:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD6If-0007yy-WA for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:17:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD6Ia-0007r9-Jk for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:17:08 -0400 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:46133) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD6IY-0007oi-Cl for qemu-devel@nongnu.org; Thu, 18 Oct 2018 07:17:04 -0400 Received: by mail-lj1-x241.google.com with SMTP id x3-v6so27315870lji.13 for ; Thu, 18 Oct 2018 04:16:59 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id v1-v6sm4576776lje.50.2018.10.18.04.16.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 04:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LtlF/gFUWanLkUDR36fO1n7Uh54wxYuuhhVmDpEI30o=; b=It7MM1Izlg5LDXFv1fNNsmYlzlzhjcZMTxFi4Wq49jqX1+tNWCsZtQNJfpZ8Wlo0/a w4E6Tw8cvfEACF0+/bZEN+Id4K3s01N9xtEJa/fwDUE7LsUcAjpwqDTZjMOqt7+adKlV ZNycb9zwxSnhr3d7iKPuTT5KJc1CLwaTX5c4FxU3s7c2i8/Wte3StARC+8Ee9zVroK5L p0Yi4wGpKjl2R7T6bJZCP2Bv17kdfNR/YB6HcnSDQK5TU17rKhhCJO7e54ObD/W9oUib 9WvR2mC7AzKdo1l7BDAiWNH1WBQfzjfL6mnJpfAWnzsdqZjMkvMCSmhU4NoJEaEM9Lt1 OVzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LtlF/gFUWanLkUDR36fO1n7Uh54wxYuuhhVmDpEI30o=; b=EGixJmkPs8Ss3Eu+W4ncHrMi36kAeZYnb1GWK+P+0xoYYJcB5sqEEW7PF/T6xRaPQh 8EN01+011i1aMFdXuHDdFuTMQgmZdJRbIpZvMwuDoWhdR1u/PbU8S7WNDbKu3MoEK4fN RDi1SVjfBtkBS+oJ4ir4PpIFervc76J7zo7obxbRyb+VIw2jKAEpNsffF0LlzaBNC6c0 7xC+8z4KELeefx6PMfxULjPPEhVjEAQ5OqclTD0alx+ZIlzTP0WsqFjthARfxMMUNdSl Ir37odJMFDmdZbkjPIVW7nxFtakBAyNe/vlfPaMYrmmNfBh6K9uIWPWkBE4kxyUYeF/u 1hmw== X-Gm-Message-State: ABuFfojzES7aBUKBUdfepEOHz1zVZaO1ylcpZ6BtMt6QUa8WOuPXJTco D3WTInPQfvOq9hev8CsSRkzvNjiXCB4= X-Google-Smtp-Source: ACcGV627BlZBSDkL5JK/28dfnKd4dvpOewD6ZVIQBlFhHsQljDTmVG3rRiCGPRCNbK+naLXH1T/odw== X-Received: by 2002:a2e:4b11:: with SMTP id y17-v6mr19251852lja.42.1539861417968; Thu, 18 Oct 2018 04:16:57 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 17:16:11 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::241 Subject: [Qemu-devel] [PATCH v3] Optimize record/replay checkpointing for all clocks it applies to X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko , Pavel Dovgalyuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Removes redundant checkpoints in replay log when there are no expired timer= s in timers list, associated with corresponding clock (i.e. no rr events as= sociated with current clock value). This also improves performance in rr mode. Signed-off-by: Artem Pisarenko --- Oops, forgot to commit this fix v3: - fixed compiler warning caused non-debug build to fail include/qemu/timer.h | 2 +- util/qemu-timer.c | 62 +++++++++++++++++++++++++-----------------------= ---- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index dc0fd14..bff8dac 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -65,7 +65,7 @@ typedef enum { * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem * * Timers with this attribute do not recorded in rr mode, therefore it cou= ld be - * used for the subsystems that operate outside the guest core. Applicable= only + * used for the subsystems that operate outside the guest core. Relevant o= nly * with virtual clock type. */ =20 diff --git a/util/qemu-timer.c b/util/qemu-timer.c index e2746cf..47205fe 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -490,6 +490,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) QEMUTimerCB *cb; void *opaque; bool need_replay_checkpoint =3D false; + ReplayCheckpoint replay_checkpoint_id =3D (ReplayCheckpoint)-1; =20 if (!atomic_read(&timer_list->active_timers)) { return false; @@ -500,43 +501,40 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) goto out; } =20 - switch (timer_list->clock->type) { - case QEMU_CLOCK_REALTIME: - break; - default: - case QEMU_CLOCK_VIRTUAL: - if (replay_mode !=3D REPLAY_MODE_NONE) { - /* Checkpoint for virtual clock is redundant in cases where - * it's being triggered with only non-EXTERNAL timers, because - * these timers don't change guest state directly. - * Since it has conditional dependence on specific timers, it = is - * subject to race conditions and requires special handling. - * See below. - */ + if (replay_mode !=3D REPLAY_MODE_NONE) { + /* Postpone actual checkpointing to timer list processing + * to properly check if we actually need it. + */ + switch (timer_list->clock->type) { + case QEMU_CLOCK_VIRTUAL: need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_VIRTUAL; + break; + case QEMU_CLOCK_HOST: + need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_HOST; + break; + case QEMU_CLOCK_VIRTUAL_RT: + need_replay_checkpoint =3D true; + replay_checkpoint_id =3D CHECKPOINT_CLOCK_VIRTUAL_RT; + break; + default: + break; } - break; - case QEMU_CLOCK_HOST: - if (!replay_checkpoint(CHECKPOINT_CLOCK_HOST)) { - goto out; - } - break; - case QEMU_CLOCK_VIRTUAL_RT: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) { - goto out; - } - break; } =20 /* - * Extract expired timers from active timers list and and process them. + * Extract expired timers from active timers list and and process them, + * taking into account checkpointing required in rr mode. * - * In rr mode we need "filtered" checkpointing for virtual clock. - * Checkpoint must be replayed before any non-EXTERNAL timer has been - * processed and only one time (virtual clock value stays same). But t= hese - * timers may appear in the timers list while it being processed, so t= his - * must be checked until we finally decide that "no timers left - we a= re - * done". + * Checkpoint must be replayed before any timer has been processed + * and only one time. But new timers may appear in the timers list whi= le + * it's being processed, so this must be checked until we finally deci= de + * that "no timers left - we are done" (to avoid skipping checkpoint d= ue to + * possible races). + * Also checkpoint for virtual clock is redundant in cases where it's = being + * triggered with only non-EXTERNAL timers, because these timers don't + * change guest state directly. */ current_time =3D qemu_clock_get_ns(timer_list->clock->type); qemu_mutex_lock(&timer_list->active_timers_lock); @@ -552,7 +550,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) /* once we got here, checkpoint clock only once */ need_replay_checkpoint =3D false; qemu_mutex_unlock(&timer_list->active_timers_lock); - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + if (!replay_checkpoint(replay_checkpoint_id)) { goto out; } qemu_mutex_lock(&timer_list->active_timers_lock); --=20 2.7.4