blob: 7ad5c9681580732c62401836f3f63c8f4a187e37 [file] [log] [blame]
Paul E. McKenney8f8e76c2019-01-17 10:41:31 -08001// SPDX-License-Identifier: GPL-2.0+
Paul E. McKenney51b11302014-01-27 11:49:39 -08002/*
3 * Common functions for in-kernel torture tests.
4 *
Paul E. McKenney51b11302014-01-27 11:49:39 -08005 * Copyright (C) IBM Corporation, 2014
6 *
Paul E. McKenney8f8e76c2019-01-17 10:41:31 -08007 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
Paul E. McKenney51b11302014-01-27 11:49:39 -08008 * Based on kernel/rcu/torture.c.
9 */
Paul E. McKenney60500032018-05-15 12:25:05 -070010
11#define pr_fmt(fmt) fmt
12
Paul E. McKenney51b11302014-01-27 11:49:39 -080013#include <linux/types.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/kthread.h>
18#include <linux/err.h>
19#include <linux/spinlock.h>
20#include <linux/smp.h>
21#include <linux/interrupt.h>
22#include <linux/sched.h>
Ingo Molnare6017572017-02-01 16:36:40 +010023#include <linux/sched/clock.h>
Paul E. McKenney51b11302014-01-27 11:49:39 -080024#include <linux/atomic.h>
25#include <linux/bitops.h>
26#include <linux/completion.h>
27#include <linux/moduleparam.h>
28#include <linux/percpu.h>
29#include <linux/notifier.h>
30#include <linux/reboot.h>
31#include <linux/freezer.h>
32#include <linux/cpu.h>
33#include <linux/delay.h>
34#include <linux/stat.h>
35#include <linux/slab.h>
36#include <linux/trace_clock.h>
Paul E. McKenney31257c32016-06-18 07:45:43 -070037#include <linux/ktime.h>
Paul E. McKenney51b11302014-01-27 11:49:39 -080038#include <asm/byteorder.h>
39#include <linux/torture.h>
Paul E. McKenneydac95902017-10-04 11:23:10 -070040#include "rcu/rcu.h"
Paul E. McKenney51b11302014-01-27 11:49:39 -080041
42MODULE_LICENSE("GPL");
Paul E. McKenney8f8e76c2019-01-17 10:41:31 -080043MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
Paul E. McKenney51b11302014-01-27 11:49:39 -080044
Paul E. McKenney8171d3e2019-12-06 15:02:59 -080045static bool disable_onoff_at_boot;
46module_param(disable_onoff_at_boot, bool, 0444);
47
Paul E. McKenney2102ad22020-06-16 15:38:24 -070048static bool ftrace_dump_at_shutdown;
49module_param(ftrace_dump_at_shutdown, bool, 0444);
50
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080051static char *torture_type;
Paul E. McKenney90127d62018-05-09 10:29:18 -070052static int verbose;
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080053
Paul E. McKenney36970bb2014-01-30 15:49:29 -080054/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
55#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
56#define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */
57#define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */
58static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney4622b482014-01-30 15:37:19 -080059static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenneyf67a3352014-01-29 07:40:27 -080060
Paul E. McKenneyae19aaa2020-11-17 11:30:18 -080061/*
62 * Schedule a high-resolution-timer sleep in nanoseconds, with a 32-bit
63 * nanosecond random fuzz. This function and its friends desynchronize
64 * testing from the timer wheel.
65 */
66int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp)
67{
68 ktime_t hto = baset_ns;
69
70 if (trsp)
71 hto += (torture_random(trsp) >> 3) % fuzzt_ns;
72 set_current_state(TASK_UNINTERRUPTIBLE);
73 return schedule_hrtimeout(&hto, HRTIMER_MODE_REL);
74}
75EXPORT_SYMBOL_GPL(torture_hrtimeout_ns);
76
77/*
78 * Schedule a high-resolution-timer sleep in microseconds, with a 32-bit
79 * nanosecond (not microsecond!) random fuzz.
80 */
81int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp)
82{
83 ktime_t baset_ns = baset_us * NSEC_PER_USEC;
84
85 return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
86}
87EXPORT_SYMBOL_GPL(torture_hrtimeout_us);
88
89/*
90 * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
91 * microsecond (not millisecond!) random fuzz.
92 */
93int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp)
94{
95 ktime_t baset_ns = baset_ms * NSEC_PER_MSEC;
96 u32 fuzzt_ns;
97
98 if ((u32)~0U / NSEC_PER_USEC < fuzzt_us)
99 fuzzt_ns = (u32)~0U;
100 else
101 fuzzt_ns = fuzzt_us * NSEC_PER_USEC;
102 return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
103}
104EXPORT_SYMBOL_GPL(torture_hrtimeout_ms);
105
106/*
107 * Schedule a high-resolution-timer sleep in jiffies, with an
108 * implied one-jiffy random fuzz. This is intended to replace calls to
109 * schedule_timeout_interruptible() and friends.
110 */
111int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp)
112{
113 ktime_t baset_ns = jiffies_to_nsecs(baset_j);
114
115 return torture_hrtimeout_ns(baset_ns, jiffies_to_nsecs(1), trsp);
116}
117EXPORT_SYMBOL_GPL(torture_hrtimeout_jiffies);
118
119/*
120 * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
121 * millisecond (not second!) random fuzz.
122 */
123int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp)
124{
125 ktime_t baset_ns = baset_s * NSEC_PER_SEC;
126 u32 fuzzt_ns;
127
128 if ((u32)~0U / NSEC_PER_MSEC < fuzzt_ms)
129 fuzzt_ns = (u32)~0U;
130 else
131 fuzzt_ns = fuzzt_ms * NSEC_PER_MSEC;
132 return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
133}
134EXPORT_SYMBOL_GPL(torture_hrtimeout_s);
135
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800136#ifdef CONFIG_HOTPLUG_CPU
137
138/*
139 * Variables for online-offline handling. Only present if CPU hotplug
140 * is enabled, otherwise does nothing.
141 */
142
143static struct task_struct *onoff_task;
144static long onoff_holdoff;
145static long onoff_interval;
Paul E. McKenney3a6cb582018-12-10 09:44:52 -0800146static torture_ofl_func *onoff_f;
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800147static long n_offline_attempts;
148static long n_offline_successes;
149static unsigned long sum_offline;
150static int min_offline = -1;
151static int max_offline;
152static long n_online_attempts;
153static long n_online_successes;
154static unsigned long sum_online;
155static int min_online = -1;
156static int max_online;
157
158/*
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700159 * Attempt to take a CPU offline. Return false if the CPU is already
160 * offline or if it is not subject to CPU-hotplug operations. The
161 * caller can detect other failures by looking at the statistics.
162 */
163bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes,
164 unsigned long *sum_offl, int *min_offl, int *max_offl)
165{
166 unsigned long delta;
167 int ret;
Paul E. McKenneya59ee762019-12-05 10:49:11 -0800168 char *s;
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700169 unsigned long starttime;
170
171 if (!cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
172 return false;
Paul E. McKenney24aca4a2019-01-22 19:23:00 -0800173 if (num_online_cpus() <= 1)
174 return false; /* Can't offline the last CPU. */
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700175
Paul E. McKenney90127d62018-05-09 10:29:18 -0700176 if (verbose > 1)
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700177 pr_alert("%s" TORTURE_FLAG
178 "torture_onoff task: offlining %d\n",
179 torture_type, cpu);
180 starttime = jiffies;
181 (*n_offl_attempts)++;
Qais Yousef457bc8e2020-03-23 13:51:08 +0000182 ret = remove_cpu(cpu);
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700183 if (ret) {
Paul E. McKenneya59ee762019-12-05 10:49:11 -0800184 s = "";
185 if (!rcu_inkernel_boot_has_ended() && ret == -EBUSY) {
186 // PCI probe frequently disables hotplug during boot.
187 (*n_offl_attempts)--;
188 s = " (-EBUSY forgiven during boot)";
189 }
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700190 if (verbose)
191 pr_alert("%s" TORTURE_FLAG
Paul E. McKenneya59ee762019-12-05 10:49:11 -0800192 "torture_onoff task: offline %d failed%s: errno %d\n",
193 torture_type, cpu, s, ret);
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700194 } else {
Paul E. McKenney90127d62018-05-09 10:29:18 -0700195 if (verbose > 1)
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700196 pr_alert("%s" TORTURE_FLAG
197 "torture_onoff task: offlined %d\n",
198 torture_type, cpu);
Paul E. McKenney3a6cb582018-12-10 09:44:52 -0800199 if (onoff_f)
200 onoff_f();
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700201 (*n_offl_successes)++;
202 delta = jiffies - starttime;
Paul E. McKenneya2b2df22017-06-22 15:38:26 -0700203 *sum_offl += delta;
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700204 if (*min_offl < 0) {
205 *min_offl = delta;
206 *max_offl = delta;
207 }
208 if (*min_offl > delta)
209 *min_offl = delta;
210 if (*max_offl < delta)
211 *max_offl = delta;
212 }
213
214 return true;
215}
216EXPORT_SYMBOL_GPL(torture_offline);
217
218/*
219 * Attempt to bring a CPU online. Return false if the CPU is already
220 * online or if it is not subject to CPU-hotplug operations. The
221 * caller can detect other failures by looking at the statistics.
222 */
223bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
224 unsigned long *sum_onl, int *min_onl, int *max_onl)
225{
226 unsigned long delta;
227 int ret;
Paul E. McKenneya59ee762019-12-05 10:49:11 -0800228 char *s;
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700229 unsigned long starttime;
230
231 if (cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
232 return false;
233
Paul E. McKenney90127d62018-05-09 10:29:18 -0700234 if (verbose > 1)
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700235 pr_alert("%s" TORTURE_FLAG
236 "torture_onoff task: onlining %d\n",
237 torture_type, cpu);
238 starttime = jiffies;
239 (*n_onl_attempts)++;
Qais Yousef457bc8e2020-03-23 13:51:08 +0000240 ret = add_cpu(cpu);
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700241 if (ret) {
Paul E. McKenneya59ee762019-12-05 10:49:11 -0800242 s = "";
243 if (!rcu_inkernel_boot_has_ended() && ret == -EBUSY) {
244 // PCI probe frequently disables hotplug during boot.
245 (*n_onl_attempts)--;
246 s = " (-EBUSY forgiven during boot)";
247 }
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700248 if (verbose)
249 pr_alert("%s" TORTURE_FLAG
Paul E. McKenneya59ee762019-12-05 10:49:11 -0800250 "torture_onoff task: online %d failed%s: errno %d\n",
251 torture_type, cpu, s, ret);
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700252 } else {
Paul E. McKenney90127d62018-05-09 10:29:18 -0700253 if (verbose > 1)
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700254 pr_alert("%s" TORTURE_FLAG
255 "torture_onoff task: onlined %d\n",
256 torture_type, cpu);
257 (*n_onl_successes)++;
258 delta = jiffies - starttime;
259 *sum_onl += delta;
260 if (*min_onl < 0) {
261 *min_onl = delta;
262 *max_onl = delta;
263 }
264 if (*min_onl > delta)
265 *min_onl = delta;
266 if (*max_onl < delta)
267 *max_onl = delta;
268 }
269
270 return true;
271}
272EXPORT_SYMBOL_GPL(torture_online);
273
274/*
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800275 * Execute random CPU-hotplug operations at the interval specified
276 * by the onoff_interval.
277 */
278static int
279torture_onoff(void *arg)
280{
281 int cpu;
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800282 int maxcpu = -1;
283 DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenney28cf5952018-08-21 15:27:16 -0700284 int ret;
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800285
286 VERBOSE_TOROUT_STRING("torture_onoff task started");
287 for_each_online_cpu(cpu)
288 maxcpu = cpu;
289 WARN_ON(maxcpu < 0);
Qais Yousef457bc8e2020-03-23 13:51:08 +0000290 if (!IS_MODULE(CONFIG_TORTURE_TEST)) {
Paul E. McKenney28cf5952018-08-21 15:27:16 -0700291 for_each_possible_cpu(cpu) {
292 if (cpu_online(cpu))
293 continue;
Qais Yousef457bc8e2020-03-23 13:51:08 +0000294 ret = add_cpu(cpu);
Paul E. McKenney28cf5952018-08-21 15:27:16 -0700295 if (ret && verbose) {
296 pr_alert("%s" TORTURE_FLAG
297 "%s: Initial online %d: errno %d\n",
298 __func__, torture_type, cpu, ret);
299 }
300 }
Qais Yousef457bc8e2020-03-23 13:51:08 +0000301 }
Boqun Feng750db0f2016-05-02 10:30:00 +0800302
303 if (maxcpu == 0) {
304 VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is disabled");
305 goto stop;
306 }
307
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800308 if (onoff_holdoff > 0) {
309 VERBOSE_TOROUT_STRING("torture_onoff begin holdoff");
310 schedule_timeout_interruptible(onoff_holdoff);
311 VERBOSE_TOROUT_STRING("torture_onoff end holdoff");
312 }
313 while (!torture_must_stop()) {
Paul E. McKenney8171d3e2019-12-06 15:02:59 -0800314 if (disable_onoff_at_boot && !rcu_inkernel_boot_has_ended()) {
315 schedule_timeout_interruptible(HZ / 10);
316 continue;
317 }
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800318 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -0700319 if (!torture_offline(cpu,
320 &n_offline_attempts, &n_offline_successes,
321 &sum_offline, &min_offline, &max_offline))
322 torture_online(cpu,
323 &n_online_attempts, &n_online_successes,
324 &sum_online, &min_online, &max_online);
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800325 schedule_timeout_interruptible(onoff_interval);
326 }
Boqun Feng750db0f2016-05-02 10:30:00 +0800327
328stop:
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800329 torture_kthread_stopping("torture_onoff");
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800330 return 0;
331}
332
333#endif /* #ifdef CONFIG_HOTPLUG_CPU */
334
335/*
336 * Initiate online-offline handling.
337 */
Paul E. McKenney3a6cb582018-12-10 09:44:52 -0800338int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f)
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800339{
Paul E. McKenney47cf29b2014-02-03 11:52:27 -0800340#ifdef CONFIG_HOTPLUG_CPU
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800341 onoff_holdoff = ooholdoff;
342 onoff_interval = oointerval;
Paul E. McKenney3a6cb582018-12-10 09:44:52 -0800343 onoff_f = f;
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800344 if (onoff_interval <= 0)
345 return 0;
Pierce Griffiths2a7d9682018-09-21 20:21:31 -0500346 return torture_create_kthread(torture_onoff, NULL, onoff_task);
347#else /* #ifdef CONFIG_HOTPLUG_CPU */
348 return 0;
349#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800350}
351EXPORT_SYMBOL_GPL(torture_onoff_init);
352
353/*
354 * Clean up after online/offline testing.
355 */
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800356static void torture_onoff_cleanup(void)
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800357{
358#ifdef CONFIG_HOTPLUG_CPU
359 if (onoff_task == NULL)
360 return;
361 VERBOSE_TOROUT_STRING("Stopping torture_onoff task");
362 kthread_stop(onoff_task);
363 onoff_task = NULL;
364#endif /* #ifdef CONFIG_HOTPLUG_CPU */
365}
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800366
367/*
368 * Print online/offline testing statistics.
369 */
Joe Percheseea203f2014-07-14 09:16:15 -0400370void torture_onoff_stats(void)
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800371{
372#ifdef CONFIG_HOTPLUG_CPU
Joe Percheseea203f2014-07-14 09:16:15 -0400373 pr_cont("onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
374 n_online_successes, n_online_attempts,
375 n_offline_successes, n_offline_attempts,
376 min_online, max_online,
377 min_offline, max_offline,
378 sum_online, sum_offline, HZ);
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800379#endif /* #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800380}
381EXPORT_SYMBOL_GPL(torture_onoff_stats);
382
383/*
384 * Were all the online/offline operations successful?
385 */
386bool torture_onoff_failures(void)
387{
388#ifdef CONFIG_HOTPLUG_CPU
389 return n_online_successes != n_online_attempts ||
390 n_offline_successes != n_offline_attempts;
391#else /* #ifdef CONFIG_HOTPLUG_CPU */
392 return false;
393#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
394}
395EXPORT_SYMBOL_GPL(torture_onoff_failures);
396
Paul E. McKenney51b11302014-01-27 11:49:39 -0800397#define TORTURE_RANDOM_MULT 39916801 /* prime */
398#define TORTURE_RANDOM_ADD 479001701 /* prime */
399#define TORTURE_RANDOM_REFRESH 10000
400
401/*
402 * Crude but fast random-number generator. Uses a linear congruential
403 * generator, with occasional help from cpu_clock().
404 */
405unsigned long
406torture_random(struct torture_random_state *trsp)
407{
408 if (--trsp->trs_count < 0) {
409 trsp->trs_state += (unsigned long)local_clock();
410 trsp->trs_count = TORTURE_RANDOM_REFRESH;
411 }
412 trsp->trs_state = trsp->trs_state * TORTURE_RANDOM_MULT +
413 TORTURE_RANDOM_ADD;
414 return swahw32(trsp->trs_state);
415}
416EXPORT_SYMBOL_GPL(torture_random);
Paul E. McKenneyf67a3352014-01-29 07:40:27 -0800417
418/*
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800419 * Variables for shuffling. The idea is to ensure that each CPU stays
420 * idle for an extended period to test interactions with dyntick idle,
Masahiro Yamadab564d622017-02-27 14:29:06 -0800421 * as well as interactions with any per-CPU variables.
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800422 */
423struct shuffle_task {
424 struct list_head st_l;
425 struct task_struct *st_t;
426};
427
428static long shuffle_interval; /* In jiffies. */
429static struct task_struct *shuffler_task;
430static cpumask_var_t shuffle_tmp_mask;
431static int shuffle_idle_cpu; /* Force all torture tasks off this CPU */
432static struct list_head shuffle_task_list = LIST_HEAD_INIT(shuffle_task_list);
433static DEFINE_MUTEX(shuffle_task_mutex);
434
435/*
436 * Register a task to be shuffled. If there is no memory, just splat
437 * and don't bother registering.
438 */
439void torture_shuffle_task_register(struct task_struct *tp)
440{
441 struct shuffle_task *stp;
442
443 if (WARN_ON_ONCE(tp == NULL))
444 return;
445 stp = kmalloc(sizeof(*stp), GFP_KERNEL);
446 if (WARN_ON_ONCE(stp == NULL))
447 return;
448 stp->st_t = tp;
449 mutex_lock(&shuffle_task_mutex);
450 list_add(&stp->st_l, &shuffle_task_list);
451 mutex_unlock(&shuffle_task_mutex);
452}
453EXPORT_SYMBOL_GPL(torture_shuffle_task_register);
454
455/*
456 * Unregister all tasks, for example, at the end of the torture run.
457 */
458static void torture_shuffle_task_unregister_all(void)
459{
460 struct shuffle_task *stp;
461 struct shuffle_task *p;
462
463 mutex_lock(&shuffle_task_mutex);
464 list_for_each_entry_safe(stp, p, &shuffle_task_list, st_l) {
465 list_del(&stp->st_l);
466 kfree(stp);
467 }
468 mutex_unlock(&shuffle_task_mutex);
469}
470
471/* Shuffle tasks such that we allow shuffle_idle_cpu to become idle.
472 * A special case is when shuffle_idle_cpu = -1, in which case we allow
473 * the tasks to run on all CPUs.
474 */
475static void torture_shuffle_tasks(void)
476{
477 struct shuffle_task *stp;
478
479 cpumask_setall(shuffle_tmp_mask);
480 get_online_cpus();
481
482 /* No point in shuffling if there is only one online CPU (ex: UP) */
483 if (num_online_cpus() == 1) {
484 put_online_cpus();
485 return;
486 }
487
488 /* Advance to the next CPU. Upon overflow, don't idle any CPUs. */
489 shuffle_idle_cpu = cpumask_next(shuffle_idle_cpu, shuffle_tmp_mask);
490 if (shuffle_idle_cpu >= nr_cpu_ids)
491 shuffle_idle_cpu = -1;
Iulia Manda5ed63b12014-03-17 15:21:21 +0200492 else
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800493 cpumask_clear_cpu(shuffle_idle_cpu, shuffle_tmp_mask);
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800494
495 mutex_lock(&shuffle_task_mutex);
496 list_for_each_entry(stp, &shuffle_task_list, st_l)
497 set_cpus_allowed_ptr(stp->st_t, shuffle_tmp_mask);
498 mutex_unlock(&shuffle_task_mutex);
499
500 put_online_cpus();
501}
502
503/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
504 * system to become idle at a time and cut off its timer ticks. This is meant
505 * to test the support for such tickless idle CPU in RCU.
506 */
507static int torture_shuffle(void *arg)
508{
509 VERBOSE_TOROUT_STRING("torture_shuffle task started");
510 do {
511 schedule_timeout_interruptible(shuffle_interval);
512 torture_shuffle_tasks();
513 torture_shutdown_absorb("torture_shuffle");
514 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800515 torture_kthread_stopping("torture_shuffle");
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800516 return 0;
517}
518
519/*
520 * Start the shuffler, with shuffint in jiffies.
521 */
522int torture_shuffle_init(long shuffint)
523{
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800524 shuffle_interval = shuffint;
525
526 shuffle_idle_cpu = -1;
527
528 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
529 VERBOSE_TOROUT_ERRSTRING("Failed to alloc mask");
530 return -ENOMEM;
531 }
532
533 /* Create the shuffler thread */
Paul E. McKenney47cf29b2014-02-03 11:52:27 -0800534 return torture_create_kthread(torture_shuffle, NULL, shuffler_task);
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800535}
536EXPORT_SYMBOL_GPL(torture_shuffle_init);
537
538/*
539 * Stop the shuffling.
540 */
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800541static void torture_shuffle_cleanup(void)
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800542{
543 torture_shuffle_task_unregister_all();
544 if (shuffler_task) {
545 VERBOSE_TOROUT_STRING("Stopping torture_shuffle task");
546 kthread_stop(shuffler_task);
547 free_cpumask_var(shuffle_tmp_mask);
548 }
549 shuffler_task = NULL;
550}
Paul E. McKenney3808dc92014-01-28 15:29:21 -0800551
552/*
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800553 * Variables for auto-shutdown. This allows "lights out" torture runs
554 * to be fully scripted.
555 */
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800556static struct task_struct *shutdown_task;
Paul E. McKenney31257c32016-06-18 07:45:43 -0700557static ktime_t shutdown_time; /* time to system shutdown. */
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800558static void (*torture_shutdown_hook)(void);
559
560/*
Paul E. McKenneyf67a3352014-01-29 07:40:27 -0800561 * Absorb kthreads into a kernel function that won't return, so that
562 * they won't ever access module text or data again.
563 */
564void torture_shutdown_absorb(const char *title)
565{
Paul E. McKenney7d0ae802015-03-03 14:57:58 -0800566 while (READ_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
Paul E. McKenney4622b482014-01-30 15:37:19 -0800567 pr_notice("torture thread %s parking due to system shutdown\n",
568 title);
Paul E. McKenneyf67a3352014-01-29 07:40:27 -0800569 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
570 }
571}
572EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800573
574/*
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800575 * Cause the torture test to shutdown the system after the test has
576 * run for the time specified by the shutdown_secs parameter.
577 */
578static int torture_shutdown(void *arg)
579{
Paul E. McKenney31257c32016-06-18 07:45:43 -0700580 ktime_t ktime_snap;
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800581
582 VERBOSE_TOROUT_STRING("torture_shutdown task started");
Paul E. McKenney31257c32016-06-18 07:45:43 -0700583 ktime_snap = ktime_get();
584 while (ktime_before(ktime_snap, shutdown_time) &&
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800585 !torture_must_stop()) {
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800586 if (verbose)
587 pr_alert("%s" TORTURE_FLAG
Paul E. McKenney31257c32016-06-18 07:45:43 -0700588 "torture_shutdown task: %llu ms remaining\n",
589 torture_type,
590 ktime_ms_delta(shutdown_time, ktime_snap));
591 set_current_state(TASK_INTERRUPTIBLE);
592 schedule_hrtimeout(&shutdown_time, HRTIMER_MODE_ABS);
593 ktime_snap = ktime_get();
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800594 }
595 if (torture_must_stop()) {
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800596 torture_kthread_stopping("torture_shutdown");
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800597 return 0;
598 }
599
600 /* OK, shut down the system. */
601
602 VERBOSE_TOROUT_STRING("torture_shutdown task shutting down system");
603 shutdown_task = NULL; /* Avoid self-kill deadlock. */
Paul E. McKenneyf8818252014-02-07 14:42:51 -0800604 if (torture_shutdown_hook)
605 torture_shutdown_hook();
606 else
607 VERBOSE_TOROUT_STRING("No torture_shutdown_hook(), skipping.");
Paul E. McKenney2102ad22020-06-16 15:38:24 -0700608 if (ftrace_dump_at_shutdown)
609 rcu_ftrace_dump(DUMP_ALL);
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800610 kernel_power_off(); /* Shut down the system. */
611 return 0;
612}
613
614/*
615 * Start up the shutdown task.
616 */
617int torture_shutdown_init(int ssecs, void (*cleanup)(void))
618{
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800619 torture_shutdown_hook = cleanup;
Paul E. McKenney31257c32016-06-18 07:45:43 -0700620 if (ssecs > 0) {
621 shutdown_time = ktime_add(ktime_get(), ktime_set(ssecs, 0));
Pierce Griffiths2a7d9682018-09-21 20:21:31 -0500622 return torture_create_kthread(torture_shutdown, NULL,
Paul E. McKenney47cf29b2014-02-03 11:52:27 -0800623 shutdown_task);
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800624 }
Pierce Griffiths2a7d9682018-09-21 20:21:31 -0500625 return 0;
Paul E. McKenneye991dbc2014-01-31 14:52:13 -0800626}
627EXPORT_SYMBOL_GPL(torture_shutdown_init);
628
629/*
Paul E. McKenney4622b482014-01-30 15:37:19 -0800630 * Detect and respond to a system shutdown.
631 */
632static int torture_shutdown_notify(struct notifier_block *unused1,
633 unsigned long unused2, void *unused3)
634{
635 mutex_lock(&fullstop_mutex);
Paul E. McKenney7d0ae802015-03-03 14:57:58 -0800636 if (READ_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
Paul E. McKenneyfac480e2014-01-30 17:06:30 -0800637 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
Paul E. McKenney7d0ae802015-03-03 14:57:58 -0800638 WRITE_ONCE(fullstop, FULLSTOP_SHUTDOWN);
Paul E. McKenneyfac480e2014-01-30 17:06:30 -0800639 } else {
Paul E. McKenney4622b482014-01-30 15:37:19 -0800640 pr_warn("Concurrent rmmod and shutdown illegal!\n");
Paul E. McKenneyfac480e2014-01-30 17:06:30 -0800641 }
Paul E. McKenney4622b482014-01-30 15:37:19 -0800642 mutex_unlock(&fullstop_mutex);
643 return NOTIFY_DONE;
644}
645
646static struct notifier_block torture_shutdown_nb = {
647 .notifier_call = torture_shutdown_notify,
648};
649
650/*
Paul E. McKenneybfefc732014-02-04 12:35:27 -0800651 * Shut down the shutdown task. Say what??? Heh! This can happen if
652 * the torture module gets an rmmod before the shutdown time arrives. ;-)
653 */
654static void torture_shutdown_cleanup(void)
655{
656 unregister_reboot_notifier(&torture_shutdown_nb);
657 if (shutdown_task != NULL) {
658 VERBOSE_TOROUT_STRING("Stopping torture_shutdown task");
659 kthread_stop(shutdown_task);
660 }
661 shutdown_task = NULL;
662}
663
664/*
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800665 * Variables for stuttering, which means to periodically pause and
666 * restart testing in order to catch bugs that appear when load is
667 * suddenly applied to or removed from the system.
668 */
669static struct task_struct *stutter_task;
670static int stutter_pause_test;
671static int stutter;
Paul E. McKenneyff3bf922019-04-09 14:44:49 -0700672static int stutter_gap;
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800673
674/*
675 * Block until the stutter interval ends. This must be called periodically
676 * by all running kthreads that need to be subject to stuttering.
677 */
Paul E. McKenney474e59b2018-08-07 14:34:44 -0700678bool stutter_wait(const char *title)
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800679{
Paul E. McKenney19012b72020-09-01 16:58:41 -0700680 unsigned int i = 0;
Paul E. McKenneye8516c62019-04-09 11:06:32 -0700681 bool ret = false;
Paul E. McKenney19012b72020-09-01 16:58:41 -0700682 int spt;
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800683
Paul E. McKenneycee43932018-03-02 16:35:27 -0800684 cond_resched_tasks_rcu_qs();
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800685 spt = READ_ONCE(stutter_pause_test);
Paul E. McKenney29d39392017-11-21 22:07:59 -0800686 for (; spt; spt = READ_ONCE(stutter_pause_test)) {
Paul E. McKenneyab1b7882020-09-22 16:42:42 -0700687 if (!ret) {
688 sched_set_normal(current, MAX_NICE);
689 ret = true;
690 }
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800691 if (spt == 1) {
692 schedule_timeout_interruptible(1);
693 } else if (spt == 2) {
Paul E. McKenney19012b72020-09-01 16:58:41 -0700694 while (READ_ONCE(stutter_pause_test)) {
Paul E. McKenneyed24aff2020-11-17 12:17:42 -0800695 if (!(i++ & 0xffff))
696 torture_hrtimeout_us(10, 0, NULL);
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800697 cond_resched();
Paul E. McKenney19012b72020-09-01 16:58:41 -0700698 }
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800699 } else {
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800700 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800701 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800702 torture_shutdown_absorb(title);
703 }
Paul E. McKenneye8516c62019-04-09 11:06:32 -0700704 return ret;
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800705}
706EXPORT_SYMBOL_GPL(stutter_wait);
707
708/*
709 * Cause the torture test to "stutter", starting and stopping all
710 * threads periodically.
711 */
712static int torture_stutter(void *arg)
713{
Paul E. McKenneyfda5ba92020-09-02 21:08:41 -0700714 DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneye8516c62019-04-09 11:06:32 -0700715 int wtime;
716
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800717 VERBOSE_TOROUT_STRING("torture_stutter task started");
718 do {
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800719 if (!torture_must_stop() && stutter > 1) {
Paul E. McKenneye8516c62019-04-09 11:06:32 -0700720 wtime = stutter;
Paul E. McKenneyfda5ba92020-09-02 21:08:41 -0700721 if (stutter > 2) {
Paul E. McKenneye8516c62019-04-09 11:06:32 -0700722 WRITE_ONCE(stutter_pause_test, 1);
Paul E. McKenneyfda5ba92020-09-02 21:08:41 -0700723 wtime = stutter - 3;
Paul E. McKenneyed24aff2020-11-17 12:17:42 -0800724 torture_hrtimeout_jiffies(wtime, &rand);
Paul E. McKenneyfda5ba92020-09-02 21:08:41 -0700725 wtime = 2;
Paul E. McKenneye8516c62019-04-09 11:06:32 -0700726 }
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800727 WRITE_ONCE(stutter_pause_test, 2);
Paul E. McKenneyed24aff2020-11-17 12:17:42 -0800728 torture_hrtimeout_jiffies(wtime, NULL);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800729 }
Paul E. McKenney4ced3312017-11-21 15:01:02 -0800730 WRITE_ONCE(stutter_pause_test, 0);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800731 if (!torture_must_stop())
Paul E. McKenneyed24aff2020-11-17 12:17:42 -0800732 torture_hrtimeout_jiffies(stutter_gap, NULL);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800733 torture_shutdown_absorb("torture_stutter");
734 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800735 torture_kthread_stopping("torture_stutter");
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800736 return 0;
737}
738
739/*
740 * Initialize and kick off the torture_stutter kthread.
741 */
Paul E. McKenneyff3bf922019-04-09 14:44:49 -0700742int torture_stutter_init(const int s, const int sgap)
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800743{
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800744 stutter = s;
Paul E. McKenneyff3bf922019-04-09 14:44:49 -0700745 stutter_gap = sgap;
Pierce Griffiths2a7d9682018-09-21 20:21:31 -0500746 return torture_create_kthread(torture_stutter, NULL, stutter_task);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800747}
748EXPORT_SYMBOL_GPL(torture_stutter_init);
749
750/*
751 * Cleanup after the torture_stutter kthread.
752 */
Paul E. McKenneybfefc732014-02-04 12:35:27 -0800753static void torture_stutter_cleanup(void)
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800754{
755 if (!stutter_task)
756 return;
757 VERBOSE_TOROUT_STRING("Stopping torture_stutter task");
758 kthread_stop(stutter_task);
759 stutter_task = NULL;
760}
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800761
762/*
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800763 * Initialize torture module. Please note that this is -not- invoked via
764 * the usual module_init() mechanism, but rather by an explicit call from
765 * the client torture module. This call must be paired with a later
766 * torture_init_end().
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800767 *
768 * The runnable parameter points to a flag that controls whether or not
769 * the test is currently runnable. If there is no such flag, pass in NULL.
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800770 */
Paul E. McKenney90127d62018-05-09 10:29:18 -0700771bool torture_init_begin(char *ttype, int v)
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800772{
773 mutex_lock(&fullstop_mutex);
Paul E. McKenney52280842014-04-07 09:14:11 -0700774 if (torture_type != NULL) {
Paul E. McKenney9eb51882016-03-21 15:36:40 -0700775 pr_alert("torture_init_begin: Refusing %s init: %s running.\n",
Paul E. McKenney52280842014-04-07 09:14:11 -0700776 ttype, torture_type);
Paul E. McKenney9eb51882016-03-21 15:36:40 -0700777 pr_alert("torture_init_begin: One torture test at a time!\n");
Paul E. McKenney52280842014-04-07 09:14:11 -0700778 mutex_unlock(&fullstop_mutex);
779 return false;
780 }
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800781 torture_type = ttype;
782 verbose = v;
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800783 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenney52280842014-04-07 09:14:11 -0700784 return true;
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800785}
786EXPORT_SYMBOL_GPL(torture_init_begin);
787
788/*
789 * Tell the torture module that initialization is complete.
790 */
Pranith Kumar2b3f8ff2014-04-16 13:42:09 -0700791void torture_init_end(void)
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800792{
793 mutex_unlock(&fullstop_mutex);
Paul E. McKenney4622b482014-01-30 15:37:19 -0800794 register_reboot_notifier(&torture_shutdown_nb);
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800795}
796EXPORT_SYMBOL_GPL(torture_init_end);
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800797
798/*
799 * Clean up torture module. Please note that this is -not- invoked via
800 * the usual module_exit() mechanism, but rather by an explicit call from
801 * the client torture module. Returns true if a race with system shutdown
Paul E. McKenneybfefc732014-02-04 12:35:27 -0800802 * is detected, otherwise, all kthreads started by functions in this file
803 * will be shut down.
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800804 *
805 * This must be called before the caller starts shutting down its own
806 * kthreads.
Davidlohr Buesod36a7a02014-09-11 20:40:21 -0700807 *
808 * Both torture_cleanup_begin() and torture_cleanup_end() must be paired,
809 * in order to correctly perform the cleanup. They are separated because
810 * threads can still need to reference the torture_type type, thus nullify
811 * only after completing all other relevant calls.
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800812 */
Davidlohr Buesod36a7a02014-09-11 20:40:21 -0700813bool torture_cleanup_begin(void)
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800814{
815 mutex_lock(&fullstop_mutex);
Paul E. McKenney7d0ae802015-03-03 14:57:58 -0800816 if (READ_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800817 pr_warn("Concurrent rmmod and shutdown illegal!\n");
818 mutex_unlock(&fullstop_mutex);
819 schedule_timeout_uninterruptible(10);
820 return true;
821 }
Paul E. McKenney7d0ae802015-03-03 14:57:58 -0800822 WRITE_ONCE(fullstop, FULLSTOP_RMMOD);
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800823 mutex_unlock(&fullstop_mutex);
Paul E. McKenneybfefc732014-02-04 12:35:27 -0800824 torture_shutdown_cleanup();
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800825 torture_shuffle_cleanup();
Paul E. McKenneybfefc732014-02-04 12:35:27 -0800826 torture_stutter_cleanup();
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800827 torture_onoff_cleanup();
Davidlohr Buesod36a7a02014-09-11 20:40:21 -0700828 return false;
829}
830EXPORT_SYMBOL_GPL(torture_cleanup_begin);
831
832void torture_cleanup_end(void)
833{
Paul E. McKenney52280842014-04-07 09:14:11 -0700834 mutex_lock(&fullstop_mutex);
835 torture_type = NULL;
836 mutex_unlock(&fullstop_mutex);
Paul E. McKenneycc47ae02014-01-30 14:21:11 -0800837}
Davidlohr Buesod36a7a02014-09-11 20:40:21 -0700838EXPORT_SYMBOL_GPL(torture_cleanup_end);
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800839
840/*
841 * Is it time for the current torture test to stop?
842 */
843bool torture_must_stop(void)
844{
845 return torture_must_stop_irq() || kthread_should_stop();
846}
847EXPORT_SYMBOL_GPL(torture_must_stop);
848
849/*
850 * Is it time for the current torture test to stop? This is the irq-safe
851 * version, hence no check for kthread_should_stop().
852 */
853bool torture_must_stop_irq(void)
854{
Paul E. McKenney7d0ae802015-03-03 14:57:58 -0800855 return READ_ONCE(fullstop) != FULLSTOP_DONTSTOP;
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800856}
857EXPORT_SYMBOL_GPL(torture_must_stop_irq);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800858
859/*
860 * Each kthread must wait for kthread_should_stop() before returning from
861 * its top-level function, otherwise segfaults ensue. This function
862 * prints a "stopping" message and waits for kthread_should_stop(), and
863 * should be called from all torture kthreads immediately prior to
864 * returning.
865 */
866void torture_kthread_stopping(char *title)
867{
Paul E. McKenney0d6821d2014-03-03 16:58:03 -0800868 char buf[128];
869
870 snprintf(buf, sizeof(buf), "Stopping %s", title);
871 VERBOSE_TOROUT_STRING(buf);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800872 while (!kthread_should_stop()) {
873 torture_shutdown_absorb(title);
874 schedule_timeout_uninterruptible(1);
875 }
876}
877EXPORT_SYMBOL_GPL(torture_kthread_stopping);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -0800878
879/*
880 * Create a generic torture kthread that is immediately runnable. If you
881 * need the kthread to be stopped so that you can do something to it before
882 * it starts, you will need to open-code your own.
883 */
884int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
885 char *f, struct task_struct **tp)
886{
887 int ret = 0;
888
889 VERBOSE_TOROUT_STRING(m);
Kees Cook69459152014-05-22 11:51:04 -0700890 *tp = kthread_run(fn, arg, "%s", s);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -0800891 if (IS_ERR(*tp)) {
892 ret = PTR_ERR(*tp);
893 VERBOSE_TOROUT_ERRSTRING(f);
894 *tp = NULL;
895 }
896 torture_shuffle_task_register(*tp);
897 return ret;
898}
899EXPORT_SYMBOL_GPL(_torture_create_kthread);
Paul E. McKenney9c029b82014-02-04 11:47:08 -0800900
901/*
902 * Stop a generic kthread, emitting a message.
903 */
904void _torture_stop_kthread(char *m, struct task_struct **tp)
905{
906 if (*tp == NULL)
907 return;
908 VERBOSE_TOROUT_STRING(m);
909 kthread_stop(*tp);
910 *tp = NULL;
911}
912EXPORT_SYMBOL_GPL(_torture_stop_kthread);