[PATCH] KVM: arm64: pmu: Resync EL0 state on counter rotation
Shijie Huang
shijie at amperemail.onmicrosoft.com
Mon Aug 14 01:12:23 PDT 2023
Hi Leo,
在 2023/8/14 15:16, Leo Yan 写道:
> On Fri, Aug 11, 2023 at 07:05:20PM +0100, Marc Zyngier wrote:
>> Huang Shijie reports that, when profiling a guest from the host
>> with a number of events that exceeds the number of available
>> counters, the reported counts are wildly inaccurate. Without
>> the counter oversubscription, the reported counts are correct.
>>
>> Their investigation indicates that upon counter rotation (which
>> takes place on the back of a timer interrupt), we fail to
>> re-apply the guest EL0 enabling, leading to the counting of host
>> events instead of guest events.
> Seems to me, it's not clear for why the counter rotation will cause
> the issue.
>
> In the example shared by Shijie in [1], the cycle counter is enabled for
> both host and guest, and cycle counter is a dedicated event which does
> not share counter with other events. Even there have counter rotation,
> it should not impact the cycle counter.
Just take a simple case:
perf stat -e cycles:G,cycles:H, e2,e3,e4,e5,e6,e7 ....
Assume we have 8 events, but PMU only privides 7 counters(cycle + 6 normal)
1.) The initial:
event 0 (cycles:G) ---> used cycle counter
event 1 (cycles:H) ---> used counter 1
event 2 ---> used counter 2
event 3 ---> used counter 3
event 4 ---> used counter 4
event 5 ---> used counter 5
event 6---> used counter 6
2.) After the event rotation , the event0 will put to the tail of the
list, please see rotate_ctx()
the first round, it will like this:
event 1(cycles:H) ---> used cycle counter
event 2 ---> used counter 1
event 3 ---> used counter 2
event 4 ---> used counter 3
event 5 ---> used counter 4
event 6 ---> used counter 5
event 7 ---> used counter 6
3.) Rotation it again, event 1 will in the tail.
In the second round, it will like this:
evnet 0(cycles:G) ---> used cycle counter
event 2 ---> used counter 1
event 3 ---> used counter 2
event 4 ---> used counter 3
event 5 ---> used counter 4
event 6 ---> used counter 5
event 7 ---> used counter 6
4.) Rotation it again, in the third round, it will like this:
evnet 0(cycles:G) ---> used cycle counter
event 3 ---> used counter 1
event 4 ---> used counter 2
event 5 ---> used counter 3
event 6 ---> used counter 4
event 7 ---> used counter 5
event 2(cycles:H) ---> used counter 6
....
So it will impact the cycle counter..:)
Thanks
Huang Shijie
More information about the linux-arm-kernel
mailing list