From patchwork Tue May 10 15:46:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 620712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r43cH4SfZz9sBg for ; Wed, 11 May 2016 01:50:23 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=PKDv4JN/; dkim-atps=neutral Received: from localhost ([::1]:47053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09vR-0000KY-FM for incoming@patchwork.ozlabs.org; Tue, 10 May 2016 11:50:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sZ-000286-CM for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b09sW-00005n-PW for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:22 -0400 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]:36225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sW-00005V-D9 for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:20 -0400 Received: by mail-lf0-x22a.google.com with SMTP id u64so19758088lff.3 for ; Tue, 10 May 2016 08:47: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; bh=9HLsLOZX7FGyW4Y6B2wmG9VBZHzw9yBw3EMgoGTO/9c=; b=PKDv4JN/va9AR2MB5K3eSh+dmKY1wZc/oE+NYz9xBH+fr6G97NyZenISOL3sLMKGcb fxojVN2KD7hzsYm+W/nmoj/xQnsNqJrshiI8DnPJ3/1wxnOMRBsDitevwkGsR68ZaoY1 jZOrkpcig7y6aPLifemLDQoRnhDavIF3ch/mg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9HLsLOZX7FGyW4Y6B2wmG9VBZHzw9yBw3EMgoGTO/9c=; b=EM31D3m70fbUjB3HpADEH3pHAnpmAHGgB/VENKKupcnwsPAY/arlYQD0qOf6k5G8Zx xwk4arzdDNijy71W3/n0i7jyyh6zmiVD7Gmg8DGXBuqGKQfQeU1b7b9nOqkLRL5dFMt1 hXKuOHP4Ydi+BcYgszjo3Mgt+nvj4UBBMTqXSTbEBDyUJyVsmf7xqw+sPq4yzKoEX352 qBRJxouI635Cpw8tULu4PYykZeQ0TyuZDp90FfvW3zsaBBkIbVcoPQg7GZ6WPLzY0BsO i7atR9m7fNIO87NI1ayxga5B5KZF5KNVxu9kMetgafUjCogMA8ZUt+nYbcfY6eIIz7AZ P0PA== X-Gm-Message-State: AOPr4FVYONN5Gm2NwFxosIrt4iRbqINQq86kSkg5UKY9snttaVz1ONbNCuQqz9XJtkqvpA1O X-Received: by 10.112.150.66 with SMTP id ug2mr17309717lbb.127.1462895239482; Tue, 10 May 2016 08:47:19 -0700 (PDT) Received: from localhost.localdomain ([195.91.132.170]) by smtp.gmail.com with ESMTPSA id jn5sm495952lbc.24.2016.05.10.08.47.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 May 2016 08:47:18 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Tue, 10 May 2016 18:46:44 +0300 Message-Id: <1462895205-8411-5-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462895205-8411-1-git-send-email-sergey.fedorov@linaro.org> References: <1462895205-8411-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22a Subject: [Qemu-devel] [PATCH 4/5] cpu-exec: Move TB execution stuff out of cpu_exec() 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: Sergey Fedorov , Peter Crosthwaite , Paolo Bonzini , Sergey Fedorov , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Sergey Fedorov Simplify cpu_exec() by extracting TB execution code outside of cpu_exec() into a new static inline function cpu_loop_exec_tb(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Richard Henderson --- cpu-exec.c | 119 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 0760d5dc274d..60f565074618 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -506,6 +506,66 @@ static inline void cpu_handle_interrupt(CPUState *cpu, } } +static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, + TranslationBlock **last_tb, int *tb_exit, + SyncClocks *sc) +{ + uintptr_t ret; + + if (unlikely(cpu->exit_request)) { + return; + } + + trace_exec_tb(tb, tb->pc); + ret = cpu_tb_exec(cpu, tb); + *last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK); + *tb_exit = ret & TB_EXIT_MASK; + switch (*tb_exit) { + case TB_EXIT_REQUESTED: + /* Something asked us to stop executing + * chained TBs; just continue round the main + * loop. Whatever requested the exit will also + * have set something else (eg exit_request or + * interrupt_request) which we will handle + * next time around the loop. But we need to + * ensure the tcg_exit_req read in generated code + * comes before the next read of cpu->exit_request + * or cpu->interrupt_request. + */ + smp_rmb(); + *last_tb = NULL; + break; + case TB_EXIT_ICOUNT_EXPIRED: + { + /* Instruction counter expired. */ +#ifdef CONFIG_USER_ONLY + abort(); +#else + int insns_left = cpu->icount_decr.u32; + if (cpu->icount_extra && insns_left >= 0) { + /* 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 { + if (insns_left > 0) { + /* Execute remaining instructions. */ + cpu_exec_nocache(cpu, insns_left, *last_tb, false); + align_clocks(sc, cpu); + } + cpu->exception_index = EXCP_INTERRUPT; + *last_tb = NULL; + cpu_loop_exit(cpu); + } + break; +#endif + } + default: + break; + } +} + /* main execution loop */ int cpu_exec(CPUState *cpu) @@ -516,8 +576,6 @@ int cpu_exec(CPUState *cpu) CPUArchState *env = &x86_cpu->env; #endif int ret; - TranslationBlock *tb, *last_tb; - int tb_exit = 0; SyncClocks sc; /* replay_interrupt may need current_cpu */ @@ -544,6 +602,9 @@ int cpu_exec(CPUState *cpu) init_delay_params(&sc, cpu); for(;;) { + TranslationBlock *tb, *last_tb; + int tb_exit = 0; + /* prepare setjmp context for exception handling */ if (sigsetjmp(cpu->jmp_env, 0) == 0) { /* if an exception is pending, we execute it here */ @@ -556,59 +617,7 @@ int cpu_exec(CPUState *cpu) for(;;) { cpu_handle_interrupt(cpu, &last_tb); tb = tb_find_fast(cpu, &last_tb, tb_exit); - if (likely(!cpu->exit_request)) { - uintptr_t ret; - trace_exec_tb(tb, tb->pc); - /* execute the generated code */ - ret = cpu_tb_exec(cpu, tb); - last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK); - tb_exit = ret & TB_EXIT_MASK; - switch (tb_exit) { - case TB_EXIT_REQUESTED: - /* Something asked us to stop executing - * chained TBs; just continue round the main - * loop. Whatever requested the exit will also - * have set something else (eg exit_request or - * interrupt_request) which we will handle - * next time around the loop. But we need to - * ensure the tcg_exit_req read in generated code - * comes before the next read of cpu->exit_request - * or cpu->interrupt_request. - */ - smp_rmb(); - last_tb = NULL; - break; - case TB_EXIT_ICOUNT_EXPIRED: - { - /* Instruction counter expired. */ -#ifdef CONFIG_USER_ONLY - abort(); -#else - int insns_left = cpu->icount_decr.u32; - if (cpu->icount_extra && insns_left >= 0) { - /* 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 { - if (insns_left > 0) { - /* Execute remaining instructions. */ - cpu_exec_nocache(cpu, insns_left, - last_tb, false); - align_clocks(&sc, cpu); - } - cpu->exception_index = EXCP_INTERRUPT; - last_tb = NULL; - cpu_loop_exit(cpu); - } - break; -#endif - } - default: - break; - } - } + cpu_loop_exec_tb(cpu, tb, &last_tb, &tb_exit, &sc); /* Try to align the host and virtual clocks if the guest is in advance */ align_clocks(&sc, cpu);