From patchwork Mon Apr 3 12:45:16 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: 96630 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp82595qgd; Mon, 3 Apr 2017 05:47:36 -0700 (PDT) X-Received: by 10.233.232.68 with SMTP id a65mr6474747qkg.104.1491223656768; Mon, 03 Apr 2017 05:47:36 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b134si2250504qkg.144.2017.04.03.05.47.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:47:36 -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]:59133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1OQ-0002dF-Cs for patch@linaro.org; Mon, 03 Apr 2017 08:47:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MU-0001LX-1M for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MP-00011u-Lw for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:34 -0400 Received: from mail-wr0-x229.google.com ([2a00:1450:400c:c0c::229]:35071) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MP-000118-FS for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:29 -0400 Received: by mail-wr0-x229.google.com with SMTP id k6so162836978wre.2 for ; Mon, 03 Apr 2017 05:45:27 -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=MIQActdlSi9GvsfxXC3ocE3vBTIuaVQbbRrJ/DaBQCpiUSAh3WiP3ep3jgjDIU5Auz liCdFtR30Qm6vRkHNra+ocBa9P+BeuauW/fTqOSagsoff5h14r0Xf/Hs/bARJh0zvyYT J6dvBwn/HLzw6qV+KMFYkM+qgCnbWYOWOmxzc= 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=b4Sf/rixOYhv1C/hw4/t2KgIo/w5HkZbm7e1MPsOdTxhhS1orfCm1HtJLagdhdZUZJ d1hJVt1DLvHLqjdymnVTOFdX43yUcMjYKUDJRaDamt1ZBE3oSvKNc/TrhkW0bK3Xaiap IfLm7FBJQLYcLz2j6QuI1zJXWtCbQvkjHb38wtaPQQQjBROF2NY3YefO8TcHBFY4mI9d Lrgf3gjI5JY6gbGVIu+5GzY/BPL0XTNKe4HFBH3Pp64oygp7ukOcpdjGIp/zLNa03zHo vsa37XYWLK73+CTcho8Z95qR0GNR3GQ15jtgbw+rhlElJzwjrcaeQMTVtmR9WspaRzDs mcZQ== X-Gm-Message-State: AFeK/H3Nb2gfK1ALuqkg8qweNnYr2HUjAKAybDFg3BrXtboiLiaCte5S WyYUr8fP0TKUUNe6 X-Received: by 10.28.113.12 with SMTP id m12mr9375748wmc.18.1491223526628; Mon, 03 Apr 2017 05:45:26 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v14sm14175247wmv.24.2017.04.03.05.45.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:25 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id CD9443E1050; Mon, 3 Apr 2017 13:45:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:16 +0100 Message-Id: <20170403124524.10824-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::229 Subject: [Qemu-devel] [RFC PATCH v1 1/9] 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 Mon Apr 3 12:45:17 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: 96633 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp83605qgd; Mon, 3 Apr 2017 05:50:25 -0700 (PDT) X-Received: by 10.237.45.198 with SMTP id i64mr17610662qtd.238.1491223825163; Mon, 03 Apr 2017 05:50:25 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x23si11810035qtb.140.2017.04.03.05.50.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:50:25 -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]:59148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1RA-0004rD-Ot for patch@linaro.org; Mon, 03 Apr 2017 08:50:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MT-0001LJ-PU for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MP-00011j-41 for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:33 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:36715) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MO-00011O-TK for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:29 -0400 Received: by mail-wr0-x232.google.com with SMTP id w11so166918693wrc.3 for ; Mon, 03 Apr 2017 05:45: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=ReyCmMwO6NiXfsHmDJfGOyNqKRuYr9BSMGPiukUOzDw=; b=e2vIdM3kiB/g/c3NIiuyBubegCxuuLbyVwhGDKvcGruOSB1zqY3liJU9GLaOhj6zlu rZ8RuZ+Cv8Om7mHI4UTUL+f2jiy2CZVXxjhcorOdUt25Dn7+ZZE5+v8800ygVbqVEtt0 S9lB3PRjK+fm/AdbfW6a3lpe089PJ//vo5RAQ= 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=ReyCmMwO6NiXfsHmDJfGOyNqKRuYr9BSMGPiukUOzDw=; b=UAXdgyAF0f4/D0cIGTAWZXPUtPHt2Ro4uRzQcLsHylb22RTP1W/v+GHaNQ14It3iov xGlZfi2UYBdpYg6dEPuy3AqgUUhUQ29vIKUUlSPu9CNq/mtZgbIpm0gypqnItXIqGEoL oS/vSnhMb/ML9tAoEp/poYH7DwovHpNMoegjfF6Y9Cy6viayiuYfF+ZbEH8esI59cCzG lncMgX/cS8yGx3N4MJEWZunxyVJhiDiJF9s4bOrmOZKdOF/F/6jCsGVjOf3JVZdt/l8u fxWfgaXShd8m98oo/gLl8ed+pzlxlY31rnxaL8Pyqih+eO09ZPy7KeKWaRG2Jzv7zaEg 78bw== X-Gm-Message-State: AFeK/H22CzYq0DvQc1tsuL/mUQmkHzcR/vH5plMFapve/ftHNJ6fYZPEUIRjk7TWVbwWvSnZ X-Received: by 10.223.136.125 with SMTP id e58mr15716006wre.14.1491223527556; Mon, 03 Apr 2017 05:45:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z79sm18112158wrc.2.2017.04.03.05.45.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:26 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DFFAA3E1055; Mon, 3 Apr 2017 13:45:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:17 +0100 Message-Id: <20170403124524.10824-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 Subject: [Qemu-devel] [RFC PATCH v1 2/9] 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 --- 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 Reviewed-by: Philippe Mathieu-Daudé 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 Mon Apr 3 12:45:18 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: 96637 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp85676qgd; Mon, 3 Apr 2017 05:56:09 -0700 (PDT) X-Received: by 10.55.10.20 with SMTP id 20mr14787810qkk.119.1491224169813; Mon, 03 Apr 2017 05:56: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 55si11807603qtq.109.2017.04.03.05.56.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:56: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]:59176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1Wj-0000oI-FK for patch@linaro.org; Mon, 03 Apr 2017 08:56:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MX-0001Oi-DF for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MQ-00012F-Fg for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:37 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:35096) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MQ-00011p-4F for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:30 -0400 Received: by mail-wr0-x233.google.com with SMTP id k6so162838502wre.2 for ; Mon, 03 Apr 2017 05:45: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=rcMB9rObBzfaiH0juvPXMmfOxfhZ44tiN81BcEBHgnw=; b=UaSC3BkhR3fm88Vc7AnysSa0kMI09zAmXfMWDDVcnAVzK7HzDb64VGK4BbUw2QepWf bA5UoFLn78j5fGxa++xxRvrd0NCEyADvIpc4rJk012FdbjgDGODm3vYpnYzjaka67BUL zmB0SIy1slopXT5nwIMMb0zbgHbmc8plckqpA= 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=AylYChVrpXisNZ2L3C/ZbgkY78BTRdRrxewOwAcwlBDOKcJe7d4Jico1t4Zj8Bu2kU bQb35aP8ZNd5Xqe+2T9dZrlGniFiWipN9EB0EJUEuH7e+wp26x45DlaZvK4hDzLnAx5h ltI1cADmJoVxdH6MV9cE8hLhYls3nWqPdZULJKkWSw5ajW+ujp8C1aHQsovGPAC+P3pZ nPJE1gC+QZpvS2+PkWTiuzg4Mgtvir+PtngX9KrnYzzKG4V1RF4RfW/w5SHpdAsJOMtd 8BeramvurFEnXcUXv3hxCuKD+bD5eswU6cxoy+xKmauLuSx/mAhmrUHYC75FY24yauT6 W3mQ== X-Gm-Message-State: AFeK/H1wvYw77ygM+VwXmbkBHMbtN9ay/XHOtEKaPSZyO8pYfQhlv7GiT01XH+XRewbEroBO X-Received: by 10.223.161.220 with SMTP id v28mr15857186wrv.54.1491223528526; Mon, 03 Apr 2017 05:45:28 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y29sm10619159wmh.3.2017.04.03.05.45.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:26 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id F12B93E1058; Mon, 3 Apr 2017 13:45:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:18 +0100 Message-Id: <20170403124524.10824-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::233 Subject: [Qemu-devel] [RFC PATCH v1 3/9] 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 Mon Apr 3 12:45:19 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: 96628 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp81948qgd; Mon, 3 Apr 2017 05:46:00 -0700 (PDT) X-Received: by 10.55.134.2 with SMTP id i2mr14907445qkd.43.1491223560456; Mon, 03 Apr 2017 05:46:00 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 52si11784121qty.179.2017.04.03.05.45.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:46:00 -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]:59128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1Mr-0001Qa-PT for patch@linaro.org; Mon, 03 Apr 2017 08:45:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MX-0001OU-AB for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MR-00012T-56 for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:37 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:35108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MQ-000128-UY for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:31 -0400 Received: by mail-wr0-x230.google.com with SMTP id k6so162839031wre.2 for ; Mon, 03 Apr 2017 05:45:30 -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=UrCf0KGnZymZ954Aa8jexPBlPlEDO5TFNMXcFkZwz+s=; b=CTtnJSjIJdW8rj2jFBW3H5AO2tl13let6GZsp5vhl1rdvuB2/OZONEovj+vSKc0gmI QOP8FzogW1hTbNwABi3pxib0zklTH22TYoTuK5MgKMiWKnvbKPuptH2brdyNs0fB/xRO x6w28BS3sr3i5A0HKRMd/enr8XVAeJ3A+UmCo= 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=UrCf0KGnZymZ954Aa8jexPBlPlEDO5TFNMXcFkZwz+s=; b=XVzhaJRXYmXit+BdoZz9Rb0Kb1vcGd2e6AyVN7SAo492Xg8ssrQfi1Gv0Wux387wOp KZvORffzQHjYKCf2QXmdzMwIALK4XnE9mUE0cfWeygSl8RsgzOcsHt/OIjLyuwJn7rHk XeUuo/XspeE3Msw5lqoAAO43Rqz+/D+5q038mxDWBZvPaidcnHbuYRSYGSnUgWC4yUTr qyzjwWALkTu5xGO07pkUqBOgPVfVcPHO2cpuYD7RX5/MqnsSUT6PxGX23f/qzlEb5O7j W+o0kgIBMaqidzkX9fA7HHXTOYLigXbCKIVg3P1aNSToIEw6TXky3e6DOotVQzVeMIrS GxAQ== X-Gm-Message-State: AFeK/H2VpkCp04ozNoXgmAVnCZ5xddsSMhvs7053p+pac3Py2ImGBYS5zImNgCbF1bBgqo25 X-Received: by 10.223.180.69 with SMTP id v5mr16262377wrd.62.1491223529445; Mon, 03 Apr 2017 05:45:29 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id i130sm14186388wmf.26.2017.04.03.05.45.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:26 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0DFE53E1061; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:19 +0100 Message-Id: <20170403124524.10824-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::230 Subject: [Qemu-devel] [RFC PATCH v1 4/9] 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 --- target/i386/misc_helper.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.11.0 Reviewed-by: Richard Henderson Acked-by: Eduardo Habkost 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 Mon Apr 3 12:45:20 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: 96629 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp82077qgd; Mon, 3 Apr 2017 05:46:18 -0700 (PDT) X-Received: by 10.55.102.146 with SMTP id a140mr17488206qkc.28.1491223578165; Mon, 03 Apr 2017 05:46:18 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o16si11801444qto.176.2017.04.03.05.46.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:46:18 -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]:59130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1N9-0001g1-LG for patch@linaro.org; Mon, 03 Apr 2017 08:46:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MU-0001LZ-1W for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MR-00012l-PZ for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:34 -0400 Received: from mail-wr0-x231.google.com ([2a00:1450:400c:c0c::231]:33065) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MR-00012N-Io for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:31 -0400 Received: by mail-wr0-x231.google.com with SMTP id w43so167567353wrb.0 for ; Mon, 03 Apr 2017 05:45:31 -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=htgqSzQ5qk5p5cwdQj4egyrMdL5TxnQDKTYbgd6tFcU=; b=JH1FeBDsu+/NmkiFGsJwPOmZENIhH85HHrpMkgl36VOTB6pSeR+p8jzJcZ+VwvCRv5 aryGP2LUCGVZdvUpGIt+vdDQk9RECg5dRw9jbVvlX1eA3/kS1d7QeO35tEHqV+OVyKHC 8/6el+Kr/fIYsrEV82o0l4b+aXsxH+TFxIdSU= 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=htgqSzQ5qk5p5cwdQj4egyrMdL5TxnQDKTYbgd6tFcU=; b=NeBDutJ0oImJshqXNAxmWzFikHFefOybd1Td/+1WtJ7rTocWQiNacQnolaI2khlTBB +WKjd45ckUcQ1T8kcHG1C9sSLVNDcH/hKIQeOOHPayMvJTF+UqVin5QDwy7iCqTljJn/ KDo3L10ffOS5vQviLUHWGubPIsA1Jv6DbLtNgn9nX0A+2LE/kjzv6Cb9hsEDFUFxGAEK 4YnGA4Sjp/hJmxKdidlQ1z1rPDkLltQEao4i0GyKFpSEZT/MyESGBTLRd1FyMc2e8tG6 L/e9qZMgALAnPOPsyNnVdMUpEtUvG4XIM6Qt5YLGwDEdaANFdgE0uOFmzB19+chdtNUF fk+w== X-Gm-Message-State: AFeK/H1dC4CL2cyesRIGA9gg25t9wmG9l729GoV13xW4x0nzKwtFv80P8CkAvJwoC6ipNBX/ X-Received: by 10.223.177.195 with SMTP id r3mr15339929wra.40.1491223530342; Mon, 03 Apr 2017 05:45:30 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k32sm17972569wre.18.2017.04.03.05.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:26 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1FC173E1068; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:20 +0100 Message-Id: <20170403124524.10824-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::231 Subject: [Qemu-devel] [RFC PATCH v1 5/9] 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 --- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.11.0 Reviewed-by: Richard Henderson 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 Mon Apr 3 12:45: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: 96631 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp82993qgd; Mon, 3 Apr 2017 05:48:38 -0700 (PDT) X-Received: by 10.55.65.136 with SMTP id o130mr14682207qka.168.1491223717981; Mon, 03 Apr 2017 05:48:37 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s56si11767107qte.291.2017.04.03.05.48.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:48:37 -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]:59136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1PP-0003gh-DN for patch@linaro.org; Mon, 03 Apr 2017 08:48:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MU-0001LY-1Q for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MS-00012z-HM for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:34 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:36763) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MS-00012h-9u for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:32 -0400 Received: by mail-wr0-x230.google.com with SMTP id w11so166921235wrc.3 for ; Mon, 03 Apr 2017 05:45:32 -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=5Zyia4swC0JOobgpDucFntVBLU3O1JbW0nRHNQA2zfk=; b=M6nPITXYojwxabaobpSfIQfxvsVtC8gfspZsimR743gVsncAHXibqw7bXXYWX6nkWC 29sGbrvukeHRRJd1e5FFsPMyBtHpo1AfgCftI7xvGZagLd/bTtOP+Es/A3xtYuDsjNbU PAmuPsxhLRAC0VsEeCuBvNNSYgM4i/0Bnmcmc= 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=5Zyia4swC0JOobgpDucFntVBLU3O1JbW0nRHNQA2zfk=; b=tKqcTrJFfwmSxf59qwIVbAHAjeTKYAkUtsOTDwqBEy+YmhrEkr5NsdadGGHsJSZoKv puaEWpHbPwur0zW9a3hMztpdtgBGW7DFjrZTCz6uKgNbey9f57PfpCPEFlNnKVFV9E1c bMkwtpceVCqZVB2iT1YFJgkjgmJQFulTrFrqkdK0MVWnAc17tjf9am2UcEAFAJHHSf41 3Fa8dFDIjP7F2G3ZlP0yATOTMvo1X0fPKyLwxeAMDwbSBbn9ebk+5BtHk6ABZDPNDEo9 vowy+nlzmhNpixHqzApeRC8JqUpDTKenbjBY49lCyb96grbsf3BWp0DPL+prqtn9dTQr D2+Q== X-Gm-Message-State: AFeK/H04JCyBGZvEt+wyRVM2bTDZctjn8aKdAOqxBpnQ5usN92mGLIZWmbHEsHGn9t+Da3OR X-Received: by 10.28.165.147 with SMTP id o141mr9713759wme.67.1491223531162; Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j2sm15527696wrd.26.2017.04.03.05.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:26 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 317143E109E; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:21 +0100 Message-Id: <20170403124524.10824-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::230 Subject: [Qemu-devel] [RFC PATCH v1 6/9] 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 --- cpus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson 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 Mon Apr 3 12:45:22 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: 96635 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp84214qgd; Mon, 3 Apr 2017 05:52:10 -0700 (PDT) X-Received: by 10.55.71.11 with SMTP id u11mr16670677qka.78.1491223930787; Mon, 03 Apr 2017 05:52:10 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 51si11817112qtw.122.2017.04.03.05.52.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:52:10 -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]:59154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1Ss-00069Q-BO for patch@linaro.org; Mon, 03 Apr 2017 08:52:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MW-0001Ng-AW for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MV-00014a-2j for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:36 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:33911) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MU-00013z-Kf for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:34 -0400 Received: by mail-wr0-x22d.google.com with SMTP id l43so169835598wre.1 for ; Mon, 03 Apr 2017 05:45:34 -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=ioZGdXqtSVKXXe40BVEfmGDqf+DM4bpjnMLB+eoUNmM=; b=g3iMvLewKt4JKAdbSbhwhmEhwrGON8so1gSXChGeoAdlh8zWK8XQLCYP52TsCqG2zU SUuOF3W1J5KmZPWjxk1vGvO/cVVVja7xvDBsKSFilSbxAkLKKaomxA25YIrpcayRoU1m QK/4V3jmuFlez8b4UBZm2rZ0467SydRIQ2Hx4= 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=ioZGdXqtSVKXXe40BVEfmGDqf+DM4bpjnMLB+eoUNmM=; b=OdEAul1LmfY46TrxslfM0JtsBwvWJiwJWwA2MIgBOQavR2Xi+XGo9uIay9WqPqrcpm UzCbt9nK/4vXxfc8eRiOGEZOIpPYwryWL4ktmN9vIGVjC3nx8qUUgVayfWvFQgn2bPu0 iCYSxLPhaWxfs44No5LYNMfOao4O+iLtSaE1wlT1+LTVPuuODTQeUSBWF/8hr3flvv1D EYsAtCdTJtQ/M+Bb72N5pIjN3PhWVpLsoZpvmrrsajKOXfk+7QUabyjodp2JG9bxWwGk WVLx+yjmFVVZGcYISOHnm6KnN4O/R1QT8gISpU4Bco4k911ewtwG61pblDUzRD5mJw2L ltFw== X-Gm-Message-State: AFeK/H0cB65nQGj4tbL0mDKvMSWvRVt8spAjCNWoV1H6uf9aABr/ZNp1vWlB+kmnQ7TRjM+a X-Received: by 10.223.163.136 with SMTP id l8mr15675237wrb.57.1491223533372; Mon, 03 Apr 2017 05:45:33 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m14sm3509306wrb.13.2017.04.03.05.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 42B4F3E10CC; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:22 +0100 Message-Id: <20170403124524.10824-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [RFC PATCH v1 7/9] 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 --- cpus.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 21 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 18b1746770..87638a75d2 100644 --- a/cpus.c +++ b/cpus.c @@ -1179,47 +1179,66 @@ 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); + + /* We must be under BQL here as cpu_exit can tweak + icount_decr.u32 */ + g_assert(qemu_mutex_iothread_locked()); cpu->icount_decr.u32 = 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 +1325,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 Mon Apr 3 12:45:23 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: 96634 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp83957qgd; Mon, 3 Apr 2017 05:51:27 -0700 (PDT) X-Received: by 10.55.116.70 with SMTP id p67mr14781043qkc.216.1491223887250; Mon, 03 Apr 2017 05:51:27 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e15si11802420qte.166.2017.04.03.05.51.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:51:27 -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]:59151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1SA-0005VR-Q8 for patch@linaro.org; Mon, 03 Apr 2017 08:51:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MV-0001Mc-7d for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MT-00013q-Pp for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:36780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MT-00013Q-JL for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:33 -0400 Received: by mail-wr0-x232.google.com with SMTP id w11so166922226wrc.3 for ; Mon, 03 Apr 2017 05:45:33 -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=4BGdwVkXgVTmpLmAjpfuBGmOkAO7R7uNtNrCdKvX/Ew=; b=d+00OirUib9x1mb4ajUEUkImcGTU79hpJvN3DZUp1DYtDjmi8Yz19SZiRlZyo+/bxE ZP+MWcb6BusvIZuRjLmX2dr9L/Q50Ip0Eev77tRyiW8v2xE0meWY8IjLii1gAYuwbjD7 bBSBVX1Ic4N5B9gNc6/iiL1WTgGXabyz5bMi0= 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=4BGdwVkXgVTmpLmAjpfuBGmOkAO7R7uNtNrCdKvX/Ew=; b=FJuNKaeKW+BnkfPWS9tWvZFHP52M+8iJU6q7ckMC9iDGqMp543VukHaL33s06s6W68 Dpfmhxy06dY82LNZXA/AnpqRgJjwMaA3yr9+vNqSqux2Wc0S50X2BZUI6P4MJ0Op5sSb hI43rfy/FsgCPFbSaOOmR9Pq6N3AQtsCHcJ9qXwUbgW3HEkAyOhUuMso1lAPfNvWRoGz SvsGSY8eSWFprIGVyyK9wfHP43WiPvaKLNcfFicS74z8Qo50Fta22MJAJJiu8WKIOM+p eGfR2DDhBDn6N8eXqohdGN+9yz0MKUla+jBzP/61wtirEP1ayguNkuMZbpq80RQa6Pfq tCvg== X-Gm-Message-State: AFeK/H1p9DpKU39kyNcMXEwuicabqWD7Vshqi+iHDsiI5vZGQky01ZVa+Z/c1PUCditwAKj7 X-Received: by 10.28.111.136 with SMTP id c8mr9668975wmi.128.1491223532421; Mon, 03 Apr 2017 05:45:32 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j77sm14199634wmj.3.2017.04.03.05.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5585E3E1104; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:23 +0100 Message-Id: <20170403124524.10824-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 Subject: [Qemu-devel] [RFC PATCH v1 8/9] 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 | 27 +++++++++++++++++++++------ include/qom/cpu.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 87638a75d2..3d18374b0e 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,16 +1219,18 @@ 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); /* We must be under BQL here as cpu_exit can tweak icount_decr.u32 */ g_assert(qemu_mutex_iothread_locked()); + + /* Reset the counters */ cpu->icount_decr.u32 = 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 Mon Apr 3 12:45:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 96636 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp85159qgd; Mon, 3 Apr 2017 05:54:46 -0700 (PDT) X-Received: by 10.200.35.195 with SMTP id r3mr17055277qtr.282.1491224086683; Mon, 03 Apr 2017 05:54:46 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c20si11798464qkb.229.2017.04.03.05.54.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:54:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1VO-00084L-AE for patch@linaro.org; Mon, 03 Apr 2017 08:54:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MW-0001Nx-Nb for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MV-00015V-Ra for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:36 -0400 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:33922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MV-00014O-Hi for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: by mail-wr0-x22e.google.com with SMTP id l43so169836316wre.1 for ; Mon, 03 Apr 2017 05:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I6dpZ2m4D+M4/C+rUO1cGS8MzDS0uWHAkxPQmtHdAs8=; b=XYIWjW9zWzkNWvv8P0GIyKB0+NR9opax7rYviJtnqiba0j7YYOC8Bu5NVhwz+lcMRm 9f+SNCroAj6uOHOsC9p7+KHITAaZairVN+k58qFgKVlos4dvlbg8TyKBARo12aoUzCRd Jysk/uCtFi4MCLrsav+pk/xEayZY4Ev9K22Mk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I6dpZ2m4D+M4/C+rUO1cGS8MzDS0uWHAkxPQmtHdAs8=; b=QYXrMIx8dbrSoiVBuvg3yx5AO8kbMNiqg2j0YznXljpl2CAyrvqoBj4rZflUj2jAg5 Cxpb/Y8/Ex+yHvfiIi0SqhK97r/PQ1O1vTL5i/xfOCgkS4k0Rjn5r2+FmgFwBXYZxqK0 nJCugnSPpKKMQBFCdT18SBKVcMFCWGt/m6tQGranT6MRoUlas+BdqxcYs1vP+bqnwUCa e1bIbWVWSCnI3NT/sm1pyYq9PkuR8X3KxkHssN0mE0ud29iCJFmPPGHGxMYDT76psFzF mep1SCgrom3AdyP7f90eBYc8vpYm0BedVf576VqmB/9zA8ea6dvpNEmehoVDmVfSG++E b7Dw== X-Gm-Message-State: AFeK/H16a0iHxBz3VDr8Llt6XOxNS5XFpfzmhBb5D9Xavk+nfL/B1UhO M2P2OpwC0aY0/oFQ X-Received: by 10.28.29.138 with SMTP id d132mr9178633wmd.40.1491223534278; Mon, 03 Apr 2017 05:45:34 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c8sm18044309wrd.57.2017.04.03.05.45.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 684853E1106; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:24 +0100 Message-Id: <20170403124524.10824-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22e Subject: [Qemu-devel] [RFC PATCH v1 9/9] replay: gracefully handle backward time events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, nikunj@linux.vnet.ibm.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For the purposes of record/replay time can only move forward. It is possible for the non-vCPU thread to find time has moved from under its feet as it goes on. This is OK as long as we don't try and re-wind time. Signed-off-by: Alex Bennée --- replay/replay-internal.c | 7 +++++++ replay/replay.c | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/replay/replay-internal.c b/replay/replay-internal.c index bea7b4aa6b..9656db7102 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -199,6 +199,13 @@ void replay_save_instructions(void) replay_put_event(EVENT_INSTRUCTION); replay_put_dword(diff); replay_state.current_step += diff; + } else if (diff < 0) { + /* Time has caught up with us, so as far as we are + * concerned use now, not the past. We still put an event + * in the stream to keep in sync. + */ + replay_put_event(EVENT_INSTRUCTION); + replay_put_dword(0); } replay_mutex_unlock(); } diff --git a/replay/replay.c b/replay/replay.c index 9e0724e756..f4376df0fd 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -84,8 +84,13 @@ void replay_account_executed_instructions(void) if (replay_state.instructions_count > 0) { int count = (int)(replay_get_current_step() - replay_state.current_step); - replay_state.instructions_count -= count; - replay_state.current_step += count; + + /* Time only goes forward */ + if (count >= 0) { + replay_state.instructions_count -= count; + replay_state.current_step += count; + } + if (replay_state.instructions_count == 0) { assert(replay_state.data_kind == EVENT_INSTRUCTION); replay_finish_event();