public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Ian Rogers <irogers@google.com>
Cc: peterz@infradead.org, mingo@kernel.org, acme@kernel.org,
	namhyung@kernel.org, adrian.hunter@intel.com,
	alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org,
	ak@linux.intel.com, eranian@google.com,
	Dapeng Mi <dapeng1.mi@linux.intel.com>
Subject: Re: [PATCH V2 07/13] perf/x86/intel: Support PERFEVTSEL extension
Date: Wed, 26 Jun 2024 09:25:27 -0400	[thread overview]
Message-ID: <e57cf98a-89c6-4913-99af-6a70e098f37b@linux.intel.com> (raw)
In-Reply-To: <CAP-5=fU4Mn0BhgS3n_aUmfamtD77d-VDhnZ1OoiRvXFrGJERCQ@mail.gmail.com>



On 2024-06-25 9:34 p.m., Ian Rogers wrote:
> On Tue, Jun 25, 2024 at 11:22 AM <kan.liang@linux.intel.com> wrote:
>>
>> From: Kan Liang <kan.liang@linux.intel.com>
>>
>> Two new fields (the unit mask2, and the equal flag) are added in the
>> IA32_PERFEVTSELx MSRs. They can be enumerated by the CPUID.23H.0.EBX.
>>
>> Update the config_mask in x86_pmu and x86_hybrid_pmu for the true layout
>> of the PERFEVTSEL.
>> Expose the new formats into sysfs if they are available. The umask
>> extension reuses the same format attr name "umask" as the previous
>> umask. Add umask2_show to determine/display the correct format
>> for the current machine.
>>
>> Reviewed-by: Andi Kleen <ak@linux.intel.com>
>> Co-developed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
>> ---
>>  arch/x86/events/intel/core.c      | 69 +++++++++++++++++++++++++++++--
>>  arch/x86/include/asm/perf_event.h |  4 ++
>>  2 files changed, 69 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
>> index 23e074fd25e1..9d50e1049e30 100644
>> --- a/arch/x86/events/intel/core.c
>> +++ b/arch/x86/events/intel/core.c
>> @@ -4632,8 +4632,55 @@ PMU_FORMAT_ATTR(pc,      "config:19"     );
>>  PMU_FORMAT_ATTR(any,   "config:21"     ); /* v3 + */
>>  PMU_FORMAT_ATTR(inv,   "config:23"     );
>>  PMU_FORMAT_ATTR(cmask, "config:24-31"  );
>> -PMU_FORMAT_ATTR(in_tx,  "config:32");
>> -PMU_FORMAT_ATTR(in_tx_cp, "config:33");
>> +PMU_FORMAT_ATTR(in_tx,  "config:32"    );
>> +PMU_FORMAT_ATTR(in_tx_cp, "config:33"  );
> 
> nit: It seems unfortunate these 2 lines change for the sake of spaces
> before the ')'. Perhaps leave unchanged.

The two lines don't follow the existing formats. It kind of ugly when
reading the code.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/events/intel/core.c#n4569

I just want to make the format consistent to facilitate the future code
review.

Thanks,
Kan

> 
> Thanks,
> Ian
> 
>> +PMU_FORMAT_ATTR(eq,    "config:36"     ); /* v6 + */
>> +
>> +static ssize_t umask2_show(struct device *dev,
>> +                          struct device_attribute *attr,
>> +                          char *page)
>> +{
>> +       u64 mask = hybrid(dev_get_drvdata(dev), config_mask) & ARCH_PERFMON_EVENTSEL_UMASK2;
>> +
>> +       if (mask == ARCH_PERFMON_EVENTSEL_UMASK2)
>> +               return sprintf(page, "config:8-15,40-47\n");
>> +
>> +       /* Roll back to the old format if umask2 is not supported. */
>> +       return sprintf(page, "config:8-15\n");
>> +}
>> +
>> +static struct device_attribute format_attr_umask2  =
>> +               __ATTR(umask, 0444, umask2_show, NULL);
>> +
>> +static struct attribute *format_evtsel_ext_attrs[] = {
>> +       &format_attr_umask2.attr,
>> +       &format_attr_eq.attr,
>> +       NULL
>> +};
>> +
>> +static umode_t
>> +evtsel_ext_is_visible(struct kobject *kobj, struct attribute *attr, int i)
>> +{
>> +       struct device *dev = kobj_to_dev(kobj);
>> +       u64 mask;
>> +
>> +       /*
>> +        * The umask and umask2 have different formats but share the
>> +        * same attr name. In update mode, the previous value of the
>> +        * umask is unconditionally removed before is_visible. If
>> +        * umask2 format is not enumerated, it's impossible to roll
>> +        * back to the old format.
>> +        * Does the check in umask2_show rather than is_visible.
>> +        */
>> +       if (i == 0)
>> +               return attr->mode;
>> +
>> +       mask = hybrid(dev_get_drvdata(dev), config_mask);
>> +       if (i == 1)
>> +               return (mask & ARCH_PERFMON_EVENTSEL_EQ) ? attr->mode : 0;
>> +
>> +       return 0;
>> +}
>>
>>  static struct attribute *intel_arch_formats_attr[] = {
>>         &format_attr_event.attr,
>> @@ -4786,8 +4833,14 @@ static inline bool intel_pmu_broken_perf_cap(void)
>>
>>  static void update_pmu_cap(struct x86_hybrid_pmu *pmu)
>>  {
>> -       unsigned int sub_bitmaps = cpuid_eax(ARCH_PERFMON_EXT_LEAF);
>> -       unsigned int eax, ebx, ecx, edx;
>> +       unsigned int sub_bitmaps, eax, ebx, ecx, edx;
>> +
>> +       cpuid(ARCH_PERFMON_EXT_LEAF, &sub_bitmaps, &ebx, &ecx, &edx);
>> +
>> +       if (ebx & ARCH_PERFMON_EXT_UMASK2)
>> +               pmu->config_mask |= ARCH_PERFMON_EVENTSEL_UMASK2;
>> +       if (ebx & ARCH_PERFMON_EXT_EQ)
>> +               pmu->config_mask |= ARCH_PERFMON_EVENTSEL_EQ;
>>
>>         if (sub_bitmaps & ARCH_PERFMON_NUM_COUNTER_LEAF_BIT) {
>>                 cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF,
>> @@ -5810,6 +5863,12 @@ static struct attribute_group group_format_extra_skl = {
>>         .is_visible = exra_is_visible,
>>  };
>>
>> +static struct attribute_group group_format_evtsel_ext = {
>> +       .name       = "format",
>> +       .attrs      = format_evtsel_ext_attrs,
>> +       .is_visible = evtsel_ext_is_visible,
>> +};
>> +
>>  static struct attribute_group group_default = {
>>         .attrs      = intel_pmu_attrs,
>>         .is_visible = default_is_visible,
>> @@ -5823,6 +5882,7 @@ static const struct attribute_group *attr_update[] = {
>>         &group_caps_lbr,
>>         &group_format_extra,
>>         &group_format_extra_skl,
>> +       &group_format_evtsel_ext,
>>         &group_default,
>>         NULL,
>>  };
>> @@ -6042,6 +6102,7 @@ static const struct attribute_group *hybrid_attr_update[] = {
>>         &group_caps_gen,
>>         &group_caps_lbr,
>>         &hybrid_group_format_extra,
>> +       &group_format_evtsel_ext,
>>         &group_default,
>>         &hybrid_group_cpus,
>>         NULL,
>> diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
>> index 400c909b8658..91b73571412f 100644
>> --- a/arch/x86/include/asm/perf_event.h
>> +++ b/arch/x86/include/asm/perf_event.h
>> @@ -32,6 +32,8 @@
>>  #define ARCH_PERFMON_EVENTSEL_INV                      (1ULL << 23)
>>  #define ARCH_PERFMON_EVENTSEL_CMASK                    0xFF000000ULL
>>  #define ARCH_PERFMON_EVENTSEL_BR_CNTR                  (1ULL << 35)
>> +#define ARCH_PERFMON_EVENTSEL_EQ                       (1ULL << 36)
>> +#define ARCH_PERFMON_EVENTSEL_UMASK2                   (0xFFULL << 40)
>>
>>  #define INTEL_FIXED_BITS_MASK                          0xFULL
>>  #define INTEL_FIXED_BITS_STRIDE                        4
>> @@ -185,6 +187,8 @@ union cpuid10_edx {
>>   * detection/enumeration details:
>>   */
>>  #define ARCH_PERFMON_EXT_LEAF                  0x00000023
>> +#define ARCH_PERFMON_EXT_UMASK2                        0x1
>> +#define ARCH_PERFMON_EXT_EQ                    0x2
>>  #define ARCH_PERFMON_NUM_COUNTER_LEAF_BIT      0x1
>>  #define ARCH_PERFMON_NUM_COUNTER_LEAF          0x1
>>
>> --
>> 2.35.1
>>

  reply	other threads:[~2024-06-26 13:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25 18:22 [PATCH V2 00/13] Support Lunar Lake and Arrow Lake core PMU kan.liang
2024-06-25 18:22 ` [PATCH V2 01/13] perf/x86/intel: Support the PEBS event mask kan.liang
2024-06-25 18:22 ` [PATCH V2 02/13] perf/x86: Support counter mask kan.liang
2024-06-25 18:22 ` [PATCH V2 03/13] perf/x86: Add Lunar Lake and Arrow Lake support kan.liang
2024-06-25 18:22 ` [PATCH V2 04/13] perf/x86/intel: Rename model-specific pebs_latency_data functions kan.liang
2024-06-25 18:22 ` [PATCH V2 05/13] perf/x86/intel: Support new data source for Lunar Lake kan.liang
2024-06-25 18:22 ` [PATCH V2 06/13] perf/x86: Add config_mask to represent EVENTSEL bitmask kan.liang
2024-06-25 18:22 ` [PATCH V2 07/13] perf/x86/intel: Support PERFEVTSEL extension kan.liang
2024-06-26  1:34   ` Ian Rogers
2024-06-26 13:25     ` Liang, Kan [this message]
2024-06-26 17:27       ` Ian Rogers
2024-06-25 18:22 ` [PATCH V2 08/13] perf/x86/intel: Support Perfmon MSRs aliasing kan.liang
2024-06-25 18:22 ` [PATCH V2 09/13] perf/x86: Extend event update interface kan.liang
2024-06-25 18:22 ` [PATCH V2 10/13] perf: Extend perf_output_read kan.liang
2024-06-25 18:22 ` [PATCH V2 11/13] perf/x86/intel: Move PEBS event update after the sample output kan.liang
2024-06-25 18:22 ` [PATCH V2 12/13] perf/x86/intel: Support PEBS counters snapshotting kan.liang
2024-06-25 18:22 ` [PATCH V2 13/13] perf/x86/intel: Support RDPMC metrics clear mode kan.liang
2024-06-26  5:20 ` [PATCH V2 00/13] Support Lunar Lake and Arrow Lake core PMU Ian Rogers
2024-06-26 13:11   ` Liang, Kan
2024-06-26 17:22     ` Ian Rogers
2024-06-26 18:55       ` Liang, Kan

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=e57cf98a-89c6-4913-99af-6a70e098f37b@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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