Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
To: Riana Tauro <riana.tauro@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <anshuman.gupta@intel.com>,
	<lucas.demarchi@intel.com>
Subject: Re: [PATCH v8 5/5] drm/xe/xe_pmu: Acquire forcewake on event init for engine events
Date: Fri, 21 Feb 2025 11:43:16 -0800	[thread overview]
Message-ID: <Z7jXVEvzltlnIUvn@orsosgc001> (raw)
In-Reply-To: <20250221105908.1966738-6-riana.tauro@intel.com>

On Fri, Feb 21, 2025 at 04:29:07PM +0530, Riana Tauro wrote:
>When the engine events are created, acquire GT forcewake to read gpm
>timestamp required for the events and release on event destroy. This
>cannot be done during read due to the raw spinlock held my pmu.
>
>v2: remove forcewake counting (Umesh)
>v3: remove extra space (Umesh)
>v4: use event pmu private data (Lucas)
>
>Signed-off-by: Riana Tauro <riana.tauro@intel.com>
>Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
>Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
>---
> drivers/gpu/drm/xe/xe_pmu.c | 50 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
>diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
>index d2c035c1924e..0c8563830195 100644
>--- a/drivers/gpu/drm/xe/xe_pmu.c
>+++ b/drivers/gpu/drm/xe/xe_pmu.c
>@@ -7,6 +7,7 @@
> #include <linux/device.h>
>
> #include "xe_device.h"
>+#include "xe_force_wake.h"
> #include "xe_gt_idle.h"
> #include "xe_guc_engine_activity.h"
> #include "xe_hw_engine.h"
>@@ -102,6 +103,41 @@ static struct xe_hw_engine *event_to_hwe(struct perf_event *event)
> 	return hwe;
> }
>
>+static bool is_engine_event(u64 config)
>+{
>+	unsigned int event_id = config_to_event_id(config);
>+
>+	return (event_id == XE_PMU_EVENT_ENGINE_TOTAL_TICKS ||
>+		event_id == XE_PMU_EVENT_ENGINE_ACTIVE_TICKS);
>+}
>+
>+static bool event_gt_forcewake(struct perf_event *event)
>+{
>+	struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
>+	u64 config = event->attr.config;
>+	struct xe_gt *gt;
>+	unsigned int *fw_ref;
>+
>+	if (!is_engine_event(config))
>+		return true;
>+
>+	gt = xe_device_get_gt(xe, config_to_gt_id(config));
>+
>+	fw_ref = kzalloc(sizeof(*fw_ref), GFP_KERNEL);
>+	if (!fw_ref)
>+		return false;
>+
>+	*fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
>+	if (!*fw_ref) {
>+		kfree(fw_ref);
>+		return false;
>+	}
>+
>+	event->pmu_private = fw_ref;
>+
>+	return true;
>+}
>+
> static bool event_supported(struct xe_pmu *pmu, unsigned int gt,
> 			    unsigned int id)
> {
>@@ -144,6 +180,15 @@ static bool event_param_valid(struct perf_event *event)
> static void xe_pmu_event_destroy(struct perf_event *event)
> {
> 	struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
>+	struct xe_gt *gt;
>+	unsigned int *fw_ref = event->pmu_private;
>+
>+	if (fw_ref) {
>+		gt = xe_device_get_gt(xe, config_to_gt_id(event->attr.config));
>+		xe_force_wake_put(gt_to_fw(gt), *fw_ref);
>+		kfree(event->pmu_private);

For correlating the kzalloc/kfree while browsing code, it helps if you 
use the local copy - kfree(fw_ref).

Thanks,
Umesh


>+		event->pmu_private = NULL;
>+	}
>
> 	drm_WARN_ON(&xe->drm, event->parent);
> 	xe_pm_runtime_put(xe);
>@@ -183,6 +228,11 @@ static int xe_pmu_event_init(struct perf_event *event)
> 	if (!event->parent) {
> 		drm_dev_get(&xe->drm);
> 		xe_pm_runtime_get(xe);
>+		if (!event_gt_forcewake(event)) {
>+			xe_pm_runtime_put(xe);
>+			drm_dev_put(&xe->drm);
>+			return -EINVAL;
>+		}
> 		event->destroy = xe_pmu_event_destroy;
> 	}
>
>-- 
>2.47.1
>

  reply	other threads:[~2025-02-21 19:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 10:59 [PATCH v8 0/5] PMU support for engine activity Riana Tauro
2025-02-21 10:59 ` [PATCH v8 1/5] drm/xe: Add engine activity support Riana Tauro
2025-02-21 10:59 ` [PATCH v8 2/5] drm/xe/trace: Add trace for engine activity Riana Tauro
2025-02-21 10:59 ` [PATCH v8 3/5] drm/xe/guc: Expose engine activity only for supported GuC version Riana Tauro
2025-02-21 10:59 ` [PATCH v8 4/5] drm/xe/xe_pmu: Add PMU support for engine activity Riana Tauro
2025-02-21 10:59 ` [PATCH v8 5/5] drm/xe/xe_pmu: Acquire forcewake on event init for engine events Riana Tauro
2025-02-21 19:43   ` Umesh Nerlige Ramappa [this message]
2025-02-21 11:25 ` ✓ CI.Patch_applied: success for PMU support for engine activity (rev4) Patchwork
2025-02-21 11:26 ` ✗ CI.checkpatch: warning " Patchwork
2025-02-21 11:27 ` ✓ CI.KUnit: success " Patchwork
2025-02-21 11:43 ` ✓ CI.Build: " Patchwork
2025-02-21 11:46 ` ✓ CI.Hooks: " Patchwork
2025-02-21 11:47 ` ✓ CI.checksparse: " Patchwork
2025-02-21 12:07 ` ✓ Xe.CI.BAT: " Patchwork
2025-02-22  1:54 ` ✗ Xe.CI.Full: failure " Patchwork

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=Z7jXVEvzltlnIUvn@orsosgc001 \
    --to=umesh.nerlige.ramappa@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=riana.tauro@intel.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