Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Laguna <lukasz.laguna@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: mauro.chehab@intel.com
Subject: [igt-dev] [PATCH i-g-t v2] lib/xe_query: add helper getting available VRAM
Date: Thu,  3 Aug 2023 13:42:32 +0200	[thread overview]
Message-ID: <20230803114232.15120-1-lukasz.laguna@intel.com> (raw)

Helper allows to read available VRAM of a specified device and GT.

v2:
- Query for current memory usage instead of using cached one (Zbigniew)

Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
---
 lib/xe/xe_query.c | 30 ++++++++++++++++++++++++++++++
 lib/xe/xe_query.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 8963c7b06..ef515b088 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -630,6 +630,36 @@ uint64_t xe_visible_vram_size(int fd, int gt)
 
 	return visible_size;
 }
+/**
+ * xe_vram_available:
+ * @fd: xe device fd
+ * @gt: gt
+ *
+ * Returns available vram of xe device @fd and @gt.
+ */
+uint64_t xe_vram_available(int fd, int gt)
+{
+	struct xe_device *xe_dev;
+	int region_idx;
+	struct drm_xe_query_mem_region *mem_region;
+
+	xe_dev = find_in_cache(fd);
+	igt_assert(xe_dev);
+
+	region_idx = ffs(native_region_for_gt(xe_dev->gts, gt)) - 1;
+	mem_region = &xe_dev->mem_usage->regions[region_idx];
+
+	if (XE_IS_CLASS_VRAM(mem_region)) {
+		pthread_mutex_lock(&cache.cache_mutex);
+		free(xe_dev->mem_usage);
+		xe_dev->mem_usage = xe_query_mem_usage_new(fd);
+		pthread_mutex_unlock(&cache.cache_mutex);
+
+		return mem_region->total_size - mem_region->used;
+	}
+
+	return 0;
+}
 
 /**
  * xe_get_default_alignment:
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index 1b74c58ab..20dbfa12c 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -97,6 +97,7 @@ unsigned int xe_number_hw_engines(int fd);
 bool xe_has_vram(int fd);
 uint64_t xe_vram_size(int fd, int gt);
 uint64_t xe_visible_vram_size(int fd, int gt);
+uint64_t xe_vram_available(int fd, int gt);
 uint32_t xe_get_default_alignment(int fd);
 uint32_t xe_va_bits(int fd);
 uint16_t xe_dev_id(int fd);
-- 
2.40.0

             reply	other threads:[~2023-08-03 11:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 11:42 Lukasz Laguna [this message]
2023-08-03 11:46 ` [igt-dev] ✗ GitLab.Pipeline: warning for lib/xe_query: add helper getting available VRAM (rev2) Patchwork
2023-08-03 12:18 ` [igt-dev] ○ CI.xeBAT: info " Patchwork
2023-08-03 12:27 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2023-08-03 17:40 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-08-03 20:20 ` [igt-dev] [PATCH i-g-t v2] lib/xe_query: add helper getting available VRAM Zbigniew Kempczyński

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=20230803114232.15120-1-lukasz.laguna@intel.com \
    --to=lukasz.laguna@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=mauro.chehab@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