Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t 0/5] igt: cleanups to random functions
@ 2026-06-18 14:09 Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 1/5] lib/kms: simplify igt_random_crtc() Jani Nikula
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jani Nikula @ 2026-06-18 14:09 UTC (permalink / raw)
  To: igt-dev; +Cc: jani.nikula


Jani Nikula (5):
  lib/kms: simplify igt_random_crtc()
  lib/rand: move static inlines to proper functions
  benchmarks/gem_exec_reloc: use hars_petruska_f54_1_random() from
    lib/rand
  benchmarks/gem_exec_trace: use hars_petruska_f54_1_random() from
    lib/rand
  tests/gem_exec_lut_handle: use hars_petruska_f54_1_random() from
    lib/rand

 benchmarks/gem_exec_reloc.c       | 15 ++++-----------
 benchmarks/gem_exec_trace.c       | 12 +++---------
 lib/igt_kms.c                     |  9 ++-------
 lib/igt_rand.c                    | 13 +++++++++++++
 lib/igt_rand.h                    | 13 ++-----------
 tests/intel/gem_exec_lut_handle.c | 14 ++++----------
 6 files changed, 28 insertions(+), 48 deletions(-)

-- 
2.47.3


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

* [PATCH i-g-t 1/5] lib/kms: simplify igt_random_crtc()
  2026-06-18 14:09 [PATCH i-g-t 0/5] igt: cleanups to random functions Jani Nikula
@ 2026-06-18 14:09 ` Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 2/5] lib/rand: move static inlines to proper functions Jani Nikula
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2026-06-18 14:09 UTC (permalink / raw)
  To: igt-dev; +Cc: jani.nikula

Now that igt_display_n_crtcs() reflects the actual number of CRTCs
again, we no longer have to count them separately.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 lib/igt_kms.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index e82d32130666..06138ad7125d 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -7922,16 +7922,11 @@ igt_crtc_t *igt_next_crtc(igt_display_t *display, igt_crtc_t *crtc)
  */
 igt_crtc_t *igt_random_crtc(igt_display_t *display)
 {
-	igt_crtc_t *crtcs[IGT_MAX_PIPES];
-	igt_crtc_t *crtc;
-	int n = 0;
-
-	for_each_crtc(display, crtc)
-		crtcs[n++] = crtc;
+	int n = igt_display_n_crtcs(display);
 
 	igt_skip_on_f(!n, "No CRTCs on device\n");
 
-	return crtcs[rand() % n];
+	return igt_crtc_for_crtc_index(display, rand() % n);
 }
 
 static drmModeConnectorPtr igt_wait_for_connector(int drm_fd, unsigned int connector_id,
-- 
2.47.3


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

* [PATCH i-g-t 2/5] lib/rand: move static inlines to proper functions
  2026-06-18 14:09 [PATCH i-g-t 0/5] igt: cleanups to random functions Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 1/5] lib/kms: simplify igt_random_crtc() Jani Nikula
@ 2026-06-18 14:09 ` Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 3/5] benchmarks/gem_exec_reloc: use hars_petruska_f54_1_random() from lib/rand Jani Nikula
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2026-06-18 14:09 UTC (permalink / raw)
  To: igt-dev; +Cc: jani.nikula

Hide the implementation details. Gut feeling says this also allows the
compiler to do better optimizations within the compilation unit.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 lib/igt_rand.c | 13 +++++++++++++
 lib/igt_rand.h | 13 ++-----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/igt_rand.c b/lib/igt_rand.c
index 16a6ba9b0c65..b2856d000450 100644
--- a/lib/igt_rand.c
+++ b/lib/igt_rand.c
@@ -35,3 +35,16 @@ uint32_t hars_petruska_f54_1_random_unsafe(void)
 {
 	return hars_petruska_f54_1_random(&global);
 }
+
+void hars_petruska_f54_1_random_perturb(uint32_t xor)
+{
+	uint32_t seed = hars_petruska_f54_1_random_seed(0) ^ xor;
+	hars_petruska_f54_1_random_seed(seed);
+	hars_petruska_f54_1_random_seed(hars_petruska_f54_1_random_unsafe());
+}
+
+/* Returns: pseudo-random number in interval [0, ep_ro) */
+uint32_t hars_petruska_f54_1_random_unsafe_max(uint32_t ep_ro)
+{
+	return ((uint64_t)hars_petruska_f54_1_random_unsafe() * ep_ro) >> 32;
+}
diff --git a/lib/igt_rand.h b/lib/igt_rand.h
index 0015680461c1..d89803bb020b 100644
--- a/lib/igt_rand.h
+++ b/lib/igt_rand.h
@@ -32,17 +32,8 @@ uint64_t hars_petruska_f54_1_random64(uint32_t *s);
 uint32_t hars_petruska_f54_1_random_seed(uint32_t seed);
 uint32_t hars_petruska_f54_1_random_unsafe(void);
 
-static inline void hars_petruska_f54_1_random_perturb(uint32_t xor)
-{
-	uint32_t seed = hars_petruska_f54_1_random_seed(0) ^ xor;
-	hars_petruska_f54_1_random_seed(seed);
-	hars_petruska_f54_1_random_seed(hars_petruska_f54_1_random_unsafe());
-}
+void hars_petruska_f54_1_random_perturb(uint32_t xor);
 
-/* Returns: pseudo-random number in interval [0, ep_ro) */
-static inline uint32_t hars_petruska_f54_1_random_unsafe_max(uint32_t ep_ro)
-{
-	return ((uint64_t)hars_petruska_f54_1_random_unsafe() * ep_ro) >> 32;
-}
+uint32_t hars_petruska_f54_1_random_unsafe_max(uint32_t ep_ro);
 
 #endif /* IGT_RAND_H */
-- 
2.47.3


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

* [PATCH i-g-t 3/5] benchmarks/gem_exec_reloc: use hars_petruska_f54_1_random() from lib/rand
  2026-06-18 14:09 [PATCH i-g-t 0/5] igt: cleanups to random functions Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 1/5] lib/kms: simplify igt_random_crtc() Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 2/5] lib/rand: move static inlines to proper functions Jani Nikula
@ 2026-06-18 14:09 ` Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 4/5] benchmarks/gem_exec_trace: " Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 5/5] tests/gem_exec_lut_handle: " Jani Nikula
  4 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2026-06-18 14:09 UTC (permalink / raw)
  To: igt-dev; +Cc: jani.nikula

Remove the local duplicate of hars_petruska_f54_1_random() by switching
to use lib/rand.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 benchmarks/gem_exec_reloc.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/benchmarks/gem_exec_reloc.c b/benchmarks/gem_exec_reloc.c
index 0610308669f2..ff25a3b3b59a 100644
--- a/benchmarks/gem_exec_reloc.c
+++ b/benchmarks/gem_exec_reloc.c
@@ -41,6 +41,7 @@
 #include "i915/gem_create.h"
 #include "i915/gem_mman.h"
 #include "igt_debugfs.h"
+#include "igt_rand.h"
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 
@@ -52,15 +53,7 @@
 #define REVERSE_OFFSET 0x40
 #define RANDOM_OFFSET 0x80
 
-static uint32_t
-hars_petruska_f54_1_random (void)
-{
-	static uint32_t state = 0x12345678;
-
-#define rol(x,k) ((x << k) | (x >> (32-k)))
-	return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
-#undef rol
-}
+static uint32_t random_state = 0x12345678;
 
 #define ELAPSED(a,b) (1e6*((b)->tv_sec - (a)->tv_sec) + ((b)->tv_usec - (a)->tv_usec))
 static int run(unsigned batch_size,
@@ -106,7 +99,7 @@ static int run(unsigned batch_size,
 			mem_reloc[n].offset = batch_size - 8 - (8*n % (batch_size - 16));
 		else if (flags & RANDOM_OFFSET)
 			mem_reloc[n].offset = 8 +
-				8*hars_petruska_f54_1_random() % (batch_size - 16);
+				8*hars_petruska_f54_1_random(&random_state) % (batch_size - 16);
 		else
 			mem_reloc[n].offset = 1024;
 		mem_reloc[n].read_domains = I915_GEM_DOMAIN_RENDER;
@@ -135,7 +128,7 @@ static int run(unsigned batch_size,
 		execbuf.flags |= I915_EXEC_NO_RELOC;
 
 	for (n = 0; n < num_relocs; n++) {
-		target[n] = hars_petruska_f54_1_random() % num_objects;
+		target[n] = hars_petruska_f54_1_random(&random_state) % num_objects;
 		if (flags & LUT)
 			reloc[n].target_handle = target[n];
 		else
-- 
2.47.3


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

* [PATCH i-g-t 4/5] benchmarks/gem_exec_trace: use hars_petruska_f54_1_random() from lib/rand
  2026-06-18 14:09 [PATCH i-g-t 0/5] igt: cleanups to random functions Jani Nikula
                   ` (2 preceding siblings ...)
  2026-06-18 14:09 ` [PATCH i-g-t 3/5] benchmarks/gem_exec_reloc: use hars_petruska_f54_1_random() from lib/rand Jani Nikula
@ 2026-06-18 14:09 ` Jani Nikula
  2026-06-18 14:09 ` [PATCH i-g-t 5/5] tests/gem_exec_lut_handle: " Jani Nikula
  4 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2026-06-18 14:09 UTC (permalink / raw)
  To: igt-dev; +Cc: jani.nikula

Remove the local duplicate of hars_petruska_f54_1_random() by switching
to use lib/rand.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 benchmarks/gem_exec_trace.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/benchmarks/gem_exec_trace.c b/benchmarks/gem_exec_trace.c
index 4263ccb03dbd..c27639105903 100644
--- a/benchmarks/gem_exec_trace.c
+++ b/benchmarks/gem_exec_trace.c
@@ -42,6 +42,7 @@
 #include "drm.h"
 #include "drmtest.h"
 #include "i915/gem_create.h"
+#include "igt_rand.h"
 #include "igt_stats.h"
 #include "intel_io.h"
 #include "ioctl_wrappers.h"
@@ -92,14 +93,7 @@ struct trace_wait {
 	uint32_t handle;
 } __attribute__((packed));
 
-static uint32_t hars_petruska_f54_1_random(void)
-{
-	static uint32_t state = 0x12345678;
-
-#define rol(x,k) ((x << k) | (x >> (32-k)))
-	return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
-#undef rol
-}
+static uint32_t random_state = 0x12345678;
 
 static double elapsed(const struct timespec *start, const struct timespec *end)
 {
@@ -277,7 +271,7 @@ static double replay(const char *filename, long nop, long range)
 				sizeof(*exec_objects)))->handle = bo[0];
 
 			if (nop > 0) {
-				eb.batch_start_offset = hars_petruska_f54_1_random();
+				eb.batch_start_offset = hars_petruska_f54_1_random(&random_state);
 				eb.batch_start_offset =
 					((uint64_t)eb.batch_start_offset * range) >> 32;
 				eb.batch_start_offset = ALIGN(eb.batch_start_offset, 64);
-- 
2.47.3


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

* [PATCH i-g-t 5/5] tests/gem_exec_lut_handle: use hars_petruska_f54_1_random() from lib/rand
  2026-06-18 14:09 [PATCH i-g-t 0/5] igt: cleanups to random functions Jani Nikula
                   ` (3 preceding siblings ...)
  2026-06-18 14:09 ` [PATCH i-g-t 4/5] benchmarks/gem_exec_trace: " Jani Nikula
@ 2026-06-18 14:09 ` Jani Nikula
  4 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2026-06-18 14:09 UTC (permalink / raw)
  To: igt-dev; +Cc: jani.nikula

Remove the local duplicate of hars_petruska_f54_1_random() by switching
to use lib/rand.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 tests/intel/gem_exec_lut_handle.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/tests/intel/gem_exec_lut_handle.c b/tests/intel/gem_exec_lut_handle.c
index fac7f2fbb45f..6ed304fc6d5e 100644
--- a/tests/intel/gem_exec_lut_handle.c
+++ b/tests/intel/gem_exec_lut_handle.c
@@ -40,6 +40,8 @@
 #include "i915/gem.h"
 #include "i915/gem_create.h"
 #include "igt.h"
+#include "igt_rand.h"
+
 /**
  * TEST: gem exec lut handle
  * Description: Exercises the basic execbuffer using the handle LUT interface.
@@ -65,15 +67,7 @@ int target[MAX_NUM_RELOC];
 struct drm_i915_gem_exec_object2 gem_exec[MAX_NUM_EXEC+1];
 struct drm_i915_gem_relocation_entry mem_reloc[MAX_NUM_RELOC];
 
-static uint32_t state = 0x12345678;
-
-static uint32_t
-hars_petruska_f54_1_random (void)
-{
-#define rol(x,k) ((x << k) | (x >> (32-k)))
-    return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
-#undef rol
-}
+static uint32_t random_state = 0x12345678;
 
 static int has_exec_lut(int fd)
 {
@@ -164,7 +158,7 @@ int igt_simple_main()
 					execbuf.flags |= I915_EXEC_NO_RELOC;
 
 				for (j = 0; j < m; j++) {
-					target[j] = hars_petruska_f54_1_random() % n;
+					target[j] = hars_petruska_f54_1_random(&random_state) % n;
 					reloc[j].target_handle = target[j];
 					reloc[j].presumed_offset = -1;
 				}
-- 
2.47.3


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

end of thread, other threads:[~2026-06-18 14:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-18 14:09 [PATCH i-g-t 0/5] igt: cleanups to random functions Jani Nikula
2026-06-18 14:09 ` [PATCH i-g-t 1/5] lib/kms: simplify igt_random_crtc() Jani Nikula
2026-06-18 14:09 ` [PATCH i-g-t 2/5] lib/rand: move static inlines to proper functions Jani Nikula
2026-06-18 14:09 ` [PATCH i-g-t 3/5] benchmarks/gem_exec_reloc: use hars_petruska_f54_1_random() from lib/rand Jani Nikula
2026-06-18 14:09 ` [PATCH i-g-t 4/5] benchmarks/gem_exec_trace: " Jani Nikula
2026-06-18 14:09 ` [PATCH i-g-t 5/5] tests/gem_exec_lut_handle: " Jani Nikula

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox