The TREE01 rcutorture scenario intentionally creates confusion as to the number of available CPUs by specifying the "maxcpus=8 nr_cpus=43" kernel boot parameters. This can disable rcutorture's load shedding, which currently uses num_online_cpus(), which would count the extra 35 CPUs. However, the rcutorture guest OS will be provisioned with only 8 CPUs, which means that rcutorture will present full load even when all but one of the original 8 CPUs are offline. This can result in spurious errors due to extreme overloading of that single remaining CPU. This commit therefore keeps a separate set of books on the number of usable online CPUs, so that torture_num_online_cpus() is used for load shedding instead of num_online_cpus(). Note that initial sizing must use num_online_cpus() because torture_num_online_cpus() will return NR_CPUS until shortly after torture_onoff_init() is invoked.
Unified · Split
| @@ -48,6 +48,11 @@ do { \ · 47 unmodified lines | ||
| 48 | 48 | void verbose_torout_sleep(void); |
| 49 | 49 | |
| 50 | 50 | /* Definitions for online/offline exerciser. */ |
| 51 | +#ifdef CONFIG_HOTPLUG_CPU | |
| 52 | +int torture_num_online_cpus(void); | |
| 53 | +#else /* #ifdef CONFIG_HOTPLUG_CPU */ | |
| 54 | +static inline int torture_num_online_cpus(void) { return 1; } | |
| 55 | +#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | |
| 51 | 56 | typedef void torture_ofl_func(void); |
| 52 | 57 | bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes, |
| 53 | 58 | unsigned long *sum_offl, int *min_onl, int *max_onl); |
| @@ -1338,7 +1338,7 @@ static void rcu_torture_reader_do_mbchk(long myid, struct rcu_torture *rtp, · 1337 unmodified lines | ||
| 1338 | 1338 | struct torture_random_state *trsp) |
| 1339 | 1339 | { |
| 1340 | 1340 | unsigned long loops; |
| 1341 | − int noc = num_online_cpus(); | |
| 1341 | + int noc = torture_num_online_cpus(); | |
| 1342 | 1342 | int rdrchked; |
| 1343 | 1343 | int rdrchker; |
| 1344 | 1344 | struct rcu_torture_reader_check *rtrcp; // Me. |
| @@ -1658,7 +1658,7 @@ rcu_torture_reader(void *arg) · 313 unmodified lines | ||
| 1658 | 1658 | torture_hrtimeout_us(500, 1000, &rand); |
| 1659 | 1659 | lastsleep = jiffies + 10; |
| 1660 | 1660 | } |
| 1661 | − while (num_online_cpus() < mynumonline && !torture_must_stop()) | |
| 1661 | + while (torture_num_online_cpus() < mynumonline && !torture_must_stop()) | |
| 1662 | 1662 | schedule_timeout_interruptible(HZ / 5); |
| 1663 | 1663 | stutter_wait("rcu_torture_reader"); |
| 1664 | 1664 | } while (!torture_must_stop()); |
| @@ -175,6 +175,19 @@ static unsigned long sum_online; · 174 unmodified lines | ||
| 175 | 175 | static int min_online = -1; |
| 176 | 176 | static int max_online; |
| 177 | 177 | |
| 178 | +static int torture_online_cpus = NR_CPUS; | |
| 179 | + | |
| 180 | +/* | |
| 181 | + * Some torture testing leverages confusion as to the number of online | |
| 182 | + * CPUs. This function returns the torture-testing view of this number, | |
| 183 | + * which allows torture tests to load-balance appropriately. | |
| 184 | + */ | |
| 185 | +int torture_num_online_cpus(void) | |
| 186 | +{ | |
| 187 | + return READ_ONCE(torture_online_cpus); | |
| 188 | +} | |
| 189 | +EXPORT_SYMBOL_GPL(torture_num_online_cpus); | |
| 190 | + | |
| 178 | 191 | /* |
| 179 | 192 | * Attempt to take a CPU offline. Return false if the CPU is already |
| 180 | 193 | * offline or if it is not subject to CPU-hotplug operations. The |
| @@ -229,6 +242,8 @@ bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes, · 48 unmodified lines | ||
| 229 | 242 | *min_offl = delta; |
| 230 | 243 | if (*max_offl < delta) |
| 231 | 244 | *max_offl = delta; |
| 245 | + WRITE_ONCE(torture_online_cpus, torture_online_cpus - 1); | |
| 246 | + WARN_ON_ONCE(torture_online_cpus <= 0); | |
| 232 | 247 | } |
| 233 | 248 | |
| 234 | 249 | return true; |
| @@ -285,6 +300,7 @@ bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes, · 50 unmodified lines | ||
| 285 | 300 | *min_onl = delta; |
| 286 | 301 | if (*max_onl < delta) |
| 287 | 302 | *max_onl = delta; |
| 303 | + WRITE_ONCE(torture_online_cpus, torture_online_cpus + 1); | |
| 288 | 304 | } |
| 289 | 305 | |
| 290 | 306 | return true; |