From patchwork Fri Apr 7 15:42:21 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: 97037 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341559qgd; Fri, 7 Apr 2017 08:47:20 -0700 (PDT) X-Received: by 10.200.3.81 with SMTP id w17mr39588862qtg.36.1491580040659; Fri, 07 Apr 2017 08:47:20 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x63si5123728qke.200.2017.04.07.08.47.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:47:20 -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]:51512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW6a-0005oh-8U for patch@linaro.org; Fri, 07 Apr 2017 11:47:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1u-0002Rc-Tq for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1u-0007Xh-33 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:30 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:35889) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1t-0007X4-T6 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:30 -0400 Received: by mail-wr0-x22b.google.com with SMTP id c55so38350821wrc.3 for ; Fri, 07 Apr 2017 08:42:29 -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=ILPIZmbHiNNGn4LVBXUsUnQ4gCN+e11KWzBQMi4gCzc=; b=SI2rZnxGyvsmVWQJZnohKGb3abM/GpWVIjA7d8M8zf48TwlHYDDbRV3dgqeF3VVHhd x4MGM6XOkhqupLDil2y548XaxSHKzwSkip2f8bkj+hPR1OBZ2c+rCewhsnY0x7a5vCav nuZtwF+sPgpszKMyi97CxxHxfglzaBZE8cEaw= 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=ILPIZmbHiNNGn4LVBXUsUnQ4gCN+e11KWzBQMi4gCzc=; b=bsN1sVEskfWAAzxug4i6bcUKNLADqRzvnE/oczluGMUh+XLjAwxU8BUkCD4n8u0Jxl dvLGpZFDlQgJgMKHvwocpSWTxjy/Os4Rpf/YTIPkQ9leTfZ49RmNh9fS/SV4qudYim9N gky2qaqN0DAIsJmRUSXs15nPYJTVEkhkizf+DV0dB5lnKFDuSQnCjk/fAwAcLU/pIrHj u+Enb7bSk2n7xNYiCkiwMPJiS+suapMW7Uh0YE0//B06dPHbGNNSpMlDaKyTan62vR4s K1EV9tWr6//c3rEKUGLPnashHIARNpn5nN7570QJiNMv17/KVj6q/56L2lKwvmI39tRh CquA== X-Gm-Message-State: AFeK/H0ZU4PvzXfJoOCRgylXYyybjJtSR5qaXjeG6cjxkkHdd4gpConUuRwc1drFVe3jYJFD X-Received: by 10.223.153.233 with SMTP id y96mr18373827wrb.96.1491579748761; Fri, 07 Apr 2017 08:42:28 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v186sm6724577wmv.2.2017.04.07.08.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id E71623E178A; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:21 +0100 Message-Id: <20170407154221.26918-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-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::22b Subject: [Qemu-devel] [PATCH v3 12/12] replay: assert time only goes forward 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" If we find ourselves trying to add an event to the log where time has gone backwards it is because a vCPU event has occurred and the main-loop is not yet aware of time moving forward. This should not happen and if it does its better to fail early than generate a log that will have weird behaviour. Signed-off-by: Alex Bennée --- replay/replay-internal.c | 4 ++++ replay/replay.c | 4 ++++ 2 files changed, 8 insertions(+) -- 2.11.0 diff --git a/replay/replay-internal.c b/replay/replay-internal.c index bea7b4aa6b..fca8514012 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -195,6 +195,10 @@ void replay_save_instructions(void) if (replay_file && replay_mode == REPLAY_MODE_RECORD) { replay_mutex_lock(); int diff = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(diff >= 0); + if (diff > 0) { replay_put_event(EVENT_INSTRUCTION); replay_put_dword(diff); diff --git a/replay/replay.c b/replay/replay.c index 9e0724e756..f810628cac 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -84,6 +84,10 @@ void replay_account_executed_instructions(void) if (replay_state.instructions_count > 0) { int count = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(count >= 0); + replay_state.instructions_count -= count; replay_state.current_step += count; if (replay_state.instructions_count == 0) {