public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 7/8] drm/i915: Track imported dma-buf objects in memory stats
Date: Fri,  9 Jun 2023 13:11:42 +0100	[thread overview]
Message-ID: <20230609121143.1232420-8-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

We want to be able to show memory usage of imported dma-buf opjects in the
fdinfo stats.

To achieve this we wrap drm_gem_prime_fd_to_handle(_obj) in
i915_gem_prime_fd_to_handle and append some client management at the end.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 32 ++++++++++++++++++++++
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h |  7 +++++
 drivers/gpu/drm/i915/i915_driver.c         |  2 +-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index fd556a076d05..2e2d9d7c1992 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -11,7 +11,10 @@
 
 #include <asm/smp.h>
 
+#include <drm/drm_file.h>
+
 #include "gem/i915_gem_dmabuf.h"
+#include "i915_drm_client.h"
 #include "i915_drv.h"
 #include "i915_gem_object.h"
 #include "i915_scatterlist.h"
@@ -344,6 +347,35 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
 	return ERR_PTR(ret);
 }
 
+int i915_gem_prime_fd_to_handle(struct drm_device *dev,
+				struct drm_file *file_priv, int prime_fd,
+				uint32_t *handle)
+{
+	struct drm_gem_object *gem_obj = NULL;
+	int ret;
+
+	if (IS_ENABLED(CONFIG_PROC_FS))
+		ret = drm_gem_prime_fd_to_handle_obj(dev, file_priv, prime_fd,
+						     handle, &gem_obj);
+	else
+		ret = drm_gem_prime_fd_to_handle(dev, file_priv, prime_fd,
+						 handle);
+	if (ret)
+		return ret;
+
+	if (gem_obj) {
+		struct drm_i915_file_private *fpriv = file_priv->driver_priv;
+		struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
+
+		/* Really imported and not just alias? */
+		if (obj->ops == &i915_gem_object_dmabuf_ops)
+			i915_drm_client_add_object(fpriv->client, obj);
+		i915_gem_object_put(obj);
+	}
+
+	return 0;
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftests/mock_dmabuf.c"
 #include "selftests/i915_gem_dmabuf.c"
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h
index 6e0405d47ce1..63635c221c7c 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h
@@ -6,8 +6,11 @@
 #ifndef __I915_GEM_DMABUF_H__
 #define __I915_GEM_DMABUF_H__
 
+#include <linux/types.h>
+
 struct drm_gem_object;
 struct drm_device;
+struct drm_file;
 struct dma_buf;
 
 struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
@@ -15,4 +18,8 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
 
 struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags);
 
+int i915_gem_prime_fd_to_handle(struct drm_device *dev,
+				struct drm_file *file_priv, int prime_fd,
+				uint32_t *handle);
+
 #endif /* __I915_GEM_DMABUF_H__ */
diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c
index ace8534b6cc5..03f3157371bf 100644
--- a/drivers/gpu/drm/i915/i915_driver.c
+++ b/drivers/gpu/drm/i915/i915_driver.c
@@ -1806,7 +1806,7 @@ static const struct drm_driver i915_drm_driver = {
 	.show_fdinfo = i915_drm_client_fdinfo,
 
 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
-	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+	.prime_fd_to_handle = i915_gem_prime_fd_to_handle,
 	.gem_prime_import = i915_gem_prime_import,
 
 	.dumb_create = i915_gem_dumb_create,
-- 
2.39.2


  parent reply	other threads:[~2023-06-09 12:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 12:11 [Intel-gfx] [PATCH v3 0/8] fdinfo memory stats Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 1/8] dma-fence: Bypass signaling annotation from dma_fence_is_signaled Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 2/8] drm/i915: Track buffer objects belonging to clients Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 3/8] drm/i915: Record which clients own a VM Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 4/8] drm/i915: Track page table backing store usage Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 5/8] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 6/8] drm: Add drm_gem_prime_fd_to_handle_obj Tvrtko Ursulin
2023-06-09 12:44   ` Iddamsetty, Aravind
2023-06-09 14:12     ` Tvrtko Ursulin
2023-06-09 17:09       ` Rob Clark
2023-06-12  8:26         ` Tvrtko Ursulin
2023-06-09 12:11 ` Tvrtko Ursulin [this message]
2023-06-09 12:11 ` [Intel-gfx] [PATCH 8/8] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin
2023-06-09 12:48 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for fdinfo memory stats (rev2) Patchwork
2023-06-09 12:48 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-06-09 17:47 ` [Intel-gfx] ✗ Fi.CI.BAT: 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=20230609121143.1232420-8-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=dri-devel@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