All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v31 38/40] lib/intel_allocator: Add alloc function which allows passing strategy argument
Date: Mon, 12 Apr 2021 12:31:45 +0200	[thread overview]
Message-ID: <20210412103147.61299-39-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20210412103147.61299-1-zbigniew.kempczynski@intel.com>

To use spinners with no-reloc we need to alloc offsets for them
from already opened allocator. As we don't know what strategy
is chosen for open (likely HIGH_TO_LOW for SIMPLE allocator) we
want to overwrite it for spinners (there's expectation they
will reside on low addresses).

Extend allocator API adding intel_allocator_alloc_with_strategy()
to support spinners rewriting.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Jason Ekstrand <jason@jlekstrand.net>
---
 lib/intel_allocator.c            | 47 +++++++++++++++++++++++++++-----
 lib/intel_allocator.h            | 10 +++++--
 lib/intel_allocator_msgchannel.h |  1 +
 lib/intel_allocator_random.c     |  4 ++-
 lib/intel_allocator_reloc.c      |  4 ++-
 lib/intel_allocator_simple.c     | 39 ++++++++++++++------------
 6 files changed, 76 insertions(+), 29 deletions(-)

diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
index 0b33b8b24..8a2e607c3 100644
--- a/lib/intel_allocator.c
+++ b/lib/intel_allocator.c
@@ -579,15 +579,17 @@ static int handle_request(struct alloc_req *req, struct alloc_resp *resp)
 			resp->alloc.offset = ial->alloc(ial,
 							req->alloc.handle,
 							req->alloc.size,
-							req->alloc.alignment);
+							req->alloc.alignment,
+							req->alloc.strategy);
 			alloc_info("<alloc> [tid: %ld] ahnd: %" PRIx64
 				   ", ctx: %u, vm: %u, handle: %u"
 				   ", size: 0x%" PRIx64 ", offset: 0x%" PRIx64
-				   ", alignment: 0x%" PRIx64 "\n",
+				   ", alignment: 0x%" PRIx64 ", strategy: %u\n",
 				   (long) req->tid, req->allocator_handle,
 				   al->ctx, al->vm,
 				   req->alloc.handle, req->alloc.size,
-				   resp->alloc.offset, req->alloc.alignment);
+				   resp->alloc.offset, req->alloc.alignment,
+				   req->alloc.strategy);
 			break;
 
 		case REQ_FREE:
@@ -1040,13 +1042,15 @@ void intel_allocator_get_address_range(uint64_t allocator_handle,
  * range returns ALLOC_INVALID_ADDRESS.
  */
 uint64_t __intel_allocator_alloc(uint64_t allocator_handle, uint32_t handle,
-				 uint64_t size, uint64_t alignment)
+				 uint64_t size, uint64_t alignment,
+				 enum allocator_strategy strategy)
 {
 	struct alloc_req req = { .request_type = REQ_ALLOC,
 				 .allocator_handle = allocator_handle,
 				 .alloc.handle = handle,
 				 .alloc.size = size,
-				 .alloc.alignment = alignment };
+				 .alloc.alignment = alignment,
+				 .alloc.strategy = strategy };
 	struct alloc_resp resp;
 
 	igt_assert(handle_request(&req, &resp) == 0);
@@ -1063,7 +1067,8 @@ uint64_t __intel_allocator_alloc(uint64_t allocator_handle, uint32_t handle,
  * @alignment: determines object alignment
  *
  * Same as __intel_allocator_alloc() but asserts if allocator can't return
- * valid address.
+ * valid address. Uses default allocation strategy chosen during opening
+ * the allocator.
  */
 uint64_t intel_allocator_alloc(uint64_t allocator_handle, uint32_t handle,
 			       uint64_t size, uint64_t alignment)
@@ -1071,12 +1076,40 @@ uint64_t intel_allocator_alloc(uint64_t allocator_handle, uint32_t handle,
 	uint64_t offset;
 
 	offset = __intel_allocator_alloc(allocator_handle, handle,
-					 size, alignment);
+					 size, alignment,
+					 ALLOC_STRATEGY_NONE);
 	igt_assert(offset != ALLOC_INVALID_ADDRESS);
 
 	return offset;
 }
 
+/**
+ * intel_allocator_alloc_with_strategy:
+ * @allocator_handle: handle to an allocator
+ * @handle: handle to an object
+ * @size: size of an object
+ * @alignment: determines object alignment
+ * @strategy: strategy of allocation
+ *
+ * Same as __intel_allocator_alloc() but asserts if allocator can't return
+ * valid address. Use @strategy instead of default chosen during opening
+ * the allocator.
+ */
+uint64_t intel_allocator_alloc_with_strategy(uint64_t allocator_handle,
+					     uint32_t handle,
+					     uint64_t size, uint64_t alignment,
+					     enum allocator_strategy strategy)
+{
+	uint64_t offset;
+
+	offset = __intel_allocator_alloc(allocator_handle, handle,
+					 size, alignment, strategy);
+	igt_assert(offset != ALLOC_INVALID_ADDRESS);
+
+	return offset;
+}
+
+
 /**
  * intel_allocator_free:
  * @allocator_handle: handle to an allocator
diff --git a/lib/intel_allocator.h b/lib/intel_allocator.h
index 9b7bd0908..c14f57b4d 100644
--- a/lib/intel_allocator.h
+++ b/lib/intel_allocator.h
@@ -141,7 +141,8 @@ struct intel_allocator {
 	void (*get_address_range)(struct intel_allocator *ial,
 				  uint64_t *startp, uint64_t *endp);
 	uint64_t (*alloc)(struct intel_allocator *ial, uint32_t handle,
-			  uint64_t size, uint64_t alignment);
+			  uint64_t size, uint64_t alignment,
+			  enum allocator_strategy strategy);
 	bool (*is_allocated)(struct intel_allocator *ial, uint32_t handle,
 			     uint64_t size, uint64_t alignment);
 	bool (*reserve)(struct intel_allocator *ial,
@@ -181,9 +182,14 @@ bool intel_allocator_close(uint64_t allocator_handle);
 void intel_allocator_get_address_range(uint64_t allocator_handle,
 				       uint64_t *startp, uint64_t *endp);
 uint64_t __intel_allocator_alloc(uint64_t allocator_handle, uint32_t handle,
-				 uint64_t size, uint64_t alignment);
+				 uint64_t size, uint64_t alignment,
+				 enum allocator_strategy strategy);
 uint64_t intel_allocator_alloc(uint64_t allocator_handle, uint32_t handle,
 			       uint64_t size, uint64_t alignment);
+uint64_t intel_allocator_alloc_with_strategy(uint64_t allocator_handle,
+					     uint32_t handle,
+					     uint64_t size, uint64_t alignment,
+					     enum allocator_strategy strategy);
 bool intel_allocator_free(uint64_t allocator_handle, uint32_t handle);
 bool intel_allocator_is_allocated(uint64_t allocator_handle, uint32_t handle,
 				  uint64_t size, uint64_t offset);
diff --git a/lib/intel_allocator_msgchannel.h b/lib/intel_allocator_msgchannel.h
index ac6edfb9e..c7a738a08 100644
--- a/lib/intel_allocator_msgchannel.h
+++ b/lib/intel_allocator_msgchannel.h
@@ -65,6 +65,7 @@ struct alloc_req {
 			uint32_t handle;
 			uint64_t size;
 			uint64_t alignment;
+			uint8_t strategy;
 		} alloc;
 
 		struct {
diff --git a/lib/intel_allocator_random.c b/lib/intel_allocator_random.c
index d804e3318..3d9a78f17 100644
--- a/lib/intel_allocator_random.c
+++ b/lib/intel_allocator_random.c
@@ -45,12 +45,14 @@ static void intel_allocator_random_get_address_range(struct intel_allocator *ial
 
 static uint64_t intel_allocator_random_alloc(struct intel_allocator *ial,
 					     uint32_t handle, uint64_t size,
-					     uint64_t alignment)
+					     uint64_t alignment,
+					     enum allocator_strategy strategy)
 {
 	struct intel_allocator_random *ialr = ial->priv;
 	uint64_t offset;
 
 	(void) handle;
+	(void) strategy;
 
 	/* randomize the address, we try to avoid relocations */
 	do {
diff --git a/lib/intel_allocator_reloc.c b/lib/intel_allocator_reloc.c
index abf9c30cd..e8af787b0 100644
--- a/lib/intel_allocator_reloc.c
+++ b/lib/intel_allocator_reloc.c
@@ -46,12 +46,14 @@ static void intel_allocator_reloc_get_address_range(struct intel_allocator *ial,
 
 static uint64_t intel_allocator_reloc_alloc(struct intel_allocator *ial,
 					    uint32_t handle, uint64_t size,
-					    uint64_t alignment)
+					    uint64_t alignment,
+					    enum allocator_strategy strategy)
 {
 	struct intel_allocator_reloc *ialr = ial->priv;
 	uint64_t offset, aligned_offset;
 
 	(void) handle;
+	(void) strategy;
 
 	alignment = max(alignment, 4096);
 	aligned_offset = ALIGN(ialr->offset, alignment);
diff --git a/lib/intel_allocator_simple.c b/lib/intel_allocator_simple.c
index a419955af..963d8d257 100644
--- a/lib/intel_allocator_simple.c
+++ b/lib/intel_allocator_simple.c
@@ -25,12 +25,7 @@ intel_allocator_simple_create_full(int fd, uint64_t start, uint64_t end,
 
 struct simple_vma_heap {
 	struct igt_list_head holes;
-
-	/* If true, simple_vma_heap_alloc will prefer high addresses
-	 *
-	 * Default is true.
-	 */
-	bool alloc_high;
+	enum allocator_strategy strategy;
 };
 
 struct simple_vma_hole {
@@ -220,14 +215,11 @@ static void simple_vma_heap_init(struct simple_vma_heap *heap,
 	IGT_INIT_LIST_HEAD(&heap->holes);
 	simple_vma_heap_free(heap, start, size);
 
-	switch (strategy) {
-	case ALLOC_STRATEGY_LOW_TO_HIGH:
-		heap->alloc_high = false;
-		break;
-	case ALLOC_STRATEGY_HIGH_TO_LOW:
-	default:
-		heap->alloc_high = true;
-	}
+	/* Use LOW_TO_HIGH or HIGH_TO_LOW strategy only */
+	if (strategy == ALLOC_STRATEGY_LOW_TO_HIGH)
+		heap->strategy = strategy;
+	else
+		heap->strategy = ALLOC_STRATEGY_HIGH_TO_LOW;
 }
 
 static void simple_vma_heap_finish(struct simple_vma_heap *heap)
@@ -294,7 +286,8 @@ static void simple_vma_hole_alloc(struct simple_vma_hole *hole,
 
 static bool simple_vma_heap_alloc(struct simple_vma_heap *heap,
 				  uint64_t *offset, uint64_t size,
-				  uint64_t alignment)
+				  uint64_t alignment,
+				  enum allocator_strategy strategy)
 {
 	struct simple_vma_hole *hole, *tmp;
 	uint64_t misalign;
@@ -305,7 +298,16 @@ static bool simple_vma_heap_alloc(struct simple_vma_heap *heap,
 
 	simple_vma_heap_validate(heap);
 
-	if (heap->alloc_high) {
+	/* Ensure we support only NONE/LOW_TO_HIGH/HIGH_TO_LOW strategies */
+	igt_assert(strategy == ALLOC_STRATEGY_NONE ||
+		   strategy == ALLOC_STRATEGY_LOW_TO_HIGH ||
+		   strategy == ALLOC_STRATEGY_HIGH_TO_LOW);
+
+	/* Use default strategy chosen on open */
+	if (strategy == ALLOC_STRATEGY_NONE)
+		strategy = heap->strategy;
+
+	if (strategy == ALLOC_STRATEGY_HIGH_TO_LOW) {
 		simple_vma_foreach_hole_safe(hole, heap, tmp) {
 			if (size > hole->size)
 				continue;
@@ -412,7 +414,8 @@ static bool simple_vma_heap_alloc_addr(struct intel_allocator_simple *ials,
 
 static uint64_t intel_allocator_simple_alloc(struct intel_allocator *ial,
 					     uint32_t handle, uint64_t size,
-					     uint64_t alignment)
+					     uint64_t alignment,
+					     enum allocator_strategy strategy)
 {
 	struct intel_allocator_record *rec;
 	struct intel_allocator_simple *ials;
@@ -430,7 +433,7 @@ static uint64_t intel_allocator_simple_alloc(struct intel_allocator *ial,
 		igt_assert(rec->size == size);
 	} else {
 		if (!simple_vma_heap_alloc(&ials->heap, &offset,
-					   size, alignment))
+					   size, alignment, strategy))
 			return ALLOC_INVALID_ADDRESS;
 
 		rec = malloc(sizeof(*rec));
-- 
2.26.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2021-04-12 10:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12 10:31 [igt-dev] [PATCH i-g-t v31 00/40] Introduce IGT allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 01/40] lib/igt_list: Add igt_list_del_init() Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 02/40] lib/igt_list: Add igt_list_for_each_entry_safe_reverse Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 03/40] lib/igt_map: Adopt Mesa hash table Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 04/40] lib/igt_core: Track child process pid and tid Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 05/40] lib/intel_allocator_simple: Add simple allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 06/40] lib/intel_allocator_reloc: Add reloc allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 07/40] lib/intel_allocator_random: Add random allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 08/40] lib/intel_allocator: Add intel_allocator core Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 09/40] lib/intel_allocator: Try to stop smoothly instead of deinit Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 10/40] lib/intel_allocator_msgchannel: Scale to 4k of parallel clients Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 11/40] lib/intel_allocator: Separate allocator multiprocess start Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 12/40] lib/intel_bufops: Change size from 32->64 bit Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 13/40] lib/intel_bufops: Add init with handle and size function Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 14/40] lib/intel_batchbuffer: Integrate intel_bb with allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 15/40] lib/intel_batchbuffer: Use relocations in intel-bb up to gen12 Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 16/40] lib/intel_batchbuffer: Create bb with strategy / vm ranges Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 17/40] lib/intel_batchbuffer: Add tracking intel_buf to intel_bb Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 18/40] lib/intel_batchbuffer: Don't collect relocations for newer gens Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 19/40] lib/igt_fb: Initialize intel_buf with same size as fb Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 20/40] tests/api_intel_bb: Remove check-canonical test Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 21/40] tests/api_intel_bb: Modify test to verify intel_bb with allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 22/40] tests/api_intel_bb: Add compressed->compressed copy Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 23/40] tests/api_intel_bb: Add purge-bb test Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 24/40] tests/api_intel_bb: Add simple intel-bb which uses allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 25/40] tests/api_intel_bb: Use allocator in delta-check test Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 26/40] tests/api_intel_bb: Check switching vm in intel-bb Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 27/40] tests/api_intel_allocator: Simple allocator test suite Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 28/40] tests/api_intel_allocator: Add execbuf with allocator example Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 29/40] tests/api_intel_allocator: Verify child can use its standalone allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 30/40] tests/gem_softpin: Verify allocator and execbuf pair work together Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 31/40] tests/gem|kms: Remove intel_bb from fixture Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 32/40] tests/gem_mmap_offset: Use intel_buf wrapper code instead direct Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 33/40] tests/gem_ppgtt: Adopt test to use intel_bb with allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 34/40] tests/gem_render_copy_redux: Adopt to use with intel_bb and allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 35/40] tests/perf.c: Remove buffer from batch Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 36/40] tests/gem_linear_blits: Use intel allocator Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 37/40] lib/intel_allocator: drop kill_children() Zbigniew Kempczyński
2021-04-12 10:31 ` Zbigniew Kempczyński [this message]
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 39/40] tests/api_intel_allocator: Check alloc with strategy API Zbigniew Kempczyński
2021-04-12 10:31 ` [igt-dev] [PATCH i-g-t v31 40/40] lib/intel_allocator: Wait for allocator thread to be ready Zbigniew Kempczyński
2021-04-12 10:59 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Introduce IGT allocator (rev34) 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=20210412103147.61299-39-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.