All of lore.kernel.org
 help / color / mirror / Atom feed
* Non-exiting rdpmc on KVM guests?
@ 2015-04-21  0:47 Andy Lutomirski
  2015-04-21 15:05 ` Peter Zijlstra
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Lutomirski @ 2015-04-21  0:47 UTC (permalink / raw)
  To: Peter Zijlstra, kvm list

I just wrote a little perf self-monitoring tool that uses rdpmc to
count cycles.  Performance sucks under KVM (VMX).

How hard would it be to avoid rdpmc exits in cases where the host and
guest pmu configurations are compatible as seen by rdpmc?  I'm mostly
ignorant of how the PMU counter offsets and such work.

(Also, grr, Intel, couldn't you come up with a better interface for this?)

--Andy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Non-exiting rdpmc on KVM guests?
  2015-04-21  0:47 Non-exiting rdpmc on KVM guests? Andy Lutomirski
@ 2015-04-21 15:05 ` Peter Zijlstra
  2015-04-21 16:32   ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2015-04-21 15:05 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: kvm list

On Mon, Apr 20, 2015 at 05:47:23PM -0700, Andy Lutomirski wrote:
> I just wrote a little perf self-monitoring tool that uses rdpmc to
> count cycles.  Performance sucks under KVM (VMX).
> 
> How hard would it be to avoid rdpmc exits in cases where the host and
> guest pmu configurations are compatible as seen by rdpmc?  I'm mostly
> ignorant of how the PMU counter offsets and such work.

I'm not sure how all the VMX stuff works. how is rdpmc seem? It it at
all possible to not trap that?

But as it stands there is not even a hint from the emulated pmu events
on which counters they 'ought' to run so they landing the same way the
guest thinks they ought to is rather small.

'someone' would have to go look at the event scheduling and see how to
implement it, my first suggestion would be to set hwc->idx to the
desired number and hope x86_schedule_events() takes the fast path.

Of course, the moment there's host events along with the guest events
the whole thing comes tumbling down, but there's nothing much one can do
about that.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Non-exiting rdpmc on KVM guests?
  2015-04-21 15:05 ` Peter Zijlstra
@ 2015-04-21 16:32   ` Paolo Bonzini
  2015-04-21 20:51     ` Peter Zijlstra
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2015-04-21 16:32 UTC (permalink / raw)
  To: Peter Zijlstra, Andy Lutomirski; +Cc: kvm list



On 21/04/2015 17:05, Peter Zijlstra wrote:
> On Mon, Apr 20, 2015 at 05:47:23PM -0700, Andy Lutomirski wrote:
>> I just wrote a little perf self-monitoring tool that uses rdpmc to
>> count cycles.  Performance sucks under KVM (VMX).
>>
>> How hard would it be to avoid rdpmc exits in cases where the host and
>> guest pmu configurations are compatible as seen by rdpmc?  I'm mostly
>> ignorant of how the PMU counter offsets and such work.
> 
> I'm not sure how all the VMX stuff works. how is rdpmc seem? It it at
> all possible to not trap that?

Yes, it is.  RDPMC is just yet another "exit reason" and you can avoid
exiting.  However, if you take into account that RDPMC can also be used
to read an inactive counter, and that multiple guests "fight" for the
same host counters, it's even harder to ensure that the guest counter
indices match those on the host.

Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Non-exiting rdpmc on KVM guests?
  2015-04-21 16:32   ` Paolo Bonzini
@ 2015-04-21 20:51     ` Peter Zijlstra
  2015-04-21 21:10       ` Andy Lutomirski
  2015-04-22 21:05       ` Paolo Bonzini
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Zijlstra @ 2015-04-21 20:51 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Andy Lutomirski, kvm list

On Tue, Apr 21, 2015 at 06:32:54PM +0200, Paolo Bonzini wrote:

> However, if you take into account that RDPMC can also be used
> to read an inactive counter, and that multiple guests "fight" for the
> same host counters, it's even harder to ensure that the guest counter
> indices match those on the host.

That doesn't make sense, only a single vcpu task will ever run at any
one time.

There cannot be inter guest counter contention.  Only the host can
compete for the same resources.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Non-exiting rdpmc on KVM guests?
  2015-04-21 20:51     ` Peter Zijlstra
@ 2015-04-21 21:10       ` Andy Lutomirski
  2015-04-22 15:26         ` Peter Zijlstra
  2015-04-22 21:05       ` Paolo Bonzini
  1 sibling, 1 reply; 7+ messages in thread
From: Andy Lutomirski @ 2015-04-21 21:10 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Paolo Bonzini, Andy Lutomirski, kvm list

On Tue, Apr 21, 2015 at 1:51 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, Apr 21, 2015 at 06:32:54PM +0200, Paolo Bonzini wrote:
>
>> However, if you take into account that RDPMC can also be used
>> to read an inactive counter, and that multiple guests "fight" for the
>> same host counters, it's even harder to ensure that the guest counter
>> indices match those on the host.
>
> That doesn't make sense, only a single vcpu task will ever run at any
> one time.
>
> There cannot be inter guest counter contention.  Only the host can
> compete for the same resources.

One question is whether we care if we leak unrelated counters to the
guest.  (We already leak them to unrelated user tasks, so this is
hopefully not a big deal.  OTOH, the API is different for guests.)

Another question is whether it's even worth trying to optimize this.

--Andy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Non-exiting rdpmc on KVM guests?
  2015-04-21 21:10       ` Andy Lutomirski
@ 2015-04-22 15:26         ` Peter Zijlstra
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2015-04-22 15:26 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: Paolo Bonzini, Andy Lutomirski, kvm list

On Tue, Apr 21, 2015 at 02:10:53PM -0700, Andy Lutomirski wrote:

> One question is whether we care if we leak unrelated counters to the
> guest.  (We already leak them to unrelated user tasks, so this is
> hopefully not a big deal.  OTOH, the API is different for guests.)

Good question indeed. I really do not know.

> Another question is whether it's even worth trying to optimize this.

I think I just ran into a bunch of people who think virt pmu stuff is
important, but we'll have to see if they follow up with the effort of
actually doing the work.

My only concern is that they'll not make a mess of things ;-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Non-exiting rdpmc on KVM guests?
  2015-04-21 20:51     ` Peter Zijlstra
  2015-04-21 21:10       ` Andy Lutomirski
@ 2015-04-22 21:05       ` Paolo Bonzini
  1 sibling, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2015-04-22 21:05 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Andy Lutomirski, kvm list



On 21/04/2015 22:51, Peter Zijlstra wrote:
> > However, if you take into account that RDPMC can also be used
> > to read an inactive counter, and that multiple guests "fight" for the
> > same host counters, it's even harder to ensure that the guest counter
> > indices match those on the host.
>
> That doesn't make sense, only a single vcpu task will ever run at any
> one time.

Right, but it puts more pressure on the scheduler which could end up
going more often through the slow path.

Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-04-22 21:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-21  0:47 Non-exiting rdpmc on KVM guests? Andy Lutomirski
2015-04-21 15:05 ` Peter Zijlstra
2015-04-21 16:32   ` Paolo Bonzini
2015-04-21 20:51     ` Peter Zijlstra
2015-04-21 21:10       ` Andy Lutomirski
2015-04-22 15:26         ` Peter Zijlstra
2015-04-22 21:05       ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.