From patchwork Mon Apr 3 12:45:24 2017 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: 96636 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp85159qgd; Mon, 3 Apr 2017 05:54:46 -0700 (PDT) X-Received: by 10.200.35.195 with SMTP id r3mr17055277qtr.282.1491224086683; Mon, 03 Apr 2017 05:54:46 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c20si11798464qkb.229.2017.04.03.05.54.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:54:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1VO-00084L-AE for patch@linaro.org; Mon, 03 Apr 2017 08:54:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MW-0001Nx-Nb for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MV-00015V-Ra for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:36 -0400 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:33922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MV-00014O-Hi for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: by mail-wr0-x22e.google.com with SMTP id l43so169836316wre.1 for ; Mon, 03 Apr 2017 05:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I6dpZ2m4D+M4/C+rUO1cGS8MzDS0uWHAkxPQmtHdAs8=; b=XYIWjW9zWzkNWvv8P0GIyKB0+NR9opax7rYviJtnqiba0j7YYOC8Bu5NVhwz+lcMRm 9f+SNCroAj6uOHOsC9p7+KHITAaZairVN+k58qFgKVlos4dvlbg8TyKBARo12aoUzCRd Jysk/uCtFi4MCLrsav+pk/xEayZY4Ev9K22Mk= 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:mime-version:content-transfer-encoding; bh=I6dpZ2m4D+M4/C+rUO1cGS8MzDS0uWHAkxPQmtHdAs8=; b=QYXrMIx8dbrSoiVBuvg3yx5AO8kbMNiqg2j0YznXljpl2CAyrvqoBj4rZflUj2jAg5 Cxpb/Y8/Ex+yHvfiIi0SqhK97r/PQ1O1vTL5i/xfOCgkS4k0Rjn5r2+FmgFwBXYZxqK0 nJCugnSPpKKMQBFCdT18SBKVcMFCWGt/m6tQGranT6MRoUlas+BdqxcYs1vP+bqnwUCa e1bIbWVWSCnI3NT/sm1pyYq9PkuR8X3KxkHssN0mE0ud29iCJFmPPGHGxMYDT76psFzF mep1SCgrom3AdyP7f90eBYc8vpYm0BedVf576VqmB/9zA8ea6dvpNEmehoVDmVfSG++E b7Dw== X-Gm-Message-State: AFeK/H16a0iHxBz3VDr8Llt6XOxNS5XFpfzmhBb5D9Xavk+nfL/B1UhO M2P2OpwC0aY0/oFQ X-Received: by 10.28.29.138 with SMTP id d132mr9178633wmd.40.1491223534278; Mon, 03 Apr 2017 05:45:34 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c8sm18044309wrd.57.2017.04.03.05.45.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 684853E1106; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:24 +0100 Message-Id: <20170403124524.10824-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22e Subject: [Qemu-devel] [RFC PATCH v1 9/9] replay: gracefully handle backward time events 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: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, nikunj@linux.vnet.ibm.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For the purposes of record/replay time can only move forward. It is possible for the non-vCPU thread to find time has moved from under its feet as it goes on. This is OK as long as we don't try and re-wind time. Signed-off-by: Alex Bennée --- replay/replay-internal.c | 7 +++++++ replay/replay.c | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/replay/replay-internal.c b/replay/replay-internal.c index bea7b4aa6b..9656db7102 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -199,6 +199,13 @@ void replay_save_instructions(void) replay_put_event(EVENT_INSTRUCTION); replay_put_dword(diff); replay_state.current_step += diff; + } else if (diff < 0) { + /* Time has caught up with us, so as far as we are + * concerned use now, not the past. We still put an event + * in the stream to keep in sync. + */ + replay_put_event(EVENT_INSTRUCTION); + replay_put_dword(0); } replay_mutex_unlock(); } diff --git a/replay/replay.c b/replay/replay.c index 9e0724e756..f4376df0fd 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -84,8 +84,13 @@ void replay_account_executed_instructions(void) if (replay_state.instructions_count > 0) { int count = (int)(replay_get_current_step() - replay_state.current_step); - replay_state.instructions_count -= count; - replay_state.current_step += count; + + /* Time only goes forward */ + if (count >= 0) { + replay_state.instructions_count -= count; + replay_state.current_step += count; + } + if (replay_state.instructions_count == 0) { assert(replay_state.data_kind == EVENT_INSTRUCTION); replay_finish_event();