Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "José Roberto de Souza" <jose.souza@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "José Roberto de Souza" <jose.souza@intel.com>
Subject: [PATCH 3/3] drm/xe/oa: Destroy dangling oa streams when xe_file is removed
Date: Thu, 15 Aug 2024 09:27:58 -0700	[thread overview]
Message-ID: <20240815162758.36495-3-jose.souza@intel.com> (raw)
In-Reply-To: <20240815162758.36495-1-jose.souza@intel.com>

If an application opens an oa stream and for whatever reason it don't
close the stream the oa unit associeted with it will never be release,
so no other application can use it.
The only workaround was to unload the driver or reboot.

So here adding a list of oa stream and and when a xe_file is closed
it will also destroy all oa stream with the same xe_file.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
---
 drivers/gpu/drm/xe/xe_device.c   |  2 ++
 drivers/gpu/drm/xe/xe_oa.c       | 28 +++++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_oa.h       |  1 +
 drivers/gpu/drm/xe/xe_oa_types.h |  8 ++++++++
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 2063283871503..b098685ed3636 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -158,6 +158,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
 
 	xe_pm_runtime_get(xe);
 
+	xe_oa_file_destroy_stream(xef);
+
 	/*
 	 * No need for exec_queue.lock here as there is no contention for it
 	 * when FD is closing as IOCTLs presumably can't be modifying the
diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 4be722b92f90b..4a01a928dd8ee 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -70,6 +70,7 @@ struct flex {
 };
 
 struct xe_oa_open_param {
+	struct xe_file *xef;
 	u32 oa_unit_id;
 	bool sample;
 	u32 metric_set;
@@ -839,6 +840,9 @@ static void xe_oa_stream_destroy(struct xe_oa_stream *stream)
 		xe_gt_WARN_ON(gt, xe_guc_pc_unset_gucrc_mode(&gt->uc.guc.pc));
 
 	xe_oa_free_configs(stream);
+
+	lockdep_assert_held(&stream->oa->streams_lock);
+	list_del(&stream->list_node);
 }
 
 static int xe_oa_alloc_oa_buffer(struct xe_oa_stream *stream)
@@ -1480,11 +1484,15 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,
 		goto exit;
 	}
 
+	stream->xef = param->xef;
 	stream->oa = oa;
 	ret = xe_oa_stream_init(stream, param);
 	if (ret)
 		goto err_free;
 
+	lockdep_assert_held(&oa->streams_lock);
+	list_add(&stream->list_node, &oa->streams);
+
 	if (!param->disabled) {
 		ret = xe_oa_enable_locked(stream);
 		if (ret)
@@ -1797,7 +1805,9 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *f
 	struct xe_device *xe = to_xe_device(dev);
 	struct xe_oa *oa = &xe->oa;
 	struct xe_file *xef = to_xe_file(file);
-	struct xe_oa_open_param param = {};
+	struct xe_oa_open_param param = {
+		.xef = xef,
+	};
 	const struct xe_oa_format *f;
 	bool privileged_op = true;
 	int ret;
@@ -2470,6 +2480,7 @@ int xe_oa_init(struct xe_device *xe)
 	oa->xe = xe;
 	oa->oa_formats = oa_formats;
 
+	INIT_LIST_HEAD(&oa->streams);
 	mutex_init(&oa->streams_lock);
 
 	drmm_mutex_init(&oa->xe->drm, &oa->metrics_lock);
@@ -2511,3 +2522,18 @@ void xe_oa_fini(struct xe_device *xe)
 	mutex_destroy(&oa->streams_lock);
 	oa->xe = NULL;
 }
+
+void
+xe_oa_file_destroy_stream(struct xe_file *xef)
+{
+	struct xe_device *xe = xef->xe;
+	struct xe_oa *oa = &xe->oa;
+	struct xe_oa_stream *stream, *n;
+
+	mutex_lock(&oa->streams_lock);
+	list_for_each_entry_safe(stream, n, &oa->streams, list_node) {
+		if (stream->xef == xef)
+			xe_oa_destroy_locked(stream);
+	}
+	mutex_unlock(&oa->streams_lock);
+}
diff --git a/drivers/gpu/drm/xe/xe_oa.h b/drivers/gpu/drm/xe/xe_oa.h
index 87a38820c317d..7d6ee9ff89c74 100644
--- a/drivers/gpu/drm/xe/xe_oa.h
+++ b/drivers/gpu/drm/xe/xe_oa.h
@@ -16,6 +16,7 @@ struct xe_hw_engine;
 
 int xe_oa_init(struct xe_device *xe);
 void xe_oa_fini(struct xe_device *xe);
+void xe_oa_file_destroy_stream(struct xe_file *xef);
 void xe_oa_register(struct xe_device *xe);
 void xe_oa_unregister(struct xe_device *xe);
 int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *file);
diff --git a/drivers/gpu/drm/xe/xe_oa_types.h b/drivers/gpu/drm/xe/xe_oa_types.h
index 17e17b5b93640..a035786e101c9 100644
--- a/drivers/gpu/drm/xe/xe_oa_types.h
+++ b/drivers/gpu/drm/xe/xe_oa_types.h
@@ -148,6 +148,8 @@ struct xe_oa {
 	u16 oa_unit_ids;
 
 	struct mutex streams_lock;
+
+	struct list_head streams;
 };
 
 /** @xe_oa_buffer: State of the stream OA buffer */
@@ -178,9 +180,15 @@ struct xe_oa_buffer {
  * struct xe_oa_stream - state for a single open stream FD
  */
 struct xe_oa_stream {
+	/** @node: node of the list of stream  */
+	struct list_head list_node;
+
 	/** @oa: xe_oa backpointer */
 	struct xe_oa *oa;
 
+	/** @xe_file: xe_file that created this stream */
+	struct xe_file *xef;
+
 	/** @gt: gt associated with the oa stream */
 	struct xe_gt *gt;
 
-- 
2.46.0


  parent reply	other threads:[~2024-08-15 16:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-15 16:27 [PATCH 1/3] drm/xe/oa: Replace per GT oa mutex per a global one José Roberto de Souza
2024-08-15 16:27 ` [PATCH 2/3] drm/xe/oa: Remove the drm device reference of oa_stream in xe_oa_destroy_locked() José Roberto de Souza
2024-08-15 16:27 ` José Roberto de Souza [this message]
2024-08-15 18:17   ` [PATCH 3/3] drm/xe/oa: Destroy dangling oa streams when xe_file is removed Lucas De Marchi
2024-08-15 20:40     ` Dixit, Ashutosh
2024-08-15 16:33 ` ✓ CI.Patch_applied: success for series starting with [1/3] drm/xe/oa: Replace per GT oa mutex per a global one Patchwork
2024-08-15 16:33 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-15 16:34 ` ✓ CI.KUnit: success " Patchwork
2024-08-15 16:42 ` [PATCH 1/3] " Matthew Brost
2024-08-15 21:11   ` Dixit, Ashutosh
2024-08-15 16:46 ` ✓ CI.Build: success for series starting with [1/3] " Patchwork
2024-08-15 16:48 ` ✗ CI.Hooks: failure " Patchwork
2024-08-15 16:50 ` ✓ CI.checksparse: success " Patchwork
2024-08-15 17:34 ` ✗ CI.BAT: failure " Patchwork
2024-08-15 18:31 ` ✗ CI.FULL: " 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=20240815162758.36495-3-jose.souza@intel.com \
    --to=jose.souza@intel.com \
    --cc=intel-xe@lists.freedesktop.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