Re: [Intel-gfx] [PATCH] drivers/gpu/drm/i915/selftests/i915_buddy.c: Fix bug

2020-08-06 Thread Chris Wilson
Quoting George Spelvin (2020-03-25 19:24:29)
> igt_mm_config() calls ilog2() on the (pseudo)random 21-bit number
> s>>12.  Once in 2 million seeds, this is zero and ilog2 summons
> the nasal demons.

I ran into a similar bug with random returning 0 and remembered this
patch sitting around.

Pushed, and many thanks for the fix!
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drivers/gpu/drm/i915/selftests/i915_buddy.c: Fix bug

2020-03-27 Thread Matthew Auld
On Thu, 26 Mar 2020 at 20:21, George Spelvin  wrote:
>
> On Thu, Mar 26, 2020 at 05:04:43PM +, Matthew Auld wrote:
> > Reviewed-by: Matthew Auld 
>
> Thank you!  I got some incomprehensible error emails (reproduced at
> https://patchwork.freedesktop.org/series/75090/) from the patchwork
> daemon, complaining about additional test failures.  Obviously, I care,
> but I can't tell if this is a genuine error, or just a flaky test being
> sensitive to the exact random number generation algorithm.
>
> If you understand these messages, do they look like I broke something?

No, doesn't seem to be related to your change.

https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17090/shards-all.html?testfilter=buddy
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drivers/gpu/drm/i915/selftests/i915_buddy.c: Fix bug

2020-03-27 Thread George Spelvin
On Thu, Mar 26, 2020 at 05:04:43PM +, Matthew Auld wrote:
> Reviewed-by: Matthew Auld 

Thank you!  I got some incomprehensible error emails (reproduced at 
https://patchwork.freedesktop.org/series/75090/) from the patchwork 
daemon, complaining about additional test failures.  Obviously, I care, 
but I can't tell if this is a genuine error, or just a flaky test being 
sensitive to the exact random number generation algorithm.

If you understand these messages, do they look like I broke something?
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drivers/gpu/drm/i915/selftests/i915_buddy.c: Fix bug

2020-03-26 Thread Matthew Auld
On Wed, 25 Mar 2020 at 21:23, George Spelvin  wrote:
>
> igt_mm_config() calls ilog2() on the (pseudo)random 21-bit number
> s>>12.  Once in 2 million seeds, this is zero and ilog2 summons
> the nasal demons.
>
> There was an attempt to handle this case with a max(), but that's
> too late; ms could already be something bizarre.
>
> Given that the low 12 bits of s and ms are always zero, it's a lot
> simpler just to divide them by 4096, then everything fits into 32
> bits, and we can easily generate a random number 1 <= s <= 0x1f.
>
> Signed-off-by: George Spelvin 
> Fixes: 14d1b9a6247c
> Cc: Matthew Auld 
> Cc: Jani Nikula 
> Cc: Joonas Lahtinen 
> Cc: Rodrigo Vivi 
> Cc: intel-gfx@lists.freedesktop.org
Reviewed-by: Matthew Auld 
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drivers/gpu/drm/i915/selftests/i915_buddy.c: Fix bug

2020-03-25 Thread George Spelvin
igt_mm_config() calls ilog2() on the (pseudo)random 21-bit number
s>>12.  Once in 2 million seeds, this is zero and ilog2 summons
the nasal demons.

There was an attempt to handle this case with a max(), but that's
too late; ms could already be something bizarre.

Given that the low 12 bits of s and ms are always zero, it's a lot
simpler just to divide them by 4096, then everything fits into 32
bits, and we can easily generate a random number 1 <= s <= 0x1f.

Signed-off-by: George Spelvin 
Fixes: 14d1b9a6247c
Cc: Matthew Auld 
Cc: Jani Nikula 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc: intel-gfx@lists.freedesktop.org
---
 drivers/gpu/drm/i915/selftests/i915_buddy.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_buddy.c 
b/drivers/gpu/drm/i915/selftests/i915_buddy.c
index 1b856bae67b53..b5d29dda45ddb 100644
--- a/drivers/gpu/drm/i915/selftests/i915_buddy.c
+++ b/drivers/gpu/drm/i915/selftests/i915_buddy.c
@@ -8,8 +8,6 @@
 #include "../i915_selftest.h"
 #include "i915_random.h"
 
-#define SZ_8G (1ULL << 33)
-
 static void __igt_dump_block(struct i915_buddy_mm *mm,
 struct i915_buddy_block *block,
 bool buddy)
@@ -281,18 +279,22 @@ static int igt_check_mm(struct i915_buddy_mm *mm)
 static void igt_mm_config(u64 *size, u64 *chunk_size)
 {
I915_RND_STATE(prng);
-   u64 s, ms;
+   u32 s, ms;
 
/* Nothing fancy, just try to get an interesting bit pattern */
 
prandom_seed_state(, i915_selftest.random_seed);
 
-   s = i915_prandom_u64_state() & (SZ_8G - 1);
-   ms = BIT_ULL(12 + (prandom_u32_state() % ilog2(s >> 12)));
-   s = max(s & -ms, ms);
+   /* Let size be a random number of pages up to 8 GB (2M pages) */
+   s = 1 + i915_prandom_u32_max_state((1 << (33-12)) - 1, );
+   /* Let the chunk size be a random power of 2 less than size */
+   ms = (u32)1 << i915_prandom_u32_max_state(ilog2(s), );
+   /* Round size down to the chunk size */
+   s &= -ms;
 
-   *chunk_size = ms;
-   *size = s;
+   /* Convert from pages to bytes */
+   *chunk_size = (u64)ms << 12;
+   *size = (u64)s << 12;
 }
 
 static int igt_buddy_alloc_smoke(void *arg)
-- 
2.26.0
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx