From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 2/3] lib/intel_allocator_*: Use common hash helpers
Date: Thu, 23 Feb 2023 12:26:41 +0100 [thread overview]
Message-ID: <20230223122641.06bda1da@maurocar-mobl2> (raw)
In-Reply-To: <20230223105321.49048-2-zbigniew.kempczynski@intel.com>
On Thu, 23 Feb 2023 11:53:20 +0100
Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> wrote:
> Reduce code duplication by using common hash helpers from igt_map.
>
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
> ---
> lib/intel_allocator_reloc.c | 23 +-------------------
> lib/intel_allocator_simple.c | 41 ++----------------------------------
> 2 files changed, 3 insertions(+), 61 deletions(-)
>
> diff --git a/lib/intel_allocator_reloc.c b/lib/intel_allocator_reloc.c
> index 60cbb88511..3aa9ebe763 100644
> --- a/lib/intel_allocator_reloc.c
> +++ b/lib/intel_allocator_reloc.c
> @@ -34,27 +34,6 @@ struct intel_allocator_record {
> /* Keep the low 256k clear, for negative deltas */
> #define BIAS (256 << 10)
>
> -/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
> -#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
> -
> -/* 2^63 + 2^61 - 2^57 + 2^54 - 2^51 - 2^18 + 1 */
> -#define GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001ULL
> -
> -static inline uint32_t hash_handles(const void *val)
> -{
> - uint32_t hash = *(uint32_t *) val;
> -
> - hash = hash * GOLDEN_RATIO_PRIME_32;
> - return hash;
> -}
> -
> -static int equal_handles(const void *a, const void *b)
> -{
> - uint32_t *key1 = (uint32_t *) a, *key2 = (uint32_t *) b;
> -
> - return *key1 == *key2;
> -}
> -
> static void map_entry_free_func(struct igt_map_entry *entry)
> {
> free(entry->data);
> @@ -252,7 +231,7 @@ intel_allocator_reloc_create(int fd, uint64_t start, uint64_t end)
>
> ialr = ial->priv = calloc(1, sizeof(*ialr));
> igt_assert(ial->priv);
> - ialr->objects = igt_map_create(hash_handles, equal_handles);
> + ialr->objects = igt_map_create(igt_map_hash_32, igt_map_equal_32);
> ialr->prng = (uint32_t) to_user_pointer(ial);
>
> start = max_t(uint64_t, start, BIAS);
> diff --git a/lib/intel_allocator_simple.c b/lib/intel_allocator_simple.c
> index 8d5105f114..3d5e45870e 100644
> --- a/lib/intel_allocator_simple.c
> +++ b/lib/intel_allocator_simple.c
> @@ -59,43 +59,6 @@ struct intel_allocator_record {
> #define simple_vma_foreach_hole_safe_rev(_hole, _heap, _tmp) \
> igt_list_for_each_entry_safe_reverse(_hole, _tmp, &(_heap)->holes, link)
>
> -/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
> -#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
> -
> -/* 2^63 + 2^61 - 2^57 + 2^54 - 2^51 - 2^18 + 1 */
> -#define GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001ULL
> -
> -static inline uint32_t hash_handles(const void *val)
> -{
> - uint32_t hash = *(uint32_t *) val;
> -
> - hash = hash * GOLDEN_RATIO_PRIME_32;
> - return hash;
> -}
> -
> -static int equal_handles(const void *a, const void *b)
> -{
> - uint32_t *key1 = (uint32_t *) a, *key2 = (uint32_t *) b;
> -
> - return *key1 == *key2;
> -}
> -
> -static inline uint32_t hash_offsets(const void *val)
> -{
> - uint64_t hash = *(uint64_t *) val;
> -
> - hash = hash * GOLDEN_RATIO_PRIME_64;
> - /* High bits are more random, so use them. */
> - return hash >> 32;
> -}
> -
> -static int equal_offsets(const void *a, const void *b)
> -{
> - uint64_t *key1 = (uint64_t *) a, *key2 = (uint64_t *) b;
> -
> - return *key1 == *key2;
> -}
> -
> static void map_entry_free_func(struct igt_map_entry *entry)
> {
> free(entry->data);
> @@ -755,8 +718,8 @@ intel_allocator_simple_create(int fd, uint64_t start, uint64_t end,
> ials = ial->priv = malloc(sizeof(struct intel_allocator_simple));
> igt_assert(ials);
>
> - ials->objects = igt_map_create(hash_handles, equal_handles);
> - ials->reserved = igt_map_create(hash_offsets, equal_offsets);
> + ials->objects = igt_map_create(igt_map_hash_32, igt_map_equal_32);
> + ials->reserved = igt_map_create(igt_map_hash_64, igt_map_equal_64);
> igt_assert(ials->objects && ials->reserved);
>
> ials->start = start;
next prev parent reply other threads:[~2023-02-23 11:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 10:53 [igt-dev] [PATCH i-g-t 1/3] lib/igt_map: Add 32-bit and 64-bit hash helper functions Zbigniew Kempczyński
2023-02-23 10:53 ` [igt-dev] [PATCH i-g-t 2/3] lib/intel_allocator_*: Use common hash helpers Zbigniew Kempczyński
2023-02-23 11:26 ` Mauro Carvalho Chehab [this message]
2023-02-23 10:53 ` [igt-dev] [PATCH i-g-t 3/3] lib/i915/gem_create: Use hash helper for gem bo pool Zbigniew Kempczyński
2023-02-23 11:26 ` Mauro Carvalho Chehab
2023-02-23 11:26 ` [igt-dev] [PATCH i-g-t 1/3] lib/igt_map: Add 32-bit and 64-bit hash helper functions Mauro Carvalho Chehab
2023-02-23 12:28 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/3] " Patchwork
2023-02-23 15:15 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-02-23 17:07 ` 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=20230223122641.06bda1da@maurocar-mobl2 \
--to=mauro.chehab@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=zbigniew.kempczynski@intel.com \
/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