public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Like Xu <like.xu.linux@gmail.com>
To: Jim Mattson <jmattson@google.com>,
	"Peter Zijlstra (Intel OTC, Netherlander)" <peterz@infradead.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Like Xu <likexu@tencent.com>
Subject: Re: [PATCH v2 2/6] KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id()
Date: Thu, 9 Dec 2021 16:11:50 +0800	[thread overview]
Message-ID: <ebfac3c7-fbc6-78a5-50c5-005ea11cc6ca@gmail.com> (raw)
In-Reply-To: <CALMp9eRaZBftkaFsmfH8V519QdSGKTORp0OAZ2WaNi3f9X=tng@mail.gmail.com>

On 9/12/2021 11:52 am, Jim Mattson wrote:
> On Mon, Nov 29, 2021 at 11:42 PM Like Xu <like.xu.linux@gmail.com> wrote:
>>
>> From: Like Xu <likexu@tencent.com>
>>
>> The find_arch_event() returns a "unsigned int" value,
>> which is used by the pmc_reprogram_counter() to
>> program a PERF_TYPE_HARDWARE type perf_event.
>>
>> The returned value is actually the kernel defined generic
> 
> Typo: generic.
> 
>> perf_hw_id, let's rename it to pmc_perf_hw_id() with simpler
>> incoming parameters for better self-explanation.
>>
>> Signed-off-by: Like Xu <likexu@tencent.com>
>> ---
>>   arch/x86/kvm/pmu.c           | 8 +-------
>>   arch/x86/kvm/pmu.h           | 3 +--
>>   arch/x86/kvm/svm/pmu.c       | 8 ++++----
>>   arch/x86/kvm/vmx/pmu_intel.c | 9 +++++----
>>   4 files changed, 11 insertions(+), 17 deletions(-)
>>
>> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
>> index 09873f6488f7..3b3ccf5b1106 100644
>> --- a/arch/x86/kvm/pmu.c
>> +++ b/arch/x86/kvm/pmu.c
>> @@ -174,7 +174,6 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
>>   void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
>>   {
>>          unsigned config, type = PERF_TYPE_RAW;
>> -       u8 event_select, unit_mask;
>>          struct kvm *kvm = pmc->vcpu->kvm;
>>          struct kvm_pmu_event_filter *filter;
>>          int i;
>> @@ -206,17 +205,12 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
>>          if (!allow_event)
>>                  return;
>>
>> -       event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
>> -       unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
>> -
>>          if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
>>                            ARCH_PERFMON_EVENTSEL_INV |
>>                            ARCH_PERFMON_EVENTSEL_CMASK |
>>                            HSW_IN_TX |
>>                            HSW_IN_TX_CHECKPOINTED))) {
> 
> The mechanics of the change look fine, but I do have some questions,
> for my own understanding.
> 
> Why don't we just use PERF_TYPE_RAW for guest counters all of the
> time? What is the advantage of matching entries in a table so that we
> can use PERF_TYPE_HARDWARE?

The first reason is we need PERF_TYPE_HARDWARE for fixed counters.

And then we might wonder whether we can create perf-event faster
using PERF_TYPE_HARDWARE compared to PERF_TYPE_HARDWARE.

But the (current) answer is no, and probably the opposite:

# The cost (nanosecond) of calling perf_event_create_kernel_counter()
PERF_TYPE_RAW
Max= 1072211
Min= 11122
Avg= 41681.7

PERF_TYPE_HARDWARE
Max= 46184215
Min= 16194
Avg= 250650

So why don't we just use PERF_TYPE_RAW for just all gp counters ?

Hi Peter, do you have any comments to invalidate this proposal ?

> 
> Why do the HSW_IN_TX* bits result in bypassing this clause, when these
> bits are extracted as arguments to pmc_reprogram_counter below?

Once upon the time, the "PERF_TYPE_RAW" was introduced in the
perf with comment "available TYPE space, raw is the max value",
which means, per my understanding, it's our final type choice
for creating a valid perf_event when HSW_IN_TX* bits are set
and KVM needs to hack other perf_event_attr stuff for this
HSW_IN_TX feature with the help of extracted arguments.

> 
> Reviewed-by: Jim Mattson <jmattson@google.com>
> 

  reply	other threads:[~2021-12-09  8:12 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30  7:42 [PATCH v2 0/6] KVM: x86/pmu: Count two basic events for emulated instructions Like Xu
2021-11-30  7:42 ` [PATCH v2 1/6] KVM: x86/pmu: Setup pmc->eventsel for fixed PMCs Like Xu
2021-12-06 19:57   ` Jim Mattson
2021-12-09 18:49     ` Paolo Bonzini
2021-12-09 18:53       ` Jim Mattson
2021-12-09 18:57         ` Paolo Bonzini
2021-12-10 10:20       ` Like Xu
     [not found]   ` <CALMp9eTq8H_bJOVKwi_7j3Kum9RvW6o-G3zCLUFco1A1cvNrkQ@mail.gmail.com>
2021-12-07  6:07     ` Like Xu
2021-12-07 17:42       ` Jim Mattson
2021-11-30  7:42 ` [PATCH v2 2/6] KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id() Like Xu
2021-12-09  3:52   ` Jim Mattson
2021-12-09  8:11     ` Like Xu [this message]
2021-12-09 19:24     ` Paolo Bonzini
2022-02-05  1:55   ` Jim Mattson
2022-02-09  9:00     ` Like Xu
2022-02-09 19:30       ` Jim Mattson
2022-02-10 11:28         ` Like Xu
2022-02-11  9:56           ` Ravi Bangoria
2022-02-11 18:16             ` Jim Mattson
2022-02-14 10:14               ` Ravi Bangoria
2022-02-16  7:44                 ` Like Xu
2022-02-16 11:24                   ` Ravi Bangoria
2021-11-30  7:42 ` [PATCH v2 3/6] KVM: x86/pmu: Reuse pmc_perf_hw_id() and drop find_fixed_event() Like Xu
2021-12-09  3:58   ` Jim Mattson
2021-11-30  7:42 ` [PATCH v2 4/6] KVM: x86/pmu: Add pmc->intr to refactor kvm_perf_overflow{_intr}() Like Xu
2021-12-09  4:25   ` Jim Mattson
2021-12-09  8:28     ` Like Xu
2021-12-10  0:54       ` Jim Mattson
2021-12-10  9:35         ` Paolo Bonzini
2021-12-10 10:11           ` Like Xu
2021-12-10 22:55           ` Jim Mattson
2021-12-10 22:59             ` Paolo Bonzini
2021-12-10 23:31               ` Jim Mattson
2021-12-12  4:56                 ` Jim Mattson
2021-12-13  6:37                   ` Jim Mattson
2021-12-16  9:57                     ` Like Xu
2021-12-16 17:52                       ` Jim Mattson
2021-11-30  7:42 ` [PATCH v2 5/6] KVM: x86: Update vPMCs when retiring instructions Like Xu
2021-12-09  4:33   ` Jim Mattson
2021-12-09  8:44     ` Like Xu
2021-12-09  9:23       ` Like Xu
2021-11-30  7:42 ` [PATCH v2 6/6] KVM: x86: Update vPMCs when retiring branch instructions Like Xu
2021-12-09  4:40   ` Jim Mattson
2021-12-09 19:30 ` [PATCH v2 0/6] KVM: x86/pmu: Count two basic events for emulated instructions Paolo Bonzini
2021-12-16 10:14   ` Like Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ebfac3c7-fbc6-78a5-50c5-005ea11cc6ca@gmail.com \
    --to=like.xu.linux@gmail.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=likexu@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox