xref: /OK3568_Linux_fs/kernel/Documentation/RCU/torture.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun==========================
4*4882a593SmuzhiyunRCU Torture Test Operation
5*4882a593Smuzhiyun==========================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunCONFIG_RCU_TORTURE_TEST
9*4882a593Smuzhiyun=======================
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThe CONFIG_RCU_TORTURE_TEST config option is available for all RCU
12*4882a593Smuzhiyunimplementations.  It creates an rcutorture kernel module that can
13*4882a593Smuzhiyunbe loaded to run a torture test.  The test periodically outputs
14*4882a593Smuzhiyunstatus messages via printk(), which can be examined via the dmesg
15*4882a593Smuzhiyuncommand (perhaps grepping for "torture").  The test is started
16*4882a593Smuzhiyunwhen the module is loaded, and stops when the module is unloaded.
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunModule parameters are prefixed by "rcutorture." in
19*4882a593SmuzhiyunDocumentation/admin-guide/kernel-parameters.txt.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunOutput
22*4882a593Smuzhiyun======
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunThe statistics output is as follows::
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun	rcu-torture:--- Start of test: nreaders=16 nfakewriters=4 stat_interval=30 verbose=0 test_no_idle_hz=1 shuffle_interval=3 stutter=5 irqreader=1 fqs_duration=0 fqs_holdoff=0 fqs_stutter=3 test_boost=1/0 test_boost_interval=7 test_boost_duration=4
27*4882a593Smuzhiyun	rcu-torture: rtc:           (null) ver: 155441 tfle: 0 rta: 155441 rtaf: 8884 rtf: 155440 rtmbe: 0 rtbe: 0 rtbke: 0 rtbre: 0 rtbf: 0 rtb: 0 nt: 3055767
28*4882a593Smuzhiyun	rcu-torture: Reader Pipe:  727860534 34213 0 0 0 0 0 0 0 0 0
29*4882a593Smuzhiyun	rcu-torture: Reader Batch:  727877838 17003 0 0 0 0 0 0 0 0 0
30*4882a593Smuzhiyun	rcu-torture: Free-Block Circulation:  155440 155440 155440 155440 155440 155440 155440 155440 155440 155440 0
31*4882a593Smuzhiyun	rcu-torture:--- End of test: SUCCESS: nreaders=16 nfakewriters=4 stat_interval=30 verbose=0 test_no_idle_hz=1 shuffle_interval=3 stutter=5 irqreader=1 fqs_duration=0 fqs_holdoff=0 fqs_stutter=3 test_boost=1/0 test_boost_interval=7 test_boost_duration=4
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunThe command "dmesg | grep torture:" will extract this information on
34*4882a593Smuzhiyunmost systems.  On more esoteric configurations, it may be necessary to
35*4882a593Smuzhiyunuse other commands to access the output of the printk()s used by
36*4882a593Smuzhiyunthe RCU torture test.  The printk()s use KERN_ALERT, so they should
37*4882a593Smuzhiyunbe evident.  ;-)
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunThe first and last lines show the rcutorture module parameters, and the
40*4882a593Smuzhiyunlast line shows either "SUCCESS" or "FAILURE", based on rcutorture's
41*4882a593Smuzhiyunautomatic determination as to whether RCU operated correctly.
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunThe entries are as follows:
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun*	"rtc": The hexadecimal address of the structure currently visible
46*4882a593Smuzhiyun	to readers.
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun*	"ver": The number of times since boot that the RCU writer task
49*4882a593Smuzhiyun	has changed the structure visible to readers.
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun*	"tfle": If non-zero, indicates that the "torture freelist"
52*4882a593Smuzhiyun	containing structures to be placed into the "rtc" area is empty.
53*4882a593Smuzhiyun	This condition is important, since it can fool you into thinking
54*4882a593Smuzhiyun	that RCU is working when it is not.  :-/
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun*	"rta": Number of structures allocated from the torture freelist.
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun*	"rtaf": Number of allocations from the torture freelist that have
59*4882a593Smuzhiyun	failed due to the list being empty.  It is not unusual for this
60*4882a593Smuzhiyun	to be non-zero, but it is bad for it to be a large fraction of
61*4882a593Smuzhiyun	the value indicated by "rta".
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun*	"rtf": Number of frees into the torture freelist.
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun*	"rtmbe": A non-zero value indicates that rcutorture believes that
66*4882a593Smuzhiyun	rcu_assign_pointer() and rcu_dereference() are not working
67*4882a593Smuzhiyun	correctly.  This value should be zero.
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun*	"rtbe": A non-zero value indicates that one of the rcu_barrier()
70*4882a593Smuzhiyun	family of functions is not working correctly.
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun*	"rtbke": rcutorture was unable to create the real-time kthreads
73*4882a593Smuzhiyun	used to force RCU priority inversion.  This value should be zero.
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun*	"rtbre": Although rcutorture successfully created the kthreads
76*4882a593Smuzhiyun	used to force RCU priority inversion, it was unable to set them
77*4882a593Smuzhiyun	to the real-time priority level of 1.  This value should be zero.
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun*	"rtbf": The number of times that RCU priority boosting failed
80*4882a593Smuzhiyun	to resolve RCU priority inversion.
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun*	"rtb": The number of times that rcutorture attempted to force
83*4882a593Smuzhiyun	an RCU priority inversion condition.  If you are testing RCU
84*4882a593Smuzhiyun	priority boosting via the "test_boost" module parameter, this
85*4882a593Smuzhiyun	value should be non-zero.
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun*	"nt": The number of times rcutorture ran RCU read-side code from
88*4882a593Smuzhiyun	within a timer handler.  This value should be non-zero only
89*4882a593Smuzhiyun	if you specified the "irqreader" module parameter.
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun*	"Reader Pipe": Histogram of "ages" of structures seen by readers.
92*4882a593Smuzhiyun	If any entries past the first two are non-zero, RCU is broken.
93*4882a593Smuzhiyun	And rcutorture prints the error flag string "!!!" to make sure
94*4882a593Smuzhiyun	you notice.  The age of a newly allocated structure is zero,
95*4882a593Smuzhiyun	it becomes one when removed from reader visibility, and is
96*4882a593Smuzhiyun	incremented once per grace period subsequently -- and is freed
97*4882a593Smuzhiyun	after passing through (RCU_TORTURE_PIPE_LEN-2) grace periods.
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun	The output displayed above was taken from a correctly working
100*4882a593Smuzhiyun	RCU.  If you want to see what it looks like when broken, break
101*4882a593Smuzhiyun	it yourself.  ;-)
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun*	"Reader Batch": Another histogram of "ages" of structures seen
104*4882a593Smuzhiyun	by readers, but in terms of counter flips (or batches) rather
105*4882a593Smuzhiyun	than in terms of grace periods.  The legal number of non-zero
106*4882a593Smuzhiyun	entries is again two.  The reason for this separate view is that
107*4882a593Smuzhiyun	it is sometimes easier to get the third entry to show up in the
108*4882a593Smuzhiyun	"Reader Batch" list than in the "Reader Pipe" list.
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun*	"Free-Block Circulation": Shows the number of torture structures
111*4882a593Smuzhiyun	that have reached a given point in the pipeline.  The first element
112*4882a593Smuzhiyun	should closely correspond to the number of structures allocated,
113*4882a593Smuzhiyun	the second to the number that have been removed from reader view,
114*4882a593Smuzhiyun	and all but the last remaining to the corresponding number of
115*4882a593Smuzhiyun	passes through a grace period.  The last entry should be zero,
116*4882a593Smuzhiyun	as it is only incremented if a torture structure's counter
117*4882a593Smuzhiyun	somehow gets incremented farther than it should.
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunDifferent implementations of RCU can provide implementation-specific
120*4882a593Smuzhiyunadditional information.  For example, Tree SRCU provides the following
121*4882a593Smuzhiyunadditional line::
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun	srcud-torture: Tree SRCU per-CPU(idx=0): 0(35,-21) 1(-4,24) 2(1,1) 3(-26,20) 4(28,-47) 5(-9,4) 6(-10,14) 7(-14,11) T(1,6)
124*4882a593Smuzhiyun
125*4882a593SmuzhiyunThis line shows the per-CPU counter state, in this case for Tree SRCU
126*4882a593Smuzhiyunusing a dynamically allocated srcu_struct (hence "srcud-" rather than
127*4882a593Smuzhiyun"srcu-").  The numbers in parentheses are the values of the "old" and
128*4882a593Smuzhiyun"current" counters for the corresponding CPU.  The "idx" value maps the
129*4882a593Smuzhiyun"old" and "current" values to the underlying array, and is useful for
130*4882a593Smuzhiyundebugging.  The final "T" entry contains the totals of the counters.
131*4882a593Smuzhiyun
132*4882a593SmuzhiyunUsage on Specific Kernel Builds
133*4882a593Smuzhiyun===============================
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunIt is sometimes desirable to torture RCU on a specific kernel build,
136*4882a593Smuzhiyunfor example, when preparing to put that kernel build into production.
137*4882a593SmuzhiyunIn that case, the kernel should be built with CONFIG_RCU_TORTURE_TEST=m
138*4882a593Smuzhiyunso that the test can be started using modprobe and terminated using rmmod.
139*4882a593Smuzhiyun
140*4882a593SmuzhiyunFor example, the following script may be used to torture RCU::
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun	#!/bin/sh
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun	modprobe rcutorture
145*4882a593Smuzhiyun	sleep 3600
146*4882a593Smuzhiyun	rmmod rcutorture
147*4882a593Smuzhiyun	dmesg | grep torture:
148*4882a593Smuzhiyun
149*4882a593SmuzhiyunThe output can be manually inspected for the error flag of "!!!".
150*4882a593SmuzhiyunOne could of course create a more elaborate script that automatically
151*4882a593Smuzhiyunchecked for such errors.  The "rmmod" command forces a "SUCCESS",
152*4882a593Smuzhiyun"FAILURE", or "RCU_HOTPLUG" indication to be printk()ed.  The first
153*4882a593Smuzhiyuntwo are self-explanatory, while the last indicates that while there
154*4882a593Smuzhiyunwere no RCU failures, CPU-hotplug problems were detected.
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun
157*4882a593SmuzhiyunUsage on Mainline Kernels
158*4882a593Smuzhiyun=========================
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunWhen using rcutorture to test changes to RCU itself, it is often
161*4882a593Smuzhiyunnecessary to build a number of kernels in order to test that change
162*4882a593Smuzhiyunacross a broad range of combinations of the relevant Kconfig options
163*4882a593Smuzhiyunand of the relevant kernel boot parameters.  In this situation, use
164*4882a593Smuzhiyunof modprobe and rmmod can be quite time-consuming and error-prone.
165*4882a593Smuzhiyun
166*4882a593SmuzhiyunTherefore, the tools/testing/selftests/rcutorture/bin/kvm.sh
167*4882a593Smuzhiyunscript is available for mainline testing for x86, arm64, and
168*4882a593Smuzhiyunpowerpc.  By default, it will run the series of tests specified by
169*4882a593Smuzhiyuntools/testing/selftests/rcutorture/configs/rcu/CFLIST, with each test
170*4882a593Smuzhiyunrunning for 30 minutes within a guest OS using a minimal userspace
171*4882a593Smuzhiyunsupplied by an automatically generated initrd.  After the tests are
172*4882a593Smuzhiyuncomplete, the resulting build products and console output are analyzed
173*4882a593Smuzhiyunfor errors and the results of the runs are summarized.
174*4882a593Smuzhiyun
175*4882a593SmuzhiyunOn larger systems, rcutorture testing can be accelerated by passing the
176*4882a593Smuzhiyun--cpus argument to kvm.sh.  For example, on a 64-CPU system, "--cpus 43"
177*4882a593Smuzhiyunwould use up to 43 CPUs to run tests concurrently, which as of v5.4 would
178*4882a593Smuzhiyuncomplete all the scenarios in two batches, reducing the time to complete
179*4882a593Smuzhiyunfrom about eight hours to about one hour (not counting the time to build
180*4882a593Smuzhiyunthe sixteen kernels).  The "--dryrun sched" argument will not run tests,
181*4882a593Smuzhiyunbut rather tell you how the tests would be scheduled into batches.  This
182*4882a593Smuzhiyuncan be useful when working out how many CPUs to specify in the --cpus
183*4882a593Smuzhiyunargument.
184*4882a593Smuzhiyun
185*4882a593SmuzhiyunNot all changes require that all scenarios be run.  For example, a change
186*4882a593Smuzhiyunto Tree SRCU might run only the SRCU-N and SRCU-P scenarios using the
187*4882a593Smuzhiyun--configs argument to kvm.sh as follows:  "--configs 'SRCU-N SRCU-P'".
188*4882a593SmuzhiyunLarge systems can run multiple copies of of the full set of scenarios,
189*4882a593Smuzhiyunfor example, a system with 448 hardware threads can run five instances
190*4882a593Smuzhiyunof the full set concurrently.  To make this happen::
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun	kvm.sh --cpus 448 --configs '5*CFLIST'
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunAlternatively, such a system can run 56 concurrent instances of a single
195*4882a593Smuzhiyuneight-CPU scenario::
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun	kvm.sh --cpus 448 --configs '56*TREE04'
198*4882a593Smuzhiyun
199*4882a593SmuzhiyunOr 28 concurrent instances of each of two eight-CPU scenarios::
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun	kvm.sh --cpus 448 --configs '28*TREE03 28*TREE04'
202*4882a593Smuzhiyun
203*4882a593SmuzhiyunOf course, each concurrent instance will use memory, which can be
204*4882a593Smuzhiyunlimited using the --memory argument, which defaults to 512M.  Small
205*4882a593Smuzhiyunvalues for memory may require disabling the callback-flooding tests
206*4882a593Smuzhiyunusing the --bootargs parameter discussed below.
207*4882a593Smuzhiyun
208*4882a593SmuzhiyunSometimes additional debugging is useful, and in such cases the --kconfig
209*4882a593Smuzhiyunparameter to kvm.sh may be used, for example, ``--kconfig 'CONFIG_KASAN=y'``.
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunKernel boot arguments can also be supplied, for example, to control
212*4882a593Smuzhiyunrcutorture's module parameters.  For example, to test a change to RCU's
213*4882a593SmuzhiyunCPU stall-warning code, use "--bootargs 'rcutorture.stall_cpu=30'".
214*4882a593SmuzhiyunThis will of course result in the scripting reporting a failure, namely
215*4882a593Smuzhiyunthe resuling RCU CPU stall warning.  As noted above, reducing memory may
216*4882a593Smuzhiyunrequire disabling rcutorture's callback-flooding tests::
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun	kvm.sh --cpus 448 --configs '56*TREE04' --memory 128M \
219*4882a593Smuzhiyun		--bootargs 'rcutorture.fwd_progress=0'
220*4882a593Smuzhiyun
221*4882a593SmuzhiyunSometimes all that is needed is a full set of kernel builds.  This is
222*4882a593Smuzhiyunwhat the --buildonly argument does.
223*4882a593Smuzhiyun
224*4882a593SmuzhiyunFinally, the --trust-make argument allows each kernel build to reuse what
225*4882a593Smuzhiyunit can from the previous kernel build.
226*4882a593Smuzhiyun
227*4882a593SmuzhiyunThere are additional more arcane arguments that are documented in the
228*4882a593Smuzhiyunsource code of the kvm.sh script.
229*4882a593Smuzhiyun
230*4882a593SmuzhiyunIf a run contains failures, the number of buildtime and runtime failures
231*4882a593Smuzhiyunis listed at the end of the kvm.sh output, which you really should redirect
232*4882a593Smuzhiyunto a file.  The build products and console output of each run is kept in
233*4882a593Smuzhiyuntools/testing/selftests/rcutorture/res in timestamped directories.  A
234*4882a593Smuzhiyungiven directory can be supplied to kvm-find-errors.sh in order to have
235*4882a593Smuzhiyunit cycle you through summaries of errors and full error logs.  For example::
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun	tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh \
238*4882a593Smuzhiyun		tools/testing/selftests/rcutorture/res/2020.01.20-15.54.23
239*4882a593Smuzhiyun
240*4882a593SmuzhiyunHowever, it is often more convenient to access the files directly.
241*4882a593SmuzhiyunFiles pertaining to all scenarios in a run reside in the top-level
242*4882a593Smuzhiyundirectory (2020.01.20-15.54.23 in the example above), while per-scenario
243*4882a593Smuzhiyunfiles reside in a subdirectory named after the scenario (for example,
244*4882a593Smuzhiyun"TREE04").  If a given scenario ran more than once (as in "--configs
245*4882a593Smuzhiyun'56*TREE04'" above), the directories corresponding to the second and
246*4882a593Smuzhiyunsubsequent runs of that scenario include a sequence number, for example,
247*4882a593Smuzhiyun"TREE04.2", "TREE04.3", and so on.
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunThe most frequently used file in the top-level directory is testid.txt.
250*4882a593SmuzhiyunIf the test ran in a git repository, then this file contains the commit
251*4882a593Smuzhiyunthat was tested and any uncommitted changes in diff format.
252*4882a593Smuzhiyun
253*4882a593SmuzhiyunThe most frequently used files in each per-scenario-run directory are:
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun.config:
256*4882a593Smuzhiyun	This file contains the Kconfig options.
257*4882a593Smuzhiyun
258*4882a593SmuzhiyunMake.out:
259*4882a593Smuzhiyun	This contains build output for a specific scenario.
260*4882a593Smuzhiyun
261*4882a593Smuzhiyunconsole.log:
262*4882a593Smuzhiyun	This contains the console output for a specific scenario.
263*4882a593Smuzhiyun	This file may be examined once the kernel has booted, but
264*4882a593Smuzhiyun	it might not exist if the build failed.
265*4882a593Smuzhiyun
266*4882a593Smuzhiyunvmlinux:
267*4882a593Smuzhiyun	This contains the kernel, which can be useful with tools like
268*4882a593Smuzhiyun	objdump and gdb.
269*4882a593Smuzhiyun
270*4882a593SmuzhiyunA number of additional files are available, but are less frequently used.
271*4882a593SmuzhiyunMany are intended for debugging of rcutorture itself or of its scripting.
272*4882a593Smuzhiyun
273*4882a593SmuzhiyunAs of v5.4, a successful run with the default set of scenarios produces
274*4882a593Smuzhiyunthe following summary at the end of the run on a 12-CPU system::
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun    SRCU-N ------- 804233 GPs (148.932/s) [srcu: g10008272 f0x0 ]
277*4882a593Smuzhiyun    SRCU-P ------- 202320 GPs (37.4667/s) [srcud: g1809476 f0x0 ]
278*4882a593Smuzhiyun    SRCU-t ------- 1122086 GPs (207.794/s) [srcu: g0 f0x0 ]
279*4882a593Smuzhiyun    SRCU-u ------- 1111285 GPs (205.794/s) [srcud: g1 f0x0 ]
280*4882a593Smuzhiyun    TASKS01 ------- 19666 GPs (3.64185/s) [tasks: g0 f0x0 ]
281*4882a593Smuzhiyun    TASKS02 ------- 20541 GPs (3.80389/s) [tasks: g0 f0x0 ]
282*4882a593Smuzhiyun    TASKS03 ------- 19416 GPs (3.59556/s) [tasks: g0 f0x0 ]
283*4882a593Smuzhiyun    TINY01 ------- 836134 GPs (154.84/s) [rcu: g0 f0x0 ] n_max_cbs: 34198
284*4882a593Smuzhiyun    TINY02 ------- 850371 GPs (157.476/s) [rcu: g0 f0x0 ] n_max_cbs: 2631
285*4882a593Smuzhiyun    TREE01 ------- 162625 GPs (30.1157/s) [rcu: g1124169 f0x0 ]
286*4882a593Smuzhiyun    TREE02 ------- 333003 GPs (61.6672/s) [rcu: g2647753 f0x0 ] n_max_cbs: 35844
287*4882a593Smuzhiyun    TREE03 ------- 306623 GPs (56.782/s) [rcu: g2975325 f0x0 ] n_max_cbs: 1496497
288*4882a593Smuzhiyun    CPU count limited from 16 to 12
289*4882a593Smuzhiyun    TREE04 ------- 246149 GPs (45.5831/s) [rcu: g1695737 f0x0 ] n_max_cbs: 434961
290*4882a593Smuzhiyun    TREE05 ------- 314603 GPs (58.2598/s) [rcu: g2257741 f0x2 ] n_max_cbs: 193997
291*4882a593Smuzhiyun    TREE07 ------- 167347 GPs (30.9902/s) [rcu: g1079021 f0x0 ] n_max_cbs: 478732
292*4882a593Smuzhiyun    CPU count limited from 16 to 12
293*4882a593Smuzhiyun    TREE09 ------- 752238 GPs (139.303/s) [rcu: g13075057 f0x0 ] n_max_cbs: 99011
294