Re: [PATCH v7 08/12] KVM/x86/vPMU: Add APIs to support host save/restore the guest lbr stack

From: Wei Wang
Date: Wed Jul 10 2019 - 04:16:19 EST


On 07/09/2019 07:45 PM, Peter Zijlstra wrote:

+ * config: Actually this field won't be used by the perf core
+ * as this event doesn't have a perf counter.
+ * sample_period: Same as above.
If it's unused; why do we need to set it at all?

OK, we'll remove the unused fields.


+ * sample_type: tells the perf core that it is an lbr event.
+ * branch_sample_type: tells the perf core that the lbr event works in
+ * the user callstack mode so that the lbr stack will be
+ * saved/restored on vCPU switching.
Again; doesn't make sense. What does the user part have to do with
save/restore? What happens when this vcpu thread drops to userspace for
an assist?

This is a fake event which doesn't run the lbr on the host.
Returning to userspace doesn't need save/restore lbr, because userspace
wouldn't change those lbr msrs.

The event is created to save/restore lbr msrs on vcpu switching.
Host perf only do this save/restore for "user callstack mode" lbr event, so we
construct the event to be "user callstack mode" to reuse the host lbr save/restore.

An alternative method is to have KVM vcpu sched_in/out callback
save/restore those msrs, which don't need to create this fake event.

Please let me know if you prefer the second method.

Best,
Wei