From patchwork Mon Oct 31 14:13:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 80188 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp149063qge; Mon, 31 Oct 2016 07:35:13 -0700 (PDT) X-Received: by 10.55.189.4 with SMTP id n4mr23478745qkf.209.1477924513458; Mon, 31 Oct 2016 07:35: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 h185si17716174qkd.260.2016.10.31.07.35.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 31 Oct 2016 07:35: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=@gmail.com; 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 Received: from localhost ([::1]:36018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1Dg8-0002Rx-VW for patch@linaro.org; Mon, 31 Oct 2016 10:35:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1DLb-0000JX-LJ for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:14:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1DLZ-0002xW-Fr for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:13:59 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c1DLZ-0002wv-4G for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:13:57 -0400 Received: by mail-wm0-x243.google.com with SMTP id p190so12379082wmp.1 for ; Mon, 31 Oct 2016 07:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=704ZRFlfxhjrydWpyij0DTgZMBq8Dh2+AS+1HumGHsY=; b=mxNuIa/XBYND21t89CU0L5/plPgC4dfN2IhsiXUp/WHyO3hfLVQO4DGHJ1Dnqvf9YL SjA04BnGtCjUajhcQnB3jkaSz2/q9TVhCf8Z4GGQ/Gr0AJ7CZMnRnM4dOXZEpsBnTMgt TOsormJmIAZ23IdUtDpsYKJ7AJiFMLdxSVIS+yOCZnOMLezd/+EsaSPRlIa7TNvy44zh mSm35pgOowzVU3thQe0Kt5kHhcT89lLk0vSsafPvNpnlkV5ll4EKsCSDY5mJtvGdK3Zf 1ML6mf9XrVHiHKV+Di6WBgWyuKKF/CSgSt70apYlWzNoO+CZMuEMaWoVqs0Zg7et4Ux4 qgaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=704ZRFlfxhjrydWpyij0DTgZMBq8Dh2+AS+1HumGHsY=; b=VwiG9A1rMTFzhga8gb6DzjX9iuCvlFeAO7a5WJvt1ospApSYsSJiQoK1MvODFPIW03 97LxsP6vuJdkS+nmEAW/f2L56gTrtboLvO8FCR1UDmL9eC2uNlczs5bx6cYqrW0jZorM gQuR130sYQ/n0+eNwpdgJrP1Q8n4And8Z9J/JQas9rwdc1K6KwzR3JaYnJlZUpo0vw8n AEfFFGLOgEsn4nALVACGUrSe8hGrPIhNyRZSzS7zKqr/6QlWDF9curqansHL6j9Ed1EU cKqdd9rbPnriiODHsKYVEHVge40Lsxjr6JEyK9pZ3nzjL5DUMHOfxPqGlWa/NFYE22Gk D3+A== X-Gm-Message-State: ABUngvdRer7QZRSk8xq15q4lpW5yiHSGw7afyxkTjTycN6crfXocX7lH2Sdv3NKigYkitA== X-Received: by 10.194.85.229 with SMTP id k5mr22235372wjz.22.1477923235814; Mon, 31 Oct 2016 07:13:55 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-246-178.clienti.tiscali.it. [78.12.246.178]) by smtp.gmail.com with ESMTPSA id p13sm25052133wmd.20.2016.10.31.07.13.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 07:13:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 31 Oct 2016 15:13:31 +0100 Message-Id: <1477923215-30323-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477923215-30323-1-git-send-email-pbonzini@redhat.com> References: <1477923215-30323-1-git-send-email-pbonzini@redhat.com> 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::243 Subject: [Qemu-devel] [PULL 10/14] tcg: move tcg_exec_all and helpers above 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée This is a pure mechanical change in preparation for up-coming re-factoring. Instead of a forward declaration for tcg_exec_all it and the associated helper functions are moved in front of the call from qemu_tcg_cpu_thread_fn. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-Id: <20161027151030.20863-12-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- cpus.c | 200 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 99 insertions(+), 101 deletions(-) -- 2.7.4 diff --git a/cpus.c b/cpus.c index 5324ba3..77cc24b 100644 --- a/cpus.c +++ b/cpus.c @@ -1055,7 +1055,105 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) #endif } -static void tcg_exec_all(void); +static int64_t tcg_get_icount_limit(void) +{ + int64_t deadline; + + if (replay_mode != REPLAY_MODE_PLAY) { + deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + + /* Maintain prior (possibly buggy) behaviour where if no deadline + * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than + * INT32_MAX nanoseconds ahead, we still use INT32_MAX + * nanoseconds. + */ + if ((deadline < 0) || (deadline > INT32_MAX)) { + deadline = INT32_MAX; + } + + return qemu_icount_round(deadline); + } else { + return replay_get_instructions(); + } +} + +static int tcg_cpu_exec(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; + 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; + } + cpu_exec_start(cpu); + ret = cpu_exec(cpu); + cpu_exec_end(cpu); +#ifdef CONFIG_PROFILER + tcg_time += profile_getclock() - ti; +#endif + 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; + cpu->icount_extra = 0; + replay_account_executed_instructions(); + } + return ret; +} + +static void tcg_exec_all(void) +{ + int r; + + /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ + qemu_account_warp_timer(); + + if (next_cpu == NULL) { + next_cpu = first_cpu; + } + for (; next_cpu != NULL && !exit_request; next_cpu = CPU_NEXT(next_cpu)) { + CPUState *cpu = next_cpu; + + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, + (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); + + if (cpu_can_run(cpu)) { + r = tcg_cpu_exec(cpu); + if (r == EXCP_DEBUG) { + cpu_handle_guest_debug(cpu); + break; + } else if (r == EXCP_ATOMIC) { + cpu_exec_step_atomic(cpu); + } + } else if (cpu->stop || cpu->stopped) { + if (cpu->unplug) { + next_cpu = CPU_NEXT(cpu); + } + break; + } + } + + /* Pairs with smp_wmb in qemu_cpu_kick. */ + atomic_mb_set(&exit_request, 0); +} static void *qemu_tcg_cpu_thread_fn(void *arg) { @@ -1412,106 +1510,6 @@ int vm_stop_force_state(RunState state) } } -static int64_t tcg_get_icount_limit(void) -{ - int64_t deadline; - - if (replay_mode != REPLAY_MODE_PLAY) { - deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); - - /* Maintain prior (possibly buggy) behaviour where if no deadline - * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than - * INT32_MAX nanoseconds ahead, we still use INT32_MAX - * nanoseconds. - */ - if ((deadline < 0) || (deadline > INT32_MAX)) { - deadline = INT32_MAX; - } - - return qemu_icount_round(deadline); - } else { - return replay_get_instructions(); - } -} - -static int tcg_cpu_exec(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; - 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; - } - cpu_exec_start(cpu); - ret = cpu_exec(cpu); - cpu_exec_end(cpu); -#ifdef CONFIG_PROFILER - tcg_time += profile_getclock() - ti; -#endif - 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; - cpu->icount_extra = 0; - replay_account_executed_instructions(); - } - return ret; -} - -static void tcg_exec_all(void) -{ - int r; - - /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ - qemu_account_warp_timer(); - - if (next_cpu == NULL) { - next_cpu = first_cpu; - } - for (; next_cpu != NULL && !exit_request; next_cpu = CPU_NEXT(next_cpu)) { - CPUState *cpu = next_cpu; - - qemu_clock_enable(QEMU_CLOCK_VIRTUAL, - (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); - - if (cpu_can_run(cpu)) { - r = tcg_cpu_exec(cpu); - if (r == EXCP_DEBUG) { - cpu_handle_guest_debug(cpu); - break; - } else if (r == EXCP_ATOMIC) { - cpu_exec_step_atomic(cpu); - } - } else if (cpu->stop || cpu->stopped) { - if (cpu->unplug) { - next_cpu = CPU_NEXT(cpu); - } - break; - } - } - - /* Pairs with smp_wmb in qemu_cpu_kick. */ - atomic_mb_set(&exit_request, 0); -} - void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg) { /* XXX: implement xxx_cpu_list for targets that still miss it */