torture.c (baf5fe761846815164753d1bd0638fd3696db8fd) torture.c (457bc8ed3ec7edc567200302d9312ac8bbc31316)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common functions for in-kernel torture tests.
4 *
5 * Copyright (C) IBM Corporation, 2014
6 *
7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8 * Based on kernel/rcu/torture.c.

--- 28 unchanged lines hidden (view full) ---

37#include <linux/ktime.h>
38#include <asm/byteorder.h>
39#include <linux/torture.h>
40#include "rcu/rcu.h"
41
42MODULE_LICENSE("GPL");
43MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
44
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common functions for in-kernel torture tests.
4 *
5 * Copyright (C) IBM Corporation, 2014
6 *
7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8 * Based on kernel/rcu/torture.c.

--- 28 unchanged lines hidden (view full) ---

37#include <linux/ktime.h>
38#include <asm/byteorder.h>
39#include <linux/torture.h>
40#include "rcu/rcu.h"
41
42MODULE_LICENSE("GPL");
43MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
44
45static bool disable_onoff_at_boot;
46module_param(disable_onoff_at_boot, bool, 0444);
47
48static char *torture_type;
49static int verbose;
50
51/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
52#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
53#define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */
54#define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */
55static int fullstop = FULLSTOP_RMMOD;

--- 26 unchanged lines hidden (view full) ---

82 * offline or if it is not subject to CPU-hotplug operations. The
83 * caller can detect other failures by looking at the statistics.
84 */
85bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes,
86 unsigned long *sum_offl, int *min_offl, int *max_offl)
87{
88 unsigned long delta;
89 int ret;
45static char *torture_type;
46static int verbose;
47
48/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
49#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
50#define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */
51#define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */
52static int fullstop = FULLSTOP_RMMOD;

--- 26 unchanged lines hidden (view full) ---

79 * offline or if it is not subject to CPU-hotplug operations. The
80 * caller can detect other failures by looking at the statistics.
81 */
82bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes,
83 unsigned long *sum_offl, int *min_offl, int *max_offl)
84{
85 unsigned long delta;
86 int ret;
90 char *s;
91 unsigned long starttime;
92
93 if (!cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
94 return false;
95 if (num_online_cpus() <= 1)
96 return false; /* Can't offline the last CPU. */
97
98 if (verbose > 1)
99 pr_alert("%s" TORTURE_FLAG
100 "torture_onoff task: offlining %d\n",
101 torture_type, cpu);
102 starttime = jiffies;
103 (*n_offl_attempts)++;
87 unsigned long starttime;
88
89 if (!cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
90 return false;
91 if (num_online_cpus() <= 1)
92 return false; /* Can't offline the last CPU. */
93
94 if (verbose > 1)
95 pr_alert("%s" TORTURE_FLAG
96 "torture_onoff task: offlining %d\n",
97 torture_type, cpu);
98 starttime = jiffies;
99 (*n_offl_attempts)++;
104 ret = cpu_down(cpu);
100 ret = remove_cpu(cpu);
105 if (ret) {
101 if (ret) {
106 s = "";
107 if (!rcu_inkernel_boot_has_ended() && ret == -EBUSY) {
108 // PCI probe frequently disables hotplug during boot.
109 (*n_offl_attempts)--;
110 s = " (-EBUSY forgiven during boot)";
111 }
112 if (verbose)
113 pr_alert("%s" TORTURE_FLAG
102 if (verbose)
103 pr_alert("%s" TORTURE_FLAG
114 "torture_onoff task: offline %d failed%s: errno %d\n",
115 torture_type, cpu, s, ret);
104 "torture_onoff task: offline %d failed: errno %d\n",
105 torture_type, cpu, ret);
116 } else {
117 if (verbose > 1)
118 pr_alert("%s" TORTURE_FLAG
119 "torture_onoff task: offlined %d\n",
120 torture_type, cpu);
121 if (onoff_f)
122 onoff_f();
123 (*n_offl_successes)++;

--- 18 unchanged lines hidden (view full) ---

142 * online or if it is not subject to CPU-hotplug operations. The
143 * caller can detect other failures by looking at the statistics.
144 */
145bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
146 unsigned long *sum_onl, int *min_onl, int *max_onl)
147{
148 unsigned long delta;
149 int ret;
106 } else {
107 if (verbose > 1)
108 pr_alert("%s" TORTURE_FLAG
109 "torture_onoff task: offlined %d\n",
110 torture_type, cpu);
111 if (onoff_f)
112 onoff_f();
113 (*n_offl_successes)++;

--- 18 unchanged lines hidden (view full) ---

132 * online or if it is not subject to CPU-hotplug operations. The
133 * caller can detect other failures by looking at the statistics.
134 */
135bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
136 unsigned long *sum_onl, int *min_onl, int *max_onl)
137{
138 unsigned long delta;
139 int ret;
150 char *s;
151 unsigned long starttime;
152
153 if (cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
154 return false;
155
156 if (verbose > 1)
157 pr_alert("%s" TORTURE_FLAG
158 "torture_onoff task: onlining %d\n",
159 torture_type, cpu);
160 starttime = jiffies;
161 (*n_onl_attempts)++;
140 unsigned long starttime;
141
142 if (cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
143 return false;
144
145 if (verbose > 1)
146 pr_alert("%s" TORTURE_FLAG
147 "torture_onoff task: onlining %d\n",
148 torture_type, cpu);
149 starttime = jiffies;
150 (*n_onl_attempts)++;
162 ret = cpu_up(cpu);
151 ret = add_cpu(cpu);
163 if (ret) {
152 if (ret) {
164 s = "";
165 if (!rcu_inkernel_boot_has_ended() && ret == -EBUSY) {
166 // PCI probe frequently disables hotplug during boot.
167 (*n_onl_attempts)--;
168 s = " (-EBUSY forgiven during boot)";
169 }
170 if (verbose)
171 pr_alert("%s" TORTURE_FLAG
153 if (verbose)
154 pr_alert("%s" TORTURE_FLAG
172 "torture_onoff task: online %d failed%s: errno %d\n",
173 torture_type, cpu, s, ret);
155 "torture_onoff task: online %d failed: errno %d\n",
156 torture_type, cpu, ret);
174 } else {
175 if (verbose > 1)
176 pr_alert("%s" TORTURE_FLAG
177 "torture_onoff task: onlined %d\n",
178 torture_type, cpu);
179 (*n_onl_successes)++;
180 delta = jiffies - starttime;
181 *sum_onl += delta;

--- 22 unchanged lines hidden (view full) ---

204 int maxcpu = -1;
205 DEFINE_TORTURE_RANDOM(rand);
206 int ret;
207
208 VERBOSE_TOROUT_STRING("torture_onoff task started");
209 for_each_online_cpu(cpu)
210 maxcpu = cpu;
211 WARN_ON(maxcpu < 0);
157 } else {
158 if (verbose > 1)
159 pr_alert("%s" TORTURE_FLAG
160 "torture_onoff task: onlined %d\n",
161 torture_type, cpu);
162 (*n_onl_successes)++;
163 delta = jiffies - starttime;
164 *sum_onl += delta;

--- 22 unchanged lines hidden (view full) ---

187 int maxcpu = -1;
188 DEFINE_TORTURE_RANDOM(rand);
189 int ret;
190
191 VERBOSE_TOROUT_STRING("torture_onoff task started");
192 for_each_online_cpu(cpu)
193 maxcpu = cpu;
194 WARN_ON(maxcpu < 0);
212 if (!IS_MODULE(CONFIG_TORTURE_TEST))
195 if (!IS_MODULE(CONFIG_TORTURE_TEST)) {
213 for_each_possible_cpu(cpu) {
214 if (cpu_online(cpu))
215 continue;
196 for_each_possible_cpu(cpu) {
197 if (cpu_online(cpu))
198 continue;
216 ret = cpu_up(cpu);
199 ret = add_cpu(cpu);
217 if (ret && verbose) {
218 pr_alert("%s" TORTURE_FLAG
219 "%s: Initial online %d: errno %d\n",
220 __func__, torture_type, cpu, ret);
221 }
222 }
200 if (ret && verbose) {
201 pr_alert("%s" TORTURE_FLAG
202 "%s: Initial online %d: errno %d\n",
203 __func__, torture_type, cpu, ret);
204 }
205 }
206 }
223
224 if (maxcpu == 0) {
225 VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is disabled");
226 goto stop;
227 }
228
229 if (onoff_holdoff > 0) {
230 VERBOSE_TOROUT_STRING("torture_onoff begin holdoff");
231 schedule_timeout_interruptible(onoff_holdoff);
232 VERBOSE_TOROUT_STRING("torture_onoff end holdoff");
233 }
234 while (!torture_must_stop()) {
207
208 if (maxcpu == 0) {
209 VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is disabled");
210 goto stop;
211 }
212
213 if (onoff_holdoff > 0) {
214 VERBOSE_TOROUT_STRING("torture_onoff begin holdoff");
215 schedule_timeout_interruptible(onoff_holdoff);
216 VERBOSE_TOROUT_STRING("torture_onoff end holdoff");
217 }
218 while (!torture_must_stop()) {
235 if (disable_onoff_at_boot && !rcu_inkernel_boot_has_ended()) {
236 schedule_timeout_interruptible(HZ / 10);
237 continue;
238 }
239 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1);
240 if (!torture_offline(cpu,
241 &n_offline_attempts, &n_offline_successes,
242 &sum_offline, &min_offline, &max_offline))
243 torture_online(cpu,
244 &n_online_attempts, &n_online_successes,
245 &sum_online, &min_online, &max_online);
246 schedule_timeout_interruptible(onoff_interval);

--- 578 unchanged lines hidden ---
219 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1);
220 if (!torture_offline(cpu,
221 &n_offline_attempts, &n_offline_successes,
222 &sum_offline, &min_offline, &max_offline))
223 torture_online(cpu,
224 &n_online_attempts, &n_online_successes,
225 &sum_online, &min_online, &max_online);
226 schedule_timeout_interruptible(onoff_interval);

--- 578 unchanged lines hidden ---