0001
0002
0003
0004
0005
0006
0007
0008
0009 #define pr_fmt(fmt) fmt
0010
0011 #include <linux/atomic.h>
0012 #include <linux/bitops.h>
0013 #include <linux/completion.h>
0014 #include <linux/cpu.h>
0015 #include <linux/delay.h>
0016 #include <linux/err.h>
0017 #include <linux/init.h>
0018 #include <linux/interrupt.h>
0019 #include <linux/kthread.h>
0020 #include <linux/kernel.h>
0021 #include <linux/mm.h>
0022 #include <linux/module.h>
0023 #include <linux/moduleparam.h>
0024 #include <linux/notifier.h>
0025 #include <linux/percpu.h>
0026 #include <linux/rcupdate.h>
0027 #include <linux/rcupdate_trace.h>
0028 #include <linux/reboot.h>
0029 #include <linux/sched.h>
0030 #include <linux/spinlock.h>
0031 #include <linux/smp.h>
0032 #include <linux/stat.h>
0033 #include <linux/srcu.h>
0034 #include <linux/slab.h>
0035 #include <linux/torture.h>
0036 #include <linux/types.h>
0037
0038 #define SCFTORT_STRING "scftorture"
0039 #define SCFTORT_FLAG SCFTORT_STRING ": "
0040
0041 #define VERBOSE_SCFTORTOUT(s, x...) \
0042 do { if (verbose) pr_alert(SCFTORT_FLAG s "\n", ## x); } while (0)
0043
0044 #define SCFTORTOUT_ERRSTRING(s, x...) pr_alert(SCFTORT_FLAG "!!! " s "\n", ## x)
0045
0046 MODULE_LICENSE("GPL");
0047 MODULE_AUTHOR("Paul E. McKenney <paulmck@kernel.org>");
0048
0049
0050 torture_param(int, holdoff, IS_BUILTIN(CONFIG_SCF_TORTURE_TEST) ? 10 : 0,
0051 "Holdoff time before test start (s)");
0052 torture_param(int, longwait, 0, "Include ridiculously long waits? (seconds)");
0053 torture_param(int, nthreads, -1, "# threads, defaults to -1 for all CPUs.");
0054 torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
0055 torture_param(int, onoff_interval, 0, "Time between CPU hotplugs (s), 0=disable");
0056 torture_param(int, shutdown_secs, 0, "Shutdown time (ms), <= zero to disable.");
0057 torture_param(int, stat_interval, 60, "Number of seconds between stats printk()s.");
0058 torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable");
0059 torture_param(bool, use_cpus_read_lock, 0, "Use cpus_read_lock() to exclude CPU hotplug.");
0060 torture_param(int, verbose, 0, "Enable verbose debugging printk()s");
0061 torture_param(int, weight_resched, -1, "Testing weight for resched_cpu() operations.");
0062 torture_param(int, weight_single, -1, "Testing weight for single-CPU no-wait operations.");
0063 torture_param(int, weight_single_rpc, -1, "Testing weight for single-CPU RPC operations.");
0064 torture_param(int, weight_single_wait, -1, "Testing weight for single-CPU operations.");
0065 torture_param(int, weight_many, -1, "Testing weight for multi-CPU no-wait operations.");
0066 torture_param(int, weight_many_wait, -1, "Testing weight for multi-CPU operations.");
0067 torture_param(int, weight_all, -1, "Testing weight for all-CPU no-wait operations.");
0068 torture_param(int, weight_all_wait, -1, "Testing weight for all-CPU operations.");
0069
0070 char *torture_type = "";
0071
0072 #ifdef MODULE
0073 # define SCFTORT_SHUTDOWN 0
0074 #else
0075 # define SCFTORT_SHUTDOWN 1
0076 #endif
0077
0078 torture_param(bool, shutdown, SCFTORT_SHUTDOWN, "Shutdown at end of torture test.");
0079
0080 struct scf_statistics {
0081 struct task_struct *task;
0082 int cpu;
0083 long long n_resched;
0084 long long n_single;
0085 long long n_single_ofl;
0086 long long n_single_rpc;
0087 long long n_single_rpc_ofl;
0088 long long n_single_wait;
0089 long long n_single_wait_ofl;
0090 long long n_many;
0091 long long n_many_wait;
0092 long long n_all;
0093 long long n_all_wait;
0094 };
0095
0096 static struct scf_statistics *scf_stats_p;
0097 static struct task_struct *scf_torture_stats_task;
0098 static DEFINE_PER_CPU(long long, scf_invoked_count);
0099
0100
0101 #define SCF_PRIM_RESCHED 0
0102 #define SCF_PRIM_SINGLE 1
0103 #define SCF_PRIM_SINGLE_RPC 2
0104 #define SCF_PRIM_MANY 3
0105 #define SCF_PRIM_ALL 4
0106 #define SCF_NPRIMS 8
0107
0108
0109
0110 static char *scf_prim_name[] = {
0111 "resched_cpu",
0112 "smp_call_function_single",
0113 "smp_call_function_single_rpc",
0114 "smp_call_function_many",
0115 "smp_call_function",
0116 };
0117
0118 struct scf_selector {
0119 unsigned long scfs_weight;
0120 int scfs_prim;
0121 bool scfs_wait;
0122 };
0123 static struct scf_selector scf_sel_array[SCF_NPRIMS];
0124 static int scf_sel_array_len;
0125 static unsigned long scf_sel_totweight;
0126
0127
0128 struct scf_check {
0129 bool scfc_in;
0130 bool scfc_out;
0131 int scfc_cpu;
0132 bool scfc_wait;
0133 bool scfc_rpc;
0134 struct completion scfc_completion;
0135 };
0136
0137
0138 static atomic_t n_started;
0139 static atomic_t n_errs;
0140 static atomic_t n_mb_in_errs;
0141 static atomic_t n_mb_out_errs;
0142 static atomic_t n_alloc_errs;
0143 static bool scfdone;
0144 static char *bangstr = "";
0145
0146 static DEFINE_TORTURE_RANDOM_PERCPU(scf_torture_rand);
0147
0148 extern void resched_cpu(int cpu);
0149
0150
0151 static void scf_torture_stats_print(void)
0152 {
0153 int cpu;
0154 int i;
0155 long long invoked_count = 0;
0156 bool isdone = READ_ONCE(scfdone);
0157 struct scf_statistics scfs = {};
0158
0159 for_each_possible_cpu(cpu)
0160 invoked_count += data_race(per_cpu(scf_invoked_count, cpu));
0161 for (i = 0; i < nthreads; i++) {
0162 scfs.n_resched += scf_stats_p[i].n_resched;
0163 scfs.n_single += scf_stats_p[i].n_single;
0164 scfs.n_single_ofl += scf_stats_p[i].n_single_ofl;
0165 scfs.n_single_rpc += scf_stats_p[i].n_single_rpc;
0166 scfs.n_single_wait += scf_stats_p[i].n_single_wait;
0167 scfs.n_single_wait_ofl += scf_stats_p[i].n_single_wait_ofl;
0168 scfs.n_many += scf_stats_p[i].n_many;
0169 scfs.n_many_wait += scf_stats_p[i].n_many_wait;
0170 scfs.n_all += scf_stats_p[i].n_all;
0171 scfs.n_all_wait += scf_stats_p[i].n_all_wait;
0172 }
0173 if (atomic_read(&n_errs) || atomic_read(&n_mb_in_errs) ||
0174 atomic_read(&n_mb_out_errs) || atomic_read(&n_alloc_errs))
0175 bangstr = "!!! ";
0176 pr_alert("%s %sscf_invoked_count %s: %lld resched: %lld single: %lld/%lld single_ofl: %lld/%lld single_rpc: %lld single_rpc_ofl: %lld many: %lld/%lld all: %lld/%lld ",
0177 SCFTORT_FLAG, bangstr, isdone ? "VER" : "ver", invoked_count, scfs.n_resched,
0178 scfs.n_single, scfs.n_single_wait, scfs.n_single_ofl, scfs.n_single_wait_ofl,
0179 scfs.n_single_rpc, scfs.n_single_rpc_ofl,
0180 scfs.n_many, scfs.n_many_wait, scfs.n_all, scfs.n_all_wait);
0181 torture_onoff_stats();
0182 pr_cont("ste: %d stnmie: %d stnmoe: %d staf: %d\n", atomic_read(&n_errs),
0183 atomic_read(&n_mb_in_errs), atomic_read(&n_mb_out_errs),
0184 atomic_read(&n_alloc_errs));
0185 }
0186
0187
0188
0189 static int
0190 scf_torture_stats(void *arg)
0191 {
0192 VERBOSE_TOROUT_STRING("scf_torture_stats task started");
0193 do {
0194 schedule_timeout_interruptible(stat_interval * HZ);
0195 scf_torture_stats_print();
0196 torture_shutdown_absorb("scf_torture_stats");
0197 } while (!torture_must_stop());
0198 torture_kthread_stopping("scf_torture_stats");
0199 return 0;
0200 }
0201
0202
0203 static void scf_sel_add(unsigned long weight, int prim, bool wait)
0204 {
0205 struct scf_selector *scfsp = &scf_sel_array[scf_sel_array_len];
0206
0207
0208
0209
0210 if (!weight ||
0211 WARN_ON_ONCE(scf_sel_array_len >= ARRAY_SIZE(scf_sel_array)) ||
0212 WARN_ON_ONCE(0 - 100000 * weight <= 100000 * scf_sel_totweight) ||
0213 WARN_ON_ONCE(prim >= ARRAY_SIZE(scf_prim_name)))
0214 return;
0215 scf_sel_totweight += weight;
0216 scfsp->scfs_weight = scf_sel_totweight;
0217 scfsp->scfs_prim = prim;
0218 scfsp->scfs_wait = wait;
0219 scf_sel_array_len++;
0220 }
0221
0222
0223 static void scf_sel_dump(void)
0224 {
0225 int i;
0226 unsigned long oldw = 0;
0227 struct scf_selector *scfsp;
0228 unsigned long w;
0229
0230 for (i = 0; i < scf_sel_array_len; i++) {
0231 scfsp = &scf_sel_array[i];
0232 w = (scfsp->scfs_weight - oldw) * 100000 / scf_sel_totweight;
0233 pr_info("%s: %3lu.%03lu %s(%s)\n", __func__, w / 1000, w % 1000,
0234 scf_prim_name[scfsp->scfs_prim],
0235 scfsp->scfs_wait ? "wait" : "nowait");
0236 oldw = scfsp->scfs_weight;
0237 }
0238 }
0239
0240
0241 static struct scf_selector *scf_sel_rand(struct torture_random_state *trsp)
0242 {
0243 int i;
0244 unsigned long w = torture_random(trsp) % (scf_sel_totweight + 1);
0245
0246 for (i = 0; i < scf_sel_array_len; i++)
0247 if (scf_sel_array[i].scfs_weight >= w)
0248 return &scf_sel_array[i];
0249 WARN_ON_ONCE(1);
0250 return &scf_sel_array[0];
0251 }
0252
0253
0254
0255
0256 static void scf_handler(void *scfc_in)
0257 {
0258 int i;
0259 int j;
0260 unsigned long r = torture_random(this_cpu_ptr(&scf_torture_rand));
0261 struct scf_check *scfcp = scfc_in;
0262
0263 if (likely(scfcp)) {
0264 WRITE_ONCE(scfcp->scfc_out, false);
0265 if (WARN_ON_ONCE(unlikely(!READ_ONCE(scfcp->scfc_in))))
0266 atomic_inc(&n_mb_in_errs);
0267 }
0268 this_cpu_inc(scf_invoked_count);
0269 if (longwait <= 0) {
0270 if (!(r & 0xffc0)) {
0271 udelay(r & 0x3f);
0272 goto out;
0273 }
0274 }
0275 if (r & 0xfff)
0276 goto out;
0277 r = (r >> 12);
0278 if (longwait <= 0) {
0279 udelay((r & 0xff) + 1);
0280 goto out;
0281 }
0282 r = r % longwait + 1;
0283 for (i = 0; i < r; i++) {
0284 for (j = 0; j < 1000; j++) {
0285 udelay(1000);
0286 cpu_relax();
0287 }
0288 }
0289 out:
0290 if (unlikely(!scfcp))
0291 return;
0292 if (scfcp->scfc_wait) {
0293 WRITE_ONCE(scfcp->scfc_out, true);
0294 if (scfcp->scfc_rpc)
0295 complete(&scfcp->scfc_completion);
0296 } else {
0297 kfree(scfcp);
0298 }
0299 }
0300
0301
0302 static void scf_handler_1(void *scfc_in)
0303 {
0304 struct scf_check *scfcp = scfc_in;
0305
0306 if (likely(scfcp) && WARN_ONCE(smp_processor_id() != scfcp->scfc_cpu, "%s: Wanted CPU %d got CPU %d\n", __func__, scfcp->scfc_cpu, smp_processor_id())) {
0307 atomic_inc(&n_errs);
0308 }
0309 scf_handler(scfcp);
0310 }
0311
0312
0313 static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_random_state *trsp)
0314 {
0315 uintptr_t cpu;
0316 int ret = 0;
0317 struct scf_check *scfcp = NULL;
0318 struct scf_selector *scfsp = scf_sel_rand(trsp);
0319
0320 if (use_cpus_read_lock)
0321 cpus_read_lock();
0322 else
0323 preempt_disable();
0324 if (scfsp->scfs_prim == SCF_PRIM_SINGLE || scfsp->scfs_wait) {
0325 scfcp = kmalloc(sizeof(*scfcp), GFP_ATOMIC);
0326 if (WARN_ON_ONCE(!scfcp)) {
0327 atomic_inc(&n_alloc_errs);
0328 } else {
0329 scfcp->scfc_cpu = -1;
0330 scfcp->scfc_wait = scfsp->scfs_wait;
0331 scfcp->scfc_out = false;
0332 scfcp->scfc_rpc = false;
0333 }
0334 }
0335 switch (scfsp->scfs_prim) {
0336 case SCF_PRIM_RESCHED:
0337 if (IS_BUILTIN(CONFIG_SCF_TORTURE_TEST)) {
0338 cpu = torture_random(trsp) % nr_cpu_ids;
0339 scfp->n_resched++;
0340 resched_cpu(cpu);
0341 this_cpu_inc(scf_invoked_count);
0342 }
0343 break;
0344 case SCF_PRIM_SINGLE:
0345 cpu = torture_random(trsp) % nr_cpu_ids;
0346 if (scfsp->scfs_wait)
0347 scfp->n_single_wait++;
0348 else
0349 scfp->n_single++;
0350 if (scfcp) {
0351 scfcp->scfc_cpu = cpu;
0352 barrier();
0353 scfcp->scfc_in = true;
0354 }
0355 ret = smp_call_function_single(cpu, scf_handler_1, (void *)scfcp, scfsp->scfs_wait);
0356 if (ret) {
0357 if (scfsp->scfs_wait)
0358 scfp->n_single_wait_ofl++;
0359 else
0360 scfp->n_single_ofl++;
0361 kfree(scfcp);
0362 scfcp = NULL;
0363 }
0364 break;
0365 case SCF_PRIM_SINGLE_RPC:
0366 if (!scfcp)
0367 break;
0368 cpu = torture_random(trsp) % nr_cpu_ids;
0369 scfp->n_single_rpc++;
0370 scfcp->scfc_cpu = cpu;
0371 scfcp->scfc_wait = true;
0372 init_completion(&scfcp->scfc_completion);
0373 scfcp->scfc_rpc = true;
0374 barrier();
0375 scfcp->scfc_in = true;
0376 ret = smp_call_function_single(cpu, scf_handler_1, (void *)scfcp, 0);
0377 if (!ret) {
0378 if (use_cpus_read_lock)
0379 cpus_read_unlock();
0380 else
0381 preempt_enable();
0382 wait_for_completion(&scfcp->scfc_completion);
0383 if (use_cpus_read_lock)
0384 cpus_read_lock();
0385 else
0386 preempt_disable();
0387 } else {
0388 scfp->n_single_rpc_ofl++;
0389 kfree(scfcp);
0390 scfcp = NULL;
0391 }
0392 break;
0393 case SCF_PRIM_MANY:
0394 if (scfsp->scfs_wait)
0395 scfp->n_many_wait++;
0396 else
0397 scfp->n_many++;
0398 if (scfcp) {
0399 barrier();
0400 scfcp->scfc_in = true;
0401 }
0402 smp_call_function_many(cpu_online_mask, scf_handler, scfcp, scfsp->scfs_wait);
0403 break;
0404 case SCF_PRIM_ALL:
0405 if (scfsp->scfs_wait)
0406 scfp->n_all_wait++;
0407 else
0408 scfp->n_all++;
0409 if (scfcp) {
0410 barrier();
0411 scfcp->scfc_in = true;
0412 }
0413 smp_call_function(scf_handler, scfcp, scfsp->scfs_wait);
0414 break;
0415 default:
0416 WARN_ON_ONCE(1);
0417 if (scfcp)
0418 scfcp->scfc_out = true;
0419 }
0420 if (scfcp && scfsp->scfs_wait) {
0421 if (WARN_ON_ONCE((num_online_cpus() > 1 || scfsp->scfs_prim == SCF_PRIM_SINGLE) &&
0422 !scfcp->scfc_out)) {
0423 pr_warn("%s: Memory-ordering failure, scfs_prim: %d.\n", __func__, scfsp->scfs_prim);
0424 atomic_inc(&n_mb_out_errs);
0425 } else {
0426 kfree(scfcp);
0427 }
0428 barrier();
0429 }
0430 if (use_cpus_read_lock)
0431 cpus_read_unlock();
0432 else
0433 preempt_enable();
0434 if (!(torture_random(trsp) & 0xfff))
0435 schedule_timeout_uninterruptible(1);
0436 }
0437
0438
0439
0440 static int scftorture_invoker(void *arg)
0441 {
0442 int cpu;
0443 int curcpu;
0444 DEFINE_TORTURE_RANDOM(rand);
0445 struct scf_statistics *scfp = (struct scf_statistics *)arg;
0446 bool was_offline = false;
0447
0448 VERBOSE_SCFTORTOUT("scftorture_invoker %d: task started", scfp->cpu);
0449 cpu = scfp->cpu % nr_cpu_ids;
0450 WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
0451 set_user_nice(current, MAX_NICE);
0452 if (holdoff)
0453 schedule_timeout_interruptible(holdoff * HZ);
0454
0455 VERBOSE_SCFTORTOUT("scftorture_invoker %d: Waiting for all SCF torturers from cpu %d", scfp->cpu, raw_smp_processor_id());
0456
0457
0458 curcpu = raw_smp_processor_id();
0459 WARN_ONCE(curcpu != scfp->cpu % nr_cpu_ids,
0460 "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
0461 __func__, scfp->cpu, curcpu, nr_cpu_ids);
0462
0463 if (!atomic_dec_return(&n_started))
0464 while (atomic_read_acquire(&n_started)) {
0465 if (torture_must_stop()) {
0466 VERBOSE_SCFTORTOUT("scftorture_invoker %d ended before starting", scfp->cpu);
0467 goto end;
0468 }
0469 schedule_timeout_uninterruptible(1);
0470 }
0471
0472 VERBOSE_SCFTORTOUT("scftorture_invoker %d started", scfp->cpu);
0473
0474 do {
0475 scftorture_invoke_one(scfp, &rand);
0476 while (cpu_is_offline(cpu) && !torture_must_stop()) {
0477 schedule_timeout_interruptible(HZ / 5);
0478 was_offline = true;
0479 }
0480 if (was_offline) {
0481 set_cpus_allowed_ptr(current, cpumask_of(cpu));
0482 was_offline = false;
0483 }
0484 cond_resched();
0485 stutter_wait("scftorture_invoker");
0486 } while (!torture_must_stop());
0487
0488 VERBOSE_SCFTORTOUT("scftorture_invoker %d ended", scfp->cpu);
0489 end:
0490 torture_kthread_stopping("scftorture_invoker");
0491 return 0;
0492 }
0493
0494 static void
0495 scftorture_print_module_parms(const char *tag)
0496 {
0497 pr_alert(SCFTORT_FLAG
0498 "--- %s: verbose=%d holdoff=%d longwait=%d nthreads=%d onoff_holdoff=%d onoff_interval=%d shutdown_secs=%d stat_interval=%d stutter=%d use_cpus_read_lock=%d, weight_resched=%d, weight_single=%d, weight_single_rpc=%d, weight_single_wait=%d, weight_many=%d, weight_many_wait=%d, weight_all=%d, weight_all_wait=%d\n", tag,
0499 verbose, holdoff, longwait, nthreads, onoff_holdoff, onoff_interval, shutdown, stat_interval, stutter, use_cpus_read_lock, weight_resched, weight_single, weight_single_rpc, weight_single_wait, weight_many, weight_many_wait, weight_all, weight_all_wait);
0500 }
0501
0502 static void scf_cleanup_handler(void *unused)
0503 {
0504 }
0505
0506 static void scf_torture_cleanup(void)
0507 {
0508 int i;
0509
0510 if (torture_cleanup_begin())
0511 return;
0512
0513 WRITE_ONCE(scfdone, true);
0514 if (nthreads && scf_stats_p)
0515 for (i = 0; i < nthreads; i++)
0516 torture_stop_kthread("scftorture_invoker", scf_stats_p[i].task);
0517 else
0518 goto end;
0519 smp_call_function(scf_cleanup_handler, NULL, 0);
0520 torture_stop_kthread(scf_torture_stats, scf_torture_stats_task);
0521 scf_torture_stats_print();
0522 kfree(scf_stats_p);
0523 scf_stats_p = NULL;
0524
0525 if (atomic_read(&n_errs) || atomic_read(&n_mb_in_errs) || atomic_read(&n_mb_out_errs))
0526 scftorture_print_module_parms("End of test: FAILURE");
0527 else if (torture_onoff_failures())
0528 scftorture_print_module_parms("End of test: LOCK_HOTPLUG");
0529 else
0530 scftorture_print_module_parms("End of test: SUCCESS");
0531
0532 end:
0533 torture_cleanup_end();
0534 }
0535
0536 static int __init scf_torture_init(void)
0537 {
0538 long i;
0539 int firsterr = 0;
0540 unsigned long weight_resched1 = weight_resched;
0541 unsigned long weight_single1 = weight_single;
0542 unsigned long weight_single_rpc1 = weight_single_rpc;
0543 unsigned long weight_single_wait1 = weight_single_wait;
0544 unsigned long weight_many1 = weight_many;
0545 unsigned long weight_many_wait1 = weight_many_wait;
0546 unsigned long weight_all1 = weight_all;
0547 unsigned long weight_all_wait1 = weight_all_wait;
0548
0549 if (!torture_init_begin(SCFTORT_STRING, verbose))
0550 return -EBUSY;
0551
0552 scftorture_print_module_parms("Start of test");
0553
0554 if (weight_resched <= 0 &&
0555 weight_single <= 0 && weight_single_rpc <= 0 && weight_single_wait <= 0 &&
0556 weight_many <= 0 && weight_many_wait <= 0 &&
0557 weight_all <= 0 && weight_all_wait <= 0) {
0558 weight_resched1 = weight_resched == 0 ? 0 : 2 * nr_cpu_ids;
0559 weight_single1 = weight_single == 0 ? 0 : 2 * nr_cpu_ids;
0560 weight_single_rpc1 = weight_single_rpc == 0 ? 0 : 2 * nr_cpu_ids;
0561 weight_single_wait1 = weight_single_wait == 0 ? 0 : 2 * nr_cpu_ids;
0562 weight_many1 = weight_many == 0 ? 0 : 2;
0563 weight_many_wait1 = weight_many_wait == 0 ? 0 : 2;
0564 weight_all1 = weight_all == 0 ? 0 : 1;
0565 weight_all_wait1 = weight_all_wait == 0 ? 0 : 1;
0566 } else {
0567 if (weight_resched == -1)
0568 weight_resched1 = 0;
0569 if (weight_single == -1)
0570 weight_single1 = 0;
0571 if (weight_single_rpc == -1)
0572 weight_single_rpc1 = 0;
0573 if (weight_single_wait == -1)
0574 weight_single_wait1 = 0;
0575 if (weight_many == -1)
0576 weight_many1 = 0;
0577 if (weight_many_wait == -1)
0578 weight_many_wait1 = 0;
0579 if (weight_all == -1)
0580 weight_all1 = 0;
0581 if (weight_all_wait == -1)
0582 weight_all_wait1 = 0;
0583 }
0584 if (weight_resched1 == 0 && weight_single1 == 0 && weight_single_rpc1 == 0 &&
0585 weight_single_wait1 == 0 && weight_many1 == 0 && weight_many_wait1 == 0 &&
0586 weight_all1 == 0 && weight_all_wait1 == 0) {
0587 SCFTORTOUT_ERRSTRING("all zero weights makes no sense");
0588 firsterr = -EINVAL;
0589 goto unwind;
0590 }
0591 if (IS_BUILTIN(CONFIG_SCF_TORTURE_TEST))
0592 scf_sel_add(weight_resched1, SCF_PRIM_RESCHED, false);
0593 else if (weight_resched1)
0594 SCFTORTOUT_ERRSTRING("built as module, weight_resched ignored");
0595 scf_sel_add(weight_single1, SCF_PRIM_SINGLE, false);
0596 scf_sel_add(weight_single_rpc1, SCF_PRIM_SINGLE_RPC, true);
0597 scf_sel_add(weight_single_wait1, SCF_PRIM_SINGLE, true);
0598 scf_sel_add(weight_many1, SCF_PRIM_MANY, false);
0599 scf_sel_add(weight_many_wait1, SCF_PRIM_MANY, true);
0600 scf_sel_add(weight_all1, SCF_PRIM_ALL, false);
0601 scf_sel_add(weight_all_wait1, SCF_PRIM_ALL, true);
0602 scf_sel_dump();
0603
0604 if (onoff_interval > 0) {
0605 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval, NULL);
0606 if (torture_init_error(firsterr))
0607 goto unwind;
0608 }
0609 if (shutdown_secs > 0) {
0610 firsterr = torture_shutdown_init(shutdown_secs, scf_torture_cleanup);
0611 if (torture_init_error(firsterr))
0612 goto unwind;
0613 }
0614 if (stutter > 0) {
0615 firsterr = torture_stutter_init(stutter, stutter);
0616 if (torture_init_error(firsterr))
0617 goto unwind;
0618 }
0619
0620
0621 if (nthreads < 0)
0622 nthreads = num_online_cpus();
0623 scf_stats_p = kcalloc(nthreads, sizeof(scf_stats_p[0]), GFP_KERNEL);
0624 if (!scf_stats_p) {
0625 SCFTORTOUT_ERRSTRING("out of memory");
0626 firsterr = -ENOMEM;
0627 goto unwind;
0628 }
0629
0630 VERBOSE_SCFTORTOUT("Starting %d smp_call_function() threads", nthreads);
0631
0632 atomic_set(&n_started, nthreads);
0633 for (i = 0; i < nthreads; i++) {
0634 scf_stats_p[i].cpu = i;
0635 firsterr = torture_create_kthread(scftorture_invoker, (void *)&scf_stats_p[i],
0636 scf_stats_p[i].task);
0637 if (torture_init_error(firsterr))
0638 goto unwind;
0639 }
0640 if (stat_interval > 0) {
0641 firsterr = torture_create_kthread(scf_torture_stats, NULL, scf_torture_stats_task);
0642 if (torture_init_error(firsterr))
0643 goto unwind;
0644 }
0645
0646 torture_init_end();
0647 return 0;
0648
0649 unwind:
0650 torture_init_end();
0651 scf_torture_cleanup();
0652 if (shutdown_secs) {
0653 WARN_ON(!IS_MODULE(CONFIG_SCF_TORTURE_TEST));
0654 kernel_power_off();
0655 }
0656 return firsterr;
0657 }
0658
0659 module_init(scf_torture_init);
0660 module_exit(scf_torture_cleanup);