Skip to content

Commit

Permalink
drm/i915/uapi: expose the avail tracking
Browse files Browse the repository at this point in the history
Vulkan would like to have a rough measure of how much device memory can
in theory be allocated. Also add unallocated_cpu_visible_size to track
the visible portion, in case the device is using small BAR.

Testcase: igt@i915_query@query-regions-unallocated
Testcase: igt@i915_query@query-regions-sanity-check
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Kenneth Graunke <kenneth@whitecape.org>
Cc: Akeem G Abodunrin <akeem.g.abodunrin@intel.com>
  • Loading branch information
matt-auld authored and intel-lab-lkp committed May 25, 2022
1 parent 2d1c55b commit 614521e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
10 changes: 9 additions & 1 deletion drivers/gpu/drm/i915/i915_query.c
Expand Up @@ -502,7 +502,15 @@ static int query_memregion_info(struct drm_i915_private *i915,
else
info.probed_cpu_visible_size = mr->total;

info.unallocated_size = mr->avail;
if (perfmon_capable()) {
intel_memory_region_avail(mr,
&info.unallocated_size,
&info.unallocated_cpu_visible_size);
} else {
info.unallocated_size = info.probed_size;
info.unallocated_cpu_visible_size =
info.probed_cpu_visible_size;
}

if (__copy_to_user(info_ptr, &info, sizeof(info)))
return -EFAULT;
Expand Down
20 changes: 20 additions & 0 deletions drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
Expand Up @@ -365,6 +365,26 @@ u64 i915_ttm_buddy_man_visible_size(struct ttm_resource_manager *man)
return bman->visible_size;
}

/**
* i915_ttm_buddy_man_visible_size - Query the avail tracking for the manager.
*
* @man: The buddy allocator ttm manager
* @avail: The total available memory in pages for the entire manager.
* @visible_avail: The total available memory in pages for the CPU visible
* portion. Note that this will always give the same value as @avail on
* configurations that don't have a small BAR.
*/
void i915_ttm_buddy_man_avail(struct ttm_resource_manager *man,
u64 *avail, u64 *visible_avail)
{
struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);

mutex_lock(&bman->lock);
*avail = bman->mm.avail >> PAGE_SHIFT;
*visible_avail = bman->visible_avail;
mutex_unlock(&bman->lock);
}

#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
void i915_ttm_buddy_man_force_visible_size(struct ttm_resource_manager *man,
u64 size)
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
Expand Up @@ -61,6 +61,9 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,

u64 i915_ttm_buddy_man_visible_size(struct ttm_resource_manager *man);

void i915_ttm_buddy_man_avail(struct ttm_resource_manager *man,
u64 *avail, u64 *avail_visible);

#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
void i915_ttm_buddy_man_force_visible_size(struct ttm_resource_manager *man,
u64 size);
Expand Down
14 changes: 14 additions & 0 deletions drivers/gpu/drm/i915/intel_memory_region.c
Expand Up @@ -279,6 +279,20 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
va_end(ap);
}

void intel_memory_region_avail(struct intel_memory_region *mr,
u64 *avail, u64 *visible_avail)
{
if (mr->type == INTEL_MEMORY_LOCAL) {
i915_ttm_buddy_man_avail(mr->region_private,
avail, visible_avail);
*avail <<= PAGE_SHIFT;
*visible_avail <<= PAGE_SHIFT;
} else {
*avail = mr->total;
*visible_avail = mr->total;
}
}

void intel_memory_region_destroy(struct intel_memory_region *mem)
{
int ret = 0;
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/i915/intel_memory_region.h
Expand Up @@ -127,6 +127,9 @@ int intel_memory_region_reserve(struct intel_memory_region *mem,
void intel_memory_region_debug(struct intel_memory_region *mr,
struct drm_printer *printer);

void intel_memory_region_avail(struct intel_memory_region *mr,
u64 *avail, u64 *visible_avail);

struct intel_memory_region *
i915_gem_ttm_system_setup(struct drm_i915_private *i915,
u16 type, u16 instance);
Expand Down
31 changes: 30 additions & 1 deletion include/uapi/drm/i915_drm.h
Expand Up @@ -3228,7 +3228,15 @@ struct drm_i915_memory_region_info {
*/
__u64 probed_size;

/** @unallocated_size: Estimate of memory remaining (-1 = unknown) */
/**
* @unallocated_size: Estimate of memory remaining (-1 = unknown)
*
* Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable accounting.
* Without this (or if this is an older kernel) the value here will
* always equal the @probed_size. Note this is only currently tracked
* for I915_MEMORY_CLASS_DEVICE regions (for other types the value here
* will always equal the @probed_size).
*/
__u64 unallocated_size;

union {
Expand Down Expand Up @@ -3262,6 +3270,27 @@ struct drm_i915_memory_region_info {
* @probed_size.
*/
__u64 probed_cpu_visible_size;

/**
* @unallocated_cpu_visible_size: Estimate of CPU
* visible memory remaining (-1 = unknown).
*
* Note this is only tracked for
* I915_MEMORY_CLASS_DEVICE regions (for other types the
* value here will always equal the
* @probed_cpu_visible_size).
*
* Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable
* accounting. Without this the value here will always
* equal the @probed_cpu_visible_size. Note this is only
* currently tracked for I915_MEMORY_CLASS_DEVICE
* regions (for other types the value here will also
* always equal the @probed_cpu_visible_size).
*
* If this is an older kernel the value here will be
* zero, see also @probed_cpu_visible_size.
*/
__u64 unallocated_cpu_visible_size;
};
};
};
Expand Down

0 comments on commit 614521e

Please sign in to comment.