Skip to content

Commit 9c029b8

Browse files
committed
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: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
1 parent 47cf29b commit 9c029b8

3 files changed

Lines changed: 30 additions & 58 deletions

File tree

‎include/linux/torture.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ bool torture_must_stop_irq(void);
9191
void torture_kthread_stopping(char *title);
9292
int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
9393
char *f, struct task_struct **tp);
94+
void _torture_stop_kthread(char *m, struct task_struct **tp);
9495

9596
#define torture_create_kthread(n, arg, tp) \
9697
_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
9798
"Failed to create " #n, &(tp))
99+
#define torture_stop_kthread(n, tp) \
100+
_torture_stop_kthread("Stopping " #n " task", &(tp))
98101

99102
#endif /* __LINUX_TORTURE_H */

‎kernel/rcu/rcutorture.c‎

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,14 +1033,12 @@ static void rcutorture_booster_cleanup(int cpu)
10331033
if (boost_tasks[cpu] == NULL)
10341034
return;
10351035
mutex_lock(&boost_mutex);
1036-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_boost task");
10371036
t = boost_tasks[cpu];
10381037
boost_tasks[cpu] = NULL;
10391038
mutex_unlock(&boost_mutex);
10401039

10411040
/* This must be outside of the mutex, otherwise deadlock! */
1042-
kthread_stop(t);
1043-
boost_tasks[cpu] = NULL;
1041+
torture_stop_kthread(rcu_torture_boost, t);
10441042
}
10451043

10461044
static int rcutorture_booster_init(int cpu)
@@ -1110,16 +1108,6 @@ static int __init rcu_torture_stall_init(void)
11101108
return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
11111109
}
11121110

1113-
/* Clean up after the CPU-stall kthread, if one was spawned. */
1114-
static void rcu_torture_stall_cleanup(void)
1115-
{
1116-
if (stall_task == NULL)
1117-
return;
1118-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_stall_task.");
1119-
kthread_stop(stall_task);
1120-
stall_task = NULL;
1121-
}
1122-
11231111
/* Callback function for RCU barrier testing. */
11241112
void rcu_torture_barrier_cbf(struct rcu_head *rcu)
11251113
{
@@ -1230,19 +1218,11 @@ static void rcu_torture_barrier_cleanup(void)
12301218
{
12311219
int i;
12321220

1233-
if (barrier_task != NULL) {
1234-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_barrier task");
1235-
kthread_stop(barrier_task);
1236-
barrier_task = NULL;
1237-
}
1221+
torture_stop_kthread(rcu_torture_barrier, barrier_task);
12381222
if (barrier_cbs_tasks != NULL) {
1239-
for (i = 0; i < n_barrier_cbs; i++) {
1240-
if (barrier_cbs_tasks[i] != NULL) {
1241-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_barrier_cbs task");
1242-
kthread_stop(barrier_cbs_tasks[i]);
1243-
barrier_cbs_tasks[i] = NULL;
1244-
}
1245-
}
1223+
for (i = 0; i < n_barrier_cbs; i++)
1224+
torture_stop_kthread(rcu_torture_barrier_cbs,
1225+
barrier_cbs_tasks[i]);
12461226
kfree(barrier_cbs_tasks);
12471227
barrier_cbs_tasks = NULL;
12481228
}
@@ -1288,53 +1268,29 @@ rcu_torture_cleanup(void)
12881268
}
12891269

12901270
rcu_torture_barrier_cleanup();
1291-
rcu_torture_stall_cleanup();
1271+
torture_stop_kthread(rcu_torture_stall, stall_task);
12921272
torture_stutter_cleanup();
1293-
1294-
if (writer_task) {
1295-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_writer task");
1296-
kthread_stop(writer_task);
1297-
}
1298-
writer_task = NULL;
1273+
torture_stop_kthread(rcu_torture_writer, writer_task);
12991274

13001275
if (reader_tasks) {
1301-
for (i = 0; i < nrealreaders; i++) {
1302-
if (reader_tasks[i]) {
1303-
VERBOSE_TOROUT_STRING(
1304-
"Stopping rcu_torture_reader task");
1305-
kthread_stop(reader_tasks[i]);
1306-
}
1307-
reader_tasks[i] = NULL;
1308-
}
1276+
for (i = 0; i < nrealreaders; i++)
1277+
torture_stop_kthread(rcu_torture_reader,
1278+
reader_tasks[i]);
13091279
kfree(reader_tasks);
1310-
reader_tasks = NULL;
13111280
}
13121281
rcu_torture_current = NULL;
13131282

13141283
if (fakewriter_tasks) {
13151284
for (i = 0; i < nfakewriters; i++) {
1316-
if (fakewriter_tasks[i]) {
1317-
VERBOSE_TOROUT_STRING(
1318-
"Stopping rcu_torture_fakewriter task");
1319-
kthread_stop(fakewriter_tasks[i]);
1320-
}
1321-
fakewriter_tasks[i] = NULL;
1285+
torture_stop_kthread(rcu_torture_fakewriter,
1286+
fakewriter_tasks[i]);
13221287
}
13231288
kfree(fakewriter_tasks);
13241289
fakewriter_tasks = NULL;
13251290
}
13261291

1327-
if (stats_task) {
1328-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_stats task");
1329-
kthread_stop(stats_task);
1330-
}
1331-
stats_task = NULL;
1332-
1333-
if (fqs_task) {
1334-
VERBOSE_TOROUT_STRING("Stopping rcu_torture_fqs task");
1335-
kthread_stop(fqs_task);
1336-
}
1337-
fqs_task = NULL;
1292+
torture_stop_kthread(rcu_torture_stats, stats_task);
1293+
torture_stop_kthread(rcu_torture_fqs, fqs_task);
13381294
if ((test_boost == 1 && cur_ops->can_boost) ||
13391295
test_boost == 2) {
13401296
unregister_cpu_notifier(&rcutorture_cpu_nb);

‎kernel/torture.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,16 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
700700
return ret;
701701
}
702702
EXPORT_SYMBOL_GPL(_torture_create_kthread);
703+
704+
/*
705+
* Stop a generic kthread, emitting a message.
706+
*/
707+
void _torture_stop_kthread(char *m, struct task_struct **tp)
708+
{
709+
if (*tp == NULL)
710+
return;
711+
VERBOSE_TOROUT_STRING(m);
712+
kthread_stop(*tp);
713+
*tp = NULL;
714+
}
715+
EXPORT_SYMBOL_GPL(_torture_stop_kthread);

0 commit comments

Comments
 (0)