Re: [PATCH v1 1/8] perf/x86: add support to mask counters from host

From: Wei Wang
Date: Mon Nov 05 2018 - 06:14:19 EST


On 11/05/2018 05:34 PM, Peter Zijlstra wrote:
On Fri, Nov 02, 2018 at 05:08:31PM +0800, Wei Wang wrote:
On 11/01/2018 10:52 PM, Peter Zijlstra wrote:
@@ -723,6 +724,9 @@ static void perf_sched_init(struct perf_sched *sched, struct event_constraint **
sched->max_weight = wmax;
sched->max_gp = gpmax;
sched->constraints = constraints;
+#ifdef CONFIG_CPU_SUP_INTEL
+ sched->state.used[0] = cpuc->intel_ctrl_guest_mask;
+#endif
NAK. This completely undermines the whole purpose of event scheduling.

Hi Peter,

Could you share more details how it would affect the host side event
scheduling?
Not all counters are equal; suppose you have one of those chips that can
only do PEBS on counter 0, and then hand out 0 to the guest for some
silly event. That means nobody can use PEBS anymore.

Thanks for sharing your point.

In this example (assume PEBS can only work with counter 0), how would the existing approach (i.e. using host event to emulate) work?
For example, guest wants to use PEBS, host also wants to use PEBS or other features that only counter 0 fits, I think either guest or host will not work then.

With the register level virtualization approach, we could further support that case: if guest requests to use a counter which host happens to be using, we can let host and guest both be satisfied by supporting counter context switching on guest/host switching. In this case, both guest and host can use counter 0. (I think this is actually a policy selection, the current series chooses to be guest first, we can further change it if necessary)


Would you have any suggestions?
I would suggest not to use virt in the first place of course ;-)

But whatever you do; you have to keep using host events to emulate the
guest PMU. That doesn't mean you can't improve things; that code is
quite insane from what you told earlier.

I agree that the host event emulation is a functional approach, but it may not be an effective one (also got complaints from people about today's perf in the guest).
We actually have similar problems when doing network virtualization. The more effective approach tends to be the one that bypasses the host network stack. Both the network stack and perf stack seem to be too heavy to be used as part of the emulation.

Hope we could have thorough discussions on the two approaches from virtualization point of view, and get to know why host event emulation has to be the one, or it could be better to use the register level virtualization model.

Best,
Wei