diff mbox series

[i-g-t,15/15] gem_wsim: Allow random seed control

Message ID 20190522155720.28723-16-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series Remaining bits of Virtual Engine tooling | expand

Commit Message

Tvrtko Ursulin May 22, 2019, 3:57 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

New command line option to allow controling the initial pseudo random
generator seed in order to allow repeatable runs.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Suggested-by: Simon Ser <simon.ser@intel.com>
---
 benchmarks/gem_wsim.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Chris Wilson May 22, 2019, 4:52 p.m. UTC | #1
Quoting Tvrtko Ursulin (2019-05-22 16:57:20)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> New command line option to allow controling the initial pseudo random
> generator seed in order to allow repeatable runs.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
> Suggested-by: Simon Ser <simon.ser@intel.com>

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

And squash maybe?
-Chris
diff mbox series

Patch

diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index c43bbbc8c94d..e2ffb93a94d5 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -2946,6 +2946,7 @@  static void print_help(void)
 "  -t <n>          Nop calibration tolerance percentage.\n"
 "                  Use when there is a difficulty obtaining calibration with the\n"
 "                  default settings.\n"
+"  -I <n>          Initial randomness seed.\n"
 "  -p <n>          Context priority to use for the following workload on the\n"
 "                  command line.\n"
 "  -w <desc|path>  Filename or a workload descriptor.\n"
@@ -3119,11 +3120,9 @@  int main(int argc, char **argv)
 	init_clocks();
 
 	master_prng = time(NULL);
-	srand(master_prng);
-	master_prng = rand();
 
 	while ((c = getopt(argc, argv,
-			   "hqv2RsSHxGdc:n:r:w:W:a:t:b:p:")) != -1) {
+			   "hqv2RsSHxGdc:n:r:w:W:a:t:b:p:I:")) != -1) {
 		switch (c) {
 		case 'W':
 			if (master_workload >= 0) {
@@ -3210,6 +3209,9 @@  int main(int argc, char **argv)
 				return 1;
 			}
 			break;
+		case 'I':
+			master_prng = strtol(optarg, NULL, 0);
+			break;
 		case 'h':
 			print_help();
 			return 0;
@@ -3294,6 +3296,7 @@  int main(int argc, char **argv)
 		clients = nr_w_args;
 
 	if (verbose > 1) {
+		printf("Random seed is %u.\n", master_prng);
 		printf("Using %lu nop calibration for %uus delay.\n",
 		       nop_calibration, nop_calibration_us);
 		printf("%u client%s.\n", clients, clients > 1 ? "s" : "");
@@ -3312,6 +3315,9 @@  int main(int argc, char **argv)
 		}
 	}
 
+	srand(master_prng);
+	master_prng = rand();
+
 	if (master_workload >= 0 && clients == 1)
 		master_workload = -1;