From patchwork Mon Apr 10 12:55: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: 97127 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1350490qgd; Mon, 10 Apr 2017 06:01:35 -0700 (PDT) X-Received: by 10.55.77.79 with SMTP id a76mr620957qkb.296.1491829183815; Mon, 10 Apr 2017 05:59:43 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a9si13368082qkg.12.2017.04.10.05.59.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:59:43 -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]:34334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYuz-0005jY-9W for patch@linaro.org; Mon, 10 Apr 2017 08:59:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqr-0002UE-Ry for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqn-00036s-Mb for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:33355) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqn-00035g-GK for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:21 -0400 Received: by mail-wr0-x234.google.com with SMTP id l28so18756218wre.0 for ; Mon, 10 Apr 2017 05:55:19 -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=TkYgST0aC7EfCsvhWzUDsbmC+uJRo/NfprdBJQDP9ck=; b=kdrOjdcBdgCutEMx4cn15OET3jTL0yU+79ue5Gy6ddgnocKdITYLYCwkb48UyOuyzq 6aL8UQRbFVwxylk88d1Q9Mmz/zBTU+56LoA4ENcnX8fq6GdLXV0soCNVvXA+W6oA8oh5 HbZk1RBOTBBV8sBJPQL1QqCxacKg964TFE4E0= 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=TkYgST0aC7EfCsvhWzUDsbmC+uJRo/NfprdBJQDP9ck=; b=bjdnVEn7j3E6FtGz5l4stxWlYAk+l98gBI5efAw4RvYmQe3eSlU1tN1Zfpjir2KtpK Vh0UAkeKGQWm0B4UdS7pPaAtfQyrn3nRuyuZNPknzsNV8DvRWrTf8Fv5+kIx1z99fSVL OtaPlXI96OcyxnLZe5tloVUYGfiYZzcKxQI01/bhKSchGArQ8MqomJjBJedAwtSIl0q4 pyd1gb/A5hhVVn4CxFWP6B/XksbkgAJx/HgI9GCLV6FHqullHwqQgUuhzUIsNupMxFpj 1S/4DazoY1dbDJ2/1/OMvg1QvnuNHZPiDvtVVgE5Ps/JUXOKf19UAri1hWoHxSBUDjsB 9EJA== X-Gm-Message-State: AFeK/H0KqLdEGYlQlqWQwu74HiBSE3oWbChPatAkY6xH921bQ/2s68kTIa4x8KddpbppyZJ7 X-Received: by 10.223.164.195 with SMTP id h3mr38501689wrb.171.1491828918062; Mon, 10 Apr 2017 05:55:18 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m201sm10226411wmd.15.2017.04.10.05.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:16 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id EDCA13E0FB5; Mon, 10 Apr 2017 13:55:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:14 +0100 Message-Id: <20170410125524.21008-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::234 Subject: [Qemu-devel] [PULL 01/11] 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org 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 -- 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 10 12:55: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: 97118 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1348662qgd; Mon, 10 Apr 2017 05:57:19 -0700 (PDT) X-Received: by 10.55.114.199 with SMTP id n190mr52867077qkc.229.1491829039595; Mon, 10 Apr 2017 05:57:19 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c3si13383357qkd.37.2017.04.10.05.57.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:57:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYsf-0003dV-4P for patch@linaro.org; Mon, 10 Apr 2017 08:57:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqr-0002UB-RZ for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqo-000377-3T for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:33019) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqn-000360-U6 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:22 -0400 Received: by mail-wm0-x230.google.com with SMTP id y18so8558745wmh.0 for ; Mon, 10 Apr 2017 05:55: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=ptQCjDDrT0sgF7YfUGyA2UApq1DFJUliZFkVZ8GTDEg=; b=ZDMVQXB5LswrVM6sX2yxx8iPV5AYJuyc2XWbSNF4MMZVf7uKrsdZJywniQiwkCnXSm YOh7ik6Z5/AXSH0CFfJuxioLTietO7m6ipfs62+ksjuZrsUcUhYokTGrYzO37haOuDxK NY/TNRrPvbJLI3iv07Iy2UjWdB4zNGgFHJOyI= 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=ptQCjDDrT0sgF7YfUGyA2UApq1DFJUliZFkVZ8GTDEg=; b=PP5a0p4BBaCY4VzMz61+fOLmEt7CKtufDZkYnb+uoBh5H1+nO/wcH/ckkQFO/VSoLX DPQuR3o2rFLE016G4LAwuKZEb20g7rFiJmo7sikjvo9BwU/XRWZWhoCQ72+FMjid3Qds BkLznTKxbs8AFra/17gF/v0f42RE9+MCwA1hewIgMPgHjeLU/6J3vqzFZY3UrfV723ax r1YOZQvzCufepyqJlrwhhVj9qi+ghQBPjod6K1VJA5iUYIfgk0kV9Qmr2QT4hB7XZkr6 8cTPqwnn8N2iO5K4rloGyOe2EvMV+CY0bgkloTkoc1PZcUV6YrVS3G9fy6sx+xt9Ec9l QXdg== X-Gm-Message-State: AN3rC/7+8JotzmeZKRovxpTRXnV+ZP1zeZxo5mv1pXlp1c06kMKjb7qd nMwaTfSXzESjosIp X-Received: by 10.28.139.134 with SMTP id n128mr9626934wmd.132.1491828919036; Mon, 10 Apr 2017 05:55:19 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 127sm10231998wmt.20.2017.04.10.05.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:16 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0B1103E0FBF; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:15 +0100 Message-Id: <20170410125524.21008-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::230 Subject: [Qemu-devel] [PULL 02/11] cpus: fix wrong define name 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: Nikunj A Dadhania , Peter Crosthwaite , qemu-devel@nongnu.org, Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Nikunj A Dadhania While the configure script generates TARGET_SUPPORTS_MTTCG define, one of the define is cpus.c is checking wrong name: TARGET_SUPPORT_MTTCG Signed-off-by: Nikunj A Dadhania Signed-off-by: Alex Bennée -- 2.11.0 diff --git a/cpus.c b/cpus.c index 68fdbc40b9..58d90aa2b9 100644 --- a/cpus.c +++ b/cpus.c @@ -202,7 +202,7 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp) } else if (use_icount) { error_setg(errp, "No MTTCG when icount is enabled"); } else { -#ifndef TARGET_SUPPORT_MTTCG +#ifndef TARGET_SUPPORTS_MTTCG error_report("Guest not yet converted to MTTCG - " "you may get unexpected results"); #endif From patchwork Mon Apr 10 12:55: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: 97116 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1348189qgd; Mon, 10 Apr 2017 05:55:50 -0700 (PDT) X-Received: by 10.200.51.252 with SMTP id d57mr50666765qtb.96.1491828950478; Mon, 10 Apr 2017 05:55:50 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j190si13377280qkd.82.2017.04.10.05.55.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:55:50 -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]:34324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYrE-0002Vr-6z for patch@linaro.org; Mon, 10 Apr 2017 08:55:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqr-0002UG-Vs for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqo-00037F-8T for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:38577) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqo-00036I-20 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:22 -0400 Received: by mail-wm0-x233.google.com with SMTP id t189so36720387wmt.1 for ; Mon, 10 Apr 2017 05:55: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=alyA6K6F3H9r0EdK+k2yUh1nqXj00TH+nUOCN4ad40o=; b=EXQ6Oz6BCR/ZWEPvxCHRK28qk/B+u7gwCKBG0kqC1cHBGgUoTtAZAaX6Hlnhf2Jbmg +Fjoy0d46aQ67po7UI71ACEzVHv8XrmvEcIfydu639Kt+F0TGROiTAWWbqlHE4vZGMqK xTTxpuOjSaLa2yvaQ/rfX+3kCumUmvOasHPRE= 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=alyA6K6F3H9r0EdK+k2yUh1nqXj00TH+nUOCN4ad40o=; b=tiy3R4jS35ad9gEP2uGlUFUuxJKtPqPa7pvVEjq5UUJYU+NZLYeF4QUYT8PQ+04CCE 8Buh0d0/r4pml+iq2+6zvF8bxnsolFaNBLPi8Zuslkocys0vsusZjSoE+cJzUHuSLghV hJIWNYuohtjCkiifgLBEAVYZWvaAqmhnLmCR43kQU+BIKrSomROPI5aKaVMZ7vyk9zgx Q2YfExy8ZKMWLDo8vhcePEJ11NxDr9fgODfUH4E+buTgq3SstdOYjHbvenT2zFhrZb0R RCf/xad8hpbCUtwg3FBWWmG3288OMXgg6AzdD/HM7sXt4LTr+PeOSjHf1DZgqbTwn1Sr wlfA== X-Gm-Message-State: AN3rC/4xnIT6HeM04OXrFkq5ysVzTX/QR7k1gZgjkYe6EZXCSr28qMGt OKsuJPBcMLzgCov6 X-Received: by 10.28.71.87 with SMTP id u84mr10009045wma.101.1491828919968; Mon, 10 Apr 2017 05:55:19 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x65sm8281495wmg.3.2017.04.10.05.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:18 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1C7A13E0FC7; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:16 +0100 Message-Id: <20170410125524.21008-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::233 Subject: [Qemu-devel] [PULL 03/11] 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: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Eduardo Habkost , Richard Henderson 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 -- 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 Mon Apr 10 12:55: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: 97115 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1348187qgd; Mon, 10 Apr 2017 05:55:50 -0700 (PDT) X-Received: by 10.200.39.130 with SMTP id w2mr50875908qtw.260.1491828950280; Mon, 10 Apr 2017 05:55:50 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q10si13355812qtq.77.2017.04.10.05.55.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:55:50 -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]:34323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYrD-0002Vm-Kx for patch@linaro.org; Mon, 10 Apr 2017 08:55:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqr-0002UA-RC for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqo-00037L-Al for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:35891) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqo-00036j-3V for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:22 -0400 Received: by mail-wr0-x22b.google.com with SMTP id c55so74644476wrc.3 for ; Mon, 10 Apr 2017 05:55: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=Ij4huRFkTP/wFHq5UK54p4Ii6b+lHuUU8Rjsz1M1zFg=; b=RkVGJywNRUDJf+GNvlUBgXiP1j1EPzylUXKnXkk92AUaYZk3F2qeUWk7WUSn3hTeVj xnjQVH0fjMZOO6J4NAJ8V1sCfz23hKDp6cPovP22s6j3y4ADqyFjXgvJ1c6jgOA33pSA s06VXhnaJeX097wk/iDPdCZ5Mnt4SghLV+o1Q= 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=Ij4huRFkTP/wFHq5UK54p4Ii6b+lHuUU8Rjsz1M1zFg=; b=JcKqo7sFTuKY97B2GyQW6nu8sbJm0JQu1ujerauN4lPhm+MQk60nsiiW8ajOFvtrAs ouhGfu/OtjS42ALKYOx2J9p0kcVxsudEhmBLU5ppMb1KeH48i04OM14PRsr10CFhi01c I3K85FCTJaRIsHVQyW3zc3MRQWwMV5kb6fIjCwYikTTPLs1eM/fsTQjM2rdl6y+GBJ8V Mtc8Krmels+0OpHwwhmSlOYB0hnOYxP7s8rqOAxAxHEsWE6DErgvtdRu1ts07G8RcTaw mXuKl1R0PF8+q0NeYYORlwIxOfyCV41bHCJ/VH9LppzjPPe3Do4DhsEvg4km4Ee6CoS/ WiAw== X-Gm-Message-State: AFeK/H2jWw+1AyRIZvyrKmkMP7Mh1ko0RKMd7x+KhS3sM500KnhrUSMmgAGHQ2+Gouo7TQrJ X-Received: by 10.223.134.152 with SMTP id 24mr40179838wrx.30.1491828920907; Mon, 10 Apr 2017 05:55:20 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a66sm17494503wrc.58.2017.04.10.05.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 2CE843E0FC9; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:17 +0100 Message-Id: <20170410125524.21008-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22b Subject: [Qemu-devel] [PULL 04/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index 58d90aa2b9..fc0ddc8793 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 10 12:55: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: 97121 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1349525qgd; Mon, 10 Apr 2017 05:59:40 -0700 (PDT) X-Received: by 10.200.3.137 with SMTP id t9mr3014250qtg.244.1491829180465; Mon, 10 Apr 2017 05:59:40 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a17si8198355qtc.163.2017.04.10.05.59.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:59:40 -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]:34333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYuw-0005hG-5A for patch@linaro.org; Mon, 10 Apr 2017 08:59:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqr-0002UD-SL for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqp-00037v-1B for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:33376) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqo-00037B-QJ for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:22 -0400 Received: by mail-wr0-x22f.google.com with SMTP id l28so18757309wre.0 for ; Mon, 10 Apr 2017 05:55: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=jrldZf0dU9y8/a6jqW3ZgGCF6m9HmctWAfhhQAdfQKE=; b=CB+jmp7Y80zUr6Fs8g/90/Yaa//AHYNoKw+4fEcVZT/7HGzq/7v6ckxuod/51Cjjxc wzWmdCK1BAZ6YRDeuAiUsW/1Skx5hTnpNyKasOQiI4wbLazfSzFuGN/ZdlDG9vTaG9iT cVqwnh9uzpPFJl7pUWlqdInsymiSviZVS9CFc= 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=jrldZf0dU9y8/a6jqW3ZgGCF6m9HmctWAfhhQAdfQKE=; b=GgXs1pbmVuUHI9hCPwF6d3Zpj/KPuRxbxVzcHrxKhgkLleAo+XB/9FcpS/q8FjW/dh 2zijR+x+WdaeBaYGuB9V7Wud810ufsI1DSpw/5WVbVLgtL5oEym0WB/9+ek8HtMz5Y8d F1JxCKDL0Nq4Kub7RKP//c4D++qLhd4DV08YinSDowY6xr/bcH/B0mTQ0EqZMmnDfXBI DKGFkak/Wy5l9fF9X6860tUGRbbdG4q3BgkQX+Mr8EHacHBqt58nz5KjRcpwueKaFL21 2b9ix6RAJtDRUbbDd5c5T6Xb8K1BoS9wGGMmCKqoJecyTd7wjxYaUFpfbHEHx577iH4q BtNA== X-Gm-Message-State: AFeK/H08p/iNF6WYTU2SH1MH4lHtkUDQMvmICs9E0awZTY+CCUo/7UU5hcFtuFFBbt28LyK1 X-Received: by 10.223.142.172 with SMTP id q41mr26520632wrb.25.1491828921623; Mon, 10 Apr 2017 05:55:21 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l14sm17363831wre.23.2017.04.10.05.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 3DDE93E0FDF; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:18 +0100 Message-Id: <20170410125524.21008-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f Subject: [Qemu-devel] [PULL 05/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index fc0ddc8793..7ec6473c02 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 10 12:55: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: 97119 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1348988qgd; Mon, 10 Apr 2017 05:58:11 -0700 (PDT) X-Received: by 10.55.144.6 with SMTP id s6mr47722197qkd.27.1491829091616; Mon, 10 Apr 2017 05:58: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 35si13370569qtx.99.2017.04.10.05.58.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:58: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]:34330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYtV-0004dY-5N for patch@linaro.org; Mon, 10 Apr 2017 08:58:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqr-0002UF-Rs for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqq-00038J-0m for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:35572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqp-000382-Qg for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:23 -0400 Received: by mail-wm0-x22d.google.com with SMTP id w64so38170949wma.0 for ; Mon, 10 Apr 2017 05:55: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=SDFJNslGPpcgtES3AVvz4f6JfirhhKWFo38wqVTp4K8=; b=hR4FS/QXt9b+oHMI/DnkY6VeI6gPPJRkJnBlnj7Sei7HilFjNSc29r+5KfLhINxrQb xLGEB01c/IL2i6T9TZ0o1BV7Df8TKIxJZ+x1/MulLnFmP5dxhGJXsqs0l6HZIGF6Dv7m 8TDyjDWAgFbL8pWECwJH1G5W6xMN+IIUSfdt4= 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=SDFJNslGPpcgtES3AVvz4f6JfirhhKWFo38wqVTp4K8=; b=pWliO8sv/kh70ExagK6ZeuQtt/cpa50n5jBrJGPcLmteFBg67qrhB+7LIpnWRgRX63 RZ1MtOqvps04sy9f0jj8Mt5HaFKxu4LOZttW0WzSoqlVcMHmkOAPjGd9nuAlBIjqr3VD K8cNQf1xJVM1yl8d1Y9x8mXiAaS1WQo5BI22alriFljJDr8MqQERDHYI1jOS4ZlDgPaZ 9zF4UE8eoZU6i9IciOnF8BZ8F3S9SfXA+C3xRd/O6pkP8a6s6s4lCiiVGWAwPdiTx9kn DWadWDq0shxHJhQM2XyQ/n/js8BFDcJvz88Skj+l7tjXTGzyJMpD98aYcqVdM9UyJlI8 CxcA== X-Gm-Message-State: AN3rC/76FCUqYUp1a/Qwp0WMAwInXFaFTH9hSaKlK9BYvKU7VcE66CFi1NyOEnEc258l/JND X-Received: by 10.28.126.77 with SMTP id z74mr10308614wmc.15.1491828922543; Mon, 10 Apr 2017 05:55:22 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v29sm17330427wrv.66.2017.04.10.05.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4E3563E0FF9; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:19 +0100 Message-Id: <20170410125524.21008-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22d Subject: [Qemu-devel] [PULL 06/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index 7ec6473c02..6034b104c3 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 Mon Apr 10 12:55: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: 97124 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1350002qgd; Mon, 10 Apr 2017 06:00:39 -0700 (PDT) X-Received: by 10.31.140.205 with SMTP id o196mr24424025vkd.7.1491829239587; Mon, 10 Apr 2017 06:00:39 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c187si6770922vkd.194.2017.04.10.06.00.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:00:39 -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]:34352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYvs-0006l9-8U for patch@linaro.org; Mon, 10 Apr 2017 09:00:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqv-0002X3-UE for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqs-00039T-0t for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:30 -0400 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:35913) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqr-00038l-PP for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: by mail-wr0-x22c.google.com with SMTP id c55so74645747wrc.3 for ; Mon, 10 Apr 2017 05:55: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=OZJ/wv1+CPPX/SHSaZmm/NonoUYVNkdrmRwtU1WtUI0=; b=OQ0EPNIhEjHEam/4pwN1DJa+9H8OeyQvTt9fXBLjsKhasyaxqbkIb/RPAQR7+2ojuq TpX8iC2hMflK4AY4OjtfgJIi8mB3OkKdZBkyO0D1wzoupUPA4DNMsSigh1k9RSPJ4MMm ZNi/LTzZvd/NLpx6brC/KNjhZth7BbLfZcxWE= 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=OZJ/wv1+CPPX/SHSaZmm/NonoUYVNkdrmRwtU1WtUI0=; b=K1qhEK8el89lVsbny0LvQACaTSGDej9Pz35Getm7EowrHopp/Zmo7z0FGbEZQUUtEg rW4kgDmD46zNj1392vft0s6CuU0qLCcEKZZ2ysVlH3IHrSn1zbtBU0E3Lc+D9YwftaEy dX6IDUoPpZqzw5uQCN7VjMRNZX2eJY8dCcCmxqzBWiqnBkhj1uQ9rJTUU8eT7NKaZplW pFFZZJXWmnyeoGslUfmejynWjCwNfjNHm6aVt9fmpA6qcfUjJ/8JCc+tqO+PE4p4bTLh o7dVb5NkW+F1P6DLXfhs8DCJf/PNF8Y2NDlh6Q0QjHfB8U1h96pnerQsOwfjS2LzysrU lb0A== X-Gm-Message-State: AFeK/H2yUMbrkV9qtFeiao284bxgwpAPICms12qwlsEg5IDaLEFG5dpPYO6Xi7pgq3uRPOhf X-Received: by 10.223.128.194 with SMTP id 60mr38388550wrl.175.1491828924501; Mon, 10 Apr 2017 05:55:24 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u63sm10142732wmu.22.2017.04.10.05.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 6028F3E100D; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:20 +0100 Message-Id: <20170410125524.21008-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22c Subject: [Qemu-devel] [PULL 07/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index 6034b104c3..0ecb0b87f0 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 Mon Apr 10 12:55: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: 97128 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1350654qgd; Mon, 10 Apr 2017 06:01:51 -0700 (PDT) X-Received: by 10.31.166.80 with SMTP id p77mr1535337vke.123.1491829311882; Mon, 10 Apr 2017 06:01:51 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 33si765855uaz.248.2017.04.10.06.01.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:01:51 -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]:34360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYx3-0007ZU-Hs for patch@linaro.org; Mon, 10 Apr 2017 09:01:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqs-0002UI-7X for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqr-00038g-15 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:26 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:35923) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqq-00038P-R8 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:24 -0400 Received: by mail-wm0-x231.google.com with SMTP id o81so38078211wmb.1 for ; Mon, 10 Apr 2017 05:55: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=9z7AxeVQ2/e8nqiU6HckJPKW2WhL9ciN/KoobzwdaVI=; b=Niz/OD9+uX63B8L2rMVNlsqhK5+BZsUXvmsQuzb7SL2R7phkOksyvVJuDxfVRkRydz DVTLKG4GfpWwbdlENIRZWjbg4WNgwWgVBjYkcT761AS2ziPWEjcOLHdVfqbq5R0Ld9bq TF83FQDTfh20pUv6CJKTUKw5AhTTMqouwY348= 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=9z7AxeVQ2/e8nqiU6HckJPKW2WhL9ciN/KoobzwdaVI=; b=WMiEKJMLwqf0SEmzQ46wiXAHk7MQsK7B8Co5u3bcfPgNPtgXsmgM6DB3s+g4aLS43p LECM8KwUqX1q9oUdHulNtyf9rmEwwkMSzQxdVHfyg2qYi3uWLtM4pRdQrtBwjumo8nXp HECsS7T6I0s4xEPSPEWRG252sqB0RdsYl8rqACMSJHzOJ0OjNm8bRK66DD4Oz1jPkr1U JwL7Dydzrv+B3Sn3vBVkYx86VVHHoSQ8Umc1UhA/9JX8Bjg8LBg2RqV38frLzPQqfAp4 74Zj/z6PwceQFsv5g5pDoZckq3wuh/4N8e+xgS5FrHOVwjCf+78gRPKbVkL637/2Mck9 3apQ== X-Gm-Message-State: AN3rC/46y6fVf9HI3faDjbp0MFi8KSNGOvQINbbqhxif52RTaBF2Ef1R qTcmf3rQLZfjCQpi X-Received: by 10.28.87.138 with SMTP id l132mr10290819wmb.95.1491828923597; Mon, 10 Apr 2017 05:55:23 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m139sm10119057wmb.27.2017.04.10.05.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 727373E1027; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:21 +0100 Message-Id: <20170410125524.21008-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Subject: [Qemu-devel] [PULL 08/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index 0ecb0b87f0..a5125d7167 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 Mon Apr 10 12:55: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: 97126 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1350390qgd; Mon, 10 Apr 2017 06:01:24 -0700 (PDT) X-Received: by 10.31.178.79 with SMTP id b76mr19809290vkf.104.1491829284868; Mon, 10 Apr 2017 06:01:24 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m3si6796449vkg.88.2017.04.10.06.01.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:01:24 -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]:34359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYwc-0007MD-8G for patch@linaro.org; Mon, 10 Apr 2017 09:01:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqu-0002Vo-No for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqt-0003Ai-Jq for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:28 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:35923) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqt-0003AM-DI for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: by mail-wr0-x22f.google.com with SMTP id c55so74646367wrc.3 for ; Mon, 10 Apr 2017 05:55: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=LXdfzu+XHr9LvGqDDL/cIa9x/i+mda3BEPIGHvgMcEE=; b=eoJdWhtSyattsK6yEVPfIappbR+STy9ttk+I8O+4I7Ld1txNSQ0VP1x/fqk4pfrSWw dcabqk2Dczl+6iQ5vftd1S2dzduK4Eer0fRcJMDE3svO6ilaTD+EP+jCdnWZipspAXdy 0FBmHuekxLYLKunJkah6Pg2LcVZ63jbTqlA24= 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=LXdfzu+XHr9LvGqDDL/cIa9x/i+mda3BEPIGHvgMcEE=; b=ZfQCVaJqX1WKwRH3Jkl+McrhEhUzkMKtu66gG6gq21gNv4cYdbBkhlLPP9eVRVUAU9 YvZ2vK0XM23lgrmEqu0+OJlzWMvraWAhWIB+CYQtxHaOJLxdHfeXx5l8ssoHFTlZwYzt C49TAY7vmdJFaEmTobp6gwyJiKyxP1DzHRyt6+1OzCjOVBZbTeo5dd1r/X22/CxVm5mA KlATeic8yj5Kimu6aIBt3nlyTFBQkaceuchzpO6ejBBn8/kpG3LiOUNk9bCekD75wPvq PlLAeluZ1t8CVUkHSniUaDPto2hrzypDL2EdbRrXbrJlf0uuISPoG1Y7lJZiAmirqQV8 wggA== X-Gm-Message-State: AN3rC/7fHpw6V++qUC5y/5sB3JxAKkQN9PpTAd6zQjLQhBTLhKHonnNPt9wpVlkuUO8rauNd X-Received: by 10.223.163.212 with SMTP id m20mr2959852wrb.29.1491828926261; Mon, 10 Apr 2017 05:55:26 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a10sm17412204wra.17.2017.04.10.05.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:22 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 841923E102C; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:22 +0100 Message-Id: <20170410125524.21008-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f Subject: [Qemu-devel] [PULL 09/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 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 a5125d7167..9c8bd2c991 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 Mon Apr 10 12:55: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: 97120 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1349003qgd; Mon, 10 Apr 2017 05:58:14 -0700 (PDT) X-Received: by 10.200.43.17 with SMTP id 17mr49091442qtu.199.1491829094656; Mon, 10 Apr 2017 05:58: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 s56si8938142qta.206.2017.04.10.05.58.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:58: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]:34332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYtY-0004fd-72 for patch@linaro.org; Mon, 10 Apr 2017 08:58:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqt-0002Uw-Ep for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqs-0003AF-MH for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:38615) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqs-00039I-Gi for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:26 -0400 Received: by mail-wm0-x231.google.com with SMTP id t189so36722602wmt.1 for ; Mon, 10 Apr 2017 05:55: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=s788N5UQVXQevsKcqsLb9eqQIYzLp/5AC4TyUxSEJSk=; b=FribKfYicy9noqWuyUL9XyF+frO1bHpZ+OYeQs8cGYaUcpMmVsIywLzYU+6YZVYrah YztNad9dc8icJJpWGLM7aFuuLu5j48Zb/JZ0WHYhAdDhbZMN0NvEC1TXdjrQJZMsFdZN k9p4J7FCSQ+f8zQa1r8lStyelnDWOgJQV3KQA= 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=s788N5UQVXQevsKcqsLb9eqQIYzLp/5AC4TyUxSEJSk=; b=qsDfIcljYQWL2uDRj50ibZhZ+uAloRZdWcYZW4Q20y6/zUxyWK8sMTQihWy+NYMu7j Hl0JV0uQM3FTr8RLj70V6JWli5piPaZp8bHLXWayv1Hn7GGMVU9IYjXn28d9eCxaLb+I 64es2dK1NSr7DrDyB0Gel/Q8vtj7IAoAsMCzcigv7tH0XaZI8Hnp4ggZ/i5oO1KeuwsK z8cSCIvFplKmYL1nIRj3yQeB5Ld1rEjryAfGbB29xI0fCzGVemmLhrY3QkWKjhEQIPQ4 sIdc/ggTeuP7yt5eTt5Qlm0yL7Cqp+70BfgpTXIEnmpbZeB/NSwQfu0ncy5CII+JzLgu EmmQ== X-Gm-Message-State: AN3rC/5yqHqvR1y/NrYyXwoYAg4U1QqawGCm58YrnmJkorJbMIySo1jg g2/bkJ5FnAFtkZkF X-Received: by 10.28.167.18 with SMTP id q18mr7462610wme.82.1491828925333; Mon, 10 Apr 2017 05:55:25 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a66sm17494696wrc.58.2017.04.10.05.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:22 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 94A8D3E1058; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:23 +0100 Message-Id: <20170410125524.21008-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Subject: [Qemu-devel] [PULL 10/11] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index 9c8bd2c991..740b8dc3f8 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 Mon Apr 10 12:55:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 97130 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1351888qgd; Mon, 10 Apr 2017 06:03:59 -0700 (PDT) X-Received: by 10.176.68.101 with SMTP id m92mr22885446uam.18.1491829439031; Mon, 10 Apr 2017 06:03:59 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 23si5700701uav.32.2017.04.10.06.03.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:03:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYz6-000127-Qt for patch@linaro.org; Mon, 10 Apr 2017 09:03:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqv-0002WW-Ec for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqu-0003BE-N4 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:29 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:35697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqu-0003As-GD for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:28 -0400 Received: by mail-wr0-x22f.google.com with SMTP id o21so119855304wrb.2 for ; Mon, 10 Apr 2017 05:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YpwkziI//txJ5Aey6bJ6KGdW498uEIr/i8vOq6DTUwE=; b=WbhQs524MAlWhu8Y6xcfMtY58PYqyJG+NolWw4P7H9QdYu137v+GJLyysZijClNFTp 7FK1tBg8JZuBIKVNypS5ISSZ3O1ecRe4lNG7ONjlYUcH2JO539mcglR+lt7U6311kiyZ yzXE6wmKj0x4RQ+jmtvZjloHIJV3zT9DI5ZiM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YpwkziI//txJ5Aey6bJ6KGdW498uEIr/i8vOq6DTUwE=; b=fMKxqQQdgkuHyZIF4rIGDbVxz1LO9XFkZBflFuwMsAk56ulq4FYjgMVgJbTsArluF4 XzWscd0acld7G1Q2W+dy9Rs2UZFjc1dvZnfn70CKhMG7rB2rvMzYALw1umJjrJbiC4DB DH5qtAVWtFKTNEcGXHorKVh2no2c5gktyzEM6ZveksYc5S9rnbm/xwmnFsRhOCUtIhpj mrjBnl8plLRx5IpOHyHGs4RvlYG+MSZivN/KBximyGKp5ud3RSZOKBWvbBW4nwrzxPfp KmXYX8OAnR3dPZjHJyjxetwtL5dFRw82BciriwNk4XDk7sJjx5kizhI/sPePUZ2Eo9p8 t6sw== X-Gm-Message-State: AN3rC/5CQtvAOIgI3xFsTDa7E1y2UWSqdoDr+AfGe3ja5TbOW9hnuxwnI3eGJBsHSitl1n3H X-Received: by 10.223.175.218 with SMTP id y26mr5108354wrd.63.1491828927404; Mon, 10 Apr 2017 05:55:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o77sm2507328wrc.38.2017.04.10.05.55.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:24 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A5A343E10CE; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:24 +0100 Message-Id: <20170410125524.21008-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f Subject: [Qemu-devel] [PULL 11/11] replay: assert time only goes forward X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" If we find ourselves trying to add an event to the log where time has gone backwards it is because a vCPU event has occurred and the main-loop is not yet aware of time moving forward. This should not happen and if it does its better to fail early than generate a log that will have weird behaviour. Signed-off-by: Alex Bennée -- 2.11.0 diff --git a/replay/replay-internal.c b/replay/replay-internal.c index bea7b4aa6b..fca8514012 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -195,6 +195,10 @@ void replay_save_instructions(void) if (replay_file && replay_mode == REPLAY_MODE_RECORD) { replay_mutex_lock(); int diff = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(diff >= 0); + if (diff > 0) { replay_put_event(EVENT_INSTRUCTION); replay_put_dword(diff); diff --git a/replay/replay.c b/replay/replay.c index 9e0724e756..f810628cac 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -84,6 +84,10 @@ void replay_account_executed_instructions(void) if (replay_state.instructions_count > 0) { int count = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(count >= 0); + replay_state.instructions_count -= count; replay_state.current_step += count; if (replay_state.instructions_count == 0) {