rcutorture: Check histogram of ages
[userspace-rcu.git] / tests / regression / rcutorture.h
CommitLineData
ce29b371
MJ
1// SPDX-FileCopyrightText: 2008 Paul E. McKenney, IBM Corporation.
2//
3// SPDX-License-Identifier: GPL-2.0-or-later
4
8a953620
MD
5/*
6 * rcutorture.h: simple user-level performance/stress test of RCU.
7 *
8 * Usage:
9 * ./rcu <nreaders> rperf [ <cpustride> ]
10 * Run a read-side performance test with the specified
11 * number of readers spaced by <cpustride>.
12 * Thus "./rcu 16 rperf 2" would run 16 readers on even-numbered
13 * CPUs from 0 to 30.
14 * ./rcu <nupdaters> uperf [ <cpustride> ]
15 * Run an update-side performance test with the specified
16 * number of updaters and specified CPU spacing.
17 * ./rcu <nreaders> perf [ <cpustride> ]
18 * Run a combined read/update performance test with the specified
19 * number of readers and one updater and specified CPU spacing.
20 * The readers run on the low-numbered CPUs and the updater
21 * of the highest-numbered CPU.
22 *
23 * The above tests produce output as follows:
24 *
25 * n_reads: 46008000 n_updates: 146026 nreaders: 2 nupdaters: 1 duration: 1
26 * ns/read: 43.4707 ns/update: 6848.1
27 *
28 * The first line lists the total number of RCU reads and updates executed
29 * during the test, the number of reader threads, the number of updater
30 * threads, and the duration of the test in seconds. The second line
31 * lists the average duration of each type of operation in nanoseconds,
32 * or "nan" if the corresponding type of operation was not performed.
33 *
34 * ./rcu <nreaders> stress
35 * Run a stress test with the specified number of readers and
36 * one updater. None of the threads are affinitied to any
37 * particular CPU.
38 *
39 * This test produces output as follows:
40 *
41 * n_reads: 114633217 n_updates: 3903415 n_mberror: 0
42 * rcu_stress_count: 114618391 14826 0 0 0 0 0 0 0 0 0
43 *
44 * The first line lists the number of RCU read and update operations
45 * executed, followed by the number of memory-ordering violations
46 * (which will be zero in a correct RCU implementation). The second
47 * line lists the number of readers observing progressively more stale
48 * data. A correct RCU implementation will have all but the first two
49 * numbers non-zero.
c8c32a52
OD
50 *
51 * rcu_stress_count: Histogram of "ages" of structures seen by readers. If any
52 * entries past the first two are non-zero, RCU is broken. The age of a newly
53 * allocated structure is zero, it becomes one when removed from reader
54 * visibility, and is incremented once per grace period subsequently -- and is
55 * freed after passing through (RCU_STRESS_PIPE_LEN-2) grace periods. Since
56 * this tests only has one true writer (there are fake writers), only buckets at
57 * indexes 0 and 1 should be none-zero.
58 *
59 * This program is free software; you can redistribute it and/or modify
60 * it under the terms of the GNU General Public License as published by
61 * the Free Software Foundation; either version 2 of the License, or
62 * (at your option) any later version.
63 *
64 * This program is distributed in the hope that it will be useful,
65 * but WITHOUT ANY WARRANTY; without even the implied warranty of
66 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 * GNU General Public License for more details.
68 *
69 * You should have received a copy of the GNU General Public License
70 * along with this program; if not, write to the Free Software
71 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72 *
73 * Copyright (c) 2008 Paul E. McKenney, IBM Corporation.
8a953620
MD
74 */
75
76/*
77 * Test variables.
78 */
79
b57aee66 80#include <stdlib.h>
ad460058
MD
81#include "tap.h"
82
c8c32a52
OD
83#include <urcu/uatomic.h>
84
0d48d10d
OD
85#include "urcu-wait.h"
86
ad460058 87#define NR_TESTS 1
b57aee66 88
8a953620
MD
89DEFINE_PER_THREAD(long long, n_reads_pt);
90DEFINE_PER_THREAD(long long, n_updates_pt);
91
26b5a74b
MD
92enum callrcu_type {
93 CALLRCU_GLOBAL,
94 CALLRCU_PERCPU,
95 CALLRCU_PERTHREAD,
96};
97
eb218d4f
MD
98enum writer_state {
99 WRITER_STATE_SYNC_RCU,
100 WRITER_STATE_CALL_RCU,
101 WRITER_STATE_POLL_RCU,
102};
103
26b5a74b
MD
104static enum callrcu_type callrcu_type = CALLRCU_GLOBAL;
105
8a953620
MD
106long long n_reads = 0LL;
107long n_updates = 0L;
6ee91d83 108int nthreadsrunning;
8a953620
MD
109char argsbuf[64];
110
111#define GOFLAG_INIT 0
112#define GOFLAG_RUN 1
113#define GOFLAG_STOP 2
114
4967f005
PB
115volatile int goflag __attribute__((__aligned__(CAA_CACHE_LINE_SIZE)))
116 = GOFLAG_INIT;
8a953620
MD
117
118#define RCU_READ_RUN 1000
119
120//MD
121#define RCU_READ_NESTABLE
122
123#ifdef RCU_READ_NESTABLE
124#define rcu_read_lock_nest() rcu_read_lock()
125#define rcu_read_unlock_nest() rcu_read_unlock()
126#else /* #ifdef RCU_READ_NESTABLE */
127#define rcu_read_lock_nest()
128#define rcu_read_unlock_nest()
129#endif /* #else #ifdef RCU_READ_NESTABLE */
130
1a43bbd8
MD
131#ifdef TORTURE_QSBR
132#define mark_rcu_quiescent_state rcu_quiescent_state
133#define put_thread_offline rcu_thread_offline
134#define put_thread_online rcu_thread_online
135#endif
136
8a953620 137#ifndef mark_rcu_quiescent_state
447c9339 138#define mark_rcu_quiescent_state() do {} while (0)
8a953620
MD
139#endif /* #ifdef mark_rcu_quiescent_state */
140
141#ifndef put_thread_offline
447c9339
MJ
142#define put_thread_offline() do {} while (0)
143#define put_thread_online() do {} while (0)
144#define put_thread_online_delay() do {} while (0)
8a953620
MD
145#else /* #ifndef put_thread_offline */
146#define put_thread_online_delay() synchronize_rcu()
147#endif /* #else #ifndef put_thread_offline */
148
149/*
150 * Performance test.
151 */
152
61c3fb60 153static
8a953620
MD
154void *rcu_read_perf_test(void *arg)
155{
156 int i;
157 int me = (long)arg;
8a953620
MD
158 long long n_reads_local = 0;
159
121a5d44 160 rcu_register_thread();
8a953620 161 run_on(me);
ec4e58a3 162 uatomic_inc(&nthreadsrunning);
3bf02b5b 163 put_thread_offline();
c8c32a52 164 while (uatomic_read(&goflag) == GOFLAG_INIT)
775aff2e 165 (void) poll(NULL, 0, 1);
3bf02b5b 166 put_thread_online();
c8c32a52 167 while (uatomic_read(&goflag) == GOFLAG_RUN) {
8a953620
MD
168 for (i = 0; i < RCU_READ_RUN; i++) {
169 rcu_read_lock();
170 /* rcu_read_lock_nest(); */
171 /* rcu_read_unlock_nest(); */
172 rcu_read_unlock();
173 }
174 n_reads_local += RCU_READ_RUN;
175 mark_rcu_quiescent_state();
176 }
177 __get_thread_var(n_reads_pt) += n_reads_local;
178 put_thread_offline();
121a5d44 179 rcu_unregister_thread();
8a953620
MD
180
181 return (NULL);
182}
183
61c3fb60 184static
70469b43 185void *rcu_update_perf_test(void *arg __attribute__((unused)))
8a953620
MD
186{
187 long long n_updates_local = 0;
188
26b5a74b 189 if (callrcu_type == CALLRCU_PERTHREAD) {
b57aee66
PM
190 struct call_rcu_data *crdp;
191
c1d2c60b 192 crdp = create_call_rcu_data(0, -1);
b57aee66 193 if (crdp != NULL) {
26b5a74b 194 diag("Successfully using per-thread call_rcu() worker.");
b57aee66
PM
195 set_thread_call_rcu_data(crdp);
196 }
197 }
ec4e58a3 198 uatomic_inc(&nthreadsrunning);
c8c32a52 199 while (uatomic_read(&goflag) == GOFLAG_INIT)
775aff2e 200 (void) poll(NULL, 0, 1);
c8c32a52 201 while (uatomic_read(&goflag) == GOFLAG_RUN) {
8a953620
MD
202 synchronize_rcu();
203 n_updates_local++;
204 }
205 __get_thread_var(n_updates_pt) += n_updates_local;
26b5a74b
MD
206 if (callrcu_type == CALLRCU_PERTHREAD) {
207 struct call_rcu_data *crdp;
208
209 crdp = get_thread_call_rcu_data();
210 set_thread_call_rcu_data(NULL);
211 call_rcu_data_free(crdp);
212 }
b0b31506 213 return NULL;
8a953620
MD
214}
215
61c3fb60 216static
8a953620
MD
217void perftestinit(void)
218{
219 init_per_thread(n_reads_pt, 0LL);
220 init_per_thread(n_updates_pt, 0LL);
ec4e58a3 221 uatomic_set(&nthreadsrunning, 0);
8a953620
MD
222}
223
61c3fb60 224static
ad460058 225int perftestrun(int nthreads, int nreaders, int nupdaters)
8a953620
MD
226{
227 int t;
228 int duration = 1;
229
ec4e58a3 230 while (uatomic_read(&nthreadsrunning) < nthreads)
775aff2e 231 (void) poll(NULL, 0, 1);
c8c32a52 232 uatomic_set(&goflag, GOFLAG_RUN);
8a953620 233 sleep(duration);
c8c32a52 234 uatomic_set(&goflag, GOFLAG_STOP);
8a953620
MD
235 wait_all_threads();
236 for_each_thread(t) {
237 n_reads += per_thread(n_reads_pt, t);
238 n_updates += per_thread(n_updates_pt, t);
239 }
ad460058 240 diag("n_reads: %lld n_updates: %ld nreaders: %d nupdaters: %d duration: %d",
8a953620 241 n_reads, n_updates, nreaders, nupdaters, duration);
ad460058 242 diag("ns/read: %g ns/update: %g",
8a953620
MD
243 ((duration * 1000*1000*1000.*(double)nreaders) /
244 (double)n_reads),
245 ((duration * 1000*1000*1000.*(double)nupdaters) /
246 (double)n_updates));
7106ddf8 247 if (get_cpu_call_rcu_data(0)) {
ad460058 248 diag("Deallocating per-CPU call_rcu threads.\n");
7106ddf8
PM
249 free_all_cpu_call_rcu_data();
250 }
ad460058 251 return 0;
8a953620
MD
252}
253
61c3fb60 254static
ad460058 255int perftest(int nreaders, int cpustride)
8a953620
MD
256{
257 int i;
258 long arg;
259
260 perftestinit();
261 for (i = 0; i < nreaders; i++) {
262 arg = (long)(i * cpustride);
263 create_thread(rcu_read_perf_test, (void *)arg);
264 }
265 arg = (long)(i * cpustride);
266 create_thread(rcu_update_perf_test, (void *)arg);
ad460058 267 return perftestrun(i + 1, nreaders, 1);
8a953620
MD
268}
269
61c3fb60 270static
ad460058 271int rperftest(int nreaders, int cpustride)
8a953620
MD
272{
273 int i;
274 long arg;
275
276 perftestinit();
277 init_per_thread(n_reads_pt, 0LL);
278 for (i = 0; i < nreaders; i++) {
279 arg = (long)(i * cpustride);
280 create_thread(rcu_read_perf_test, (void *)arg);
281 }
ad460058 282 return perftestrun(i, nreaders, 0);
8a953620
MD
283}
284
61c3fb60 285static
ad460058 286int uperftest(int nupdaters, int cpustride)
8a953620
MD
287{
288 int i;
289 long arg;
290
291 perftestinit();
292 init_per_thread(n_reads_pt, 0LL);
293 for (i = 0; i < nupdaters; i++) {
294 arg = (long)(i * cpustride);
295 create_thread(rcu_update_perf_test, (void *)arg);
296 }
ad460058 297 return perftestrun(i, 0, nupdaters);
8a953620
MD
298}
299
300/*
301 * Stress test.
302 */
303
304#define RCU_STRESS_PIPE_LEN 10
305
306struct rcu_stress {
307 int pipe_count;
308 int mbtest;
309};
310
153b081a 311struct rcu_stress rcu_stress_array[RCU_STRESS_PIPE_LEN] = { { 0, 0 } };
8a953620
MD
312struct rcu_stress *rcu_stress_current;
313int rcu_stress_idx = 0;
314
c8c32a52
OD
315/*
316 * How many time a reader has seen something that should not be visible. It is
317 * an error if this value is different than zero at the end of the stress test.
318 *
319 * Here, the something that should not be visibile is an old pipe that has been
320 * freed (mbtest = 0).
321 */
8a953620
MD
322int n_mberror = 0;
323DEFINE_PER_THREAD(long long [RCU_STRESS_PIPE_LEN + 1], rcu_stress_count);
324
325int garbage = 0;
326
61c3fb60 327static
70469b43 328void *rcu_read_stress_test(void *arg __attribute__((unused)))
8a953620
MD
329{
330 int i;
331 int itercnt = 0;
332 struct rcu_stress *p;
333 int pc;
334
121a5d44 335 rcu_register_thread();
3bf02b5b 336 put_thread_offline();
c8c32a52 337 while (uatomic_read(&goflag) == GOFLAG_INIT)
775aff2e 338 (void) poll(NULL, 0, 1);
3bf02b5b 339 put_thread_online();
c8c32a52 340 while (uatomic_read(&goflag) == GOFLAG_RUN) {
8a953620
MD
341 rcu_read_lock();
342 p = rcu_dereference(rcu_stress_current);
343 if (p->mbtest == 0)
c8c32a52 344 uatomic_inc_mo(&n_mberror, CMM_RELAXED);
8a953620 345 rcu_read_lock_nest();
c8c32a52
OD
346 /*
347 * The value of garbage is nothing important. This is
348 * essentially a busy loop. The atomic operation -- while not
349 * important here -- helps tools such as TSAN to not flag this
350 * as a race condition.
351 */
8a953620 352 for (i = 0; i < 100; i++)
c8c32a52 353 uatomic_inc(&garbage);
8a953620 354 rcu_read_unlock_nest();
c8c32a52 355 pc = uatomic_read(&p->pipe_count);
8a953620
MD
356 rcu_read_unlock();
357 if ((pc > RCU_STRESS_PIPE_LEN) || (pc < 0))
358 pc = RCU_STRESS_PIPE_LEN;
359 __get_thread_var(rcu_stress_count)[pc]++;
360 __get_thread_var(n_reads_pt)++;
361 mark_rcu_quiescent_state();
362 if ((++itercnt % 0x1000) == 0) {
363 put_thread_offline();
364 put_thread_online_delay();
365 put_thread_online();
366 }
367 }
368 put_thread_offline();
121a5d44 369 rcu_unregister_thread();
8a953620
MD
370
371 return (NULL);
372}
373
0d48d10d 374static DEFINE_URCU_WAIT_QUEUE(call_rcu_waiters);
b57aee66 375
61c3fb60 376static
70469b43 377void rcu_update_stress_test_rcu(struct rcu_head *head __attribute__((unused)))
b57aee66 378{
0d48d10d
OD
379 struct urcu_waiters waiters;
380
381 urcu_move_waiters(&waiters, &call_rcu_waiters);
382 urcu_wake_all_waiters(&waiters);
b57aee66
PM
383}
384
eb218d4f
MD
385static
386void advance_writer_state(enum writer_state *state)
387{
388 switch (*state) {
389 case WRITER_STATE_SYNC_RCU:
390 *state = WRITER_STATE_CALL_RCU;
391 break;
392 case WRITER_STATE_CALL_RCU:
393 *state = WRITER_STATE_POLL_RCU;
394 break;
395 case WRITER_STATE_POLL_RCU:
396 *state = WRITER_STATE_SYNC_RCU;
397 break;
398 }
399}
400
61c3fb60 401static
70469b43 402void *rcu_update_stress_test(void *arg __attribute__((unused)))
8a953620
MD
403{
404 int i;
c8c32a52 405 struct rcu_stress *p, *old_p;
b57aee66 406 struct rcu_head rh;
eb218d4f 407 enum writer_state writer_state = WRITER_STATE_SYNC_RCU;
8a953620 408
b21d2eb5
OD
409 rcu_register_thread();
410
411 /* Offline for poll. */
412 put_thread_offline();
c8c32a52 413 while (uatomic_read(&goflag) == GOFLAG_INIT)
775aff2e 414 (void) poll(NULL, 0, 1);
b21d2eb5
OD
415 put_thread_online();
416
c8c32a52
OD
417 old_p = NULL;
418 while (uatomic_read(&goflag) == GOFLAG_RUN) {
8a953620
MD
419 i = rcu_stress_idx + 1;
420 if (i >= RCU_STRESS_PIPE_LEN)
421 i = 0;
c8c32a52
OD
422
423 rcu_read_lock();
424 old_p = rcu_dereference(rcu_stress_current);
425 rcu_read_unlock();
426
427 /*
428 * Allocate a new pipe.
429 */
8a953620 430 p = &rcu_stress_array[i];
8a953620
MD
431 p->pipe_count = 0;
432 p->mbtest = 1;
c8c32a52 433
8a953620
MD
434 rcu_assign_pointer(rcu_stress_current, p);
435 rcu_stress_idx = i;
c8c32a52
OD
436
437 /*
438 * Increment every pipe except the freshly allocated one. A
439 * reader should only see either the old pipe or the new
440 * pipe. This is reflected in the rcu_stress_count histogram.
441 */
8a953620
MD
442 for (i = 0; i < RCU_STRESS_PIPE_LEN; i++)
443 if (i != rcu_stress_idx)
c8c32a52
OD
444 uatomic_inc(&rcu_stress_array[i].pipe_count);
445
eb218d4f
MD
446 switch (writer_state) {
447 case WRITER_STATE_SYNC_RCU:
b57aee66 448 synchronize_rcu();
eb218d4f
MD
449 break;
450 case WRITER_STATE_CALL_RCU:
451 {
0d48d10d
OD
452 DEFINE_URCU_WAIT_NODE(wait, URCU_WAIT_WAITING);
453
454 urcu_wait_add(&call_rcu_waiters, &wait);
455
b57aee66 456 call_rcu(&rh, rcu_update_stress_test_rcu);
b21d2eb5 457
c92c9904
OD
458 /* Offline for busy-wait. */
459 put_thread_offline();
0d48d10d 460 urcu_adaptative_busy_wait(&wait);
c92c9904 461 put_thread_online();
eb218d4f
MD
462 break;
463 }
464 case WRITER_STATE_POLL_RCU:
465 {
466 struct urcu_gp_poll_state poll_state;
467
eb218d4f 468 poll_state = start_poll_synchronize_rcu();
b21d2eb5
OD
469
470 /* Offline for poll. */
471 put_thread_offline();
eb218d4f
MD
472 while (!poll_state_synchronize_rcu(poll_state))
473 (void) poll(NULL, 0, 1); /* Wait for 1ms */
b21d2eb5 474 put_thread_online();
eb218d4f
MD
475 break;
476 }
b57aee66 477 }
c8c32a52
OD
478 /*
479 * No readers should see that old pipe now. Setting mbtest to 0
480 * to mark it as "freed".
481 */
482 if (old_p) {
483 old_p->mbtest = 0;
484 }
485 old_p = p;
8a953620 486 n_updates++;
eb218d4f 487 advance_writer_state(&writer_state);
8a953620 488 }
a13ef613 489
b21d2eb5
OD
490 rcu_unregister_thread();
491
b0b31506 492 return NULL;
8a953620
MD
493}
494
61c3fb60 495static
70469b43 496void *rcu_fake_update_stress_test(void *arg __attribute__((unused)))
8a953620 497{
26b5a74b 498 if (callrcu_type == CALLRCU_PERTHREAD) {
b57aee66
PM
499 struct call_rcu_data *crdp;
500
c1d2c60b 501 crdp = create_call_rcu_data(0, -1);
b57aee66 502 if (crdp != NULL) {
26b5a74b 503 diag("Successfully using per-thread call_rcu() worker.");
b57aee66
PM
504 set_thread_call_rcu_data(crdp);
505 }
506 }
c8c32a52 507 while (uatomic_read(&goflag) == GOFLAG_INIT)
775aff2e 508 (void) poll(NULL, 0, 1);
c8c32a52 509 while (uatomic_read(&goflag) == GOFLAG_RUN) {
8a953620 510 synchronize_rcu();
775aff2e 511 (void) poll(NULL, 0, 1);
8a953620 512 }
26b5a74b
MD
513 if (callrcu_type == CALLRCU_PERTHREAD) {
514 struct call_rcu_data *crdp;
515
516 crdp = get_thread_call_rcu_data();
517 set_thread_call_rcu_data(NULL);
518 call_rcu_data_free(crdp);
519 }
b0b31506 520 return NULL;
8a953620
MD
521}
522
61c3fb60 523static
ad460058 524int stresstest(int nreaders)
8a953620
MD
525{
526 int i;
527 int t;
528 long long *p;
529 long long sum;
54bb03ca 530 int ret;
8a953620
MD
531
532 init_per_thread(n_reads_pt, 0LL);
533 for_each_thread(t) {
534 p = &per_thread(rcu_stress_count,t)[0];
535 for (i = 0; i <= RCU_STRESS_PIPE_LEN; i++)
536 p[i] = 0LL;
537 }
538 rcu_stress_current = &rcu_stress_array[0];
539 rcu_stress_current->pipe_count = 0;
540 rcu_stress_current->mbtest = 1;
541 for (i = 0; i < nreaders; i++)
542 create_thread(rcu_read_stress_test, NULL);
543 create_thread(rcu_update_stress_test, NULL);
544 for (i = 0; i < 5; i++)
545 create_thread(rcu_fake_update_stress_test, NULL);
c8c32a52 546 uatomic_set(&goflag, GOFLAG_RUN);
8a953620 547 sleep(10);
c8c32a52 548 uatomic_set(&goflag, GOFLAG_STOP);
8a953620
MD
549 wait_all_threads();
550 for_each_thread(t)
551 n_reads += per_thread(n_reads_pt, t);
ad460058 552 diag("n_reads: %lld n_updates: %ld n_mberror: %d",
8a953620 553 n_reads, n_updates, n_mberror);
ad460058
MD
554 rdiag_start();
555 rdiag("rcu_stress_count:");
54bb03ca 556 ret = 0;
8a953620
MD
557 for (i = 0; i <= RCU_STRESS_PIPE_LEN; i++) {
558 sum = 0LL;
559 for_each_thread(t) {
560 sum += per_thread(rcu_stress_count, t)[i];
561 }
54bb03ca
OD
562 /*
563 * If any entries past the first two are non-zero, RCU is
564 * broken. See details above about rcu_stress_count.
565 */
566 if (i > 1 && sum != 0) {
567 ret = -1;
568 }
ad460058 569 rdiag(" %lld", sum);
8a953620 570 }
ad460058 571 rdiag_end();
7106ddf8 572 if (get_cpu_call_rcu_data(0)) {
ad460058 573 diag("Deallocating per-CPU call_rcu threads.");
7106ddf8
PM
574 free_all_cpu_call_rcu_data();
575 }
54bb03ca
OD
576 if (n_mberror)
577 ret = -1;
578 return ret;
8a953620
MD
579}
580
581/*
582 * Mainprogram.
583 */
584
a142df4e 585static
6fa8b4f8 586void usage(char *argv[]) __attribute__((__noreturn__));
a142df4e 587
61c3fb60 588static
70469b43 589void usage(char *argv[])
8a953620 590{
26b5a74b 591 diag("Usage: %s nreaders [ perf | rperf | uperf | stress ] [ stride ] [ callrcu_global | callrcu_percpu | callrcu_perthread ]\n", argv[0]);
8a953620
MD
592 exit(-1);
593}
594
595int main(int argc, char *argv[])
596{
597 int nreaders = 1;
598 int cpustride = 1;
599
ad460058
MD
600 plan_tests(NR_TESTS);
601
8a953620
MD
602 smp_init();
603 //rcu_init();
26b5a74b
MD
604 if (argc > 4) {
605 const char *callrcu_str = argv[4];;
606
607 if (strcmp(callrcu_str, "callrcu_global") == 0) {
608 callrcu_type = CALLRCU_GLOBAL;
609 } else if (strcmp(callrcu_str, "callrcu_percpu") == 0) {
610 callrcu_type = CALLRCU_PERCPU;
611 } else if (strcmp(callrcu_str, "callrcu_perthread") == 0) {
612 callrcu_type = CALLRCU_PERTHREAD;
613 } else {
70469b43 614 usage(argv);
26b5a74b
MD
615 goto end;
616 }
617 }
929cfaff 618
26b5a74b
MD
619 switch (callrcu_type) {
620 case CALLRCU_GLOBAL:
621 diag("Using global per-process call_rcu thread.");
622 break;
623 case CALLRCU_PERCPU:
624 diag("Using per-CPU call_rcu threads.");
b57aee66 625 if (create_all_cpu_call_rcu_data(0))
ad460058
MD
626 diag("create_all_cpu_call_rcu_data: %s",
627 strerror(errno));
26b5a74b
MD
628 break;
629 case CALLRCU_PERTHREAD:
630 diag("Using per-thread call_rcu() worker.");
631 break;
632 default:
633 abort();
b57aee66 634 }
8a953620 635
9b171f46
MD
636#ifdef DEBUG_YIELD
637 yield_active |= YIELD_READ;
638 yield_active |= YIELD_WRITE;
639#endif
640
8a953620 641 if (argc > 1) {
26b5a74b
MD
642 if (strcmp(argv[1], "-h") == 0
643 || strcmp(argv[1], "--help") == 0) {
70469b43 644 usage(argv);
26b5a74b
MD
645 goto end;
646 }
8a953620 647 nreaders = strtoul(argv[1], NULL, 0);
ad460058
MD
648 if (argc == 2) {
649 ok(!perftest(nreaders, cpustride),
650 "perftest readers: %d, stride: %d",
651 nreaders, cpustride);
652 goto end;
653 }
8a953620
MD
654 if (argc > 3)
655 cpustride = strtoul(argv[3], NULL, 0);
656 if (strcmp(argv[2], "perf") == 0)
ad460058
MD
657 ok(!perftest(nreaders, cpustride),
658 "perftest readers: %d, stride: %d",
659 nreaders, cpustride);
8a953620 660 else if (strcmp(argv[2], "rperf") == 0)
ad460058
MD
661 ok(!rperftest(nreaders, cpustride),
662 "rperftest readers: %d, stride: %d",
663 nreaders, cpustride);
8a953620 664 else if (strcmp(argv[2], "uperf") == 0)
ad460058
MD
665 ok(!uperftest(nreaders, cpustride),
666 "uperftest readers: %d, stride: %d",
667 nreaders, cpustride);
8a953620 668 else if (strcmp(argv[2], "stress") == 0)
ad460058
MD
669 ok(!stresstest(nreaders),
670 "stresstest readers: %d, stride: %d",
671 nreaders, cpustride);
672 else
70469b43 673 usage(argv);
ad460058 674 } else {
70469b43 675 usage(argv);
8a953620 676 }
ad460058
MD
677end:
678 return exit_status();
8a953620 679}
This page took 0.078839 seconds and 4 git commands to generate.