All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 12/50] Treewide: Extirpate prandom_u32_state(rnd) % range
@ 2019-03-18  6:46 ` George Spelvin
  0 siblings, 0 replies; 2+ messages in thread
From: George Spelvin @ 2019-03-18  6:46 UTC (permalink / raw)
  To: linux-kernel, lkml
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx,
	Davidlohr Bueso, Chris Wilson

There's no prandom_u32_state_max, so we're using reciprocal_scale()
here directly.

(Also add a missing "const" to drivers/gpu/drm/i915/selftests/scatterist.c)

Signed-off-by: George Spelvin <lkml@sdf.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/selftests/scatterlist.c | 4 ++--
 lib/interval_tree_test.c                     | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/scatterlist.c b/drivers/gpu/drm/i915/selftests/scatterlist.c
index d599186d5b714..be9ff9d03eada 100644
--- a/drivers/gpu/drm/i915/selftests/scatterlist.c
+++ b/drivers/gpu/drm/i915/selftests/scatterlist.c
@@ -195,13 +195,13 @@ static unsigned int random_page_size_pages(unsigned long n,
 					   struct rnd_state *rnd)
 {
 	/* 4K, 64K, 2M */
-	static unsigned int page_count[] = {
+	static const unsigned int page_count[] = {
 		BIT(12) >> PAGE_SHIFT,
 		BIT(16) >> PAGE_SHIFT,
 		BIT(21) >> PAGE_SHIFT,
 	};
 
-	return page_count[(prandom_u32_state(rnd) % 3)];
+	return page_count[reciprocal_scale(prandom_u32_state(rnd), 3)];
 }
 
 static inline bool page_contiguous(struct page *first,
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c
index f37f4d44faa90..8c129c8c638b9 100644
--- a/lib/interval_tree_test.c
+++ b/lib/interval_tree_test.c
@@ -43,8 +43,8 @@ static void init(void)
 	int i;
 
 	for (i = 0; i < nnodes; i++) {
-		u32 b = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
-		u32 a = (prandom_u32_state(&rnd) >> 4) % b;
+		u32 b = reciprocal_scale(prandom_u32_state(&rnd), max_endpoint);
+		u32 a = reciprocal_scale(prandom_u32_state(&rnd), b);
 
 		nodes[i].start = a;
 		nodes[i].last = b;
@@ -56,7 +56,8 @@ static void init(void)
 	 * which is pointless.
 	 */
 	for (i = 0; i < nsearches; i++)
-		queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
+		queries[i] = reciprocal_scale(prandom_u32_state(&rnd),
+					      max_endpoint);
 }
 
 static int interval_tree_test_init(void)
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Intel-gfx] [RFC PATCH v1 12/50] Treewide: Extirpate prandom_u32_state(rnd) % range
@ 2019-03-18  6:46 ` George Spelvin
  0 siblings, 0 replies; 2+ messages in thread
From: George Spelvin @ 2019-03-18  6:46 UTC (permalink / raw)
  To: linux-kernel, lkml; +Cc: Davidlohr Bueso, intel-gfx, Chris Wilson

There's no prandom_u32_state_max, so we're using reciprocal_scale()
here directly.

(Also add a missing "const" to drivers/gpu/drm/i915/selftests/scatterist.c)

Signed-off-by: George Spelvin <lkml@sdf.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/selftests/scatterlist.c | 4 ++--
 lib/interval_tree_test.c                     | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/scatterlist.c b/drivers/gpu/drm/i915/selftests/scatterlist.c
index d599186d5b714..be9ff9d03eada 100644
--- a/drivers/gpu/drm/i915/selftests/scatterlist.c
+++ b/drivers/gpu/drm/i915/selftests/scatterlist.c
@@ -195,13 +195,13 @@ static unsigned int random_page_size_pages(unsigned long n,
 					   struct rnd_state *rnd)
 {
 	/* 4K, 64K, 2M */
-	static unsigned int page_count[] = {
+	static const unsigned int page_count[] = {
 		BIT(12) >> PAGE_SHIFT,
 		BIT(16) >> PAGE_SHIFT,
 		BIT(21) >> PAGE_SHIFT,
 	};
 
-	return page_count[(prandom_u32_state(rnd) % 3)];
+	return page_count[reciprocal_scale(prandom_u32_state(rnd), 3)];
 }
 
 static inline bool page_contiguous(struct page *first,
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c
index f37f4d44faa90..8c129c8c638b9 100644
--- a/lib/interval_tree_test.c
+++ b/lib/interval_tree_test.c
@@ -43,8 +43,8 @@ static void init(void)
 	int i;
 
 	for (i = 0; i < nnodes; i++) {
-		u32 b = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
-		u32 a = (prandom_u32_state(&rnd) >> 4) % b;
+		u32 b = reciprocal_scale(prandom_u32_state(&rnd), max_endpoint);
+		u32 a = reciprocal_scale(prandom_u32_state(&rnd), b);
 
 		nodes[i].start = a;
 		nodes[i].last = b;
@@ -56,7 +56,8 @@ static void init(void)
 	 * which is pointless.
 	 */
 	for (i = 0; i < nsearches; i++)
-		queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
+		queries[i] = reciprocal_scale(prandom_u32_state(&rnd),
+					      max_endpoint);
 }
 
 static int interval_tree_test_init(void)
-- 
2.26.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-30 14:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18  6:46 [RFC PATCH v1 12/50] Treewide: Extirpate prandom_u32_state(rnd) % range George Spelvin
2019-03-18  6:46 ` [Intel-gfx] " George Spelvin

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.