Skip to contentSkip to conversation

lib/xe_query: add helper getting available VRAM

PATCH In review Lukasz Laguna 3 participants 4 messages Aug 4, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 lib/xe_query: add helper getting available VRAM

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

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

---
 lib/xe/xe_query.c | 31 +++++++++++++++++++++++++++++++
 lib/xe/xe_query.h |  1 +
 2 files changed, 32 insertions(+)
lib/xe/xe_query.c +31 -0
index 8963c7b06..e1fe6139c 100644
@@ -630,6 +630,37 @@ 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);
+		mem_region = &xe_dev->mem_usage->regions[region_idx];
+
+		return mem_region->total_size - mem_region->used;
+	}
+
+	return 0;
+}
 
 /**
  * xe_get_default_alignment:
lib/xe/xe_query.h +1 -0
index 1b74c58ab..20dbfa12c 100644
@@ -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);
Signature · 1 line
2.40.0
#1 lore raw
Quoted 36 lines · Lukasz Laguna

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

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

---
 lib/xe/xe_query.c | 31 +++++++++++++++++++++++++++++++
 lib/xe/xe_query.h |  1 +
 2 files changed, 32 insertions(+)
lib/xe/xe_query.c +15 -0
index 8963c7b06..e1fe6139c 100644
@@ -630,6 +630,37 @@ 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);

lib/xe/xe_query.c uint64_t xe_visible_vram_size(int fd, int gt) · line 657

Quoted 10 lines
lib/xe/xe_query.c +10 -0
+
+	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);
+		mem_region = &xe_dev->mem_usage->regions[region_idx];

What if other thread in the meantime will call xe_vram_available()? xe_dev->mem_usage might be not valid pointer at the moment.

I think reacquiring and mem_region->total_size - mem_region->used should also be protected in this critical section. Likely you need to introduce additional variable which contain this subtraction when you'll leave this section.

--
Zbigniew

Quoted 24 lines
lib/xe/xe_query.c +6 -0
+
+		return mem_region->total_size - mem_region->used;
+	}
+
+	return 0;
+}
 
 /**
  * xe_get_default_alignment:
lib/xe/xe_query.h +1 -0
index 1b74c58ab..20dbfa12c 100644
@@ -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);
Signature · 1 line
2.40.0
#2 lore raw

[igt-dev] ✗ Fi.CI.BAT: failure for lib/xe_query: add helper getting available VRAM (rev3)

In reply to Lukasz Laguna
== Series Details ==

== Series Details ==

Series: lib/xe_query: add helper getting available VRAM (rev3)
URL : https://patchwork.freedesktop.org/series/121704/
State : failure

== Summary ==

CI Bug Log - changes from IGT_7414 -> IGTPW_9514
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with IGTPW_9514 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in IGTPW_9514, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/index.html

Participating hosts (42 -> 42)
------------------------------

Additional (1): fi-kbl-soraka
Missing (1): fi-snb-2520m

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in IGTPW_9514:

### IGT changes ###

#### Possible regressions ####

* igt@kms_flip@basic-flip-vs-dpms:
- fi-kbl-soraka: NOTRUN -> [INCOMPLETE][1]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/fi-kbl-soraka/igt@[email protected]

#### Warnings ####

* igt@i915_pm_rpm@basic-pci-d3-state:
- bat-adlp-9: [FAIL][2] ([i915#7940]) -> [FAIL][3]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_7414/bat-adlp-9/igt@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/bat-adlp-9/igt@[email protected]

Known issues
------------

Here are the changes found in IGTPW_9514 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_huc_copy@huc-copy:
- fi-kbl-soraka: NOTRUN -> [SKIP][4] ([fdo#109271] / [i915#2190])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/fi-kbl-soraka/igt@[email protected]

* igt@gem_lmem_swapping@basic:
- fi-kbl-soraka: NOTRUN -> [SKIP][5] ([fdo#109271] / [i915#4613]) +3 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/fi-kbl-soraka/igt@[email protected]

* igt@i915_pm_rpm@module-reload:
- fi-rkl-11600: [PASS][6] -> [FAIL][7] ([i915#7940])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_7414/fi-rkl-11600/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/fi-rkl-11600/igt@[email protected]

* igt@i915_selftest@live@gt_mocs:
- bat-mtlp-8: [PASS][8] -> [DMESG-FAIL][9] ([i915#7059])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_7414/bat-mtlp-8/igt@i915_selftest@live@gt_mocs.html
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/bat-mtlp-8/igt@i915_selftest@live@gt_mocs.html

* igt@i915_selftest@live@gt_pm:
- fi-kbl-soraka: NOTRUN -> [DMESG-FAIL][10] ([i915#1886] / [i915#7913])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/fi-kbl-soraka/igt@i915_selftest@live@gt_pm.html

* igt@i915_selftest@live@slpc:
- bat-rpls-2: [PASS][11] -> [DMESG-WARN][12] ([i915#6367])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_7414/bat-rpls-2/igt@i915_selftest@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/bat-rpls-2/igt@i915_selftest@[email protected]
- bat-mtlp-8: [PASS][13] -> [DMESG-WARN][14] ([i915#6367])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_7414/bat-mtlp-8/igt@i915_selftest@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/bat-mtlp-8/igt@i915_selftest@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-kbl-soraka: NOTRUN -> [SKIP][15] ([fdo#109271]) +16 similar issues
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/fi-kbl-soraka/igt@[email protected]

#### Warnings ####

* igt@kms_psr@cursor_plane_move:
- bat-rplp-1: [SKIP][16] ([i915#1072]) -> [ABORT][17] ([i915#8434] / [i915#8668])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_7414/bat-rplp-1/igt@kms_psr@cursor_plane_move.html
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/bat-rplp-1/igt@kms_psr@cursor_plane_move.html

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#1886]: https://gitlab.freedesktop.org/drm/intel/issues/1886
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#6367]: https://gitlab.freedesktop.org/drm/intel/issues/6367
[i915#7059]: https://gitlab.freedesktop.org/drm/intel/issues/7059
[i915#7913]: https://gitlab.freedesktop.org/drm/intel/issues/7913
[i915#7940]: https://gitlab.freedesktop.org/drm/intel/issues/7940
[i915#8434]: https://gitlab.freedesktop.org/drm/intel/issues/8434
[i915#8668]: https://gitlab.freedesktop.org/drm/intel/issues/8668

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_7414 -> IGTPW_9514

CI-20190529: 20190529
CI_DRM_13472: 9f699732195d9d8071692f7981e8fe58d51cd024 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_9514: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/index.html
IGT_7414: 056c9d7f2a63dd6d0b9b6462b4ab1b096178dcc6 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_9514/index.html

#3 lore raw

[igt-dev] ○ CI.xeBAT: info for lib/xe_query: add helper getting available VRAM (rev3)

In reply to Lukasz Laguna
== Series Details ==

== Series Details ==

Series: lib/xe_query: add helper getting available VRAM (rev3)
URL : https://patchwork.freedesktop.org/series/121704/
State : info

== Summary ==

Participating hosts:
bat-pvc-2
bat-atsm-2
bat-dg2-oem2
bat-adlp-7
Missing hosts results[0]:
Results: [IGTPW_9514](https://intel-gfx-ci.01.org/tree/intel-xe/IGTPW_9514/index.html)