From patchwork Wed Apr 5 13:24:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 96854 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260356obc; Wed, 5 Apr 2017 06:30:03 -0700 (PDT) X-Received: by 10.200.40.86 with SMTP id 22mr32090546qtr.245.1491399003194; Wed, 05 Apr 2017 06:30:03 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g50si17810233qtc.60.2017.04.05.06.30.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl0c-0000Eh-Nb for patch@linaro.org; Wed, 05 Apr 2017 09:30:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvw-0004ec-Oe for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvv-0000KM-Oo for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:36445) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvv-0000Jy-Hj for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:11 -0400 Received: by mail-wr0-x22f.google.com with SMTP id w11so13736044wrc.3 for ; Wed, 05 Apr 2017 06:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=do5s9bqyDkirtBCVtHMCEH1EhNrpNVT5N+MVuFJKP1s=; b=CfFP3sJs8oRSnCDnunm5J15c1dv8ADoCg/2lwQUMwSdS7YK/nX8lZcthMKM7e6aEu8 mEm5WURuWDkYWj5brHl/2+7zXHWszAd6WhnFQikdk1n7z5Sh39U8HF8CISZOx308iwmH aofR0/3eo97DPiyjL7Thh3fcwIHUm/4sk6IZM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=do5s9bqyDkirtBCVtHMCEH1EhNrpNVT5N+MVuFJKP1s=; b=AKdP+iMLCxKJoPwuvBi3Jm/+hrz6+6dXVwy7TQAKXIiaj5AwMHOfgbly+eVxfJiuPy JuNQFwvpWWyQ108DYDIY0rkFdJnXxAUkL/2Snd6QiMTJhLpiIR+ZJZVfhs00XPCXOmz6 LY18lYzWf292k6mlNJjxHGDrrl98Om/OKWp+d7tHSw5MfLAWHpvKqalqUX9/J6yieafm J2cGVyRAgcoQnsnmtMx2vYyRSvh5eqjFWSvFSM/TKSqvfsSntxfDUEMUh/rspy2faEHv YjNX7AplVhAbewD6U7SbUJuj9jV/+3Vi8wDXiIw0To5gPX7YArr1zQI1cmsMoYQP0Kj/ 0Xfg== X-Gm-Message-State: AFeK/H2qZoyeDcxZEPh5IEzcRzSgrKrKzbKNJK8jXrG2DHENyvqsz3XQL/EQ6Gv0NtPAUozX X-Received: by 10.223.151.193 with SMTP id t1mr26803239wrb.149.1491398709852; Wed, 05 Apr 2017 06:25:09 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u145sm22350893wmu.1.2017.04.05.06.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 95FD33E0FDF; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:24:58 +0100 Message-Id: <20170405132503.32125-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f Subject: [Qemu-devel] [PATCH v2 07/12] cpus: move icount preparation out of tcg_exec_cpu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" As icount is only supported for single-threaded execution due to the requirement for determinism let's remove it from the common tcg_exec_cpu path. Also remove the additional fiddling which shouldn't be required as the icount counters should all be rectified as you enter the loop. Signed-off-by: Alex Bennée --- v2 - only clear u16.low - drop BQL assert --- cpus.c | 67 ++++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 22 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 18b1746770..d9cb9407a2 100644 --- a/cpus.c +++ b/cpus.c @@ -1179,47 +1179,64 @@ static void handle_icount_deadline(void) } } -static int tcg_cpu_exec(CPUState *cpu) +static void prepare_icount_for_run(CPUState *cpu) { - int ret; -#ifdef CONFIG_PROFILER - int64_t ti; -#endif - -#ifdef CONFIG_PROFILER - ti = profile_getclock(); -#endif if (use_icount) { int64_t count; int decr; - timers_state.qemu_icount -= (cpu->icount_decr.u16.low - + cpu->icount_extra); - cpu->icount_decr.u16.low = 0; - cpu->icount_extra = 0; + + /* These should always be cleared by process_icount_data after + * each vCPU execution. However u16.high can be raised + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt + */ + g_assert(cpu->icount_decr.u16.low == 0); + g_assert(cpu->icount_extra == 0); + + count = tcg_get_icount_limit(); + timers_state.qemu_icount += count; decr = (count > 0xffff) ? 0xffff : count; count -= decr; cpu->icount_decr.u16.low = decr; cpu->icount_extra = count; } - qemu_mutex_unlock_iothread(); - cpu_exec_start(cpu); - ret = cpu_exec(cpu); - cpu_exec_end(cpu); - qemu_mutex_lock_iothread(); -#ifdef CONFIG_PROFILER - tcg_time += profile_getclock() - ti; -#endif +} + +static void process_icount_data(CPUState *cpu) +{ if (use_icount) { /* Fold pending instructions back into the instruction counter, and clear the interrupt flag. */ timers_state.qemu_icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); - cpu->icount_decr.u32 = 0; + + /* Reset the counters */ + cpu->icount_decr.u16.low = 0; cpu->icount_extra = 0; replay_account_executed_instructions(); } +} + + +static int tcg_cpu_exec(CPUState *cpu) +{ + int ret; +#ifdef CONFIG_PROFILER + int64_t ti; +#endif + +#ifdef CONFIG_PROFILER + ti = profile_getclock(); +#endif + qemu_mutex_unlock_iothread(); + cpu_exec_start(cpu); + ret = cpu_exec(cpu); + cpu_exec_end(cpu); + qemu_mutex_lock_iothread(); +#ifdef CONFIG_PROFILER + tcg_time += profile_getclock() - ti; +#endif return ret; } @@ -1306,7 +1323,13 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) if (cpu_can_run(cpu)) { int r; + + prepare_icount_for_run(cpu); + r = tcg_cpu_exec(cpu); + + process_icount_data(cpu); + if (r == EXCP_DEBUG) { cpu_handle_guest_debug(cpu); break;