From patchwork Mon Apr 10 12:55: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: 97130 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1351888qgd; Mon, 10 Apr 2017 06:03:59 -0700 (PDT) X-Received: by 10.176.68.101 with SMTP id m92mr22885446uam.18.1491829439031; Mon, 10 Apr 2017 06:03:59 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 23si5700701uav.32.2017.04.10.06.03.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:03:59 -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]:34392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYz6-000127-Qt for patch@linaro.org; Mon, 10 Apr 2017 09:03:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqv-0002WW-Ec for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqu-0003BE-N4 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:29 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:35697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqu-0003As-GD for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:28 -0400 Received: by mail-wr0-x22f.google.com with SMTP id o21so119855304wrb.2 for ; Mon, 10 Apr 2017 05:55:28 -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=YpwkziI//txJ5Aey6bJ6KGdW498uEIr/i8vOq6DTUwE=; b=WbhQs524MAlWhu8Y6xcfMtY58PYqyJG+NolWw4P7H9QdYu137v+GJLyysZijClNFTp 7FK1tBg8JZuBIKVNypS5ISSZ3O1ecRe4lNG7ONjlYUcH2JO539mcglR+lt7U6311kiyZ yzXE6wmKj0x4RQ+jmtvZjloHIJV3zT9DI5ZiM= 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=YpwkziI//txJ5Aey6bJ6KGdW498uEIr/i8vOq6DTUwE=; b=fMKxqQQdgkuHyZIF4rIGDbVxz1LO9XFkZBflFuwMsAk56ulq4FYjgMVgJbTsArluF4 XzWscd0acld7G1Q2W+dy9Rs2UZFjc1dvZnfn70CKhMG7rB2rvMzYALw1umJjrJbiC4DB DH5qtAVWtFKTNEcGXHorKVh2no2c5gktyzEM6ZveksYc5S9rnbm/xwmnFsRhOCUtIhpj mrjBnl8plLRx5IpOHyHGs4RvlYG+MSZivN/KBximyGKp5ud3RSZOKBWvbBW4nwrzxPfp KmXYX8OAnR3dPZjHJyjxetwtL5dFRw82BciriwNk4XDk7sJjx5kizhI/sPePUZ2Eo9p8 t6sw== X-Gm-Message-State: AN3rC/5CQtvAOIgI3xFsTDa7E1y2UWSqdoDr+AfGe3ja5TbOW9hnuxwnI3eGJBsHSitl1n3H X-Received: by 10.223.175.218 with SMTP id y26mr5108354wrd.63.1491828927404; Mon, 10 Apr 2017 05:55:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o77sm2507328wrc.38.2017.04.10.05.55.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:24 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A5A343E10CE; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:24 +0100 Message-Id: <20170410125524.21008-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-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::22f Subject: [Qemu-devel] [PULL 11/11] 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org 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 -- 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) {