{ "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test, }, { "vm_map_ram_test", vm_map_ram_test, }, { "no_block_alloc_test", no_block_alloc_test, true }, { "vrealloc_test", vrealloc_test, }, /* Add a new test case here. */}; struct test_case_data { int test_failed; int test_xfailed; int test_passed; u64 time;}; static struct test_driver { struct task_struct *task; struct test_case_data data[ARRAY_SIZE(test_case_array)]; unsigned long start; unsigned long stop;} *tdriver; static void shuffle_array(int *arr, int n){ int i, j; for (i = n - 1; i > 0; i--) { /* Cut the range. */ j = get_random_u32_below(i); /* Swap indexes. */ swap(arr[i], arr[j]); }} static int test_func(void *private){ struct test_driver *t = private; int random_array[ARRAY_SIZE(test_case_array)]; int index, i, j, ret; ktime_t kt; u64 delta; for (i = 0; i < ARRAY_SIZE(test_case_array); i++) random_array[i] = i; if (!sequential_test_order) shuffle_array(random_array, ARRAY_SIZE(test_case_array)); /* * Block until initialization is done. */ synchronize_srcu(&prepare_for_test_srcu); t->start = get_cycles(); for (i = 0; i < ARRAY_SIZE(test_case_array); i++) { index = random_array[i]; /* * Skip tests if run_test_mask has been specified. */ if (!((run_test_mask & (1 << index)) >> index)) continue; kt = ktime_get(); for (j = 0; j < test_repeat_count; j++) { ret = test_case_array[index].test_func(); if (!ret) t->data[index].test_passed++; else if (ret && test_case_array[index].xfail) t->data[index].test_xfailed++; else t->data[index].test_failed++; } /* * Take an average time that test took. */ delta = (u64) ktime_us_delta(ktime_get(), kt); do_div(delta, (u32) test_repeat_count); t->data[index].time = delta; } t->stop = get_cycles(); test_report_one_done(); /* * Wait for the kthread_stop() call. */ while (!kthread_should_stop()) msleep(10); return 0;} static intinit_test_configuration(void){ /* * A maximum number of workers is defined as hard-coded * value and set to USHRT_MAX. We add such gap just in * case and for potential heavy stressing. */ nr_threads = clamp(nr_threads, 1, (int) USHRT_MAX); /* Allocate the space for test instances. */ tdriver = kvzalloc_objs(*tdriver, nr_threads); if (tdriver == NULL) return -1; if (test_repeat_count <= 0) test_repeat_count = 1; if (test_loop_count <= 0) test_loop_count = 1; return 0;} static void do_concurrent_test(void){ int i, ret, idx; /* * Set some basic configurations plus sanity check. */ ret = init_test_configuration(); if (ret < 0) return; /* * Put on hold all workers. */ idx = srcu_read_lock(&prepare_for_test_srcu); for (i = 0; i < nr_threads; i++) { struct test_driver *t = &tdriver[i]; t->task = kthread_run(test_func, t, "vmalloc_test/%d", i); if (!IS_ERR(t->task)) /* Success. */ atomic_inc(&test_n_undone); else pr_err("Failed to start %d kthread\n", i); } /* * Now let the workers do their job. */ srcu_read_unlock(&prepare_for_test_srcu, idx); /* * Sleep quiet until all workers are done with 1 second * interval. Since the test can take a lot of time we * can run into a stack trace of the hung task. That is * why we go with completion_timeout and HZ value. */ do { ret = wait_for_completion_timeout(&test_all_done_comp, HZ); } while (!ret); for (i = 0; i < nr_threads; i++) { struct test_driver *t = &tdriver[i]; int j; if (!IS_ERR(t->task)) kthread_stop(t->task); for (j = 0; j < ARRAY_SIZE(test_case_array); j++) { if (!((run_test_mask & (1 << j)) >> j)) continue; pr_info( "Summary: %s passed: %d failed: %d xfailed: %d repeat: %d loops: %d avg: %llu usec\n", test_case_array[j].test_name, t->data[j].test_passed, t->data[j].test_failed, t->data[j].test_xfailed, test_repeat_count, test_loop_count, t->data[j].time); } pr_info("All test took worker%d=%lu cycles\n", i, t->stop - t->start); } kvfree(tdriver);} static int __init vmalloc_test_init(void){ do_concurrent_test(); /* Fail will directly unload the module */ return IS_BUILTIN(CONFIG_TEST_VMALLOC) ? 0:-EAGAIN;} #ifdef MODULEmodule_init(vmalloc_test_init)#elselate_initcall(vmalloc_test_init);#endif MODULE_LICENSE("GPL");MODULE_AUTHOR("Uladzislau Rezki");MODULE_DESCRIPTION("vmalloc test module");Lines 501–706 of 706. Previous lines
{ "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test, }, { "vm_map_ram_test", vm_map_ram_test, }, { "no_block_alloc_test", no_block_alloc_test, true }, { "vrealloc_test", vrealloc_test, }, /* Add a new test case here. */ }; struct test_case_data { int test_failed; int test_xfailed; int test_passed; u64 time; }; static struct test_driver { struct task_struct *task; struct test_case_data data[ARRAY_SIZE(test_case_array)]; unsigned long start; unsigned long stop; } *tdriver; static void shuffle_array(int *arr, int n) { int i, j; for (i = n - 1; i > 0; i--) { /* Cut the range. */ j = get_random_u32_below(i); /* Swap indexes. */ swap(arr[i], arr[j]); } } static int test_func(void *private) { struct test_driver *t = private; int random_array[ARRAY_SIZE(test_case_array)]; int index, i, j, ret; ktime_t kt; u64 delta; for (i = 0; i < ARRAY_SIZE(test_case_array); i++) random_array[i] = i; if (!sequential_test_order) shuffle_array(random_array, ARRAY_SIZE(test_case_array)); /* * Block until initialization is done. */ synchronize_srcu(&prepare_for_test_srcu); t->start = get_cycles(); for (i = 0; i < ARRAY_SIZE(test_case_array); i++) { index = random_array[i]; /* * Skip tests if run_test_mask has been specified. */ if (!((run_test_mask & (1 << index)) >> index)) continue; kt = ktime_get(); for (j = 0; j < test_repeat_count; j++) { ret = test_case_array[index].test_func(); if (!ret) t->data[index].test_passed++; else if (ret && test_case_array[index].xfail) t->data[index].test_xfailed++; else t->data[index].test_failed++; } /* * Take an average time that test took. */ delta = (u64) ktime_us_delta(ktime_get(), kt); do_div(delta, (u32) test_repeat_count); t->data[index].time = delta; } t->stop = get_cycles(); test_report_one_done(); /* * Wait for the kthread_stop() call. */ while (!kthread_should_stop()) msleep(10); return 0; } static int init_test_configuration(void) { /* * A maximum number of workers is defined as hard-coded * value and set to USHRT_MAX. We add such gap just in * case and for potential heavy stressing. */ nr_threads = clamp(nr_threads, 1, (int) USHRT_MAX); /* Allocate the space for test instances. */ tdriver = kvzalloc_objs(*tdriver, nr_threads); if (tdriver == NULL) return -1; if (test_repeat_count <= 0) test_repeat_count = 1; if (test_loop_count <= 0) test_loop_count = 1; return 0; } static void do_concurrent_test(void) { int i, ret, idx; /* * Set some basic configurations plus sanity check. */ ret = init_test_configuration(); if (ret < 0) return; /* * Put on hold all workers. */ idx = srcu_read_lock(&prepare_for_test_srcu); for (i = 0; i < nr_threads; i++) { struct test_driver *t = &tdriver[i]; t->task = kthread_run(test_func, t, "vmalloc_test/%d", i); if (!IS_ERR(t->task)) /* Success. */ atomic_inc(&test_n_undone); else pr_err("Failed to start %d kthread\n", i); } /* * Now let the workers do their job. */ srcu_read_unlock(&prepare_for_test_srcu, idx); /* * Sleep quiet until all workers are done with 1 second * interval. Since the test can take a lot of time we * can run into a stack trace of the hung task. That is * why we go with completion_timeout and HZ value. */ do { ret = wait_for_completion_timeout(&test_all_done_comp, HZ); } while (!ret); for (i = 0; i < nr_threads; i++) { struct test_driver *t = &tdriver[i]; int j; if (!IS_ERR(t->task)) kthread_stop(t->task); for (j = 0; j < ARRAY_SIZE(test_case_array); j++) { if (!((run_test_mask & (1 << j)) >> j)) continue; pr_info( "Summary: %s passed: %d failed: %d xfailed: %d repeat: %d loops: %d avg: %llu usec\n", test_case_array[j].test_name, t->data[j].test_passed, t->data[j].test_failed, t->data[j].test_xfailed, test_repeat_count, test_loop_count, t->data[j].time); } pr_info("All test took worker%d=%lu cycles\n", i, t->stop - t->start); } kvfree(tdriver); } static int __init vmalloc_test_init(void) { do_concurrent_test(); /* Fail will directly unload the module */ return IS_BUILTIN(CONFIG_TEST_VMALLOC) ? 0:-EAGAIN; } #ifdef MODULE module_init(vmalloc_test_init) #else late_initcall(vmalloc_test_init); #endif MODULE_LICENSE("GPL"); MODULE_AUTHOR("Uladzislau Rezki"); MODULE_DESCRIPTION("vmalloc test module");