All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: Jason Ekstrand <jason@jlekstrand.net>
Cc: IGT GPU Tools <igt-dev@lists.freedesktop.org>
Subject: Re: [igt-dev] [PATCH i-g-t v26 05/35] lib/intel_allocator_simple: Add simple allocator
Date: Thu, 18 Mar 2021 11:40:53 +0100	[thread overview]
Message-ID: <20210318104053.GA12222@zkempczy-mobl2> (raw)
In-Reply-To: <CAOFGe97V716nqQHiM1Vh0kpz5kws6-dTQo7dMXNbt5Z5uHf0aA@mail.gmail.com>

On Wed, Mar 17, 2021 at 02:38:35PM -0500, Jason Ekstrand wrote:

<cut>

I've addressed all that weird indentations you've noticed.
I've seen that code a lot of times so definitely fresh 
look was refreshing.

> +
> > +static bool intel_allocator_simple_is_allocated(struct intel_allocator *ial,
> > +                                               uint32_t handle, uint64_t size,
> > +                                               uint64_t offset)
> > +{
> > +       struct intel_allocator_record *rec;
> > +       struct intel_allocator_simple *ials;
> > +       bool same = false;
> > +
> > +       igt_assert(ial);
> > +       ials = (struct intel_allocator_simple *) ial->priv;
> > +       igt_assert(ials);
> > +       igt_assert(handle);
> > +
> > +       rec = igt_map_find(&ials->objects, &handle);
> > +       if (rec && __same(rec, handle, size, offset))
> > +               same = true;
> > +
> > +       return same;
> > +}
> > +
> > +static bool intel_allocator_simple_reserve(struct intel_allocator *ial,
> > +                                          uint32_t handle,
> > +                                          uint64_t start, uint64_t end)
> > +{
> > +       uint64_t size = end - start;
> 
> With canonical addresses, our size calculations aren't going to be
> correct if start and end are on different sides of the 47-bit
> boundary.  I'm not sure how to deal with that, TBH.  Most of the time,
> I think you get saved by the fact that you're only really likely to
> hit that if you have a > 128 TB range which never happens.  One simple
> thing we could do is
> 
> igt_assert(end >> GEN8_GT_ADDRESS_WIDTH == start >> GEN8_GT_ADDRESS_WIDTH);
> 
> or similar.  Same goes for the 3-4 other cases below.

What do you say about:

static uint64_t get_size(uint64_t start, uint64_t end)
{
	end = end ? end : 1ull << GEN8_GTT_ADDRESS_WIDTH;

	return end - start;
}

then

	igt_assert(end > start || end == 0);
	size = get_size(start, end);

> 
> > +       struct intel_allocator_record *rec = NULL;
> > +       struct intel_allocator_simple *ials;
> > +
> > +       igt_assert(ial);
> > +       ials = (struct intel_allocator_simple *) ial->priv;
> > +       igt_assert(ials);
> > +
> > +       /* clear [63:48] bits to get rid of canonical form */
> > +       start = DECANONICAL(start);
> > +       end = DECANONICAL(end);
> > +       igt_assert(end > start || end == 0);
> 
> With always reserving the top 4K, end = 0 should never happen.

That's true, but limit us from catching problems with last page
- gpu can hang when using 3d pipeline with batch on that page.
Take a look to:

https://patchwork.freedesktop.org/patch/424031/?series=82954&rev=26

Daniel requested to remove that test because it hangs gpu
on glk/kbl/skl so we likely want to check that in the future
in other cases. So totally excluding last page is not we want imo.
For "normal" usage I want to skip that page from default but 
I still want to have a possibility to use it in "full" version.

--
Zbigniew

> 
> > +
> > +       if (simple_vma_heap_alloc_addr(ials, start, size)) {
> > +               rec = malloc(sizeof(*rec));
> > +               rec->handle = handle;
> > +               rec->offset = start;
> > +               rec->size = size;
> > +
> > +               igt_map_add(&ials->reserved, &rec->offset, rec);
> > +
> > +               ials->reserved_areas++;
> > +               ials->reserved_size += rec->size;
> > +               return true;
> > +       }
> > +
> > +       igt_debug("Failed to reserve %llx + %llx\n", (long long)start, (long long)size);
> > +       return false;
> > +}
> > +
> > +static bool intel_allocator_simple_unreserve(struct intel_allocator *ial,
> > +                                            uint32_t handle,
> > +                                            uint64_t start, uint64_t end)
> > +{
> > +       uint64_t size = end - start;
> > +       struct intel_allocator_record *rec = NULL;
> > +       struct intel_allocator_simple *ials;
> > +
> > +       igt_assert(ial);
> > +       ials = (struct intel_allocator_simple *) ial->priv;
> > +       igt_assert(ials);
> > +
> > +       /* clear [63:48] bits to get rid of canonical form */
> > +       start = DECANONICAL(start);
> > +       end = DECANONICAL(end);
> > +
> > +       igt_assert(end > start || end == 0);
> > +
> > +       rec = igt_map_find(&ials->reserved, &start);
> > +
> > +       if (!rec) {
> > +               igt_debug("Only reserved blocks can be unreserved\n");
> > +               return false;
> > +       }
> > +
> > +       if (rec->size != size) {
> > +               igt_debug("Only the whole block unreservation allowed\n");
> > +               return false;
> > +       }
> > +
> > +       if (rec->handle != handle) {
> > +               igt_debug("Handle %u doesn't match reservation handle: %u\n",
> > +                        rec->handle, handle);
> > +               return false;
> > +       }
> > +
> > +       igt_map_del(&ials->reserved, &start);
> > +
> > +       ials->reserved_areas--;
> > +       ials->reserved_size -= rec->size;
> > +       free(rec);
> > +       simple_vma_heap_free(&ials->heap, start, size);
> > +
> > +       return true;
> > +}
> > +
> > +static bool intel_allocator_simple_is_reserved(struct intel_allocator *ial,
> > +                                              uint64_t start, uint64_t end)
> > +{
> > +       uint64_t size = end - start;
> > +       struct intel_allocator_record *rec = NULL;
> > +       struct intel_allocator_simple *ials;
> > +
> > +       igt_assert(ial);
> > +       ials = (struct intel_allocator_simple *) ial->priv;
> > +       igt_assert(ials);
> > +
> > +       /* clear [63:48] bits to get rid of canonical form */
> > +       start = DECANONICAL(start);
> > +       end = DECANONICAL(end);
> > +
> > +       igt_assert(end > start || end == 0);
> > +
> > +       rec = igt_map_find(&ials->reserved, &start);
> > +
> > +       if (!rec)
> > +               return false;
> > +
> > +       if (rec->offset == start && rec->size == size)
> > +               return true;
> > +
> > +       return false;
> > +}
> > +
> > +static bool equal_8bytes(const void *key1, const void *key2)
> > +{
> > +       const uint64_t *k1 = key1, *k2 = key2;
> > +       return *k1 == *k2;
> > +}
> > +
> > +static void intel_allocator_simple_destroy(struct intel_allocator *ial)
> > +{
> > +       struct intel_allocator_simple *ials;
> > +       struct igt_map_entry *pos;
> > +       struct igt_map *map;
> > +       int i;
> > +
> > +       igt_assert(ial);
> > +       ials = (struct intel_allocator_simple *) ial->priv;
> > +       simple_vma_heap_finish(&ials->heap);
> > +
> > +       map = &ials->objects;
> > +       igt_map_for_each(map, i, pos)
> > +               free(pos->value);
> > +       igt_map_free(&ials->objects);
> > +
> > +       map = &ials->reserved;
> > +       igt_map_for_each(map, i, pos)
> > +               free(pos->value);
> > +       igt_map_free(&ials->reserved);
> > +
> > +       free(ial->priv);
> > +       free(ial);
> > +}
> > +
> > +static bool intel_allocator_simple_is_empty(struct intel_allocator *ial)
> > +{
> > +       struct intel_allocator_simple *ials = ial->priv;
> > +
> > +       igt_debug("<ial: %p, fd: %d> objects: %" PRId64
> > +                 ", reserved_areas: %" PRId64 "\n",
> > +                 ial, ial->fd,
> > +                 ials->allocated_objects, ials->reserved_areas);
> > +
> > +       return !ials->allocated_objects && !ials->reserved_areas;
> > +}
> > +
> > +static void intel_allocator_simple_print(struct intel_allocator *ial, bool full)
> > +{
> > +       struct intel_allocator_simple *ials;
> > +       struct simple_vma_hole *hole;
> > +       struct simple_vma_heap *heap;
> > +       struct igt_map_entry *pos;
> > +       struct igt_map *map;
> > +       uint64_t total_free = 0, allocated_size = 0, allocated_objects = 0;
> > +       uint64_t reserved_size = 0, reserved_areas = 0;
> > +       int i;
> > +
> > +       igt_assert(ial);
> > +       ials = (struct intel_allocator_simple *) ial->priv;
> > +       igt_assert(ials);
> > +       heap = &ials->heap;
> > +
> > +       igt_info("intel_allocator_simple <ial: %p, fd: %d> on "
> > +                "[0x%"PRIx64" : 0x%"PRIx64"]:\n", ial, ial->fd,
> > +                ials->start, ials->end);
> > +
> > +       if (full) {
> > +               igt_info("holes:\n");
> > +               simple_vma_foreach_hole(hole, heap) {
> > +                       igt_info("offset = %"PRIu64" (0x%"PRIx64", "
> > +                                "size = %"PRIu64" (0x%"PRIx64")\n",
> > +                                hole->offset, hole->offset, hole->size,
> > +                                hole->size);
> > +                       total_free += hole->size;
> > +               }
> > +               igt_assert(total_free <= ials->total_size);
> > +               igt_info("total_free: %" PRIx64
> > +                        ", total_size: %" PRIx64
> > +                        ", allocated_size: %" PRIx64
> > +                        ", reserved_size: %" PRIx64 "\n",
> > +                        total_free, ials->total_size, ials->allocated_size,
> > +                        ials->reserved_size);
> > +               igt_assert(total_free ==
> > +                          ials->total_size - ials->allocated_size - ials->reserved_size);
> > +
> > +               igt_info("objects:\n");
> > +               map = &ials->objects;
> > +               igt_map_for_each(map, i, pos) {
> > +                       struct intel_allocator_record *rec = pos->value;
> > +
> > +                       igt_info("handle = %d, offset = %"PRIu64" "
> > +                               "(0x%"PRIx64", size = %"PRIu64" (0x%"PRIx64")\n",
> > +                                rec->handle, rec->offset, rec->offset,
> > +                                rec->size, rec->size);
> > +                       allocated_objects++;
> > +                       allocated_size += rec->size;
> > +               }
> > +               igt_assert(ials->allocated_size == allocated_size);
> > +               igt_assert(ials->allocated_objects == allocated_objects);
> > +
> > +               igt_info("reserved areas:\n");
> > +               map = &ials->reserved;
> > +               igt_map_for_each(map, i, pos) {
> > +                       struct intel_allocator_record *rec = pos->value;
> > +
> > +                       igt_info("offset = %"PRIu64" (0x%"PRIx64", "
> > +                                "size = %"PRIu64" (0x%"PRIx64")\n",
> > +                                rec->offset, rec->offset,
> > +                                rec->size, rec->size);
> > +                       reserved_areas++;
> > +                       reserved_size += rec->size;
> > +               }
> > +               igt_assert(ials->reserved_areas == reserved_areas);
> > +               igt_assert(ials->reserved_size == reserved_size);
> > +       } else {
> > +               simple_vma_foreach_hole(hole, heap)
> > +                       total_free += hole->size;
> > +       }
> > +
> > +       igt_info("free space: %"PRIu64"B (0x%"PRIx64") (%.2f%% full)\n"
> > +                "allocated objects: %"PRIu64", reserved areas: %"PRIu64"\n",
> > +                total_free, total_free,
> > +                ((double) (ials->total_size - total_free) /
> > +                 (double) ials->total_size) * 100,
> > +                ials->allocated_objects, ials->reserved_areas);
> > +}
> > +
> > +static struct intel_allocator *
> > +__intel_allocator_simple_create(int fd, uint64_t start, uint64_t end,
> > +                               enum allocator_strategy strategy)
> > +{
> > +       struct intel_allocator *ial;
> > +       struct intel_allocator_simple *ials;
> > +
> > +       igt_debug("Using simple allocator\n");
> > +
> > +       ial = calloc(1, sizeof(*ial));
> > +       igt_assert(ial);
> > +
> > +       ial->fd = fd;
> > +       ial->get_address_range = intel_allocator_simple_get_address_range;
> > +       ial->alloc = intel_allocator_simple_alloc;
> > +       ial->free = intel_allocator_simple_free;
> > +       ial->is_allocated = intel_allocator_simple_is_allocated;
> > +       ial->reserve = intel_allocator_simple_reserve;
> > +       ial->unreserve = intel_allocator_simple_unreserve;
> > +       ial->is_reserved = intel_allocator_simple_is_reserved;
> > +       ial->destroy = intel_allocator_simple_destroy;
> > +       ial->is_empty = intel_allocator_simple_is_empty;
> > +       ial->print = intel_allocator_simple_print;
> > +       ials = ial->priv = malloc(sizeof(struct intel_allocator_simple));
> > +       igt_assert(ials);
> > +
> > +       igt_map_init(&ials->objects);
> > +       /* Reserved addresses hashtable is indexed by an offset */
> > +       __igt_map_init(&ials->reserved, equal_8bytes, NULL, 3);
> 
> We have this same problem with Mesa.  Maybe just make the hash map
> take a uint64_t key instead of a void*.  Then it'll work for both
> cases easily at the cost of a little extra memory on 32-bit platforms.
> 
> Looking a bit more, I guess it's not quite as bad as the Mesa case
> because you have the uint64_t key in the object you're adding so you
> don't have to malloc a bunch of uint64_t's just to use as keys.
> 
> > +
> > +       ials->start = start;
> > +       ials->end = end;
> > +       ials->total_size = end - start;
> > +       simple_vma_heap_init(&ials->heap, ials->start, ials->total_size,
> > +                            strategy);
> > +
> > +       ials->allocated_size = 0;
> > +       ials->allocated_objects = 0;
> > +       ials->reserved_size = 0;
> > +       ials->reserved_areas = 0;
> > +
> > +       return ial;
> > +}
> > +
> > +struct intel_allocator *
> > +intel_allocator_simple_create(int fd)
> > +{
> > +       uint64_t gtt_size = gem_aperture_size(fd);
> > +
> > +       if (!gem_uses_full_ppgtt(fd))
> > +               gtt_size /= 2;
> > +       else
> > +               gtt_size -= RESERVED;
> > +
> > +       return __intel_allocator_simple_create(fd, 0, gtt_size,
> > +                                              ALLOC_STRATEGY_HIGH_TO_LOW);
> > +}
> > +
> > +struct intel_allocator *
> > +intel_allocator_simple_create_full(int fd, uint64_t start, uint64_t end,
> > +                                  enum allocator_strategy strategy)
> > +{
> > +       uint64_t gtt_size = gem_aperture_size(fd);
> > +
> > +       igt_assert(end <= gtt_size);
> > +       if (!gem_uses_full_ppgtt(fd))
> > +               gtt_size /= 2;
> > +       igt_assert(end - start <= gtt_size);
> 
> Don't you want just `end <= gtt_size`?  When is something only going
> to use the top half?
> 
> > +
> > +       return __intel_allocator_simple_create(fd, start, end, strategy);
> > +}
> > --
> > 2.26.0
> >
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2021-03-18 10:40 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 14:45 [igt-dev] [PATCH i-g-t v26 00/35] Introduce IGT allocator Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 01/35] lib/igt_list: Add igt_list_del_init() Zbigniew Kempczyński
2021-03-17 16:40   ` Jason Ekstrand
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 02/35] lib/igt_list: igt_hlist implementation Zbigniew Kempczyński
2021-03-17 16:43   ` Jason Ekstrand
2021-03-17 17:43     ` Zbigniew Kempczyński
2021-03-17 18:02       ` Jason Ekstrand
2021-03-17 19:13         ` Zbigniew Kempczyński
2021-03-17 20:44           ` Grzegorzek, Dominik
2021-03-18 13:26             ` Grzegorzek, Dominik
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 03/35] lib/igt_map: Introduce igt_map Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 04/35] lib/igt_core: Track child process pid and tid Zbigniew Kempczyński
2021-03-18  9:07   ` Petri Latvala
2021-03-18 13:48     ` Zbigniew Kempczyński
2021-03-18 15:17       ` Petri Latvala
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 05/35] lib/intel_allocator_simple: Add simple allocator Zbigniew Kempczyński
2021-03-17 19:38   ` Jason Ekstrand
2021-03-18 10:40     ` Zbigniew Kempczyński [this message]
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 06/35] lib/intel_allocator_reloc: Add reloc allocator Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 07/35] lib/intel_allocator_random: Add random allocator Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 08/35] lib/intel_allocator: Add intel_allocator core Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 09/35] lib/intel_allocator: Try to stop smoothly instead of deinit Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 10/35] lib/intel_allocator_msgchannel: Scale to 4k of parallel clients Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 11/35] lib/intel_allocator: Separate allocator multiprocess start Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 12/35] lib/intel_bufops: Change size from 32->64 bit Zbigniew Kempczyński
2021-03-17 21:33   ` Jason Ekstrand
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 13/35] lib/intel_bufops: Add init with handle and size function Zbigniew Kempczyński
2021-03-17 21:36   ` Jason Ekstrand
2021-03-18  7:32     ` Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 14/35] lib/intel_batchbuffer: Integrate intel_bb with allocator Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 15/35] lib/intel_batchbuffer: Use relocations in intel-bb up to gen12 Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 16/35] lib/intel_batchbuffer: Create bb with strategy / vm ranges Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 17/35] lib/intel_batchbuffer: Add tracking intel_buf to intel_bb Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 18/35] lib/igt_fb: Initialize intel_buf with same size as fb Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 19/35] tests/api_intel_bb: Remove check-canonical test Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 20/35] tests/api_intel_bb: Modify test to verify intel_bb with allocator Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 21/35] tests/api_intel_bb: Add compressed->compressed copy Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 22/35] tests/api_intel_bb: Add purge-bb test Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 23/35] tests/api_intel_bb: Add simple intel-bb which uses allocator Zbigniew Kempczyński
2021-03-17 14:45 ` [igt-dev] [PATCH i-g-t v26 24/35] tests/api_intel_bb: Use allocator in delta-check test Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 25/35] tests/api_intel_bb: Check switching vm in intel-bb Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 26/35] tests/api_intel_allocator: Simple allocator test suite Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 27/35] tests/api_intel_allocator: Add execbuf with allocator example Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 28/35] tests/api_intel_allocator: Verify child can use its standalone allocator Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 29/35] tests/gem_softpin: Verify allocator and execbuf pair work together Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 30/35] tests/gem|kms: Remove intel_bb from fixture Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 31/35] tests/gem_mmap_offset: Use intel_buf wrapper code instead direct Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 32/35] tests/gem_ppgtt: Adopt test to use intel_bb with allocator Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 33/35] tests/gem_render_copy_redux: Adopt to use with intel_bb and allocator Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 34/35] tests/perf.c: Remove buffer from batch Zbigniew Kempczyński
2021-03-17 14:46 ` [igt-dev] [PATCH i-g-t v26 35/35] tests/gem_linear_blits: Use intel allocator Zbigniew Kempczyński
2021-03-17 16:03 ` [igt-dev] ✓ Fi.CI.BAT: success for Introduce IGT allocator (rev29) Patchwork
2021-03-17 17:47 ` [igt-dev] ✓ Fi.CI.IGT: " 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=20210318104053.GA12222@zkempczy-mobl2 \
    --to=zbigniew.kempczynski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jason@jlekstrand.net \
    /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.