From nobody Thu Nov 6 06:19:17 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