From patchwork Wed Apr 5 13:24:52 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: 96848 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp258336obc; Wed, 5 Apr 2017 06:25:32 -0700 (PDT) X-Received: by 10.237.63.39 with SMTP id p36mr27590898qtf.187.1491398732143; Wed, 05 Apr 2017 06:25:32 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v2si17766655qte.298.2017.04.05.06.25.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:25:32 -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]:40553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkwF-0004dv-Mx for patch@linaro.org; Wed, 05 Apr 2017 09:25:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvq-0004VR-PQ for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvo-0000Cv-OZ for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:06 -0400 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]:36361) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvo-0000Cf-IQ for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:04 -0400 Received: by mail-wr0-x235.google.com with SMTP id w11so13731202wrc.3 for ; Wed, 05 Apr 2017 06:25:04 -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=y4gLmuyiJw4HesVY6D0Ojzjezl7TjKLlEXwQrdHobHg=; b=XvjMPT9k/uYDRTkTG6o8j8NjuOJ+6lQxHkvIG1fUgw6H08FXvWAVLm5Tm3A+ZL+0MO LpEacab3Xpf26J+I591OeOVAt19lJZUT7ZfsDwWOMDRUNmlUK75u4ifdY2feMpXYopom 3b5MDwiJD1rsvlimbH3Xnfe7VRl1JSoOgXXto= 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=y4gLmuyiJw4HesVY6D0Ojzjezl7TjKLlEXwQrdHobHg=; b=JG92XtEXaAoQ27x5aqCly1a8XXNIYpOG5vpzrNSm4YQO//HdA0ew6S+9JU3JOIBD6h eDTtr3BQFFNhhpN6y4eV1yWl/yAdAvc4zMfVsaK9LdvALoFsJhavt7CrnczLN94DaM/D 73bZ9T+zowzOm+MmxAA2rfFqltqJ3wpCXW2keAM5hzImEgQ54H4LfmfgEHmut9rwrH3t w7lZTmPa1YMHv8a4cOlzD795itGWqhJP+tB2MHK5xHY/OYBTi/ncRnewnGC5HcBjMMLK cqYjA2rpOibqEX6tPKtJ8OSUTg69sJG0pWipfg+54dEZobKxiIbS6os5eMjD9bP9YOdc dePQ== X-Gm-Message-State: AFeK/H0uq6kDymZAsFjshTSlOmdOoVkr0s+lFF+GaI1cJk56VyWB1XvKDEJdZM8A0FRHtW2l X-Received: by 10.28.64.135 with SMTP id n129mr13808757wma.45.1491398702916; Wed, 05 Apr 2017 06:25:02 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u9sm12512275wme.8.2017.04.05.06.25.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:01 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 2EDCF3E029D; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:52 +0100 Message-Id: <20170405132503.32125-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::235 Subject: [Qemu-devel] [PATCH v2 01/12] scripts/qemugdb/mtree.py: fix up mtree dump 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" Since QEMU has been able to build with native Int128 support this was broken as it attempts to fish values out of the non-existent structure. Also the alias print was trying to make a %x out of gdb.ValueType directly which didn't seem to work. Signed-off-by: Alex Bennée --- scripts/qemugdb/mtree.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/scripts/qemugdb/mtree.py b/scripts/qemugdb/mtree.py index cc8131c2e7..e6791b7885 100644 --- a/scripts/qemugdb/mtree.py +++ b/scripts/qemugdb/mtree.py @@ -21,7 +21,15 @@ def isnull(ptr): return ptr == gdb.Value(0).cast(ptr.type) def int128(p): - return int(p['lo']) + (int(p['hi']) << 64) + '''Read an Int128 type to a python integer. + + QEMU can be built with native Int128 support so we need to detect + if the value is a structure or the native type. + ''' + if p.type.code == gdb.TYPE_CODE_STRUCT: + return int(p['lo']) + (int(p['hi']) << 64) + else: + return int(("%s" % p), 16) class MtreeCommand(gdb.Command): '''Display the memory tree hierarchy''' @@ -69,7 +77,7 @@ class MtreeCommand(gdb.Command): gdb.write('%s alias: %s@%016x (@ %s)\n' % (' ' * level, alias['name'].string(), - ptr['alias_offset'], + int(ptr['alias_offset']), alias, ), gdb.STDOUT) From patchwork Wed Apr 5 13:24:53 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: 96850 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp258898obc; Wed, 5 Apr 2017 06:26:48 -0700 (PDT) X-Received: by 10.200.42.13 with SMTP id k13mr27801908qtk.230.1491398808191; Wed, 05 Apr 2017 06:26:48 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g31si17789643qtd.131.2017.04.05.06.26.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:26:48 -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]:40555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkxT-0005W4-KO for patch@linaro.org; Wed, 05 Apr 2017 09:26:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvr-0004Wg-Rc for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvq-0000E7-C7 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:07 -0400 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:35396) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvq-0000DH-5n for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:06 -0400 Received: by mail-wr0-x234.google.com with SMTP id k6so14519350wre.2 for ; Wed, 05 Apr 2017 06:25:06 -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=f9S/5vQAaqH5p1VznmOtF2yJj3YXgg3ABa33JNSOsG0=; b=dqm0p3fBblP3NviOnx9dzMAn5ZnWe1DoDJzoj3QJw9dnERt4t+mahrd9Eykdegy3VC SEDdGNtIPcMOYkLvz4FPMFvmn29EsfR7/QmlMN97byQw1dgVxZKIkLyI8gJLzrcXp0of 7yx8NHRHuSbVMbxXDhplnK/PEnYy9tpUO3wXQ= 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=f9S/5vQAaqH5p1VznmOtF2yJj3YXgg3ABa33JNSOsG0=; b=A4ecPbSwF5HGDy50xxuARR/IE3KK5aeT7+i+ZjTjMWig+Js3YO4+BKUYQtA+5wJK7n ROVxrEmBdlCfOYc+hSH2rBTpqmdmsaYC/AktXF4nrDVfevGT5JmB6rbcdngM/R/Ef97W UP0uuVYuV89SInVOkeXeLyZIW05MZdDz2YeZBNulQI4vDCBAzENlMIjfMpVs69X/N7cV Aqv9retGJfxDbLC5opNkDUcVR15YsnXnk1ufxeKgTrcz1Cpx+gS/I+8+FGAERJXkT6Wn onhW67Md2LRXCXO8kn7TGhd7F8fgw14NpOY8Qmka6KS2L0ZKAv8XXs8JWfNIpq5sHnlF 5C2w== X-Gm-Message-State: AFeK/H3jpKTxr/tdPQR8RAsWtU5GcA0OCXqGUlvpWSzAvLC4aUdSvH2M83QtKRPIZd8j7sfy X-Received: by 10.223.151.193 with SMTP id t1mr26802882wrb.149.1491398704925; Wed, 05 Apr 2017 06:25:04 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g41sm26170462wrg.53.2017.04.05.06.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:02 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 407513E031F; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:53 +0100 Message-Id: <20170405132503.32125-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::234 Subject: [Qemu-devel] [PATCH v2 02/12] scripts/qemu-gdb/timers.py: new helper to dump timer state 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" This introduces the qemu-gdb command "qemu timers" which will dump the state of the main timers in the system. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/timers.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/timers.py -- 2.11.0 diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index b3f8e04f77..3e7adb87dc 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -26,7 +26,7 @@ import os, sys sys.path.append(os.path.dirname(__file__)) -from qemugdb import aio, mtree, coroutine +from qemugdb import aio, mtree, coroutine, timers class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands''' @@ -38,6 +38,7 @@ QemuCommand() coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() +timers.TimersCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() diff --git a/scripts/qemugdb/timers.py b/scripts/qemugdb/timers.py new file mode 100644 index 0000000000..be71a001e3 --- /dev/null +++ b/scripts/qemugdb/timers.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# GDB debugging support +# +# Copyright 2017 Linaro Ltd +# +# Author: Alex Bennée +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. + +# 'qemu timers' -- display the current timerlists + +import gdb + +class TimersCommand(gdb.Command): + '''Display the current QEMU timers''' + + def __init__(self): + 'Register the class as a gdb command' + gdb.Command.__init__(self, 'qemu timers', gdb.COMMAND_DATA, + gdb.COMPLETE_NONE) + + def dump_timers(self, timer): + "Follow a timer and recursively dump each one in the list." + # timer should be of type QemuTimer + gdb.write(" timer %s/%s (cb:%s,opq:%s)\n" % ( + timer['expire_time'], + timer['scale'], + timer['cb'], + timer['opaque'])) + + if int(timer['next']) > 0: + self.dump_timers(timer['next']) + + + def process_timerlist(self, tlist, ttype): + gdb.write("Processing %s timers\n" % (ttype)) + gdb.write(" clock %s is enabled:%s, last:%s\n" % ( + tlist['clock']['type'], + tlist['clock']['enabled'], + tlist['clock']['last'])) + if int(tlist['active_timers']) > 0: + self.dump_timers(tlist['active_timers']) + + + def invoke(self, arg, from_tty): + 'Run the command' + main_timers = gdb.parse_and_eval("main_loop_tlg") + + # This will break if QEMUClockType in timer.h is redfined + self.process_timerlist(main_timers['tl'][0], "Realtime") + self.process_timerlist(main_timers['tl'][1], "Virtual") + self.process_timerlist(main_timers['tl'][2], "Host") + self.process_timerlist(main_timers['tl'][3], "Virtual RT") From patchwork Wed Apr 5 13:24:54 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: 96852 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260021obc; Wed, 5 Apr 2017 06:29:19 -0700 (PDT) X-Received: by 10.200.47.208 with SMTP id m16mr27735722qta.103.1491398959607; Wed, 05 Apr 2017 06:29:19 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o62si17788352qkb.99.2017.04.05.06.29.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:29:19 -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]:40563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkzv-0007ug-3z for patch@linaro.org; Wed, 05 Apr 2017 09:29:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvs-0004Wt-D6 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvq-0000Dl-3J for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:08 -0400 Received: from mail-wr0-x236.google.com ([2a00:1450:400c:c0c::236]:36374) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvp-0000D7-Q3 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:06 -0400 Received: by mail-wr0-x236.google.com with SMTP id w11so13731963wrc.3 for ; Wed, 05 Apr 2017 06:25:05 -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=rcMB9rObBzfaiH0juvPXMmfOxfhZ44tiN81BcEBHgnw=; b=dra1VPNhEgrs9jkBEZ1k/brzPYY5TaOB8MfG78WtTuv0/G1gBPvQUnIjDzdEAlRgOw EVhamTvdlZA913jPxBRnaKPvjH7Au/Ofrpa/2FrckHy0b+BGpbxGlX7pfK6sTb9XC3Z1 t5qimm0qB8CEjaJQnTaw1Fr6F4M7sSs0UcUPM= 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=rcMB9rObBzfaiH0juvPXMmfOxfhZ44tiN81BcEBHgnw=; b=jNkp8O2pHKk0mJvPaZXyJJv30utIN1kOzi+sde6mmnXGlS/qTbOt/dQ6sOz9SjRV/R pDQX8LIJEb7vXFcO4wr5qK990vuL5B6Bk33OF2BiAzyZBgGGos2zaA+Z5yjlUUbyRaXA Khpe6selmbHEaEZgrQXZ+Dz7rOJ4X0EwCls5KUa1aly/5C21Jkx/PWqmmj/9MJBMXq5o 7FTKMDnihtRJhN6Mk03A25Jm2yheNbuIxNTAP2aVxl3RD18etTjSZN1j8O3CY1Q0r8Nv YmKbax/kp3lchkc2YRfeJEkegxNC0QXi8rTJpAAsmi+gm5vJGFUBFidN4t/DHjr/H6j5 SXIg== X-Gm-Message-State: AFeK/H1aIv7Uq8SbGwH1rrQF5tMwQ2hGPwd4q3ukvjFTKUKUKEErskvWjs8++VXW11FtukEr X-Received: by 10.28.147.129 with SMTP id v123mr19785233wmd.51.1491398703966; Wed, 05 Apr 2017 06:25:03 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v29sm26179892wrv.66.2017.04.05.06.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:02 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 50D5D3E080A; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:54 +0100 Message-Id: <20170405132503.32125-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::236 Subject: [Qemu-devel] [PATCH v2 03/12] scripts/replay-dump.py: replay log dumper 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" This script is a debugging tool for looking through the contents of a replay log file. It is incomplete but should fail gracefully at events it doesn't understand. It currently understands two different log formats as the audio record/replay support was merged during since MTTCG. It was written to help debug what has caused the BQL changes to break replay support. Signed-off-by: Alex Bennée --- scripts/replay-dump.py | 272 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100755 scripts/replay-dump.py -- 2.11.0 diff --git a/scripts/replay-dump.py b/scripts/replay-dump.py new file mode 100755 index 0000000000..fdd178aba0 --- /dev/null +++ b/scripts/replay-dump.py @@ -0,0 +1,272 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Dump the contents of a recorded execution stream +# +# Copyright (c) 2017 Alex Bennée +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see . + +import argparse +import struct +from collections import namedtuple + +# This mirrors some of the global replay state which some of the +# stream loading refers to. Some decoders may read the next event so +# we need handle that case. Calling reuse_event will ensure the next +# event is read from the cache rather than advancing the file. + +class ReplayState(object): + def __init__(self): + self.event = -1 + self.event_count = 0 + self.already_read = False + self.current_checkpoint = 0 + self.checkpoint = 0 + + def set_event(self, ev): + self.event = ev + self.event_count += 1 + + def get_event(self): + self.already_read = False + return self.event + + def reuse_event(self, ev): + self.event = ev + self.already_read = True + + def set_checkpoint(self): + self.checkpoint = self.event - self.checkpoint_start + + def get_checkpoint(self): + return self.checkpoint + +replay_state = ReplayState() + +# Simple read functions that mirror replay-internal.c +# The file-stream is big-endian and manually written out a byte at a time. + +def read_byte(fin): + "Read a single byte" + return struct.unpack('>B', fin.read(1))[0] + +def read_event(fin): + "Read a single byte event, but save some state" + if replay_state.already_read: + return replay_state.get_event() + else: + replay_state.set_event(read_byte(fin)) + return replay_state.event + +def read_word(fin): + "Read a 16 bit word" + return struct.unpack('>H', fin.read(2))[0] + +def read_dword(fin): + "Read a 32 bit word" + return struct.unpack('>I', fin.read(4))[0] + +def read_qword(fin): + "Read a 64 bit word" + return struct.unpack('>Q', fin.read(8))[0] + +# Generic decoder structure +Decoder = namedtuple("Decoder", "eid name fn") + +def call_decode(table, index, dumpfile): + "Search decode table for next step" + decoder = next((d for d in table if d.eid == index), None) + if not decoder: + print "Could not decode index: %d" % (index) + print "Entry is: %s" % (decoder) + print "Decode Table is:\n%s" % (table) + return False + else: + return decoder.fn(decoder.eid, decoder.name, dumpfile) + +# Print event +def print_event(eid, name, string=None, event_count=None): + "Print event with count" + if not event_count: + event_count = replay_state.event_count + + if string: + print "%d:%s(%d) %s" % (event_count, name, eid, string) + else: + print "%d:%s(%d)" % (event_count, name, eid) + + +# Decoders for each event type + +def decode_unimp(eid, name, _unused_dumpfile): + "Unimplimented decoder, will trigger exit" + print "%s not handled - will now stop" % (name) + return False + +# Checkpoint decoder +def swallow_async_qword(eid, name, dumpfile): + "Swallow a qword of data without looking at it" + step_id = read_qword(dumpfile) + print " %s(%d) @ %d" % (name, eid, step_id) + return True + +async_decode_table = [ Decoder(0, "REPLAY_ASYNC_EVENT_BH", swallow_async_qword), + Decoder(1, "REPLAY_ASYNC_INPUT", decode_unimp), + Decoder(2, "REPLAY_ASYNC_INPUT_SYNC", decode_unimp), + Decoder(3, "REPLAY_ASYNC_CHAR_READ", decode_unimp), + Decoder(4, "REPLAY_ASYNC_EVENT_BLOCK", decode_unimp), + Decoder(5, "REPLAY_ASYNC_EVENT_NET", decode_unimp), +] +# See replay_read_events/replay_read_event +def decode_async(eid, name, dumpfile): + """Decode an ASYNC event""" + + print_event(eid, name) + + async_event_kind = read_byte(dumpfile) + async_event_checkpoint = read_byte(dumpfile) + + if async_event_checkpoint != replay_state.current_checkpoint: + print " mismatch between checkpoint %d and async data %d" % ( + replay_state.current_checkpoint, async_event_checkpoint) + return True + + return call_decode(async_decode_table, async_event_kind, dumpfile) + + +def decode_instruction(eid, name, dumpfile): + ins_diff = read_dword(dumpfile) + print_event(eid, name, "0x%x" % (ins_diff)) + return True + +def decode_audio_out(eid, name, dumpfile): + audio_data = read_dword(dumpfile) + print_event(eid, name, "%d" % (audio_data)) + return True + +def decode_checkpoint(eid, name, dumpfile): + """Decode a checkpoint. + + Checkpoints contain a series of async events with their own specific data. + """ + replay_state.set_checkpoint() + # save event count as we peek ahead + event_number = replay_state.event_count + next_event = read_event(dumpfile) + + # if the next event is EVENT_ASYNC there are a bunch of + # async events to read, otherwise we are done + if next_event != 3: + print_event(eid, name, "no additional data", event_number) + else: + print_event(eid, name, "more data follows", event_number) + + replay_state.reuse_event(next_event) + return True + +def decode_checkpoint_init(eid, name, dumpfile): + print_event(eid, name) + return True + +def decode_interrupt(eid, name, dumpfile): + print_event(eid, name) + return True + +def decode_clock(eid, name, dumpfile): + clock_data = read_qword(dumpfile) + print_event(eid, name, "0x%x" % (clock_data)) + return True + + +# pre-MTTCG merge +v5_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction), + Decoder(1, "EVENT_INTERRUPT", decode_interrupt), + Decoder(2, "EVENT_EXCEPTION", decode_unimp), + Decoder(3, "EVENT_ASYNC", decode_async), + Decoder(4, "EVENT_SHUTDOWN", decode_unimp), + Decoder(5, "EVENT_CHAR_WRITE", decode_unimp), + Decoder(6, "EVENT_CHAR_READ_ALL", decode_unimp), + Decoder(7, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp), + Decoder(8, "EVENT_CLOCK_HOST", decode_clock), + Decoder(9, "EVENT_CLOCK_VIRTUAL_RT", decode_clock), + Decoder(10, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint), + Decoder(11, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint), + Decoder(12, "EVENT_CP_RESET_REQUESTED", decode_checkpoint), + Decoder(13, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint), + Decoder(14, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint), + Decoder(15, "EVENT_CP_CLOCK_HOST", decode_checkpoint), + Decoder(16, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint), + Decoder(17, "EVENT_CP_INIT", decode_checkpoint_init), + Decoder(18, "EVENT_CP_RESET", decode_checkpoint), +] + +# post-MTTCG merge, AUDIO support added +v6_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction), + Decoder(1, "EVENT_INTERRUPT", decode_interrupt), + Decoder(2, "EVENT_EXCEPTION", decode_unimp), + Decoder(3, "EVENT_ASYNC", decode_async), + Decoder(4, "EVENT_SHUTDOWN", decode_unimp), + Decoder(5, "EVENT_CHAR_WRITE", decode_unimp), + Decoder(6, "EVENT_CHAR_READ_ALL", decode_unimp), + Decoder(7, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp), + Decoder(8, "EVENT_AUDIO_OUT", decode_audio_out), + Decoder(9, "EVENT_AUDIO_IN", decode_unimp), + Decoder(10, "EVENT_CLOCK_HOST", decode_clock), + Decoder(11, "EVENT_CLOCK_VIRTUAL_RT", decode_clock), + Decoder(12, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint), + Decoder(13, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint), + Decoder(14, "EVENT_CP_RESET_REQUESTED", decode_checkpoint), + Decoder(15, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint), + Decoder(16, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint), + Decoder(17, "EVENT_CP_CLOCK_HOST", decode_checkpoint), + Decoder(18, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint), + Decoder(19, "EVENT_CP_INIT", decode_checkpoint_init), + Decoder(20, "EVENT_CP_RESET", decode_checkpoint), +] + +def parse_arguments(): + "Grab arguments for script" + parser = argparse.ArgumentParser() + parser.add_argument("-f", "--file", help='record/replay dump to read from', + required=True) + return parser.parse_args() + +def decode_file(filename): + "Decode a record/replay dump" + dumpfile = open(filename, "rb") + + # read and throwaway the header + version = read_dword(dumpfile) + junk = read_qword(dumpfile) + + print "HEADER: version 0x%x" % (version) + if version == 0xe02006: + event_decode_table = v6_event_table + replay_state.checkpoint_start = 12 + else: + event_decode_table = v5_event_table + replay_state.checkpoint_start = 10 + + try: + decode_ok = True + while decode_ok: + event = read_event(dumpfile) + decode_ok = call_decode(event_decode_table, event, dumpfile) + finally: + dumpfile.close() + +if __name__ == "__main__": + args = parse_arguments() + decode_file(args.file) From patchwork Wed Apr 5 13:24:55 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: 96855 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260358obc; Wed, 5 Apr 2017 06:30:03 -0700 (PDT) X-Received: by 10.200.50.20 with SMTP id x20mr28548925qta.169.1491399003499; Wed, 05 Apr 2017 06:30:03 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h10si17801872qta.54.2017.04.05.06.30.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:30:03 -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]:40568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl0d-0000F1-2R for patch@linaro.org; Wed, 05 Apr 2017 09:30:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvv-0004cd-AN for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvr-0000Fs-4S for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:11 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:35407) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvq-0000E2-Vc for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:07 -0400 Received: by mail-wr0-x233.google.com with SMTP id k6so14519971wre.2 for ; Wed, 05 Apr 2017 06:25:06 -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=Vma+WY0g4IYtFBe1+uJbndMPoNWlWhlcNAqnBcBpzD0=; b=TEYXeY3dL2noLfUhsrZ89YYSPmU3dLkFjXw1oqdSgw53zpfe8wflY9fSTcG3JeVE7A JvDCPc47C/amMRKAlMZPAkWObSqDyAbZNt0TDFtGlVd8pDqaxT/V5f5cboAGW2UqKr9b LIk4MKvxwonE7a8KOjYx4+IxswI3GG9EuyvZA= 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=Vma+WY0g4IYtFBe1+uJbndMPoNWlWhlcNAqnBcBpzD0=; b=XKP19Ih6NAn+vUvMezIRvLjlGwLAil9/PGnoC9TGnSmersQg5/s+i97Q0uI2VPzX2E Oza3f/Z/fMAygeRabGmAhFcI+9GsB/5YAA8zJjaP72UkDVX3e4HSy+cMyixYnb4DuCgS UWtgc6h7NopOx/0x9ekYagj8XJxaNEKkLqaK+bNQ67gpl/Cw/MEYJDwj9q3aXLajXoVj FVtM0E+aNF9LNGVuPmCHrp9xqOP/SsLoGUXYMGgxTlpSUc0K/Bgk3fQKqErkqXWoGC3W eQlm2NhioEYKox7D9/MGP4Q8kDgzear/g+24tKsFgTzmjo4bKNuHsSWSbIJhcgM6K0hT MVsg== X-Gm-Message-State: AN3rC/52gnPqJkFMAlcwFuiczNGtHgPJZPP4LC4TT/L+g8lGKIDlM+0R 8KXWoijbAfgut232 X-Received: by 10.28.213.198 with SMTP id m189mr609463wmg.102.1491398705830; Wed, 05 Apr 2017 06:25:05 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id b199sm22362012wmb.13.2017.04.05.06.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:02 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 620FC3E087F; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:55 +0100 Message-Id: <20170405132503.32125-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::233 Subject: [Qemu-devel] [PATCH v2 04/12] target/i386/misc_helper: wrap BQL around another IRQ generator 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, Eduardo Habkost , 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" Anything that calls into HW emulation must be protected by the BQL. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Acked-by: Eduardo Habkost --- target/i386/misc_helper.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.11.0 diff --git a/target/i386/misc_helper.c b/target/i386/misc_helper.c index ca2ea09f54..628f64aad5 100644 --- a/target/i386/misc_helper.c +++ b/target/i386/misc_helper.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "exec/helper-proto.h" #include "exec/exec-all.h" @@ -156,7 +157,9 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0) break; case 8: if (!(env->hflags2 & HF2_VINTR_MASK)) { + qemu_mutex_lock_iothread(); cpu_set_apic_tpr(x86_env_get_cpu(env)->apic_state, t0); + qemu_mutex_unlock_iothread(); } env->v_tpr = t0 & 0x0f; break; From patchwork Wed Apr 5 13:24:56 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: 96853 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260024obc; Wed, 5 Apr 2017 06:29:19 -0700 (PDT) X-Received: by 10.200.54.136 with SMTP id a8mr31151265qtc.185.1491398959857; Wed, 05 Apr 2017 06:29:19 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n20si6363222qki.228.2017.04.05.06.29.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:29:19 -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]:40564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkzv-0007uj-Dz for patch@linaro.org; Wed, 05 Apr 2017 09:29:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvu-0004ZW-BH for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvt-0000Iq-AD for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:10 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:33691) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvt-0000Hk-4Q for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:09 -0400 Received: by mail-wr0-x22d.google.com with SMTP id w43so14047405wrb.0 for ; Wed, 05 Apr 2017 06:25:09 -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=24uhtL1rsRWJyGEN487kXclBTAGuCMUuaxwKASZpmQA=; b=cH/MREoE03CBTrH0bmhc20QlxoC/2BQDKC3m4GsfOlNj7/BiIVuJoCXZJ6L2yFOGUc 8XMs1JrND5IBxWjRKBjt1oVgWqzWT6XEQbgAFD8euzrP2yImVg4SbacNimGydtZN0BWK uO5E2UOwQxMUGIIUXdCFsVUM6T3AjZrygojBE= 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=24uhtL1rsRWJyGEN487kXclBTAGuCMUuaxwKASZpmQA=; b=PQNGtfbCGbOfZn44CkwjhGRgTajLl189NKEPyRx/xWi1VF7SP6XQf6MuJSWVQWkiSf fVv1DpfN9fyt/8UvbU2e19qhXR0lhXMbJ0GNRRc/CMbwSyNPXwLvf+lHpLGkpYHJJy/C j5FapWff117E8E0n329XWfvDDFxbvSSn9f+VI5UtojgK7mBodH+btGIsyskTD6mn3gIg j2Ls2phSCGODhhm/qeh50wH8MKvGQZ2/r92wAe0lhLtc8tpDS8A7L2NpY5TZ6CJhLafq t4GpC/xrKLwNjhXgepvCICSbfVRkzlLBzKTUp6cs4WoFjZaodZkrL4j2cASMhH+onaL0 yk6w== X-Gm-Message-State: AFeK/H3fGHb0GpUqInDl99bddXO8G278c2G5oQfZtphx128Nt9jXlHnlPlMur/xeMkc3RhLx X-Received: by 10.223.150.121 with SMTP id c54mr3150444wra.202.1491398707547; Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f62sm7761150wmh.33.2017.04.05.06.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:02 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 7352F3E088F; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:56 +0100 Message-Id: <20170405132503.32125-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::22d Subject: [Qemu-devel] [PATCH v2 05/12] cpus: remove icount handling from qemu_tcg_cpu_thread_fn 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, Peter Crosthwaite , 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" We should never be running in multi-threaded mode with icount enabled. There is no point calling handle_icount_deadline here so remove it and assert !use_icount. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 68fdbc40b9..4e48b9c4ad 100644 --- a/cpus.c +++ b/cpus.c @@ -1392,6 +1392,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUState *cpu = arg; + g_assert(!use_icount); + rcu_register_thread(); qemu_mutex_lock_iothread(); @@ -1434,8 +1436,6 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } } - handle_icount_deadline(); - atomic_mb_set(&cpu->exit_request, 0); qemu_tcg_wait_io_event(cpu); } From patchwork Wed Apr 5 13:24:57 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: 96851 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp259999obc; Wed, 5 Apr 2017 06:29:16 -0700 (PDT) X-Received: by 10.55.105.6 with SMTP id e6mr26849606qkc.252.1491398956421; Wed, 05 Apr 2017 06:29:16 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z32si17788510qtg.133.2017.04.05.06.29.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:29:16 -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]:40562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkzr-0007rE-W8 for patch@linaro.org; Wed, 05 Apr 2017 09:29:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvs-0004X2-PP for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvr-0000Gj-Um for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:08 -0400 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:35417) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvr-0000Fl-PD for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:07 -0400 Received: by mail-wr0-x22e.google.com with SMTP id k6so14520524wre.2 for ; Wed, 05 Apr 2017 06:25:07 -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=F09GCa5eHvuVekUK+Doi4XLbF9zSIlDsNKTqOGhWdxw=; b=gjXEi2aqNA3bhFS6pt/lG8mkkN8zr8tPF2PwEBoxr2lYQMudj6nfH8p606lhwFwp7z hsnMroA8Ue7lE/+JJxarfShC0EV28+ylY3mBkjw1Rg+gjdjEn0cvi8Taf3EGNIbLjvFP Va8uav2jty4W7eEuDY5//NRy+c/GNDqUOeD/w= 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=F09GCa5eHvuVekUK+Doi4XLbF9zSIlDsNKTqOGhWdxw=; b=kUMCfkyUEThzWNgy35Q3e3MMhxpMzmzhwdtn9iJro5/JJhqEY1IUz2W8UhxHuAXayq r57tZ7D1SlsGghJwdJDinAOFPvSb35BQZifLlsHacoG/HCvN5XsXvcQboje43O3XCcto 5b5j2tkzhoocMEvre0JQmXQX7kUPkxYHrv2VyhAMHmXTLOPTJlQPxd5ms6EMJUBnMlFO UqxRYmIlPzpnUgPS7ix+bZaZdkXKPX+1T5SH7hH6Da2TCqAHIkulw1yVSf6me3NUuCGd y3+j/kVPXmDgMu5Pwc4CfYsQ0pPjl67k3TsTGd7mHFMYJHxC0ZAQnBl3fuzfc3GssWoZ cw0g== X-Gm-Message-State: AFeK/H1P/QS7kJ6ql7sHk5idVAT16CSoZhleD/v1QEJhFCuUJ9oHb/lJaK13dALZt7+ppNeS X-Received: by 10.28.139.195 with SMTP id n186mr20391160wmd.139.1491398706602; Wed, 05 Apr 2017 06:25:06 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 81sm22385813wmj.9.2017.04.05.06.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:02 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 842483E0BC6; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:57 +0100 Message-Id: <20170405132503.32125-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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] [PATCH v2 06/12] cpus: check cpu->running in cpu_get_icount_raw() 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, Peter Crosthwaite , 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" The lifetime of current_cpu is now the lifetime of the vCPU thread. However get_icount_raw() can apply a fudge factor if called while code is running to take into account the current executed instruction count. To ensure this is always the case we also check cpu->running. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- cpus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 4e48b9c4ad..18b1746770 100644 --- a/cpus.c +++ b/cpus.c @@ -229,7 +229,7 @@ int64_t cpu_get_icount_raw(void) CPUState *cpu = current_cpu; icount = timers_state.qemu_icount; - if (cpu) { + if (cpu && cpu->running) { if (!cpu->can_do_io) { fprintf(stderr, "Bad icount read\n"); exit(1); From patchwork Wed Apr 5 13:24:58 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: 96854 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260356obc; Wed, 5 Apr 2017 06:30:03 -0700 (PDT) X-Received: by 10.200.40.86 with SMTP id 22mr32090546qtr.245.1491399003194; Wed, 05 Apr 2017 06:30:03 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g50si17810233qtc.60.2017.04.05.06.30.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:30:03 -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]:40567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl0c-0000Eh-Nb for patch@linaro.org; Wed, 05 Apr 2017 09:30:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvw-0004ec-Oe for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvv-0000KM-Oo for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:36445) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvv-0000Jy-Hj for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:11 -0400 Received: by mail-wr0-x22f.google.com with SMTP id w11so13736044wrc.3 for ; Wed, 05 Apr 2017 06:25:11 -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=do5s9bqyDkirtBCVtHMCEH1EhNrpNVT5N+MVuFJKP1s=; b=CfFP3sJs8oRSnCDnunm5J15c1dv8ADoCg/2lwQUMwSdS7YK/nX8lZcthMKM7e6aEu8 mEm5WURuWDkYWj5brHl/2+7zXHWszAd6WhnFQikdk1n7z5Sh39U8HF8CISZOx308iwmH aofR0/3eo97DPiyjL7Thh3fcwIHUm/4sk6IZM= 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=do5s9bqyDkirtBCVtHMCEH1EhNrpNVT5N+MVuFJKP1s=; b=AKdP+iMLCxKJoPwuvBi3Jm/+hrz6+6dXVwy7TQAKXIiaj5AwMHOfgbly+eVxfJiuPy JuNQFwvpWWyQ108DYDIY0rkFdJnXxAUkL/2Snd6QiMTJhLpiIR+ZJZVfhs00XPCXOmz6 LY18lYzWf292k6mlNJjxHGDrrl98Om/OKWp+d7tHSw5MfLAWHpvKqalqUX9/J6yieafm J2cGVyRAgcoQnsnmtMx2vYyRSvh5eqjFWSvFSM/TKSqvfsSntxfDUEMUh/rspy2faEHv YjNX7AplVhAbewD6U7SbUJuj9jV/+3Vi8wDXiIw0To5gPX7YArr1zQI1cmsMoYQP0Kj/ 0Xfg== X-Gm-Message-State: AFeK/H2qZoyeDcxZEPh5IEzcRzSgrKrKzbKNJK8jXrG2DHENyvqsz3XQL/EQ6Gv0NtPAUozX X-Received: by 10.223.151.193 with SMTP id t1mr26803239wrb.149.1491398709852; Wed, 05 Apr 2017 06:25:09 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u145sm22350893wmu.1.2017.04.05.06.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 95FD33E0FDF; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:58 +0100 Message-Id: <20170405132503.32125-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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] [PATCH v2 07/12] cpus: move icount preparation out of tcg_exec_cpu 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, Peter Crosthwaite , 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" As icount is only supported for single-threaded execution due to the requirement for determinism let's remove it from the common tcg_exec_cpu path. Also remove the additional fiddling which shouldn't be required as the icount counters should all be rectified as you enter the loop. Signed-off-by: Alex Bennée --- v2 - only clear u16.low - drop BQL assert --- cpus.c | 67 ++++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 22 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 18b1746770..d9cb9407a2 100644 --- a/cpus.c +++ b/cpus.c @@ -1179,47 +1179,64 @@ static void handle_icount_deadline(void) } } -static int tcg_cpu_exec(CPUState *cpu) +static void prepare_icount_for_run(CPUState *cpu) { - int ret; -#ifdef CONFIG_PROFILER - int64_t ti; -#endif - -#ifdef CONFIG_PROFILER - ti = profile_getclock(); -#endif if (use_icount) { int64_t count; int decr; - timers_state.qemu_icount -= (cpu->icount_decr.u16.low - + cpu->icount_extra); - cpu->icount_decr.u16.low = 0; - cpu->icount_extra = 0; + + /* These should always be cleared by process_icount_data after + * each vCPU execution. However u16.high can be raised + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt + */ + g_assert(cpu->icount_decr.u16.low == 0); + g_assert(cpu->icount_extra == 0); + + count = tcg_get_icount_limit(); + timers_state.qemu_icount += count; decr = (count > 0xffff) ? 0xffff : count; count -= decr; cpu->icount_decr.u16.low = decr; cpu->icount_extra = count; } - qemu_mutex_unlock_iothread(); - cpu_exec_start(cpu); - ret = cpu_exec(cpu); - cpu_exec_end(cpu); - qemu_mutex_lock_iothread(); -#ifdef CONFIG_PROFILER - tcg_time += profile_getclock() - ti; -#endif +} + +static void process_icount_data(CPUState *cpu) +{ if (use_icount) { /* Fold pending instructions back into the instruction counter, and clear the interrupt flag. */ timers_state.qemu_icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); - cpu->icount_decr.u32 = 0; + + /* Reset the counters */ + cpu->icount_decr.u16.low = 0; cpu->icount_extra = 0; replay_account_executed_instructions(); } +} + + +static int tcg_cpu_exec(CPUState *cpu) +{ + int ret; +#ifdef CONFIG_PROFILER + int64_t ti; +#endif + +#ifdef CONFIG_PROFILER + ti = profile_getclock(); +#endif + qemu_mutex_unlock_iothread(); + cpu_exec_start(cpu); + ret = cpu_exec(cpu); + cpu_exec_end(cpu); + qemu_mutex_lock_iothread(); +#ifdef CONFIG_PROFILER + tcg_time += profile_getclock() - ti; +#endif return ret; } @@ -1306,7 +1323,13 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) if (cpu_can_run(cpu)) { int r; + + prepare_icount_for_run(cpu); + r = tcg_cpu_exec(cpu); + + process_icount_data(cpu); + if (r == EXCP_DEBUG) { cpu_handle_guest_debug(cpu); break; From patchwork Wed Apr 5 13:24:59 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: 96856 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260951obc; Wed, 5 Apr 2017 06:31:16 -0700 (PDT) X-Received: by 10.55.174.198 with SMTP id x189mr29068029qke.318.1491399076183; Wed, 05 Apr 2017 06:31:16 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g9si17800458qte.112.2017.04.05.06.31.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:31:16 -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]:40575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl1n-00018F-KB for patch@linaro.org; Wed, 05 Apr 2017 09:31:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvv-0004dO-ID for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvu-0000Ja-Es for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:11 -0400 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:36429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvu-0000Iz-8I for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:10 -0400 Received: by mail-wr0-x22c.google.com with SMTP id w11so13735154wrc.3 for ; Wed, 05 Apr 2017 06:25:10 -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=OujuJTRrHqM7wKLvvLxcSDIhuBftGtKlsyFfgtR7jxU=; b=IBec1eMIHmqz4tpVXRaCjleUhxYcHd5hzA3LALv1mbJOuPoISMN5RcJPeRMQpBs4nQ Pf4m3uTcOfVYsjXm5Kocyqyhrf0AagpeDvNPJ14SuHid+rej0GRatnqszDIrIrc5ERe+ 5bMXO1KVj8aELJfIg2+rO+ksCCR20t8jMgfow= 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=OujuJTRrHqM7wKLvvLxcSDIhuBftGtKlsyFfgtR7jxU=; b=d4owI+kiN54+G0JR4iMPk+m+Y3fYWiyVFTjaIpyLazgme0glKI9uIiX/82LWOQE/OS +3WVV1kpYpb75VobQcDdihPivnKLMvCvG5gSBIr9yWwtVWD2TRWS9bPBGcEIur1AS0mj 9Crd262DcLCs6zqEdqNtjwjzx9d+YSdbBdewaPjkN5/kD9NoBJgTHDinPevhG/vqgbDX aVy8VkNvKfAA4/UIRN/sFT8JKx5ItjokBx3uvnBpET7CTKUWmTlCyRY8wiePvjDI1+Ts H+Uc2eyY4RJX+zg7RpBjkpBMkw6ifF5x8N2I1k6H7I39lPXFhPWAFAm/lZFx1l9o5WOu 2hzQ== X-Gm-Message-State: AFeK/H3lsYdR9w/ylvH1oPQ8iaO4mSjpBVwgjteKPPAZRR8lZ+IkAllBp8cc4PEJTG7axXDT X-Received: by 10.28.46.213 with SMTP id u204mr19002421wmu.136.1491398708682; Wed, 05 Apr 2017 06:25:08 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m21sm22270844wma.19.2017.04.05.06.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A85D33E0FF9; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:59 +0100 Message-Id: <20170405132503.32125-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::22c Subject: [Qemu-devel] [PATCH v2 08/12] cpus: don't credit executed instructions before they have run 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, Peter Crosthwaite , 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" Outside of the vCPU thread icount time will only be tracked against timers_state.qemu_icount. We no longer credit cycles until they have completed the run. Inside the vCPU thread we adjust for passage of time by looking at how many have run so far. This is only valid inside the vCPU thread while it is running. Signed-off-by: Alex Bennée --- cpus.c | 25 +++++++++++++++++++------ include/qom/cpu.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index d9cb9407a2..88eabdc19f 100644 --- a/cpus.c +++ b/cpus.c @@ -223,6 +223,15 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp) } } +/* The current number of executed instructions is based on what we + * originally budgeted minus the current state of the decrementing + * icount counters in extra/u16.low. + */ +static int64_t cpu_get_icount_executed(CPUState *cpu) +{ + return cpu->icount_budget - (cpu->icount_decr.u16.low + cpu->icount_extra); +} + int64_t cpu_get_icount_raw(void) { int64_t icount; @@ -234,7 +243,8 @@ int64_t cpu_get_icount_raw(void) fprintf(stderr, "Bad icount read\n"); exit(1); } - icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); + /* Take into account what has run */ + icount += cpu_get_icount_executed(cpu); } return icount; } @@ -1195,7 +1205,10 @@ static void prepare_icount_for_run(CPUState *cpu) count = tcg_get_icount_limit(); - timers_state.qemu_icount += count; + /* To calculate what we have executed so far we need to know + * what we originally budgeted to run this cycle */ + cpu->icount_budget = count; + decr = (count > 0xffff) ? 0xffff : count; count -= decr; cpu->icount_decr.u16.low = decr; @@ -1206,14 +1219,14 @@ static void prepare_icount_for_run(CPUState *cpu) static void process_icount_data(CPUState *cpu) { if (use_icount) { - /* Fold pending instructions back into the - instruction counter, and clear the interrupt flag. */ - timers_state.qemu_icount -= (cpu->icount_decr.u16.low - + cpu->icount_extra); + /* Account for executed instructions */ + timers_state.qemu_icount += cpu_get_icount_executed(cpu); /* Reset the counters */ cpu->icount_decr.u16.low = 0; cpu->icount_extra = 0; + cpu->icount_budget = 0; + replay_account_executed_instructions(); } } diff --git a/include/qom/cpu.h b/include/qom/cpu.h index c3292efe1c..5d10359c8f 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -332,6 +332,7 @@ struct CPUState { /* updates protected by BQL */ uint32_t interrupt_request; int singlestep_enabled; + int64_t icount_budget; int64_t icount_extra; sigjmp_buf jmp_env; From patchwork Wed Apr 5 13:25:00 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: 96860 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp262162obc; Wed, 5 Apr 2017 06:33:47 -0700 (PDT) X-Received: by 10.55.139.1 with SMTP id n1mr26802484qkd.269.1491399227473; Wed, 05 Apr 2017 06:33:47 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w76si17796919qka.93.2017.04.05.06.33.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:33:47 -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]:40585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl4E-0003AU-TW for patch@linaro.org; Wed, 05 Apr 2017 09:33:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvz-0004hZ-7O for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvw-0000Kb-3D for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:35475) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvv-0000K4-Tp for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: by mail-wr0-x22d.google.com with SMTP id k6so14523718wre.2 for ; Wed, 05 Apr 2017 06:25:11 -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=UP+AFiBfHOY8/mlkST5aMGha+kgWptX2T3X1O1+gBek=; b=Lqlx3RgtM/P15ix7MrsqKOR4tccNfq4A0Ks9mmaqEvcRZkleBDYK96jydJ/hTQ6r1K vJ12bEmqARrH0WsClRpJ52uzhgMSpCv438cHZ2uP7uVDwvYGse1Kc3kihUVx0spilvGc hwnmTOv32tWzbQ39RCCPDSxe/cEPp7OgO1S9k= 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=UP+AFiBfHOY8/mlkST5aMGha+kgWptX2T3X1O1+gBek=; b=dSSohDZlytwZtIUwQaUrVEsEQWJrglpd3bxV4fzM2PZDZlYkmz5+4QIzRhdMy8iCZU 0SMYGZsb0vZIYn8HkCue9c2X5Bs9W4km54JpWLfEkuN4SwJ/NJIf86a4scP1zJUib4dk K7d5FKYM0RrE8l+WSuJ+rfNCXrgMUMYTsTPWTiROO5Q7VjB/d3nAN9p1sYa7jXJUCo4U tYj4BykS0F+hQtcbwTIG4Etx6ifF9wWi9FNFFUMpImDEN+VG6rCLhv5XjLQSwA8ZZ1X9 /xskXPNGHtwwDel3eU7Q2HhBWCpzgCWblynyfk7iqpaV39Y+zACEhjzYoa6n70owVhQZ sw2Q== X-Gm-Message-State: AFeK/H320F2rc6KOzbIdJKn/1+wI3BtIKX3ek0FCG0GiDXep+9IgvANrO11teHsM+4Ckpz5W X-Received: by 10.223.139.80 with SMTP id v16mr23868973wra.133.1491398710485; Wed, 05 Apr 2017 06:25:10 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z40sm26287568wrz.67.2017.04.05.06.25.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id BB28E3E102C; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:25:00 +0100 Message-Id: <20170405132503.32125-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::22d Subject: [Qemu-devel] [PATCH v2 09/12] cpus: introduce cpu_update_icount helper 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, Peter Crosthwaite , 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" By holding off updates to timer_state.qemu_icount we can run into trouble when the non-vCPU thread needs to know the time. This helper ensures we atomically update timers_state.qemu_icount based on what has been currently executed. Signed-off-by: Alex Bennée --- cpus.c | 16 ++++++++++++++-- include/qemu/timer.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 88eabdc19f..71c3baba87 100644 --- a/cpus.c +++ b/cpus.c @@ -232,12 +232,24 @@ static int64_t cpu_get_icount_executed(CPUState *cpu) return cpu->icount_budget - (cpu->icount_decr.u16.low + cpu->icount_extra); } +/* + * Update the global shared timer_state.qemu_icount to take into + * account executed instructions. This is done by the TCG vCPU + * thread so the main-loop can see time has moved forward. + */ +void cpu_update_icount(CPUState *cpu) +{ + int64_t executed = cpu_get_icount_executed(cpu); + cpu->icount_budget -= executed; + atomic_add(&timers_state.qemu_icount, executed); +} + int64_t cpu_get_icount_raw(void) { int64_t icount; CPUState *cpu = current_cpu; - icount = timers_state.qemu_icount; + icount = atomic_read(&timers_state.qemu_icount); if (cpu && cpu->running) { if (!cpu->can_do_io) { fprintf(stderr, "Bad icount read\n"); @@ -1220,7 +1232,7 @@ static void process_icount_data(CPUState *cpu) { if (use_icount) { /* Account for executed instructions */ - timers_state.qemu_icount += cpu_get_icount_executed(cpu); + cpu_update_icount(cpu); /* Reset the counters */ cpu->icount_decr.u16.low = 0; diff --git a/include/qemu/timer.h b/include/qemu/timer.h index e1742f2f3d..8a1eb74839 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -869,6 +869,7 @@ int64_t cpu_get_icount_raw(void); int64_t cpu_get_icount(void); int64_t cpu_get_clock(void); int64_t cpu_icount_to_ns(int64_t icount); +void cpu_update_icount(CPUState *cpu); /*******************************************/ /* host CPU ticks (if available) */ From patchwork Wed Apr 5 13:25:01 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: 96857 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp261331obc; Wed, 5 Apr 2017 06:32:01 -0700 (PDT) X-Received: by 10.55.161.6 with SMTP id k6mr12852944qke.148.1491399121646; Wed, 05 Apr 2017 06:32:01 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a128si17778022qkb.211.2017.04.05.06.32.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:32:01 -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]:40579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl2X-0001pY-7f for patch@linaro.org; Wed, 05 Apr 2017 09:32:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvz-0004ha-7c for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvw-0000Kx-QW for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:34259) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvw-0000KU-Ks for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: by mail-wr0-x22a.google.com with SMTP id t20so14817886wra.1 for ; Wed, 05 Apr 2017 06:25:12 -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=LeN7a6z8rTYNSZpSeuvUih+9Syn1e5KGL2c4SK4PsMs=; b=D0t5FRFeQHo5EXUxllbS84yL4ZJM6FqcbBtIJnuwkyU5HieOupSr7s5fEq6MBFzrG4 QNmhOV6tFOQisXit4z14KXClLTLxd4Wgd+XlSwc2tobxr4k2Ub9vBF4dFYtwLM6wCY2m caP/vIzFpYyRdifboipnAn9Z5ZJei+uWHm2+0= 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=LeN7a6z8rTYNSZpSeuvUih+9Syn1e5KGL2c4SK4PsMs=; b=bUFa8M/wWBkTSz01yHvEMPoMfz7C4LKQZc11jFvPMMGUXvTG7G8nXzPqhIcNuV141x doWjIb1MWdlPvNe5njU3WQ/xhXVsd03jwOWFmgkLAcT/HHjcni19zcvMFwIDuMe6lqKk oBZNG3EAzqacZv2aNJS5atU5sljpIBchvGIv0tSmblZ5KbkgAzr/o/Qzss3jQPIxRh80 kiR5eoSocZEimehkxNAGmbm9m2cGv719DrMUR1zGOMciZO3DcMrE8rocUhibAE/RL/S1 psIQfWxDbf8lQaTi06NkYFwVS/uV6K+FqjXcMTrOyfcBFiWmzZtoKYgqxRw5WS7nmf67 nXjw== X-Gm-Message-State: AFeK/H0ALc/PpwkXT/T0TDa6QED2rxt9PX8IN7E6ZBWhxQ3tvH4wxawx/kdBn1xGWC3X7K0R X-Received: by 10.223.132.35 with SMTP id 32mr2270764wrf.58.1491398711458; Wed, 05 Apr 2017 06:25:11 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 18sm26302054wrt.52.2017.04.05.06.25.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id CDC423E1055; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:25:01 +0100 Message-Id: <20170405132503.32125-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::22a Subject: [Qemu-devel] [PATCH v2 10/12] cpu-exec: update icount after each TB_EXIT 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, Peter Crosthwaite , 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" There is no particular reason we shouldn't update the global system icount time as we exit each TranslationBlock run. This ensures the main-loop doesn't have to wait until we exit to the outer loop for executed instructions to be credited to timer_state. The prepare_icount_for_run function is slightly tweaked to match the logic we run in cpu_loop_exec_tb. Based on Paolo's original suggestion. Signed-off-by: Alex Bennée --- cpu-exec.c | 14 +++++++------- cpus.c | 18 +++++------------- 2 files changed, 12 insertions(+), 20 deletions(-) -- 2.11.0 diff --git a/cpu-exec.c b/cpu-exec.c index 748cb66bca..63a56d0407 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -600,13 +600,13 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, /* Instruction counter expired. */ assert(use_icount); #ifndef CONFIG_USER_ONLY - if (cpu->icount_extra) { - /* Refill decrementer and continue execution. */ - cpu->icount_extra += insns_left; - insns_left = MIN(0xffff, cpu->icount_extra); - cpu->icount_extra -= insns_left; - cpu->icount_decr.u16.low = insns_left; - } else { + /* Ensure global icount has gone forward */ + cpu_update_icount(cpu); + /* Refill decrementer and continue execution. */ + insns_left = MIN(0xffff, cpu->icount_budget); + cpu->icount_decr.u16.low = insns_left; + cpu->icount_extra = cpu->icount_budget - insns_left; + if (!cpu->icount_extra) { /* Execute any remaining instructions, then let the main loop * handle the next event. */ diff --git a/cpus.c b/cpus.c index 71c3baba87..ff75af449a 100644 --- a/cpus.c +++ b/cpus.c @@ -1204,8 +1204,7 @@ static void handle_icount_deadline(void) static void prepare_icount_for_run(CPUState *cpu) { if (use_icount) { - int64_t count; - int decr; + int insns_left; /* These should always be cleared by process_icount_data after * each vCPU execution. However u16.high can be raised @@ -1214,17 +1213,10 @@ static void prepare_icount_for_run(CPUState *cpu) g_assert(cpu->icount_decr.u16.low == 0); g_assert(cpu->icount_extra == 0); - - count = tcg_get_icount_limit(); - - /* To calculate what we have executed so far we need to know - * what we originally budgeted to run this cycle */ - cpu->icount_budget = count; - - decr = (count > 0xffff) ? 0xffff : count; - count -= decr; - cpu->icount_decr.u16.low = decr; - cpu->icount_extra = count; + cpu->icount_budget = tcg_get_icount_limit(); + insns_left = MIN(0xffff, cpu->icount_budget); + cpu->icount_decr.u16.low = insns_left; + cpu->icount_extra = cpu->icount_budget - insns_left; } } From patchwork Wed Apr 5 13:25:02 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: 96858 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp261870obc; Wed, 5 Apr 2017 06:33:09 -0700 (PDT) X-Received: by 10.55.31.156 with SMTP id n28mr2427807qkh.321.1491399189024; Wed, 05 Apr 2017 06:33:09 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l45si17823251qtf.37.2017.04.05.06.33.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:33:09 -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]:40581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl3c-0002h4-JB for patch@linaro.org; Wed, 05 Apr 2017 09:33:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvz-0004hf-8U for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvy-0000LU-FY for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:33752) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvy-0000L8-99 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:14 -0400 Received: by mail-wr0-x232.google.com with SMTP id w43so14050803wrb.0 for ; Wed, 05 Apr 2017 06:25:14 -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=/9qPGLnIfnyBdr0zN+1EuOxX+IvmXq8/A12GO2IcCiI=; b=BfWsbeRhhz0iTfNWvkWd6Ff2qLrZyInlqgdSLHpBJZFuPYLvLfLxyh3ZvSsaDl3wu+ 6MDlrZTcAfJ+f4eqQUrR6EC9Xf5HngK/6Xn5Mc5L21dpzpXVEHL8JjJOYEhbTaLqoXr+ L6l+8lMNyLn9mLaLlPVrd4hjmQ5fJLuxw7Tys= 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=/9qPGLnIfnyBdr0zN+1EuOxX+IvmXq8/A12GO2IcCiI=; b=WCZu1ZDE9yOaVi7n6HEOxR6dXPE28mdTWbBSk8ppqCv8OdqjmYp/MMAOhbu+REmm2A 2aVkYhqIhFbRsTirFyJYdTrTnsSuXBV+IqvNdRrwg4Ck/NC723O4M7A3/55Js2nLhKb/ vTn8pwSunGUu821KKXjHeuF4WZ/hLNg1mJfenYwSxFCsNnmvKETFXkndhnPjoxME8PG/ E0ZsHmzlJZit9tKqxCxDSpjGteCQSlqjahv8456dyrWOPO+0jJCOE6xgzdIOaZAji/cO 0EmyjIDEEeGNQoK+cmBcIiXfDWlK/0WWyhnRwnJ55C0GpTtJSAorP2rMygY2Stz9e7ow nj7w== X-Gm-Message-State: AFeK/H1DmZrza3tku5yfwIW+FGd6neLJXDcqa0G9Dwx4Hn9fqhFtLWZJEVFvJtzR2Gk8xZri X-Received: by 10.223.172.129 with SMTP id o1mr23246209wrc.121.1491398712780; Wed, 05 Apr 2017 06:25:12 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t21sm22350571wmd.19.2017.04.05.06.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DF3DC3E1058; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:25:02 +0100 Message-Id: <20170405132503.32125-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::232 Subject: [Qemu-devel] [PATCH v2 11/12] cpus: call cpu_update_icount on read 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, Peter Crosthwaite , 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" This ensures each time the vCPU thread reads the icount we update the master timer_state.qemu_icount field. This way as long as updates are in BQL protected sections (which they should be) the main-loop can never come to update the log and find time has gone backwards. Signed-off-by: Alex Bennée --- cpus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index ff75af449a..63de033cc8 100644 --- a/cpus.c +++ b/cpus.c @@ -246,19 +246,17 @@ void cpu_update_icount(CPUState *cpu) int64_t cpu_get_icount_raw(void) { - int64_t icount; CPUState *cpu = current_cpu; - icount = atomic_read(&timers_state.qemu_icount); if (cpu && cpu->running) { if (!cpu->can_do_io) { fprintf(stderr, "Bad icount read\n"); exit(1); } /* Take into account what has run */ - icount += cpu_get_icount_executed(cpu); + cpu_update_icount(cpu); } - return icount; + return atomic_read(&timers_state.qemu_icount); } /* Return the virtual CPU time, based on the instruction counter. */ From patchwork Wed Apr 5 13:25:03 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: 96859 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp262161obc; Wed, 5 Apr 2017 06:33:47 -0700 (PDT) X-Received: by 10.55.87.198 with SMTP id l189mr26361582qkb.304.1491399226988; Wed, 05 Apr 2017 06:33: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 c38si17791419qte.183.2017.04.05.06.33.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:33: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]:40584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl4E-0003AR-IV for patch@linaro.org; Wed, 05 Apr 2017 09:33:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkw0-0004iy-Dd for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvz-0000M2-Fy for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:16 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:36490) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvz-0000La-90 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: by mail-wr0-x233.google.com with SMTP id w11so13738593wrc.3 for ; Wed, 05 Apr 2017 06:25:15 -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=jxbGibZgUkHA2NMyxqCfOSGHHK9BRkxvi0uAJduVdSypoV2aPXOxHSahbmJEkYNVF+ nn/4B/5mDYtEXLRekkWddjrWyleuNCZ+lUNzoqunwNB7EeKK9VlsCSAq+MGUeuma+7sA T49RWarxXja03rIhWwkoRaDu/4dOn4hhqkLfM= 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=fevHsYnZ+PPQZkQEQq8xQOXpcpe4ePtrZueAM+wv2PN8Yo/5OZDPFGfHiTlTgMGWZ3 vrQP64bk8BjvLeYzJ26S4AoOAti7oeqmr+eMD/FGkcRuyrKUBoqsDG5PC+axIsFj9GqX xZnLiVEjfJbq4xSjuAOuMSYeL2c5XPkEpLB6DSWjFVCpKBNWxpwhdDzDx01NwXAsNlZx GKy/uzsiI03aZaaLlbRd2FeD2xQBGUDXSH4El+TImbuBkv3gGIqIOnXM3hZUm/l/mBWP IOnmJGNqGaoXVyNY+9CJCFQJn4omGShSsKyW2I7pq+Of5gIuTQ/3lEwROmCLJZvp31L4 NRfg== X-Gm-Message-State: AFeK/H2RD/Z3OiLn3veYlGcMq6csnQZJQmsDk8GXAlY8s88bR+SFSxgW UH5nJ7/acorA+0Fb X-Received: by 10.28.220.132 with SMTP id t126mr9471356wmg.140.1491398713679; Wed, 05 Apr 2017 06:25:13 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q131sm7828568wmd.0.2017.04.05.06.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id F15C93E1061; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:25:03 +0100 Message-Id: <20170405132503.32125-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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::233 Subject: [Qemu-devel] [PATCH v2 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) {