qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Cédric Le Goater" <clg@kaod.org>
Subject: [PULL 25/26] target/ppc: Use env->pnc_cyc_cnt
Date: Tue,  4 Jan 2022 08:31:20 +0100	[thread overview]
Message-ID: <20220104073121.3784280-26-clg@kaod.org> (raw)
In-Reply-To: <20220104073121.3784280-1-clg@kaod.org>

From: Richard Henderson <richard.henderson@linaro.org>

Use the cached pmc_cyc_cnt value in pmu_update_cycles
and pmc_update_overflow_timer.  This leaves pmc_get_event
and pmc_is_inactive unused, so remove them.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220103224746.167831-4-danielhb413@gmail.com>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 target/ppc/power8-pmu.c | 107 ++++------------------------------------
 1 file changed, 9 insertions(+), 98 deletions(-)

diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c
index 27c4c7915bf3..73713ca2a320 100644
--- a/target/ppc/power8-pmu.c
+++ b/target/ppc/power8-pmu.c
@@ -24,19 +24,6 @@
 
 #define PMC_COUNTER_NEGATIVE_VAL 0x80000000UL
 
-static bool pmc_is_inactive(CPUPPCState *env, int sprn)
-{
-    if (env->spr[SPR_POWER_MMCR0] & MMCR0_FC) {
-        return true;
-    }
-
-    if (sprn < SPR_POWER_PMC5) {
-        return env->spr[SPR_POWER_MMCR0] & MMCR0_FC14;
-    }
-
-    return env->spr[SPR_POWER_MMCR0] & MMCR0_FC56;
-}
-
 static bool pmc_has_overflow_enabled(CPUPPCState *env, int sprn)
 {
     if (sprn == SPR_POWER_PMC1) {
@@ -46,80 +33,6 @@ static bool pmc_has_overflow_enabled(CPUPPCState *env, int sprn)
     return env->spr[SPR_POWER_MMCR0] & MMCR0_PMCjCE;
 }
 
-/*
- * For PMCs 1-4, IBM POWER chips has support for an implementation
- * dependent event, 0x1E, that enables cycle counting. The Linux kernel
- * makes extensive use of 0x1E, so let's also support it.
- *
- * Likewise, event 0x2 is an implementation-dependent event that IBM
- * POWER chips implement (at least since POWER8) that is equivalent to
- * PM_INST_CMPL. Let's support this event on PMCs 1-4 as well.
- */
-static PMUEventType pmc_get_event(CPUPPCState *env, int sprn)
-{
-    uint8_t mmcr1_evt_extr[] = { MMCR1_PMC1EVT_EXTR, MMCR1_PMC2EVT_EXTR,
-                                 MMCR1_PMC3EVT_EXTR, MMCR1_PMC4EVT_EXTR };
-    PMUEventType evt_type = PMU_EVENT_INVALID;
-    uint8_t pmcsel;
-    int i;
-
-    if (pmc_is_inactive(env, sprn)) {
-        return PMU_EVENT_INACTIVE;
-    }
-
-    if (sprn == SPR_POWER_PMC5) {
-        return PMU_EVENT_INSTRUCTIONS;
-    }
-
-    if (sprn == SPR_POWER_PMC6) {
-        return PMU_EVENT_CYCLES;
-    }
-
-    i = sprn - SPR_POWER_PMC1;
-    pmcsel = extract64(env->spr[SPR_POWER_MMCR1], mmcr1_evt_extr[i],
-                       MMCR1_EVT_SIZE);
-
-    switch (pmcsel) {
-    case 0x2:
-        evt_type = PMU_EVENT_INSTRUCTIONS;
-        break;
-    case 0x1E:
-        evt_type = PMU_EVENT_CYCLES;
-        break;
-    case 0xF0:
-        /*
-         * PMC1SEL = 0xF0 is the architected PowerISA v3.1
-         * event that counts cycles using PMC1.
-         */
-        if (sprn == SPR_POWER_PMC1) {
-            evt_type = PMU_EVENT_CYCLES;
-        }
-        break;
-    case 0xFA:
-        /*
-         * PMC4SEL = 0xFA is the "instructions completed
-         * with run latch set" event.
-         */
-        if (sprn == SPR_POWER_PMC4) {
-            evt_type = PMU_EVENT_INSN_RUN_LATCH;
-        }
-        break;
-    case 0xFE:
-        /*
-         * PMC1SEL = 0xFE is the architected PowerISA v3.1
-         * event to sample instructions using PMC1.
-         */
-        if (sprn == SPR_POWER_PMC1) {
-            evt_type = PMU_EVENT_INSTRUCTIONS;
-        }
-        break;
-    default:
-        break;
-    }
-
-    return evt_type;
-}
-
 void pmu_update_summaries(CPUPPCState *env)
 {
     target_ulong mmcr0 = env->spr[SPR_POWER_MMCR0];
@@ -238,18 +151,16 @@ static void pmu_update_cycles(CPUPPCState *env)
 {
     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     uint64_t time_delta = now - env->pmu_base_time;
-    int sprn;
+    int sprn, cyc_cnt = env->pmc_cyc_cnt;
 
     for (sprn = SPR_POWER_PMC1; sprn <= SPR_POWER_PMC6; sprn++) {
-        if (pmc_get_event(env, sprn) != PMU_EVENT_CYCLES) {
-            continue;
+        if (cyc_cnt & (1 << (sprn - SPR_POWER_PMC1 + 1))) {
+            /*
+             * The pseries and powernv clock runs at 1Ghz, meaning
+             * that 1 nanosec equals 1 cycle.
+             */
+            env->spr[sprn] += time_delta;
         }
-
-        /*
-         * The pseries and powernv clock runs at 1Ghz, meaning
-         * that 1 nanosec equals 1 cycle.
-         */
-        env->spr[sprn] += time_delta;
     }
 
     /* Update base_time for future calculations */
@@ -278,7 +189,7 @@ static void pmc_update_overflow_timer(CPUPPCState *env, int sprn)
         return;
     }
 
-    if (pmc_get_event(env, sprn) != PMU_EVENT_CYCLES ||
+    if (!(env->pmc_cyc_cnt & (1 << (sprn - SPR_POWER_PMC1 + 1))) ||
         !pmc_has_overflow_enabled(env, sprn)) {
         /* Overflow timer is not needed for this counter */
         timer_del(pmc_overflow_timer);
@@ -286,7 +197,7 @@ static void pmc_update_overflow_timer(CPUPPCState *env, int sprn)
     }
 
     if (env->spr[sprn] >= PMC_COUNTER_NEGATIVE_VAL) {
-        timeout =  0;
+        timeout = 0;
     } else {
         timeout = PMC_COUNTER_NEGATIVE_VAL - env->spr[sprn];
     }
-- 
2.31.1



  parent reply	other threads:[~2022-01-04  7:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04  7:30 [PULL 00/26] ppc queue Cédric Le Goater
2022-01-04  7:30 ` [PULL 01/26] ppc/pnv: Change the maximum of PHB3 devices for Power8NVL Cédric Le Goater
2022-01-04  7:30 ` [PULL 02/26] ppc/pnv: Remove PHB4 reset handler Cédric Le Goater
2022-01-04  7:30 ` [PULL 03/26] ppc/pnv: Remove the PHB4 "device-id" property Cédric Le Goater
2022-01-04  7:30 ` [PULL 04/26] pnv_phb3.c: do not set 'root-bus' as bus name Cédric Le Goater
2022-01-04  7:31 ` [PULL 05/26] pnv_phb4.c: " Cédric Le Goater
2022-01-04  7:31 ` [PULL 06/26] target/ppc: Improve logging in Radix MMU Cédric Le Goater
2022-01-11 16:51   ` Peter Maydell
2022-01-11 17:28     ` Cédric Le Goater
2022-01-04  7:31 ` [PULL 07/26] target/ppc: Check effective address validity Cédric Le Goater
2022-01-04  7:31 ` [PULL 08/26] target/ppc: Remove static inline Cédric Le Goater
2022-01-04  7:31 ` [PULL 09/26] target/ppc: Print out literal exception names in logs Cédric Le Goater
2022-01-04  7:31 ` [PULL 10/26] ppc/ppc4xx: Convert printfs() Cédric Le Goater
2022-01-04  7:31 ` [PULL 11/26] ppc/ppc405: Activate MMU logs Cédric Le Goater
2022-01-04  7:31 ` [PULL 12/26] ppc/ppc405: Restore TCR and STR write handlers Cédric Le Goater
2022-01-04  7:31 ` [PULL 13/26] ppc/ppc405: Rework ppc_40x_timers_init() to use a PowerPCCPU Cédric Le Goater
2022-01-04  7:31 ` [PULL 14/26] ppc/ppc405: Fix timer initialization Cédric Le Goater
2022-01-04  7:31 ` [PULL 15/26] ppc/ppc405: Introduce a store helper for SPR_40x_PID Cédric Le Goater
2022-01-04  7:31 ` [PULL 16/26] ppc/ppc405: Dump specific registers Cédric Le Goater
2022-01-04  7:31 ` [PULL 17/26] target/ppc: do not silence snan in xscvspdpn Cédric Le Goater
2022-01-04  7:31 ` [PULL 18/26] target/ppc: powerpc_excp: Set alternate SRRs directly Cédric Le Goater
2022-01-04  7:31 ` [PULL 19/26] target/ppc: powerpc_excp: Add excp_vectors bounds check Cédric Le Goater
2022-01-04  7:31 ` [PULL 20/26] target/ppc: powerpc_excp: Set vector earlier Cédric Le Goater
2022-01-04  7:31 ` [PULL 21/26] target/ppc: powerpc_excp: Move system call vectored code together Cédric Le Goater
2022-01-04  7:31 ` [PULL 22/26] target/ppc: powerpc_excp: Stop passing excp_model around Cédric Le Goater
2022-01-04  7:31 ` [PULL 23/26] target/ppc: Cache per-pmc insn and cycle count settings Cédric Le Goater
2022-01-04  7:31 ` [PULL 24/26] target/ppc: Rewrite pmu_increment_insns Cédric Le Goater
2022-01-04  7:31 ` Cédric Le Goater [this message]
2022-01-04  7:31 ` [PULL 26/26] target/ppc: do not call hreg_compute_hflags() in helper_store_mmcr0() Cédric Le Goater
2022-01-04 17:55 ` [PULL 00/26] ppc queue Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220104073121.3784280-26-clg@kaod.org \
    --to=clg@kaod.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).