# \[PATCH v1 00/55\] KVM: PPC: Book3S HV P9: entry/exit optimisations (page 2 of 2)

- Subsystems: KERNEL VIRTUAL MACHINE FOR POWERPC (KVM/powerpc), LINUX FOR POWERPC (32-BIT AND 64-BIT), DOCUMENTATION, THE REST
- Maintainers: Madhavan Srinivasan, Jonathan Corbet, Linus Torvalds
- Series: 55 patches touching 28 files, +2,194/-1,424
- Status: SUPERSEDED (Superseded by v4 posted 2021-11-23)
- Superseded by v4 (posted 2021-11-23).
- Revision v1 (4 revisions archived).
- List: linuxppc-dev
- 77 messages, 7 authors
- Page: https://ratatoskr.run/linuxppc-dev/2021/07/9523717/t/2
- Previous page: https://ratatoskr.run/linuxppc-dev/2021/07/9523717/t.md

## Re: \[PATCH v1 17/55\] KVM: PPC: Book3S HV P9: Implement PMU save/restore in C

- From: Nicholas Piggin \<npiggin@gmail.com\>
- Date: 2021-08-13 04:25:09 
- Message: https://ratatoskr.run/linuxppc-dev/2021/08/9524071.md

```text
Excerpts from Athira Rajeev's message of August 9, 2021 1:03 pm:
> 
> 
>> On 26-Jul-2021, at 9:19 AM, Nicholas Piggin [ref] wrote:


>> +static void freeze_pmu(unsigned long mmcr0, unsigned long mmcra)
>> +{
>> +	if (!(mmcr0 & MMCR0_FC))
>> +		goto do_freeze;
>> +	if (mmcra & MMCRA_SAMPLE_ENABLE)
>> +		goto do_freeze;
>> +	if (cpu_has_feature(CPU_FTR_ARCH_31)) {
>> +		if (!(mmcr0 & MMCR0_PMCCEXT))
>> +			goto do_freeze;
>> +		if (!(mmcra & MMCRA_BHRB_DISABLE))
>> +			goto do_freeze;
>> +	}
>> +	return;
>> +
>> +do_freeze:
>> +	mmcr0 = MMCR0_FC;
>> +	mmcra = 0;
>> +	if (cpu_has_feature(CPU_FTR_ARCH_31)) {
>> +		mmcr0 |= MMCR0_PMCCEXT;
>> +		mmcra = MMCRA_BHRB_DISABLE;
>> +	}
>> +
>> +	mtspr(SPRN_MMCR0, mmcr0);
>> +	mtspr(SPRN_MMCRA, mmcra);
>> +	isync();
>> +}
>> +
> Hi Nick,
> 
> After feezing pmu, do we need to clear “pmcregs_in_use” as well?

Not until we save the values out of the registers. pmcregs_in_use = 0 
means our hypervisor is free to clear our PMU register contents.

> Also can’t we unconditionally do the MMCR0/MMCRA/ freeze settings in here ? do we need the if conditions for FC/PMCCEXT/BHRB ?

I think it's possible, but pretty minimal advantage. I would prefer to 
set them the way perf does for now. If we can move this code into perf/
it should become easier for you to tweak things.

Thanks,
Nick
```

## Re: \[PATCH v1 17/55\] KVM: PPC: Book3S HV P9: Implement PMU save/restore in C

- From: Athira Rajeev \<hidden\>
- Date: 2021-08-14 07:13:03 
- Message: https://ratatoskr.run/linuxppc-dev/2021/08/9524086.md

```text


> On 13-Aug-2021, at 9:54 AM, Nicholas Piggin [ref] wrote:
> 
> Excerpts from Athira Rajeev's message of August 9, 2021 1:03 pm:
>> 
>> 
>>> On 26-Jul-2021, at 9:19 AM, Nicholas Piggin [ref] wrote:
> 
> 
>>> +static void freeze_pmu(unsigned long mmcr0, unsigned long mmcra)
>>> +{
>>> +	if (!(mmcr0 & MMCR0_FC))
>>> +		goto do_freeze;
>>> +	if (mmcra & MMCRA_SAMPLE_ENABLE)
>>> +		goto do_freeze;
>>> +	if (cpu_has_feature(CPU_FTR_ARCH_31)) {
>>> +		if (!(mmcr0 & MMCR0_PMCCEXT))
>>> +			goto do_freeze;
>>> +		if (!(mmcra & MMCRA_BHRB_DISABLE))
>>> +			goto do_freeze;
>>> +	}
>>> +	return;
>>> +
>>> +do_freeze:
>>> +	mmcr0 = MMCR0_FC;
>>> +	mmcra = 0;
>>> +	if (cpu_has_feature(CPU_FTR_ARCH_31)) {
>>> +		mmcr0 |= MMCR0_PMCCEXT;
>>> +		mmcra = MMCRA_BHRB_DISABLE;
>>> +	}
>>> +
>>> +	mtspr(SPRN_MMCR0, mmcr0);
>>> +	mtspr(SPRN_MMCRA, mmcra);
>>> +	isync();
>>> +}
>>> +
>> Hi Nick,
>> 
>> After feezing pmu, do we need to clear “pmcregs_in_use” as well?
> 
> Not until we save the values out of the registers. pmcregs_in_use = 0 
> means our hypervisor is free to clear our PMU register contents.
> 
>> Also can’t we unconditionally do the MMCR0/MMCRA/ freeze settings in here ? do we need the if conditions for FC/PMCCEXT/BHRB ?
> 
> I think it's possible, but pretty minimal advantage. I would prefer to 
> set them the way perf does for now.

Sure Nick, 

Other changes looks good to me.

Reviewed-by: Athira Rajeev <redacted>

Thanks
Athira
> If we can move this code into perf/
> it should become easier for you to tweak things.
> 
> Thanks,
> Nick

```
