public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Rui" <rui.zhang@intel.com>
To: "alexander.shishkin@linux.intel.com"
	<alexander.shishkin@linux.intel.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"Hunter, Adrian" <adrian.hunter@intel.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"irogers@google.com" <irogers@google.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"gustavoars@kernel.org" <gustavoars@kernel.org>,
	"kan.liang@linux.intel.com" <kan.liang@linux.intel.com>,
	"kees@kernel.org" <kees@kernel.org>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"Dhananjay.Ugwekar@amd.com" <Dhananjay.Ugwekar@amd.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"acme@kernel.org" <acme@kernel.org>,
	"oleksandr@natalenko.name" <oleksandr@natalenko.name>,
	"jolsa@kernel.org" <jolsa@kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	"namhyung@kernel.org" <namhyung@kernel.org>
Cc: "ravi.bangoria@amd.com" <ravi.bangoria@amd.com>,
	"kprateek.nayak@amd.com" <kprateek.nayak@amd.com>,
	"gautham.shenoy@amd.com" <gautham.shenoy@amd.com>,
	"linux-perf-users@vger.kernel.org"
	<linux-perf-users@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>,
	"sandipan.das@amd.com" <sandipan.das@amd.com>,
	"ananth.narayan@amd.com" <ananth.narayan@amd.com>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Subject: Re: [PATCH v4 10/11] perf/x86/rapl: Add per-core energy counter support for AMD CPUs
Date: Fri, 12 Jul 2024 06:15:16 +0000	[thread overview]
Message-ID: <6eac25a0c523144980b7f606132d49221906e911.camel@intel.com> (raw)
In-Reply-To: <20240711102436.4432-11-Dhananjay.Ugwekar@amd.com>

> 
> @@ -352,9 +384,13 @@ static int rapl_pmu_event_init(struct perf_event
> *event)
>         u64 cfg = event->attr.config & RAPL_EVENT_MASK;
>         int bit, ret = 0;
>         struct rapl_pmu *rapl_pmu;
> +       struct rapl_pmus *curr_rapl_pmus;
>  
>         /* only look at RAPL events */
> -       if (event->attr.type != rapl_pmus_pkg->pmu.type)
> +       if (event->attr.type == rapl_pmus_pkg->pmu.type ||
> +               (rapl_pmus_core && event->attr.type ==
> rapl_pmus_core->pmu.type))
> +               curr_rapl_pmus = container_of(event->pmu, struct
> rapl_pmus, pmu);
> +       else
>                 return -ENOENT;
>  
>         /* check only supported bits are set */
> @@ -364,7 +400,8 @@ static int rapl_pmu_event_init(struct perf_event
> *event)
>         if (event->cpu < 0)
>                 return -EINVAL;
>  
> -       event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG;
> +       if (curr_rapl_pmus == rapl_pmus_pkg)
> +               event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG;
>  
>         if (!cfg || cfg >= NR_RAPL_PKG_DOMAINS + 1)
>                 return -EINVAL;

this sanity check becomes bogus for per_core event.

> @@ -373,7 +410,8 @@ static int rapl_pmu_event_init(struct perf_event
> *event)
>         bit = cfg - 1;
>  
>         /* check event supported */
> -       if (!(rapl_pkg_cntr_mask & (1 << bit)))
> +       if (!(rapl_pkg_cntr_mask & (1 << bit)) &&
> +           !(rapl_core_cntr_mask & (1 << bit)))
>                 return -EINVAL;

what if bit > 1 for a per_core event?

>  
>         /* unsupported modes and filters */
> @@ -381,12 +419,18 @@ static int rapl_pmu_event_init(struct
> perf_event *event)
>                 return -EINVAL;
>  
>         /* must be done before validate_group */
> -       rapl_pmu = cpu_to_rapl_pmu(event->cpu);
> +       if (curr_rapl_pmus == rapl_pmus_core) {
> +               rapl_pmu = curr_rapl_pmus-
> >rapl_pmu[topology_logical_core_id(event->cpu)];
> +               event->hw.event_base = rapl_model-
> >rapl_core_msrs[bit].msr;
> +       } else {
> +               rapl_pmu = curr_rapl_pmus-
> >rapl_pmu[get_rapl_pmu_idx(event->cpu)];
> +               event->hw.event_base = rapl_model-
> >rapl_pkg_msrs[bit].msr;
> +       }
> +

To avoid the above issues and check for (curr_rapl_pmus ==
rapl_pmus_core) all over the places, I'd suggest we do the
per_core/per_pkg sanity checks and handlings altogether, say something
like

if (event->attr.type == rapl_pmus_pkg->pmu.type) {
	all sanity checks
	rapl_pmu = ...
	event->hw.event_base = ...
} else if (rapl_pmus_core && event->attr.type ==
rapl_pmus_core->pmu.type) {
	all sanity checks
	rapl_pmu = ...
	event->hw.event_base = ...
} else {
	return --ENOENT;
}

[...]

>  static int rapl_cpu_offline(unsigned int cpu)
>  {
> -       return __rapl_cpu_offline(rapl_pmus_pkg,
> get_rapl_pmu_idx(cpu),
> +       int ret =  __rapl_cpu_offline(rapl_pmus_pkg,
> get_rapl_pmu_idx(cpu),
>                                   get_rapl_pmu_cpumask(cpu), cpu);

extra space after '='?
[...]

> +
> +       if (ret == 0 && rapl_model->core_events)
> +               ret = __rapl_cpu_offline(rapl_pmus_core,
> topology_logical_core_id(cpu),
> +                                  topology_sibling_cpumask(cpu),
> cpu);
> +
> +       return ret;
>  }
>  
>  static int __rapl_cpu_online(struct rapl_pmus *rapl_pmus, unsigned
> int rapl_pmu_idx,
> @@ -629,8 +725,14 @@ static int __rapl_cpu_online(struct rapl_pmus
> *rapl_pmus, unsigned int rapl_pmu_
>  
>  static int rapl_cpu_online(unsigned int cpu)
>  {
> -       return __rapl_cpu_online(rapl_pmus_pkg,
> get_rapl_pmu_idx(cpu),
> +       int ret =  __rapl_cpu_online(rapl_pmus_pkg,
> get_rapl_pmu_idx(cpu),
>                                  get_rapl_pmu_cpumask(cpu), cpu);

extra space after '='?
[...]


> +
> +       if (rapl_core_cntr_mask & (1 << PERF_RAPL_PER_CORE))
> +               pr_info("hw unit of domain %s 2^-%d Joules\n",
> +                       rapl_core_domain_names[PERF_RAPL_PER_CORE],
> rapl_core_hw_unit);
>  }

Are we expecting to have more than one Domain for per_core power PMU?
if no, we don't need introduce
+enum perf_rapl_core_events {
+	PERF_RAPL_PER_CORE = 0,		/* per-core */
+
+	PERF_RAPL_CORE_EVENTS_MAX,
+	NR_RAPL_CORE_DOMAINS = PERF_RAPL_CORE_EVENTS_MAX,
+};
+
and check for NR_RAPL_CORE_DOMAINS all over the place.

Or else, we should use a loop here to advertise all possible per_core
domains. Either is okay with me but the code needs to be consistent.

>  
>  static void cleanup_rapl_pmus(struct rapl_pmus *rapl_pmus)
> @@ -712,14 +820,16 @@ static const struct attribute_group
> *rapl_attr_update[] = {
>         NULL,
>  };
>  
> -static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr)
> +static const struct attribute_group *rapl_per_core_attr_update[] = {
> +       &rapl_events_per_core_group,
> +};
> +
> +static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr,
> int nr_rapl_pmu,
> +                                const struct attribute_group
> **rapl_attr_groups,
> +                                const struct attribute_group
> **rapl_attr_update)
>  {
> -       int nr_rapl_pmu = topology_max_packages();
>         struct rapl_pmus *rapl_pmus;
>  
> -       if (!rapl_pmu_is_pkg_scope())
> -               nr_rapl_pmu *= topology_max_dies_per_package();
> -
>         rapl_pmus = kzalloc(struct_size(rapl_pmus, rapl_pmu,
> nr_rapl_pmu), GFP_KERNEL);
>         if (!rapl_pmus)
>                 return -ENOMEM;
> @@ -809,8 +919,10 @@ static struct rapl_model model_spr = {
>  
>  static struct rapl_model model_amd_hygon = {
>         .pkg_events     = BIT(PERF_RAPL_PKG),
> +       .core_events    = BIT(PERF_RAPL_PER_CORE),
>         .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
>         .rapl_pkg_msrs  = amd_rapl_pkg_msrs,
> +       .rapl_core_msrs = amd_rapl_core_msrs,
>  };
>  
>  static const struct x86_cpu_id rapl_model_match[] __initconst = {
> @@ -867,6 +979,11 @@ static int __init rapl_pmu_init(void)
>  {
>         const struct x86_cpu_id *id;
>         int ret;
> +       int nr_rapl_pmu = topology_max_packages() *
> topology_max_dies_per_package();
> +       int nr_cores = topology_max_packages() *
> topology_num_cores_per_package();
> +

I thought we agreed to use one variable for all three cases.

thanks,
rui


  reply	other threads:[~2024-07-12  6:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11 10:24 [PATCH v4 00/11] Add per-core RAPL energy counter support for AMD CPUs Dhananjay Ugwekar
2024-07-11 10:24 ` [PATCH v4 01/11] x86/topology: Introduce topology_logical_core_id() Dhananjay Ugwekar
2024-07-11 10:24 ` [PATCH v4 02/11] perf/x86/rapl: Fix the energy-pkg event for AMD CPUs Dhananjay Ugwekar
2024-07-12  2:04   ` Zhang, Rui
2024-07-12  3:28     ` Dhananjay Ugwekar
2024-07-16  8:56   ` Dhananjay Ugwekar
2024-07-11 10:24 ` [PATCH v4 03/11] perf/x86/rapl: Rename rapl_pmu variables Dhananjay Ugwekar
2024-07-12  2:14   ` Zhang, Rui
2024-07-11 10:24 ` [PATCH v4 04/11] perf/x86/rapl: Make rapl_model struct global Dhananjay Ugwekar
2024-07-12  3:03   ` Zhang, Rui
2024-07-11 10:24 ` [PATCH v4 05/11] perf/x86/rapl: Move cpumask variable to rapl_pmus struct Dhananjay Ugwekar
2024-07-12  3:07   ` Zhang, Rui
2024-07-12  3:30     ` Dhananjay Ugwekar
2024-07-11 10:24 ` [PATCH v4 06/11] perf/x86/rapl: Add wrapper for online/offline functions Dhananjay Ugwekar
2024-07-12  3:20   ` Zhang, Rui
2024-07-11 10:24 ` [PATCH v4 07/11] perf/x86/rapl: Add an argument to the cleanup and init functions Dhananjay Ugwekar
2024-07-12  3:22   ` Zhang, Rui
2024-07-11 10:24 ` [PATCH v4 08/11] perf/x86/rapl: Modify the generic variable names to *_pkg* Dhananjay Ugwekar
2024-07-12  3:28   ` Zhang, Rui
2024-07-11 10:24 ` [PATCH v4 09/11] perf/x86/rapl: Remove the global variable rapl_msrs Dhananjay Ugwekar
2024-07-12  3:29   ` Zhang, Rui
2024-07-11 10:24 ` [PATCH v4 10/11] perf/x86/rapl: Add per-core energy counter support for AMD CPUs Dhananjay Ugwekar
2024-07-12  6:15   ` Zhang, Rui [this message]
2024-07-11 10:24 ` [PATCH v4 11/11] perf/x86/rapl: Remove the unused function cpu_to_rapl_pmu Dhananjay Ugwekar
2024-07-11 22:23 ` [PATCH v4 00/11] Add per-core RAPL energy counter support for AMD CPUs Ian Rogers
2024-07-15  9:35   ` Dhananjay Ugwekar
2024-07-15 15:22     ` Ian Rogers
2024-07-16  8:42       ` Dhananjay Ugwekar
2024-07-16 22:47         ` Ian Rogers
2024-07-17  8:04           ` Dhananjay Ugwekar
2024-07-17 15:36             ` Ian Rogers

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=6eac25a0c523144980b7f606132d49221906e911.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=Dhananjay.Ugwekar@amd.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ananth.narayan@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=gautham.shenoy@amd.com \
    --cc=gustavoars@kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=oleksandr@natalenko.name \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=sandipan.das@amd.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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