From nobody Mon Feb 9 17:40:22 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.zohomail.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 153021993431639.570489431638066; Thu, 28 Jun 2018 14:05:34 -0700 (PDT) Received: from localhost ([::1]:38637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYe6f-0007O4-8d for importer@patchew.org; Thu, 28 Jun 2018 17:05:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYddk-0007Hy-V1 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYddh-0008AM-Rd for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:35:40 -0400 Received: from relay2.mail.vrmd.de ([81.28.224.28]:56669) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYddh-0007xw-Jv; Thu, 28 Jun 2018 16:35:37 -0400 Received: from [92.78.130.29] (helo=murray.fritz.box) by relay2.mail.vrmd.de with esmtpa (Exim 4.86_2) (envelope-from ) id 1fYddW-000JcK-J5; Thu, 28 Jun 2018 22:35:26 +0200 From: Sebastian Bauer To: mail@sebastianbauer.info Date: Thu, 28 Jun 2018 22:35:24 +0200 Message-Id: <20180628203524.16221-1-mail@sebastianbauer.info> X-Mailer: git-send-email 2.18.0 X-Relay-User: mail@sebastianbauer.info X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 81.28.224.28 Subject: [Qemu-devel] [RFC] ppc/tcg: send cpu to sleep for simple endless guest loops 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: agraf@suse.de, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, david@gibson.dropbear.id.au 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" When a branch instructions points to itself, only external events will change the internally observable cpu state. This change will adjust the behaviour of QEMU such that it sends the emulated cpu into a sleep state if this case is detected. The effect for guests whose idle task contains this endless loop (e.g., AmigaOS) is that they no longer hog the cpu of the host if they are idle. Signed-off-by: Sebastian Bauer --- This is a RFC because I'm not really familiar with the internals of QEMU. There are probably other (better) ways to achive a similar behaviour. For that reason I haven't tested the change thoroughly yet, except that it produces the desired effect. The patch will change the behaviour wrt. the instruction count which is no longer the same. But I don't think that this will matter. I will be grateful for any expressed concerns and suggestion of that matter. Patch is based on ppc-for-3.0. --- target/ppc/helper.h | 2 ++ target/ppc/translate.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index d751f0e219..5f9b157417 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -799,3 +799,5 @@ DEF_HELPER_4(dscliq, void, env, fprp, fprp, i32) =20 DEF_HELPER_1(tbegin, void, env) DEF_HELPER_FLAGS_1(fixup_thrm, TCG_CALL_NO_RWG, void, env) + +DEF_HELPER_1(sleep, void, env) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 3a215a1dc6..7db53003ea 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3469,6 +3469,18 @@ static inline void gen_setlr(DisasContext *ctx, targ= et_ulong nip) tcg_gen_movi_tl(cpu_lr, nip); } =20 +/* Helper for bringing the cpu to the sleep state so it will + * react only on "external" events */ +void helper_sleep(CPUPPCState *env) +{ + CPUState *cs =3D CPU(ppc_env_get_cpu(env)); + + cs->exception_index =3D EXCP_HALTED; + cs->exit_request =3D 1; + cs->halted =3D 1; + cpu_loop_exit(cs); +} + /* b ba bl bla */ static void gen_b(DisasContext *ctx) { @@ -3483,6 +3495,13 @@ static void gen_b(DisasContext *ctx) } else { target =3D li; } + + if (target =3D=3D ctx->base.pc_next - 4) { + /* Endless-loop, CPU can now react on "external" events only, so we + * simply go to sleep in order to save host processing resources */ + gen_helper_sleep(cpu_env); + } + if (LK(ctx->opcode)) { gen_setlr(ctx, ctx->base.pc_next); } --=20 2.18.0