From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424509AbcKPWmu (ORCPT ); Wed, 16 Nov 2016 17:42:50 -0500 Received: from p3plsmtps2ded02.prod.phx3.secureserver.net ([208.109.80.59]:59502 "EHLO p3plsmtps2ded02.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S940135AbcKPWfY (ORCPT ); Wed, 16 Nov 2016 17:35:24 -0500 x-originating-ip: 72.167.245.219 From: Matthew Wilcox To: linux-kernel@vger.kernel.org, Andrew Morton , Konstantin Khlebnikov , Ross Zwisler Cc: linux-fsdevel@vger.kernel.org, Matthew Wilcox , linux-mm@kvack.org, "Kirill A . Shutemov" Subject: [PATCH 05/29] radix tree test suite: Make runs more reproducible Date: Wed, 16 Nov 2016 16:16:30 -0800 Message-Id: <1479341856-30320-6-git-send-email-mawilcox@linuxonhyperv.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> References: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> X-CMAE-Envelope: MS4wfC7gyTSeBxx+x4f2XL9XwexeU1IrJs4MMrfTSoDLLEB7MYdCsaqYWRCfdzZaGx67u9KAKrpDFT3rcTAG2kVFZJ5lRYc3N4sSyNC/CpSWb5PmkSJ4QHHq dmYPJqPM9lJh475rX7Ww8k5HcsQ7PlbZKHpzJn0CGefKRvoqfdMJysus4PwYIvi7IzqK/sIJnN4cvQw7rgQOLcLYERLr0OlLDvu6MtU0JsUJBHT94yE7n/9q RqDyJ5cHe1ZEDu2Z6Q7KEvnd9E44MLiAeJOsuJW2ersUJj/v8mmEly76xpnKOU5V/jIpj7YavZ57gwUJNE9/eZDlulJprKh2km9vLEWSBhVrUti62v+diOdA zh9ooAzs7IAom/hHSrN5q4SOku1p8QDbsZmwXmx3kq+mfdceg1/93c9njmkJdmCOuNoMOUBEDgM7fdmK2glhjewkQmL+xIx83rjWcwpIcuZDtAONHgQ= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Instead of reseeding the random number generator every time around the loop in big_gang_check(), seed it at the beginning of execution. Use rand_r() and an independent base seed for each thread in iteration_test() so they don't stomp all over each others state. Since this particular test depends on the kernel scheduler, the iteration test can't be reproduced based purely on the random seed, but at least it won't pollute the other tests. Print the seed, and allow the seed to be specified so that a run which hits a problem can be reproduced. Signed-off-by: Matthew Wilcox --- tools/testing/radix-tree/iteration_check.c | 11 +++++++---- tools/testing/radix-tree/main.c | 9 +++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/radix-tree/iteration_check.c b/tools/testing/radix-tree/iteration_check.c index 9adb8e7..11d570c 100644 --- a/tools/testing/radix-tree/iteration_check.c +++ b/tools/testing/radix-tree/iteration_check.c @@ -20,6 +20,7 @@ #define TAG 0 static pthread_mutex_t tree_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t threads[NUM_THREADS]; +static unsigned int seeds[3]; RADIX_TREE(tree, GFP_KERNEL); bool test_complete; @@ -71,7 +72,7 @@ static void *tagged_iteration_fn(void *arg) continue; } - if (rand() % 50 == 0) + if (rand_r(&seeds[0]) % 50 == 0) slot = radix_tree_iter_next(&iter); } rcu_read_unlock(); @@ -111,7 +112,7 @@ static void *untagged_iteration_fn(void *arg) continue; } - if (rand() % 50 == 0) + if (rand_r(&seeds[1]) % 50 == 0) slot = radix_tree_iter_next(&iter); } rcu_read_unlock(); @@ -129,7 +130,7 @@ static void *remove_entries_fn(void *arg) while (!test_complete) { int pgoff; - pgoff = rand() % 100; + pgoff = rand_r(&seeds[2]) % 100; pthread_mutex_lock(&tree_lock); item_delete(&tree, pgoff); @@ -146,9 +147,11 @@ void iteration_test(void) printf("Running iteration tests for 10 seconds\n"); - srand(time(0)); test_complete = false; + for (i = 0; i < 3; i++) + seeds[i] = rand(); + if (pthread_create(&threads[0], NULL, tagged_iteration_fn, NULL)) { perror("pthread_create"); exit(1); diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c index 2930560..5ddec8e 100644 --- a/tools/testing/radix-tree/main.c +++ b/tools/testing/radix-tree/main.c @@ -67,7 +67,6 @@ void big_gang_check(bool long_run) for (i = 0; i < (long_run ? 1000 : 3); i++) { __big_gang_check(); - srand(time(0)); printf("%d ", i); fflush(stdout); } @@ -329,12 +328,18 @@ int main(int argc, char **argv) { bool long_run = false; int opt; + unsigned int seed = time(NULL); - while ((opt = getopt(argc, argv, "l")) != -1) { + while ((opt = getopt(argc, argv, "ls:")) != -1) { if (opt == 'l') long_run = true; + else if (opt == 's') + seed = strtoul(optarg, NULL, 0); } + printf("random seed %u\n", seed); + srand(seed); + rcu_register_thread(); radix_tree_init(); -- 2.10.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Matthew Wilcox To: linux-kernel@vger.kernel.org, Andrew Morton , Konstantin Khlebnikov , Ross Zwisler Cc: linux-fsdevel@vger.kernel.org, Matthew Wilcox , linux-mm@kvack.org, "Kirill A . Shutemov" Subject: [PATCH 05/29] radix tree test suite: Make runs more reproducible Date: Wed, 16 Nov 2016 16:16:30 -0800 Message-Id: <1479341856-30320-6-git-send-email-mawilcox@linuxonhyperv.com> In-Reply-To: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> References: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> Sender: owner-linux-mm@kvack.org List-ID: From: Matthew Wilcox Instead of reseeding the random number generator every time around the loop in big_gang_check(), seed it at the beginning of execution. Use rand_r() and an independent base seed for each thread in iteration_test() so they don't stomp all over each others state. Since this particular test depends on the kernel scheduler, the iteration test can't be reproduced based purely on the random seed, but at least it won't pollute the other tests. Print the seed, and allow the seed to be specified so that a run which hits a problem can be reproduced. Signed-off-by: Matthew Wilcox --- tools/testing/radix-tree/iteration_check.c | 11 +++++++---- tools/testing/radix-tree/main.c | 9 +++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/radix-tree/iteration_check.c b/tools/testing/radix-tree/iteration_check.c index 9adb8e7..11d570c 100644 --- a/tools/testing/radix-tree/iteration_check.c +++ b/tools/testing/radix-tree/iteration_check.c @@ -20,6 +20,7 @@ #define TAG 0 static pthread_mutex_t tree_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t threads[NUM_THREADS]; +static unsigned int seeds[3]; RADIX_TREE(tree, GFP_KERNEL); bool test_complete; @@ -71,7 +72,7 @@ static void *tagged_iteration_fn(void *arg) continue; } - if (rand() % 50 == 0) + if (rand_r(&seeds[0]) % 50 == 0) slot = radix_tree_iter_next(&iter); } rcu_read_unlock(); @@ -111,7 +112,7 @@ static void *untagged_iteration_fn(void *arg) continue; } - if (rand() % 50 == 0) + if (rand_r(&seeds[1]) % 50 == 0) slot = radix_tree_iter_next(&iter); } rcu_read_unlock(); @@ -129,7 +130,7 @@ static void *remove_entries_fn(void *arg) while (!test_complete) { int pgoff; - pgoff = rand() % 100; + pgoff = rand_r(&seeds[2]) % 100; pthread_mutex_lock(&tree_lock); item_delete(&tree, pgoff); @@ -146,9 +147,11 @@ void iteration_test(void) printf("Running iteration tests for 10 seconds\n"); - srand(time(0)); test_complete = false; + for (i = 0; i < 3; i++) + seeds[i] = rand(); + if (pthread_create(&threads[0], NULL, tagged_iteration_fn, NULL)) { perror("pthread_create"); exit(1); diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c index 2930560..5ddec8e 100644 --- a/tools/testing/radix-tree/main.c +++ b/tools/testing/radix-tree/main.c @@ -67,7 +67,6 @@ void big_gang_check(bool long_run) for (i = 0; i < (long_run ? 1000 : 3); i++) { __big_gang_check(); - srand(time(0)); printf("%d ", i); fflush(stdout); } @@ -329,12 +328,18 @@ int main(int argc, char **argv) { bool long_run = false; int opt; + unsigned int seed = time(NULL); - while ((opt = getopt(argc, argv, "l")) != -1) { + while ((opt = getopt(argc, argv, "ls:")) != -1) { if (opt == 'l') long_run = true; + else if (opt == 's') + seed = strtoul(optarg, NULL, 0); } + printf("random seed %u\n", seed); + srand(seed); + rcu_register_thread(); radix_tree_init(); -- 2.10.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org