From nobody Mon Nov 25 09:52:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1716350734; cv=none; d=zohomail.com; s=zohoarc; b=m25jo8iWfT/JBp9ZusZ4HkKsXM2j3vl5e9uOsIwH8K/gIB9TBs40CYhBfQvS7MWOeIF3NdLIxLqDMZ5ryLuISmXukkuLRI078HP0j/2vgF1V0537zi5XYIjVIniWBMLXLxKRXwoksrucJ379mlptfdNQRgakLCJMzGwO6FPvmRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716350734; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0b2GXCJ22WFvTHgVXjNvK42VHOxSdD4f2sQ0k5SMWIQ=; b=DQLW8pSI5GilwlziFQub7Y3N+/sStUp39wlhNbmGphEqWPGlWegqVlHvgWowxGAWOx2jHj6Nuphg9IbhOr//NOTXFxQx+GVbXF7kRR7MdmSKCF0GWWvzXKrBrp9L5lod9Q/2z0csXWhf/rAxPqiPKI9nkWmA5mmSv85qp8wk958= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716350734225168.12017511887825; Tue, 21 May 2024 21:05:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9dDa-0005bA-MZ; Wed, 22 May 2024 00:04:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9dDW-0005Zy-Lo; Wed, 22 May 2024 00:04:43 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9dDI-0007xg-NS; Wed, 22 May 2024 00:04:42 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6f4603237e0so373783b3a.0; Tue, 21 May 2024 21:04:27 -0700 (PDT) Received: from wheely.local0.net (110-175-65-7.tpgi.com.au. [110.175.65.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6589645bbefsm10197158a12.55.2024.05.21.21.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 21:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716350666; x=1716955466; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0b2GXCJ22WFvTHgVXjNvK42VHOxSdD4f2sQ0k5SMWIQ=; b=H08e7ePvWDRGTQ4Rouqb6coQulaXqIqZFiWD6wSYPTyW67ykVdxHsllvCT5L/CrPeS nn9Fxm4UewfuAaOYu0PO+pPx/QUXswOhuBwutWCtYFVWRKVzLf2ZnHwaQHViGtBovYvW fL0lyrOupaPo5LzZRa5+KZg7J339DdaSHJWROjxfuZ0tHFb3Xb3rOrCJ8lxFHiTFKScH qRskUBVWPR+wL3AS/iNoUPjXQdmCxMkJkPI0mO17+atipjdQIFE0WTv1vD0QjWUuR4RN WkjiaiXPsqY93Lu14Qrm7UEUuX8ZravkFVR2FhmVSC3YtZcTq2zJt2kwuSrXD2R6czHZ WOpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716350666; x=1716955466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0b2GXCJ22WFvTHgVXjNvK42VHOxSdD4f2sQ0k5SMWIQ=; b=RZrMens1zn2bqQJfmhiB9VmADQEmZ4XMfc/M+git9uLB2Hf2s+1eiquI14ogBcQl9s 74YPqpHrLpPih48fmqxOBRYjjjaI77/RSx3yesDW73RcAN+FK8j+zzIRfzhk3iY5ojk8 lUZWjSCuJ10JgoxW3jR2BMIatx4G9S0zQM0M+OBe68MEDTKe/eqgMVEWrscRM1xwVAJQ 2R+KVkJzNIXqDA1o4lY6haysyDLV79C2Z02+H3WBh/CvqWPzGfeY5ypezyMd+JXHbvd2 UH22pcmoRepHyMcN5V9+Z2DJoGH820UVnZIoRFyKbdhMm3HQWYNs5sdFkYw6KCIxaFyo m0qg== X-Forwarded-Encrypted: i=1; AJvYcCUYGqwFIdajR4EsKPhwaIGVlZLdekZ8MFjPMsd/JqWCuR2BUQhK78aGfCBNtvYV0RFkDlJNso1ausxXDmR8hPzY2TZP1fY= X-Gm-Message-State: AOJu0Yx2s1Mq+mV9q85mriiqa71iGG21nuWz8cgFxUHNrhuLOsKhQk7R o4pXF3CLA8UF2zesFnJ7hoAlNJgUV144v02XEu+uV18nh/BKMZv4qOj+gQ== X-Google-Smtp-Source: AGHT+IFaFWPWJB2d2OMW0uhWNDaqI8vewArE69LE6f5+mNQBgQspjuFSSoOPRWbp3udUMExxnwgSUw== X-Received: by 2002:a05:6a20:432a:b0:1af:86e4:bc99 with SMTP id adf61e73a8af0-1b1f8045e52mr1361472637.10.1716350666332; Tue, 21 May 2024 21:04:26 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , qemu-devel@nongnu.org, Richard Henderson Subject: [PATCH 2/2] target/ppc: Tidy pmu_count_insns implementation Date: Wed, 22 May 2024 14:04:11 +1000 Message-ID: <20240522040411.90655-3-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522040411.90655-1-npiggin@gmail.com> References: <20240522040411.90655-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=npiggin@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716350735124100005 Content-Type: text/plain; charset="utf-8" Merge the user-only and full implementations together, and only call translator_io_start() and only create and set the label when necessary. Signed-off-by: Nicholas Piggin --- target/ppc/translate.c | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 344e78843c..9ce823b018 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -298,6 +298,8 @@ static inline void gen_update_nip(DisasContext *ctx, ta= rget_ulong nip) #if defined(TARGET_PPC64) static void pmu_count_insns(DisasContext *ctx) { + bool pmc_other, pmc_check_overflow; + /* * Do not bother calling the helper if the PMU isn't counting * instructions. @@ -306,48 +308,47 @@ static void pmu_count_insns(DisasContext *ctx) return; } =20 - #if !defined(CONFIG_USER_ONLY) - TCGLabel *l; - TCGv t0; + /* + * The PMU insns_inc() and handle_pmc5_overflow() helpers stop the int= ernal + * PMU timer if a counter overflow happens. In that case, if the guest= is + * running with icount and we do not handle it beforehand, the helper = can + * trigger a 'bad icount read'. So call translator_io_start() for cases + * where that might trigger. + */ =20 + #if defined(CONFIG_USER_ONLY) /* - * The PMU insns_inc() helper stops the internal PMU timer if a - * counter overflows happens. In that case, if the guest is - * running with icount and we do not handle it beforehand, - * the helper can trigger a 'bad icount read'. + * User mode can read (but not write) PMC5 and start/stop + * the PMU via MMCR0_FC. In this case just increment + * PMC5 with base.num_insns. */ - translator_io_start(&ctx->base); + pmc_other =3D false; + pmc_check_overflow =3D false; + #else + pmc_other =3D ctx->pmc_other; + pmc_check_overflow =3D ctx->mmcr0_pmcjce; + #endif =20 /* Avoid helper calls when only PMC5-6 are enabled. */ - if (!ctx->pmc_other) { - l =3D gen_new_label(); - t0 =3D tcg_temp_new(); + if (!pmc_other) { + TCGv t0 =3D tcg_temp_new(); =20 gen_load_spr(t0, SPR_POWER_PMC5); tcg_gen_addi_tl(t0, t0, ctx->base.num_insns); gen_store_spr(SPR_POWER_PMC5, t0); - /* Check for overflow, if it's enabled */ - if (ctx->mmcr0_pmcjce) { + + if (pmc_check_overflow) { + TCGLabel *l =3D gen_new_label(); + + translator_io_start(&ctx->base); tcg_gen_brcondi_tl(TCG_COND_LT, t0, PMC_COUNTER_NEGATIVE_VAL, = l); gen_helper_handle_pmc5_overflow(tcg_env); + gen_set_label(l); } - - gen_set_label(l); } else { + translator_io_start(&ctx->base); gen_helper_insns_inc(tcg_env, tcg_constant_i32(ctx->base.num_insns= )); } - #else - /* - * User mode can read (but not write) PMC5 and start/stop - * the PMU via MMCR0_FC. In this case just increment - * PMC5 with base.num_insns. - */ - TCGv t0 =3D tcg_temp_new(); - - gen_load_spr(t0, SPR_POWER_PMC5); - tcg_gen_addi_tl(t0, t0, ctx->base.num_insns); - gen_store_spr(SPR_POWER_PMC5, t0); - #endif /* #if !defined(CONFIG_USER_ONLY) */ } #else static void pmu_count_insns(DisasContext *ctx) --=20 2.43.0