From: George Spelvin <lkml@sdf.org>
To: linux-kernel@vger.kernel.org, lkml@sdf.org
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
intel-gfx@lists.freedesktop.org,
Davidlohr Bueso <dave@stgolabs.net>,
Chris Wilson <chris@chris-wilson.co.uk>
Subject: [RFC PATCH v1 12/50] Treewide: Extirpate prandom_u32_state(rnd) % range
Date: Mon, 18 Mar 2019 02:46:05 -0400 [thread overview]
Message-ID: <202003281643.02SGhBxX000080@sdf.org> (raw)
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
reply other threads:[~2020-03-28 16:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=202003281643.02SGhBxX000080@sdf.org \
--to=lkml@sdf.org \
--cc=chris@chris-wilson.co.uk \
--cc=dave@stgolabs.net \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.vivi@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
all inboxes | Powered by JetHome®