From patchwork Mon Apr 3 12:45:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 96635 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp84214qgd; Mon, 3 Apr 2017 05:52:10 -0700 (PDT) X-Received: by 10.55.71.11 with SMTP id u11mr16670677qka.78.1491223930787; Mon, 03 Apr 2017 05:52:10 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 51si11817112qtw.122.2017.04.03.05.52.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:52:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1Ss-00069Q-BO for patch@linaro.org; Mon, 03 Apr 2017 08:52:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MW-0001Ng-AW for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MV-00014a-2j for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:36 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:33911) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MU-00013z-Kf for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:34 -0400 Received: by mail-wr0-x22d.google.com with SMTP id l43so169835598wre.1 for ; Mon, 03 Apr 2017 05:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ioZGdXqtSVKXXe40BVEfmGDqf+DM4bpjnMLB+eoUNmM=; b=g3iMvLewKt4JKAdbSbhwhmEhwrGON8so1gSXChGeoAdlh8zWK8XQLCYP52TsCqG2zU SUuOF3W1J5KmZPWjxk1vGvO/cVVVja7xvDBsKSFilSbxAkLKKaomxA25YIrpcayRoU1m QK/4V3jmuFlez8b4UBZm2rZ0467SydRIQ2Hx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ioZGdXqtSVKXXe40BVEfmGDqf+DM4bpjnMLB+eoUNmM=; b=OdEAul1LmfY46TrxslfM0JtsBwvWJiwJWwA2MIgBOQavR2Xi+XGo9uIay9WqPqrcpm UzCbt9nK/4vXxfc8eRiOGEZOIpPYwryWL4ktmN9vIGVjC3nx8qUUgVayfWvFQgn2bPu0 iCYSxLPhaWxfs44No5LYNMfOao4O+iLtSaE1wlT1+LTVPuuODTQeUSBWF/8hr3flvv1D EYsAtCdTJtQ/M+Bb72N5pIjN3PhWVpLsoZpvmrrsajKOXfk+7QUabyjodp2JG9bxWwGk WVLx+yjmFVVZGcYISOHnm6KnN4O/R1QT8gISpU4Bco4k911ewtwG61pblDUzRD5mJw2L ltFw== X-Gm-Message-State: AFeK/H0cB65nQGj4tbL0mDKvMSWvRVt8spAjCNWoV1H6uf9aABr/ZNp1vWlB+kmnQ7TRjM+a X-Received: by 10.223.163.136 with SMTP id l8mr15675237wrb.57.1491223533372; Mon, 03 Apr 2017 05:45:33 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m14sm3509306wrb.13.2017.04.03.05.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 42B4F3E10CC; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:22 +0100 Message-Id: <20170403124524.10824-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [RFC PATCH v1 7/9] cpus: move icount preparation out of tcg_exec_cpu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" As icount is only supported for single-threaded execution due to the requirement for determinism let's remove it from the common tcg_exec_cpu path. Also remove the additional fiddling which shouldn't be required as the icount counters should all be rectified as you enter the loop. Signed-off-by: Alex Bennée --- cpus.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 21 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 18b1746770..87638a75d2 100644 --- a/cpus.c +++ b/cpus.c @@ -1179,47 +1179,66 @@ static void handle_icount_deadline(void) } } -static int tcg_cpu_exec(CPUState *cpu) +static void prepare_icount_for_run(CPUState *cpu) { - int ret; -#ifdef CONFIG_PROFILER - int64_t ti; -#endif - -#ifdef CONFIG_PROFILER - ti = profile_getclock(); -#endif if (use_icount) { int64_t count; int decr; - timers_state.qemu_icount -= (cpu->icount_decr.u16.low - + cpu->icount_extra); - cpu->icount_decr.u16.low = 0; - cpu->icount_extra = 0; + + /* These should always be cleared by process_icount_data after + * each vCPU execution. However u16.high can be raised + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt + */ + g_assert(cpu->icount_decr.u16.low == 0); + g_assert(cpu->icount_extra == 0); + + count = tcg_get_icount_limit(); + timers_state.qemu_icount += count; decr = (count > 0xffff) ? 0xffff : count; count -= decr; cpu->icount_decr.u16.low = decr; cpu->icount_extra = count; } - qemu_mutex_unlock_iothread(); - cpu_exec_start(cpu); - ret = cpu_exec(cpu); - cpu_exec_end(cpu); - qemu_mutex_lock_iothread(); -#ifdef CONFIG_PROFILER - tcg_time += profile_getclock() - ti; -#endif +} + +static void process_icount_data(CPUState *cpu) +{ if (use_icount) { /* Fold pending instructions back into the instruction counter, and clear the interrupt flag. */ timers_state.qemu_icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); + + /* We must be under BQL here as cpu_exit can tweak + icount_decr.u32 */ + g_assert(qemu_mutex_iothread_locked()); cpu->icount_decr.u32 = 0; cpu->icount_extra = 0; replay_account_executed_instructions(); } +} + + +static int tcg_cpu_exec(CPUState *cpu) +{ + int ret; +#ifdef CONFIG_PROFILER + int64_t ti; +#endif + +#ifdef CONFIG_PROFILER + ti = profile_getclock(); +#endif + qemu_mutex_unlock_iothread(); + cpu_exec_start(cpu); + ret = cpu_exec(cpu); + cpu_exec_end(cpu); + qemu_mutex_lock_iothread(); +#ifdef CONFIG_PROFILER + tcg_time += profile_getclock() - ti; +#endif return ret; } @@ -1306,7 +1325,13 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) if (cpu_can_run(cpu)) { int r; + + prepare_icount_for_run(cpu); + r = tcg_cpu_exec(cpu); + + process_icount_data(cpu); + if (r == EXCP_DEBUG) { cpu_handle_guest_debug(cpu); break;