qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: "Matheus K. Ferst" <matheus.ferst@eldorado.org.br>,
	qemu-devel@nongnu.org
Cc: Gustavo Romero <gustavo.romero@linaro.org>,
	Gustavo Romero <gromero@linux.ibm.com>,
	richard.henderson@linaro.org, groug@kaod.org,
	qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au
Subject: Re: [PATCH v5 09/10] target/ppc: PMU Event-Based exception support
Date: Mon, 8 Nov 2021 18:03:43 -0300	[thread overview]
Message-ID: <50853219-ae7d-d48d-4fd9-3bafe27f14e2@gmail.com> (raw)
In-Reply-To: <ee84d577-b51b-2b08-6fea-5e3a67a459c8@eldorado.org.br>



On 11/8/21 17:34, Matheus K. Ferst wrote:
> On 08/11/2021 17:03, Daniel Henrique Barboza wrote:
>> [E-MAIL EXTERNO] Não clique em links ou abra anexos, a menos que você possa confirmar o remetente e saber que o conteúdo é seguro. Em caso de e-mail suspeito entre imediatamente em contato com o DTI.
>>
>> On 11/8/21 16:48, Matheus K. Ferst wrote:
>>> On 01/11/2021 20:56, Daniel Henrique Barboza wrote:
>>>> From: Gustavo Romero <gromero@linux.ibm.com>
>>>>
>>>> Following up the rfebb implementation, this patch adds the EBB exception
>>>> support that are triggered by Performance Monitor alerts. This exception
>>>> occurs when an enabled PMU condition or event happens and both MMCR0_EBE
>>>> and BESCR_PME are set.
>>>>
>>>> The supported PM alerts will consist of counter negative conditions of
>>>> the PMU counters. This will be achieved by a timer mechanism that will
>>>> predict when a counter becomes negative. The PMU timer callback will set
>>>> the appropriate bits in MMCR0 and fire a PMC interrupt. The EBB
>>>> exception code will then set the appropriate BESCR bits, set the next
>>>> instruction pointer to the address pointed by the return register
>>>> (SPR_EBBRR), and redirect execution to the handler (pointed by
>>>> SPR_EBBHR).
>>>>
>>>> CC: Gustavo Romero <gustavo.romero@linaro.org>
>>>> Signed-off-by: Gustavo Romero <gromero@linux.ibm.com>
>>>> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
>>>> ---
>>>>   target/ppc/cpu.h         |  5 ++++-
>>>>   target/ppc/excp_helper.c | 28 ++++++++++++++++++++++++++++
>>>>   target/ppc/power8-pmu.c  | 26 ++++++++++++++++++++++++--
>>>>   3 files changed, 56 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
>>>> index 8f545ff482..592031ce54 100644
>>>> --- a/target/ppc/cpu.h
>>>> +++ b/target/ppc/cpu.h
>>>> @@ -129,8 +129,10 @@ enum {
>>>>       /* ISA 3.00 additions */
>>>>       POWERPC_EXCP_HVIRT    = 101,
>>>>       POWERPC_EXCP_SYSCALL_VECTORED = 102, /* scv exception                     */
>>>> +    POWERPC_EXCP_EBB = 103, /* Event-based branch exception                  */
>>>> +
>>>>       /* EOL                                                                   */
>>>> -    POWERPC_EXCP_NB       = 103,
>>>> +    POWERPC_EXCP_NB       = 104,
>>>>       /* QEMU exceptions: special cases we want to stop translation            */
>>>>       POWERPC_EXCP_SYSCALL_USER = 0x203, /* System call in user mode only      */
>>>>   };
>>>> @@ -2455,6 +2457,7 @@ enum {
>>>>       PPC_INTERRUPT_HMI,            /* Hypervisor Maintenance interrupt    */
>>>>       PPC_INTERRUPT_HDOORBELL,      /* Hypervisor Doorbell interrupt        */
>>>>       PPC_INTERRUPT_HVIRT,          /* Hypervisor virtualization interrupt  */
>>>> +    PPC_INTERRUPT_PMC,            /* Hypervisor virtualization interrupt  */
>>>>   };
>>>>
>>>>   /* Processor Compatibility mask (PCR) */
>>>> diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
>>>> index 7be334e007..88aa0a84f8 100644
>>>> --- a/target/ppc/excp_helper.c
>>>> +++ b/target/ppc/excp_helper.c
>>>> @@ -797,6 +797,22 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
>>>>           cpu_abort(cs, "Non maskable external exception "
>>>>                     "is not implemented yet !\n");
>>>>           break;
>>>> +    case POWERPC_EXCP_EBB:       /* Event-based branch exception             */
>>>> +        if ((env->spr[SPR_BESCR] & BESCR_GE) &&
>>>> +            (env->spr[SPR_BESCR] & BESCR_PME)) {
>>>
>>> Do we need to check FSCR[EBB] here?
>>
>> FSCR[EBB] is being checked in the spr_read_ebb* and spr_write_ebb* callbacks
>> in translate.c. These are the read/write callbacks of EBB sprs
>> (register_power8_ebb_sprs() in target/ppc/cpu_init.c).
>>
> 
> I'm not sure if these checks are enough. Looking at section 4.4 of book III, it seems that we need to check again before delivering the exception. E.g., if the timer expires with MSR[PR]=0 and supervisor code disables the facility before it returns to problem state, we would have a spurious exception.

Hmmm yeah, I guess it's not worth assuming that this bit will be intact.

I'll go with your suggestion and add a check for FSCR[EBB] before firing the
interrupt.


Thanks,

Daniel


> 
>>
>> Thanks,
>>
>>
>> Daniel
>>
>>
>>>
>>>> +            target_ulong nip;
>>>> +
>>>> +            env->spr[SPR_BESCR] &= ~BESCR_GE;   /* Clear GE */
>>>> +            env->spr[SPR_BESCR] |= BESCR_PMEO;  /* Set PMEO */
>>>> +            env->spr[SPR_EBBRR] = env->nip;     /* Save NIP for rfebb insn */
>>>> +            nip = env->spr[SPR_EBBHR];          /* EBB handler */
>>>> +            powerpc_set_excp_state(cpu, nip, env->msr);
>>>> +        }
>>>> +        /*
>>>> +         * This interrupt is handled by userspace. No need
>>>> +         * to proceed.
>>>> +         */
>>>> +        return;
>>>>       default:
>>>>       excp_invalid:
>>>>           cpu_abort(cs, "Invalid PowerPC exception %d. Aborting\n", excp);
>>>> @@ -1044,6 +1060,18 @@ static void ppc_hw_interrupt(CPUPPCState *env)
>>>>               powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_THERM);
>>>>               return;
>>>>           }
>>>> +        /* PMC -> Event-based branch exception */
>>>> +        if (env->pending_interrupts & (1 << PPC_INTERRUPT_PMC)) {
>>>> +            /*
>>>> +             * Performance Monitor event-based exception can only
>>>> +             * occur in problem state.
>>>> +             */
>>>> +            if (msr_pr == 1) {
>>>> +                env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PMC);
>>>> +                powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_EBB);
>>>> +                return;
>>>> +            }
>>>> +        }
>>>>       }
>>>>
>>>>       if (env->resume_as_sreset) {
>>>> diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c
>>>> index aa10233b29..ca3954ff0e 100644
>>>> --- a/target/ppc/power8-pmu.c
>>>> +++ b/target/ppc/power8-pmu.c
>>>> @@ -323,8 +323,30 @@ static void fire_PMC_interrupt(PowerPCCPU *cpu)
>>>>           return;
>>>>       }
>>>>
>>>> -    /* PMC interrupt not implemented yet */
>>>> -    return;
>>>> +    if (env->spr[SPR_POWER_MMCR0] & MMCR0_FCECE) {
>>>> +        env->spr[SPR_POWER_MMCR0] &= ~MMCR0_FCECE;
>>>> +        env->spr[SPR_POWER_MMCR0] |= MMCR0_FC;
>>>> +
>>>> +        /* Changing MMCR0_FC demands a new hflags compute */
>>>> +        hreg_compute_hflags(env);
>>>> +
>>>> +        /*
>>>> +         * Delete all pending timers if we need to freeze
>>>> +         * the PMC. We'll restart them when the PMC starts
>>>> +         * running again.
>>>> +         */
>>>> +        pmu_delete_timers(env);
>>>> +    }
>>>> +
>>>> +    pmu_update_cycles(env);
>>>> +
>>>> +    if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMAE) {
>>>> +        env->spr[SPR_POWER_MMCR0] &= ~MMCR0_PMAE;
>>>> +        env->spr[SPR_POWER_MMCR0] |= MMCR0_PMAO;
>>>> +    }
>>>> +
>>>> +    /* Fire the PMC hardware exception */
>>>> +    ppc_set_irq(cpu, PPC_INTERRUPT_PMC, 1);
>>>>   }
>>>>
>>>>   /* This helper assumes that the PMC is running. */
>>>> -- 
>>>> 2.31.1
>>>>
>>>
>>>
> 
> 
> Thanks,
> Matheus K. Ferst
> Instituto de Pesquisas ELDORADO <http://www.eldorado.org.br/>
> Analista de Software
> Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>


  reply	other threads:[~2021-11-08 21:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 23:56 [PATCH v5 00/10] PMU-EBB support for PPC64 TCG Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 01/10] target/ppc: introduce PMUEventType and PMU overflow timers Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 02/10] target/ppc: PMU basic cycle count for pseries TCG Daniel Henrique Barboza
2021-11-05 12:56   ` Matheus K. Ferst
2021-11-08 19:35     ` Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 03/10] target/ppc: enable PMU counter overflow with cycle events Daniel Henrique Barboza
2021-11-05 12:56   ` Matheus K. Ferst
2021-11-08 19:45     ` Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 04/10] target/ppc: enable PMU instruction count Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 05/10] target/ppc/power8-pmu.c: add PM_RUN_INST_CMPL (0xFA) event Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 06/10] target/ppc: PMU: handle setting of PMCs while running Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 07/10] target/ppc/power8-pmu.c: handle overflow bits when PMU is running Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 08/10] PPC64/TCG: Implement 'rfebb' instruction Daniel Henrique Barboza
2021-11-01 23:56 ` [PATCH v5 09/10] target/ppc: PMU Event-Based exception support Daniel Henrique Barboza
2021-11-08 19:48   ` Matheus K. Ferst
2021-11-08 20:03     ` Daniel Henrique Barboza
2021-11-08 20:34       ` Matheus K. Ferst
2021-11-08 21:03         ` Daniel Henrique Barboza [this message]
2021-11-01 23:56 ` [PATCH v5 10/10] target/ppc/excp_helper.c: EBB handling adjustments Daniel Henrique Barboza

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=50853219-ae7d-d48d-4fd9-3bafe27f14e2@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=gromero@linux.ibm.com \
    --cc=groug@kaod.org \
    --cc=gustavo.romero@linaro.org \
    --cc=matheus.ferst@eldorado.org.br \
    --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).