Commit 9c029b86 authored by Paul E. McKenney's avatar Paul E. McKenney

rcutorture: Abstract torture_stop_kthread()

Stopping of kthreads is not RCU-specific, so this commit abstracts
out torture_stop_kthread(), saving a few lines of code in the process.
Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: default avatarJosh Triplett <josh@joshtriplett.org>
parent 47cf29b9
...@@ -91,9 +91,12 @@ bool torture_must_stop_irq(void); ...@@ -91,9 +91,12 @@ bool torture_must_stop_irq(void);
void torture_kthread_stopping(char *title); void torture_kthread_stopping(char *title);
int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
char *f, struct task_struct **tp); char *f, struct task_struct **tp);
void _torture_stop_kthread(char *m, struct task_struct **tp);
#define torture_create_kthread(n, arg, tp) \ #define torture_create_kthread(n, arg, tp) \
_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \ _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
"Failed to create " #n, &(tp)) "Failed to create " #n, &(tp))
#define torture_stop_kthread(n, tp) \
_torture_stop_kthread("Stopping " #n " task", &(tp))
#endif /* __LINUX_TORTURE_H */ #endif /* __LINUX_TORTURE_H */
...@@ -1033,14 +1033,12 @@ static void rcutorture_booster_cleanup(int cpu) ...@@ -1033,14 +1033,12 @@ static void rcutorture_booster_cleanup(int cpu)
if (boost_tasks[cpu] == NULL) if (boost_tasks[cpu] == NULL)
return; return;
mutex_lock(&boost_mutex); mutex_lock(&boost_mutex);
VERBOSE_TOROUT_STRING("Stopping rcu_torture_boost task");
t = boost_tasks[cpu]; t = boost_tasks[cpu];
boost_tasks[cpu] = NULL; boost_tasks[cpu] = NULL;
mutex_unlock(&boost_mutex); mutex_unlock(&boost_mutex);
/* This must be outside of the mutex, otherwise deadlock! */ /* This must be outside of the mutex, otherwise deadlock! */
kthread_stop(t); torture_stop_kthread(rcu_torture_boost, t);
boost_tasks[cpu] = NULL;
} }
static int rcutorture_booster_init(int cpu) static int rcutorture_booster_init(int cpu)
...@@ -1110,16 +1108,6 @@ static int __init rcu_torture_stall_init(void) ...@@ -1110,16 +1108,6 @@ static int __init rcu_torture_stall_init(void)
return torture_create_kthread(rcu_torture_stall, NULL, stall_task); return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
} }
/* Clean up after the CPU-stall kthread, if one was spawned. */
static void rcu_torture_stall_cleanup(void)
{
if (stall_task == NULL)
return;
VERBOSE_TOROUT_STRING("Stopping rcu_torture_stall_task.");
kthread_stop(stall_task);
stall_task = NULL;
}
/* Callback function for RCU barrier testing. */ /* Callback function for RCU barrier testing. */
void rcu_torture_barrier_cbf(struct rcu_head *rcu) void rcu_torture_barrier_cbf(struct rcu_head *rcu)
{ {
...@@ -1230,19 +1218,11 @@ static void rcu_torture_barrier_cleanup(void) ...@@ -1230,19 +1218,11 @@ static void rcu_torture_barrier_cleanup(void)
{ {
int i; int i;
if (barrier_task != NULL) { torture_stop_kthread(rcu_torture_barrier, barrier_task);
VERBOSE_TOROUT_STRING("Stopping rcu_torture_barrier task");
kthread_stop(barrier_task);
barrier_task = NULL;
}
if (barrier_cbs_tasks != NULL) { if (barrier_cbs_tasks != NULL) {
for (i = 0; i < n_barrier_cbs; i++) { for (i = 0; i < n_barrier_cbs; i++)
if (barrier_cbs_tasks[i] != NULL) { torture_stop_kthread(rcu_torture_barrier_cbs,
VERBOSE_TOROUT_STRING("Stopping rcu_torture_barrier_cbs task"); barrier_cbs_tasks[i]);
kthread_stop(barrier_cbs_tasks[i]);
barrier_cbs_tasks[i] = NULL;
}
}
kfree(barrier_cbs_tasks); kfree(barrier_cbs_tasks);
barrier_cbs_tasks = NULL; barrier_cbs_tasks = NULL;
} }
...@@ -1288,53 +1268,29 @@ rcu_torture_cleanup(void) ...@@ -1288,53 +1268,29 @@ rcu_torture_cleanup(void)
} }
rcu_torture_barrier_cleanup(); rcu_torture_barrier_cleanup();
rcu_torture_stall_cleanup(); torture_stop_kthread(rcu_torture_stall, stall_task);
torture_stutter_cleanup(); torture_stutter_cleanup();
torture_stop_kthread(rcu_torture_writer, writer_task);
if (writer_task) {
VERBOSE_TOROUT_STRING("Stopping rcu_torture_writer task");
kthread_stop(writer_task);
}
writer_task = NULL;
if (reader_tasks) { if (reader_tasks) {
for (i = 0; i < nrealreaders; i++) { for (i = 0; i < nrealreaders; i++)
if (reader_tasks[i]) { torture_stop_kthread(rcu_torture_reader,
VERBOSE_TOROUT_STRING( reader_tasks[i]);
"Stopping rcu_torture_reader task");
kthread_stop(reader_tasks[i]);
}
reader_tasks[i] = NULL;
}
kfree(reader_tasks); kfree(reader_tasks);
reader_tasks = NULL;
} }
rcu_torture_current = NULL; rcu_torture_current = NULL;
if (fakewriter_tasks) { if (fakewriter_tasks) {
for (i = 0; i < nfakewriters; i++) { for (i = 0; i < nfakewriters; i++) {
if (fakewriter_tasks[i]) { torture_stop_kthread(rcu_torture_fakewriter,
VERBOSE_TOROUT_STRING( fakewriter_tasks[i]);
"Stopping rcu_torture_fakewriter task");
kthread_stop(fakewriter_tasks[i]);
}
fakewriter_tasks[i] = NULL;
} }
kfree(fakewriter_tasks); kfree(fakewriter_tasks);
fakewriter_tasks = NULL; fakewriter_tasks = NULL;
} }
if (stats_task) { torture_stop_kthread(rcu_torture_stats, stats_task);
VERBOSE_TOROUT_STRING("Stopping rcu_torture_stats task"); torture_stop_kthread(rcu_torture_fqs, fqs_task);
kthread_stop(stats_task);
}
stats_task = NULL;
if (fqs_task) {
VERBOSE_TOROUT_STRING("Stopping rcu_torture_fqs task");
kthread_stop(fqs_task);
}
fqs_task = NULL;
if ((test_boost == 1 && cur_ops->can_boost) || if ((test_boost == 1 && cur_ops->can_boost) ||
test_boost == 2) { test_boost == 2) {
unregister_cpu_notifier(&rcutorture_cpu_nb); unregister_cpu_notifier(&rcutorture_cpu_nb);
......
...@@ -700,3 +700,16 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, ...@@ -700,3 +700,16 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(_torture_create_kthread); EXPORT_SYMBOL_GPL(_torture_create_kthread);
/*
* Stop a generic kthread, emitting a message.
*/
void _torture_stop_kthread(char *m, struct task_struct **tp)
{
if (*tp == NULL)
return;
VERBOSE_TOROUT_STRING(m);
kthread_stop(*tp);
*tp = NULL;
}
EXPORT_SYMBOL_GPL(_torture_stop_kthread);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment