Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: chris.p.wilson@linux.intel.com, jonathan.cavitt@intel.com
Subject: [igt-dev] [PATCH i-g-t 1/1] lib/intel_allocator: Query exact gtt size
Date: Thu, 14 Sep 2023 10:23:32 -0700	[thread overview]
Message-ID: <20230914172332.2322524-2-jonathan.cavitt@intel.com> (raw)
In-Reply-To: <20230914172332.2322524-1-jonathan.cavitt@intel.com>

Use the gem_context_get_param functionality to query the exact gtt size
for each vm in the intel_allocator.  This replaces the fixed declaration
using the GEN8_GTT_ADDRESS_WIDTH.

Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Suggested-by: Chris Wilson <chris.p.wilson@linux.intel.com>
---
 lib/intel_allocator.h        | 11 +++++++++++
 lib/intel_allocator_simple.c | 10 +++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/lib/intel_allocator.h b/lib/intel_allocator.h
index f9ff7f1cc9..cfe20bf8aa 100644
--- a/lib/intel_allocator.h
+++ b/lib/intel_allocator.h
@@ -12,6 +12,7 @@
 #include <stdint.h>
 #include <stdatomic.h>
 #include "i915/gem_submission.h"
+#include "i915/gem_context.h"
 #include "intel_reg.h"
 
 /**
@@ -275,6 +276,16 @@ static inline uint64_t get_offset(uint64_t ahnd, uint32_t handle,
 	return intel_allocator_alloc(ahnd, handle, size, alignment);
 }
 
+static inline uint64_t get_gtt_size(int fd)
+{
+	struct drm_i915_gem_context_param p = {
+		.param = I915_CONTEXT_PARAM_GTT_SIZE
+	};
+
+	gem_context_get_param(fd, &p);
+	return p.value;
+}
+
 static inline bool put_offset(uint64_t ahnd, uint32_t handle)
 {
 	if (!ahnd)
diff --git a/lib/intel_allocator_simple.c b/lib/intel_allocator_simple.c
index 3d5e45870e..137885a88b 100644
--- a/lib/intel_allocator_simple.c
+++ b/lib/intel_allocator_simple.c
@@ -459,9 +459,9 @@ static bool intel_allocator_simple_is_allocated(struct intel_allocator *ial,
 	return same;
 }
 
-static uint64_t get_size(uint64_t start, uint64_t end)
+static uint64_t get_size(int fd, uint64_t start, uint64_t end)
 {
-	end = end ? end : 1ull << GEN8_GTT_ADDRESS_WIDTH;
+	end = end ? end : get_gtt_size(fd);
 
 	return end - start;
 }
@@ -485,7 +485,7 @@ static bool intel_allocator_simple_reserve(struct intel_allocator *ial,
 	start = DECANONICAL(start);
 	end = DECANONICAL(end);
 	igt_assert(end > start || end == 0);
-	size = get_size(start, end);
+	size = get_size(ial->fd, start, end);
 	igt_assert(start + size <= ials->end);
 	igt_assert(start >= ials->start);
 
@@ -526,7 +526,7 @@ static bool intel_allocator_simple_unreserve(struct intel_allocator *ial,
 	start = DECANONICAL(start);
 	end = DECANONICAL(end);
 	igt_assert(end > start || end == 0);
-	size = get_size(start, end);
+	size = get_size(ial->fd, start, end);
 
 	entry = igt_map_search_entry(ials->reserved, &start);
 
@@ -574,7 +574,7 @@ static bool intel_allocator_simple_is_reserved(struct intel_allocator *ial,
 	start = DECANONICAL(start);
 	end = DECANONICAL(end);
 	igt_assert(end > start || end == 0);
-	size = get_size(start, end);
+	size = get_size(ial->fd, start, end);
 
 	rec = igt_map_search(ials->reserved, &start);
 
-- 
2.25.1

  reply	other threads:[~2023-09-14 17:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14 17:23 [igt-dev] [PATCH i-g-t 0/1] lib/intel_allocator: Query exact gtt size Jonathan Cavitt
2023-09-14 17:23 ` Jonathan Cavitt [this message]
2023-09-18  7:39   ` [igt-dev] [PATCH i-g-t 1/1] " Zbigniew Kempczyński
2023-09-14 18:48 ` [igt-dev] ✗ CI.xeBAT: failure for " Patchwork
2023-09-14 18:53 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2023-09-15  0:51 ` [igt-dev] ✗ Fi.CI.IGT: 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=20230914172332.2322524-2-jonathan.cavitt@intel.com \
    --to=jonathan.cavitt@intel.com \
    --cc=chris.p.wilson@linux.intel.com \
    --cc=igt-dev@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