← Documents Documentation/locking/locktorture.rst GitHub 원문 ↗

Linux 6.18.37 · Locking

Kernel lock torture test

locktorture module로 writer·reader 경쟁, CPU hotplug와 stutter를 주어 lock primitive의 정확성을 장시간 검증하는 방법을 설명합니다.

Source pathDocumentation/locking/locktorture.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Lock을 고의로 경쟁시키는 kernel thread

locktorture.rst:1-23

CONFIG_LOCK_TORTURE_TEST는 core lock primitive를 반복 획득하고 일정 시간 보유하는 kernel thread를 생성합니다. Thread 수와 critical section hold time을 키워 contention을 조절하고, module load부터 unload까지 계속 실행하며 status를 printk로 보고합니다.

이 테스트는 일반 unit test처럼 한 번의 반환값만 검사하지 않습니다. 장시간 scheduler interleaving, reader·writer 경쟁, CPU hotplug, affinity 이동과 pause/resume을 섞어 매우 드문 race와 lock 구현 실패를 드러냅니다.

대상 lock과 stress thread 수

locktorture.rst:24-75
Parameter의미
nwriters_stressexclusive writer thread 수. 기본은 online CPU 수의 두 배
nreaders_stressshared reader thread 수
torture_type=spin_lockspin_lock/unlock 검증
torture_type=spin_lock_irqIRQ variant 검증
torture_type=rw_lock 또는 rw_lock_irqreader/writer spinlock 검증
torture_type=mutex_lockmutex 검증
torture_type=rtmutex_lockCONFIG_RT_MUTEXES의 rt_mutex 검증
torture_type=rwsem_lockrw_semaphore 검증
torture_type=lock_busted실패 검출 경로를 확인하는 의도적으로 잘못된 lock

Torture framework 공통 parameter

locktorture.rst:76-126
  • shutdown_secs: 지정 시간 뒤 test 종료와 poweroff, 0이면 비활성
  • onoff_interval: 무작위 CPU hotplug 시도 간격
  • onoff_holdoff: boot 초기 code를 방해하지 않도록 hotplug 시작을 지연
  • stat_interval: 통계 printk 주기, 0이면 unload 때만 출력
  • stutter: 같은 시간만큼 실행과 정지를 반복, 0이면 연속 실행
  • shuffle_interval: test thread CPU affinity subset을 바꾸는 간격
  • verbose: framework 오류와 상태 메시지 출력

결과 행 해석

locktorture.rst:127-149
spin_lock-torture: Writes: Total: 93746064 Max/Min: 0/0 Fail: 0

Total은 획득 횟수이고 read/write primitive면 Reads 행도 나옵니다. Max/Min은 thread별 실패 횟수 범위이며 blocking lock operation은 정상 구현에서 실패하면 안 됩니다. Fail이 true이거나 !!! 표시가 나오면 lock 구현 또는 test 환경에 문제가 있습니다.

한 시간 실행 예

locktorture.rst:150-170
modprobe locktorture torture_type=mutex_lock \
    nwriters_stress=16 stat_interval=60
sleep 3600
rmmod locktorture
dmesg | grep 'torture:'

rmmod는 최종 SUCCESS, FAILURE 또는 RCU_HOTPLUG 결과를 출력합니다. RCU_HOTPLUG는 lock failure는 없었지만 CPU hotplug 관련 문제가 관찰되었다는 뜻입니다. Automated test에서는 !!!, FAILURE와 unexpected hotplug 결과를 모두 failure condition으로 수집해야 합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ==================================
2 Kernel Lock Torture Test Operation
3 ==================================
4
5 CONFIG_LOCK_TORTURE_TEST
6 ========================
7
8 The CONFIG_LOCK_TORTURE_TEST config option provides a kernel module
9 that runs torture tests on core kernel locking primitives. The kernel
10 module, 'locktorture', may be built after the fact on the running
11 kernel to be tested, if desired. The tests periodically output status
12 messages via printk(), which can be examined via the dmesg (perhaps
13 grepping for "torture"). The test is started when the module is loaded,
14 and stops when the module is unloaded. This program is based on how RCU
15 is tortured, via rcutorture.
16
17 This torture test consists of creating a number of kernel threads which
18 acquire the lock and hold it for specific amount of time, thus simulating
19 different critical region behaviors. The amount of contention on the lock
20 can be simulated by either enlarging this critical region hold time and/or
21 creating more kthreads.
22
23
24 Module Parameters
25 =================
26
27 This module has the following parameters:
28
29
30 Locktorture-specific
31 --------------------
32
33 nwriters_stress
34 Number of kernel threads that will stress exclusive lock
35 ownership (writers). The default value is twice the number
36 of online CPUs.
37
38 nreaders_stress
39 Number of kernel threads that will stress shared lock
40 ownership (readers). The default is the same amount of writer
41 locks. If the user did not specify nwriters_stress, then
42 both readers and writers be the amount of online CPUs.
43
44 torture_type
45 Type of lock to torture. By default, only spinlocks will
46 be tortured. This module can torture the following locks,
47 with string values as follows:
48
49 - "lock_busted":
50 Simulates a buggy lock implementation.
51
52 - "spin_lock":
53 spin_lock() and spin_unlock() pairs.
54
55 - "spin_lock_irq":
56 spin_lock_irq() and spin_unlock_irq() pairs.
57
58 - "rw_lock":
59 read/write lock() and unlock() rwlock pairs.
60
61 - "rw_lock_irq":
62 read/write lock_irq() and unlock_irq()
63 rwlock pairs.
64
65 - "mutex_lock":
66 mutex_lock() and mutex_unlock() pairs.
67
68 - "rtmutex_lock":
69 rtmutex_lock() and rtmutex_unlock() pairs.
70 Kernel must have CONFIG_RT_MUTEXES=y.
71
72 - "rwsem_lock":
73 read/write down() and up() semaphore pairs.
74
75
76 Torture-framework (RCU + locking)
77 ---------------------------------
78
79 shutdown_secs
80 The number of seconds to run the test before terminating
81 the test and powering off the system. The default is
82 zero, which disables test termination and system shutdown.
83 This capability is useful for automated testing.
84
85 onoff_interval
86 The number of seconds between each attempt to execute a
87 randomly selected CPU-hotplug operation. Defaults
88 to zero, which disables CPU hotplugging. In
89 CONFIG_HOTPLUG_CPU=n kernels, locktorture will silently
90 refuse to do any CPU-hotplug operations regardless of
91 what value is specified for onoff_interval.
92
93 onoff_holdoff
94 The number of seconds to wait until starting CPU-hotplug
95 operations. This would normally only be used when
96 locktorture was built into the kernel and started
97 automatically at boot time, in which case it is useful
98 in order to avoid confusing boot-time code with CPUs
99 coming and going. This parameter is only useful if
100 CONFIG_HOTPLUG_CPU is enabled.
101
102 stat_interval
103 Number of seconds between statistics-related printk()s.
104 By default, locktorture will report stats every 60 seconds.
105 Setting the interval to zero causes the statistics to
106 be printed -only- when the module is unloaded.
107
108 stutter
109 The length of time to run the test before pausing for this
110 same period of time. Defaults to "stutter=5", so as
111 to run and pause for (roughly) five-second intervals.
112 Specifying "stutter=0" causes the test to run continuously
113 without pausing.
114
115 shuffle_interval
116 The number of seconds to keep the test threads affinitized
117 to a particular subset of the CPUs, defaults to 3 seconds.
118 Used in conjunction with test_no_idle_hz.
119
120 verbose
121 Enable verbose debugging printing, via printk(). Enabled
122 by default. This extra information is mostly related to
123 high-level errors and reports from the main 'torture'
124 framework.
125
126
127 Statistics
128 ==========
129
130 Statistics are printed in the following format::
131
132 spin_lock-torture: Writes: Total: 93746064 Max/Min: 0/0 Fail: 0
133 (A) (B) (C) (D) (E)
134
135 (A): Lock type that is being tortured -- torture_type parameter.
136
137 (B): Number of writer lock acquisitions. If dealing with a read/write
138 primitive a second "Reads" statistics line is printed.
139
140 (C): Number of times the lock was acquired.
141
142 (D): Min and max number of times threads failed to acquire the lock.
143
144 (E): true/false values if there were errors acquiring the lock. This should
145 -only- be positive if there is a bug in the locking primitive's
146 implementation. Otherwise a lock should never fail (i.e., spin_lock()).
147 Of course, the same applies for (C), above. A dummy example of this is
148 the "lock_busted" type.
149
150 Usage
151 =====
152
153 The following script may be used to torture locks::
154
155 #!/bin/sh
156
157 modprobe locktorture
158 sleep 3600
159 rmmod locktorture
160 dmesg | grep torture:
161
162 The output can be manually inspected for the error flag of "!!!".
163 One could of course create a more elaborate script that automatically
164 checked for such errors. The "rmmod" command forces a "SUCCESS",
165 "FAILURE", or "RCU_HOTPLUG" indication to be printk()ed. The first
166 two are self-explanatory, while the last indicates that while there
167 were no locking failures, CPU-hotplug problems were detected.
168
169 Also see: Documentation/RCU/torture.rst
170

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

CONFIG_LOCK_TORTURE_TEST

1-21

CONFIG_LOCK_TORTURE_TEST option은 핵심 kernel locking primitive에 torture test를 수행하는 locktorture module을 제공한다. 원한다면 시험할 running kernel에 맞춰 module을 나중에 별도로 build할 수 있다.

Test는 printk()로 주기적인 상태 message를 출력하며 dmesg에서 확인할 수 있다. torture 문자열로 grep하면 관련 message를 찾기 쉽다. Module을 load하면 test가 시작되고 unload하면 끝난다. 이 program은 RCU를 시험하는 rcutorture의 방식을 바탕으로 작성되었다.

Locktorture는 여러 kernel thread를 만들고 각 thread가 lock을 획득해 일정 시간 보유하게 함으로써 서로 다른 critical region 동작을 재현한다. Critical region의 lock 보유 시간을 늘리거나 kthread 수를 늘리면 lock contention을 높일 수 있다.

Locktorture 전용 module parameter

24-74
Parameter설명
nwriters_stress배타적 lock ownership을 압박하는 writer kernel thread 수다. 기본값은 online CPU 수의 두 배다.
nreaders_stress공유 lock ownership을 압박하는 reader kernel thread 수다. 기본값은 writer 수와 같다. nwriters_stress를 지정하지 않았다면 reader와 writer가 각각 online CPU 수만큼 생성된다.
torture_type시험할 lock 종류다. 기본값은 spin_lock이며 아래 문자열 중 하나를 사용한다.
torture_type시험 대상
lock_busted결함이 있는 lock 구현을 흉내 낸다
spin_lockspin_lock()/spin_unlock() 쌍
spin_lock_irqspin_lock_irq()/spin_unlock_irq() 쌍
rw_lockread/write lock()/unlock() rwlock 쌍
rw_lock_irqread/write lock_irq()/unlock_irq() rwlock 쌍
mutex_lockmutex_lock()/mutex_unlock() 쌍
rtmutex_lockrtmutex_lock()/rtmutex_unlock() 쌍, CONFIG_RT_MUTEXES=y 필요
rwsem_lockread/write down()/up() semaphore 쌍

공통 torture framework parameter

76-124
Parameter설명
shutdown_secs지정한 초만큼 test한 뒤 test를 끝내고 system power를 끈다. 기본값 0은 자동 종료를 disable하며 자동화 시험에 유용하다.
onoff_interval무작위 CPU hotplug operation을 시도하는 간격이다. 기본값 0은 hotplug를 disable한다. CONFIG_HOTPLUG_CPU=n이면 지정값과 무관하게 hotplug를 조용히 거부한다.
onoff_holdoffCPU hotplug 시작 전 대기 시간이다. Boot 때 자동 시작되는 built-in locktorture가 boot code와 CPU online/offline 동작을 섞지 않도록 할 때 유용하며 CONFIG_HOTPLUG_CPU가 필요하다.
stat_interval통계 printk() 간격이다. 기본값은 60초이고 0이면 module을 unload할 때만 출력한다.
stuttertest를 실행한 뒤 같은 시간 동안 멈추는 주기다. 기본 stutter=5는 약 5초 실행과 5초 정지를 반복하며 0은 중단 없이 계속 실행한다.
shuffle_intervaltest thread를 특정 CPU subset에 affinity로 묶어 두는 시간이다. 기본값은 3초이며 test_no_idle_hz와 함께 사용한다.
verboseprintk() debug 출력을 켠다. 기본 enable이며 주로 상위 수준 error와 torture framework report를 추가한다.

통계 출력 해석

127-148
spin_lock-torture: Writes:  Total: 93746064  Max/Min: 0/0  Fail: 0
(A)                     (B)            (C)         (D)        (E)
  • (A)는 torture_type으로 선택한 lock 종류다.
  • (B)는 writer lock acquisition 통계라는 뜻이다. Read/write primitive를 시험하면 별도의 Reads 통계 줄도 출력한다.
  • (C)는 lock 획득 횟수다.
  • (D)는 thread가 lock 획득에 실패한 횟수의 최댓값과 최솟값이다.
  • (E)는 lock 획득 error 여부를 나타내는 boolean 값이다. Lock primitive 구현에 bug가 있을 때만 positive여야 한다. 정상 spin_lock()은 실패하지 않는다. lock_busted가 의도적인 실패 예다.

실행 예와 결과 판정

150-169
#!/bin/sh

modprobe locktorture
sleep 3600
rmmod locktorture
dmesg | grep torture:

출력에서 error flag인 !!!를 직접 확인하거나 이를 자동으로 검사하는 script를 작성할 수 있다. rmmod는 SUCCESS, FAILURE, RCU_HOTPLUG 중 하나를 printk()하게 만든다. 앞의 두 값은 성공과 실패를 뜻하고 RCU_HOTPLUG는 locking failure는 없었지만 CPU hotplug 문제가 발견되었다는 뜻이다.

공통 torture framework의 추가 내용은 Documentation/RCU/torture.rst에서 확인한다.