From nobody Thu Nov 6 01:10:29 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538296991410732.6804634138078; Sun, 30 Sep 2018 01:43:11 -0700 (PDT) Received: from localhost ([::1]:54371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6XJm-0005Um-4A for importer@patchew.org; Sun, 30 Sep 2018 04:43:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6Wrd-0002Xu-Ja for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6Wrb-0000qp-0s for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:14:05 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:40728) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6Wra-0000pI-Og for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:14:02 -0400 Received: by mail-wr1-x433.google.com with SMTP id y8-v6so10478459wrh.7 for ; Sun, 30 Sep 2018 01:14:02 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.14.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=OXmPuhMUHWqCqChnPMQ2XsmBlhZG3ZsTUx6etZWhmHM=; b=JilxZqCRh6004VAXV5wix9ylopZkPKqmcJytBbxkzluYXc/CAQALXtQwWTJgziKARq mhuPh2LA+tvtFtjSog9qn4buS4mirBvrqm6kg5qa5xKLdEdT+DLfOktxp3zHdRVoZ+Zm KFI6a/tmqCKoJt4PcFk4oDFd/iCqW/P8tD2vLc0LU00ALI+opsh520ndF1i5p/GL/Y2S 5bfTmLDEVbNCTiNdIUWd/Z/1uzc7WEFLdvnKXtSrctd4b/aSX31sDR4urhtpXchaL2Dv BE8GbVGzSKxv2QKe3GoFoSn9wC0G3U0HcKhgIw4m89On6F7r1r0M775D5uTDZvbix02U tdmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=OXmPuhMUHWqCqChnPMQ2XsmBlhZG3ZsTUx6etZWhmHM=; b=Ve5hY/qgKnyDXCZK5567l5dUbgXHMB7HhTNlEpXyUjnCXzbW1lgquRXhNeZWQu4mHX 7dPB8SVYDRiLOVf41+YKqg366D8HG3uTvPmS6Ep16CPO7NF9EK9PYIejakMU2a+bNcii dBUiiJ0jlQSyt06W7cONN6kTdjA23PIPOaiZQg6zF/Wc4dmxkpsNGnsvfXc3kmUxh9jv u6wJwpcgTyqr/9/LIT3qs2/c8rNrc3VD3q/fCfzZtdxspdf/zoXAZjkX65z68q6cjS37 fotFB+ub0p76bfF5FFZRY2wpS7uw6u0vH5PR4SNESo3jAW/fj8xfxO3oZjqtaWS4V9zq U+AQ== X-Gm-Message-State: ABuFfog/Do8heIEEZLlwKEI8OTLImytwre6Pb82zuzxDFnCGO96o0R8W LFGOQg71vCPwI59D27El2v4WAanP X-Google-Smtp-Source: ACcGV618Mof8HBxrXy7e3ezjYjyp/NHw4bEeeVpgyMhWqoYv6m7jqx/HOFuVJ008/D6V3bA4Z7XuDw== X-Received: by 2002:adf:afdd:: with SMTP id y29-v6mr3980000wrd.176.1538295241292; Sun, 30 Sep 2018 01:14:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:36 +0200 Message-Id: <1538295197-23704-39-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::433 Subject: [Qemu-devel] [PULL 38/79] replay: wake up vCPU when replaying 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: 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" From: Pavel Dovgalyuk In record/replay icount mode vCPU thread and iothread synchronize the execution using the checkpoints. vCPU thread processes the virtual timers and iothread processes all others. When iothread wants to wake up sleeping vCPU thread, it sends dummy queued work. Therefore it could be the following sequence of the events in record mode: - IO: sending dummy work - IO: processing timers - CPU: wakeup - CPU: clearing dummy work - CPU: processing virtual timers But due to the races in replay mode the sequence may change: - IO: sending dummy work - CPU: wakeup - CPU: clearing dummy work - CPU: sleeping again because nothing to do - IO: Processing timers - CPU: zzzz In this case vCPU will not wake up, because dummy work is not to be set up again. This patch tries to wake up the vCPU when it sleeps and the icount warp checkpoint isn't met. It means that vCPU has something to do, because there are no other reasons of non-matching warp checkpoint. Signed-off-by: Pavel Dovgalyuk -- v5: improve checking that vCPU is still sleeping Message-Id: <20180912081945.3228.19776.stgit@pasha-VirtualBox> Signed-off-by: Paolo Bonzini --- cpus.c | 31 +++++++++++++++++++++---------- include/sysemu/replay.h | 3 +++ replay/replay.c | 12 ++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/cpus.c b/cpus.c index d8b3b46..68f08f5 100644 --- a/cpus.c +++ b/cpus.c @@ -583,18 +583,29 @@ void qemu_start_warp_timer(void) return; } =20 - /* warp clock deterministically in record/replay mode */ - if (!replay_checkpoint(CHECKPOINT_CLOCK_WARP_START)) { - return; - } + if (replay_mode !=3D REPLAY_MODE_PLAY) { + if (!all_cpu_threads_idle()) { + return; + } =20 - if (!all_cpu_threads_idle()) { - return; - } + if (qtest_enabled()) { + /* When testing, qtest commands advance icount. */ + return; + } =20 - if (qtest_enabled()) { - /* When testing, qtest commands advance icount. */ - return; + replay_checkpoint(CHECKPOINT_CLOCK_WARP_START); + } else { + /* warp clock deterministically in record/replay mode */ + if (!replay_checkpoint(CHECKPOINT_CLOCK_WARP_START)) { + /* vCPU is sleeping and warp can't be started. + It is probably a race condition: notification sent + to vCPU was processed in advance and vCPU went to sleep. + Therefore we have to wake it up for doing someting. */ + if (replay_has_checkpoint()) { + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); + } + return; + } } =20 /* We want to use the earliest deadline from ALL vm_clocks */ diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 3ced6bc..7f7a594 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -120,6 +120,9 @@ void replay_shutdown_request(ShutdownCause cause); Returns 0 in PLAY mode if checkpoint was not found. Returns 1 in all other cases. */ bool replay_checkpoint(ReplayCheckpoint checkpoint); +/*! Used to determine that checkpoint is pending. + Does not proceed to the next event in the log. */ +bool replay_has_checkpoint(void); =20 /* Asynchronous events queue */ =20 diff --git a/replay/replay.c b/replay/replay.c index 8228261..379b51a 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -224,6 +224,18 @@ out: return res; } =20 +bool replay_has_checkpoint(void) +{ + bool res =3D false; + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + g_assert(replay_mutex_locked()); + replay_account_executed_instructions(); + res =3D EVENT_CHECKPOINT <=3D replay_state.data_kind + && replay_state.data_kind <=3D EVENT_CHECKPOINT_LAST; + } + return res; +} + static void replay_enable(const char *fname, int mode) { const char *fmode =3D NULL; --=20 1.8.3.1