요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
대상 lock과 stress thread 수
locktorture.rst:24-75| Parameter | 의미 |
|---|---|
| nwriters_stress | exclusive writer thread 수. 기본은 online CPU 수의 두 배 |
| nreaders_stress | shared reader thread 수 |
| torture_type=spin_lock | spin_lock/unlock 검증 |
| torture_type=spin_lock_irq | IRQ variant 검증 |
| torture_type=rw_lock 또는 rw_lock_irq | reader/writer spinlock 검증 |
| torture_type=mutex_lock | mutex 검증 |
| torture_type=rtmutex_lock | CONFIG_RT_MUTEXES의 rt_mutex 검증 |
| torture_type=rwsem_lock | rw_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-149spin_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-170modprobe 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 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
==================================
Kernel Lock Torture Test Operation
==================================
CONFIG_LOCK_TORTURE_TEST
========================
The CONFIG_LOCK_TORTURE_TEST config option provides a kernel module
that runs torture tests on core kernel locking primitives. The kernel
module, 'locktorture', may be built after the fact on the running
kernel to be tested, if desired. The tests periodically output status
messages via printk(), which can be examined via the dmesg (perhaps
grepping for "torture"). The test is started when the module is loaded,
and stops when the module is unloaded. This program is based on how RCU
is tortured, via rcutorture.
This torture test consists of creating a number of kernel threads which
acquire the lock and hold it for specific amount of time, thus simulating
different critical region behaviors. The amount of contention on the lock
can be simulated by either enlarging this critical region hold time and/or
creating more kthreads.
Module Parameters
=================
This module has the following parameters:
Locktorture-specific
--------------------
nwriters_stress
Number of kernel threads that will stress exclusive lock
ownership (writers). The default value is twice the number
of online CPUs.
nreaders_stress
Number of kernel threads that will stress shared lock
ownership (readers). The default is the same amount of writer
locks. If the user did not specify nwriters_stress, then
both readers and writers be the amount of online CPUs.
torture_type
Type of lock to torture. By default, only spinlocks will
be tortured. This module can torture the following locks,
with string values as follows:
- "lock_busted":
Simulates a buggy lock implementation.
- "spin_lock":
spin_lock() and spin_unlock() pairs.
- "spin_lock_irq":
spin_lock_irq() and spin_unlock_irq() pairs.
- "rw_lock":
read/write lock() and unlock() rwlock pairs.
- "rw_lock_irq":
read/write lock_irq() and unlock_irq()
rwlock pairs.
- "mutex_lock":
mutex_lock() and mutex_unlock() pairs.
- "rtmutex_lock":
rtmutex_lock() and rtmutex_unlock() pairs.
Kernel must have CONFIG_RT_MUTEXES=y.
- "rwsem_lock":
read/write down() and up() semaphore pairs.
Torture-framework (RCU + locking)
---------------------------------
shutdown_secs
The number of seconds to run the test before terminating
the test and powering off the system. The default is
zero, which disables test termination and system shutdown.
This capability is useful for automated testing.
onoff_interval
The number of seconds between each attempt to execute a
randomly selected CPU-hotplug operation. Defaults
to zero, which disables CPU hotplugging. In
CONFIG_HOTPLUG_CPU=n kernels, locktorture will silently
refuse to do any CPU-hotplug operations regardless of
what value is specified for onoff_interval.
onoff_holdoff
The number of seconds to wait until starting CPU-hotplug
operations. This would normally only be used when
locktorture was built into the kernel and started
automatically at boot time, in which case it is useful
in order to avoid confusing boot-time code with CPUs
coming and going. This parameter is only useful if
CONFIG_HOTPLUG_CPU is enabled.
stat_interval
Number of seconds between statistics-related printk()s.
By default, locktorture will report stats every 60 seconds.
Setting the interval to zero causes the statistics to
be printed -only- when the module is unloaded.
stutter
The length of time to run the test before pausing for this
same period of time. Defaults to "stutter=5", so as
to run and pause for (roughly) five-second intervals.
Specifying "stutter=0" causes the test to run continuously
without pausing.
shuffle_interval
The number of seconds to keep the test threads affinitized
to a particular subset of the CPUs, defaults to 3 seconds.
Used in conjunction with test_no_idle_hz.
verbose
Enable verbose debugging printing, via printk(). Enabled
by default. This extra information is mostly related to
high-level errors and reports from the main 'torture'
framework.
Statistics
==========
Statistics are printed in the following format::
spin_lock-torture: Writes: Total: 93746064 Max/Min: 0/0 Fail: 0
(A) (B) (C) (D) (E)
(A): Lock type that is being tortured -- torture_type parameter.
(B): Number of writer lock acquisitions. If dealing with a read/write
primitive a second "Reads" statistics line is printed.
(C): Number of times the lock was acquired.
(D): Min and max number of times threads failed to acquire the lock.
(E): true/false values if there were errors acquiring the lock. This should
-only- be positive if there is a bug in the locking primitive's
implementation. Otherwise a lock should never fail (i.e., spin_lock()).
Of course, the same applies for (C), above. A dummy example of this is
the "lock_busted" type.
Usage
=====
The following script may be used to torture locks::
#!/bin/sh
modprobe locktorture
sleep 3600
rmmod locktorture
dmesg | grep torture:
The output can be manually inspected for the error flag of "!!!".
One could of course create a more elaborate script that automatically
checked for such errors. The "rmmod" command forces a "SUCCESS",
"FAILURE", or "RCU_HOTPLUG" indication to be printk()ed. The first
two are self-explanatory, while the last indicates that while there
were no locking failures, CPU-hotplug problems were detected.
Also see: Documentation/RCU/torture.rst
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
CONFIG_LOCK_TORTURE_TEST
1-21CONFIG_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_lock | spin_lock()/spin_unlock() 쌍 |
| spin_lock_irq | spin_lock_irq()/spin_unlock_irq() 쌍 |
| rw_lock | read/write lock()/unlock() rwlock 쌍 |
| rw_lock_irq | read/write lock_irq()/unlock_irq() rwlock 쌍 |
| mutex_lock | mutex_lock()/mutex_unlock() 쌍 |
| rtmutex_lock | rtmutex_lock()/rtmutex_unlock() 쌍, CONFIG_RT_MUTEXES=y 필요 |
| rwsem_lock | read/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_holdoff | CPU hotplug 시작 전 대기 시간이다. Boot 때 자동 시작되는 built-in locktorture가 boot code와 CPU online/offline 동작을 섞지 않도록 할 때 유용하며 CONFIG_HOTPLUG_CPU가 필요하다. |
| stat_interval | 통계 printk() 간격이다. 기본값은 60초이고 0이면 module을 unload할 때만 출력한다. |
| stutter | test를 실행한 뒤 같은 시간 동안 멈추는 주기다. 기본 stutter=5는 약 5초 실행과 5초 정지를 반복하며 0은 중단 없이 계속 실행한다. |
| shuffle_interval | test thread를 특정 CPU subset에 affinity로 묶어 두는 시간이다. 기본값은 3초이며 test_no_idle_hz와 함께 사용한다. |
| verbose | printk() debug 출력을 켠다. 기본 enable이며 주로 상위 수준 error와 torture framework report를 추가한다. |
통계 출력 해석
127-148spin_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에서 확인한다.
Lock을 고의로 경쟁시키는 kernel thread
locktorture.rst:1-23CONFIG_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 구현 실패를 드러냅니다.