From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Subject: [igt-dev] [PATCH i-g-t v10 05/31] lib/intel_allocator_random: Add random allocator
Date: Fri, 20 Nov 2020 12:31:05 +0100 [thread overview]
Message-ID: <20201120113131.67971-6-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20201120113131.67971-1-zbigniew.kempczynski@intel.com>
Sometimes we want to experiment with addresses so randomizing can help
us a little.
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
lib/intel_allocator_random.c | 223 +++++++++++++++++++++++++++++++++++
1 file changed, 223 insertions(+)
create mode 100644 lib/intel_allocator_random.c
diff --git a/lib/intel_allocator_random.c b/lib/intel_allocator_random.c
new file mode 100644
index 00000000..23cf7c4e
--- /dev/null
+++ b/lib/intel_allocator_random.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright © 2020 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include "igt.h"
+#include "igt_x86.h"
+#include "igt_rand.h"
+#include "intel_allocator.h"
+
+struct intel_allocator *intel_allocator_random_create(int fd, uint32_t ctx);
+
+struct intel_allocator_random {
+ uint64_t bias;
+ uint32_t prng;
+ uint64_t gtt_size;
+ uint64_t start;
+ uint64_t end;
+
+ /* statistics */
+ uint64_t allocated_objects;
+};
+
+#define GEN8_HIGH_ADDRESS_BIT 47
+static uint64_t gen8_canonical_addr(uint64_t address)
+{
+ int shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+
+ return (int64_t)(address << shift) >> shift;
+}
+
+static uint64_t get_bias(int fd)
+{
+ (void) fd;
+
+ return 256 << 10;
+}
+
+static void intel_allocator_random_get_address_range(struct intel_allocator *ial,
+ uint64_t *startp,
+ uint64_t *endp)
+{
+ struct intel_allocator_random *ialr = ial->priv;
+
+ if (startp)
+ *startp = ialr->start;
+
+ if (endp)
+ *endp = ialr->end;
+}
+
+static uint64_t intel_allocator_random_alloc(struct intel_allocator *ial,
+ uint32_t handle, uint64_t size,
+ uint64_t alignment)
+{
+ struct intel_allocator_random *ialr = ial->priv;
+ uint64_t offset;
+
+ (void) handle;
+
+ /* randomize the address, we try to avoid relocations */
+ offset = hars_petruska_f54_1_random64(&ialr->prng);
+ offset += ialr->bias; /* Keep the low 256k clear, for negative deltas */
+ offset &= ialr->gtt_size - 1;
+ offset &= ~(alignment - 1);
+ offset = gen8_canonical_addr(offset);
+
+ ialr->allocated_objects++;
+
+ return offset;
+}
+
+static bool intel_allocator_random_free(struct intel_allocator *ial,
+ uint32_t handle)
+{
+ struct intel_allocator_random *ialr = ial->priv;
+
+ (void) handle;
+
+ ialr->allocated_objects--;
+
+ return false;
+}
+
+static bool intel_allocator_random_is_allocated(struct intel_allocator *ial,
+ uint32_t handle, uint64_t size,
+ uint64_t offset)
+{
+ (void) ial;
+ (void) handle;
+ (void) size;
+ (void) offset;
+
+ return false;
+}
+
+static void intel_allocator_random_destroy(struct intel_allocator *ial)
+{
+ igt_assert(ial);
+
+ free(ial->priv);
+ free(ial);
+}
+
+static bool intel_allocator_random_reserve(struct intel_allocator *ial,
+ uint32_t handle,
+ uint64_t start, uint64_t end)
+{
+ (void) ial;
+ (void) handle;
+ (void) start;
+ (void) end;
+
+ return false;
+}
+
+static bool intel_allocator_random_unreserve(struct intel_allocator *ial,
+ uint32_t handle,
+ uint64_t start, uint64_t end)
+{
+ (void) ial;
+ (void) handle;
+ (void) start;
+ (void) end;
+
+ return false;
+}
+
+static bool intel_allocator_random_is_reserved(struct intel_allocator *ial,
+ uint64_t start, uint64_t end)
+{
+ (void) ial;
+ (void) start;
+ (void) end;
+
+ return false;
+}
+
+static void intel_allocator_random_print(struct intel_allocator *ial, bool full)
+{
+ struct intel_allocator_random *ialr = ial->priv;
+
+ (void) full;
+
+ igt_info("<fd: %d, ctx: %u> allocated objects: %" PRIx64 "\n",
+ ial->fd, ial->ctx, ialr->allocated_objects);
+}
+
+static bool intel_allocator_random_is_empty(struct intel_allocator *ial)
+{
+ struct intel_allocator_random *ialr = ial->priv;
+
+ return !ialr->allocated_objects;
+}
+
+struct intel_allocator *intel_allocator_random_create(int fd, uint32_t ctx)
+{
+ struct intel_allocator *ial;
+ struct intel_allocator_random *ialr;
+
+ igt_debug("Using random allocator\n");
+ ial = calloc(1, sizeof(*ial));
+ igt_assert(ial);
+
+ ial->fd = fd;
+ ial->ctx = ctx;
+ ial->get_address_range = intel_allocator_random_get_address_range;
+ ial->alloc = intel_allocator_random_alloc;
+ ial->free = intel_allocator_random_free;
+ ial->is_allocated = intel_allocator_random_is_allocated;
+ ial->reserve = intel_allocator_random_reserve;
+ ial->unreserve = intel_allocator_random_unreserve;
+ ial->is_reserved = intel_allocator_random_is_reserved;
+ ial->destroy = intel_allocator_random_destroy;
+ ial->print = intel_allocator_random_print;
+ ial->is_empty = intel_allocator_random_is_empty;
+
+ ialr = ial->priv = calloc(1, sizeof(*ialr));
+ igt_assert(ial->priv);
+ ialr->prng = (uint32_t) to_user_pointer(ial);
+ ialr->gtt_size = gem_aperture_size(fd);
+ igt_debug("Gtt size: %" PRId64 "\n", ialr->gtt_size);
+ if (!gem_uses_full_ppgtt(fd))
+ ialr->gtt_size /= 2;
+
+ if ((ialr->gtt_size - 1) >> 32) {
+ /*
+ * We're not aware of bo sizes, so limiting to 46 bit make us
+ * sure we won't enter to addresses with 47-bit set
+ * (we use 32-bit size now so still we fit 47-bit address space).
+ */
+ if (ialr->gtt_size & (3ull << 47))
+ ialr->gtt_size = (1ull << 46);
+ }
+ ialr->bias = get_bias(fd);
+ ialr->start = ialr->bias;
+ ialr->end = ialr->gtt_size;
+
+ ialr->allocated_objects = 0;
+
+ return ial;
+}
--
2.26.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2020-11-20 11:31 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 11:31 [igt-dev] [PATCH i-g-t v10 00/31] Introduce IGT allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 01/31] lib/igt_list: igt_hlist implementation Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 02/31] lib/igt_map: Introduce igt_map Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 03/31] lib/igt_core: Track child process pid and tid Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 04/31] lib/intel_allocator_simple: Add simple allocator Zbigniew Kempczyński
2020-11-20 11:31 ` Zbigniew Kempczyński [this message]
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 06/31] lib/intel_allocator: Add intel_allocator core Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 07/31] lib/intel_allocator: Try to stop smoothly instead of deinit Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 08/31] lib/intel_allocator_msgchannel: Scale to 4k of parallel clients Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 09/31] lib/intel_bufops: Removes handle from allocator, change size Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 10/31] lib/intel_bufops: Add init with handle and size function Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 11/31] lib/intel_batchbuffer: Integrate intel_bb with allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 12/31] lib/intel_batchbuffer: Add tracking intel_buf to intel_bb Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 13/31] lib/intel_aux_pgtable: Get addresses for aux table from an allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 14/31] lib/igt_fb: Initialize intel_buf with same size as fb Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 15/31] tests/api_intel_bb: Modify test to verify intel_bb with allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 16/31] tests/api_intel_bb: Add compressed->compressed copy Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 17/31] tests/api_intel_allocator: Simple allocator test suite Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 18/31] tests/gem|kms: Remove intel_bb from fixture Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 19/31] tests/gem_mmap_offset: Use intel_buf wrapper code instead direct Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 20/31] tests/gem_ppgtt: Adopt test to use intel_bb with allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 21/31] tests/gem_render_copy_redux: Adopt to use with intel_bb and allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 22/31] tests/perf.c: Remove buffer from batch Zbigniew Kempczyński
2020-11-20 12:06 ` Lionel Landwerlin
2020-11-20 12:17 ` Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 23/31] tests/gem_linear_blits: Use intel allocator Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 24/31] lib/ioctl_wrappers: Add gem_has_relocations() check Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 25/31] lib/intel_batchbuffer: Use relocations in intel-bb up to gen12 Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 26/31] tests/api_intel_*: Adopt to use relocations as default " Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 27/31] tests/gem_ppgtt: Migrate memory check out of render blits Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 28/31] tests/api_intel_bb: Remove check-canonical test Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 29/31] tests/api_intel_bb: Use allocator in delta-check test Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 30/31] lib/intel_allocator: Separate allocator multiprocess start Zbigniew Kempczyński
2020-11-20 11:31 ` [igt-dev] [PATCH i-g-t v10 31/31] tests/api_intel_allocator: Prepare to run with sanitizer Zbigniew Kempczyński
2020-11-20 13:28 ` [igt-dev] ✗ Fi.CI.BAT: failure for Introduce IGT allocator (rev11) Patchwork
2020-11-20 17:34 ` 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=20201120113131.67971-6-zbigniew.kempczynski@intel.com \
--to=zbigniew.kempczynski@intel.com \
--cc=chris@chris-wilson.co.uk \
--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