From nobody Mon Feb 9 19:08:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487958799537725.4034562961652; Fri, 24 Feb 2017 09:53:19 -0800 (PST) Received: from localhost ([::1]:38950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chK3Q-000638-VF for importer@patchew.org; Fri, 24 Feb 2017 12:53:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chJrE-0007rF-91 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:40:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chJrB-0002F2-Qd for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:40:40 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36851) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1chJrB-0002Ej-KL for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:40:37 -0500 Received: by mail-wm0-x244.google.com with SMTP id r18so4053922wmd.3 for ; Fri, 24 Feb 2017 09:40:37 -0800 (PST) Received: from 640k.lan (94-39-187-56.adsl-ull.clienti.tiscali.it. [94.39.187.56]) by smtp.gmail.com with ESMTPSA id s26sm8814533wra.66.2017.02.24.09.40.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 09:40:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=wk+Eqr3Znz4osivFBnWipmLSUiJ/M92ZMtzRUDCFz88=; b=Bju6uMbNq568Rt0Nvdwvohbs/urp5MHMzkAWyBK5CAmfBC7PmBPiXHvL5Z4M0o+uRe uH/MTVaDOHi+ZNQzOjAFnOzaC/A4DQg0JWFpEfwLTHMXXH1M/wgOrpimXWEstitgtlwO GzUcjVl5QE9LUTCXxu0MiSjRfBFURLOxE9ddXRktm1lU3Gwwv1BJKaR8SO5eFun0M9fS Y0ofWg1UGNP5ihkKamPw3A/ts7HP2hMklzvRjH/cJpC1O97MezVVn4+or9G1oMMP7eRv a+6zUik9FlGkD44brNDQEgLg1zo9URmanV3yVGD7oHKEHAZRVrXxJfd5hS3v7dveC/zW aRJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=wk+Eqr3Znz4osivFBnWipmLSUiJ/M92ZMtzRUDCFz88=; b=I0YYyFMtfyjwYpIHfPokxaHntlv5sqpP1a2+vb785FtBCvv9QIwBw8hQWiFZup9Gwf WBIRhdMHqWED67Ih0/6Y8M0bR6cl37Y6d0w6marC68fvhAdbNFOuWx8hekkBlBXYsZRI QPGXLRkSpmhVYTgoETJNa43JqfPiJO3FG8RlKlaNC0QaZhU9K9C4dNhkVKXKNANaSvdy 04ZYbDu2QZPPWLYnnynf/4fM9lgL39qW/oT7/BEzPrBZEQAEtQWUXhC1RAONVzWZ8ms7 BYSMoPbjKjV+djguhflIVjxR+Ezy37PO5mOjBudgrnzjOPDxY6byJ8bLzp2exGWTWARJ ling== X-Gm-Message-State: AMke39nrOtBFpdJG1+y/wCYAB8rGCPjDe+9xPAlnjX4m2cfuiRLX1jLoD1FC1Z0lZqbu5Q== X-Received: by 10.28.147.72 with SMTP id v69mr3822774wmd.51.1487958036344; Fri, 24 Feb 2017 09:40:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 24 Feb 2017 18:40:15 +0100 Message-Id: <1487958030-51417-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487958030-51417-1-git-send-email-pbonzini@redhat.com> References: <1487958030-51417-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 02/17] replay: check icount in cpu exec loop 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: Pavel Dovgalyuk , Pavel Dovgalyuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pavel Dovgalyuk This patch adds check to break cpu loop when icount expires without setting the TB_EXIT_ICOUNT_EXPIRED flag. It happens when there is no available translated blocks and all instructions were executed. In icount replay mode unnecessary tb_find will be called (which may cause an exception) and execution will be non-deterministic. Because cpu_loop_exec_tb cannot longjmp anymore, we can remove the anticipated call to align_clocks in cpu_loop_exec_tb, as well as the SyncClocks *sc argument. Signed-off-by: Pavel Dovgalyuk Message-Id: <002801d2810f$18809c20$4981d460$@ru> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- cpu-exec.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 8f094c8..7ddf66c 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -517,7 +517,10 @@ static inline bool cpu_handle_interrupt(CPUState *cpu, *last_tb =3D NULL; } } - if (unlikely(atomic_read(&cpu->exit_request) || replay_has_interrupt()= )) { + + /* Finally, check if we need to exit to the main loop. */ + if (unlikely(atomic_read(&cpu->exit_request) + || (use_icount && cpu->icount_decr.u16.low + cpu->icount_extra =3D= =3D 0))) { atomic_set(&cpu->exit_request, 0); cpu->exception_index =3D EXCP_INTERRUPT; return true; @@ -527,8 +530,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu, } =20 static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, - TranslationBlock **last_tb, int *tb_ex= it, - SyncClocks *sc) + TranslationBlock **last_tb, int *tb_ex= it) { uintptr_t ret; int32_t insns_left; @@ -579,10 +581,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, Tra= nslationBlock *tb, */ if (insns_left > 0) { cpu_exec_nocache(cpu, insns_left, tb, false); - align_clocks(sc, cpu); } - cpu->exception_index =3D EXCP_INTERRUPT; - cpu_loop_exit(cpu); } #endif } @@ -593,7 +592,7 @@ int cpu_exec(CPUState *cpu) { CPUClass *cc =3D CPU_GET_CLASS(cpu); int ret; - SyncClocks sc; + SyncClocks sc =3D { 0 }; =20 /* replay_interrupt may need current_cpu */ current_cpu =3D cpu; @@ -643,7 +642,7 @@ int cpu_exec(CPUState *cpu) =20 while (!cpu_handle_interrupt(cpu, &last_tb)) { TranslationBlock *tb =3D tb_find(cpu, last_tb, tb_exit); - cpu_loop_exec_tb(cpu, tb, &last_tb, &tb_exit, &sc); + cpu_loop_exec_tb(cpu, tb, &last_tb, &tb_exit); /* Try to align the host and virtual clocks if the guest is in advance */ align_clocks(&sc, cpu); --=20 1.8.3.1