From patchwork Fri Apr 7 15:42:10 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: 97030 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp339713qgd; Fri, 7 Apr 2017 08:42:53 -0700 (PDT) X-Received: by 10.55.132.3 with SMTP id g3mr37145250qkd.300.1491579773813; Fri, 07 Apr 2017 08:42:53 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 65si5104142qte.303.2017.04.07.08.42.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:42:53 -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]:51491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW2H-0002Po-BU for patch@linaro.org; Fri, 07 Apr 2017 11:42:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1p-0002OU-2u for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1k-0007Q4-OM for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:25 -0400 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:37894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1k-0007Ok-Hm for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:20 -0400 Received: by mail-wm0-x232.google.com with SMTP id t189so10640824wmt.1 for ; Fri, 07 Apr 2017 08:42:20 -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=CvLaOogEdw2bHyCTInO6Sox/QMgNE90JOPZNdbs+JD25M4Q4jKDYY2/ui2jwSkFxyr 2eNOji/omB19GIFMnOInNJd7lyeFlNugTs6QGKFGDt4wm55ASVGHrDh5C7VWsDhFOAMs s2D58tlA+Jh2IjwzjecpzqAz80y0gT0hRj9sY= 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=NovT8adT4yiidc68l7fllDW9MnMv0kKYuDI9YmHuIhNv9uK1NSUg3nxCwSEoTPrUWx UeUk2Pj4RLAXjXrdaLBExGWBjM+6UWa/qHGCCNahuok9SzxRKzO1sPVoZRcA1CvvWmeb K5I8aUhHyP32tsfAQBcYka3+Z18CLIU1wyW5LCED9d2e09l1KRTQxnKfi4L4c3ibL7sh sualGY85lPsirnsaC7hz5lpSkUPp6oh6jY+DM0g0UjiTdriwVxCm8UQmRuJ/ukiMkWq/ g/4PYSxYQ3RXx/RDhvzR8LPOLbq31NG8CmskRSIthZ3vwOcyZ8UqM+KGumruW5561pps yKMQ== X-Gm-Message-State: AN3rC/5+mH3yyokawatWNJb7ekKVPcxcsQK8GAhd3v6mATHjAFb0eQFb npPcMJCk7dPynYL3 X-Received: by 10.28.128.197 with SMTP id b188mr1401259wmd.115.1491579739358; Fri, 07 Apr 2017 08:42:19 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m201sm6743476wmd.15.2017.04.07.08.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:17 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1CC7D3E0FF9; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:10 +0100 Message-Id: <20170407154221.26918-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42:11 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: 97035 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341494qgd; Fri, 7 Apr 2017 08:47:11 -0700 (PDT) X-Received: by 10.233.235.4 with SMTP id b4mr8923315qkg.75.1491580031334; Fri, 07 Apr 2017 08:47:11 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p20si5139676qte.151.2017.04.07.08.47.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:47:11 -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]:51509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW6Q-0005g4-Qt for patch@linaro.org; Fri, 07 Apr 2017 11:47:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1p-0002OV-30 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1l-0007R1-Ny for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:25 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:37899) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1l-0007QF-HO for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:21 -0400 Received: by mail-wm0-x22a.google.com with SMTP id t189so10641151wmt.1 for ; Fri, 07 Apr 2017 08:42:21 -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=iu1rwjdtlizQx4tNSiY6tZvx2feqWSV61jB5XQsy5ykLC9W8irTsDMd+6tEfy3v7yu J0Zibc+5CEWdt/6tIO6m4Xhdi0xvhzHpp4qqo6UlaZ868IJc5/kGF0Cw2rkct4zs+ThU bLAL9kvtt217Cbua8zMh7+7cuw/7Xruuaidz0= 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=KUSW/Z1OWHdPKmPFGxeABU1+PWhbEJemOxYnZ80bGsHAmdDz3yYL+bIidX2WfHDn6f P3Jb3X4GV+YiYe43hcDuu/NZjyiqyhgn6BFDaxPzzJgIG2GM9CP6av9piAewt2eqKP+n EQTAIZPwwV/y8f/hni1LjDW6CEBVc90xZu9GQGRbcEXXyChAFwOzd9nEnBprlTHkBxfX gnk0sL2EbngVnhhTypQl4tEJEqWi+fp6hM+lN+TdjRxt1VHVjPLimdcryxW2J60Txsoq eB0WxBnBIa3Elk0aPx4VOTA3uQu0anaSyuMel1oz+nYz8V3eyBoGtzfQG7NKJfPRDKjC Y8MA== X-Gm-Message-State: AN3rC/7dFuuYyYXdci8syeQTtaBWyXQemLG50BikBje7xC4DRZkPtaZA5Da4GVnwEiZakQO3 X-Received: by 10.28.38.133 with SMTP id m127mr997wmm.41.1491579740353; Fri, 07 Apr 2017 08:42:20 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j138sm6757075wmg.10.2017.04.07.08.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:17 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 307F43E100D; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:11 +0100 Message-Id: <20170407154221.26918-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22a Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42:12 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: 97040 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp342487qgd; Fri, 7 Apr 2017 08:49:53 -0700 (PDT) X-Received: by 10.55.182.193 with SMTP id g184mr24768291qkf.20.1491580193945; Fri, 07 Apr 2017 08:49:53 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c71si5034950qkb.229.2017.04.07.08.49.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:49:53 -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]:51519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW93-0007qT-Dt for patch@linaro.org; Fri, 07 Apr 2017 11:49:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1p-0002OW-3Q for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1m-0007SZ-Rt for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:25 -0400 Received: from mail-wr0-x231.google.com ([2a00:1450:400c:c0c::231]:35845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1m-0007R5-Hy for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:22 -0400 Received: by mail-wr0-x231.google.com with SMTP id c55so38348374wrc.3 for ; Fri, 07 Apr 2017 08:42:22 -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=UXwovhSR/LNBraacdwK1JqOnoNZI8o3ytGujHUkI3rgsrW3gkXPLge3mL5SapjSC+h KISIxuFTO+a9VtN8UkXD8Lv0oFfIlHSRRutrnWxN/sZuYluPj9fzA43IUt5bzj47BqNQ BR8t4xCPIJiUYQCqoqSvEHX7Jm/VrdXxR4UJw= 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=hfkDxjoGAhxSTqcKbI4lWG/R+UaFWXYnksKYLDKDAiEbmQ1g+Wpi/9z71e/Q45pfxp n/digILEtFnId2E/pttpi2TLe6cui5jflV1dyCyez8/KLHVIm7+bAyvbqJEMbj5JO4v4 VSMBvlPndQtkE0jaA8vu7iM8WnvfqUArW3U3dxIV3AKEdGrfQMWNrDNUJ6gqFrmAmyFU JPICDDUMn7niN1iProyxHTCxaUT+NHPvT837hNx9d9i3TqPy41baOrBGjnP6h1RDQaHR Qeuc29BZw8mhc7/A8M5F8Y7CjeJ8OCdoByznzusEVu90qxzDl0M/qaNAUFgSaExUMjQn sHkw== X-Gm-Message-State: AFeK/H1Om/hD2sog+/XNUx7L7nRpICq1taSEDNDonDalWcmfNNyHoTsEANX06WMVOLjKFA3l X-Received: by 10.223.152.67 with SMTP id v61mr13934923wrb.8.1491579741272; Fri, 07 Apr 2017 08:42:21 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m90sm6718017wmi.34.2017.04.07.08.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 436A83E1027; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:12 +0100 Message-Id: <20170407154221.26918-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::231 Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42:13 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: 97034 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp340826qgd; Fri, 7 Apr 2017 08:45:33 -0700 (PDT) X-Received: by 10.200.43.85 with SMTP id 21mr39590373qtv.81.1491579933605; Fri, 07 Apr 2017 08:45:33 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b18si5119635qkj.183.2017.04.07.08.45.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:45:33 -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]:51505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW4r-0004Xx-5R for patch@linaro.org; Fri, 07 Apr 2017 11:45:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1p-0002OX-3R for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1n-0007Tr-MO for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:25 -0400 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:33674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1n-0007SV-GH for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:23 -0400 Received: by mail-wr0-x22e.google.com with SMTP id g19so68076883wrb.0 for ; Fri, 07 Apr 2017 08:42:23 -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=hR9oCGuZAOF2VNXuwtm02iiCyfg2e0yvXdEc0H76QQYUsPfWI4nvbjdEEgcgI0ByiT 0HyfVuPmWGJIHttioElQFJ/pSLpLsMixNCJYhawmVRWqQPowKJwK4nfzUxADw9usFMGr P0rN9OJnZuRWgJZCBstKZ5QURyOEDf9De2aBc= 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=B7g14rGevmrp5/CUTwxYP3xNVfDfSpNW4NZsRF+nftpGb9zMRpp50R+MtxtYAebp+O yUgbVkLGWpE/s4s1TJzRnjKkNYW5vjDlxoVVZALsGQxl4KWpjIfWB2HlRvms+eleS7uI QsjPYT3cvjJgidmspSTAB22wOMS7PNhjR7XbDrJWO/24TRSVUegTFUT0FNceTxk+VVEN fJ3SRV4G1QQsX78+w6+yOjQoIGQrwSaZ3BzIdwHRUGnCy0tHZ9pRJtl1//dB0MRKoIsj 1+egdNRY5nGc5EmYgoMZOyPrzjum2j63vcIUi70wKim33kwybd0Gog8F4j3EZqjXd9+r qhIw== X-Gm-Message-State: AFeK/H1zu2SFH6glADG7SEkIete8s1Mhi6t8o5WJb6lyBU4jJ9zle4t6YTuEiKwF4NtZCIjR X-Received: by 10.223.130.197 with SMTP id 63mr13434890wrc.177.1491579742350; Fri, 07 Apr 2017 08:42:22 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 60sm6425839wrg.60.2017.04.07.08.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 54F153E102C; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:13 +0100 Message-Id: <20170407154221.26918-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22e Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42:14 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: 97032 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp340383qgd; Fri, 7 Apr 2017 08:44:30 -0700 (PDT) X-Received: by 10.237.36.210 with SMTP id u18mr44152091qtc.51.1491579870251; Fri, 07 Apr 2017 08:44:30 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f9si5126989qkb.156.2017.04.07.08.44.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:44:30 -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]:51493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW3p-0003ZD-QH for patch@linaro.org; Fri, 07 Apr 2017 11:44:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1p-0002OY-AN for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1o-0007VC-Fx for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:25 -0400 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]:35565) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1o-0007Tm-AE for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:24 -0400 Received: by mail-wr0-x235.google.com with SMTP id o21so83623618wrb.2 for ; Fri, 07 Apr 2017 08:42:24 -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=KricS5JMkRL4X65rij67E3qO9d8u6iyp6/rYqvGwcRdxHNDkjbqjENaj6ihGP9TxLk I6kdDAqxbKMHbg0Qu5CpwyNkub6jfWl2Ea6/kZoyc7OqFrLhztwOCgMKglEOzqtZczvl uQy6C7LaZZTL5g/wzXCjPBpXPbKjytcs4Ob2Y= 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=L4R05jxt3W2rX8F5xUJzKnwjSVsiRRZV+8wZJOxgjVUnqCtDzSD9SQ5+YnVYbDpDP0 h7MXmE6EI3zTOrIln7pzBcDMbnxBzr6c1A2h/BUI0LjpT0MdS2jxSENsdC4XgnuxFK+S n40lfB553njaXfh0VwdDJhudbIJPoyyE8rXvtXVAEwdLW4mBX4pE59GutMsCDOO9cKb0 r8s5kwBOu/o+K/w3XbQ+3TjgGKrJmocbn8aCibMD/hHGj2Yh5hJE8GGiIlmeCoYTb7z4 b/oHUPq1aVCB36CM+vSP5wo3qlm/Se9QVUcZAnmSOMyBSFADFc24ijjzZSzU5WXKbHxe 5vpw== X-Gm-Message-State: AN3rC/7QbSVTmk4N/bsAifR4huOtFdnxsTKnE50A9quadl9zE64l/fdrSBB5bN8TQ+I9PeOU X-Received: by 10.223.151.200 with SMTP id t8mr3466343wrb.148.1491579743180; Fri, 07 Apr 2017 08:42:23 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l41sm6427230wrl.59.2017.04.07.08.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 6678E3E1058; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:14 +0100 Message-Id: <20170407154221.26918-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::235 Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42:15 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: 97038 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341879qgd; Fri, 7 Apr 2017 08:48:14 -0700 (PDT) X-Received: by 10.200.56.162 with SMTP id f31mr39711899qtc.152.1491580094227; Fri, 07 Apr 2017 08:48:14 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x2si5130350qtx.200.2017.04.07.08.48.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:48:14 -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]:51513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW7R-0006cw-PC for patch@linaro.org; Fri, 07 Apr 2017 11:48:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1q-0002Op-HE for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1p-0007Vo-G5 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:34277) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1p-0007VG-Aj for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:25 -0400 Received: by mail-wr0-x22d.google.com with SMTP id t20so112057569wra.1 for ; Fri, 07 Apr 2017 08:42:25 -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=eU66FEMb+9IUqNZp+f3VYPDR5yFr52wrPK4ICpZMkLloaqP1s63Dxas1R8S417RScc u822xZ2hEAxtl4p2byCBp9x+062s9GXftNgVe6XwwSjBfOs1uRYoS3m1yLED3sTxCBtS Y5wiAF/BhbZ+Hvta2tHv1GlATV8Rzu+GUGBN8= 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=NyxXoZdjkADS5rAOI8L2xZhtQHLhb//FqxQl6okMAA2EjqYebLe4biOXQhT+PbFPgv 3LPIdMCCDJ3NMJaIvBl0Gzn9YdQkXnMQ7AEODCr0i5pK+eNmErcESvtDb5fl6rO5KyhU vQB8RhSpSKFoAZ8tduvUtTvFYchwnbZBxobwhAs5DVVV91BKXXS/tStIIF5lqXXakM4l 7bRbEOyiKXIDktTb/jDLiUm88roWF4i7Z+HKYwkBWBHPqfAc4L9xiqEV7T4Sy67XWhBj KCMN6PVAy7HiQCniFXM1d48PBk4CNkSzHc9PdRo162CN9eoWAlBkZzi4W6xH7wHaKc8F UV7A== X-Gm-Message-State: AFeK/H0yMZK+SU29p58krQVxErp9es9Jy+DIxjj+T3ILSpp9ManAQZXD8l86AUYE2H2JvIMk X-Received: by 10.223.151.16 with SMTP id r16mr14817363wrb.189.1491579744126; Fri, 07 Apr 2017 08:42:24 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g10sm6435500wrb.56.2017.04.07.08.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 782E73E1104; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:15 +0100 Message-Id: <20170407154221.26918-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42: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: 97041 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp342897qgd; Fri, 7 Apr 2017 08:50:48 -0700 (PDT) X-Received: by 10.237.35.164 with SMTP id j33mr43599224qtc.194.1491580248763; Fri, 07 Apr 2017 08:50: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 n41si5134833qtf.240.2017.04.07.08.50.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:50: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]:51527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW9w-0000Sp-AY for patch@linaro.org; Fri, 07 Apr 2017 11:50:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1s-0002QW-2f for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1r-0007WI-53 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:28 -0400 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:33697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1q-0007Vz-VG for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:27 -0400 Received: by mail-wr0-x22a.google.com with SMTP id g19so68078056wrb.0 for ; Fri, 07 Apr 2017 08:42:26 -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=XJewxhm+dsGdFm0MssxGQNHSju99kLTNF0WuCLV0NAkA+H4JMIY4ygl0MhbcFJqjSr maHuiTaCCJdUIyM7OgaoCy6IKnC+gHyXqsolzSnDUJlJwHBAMTdA3k+I7FQQAjVL5ffY FI90qqpZdSsrN7VIrXkeDWozEtFJe+4jul9+k= 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=Z6V490ua1xfl9ONVJlm4uQbdifabUvuYDlmFMY9xnDvNg+VVx74PX4TmsGaG9ENPL8 tQxNNo2iUWx+1yqgqsfpAVDFvNcSfBP52YhzYdMOjEHec+eCYJosmveRkASShul/jK/o CcdPWTvJ1wCr+FG5kXeZGzoGPPUD8MT8uU56STaWUiee/lRVmCQeiSMU+hiEDuNnv3Zy rL3WFq852ojHEDyRNvp7dlrKKiPVPLKdpJWJiQP+eMAWLt8YxfHG9xMxxMPvYcHeLJkN 4QqpLzCsAJrOx9tL5nTsEc1yPJL4wck7itWdM2gh3M4JzFICL4coh9YKLXq2z4ImZKG7 cP1w== X-Gm-Message-State: AN3rC/5IsPa4K3p3wRNltqvxxi3UFfINT9psqkLus3fEtRAf/AZ5C8dpi84wWKzkbFMnZMUc X-Received: by 10.223.130.81 with SMTP id 75mr7018860wrb.150.1491579745752; Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 134sm30553597wmj.6.2017.04.07.08.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:21 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 89AC73E118A; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:16 +0100 Message-Id: <20170407154221.26918-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22a Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42: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: 97036 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341508qgd; Fri, 7 Apr 2017 08:47:13 -0700 (PDT) X-Received: by 10.237.61.74 with SMTP id h10mr3406936qtf.225.1491580033406; Fri, 07 Apr 2017 08:47:13 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c38si5130198qte.183.2017.04.07.08.47.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:47:13 -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]:51511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW6S-0005iD-Op for patch@linaro.org; Fri, 07 Apr 2017 11:47:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1r-0002PX-Cy for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1q-0007W5-FB for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:27 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:35726) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1q-0007Vt-9i for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: by mail-wm0-x22c.google.com with SMTP id w64so1697780wma.0 for ; Fri, 07 Apr 2017 08:42:26 -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=WS9TH+KIK21em4EC8rkoNY5O2G86pI3VVIlDioD7nXjRdfkaQV53IYRtB/GOXBaEKn 6aVrnot+ng4aWvrFmvfLmYx+Xvmdqe+M97bMYMigla6wkb2JZVqQsx2PM5oNcMGsoBXq 3DkbdPS0DerV6s+0RFjUha/zA1DoC3dIGfCbA= 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=p57+YnJxRx/Qp639BxEmwGh/9+5f6x5sHzuoXrn/u1GN2Yqd5gUvw99PbGByq2WMBW xyw2SOMBMVyYxQbsdRems5SUsY4dwiEyjaA6qAtCnFWg7PxQT5OmH2Sh5Z4E7rI0hbeF 0rip17X8naMxMryoOboxyVAIRFlMEkLQwtrPQylkjFj6FjtyBsuhKYzLUlCxc7ozmxig klaVIV6uUZzTCsIq1uqWegmTHFlJDIDPym4QvewpVFRcGIzEjJ0F5CZlmgvsaINSm0p0 nLZXLeBHMv5A2oRNdkzDR4bYrv5HFK9qmDa9qw6RtD9R0WU7hmFjF12wXRRgonmjweBN nE5g== X-Gm-Message-State: AN3rC/7OXQ2hOjcPcNyJ2k70383IzfNtBScYlzrSeUGtI/TCt7KGV3q4M8+JsLfmQ72ipvkQ X-Received: by 10.28.45.216 with SMTP id t207mr10409482wmt.85.1491579745071; Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l141sm6729939wma.32.2017.04.07.08.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:21 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 9C1673E11B6; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:17 +0100 Message-Id: <20170407154221.26918-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22c Subject: [Qemu-devel] [PATCH v3 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 Fri Apr 7 15:42: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: 97039 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341906qgd; Fri, 7 Apr 2017 08:48:17 -0700 (PDT) X-Received: by 10.237.53.226 with SMTP id d31mr40657198qte.184.1491580097626; Fri, 07 Apr 2017 08:48:17 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p18si5148330qtc.21.2017.04.07.08.48.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:48:17 -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]:51515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW7V-0006fm-5p for patch@linaro.org; Fri, 07 Apr 2017 11:48:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1t-0002RX-2G for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1s-0007Wi-4a for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:29 -0400 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:35735) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1r-0007WU-UC for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:28 -0400 Received: by mail-wm0-x232.google.com with SMTP id w64so1698364wma.0 for ; Fri, 07 Apr 2017 08:42: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=FymwcrX/nal7C5r6MWL6iyizFy4DQcKc7z+EDAFp5Oo=; b=c+0ABzIeRjPWanWunWoCKaZg3YmHxCGuampRPIsMoYpUOfF+4yT+jaM2HMSS855rNV p7r5RSbEdtwRY4uQqzzNxBm9jXjPiZd47//cBN+Y1rKbW35KXWx+Wwz4gZ9Eht8hgADM yJ+sK7/h9yAkeSvIfFTLDziDcOsifAp8QheMU= 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=FymwcrX/nal7C5r6MWL6iyizFy4DQcKc7z+EDAFp5Oo=; b=a6ykgT0ICGmKkhFT3WY+8fhq4ZLCcxUqMml7S7BjYpZIXQAUSVAoFK0ES93YtT0+ok dJsUxSRLZQ9uVeMyKmYKJUxkFWndMp6oI3lldX1c0fa5GVYicGZ6xCLecTT0/LwTrtiM 7MqNssGguGrktOHrQUTr7VrOEOXQdBf4priTggGExO5udYL2S8VsBXigv1V8Cs3VurSo /DZhBMXb7Ao/SptW1ckbla3L1WynV0PBFht1P4GGHT+M1mZU4/V0VCiukDKOfCcidNjz JF2NA0VuR1+uCXB5nyvs2Dipk1Zm0p2JS68Dts1L5fXA14H9HK7Md7gxT+S5+uR86zF1 r3bg== X-Gm-Message-State: AN3rC/7nnx3FPKVALJQuv/Ptffy3drXHp9fe8HJOKatYbGqvq7XO0ZzecruhzYJPVKpNoUbB X-Received: by 10.28.63.71 with SMTP id m68mr34442wma.46.1491579746860; Fri, 07 Apr 2017 08:42:26 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g23sm6733124wme.8.2017.04.07.08.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:24 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AEFC73E121E; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:18 +0100 Message-Id: <20170407154221.26918-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 Subject: [Qemu-devel] [PATCH v3 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 | 23 +++++++++++++++++++++-- include/qemu/timer.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 88eabdc19f..3854f17c35 100644 --- a/cpus.c +++ b/cpus.c @@ -232,12 +232,31 @@ 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; + +#ifdef CONFIG_ATOMIC64 + atomic_set__nocheck(&timers_state.qemu_icount, + atomic_read__nocheck(&timers_state.qemu_icount) + + executed); +#else /* FIXME: we need 64bit atomics to do this safely */ + timers_state.qemu_icount += executed; +#endif +} + 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 +1239,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 Fri Apr 7 15:42: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: 97031 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp339736qgd; Fri, 7 Apr 2017 08:42:58 -0700 (PDT) X-Received: by 10.55.159.136 with SMTP id i130mr11274895qke.94.1491579778693; Fri, 07 Apr 2017 08:42:58 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j3si5129932qtj.62.2017.04.07.08.42.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:42:58 -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]:51492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW2M-0002U2-6o for patch@linaro.org; Fri, 07 Apr 2017 11:42:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1u-0002RZ-3n for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1t-0007X2-7A for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:30 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:35594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1t-0007Wq-12 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:29 -0400 Received: by mail-wr0-x230.google.com with SMTP id o21so83625107wrb.2 for ; Fri, 07 Apr 2017 08:42: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=kUaptWrpMRcEzjgmHXYy8PHozSdCXQFCFoqBG2b9QzY=; b=OpYSUVplRyWFlMnj1cMzJD0lUP7NXHVpMOObGD07raJbIGAxEbC6+WjWlqpHzuIGGA h8KWTIYzn7RcuPpFJIGSi3RJq0W9OfA8m90oPqfFK93TGGuIvalo9pG2D0NZ9pOX7zDB Q7BnJ7JwIXK6PLQ2coZYGhHw33iQgcY/tyv6c= 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=kUaptWrpMRcEzjgmHXYy8PHozSdCXQFCFoqBG2b9QzY=; b=LZVnK/accIXPX2YmQbvOZWjZYr19byVjlBNe3XVBReYjhRyd7bnWSihM4gmitlmsiT 1T4RT0wGhwjyOilq7yHBZ+NyEqn7ixt2OG0lppXvq0ohTh6Y1oSG3MJ46uNtfjWJH8v3 XJuCCU5TJwq0H1ZagU9/8+4ScstiFlxsVkVlxB8AOip9hK+f7PZAoiXv99BUTuOnW2Yu A5XggFxSYpkjXKa+wTAYckbJ877DjyCzLWlvFxYaZrsY30IjnJZ5YiVvx8HKKGEMzRuS /Pe94BWerQuhanqgMJhAcu5ZbYKj93QT4pbM0jkTTbSoX0c1tdg6kKx0ge9m/FwqVkdk 1NGQ== X-Gm-Message-State: AFeK/H2W3A08KeAaEheu1NFTwCtRcUScMsIsO51m3+iBWtUbIIAA9pt7F50Z1xqiHLuvsPmK X-Received: by 10.223.141.214 with SMTP id o80mr18213022wrb.110.1491579747826; Fri, 07 Apr 2017 08:42:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d4sm6464358wrb.24.2017.04.07.08.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:24 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C33173E123B; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:19 +0100 Message-Id: <20170407154221.26918-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::230 Subject: [Qemu-devel] [PATCH v3 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 3854f17c35..14c2149987 100644 --- a/cpus.c +++ b/cpus.c @@ -1211,8 +1211,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 @@ -1221,17 +1220,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 Fri Apr 7 15:42: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: 97042 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp344389qgd; Fri, 7 Apr 2017 08:54:41 -0700 (PDT) X-Received: by 10.200.39.56 with SMTP id g53mr43379405qtg.134.1491580481913; Fri, 07 Apr 2017 08:54:41 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r6si5162110qkb.41.2017.04.07.08.54.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:54:41 -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]:51551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwWDh-0003fK-I4 for patch@linaro.org; Fri, 07 Apr 2017 11:54:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1z-0002WG-Sy for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1v-0007YB-5X for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:35 -0400 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:33719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1u-0007Xq-V8 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:31 -0400 Received: by mail-wr0-x234.google.com with SMTP id g19so68079292wrb.0 for ; Fri, 07 Apr 2017 08:42: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=xfiexOHs1UqlXeei4yUFNO4/ImgtjV9V7GCgD8vy7UE=; b=J0y639Nzzei/uLOxLQ+gaqwtEQGNqZUaKLBb5s/rTi2VrCcGffB5aIr40NvJ1ufgZ7 G7fsmBOZDgXhdcJa8K4+8BaDdEJQTYKWk3iEP1nA9jlIUCgEatMZtfVbOZfH93+pGIvd xwb6nKTKF81KUPVCy4uHRjNNFvc1K7Do1yeyE= 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=xfiexOHs1UqlXeei4yUFNO4/ImgtjV9V7GCgD8vy7UE=; b=XVCm7/+mLgtrqSqA1v0wHH6YLFZjsp1XXgGxevuKaT5os9smze0ZRvWJYplSwN13wM bLHU/D88T7t6VrKXaMtqEoBKrqEP9z4uRGPBL88LeJUDpVfOdvqaw7211y+aYg8c9EQS dw4YRZrNAHEIK7RS+X7lPUf6oc7iw7grIQZrnd6So5t8XhM79rjIlvl1/ih8JpHm3Bwp fc8wHpP7AjXtWL20epgSLUcqxmtyJ2Yc4fhM1LNAJOA+R6afNV1FHdQPhTXC67rPv0ZT hcsu+GuwcxbKU1IAcbaqKfinld+wBxkh4vECns5oRZLXvC+VnoNfDAbRugLKmzxr/zOk G88A== X-Gm-Message-State: AN3rC/4SbzJcSmJtRduKPgi69s9eoSIXY40HHuwifGNOTSxiCDo+bt0SeCfX/eO8VYMdScaD X-Received: by 10.223.161.222 with SMTP id v30mr3457267wrv.132.1491579749798; Fri, 07 Apr 2017 08:42:29 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u145sm30656919wmu.1.2017.04.07.08.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id D4CA73E1775; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:20 +0100 Message-Id: <20170407154221.26918-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::234 Subject: [Qemu-devel] [PATCH v3 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 14c2149987..a6a85bfdba 100644 --- a/cpus.c +++ b/cpus.c @@ -253,19 +253,21 @@ 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; +#ifdef CONFIG_ATOMIC64 + return atomic_read__nocheck(&timers_state.qemu_icount); +#else /* FIXME: we need 64bit atomics to do this safely */ + return timers_state.qemu_icount; +#endif } /* Return the virtual CPU time, based on the instruction counter. */ From patchwork Fri Apr 7 15:42:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 97037 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341559qgd; Fri, 7 Apr 2017 08:47:20 -0700 (PDT) X-Received: by 10.200.3.81 with SMTP id w17mr39588862qtg.36.1491580040659; Fri, 07 Apr 2017 08:47:20 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x63si5123728qke.200.2017.04.07.08.47.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW6a-0005oh-8U for patch@linaro.org; Fri, 07 Apr 2017 11:47:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1u-0002Rc-Tq for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1u-0007Xh-33 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:30 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:35889) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1t-0007X4-T6 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:30 -0400 Received: by mail-wr0-x22b.google.com with SMTP id c55so38350821wrc.3 for ; Fri, 07 Apr 2017 08:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ILPIZmbHiNNGn4LVBXUsUnQ4gCN+e11KWzBQMi4gCzc=; b=SI2rZnxGyvsmVWQJZnohKGb3abM/GpWVIjA7d8M8zf48TwlHYDDbRV3dgqeF3VVHhd x4MGM6XOkhqupLDil2y548XaxSHKzwSkip2f8bkj+hPR1OBZ2c+rCewhsnY0x7a5vCav nuZtwF+sPgpszKMyi97CxxHxfglzaBZE8cEaw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ILPIZmbHiNNGn4LVBXUsUnQ4gCN+e11KWzBQMi4gCzc=; b=bsN1sVEskfWAAzxug4i6bcUKNLADqRzvnE/oczluGMUh+XLjAwxU8BUkCD4n8u0Jxl dvLGpZFDlQgJgMKHvwocpSWTxjy/Os4Rpf/YTIPkQ9leTfZ49RmNh9fS/SV4qudYim9N gky2qaqN0DAIsJmRUSXs15nPYJTVEkhkizf+DV0dB5lnKFDuSQnCjk/fAwAcLU/pIrHj u+Enb7bSk2n7xNYiCkiwMPJiS+suapMW7Uh0YE0//B06dPHbGNNSpMlDaKyTan62vR4s K1EV9tWr6//c3rEKUGLPnashHIARNpn5nN7570QJiNMv17/KVj6q/56L2lKwvmI39tRh CquA== X-Gm-Message-State: AFeK/H0ZU4PvzXfJoOCRgylXYyybjJtSR5qaXjeG6cjxkkHdd4gpConUuRwc1drFVe3jYJFD X-Received: by 10.223.153.233 with SMTP id y96mr18373827wrb.96.1491579748761; Fri, 07 Apr 2017 08:42:28 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v186sm6724577wmv.2.2017.04.07.08.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id E71623E178A; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:21 +0100 Message-Id: <20170407154221.26918-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22b Subject: [Qemu-devel] [PATCH v3 12/12] replay: assert time only goes forward X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, nikunj@linux.vnet.ibm.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" If we find ourselves trying to add an event to the log where time has gone backwards it is because a vCPU event has occurred and the main-loop is not yet aware of time moving forward. This should not happen and if it does its better to fail early than generate a log that will have weird behaviour. Signed-off-by: Alex Bennée --- replay/replay-internal.c | 4 ++++ replay/replay.c | 4 ++++ 2 files changed, 8 insertions(+) -- 2.11.0 diff --git a/replay/replay-internal.c b/replay/replay-internal.c index bea7b4aa6b..fca8514012 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -195,6 +195,10 @@ void replay_save_instructions(void) if (replay_file && replay_mode == REPLAY_MODE_RECORD) { replay_mutex_lock(); int diff = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(diff >= 0); + if (diff > 0) { replay_put_event(EVENT_INSTRUCTION); replay_put_dword(diff); diff --git a/replay/replay.c b/replay/replay.c index 9e0724e756..f810628cac 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -84,6 +84,10 @@ void replay_account_executed_instructions(void) if (replay_state.instructions_count > 0) { int count = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(count >= 0); + replay_state.instructions_count -= count; replay_state.current_step += count; if (replay_state.instructions_count == 0) {