内核锁压力测试操作¶
CONFIG_LOCK_TORTURE_TEST¶
CONFIG_LOCK_TORTURE_TEST 配置选项提供了一个内核模块,用于在核心内核锁原语上运行压力测试。 如果需要,可以在运行中的内核上构建内核模块“locktorture”来进行测试。 这些测试通过 printk()
定期输出状态消息,可以使用 dmesg(可能使用 grep 搜索“torture”)检查这些消息。 测试在加载模块时开始,在卸载模块时停止。 此程序基于 RCU 的压力测试方式,通过 rcutorture。
此压力测试包括创建多个内核线程,这些线程获取锁并保持特定时间,从而模拟不同的临界区行为。 可以通过延长此临界区保持时间和/或创建更多 kthread 来模拟锁的争用量。
模块参数¶
此模块具有以下参数
Locktorture 特定参数¶
- nwriters_stress
将压力施加到独占锁所有权(写入者)的内核线程数。 默认值为在线 CPU 数量的两倍。
- nreaders_stress
将压力施加到共享锁所有权(读取者)的内核线程数。 默认值与写入锁的数量相同。 如果用户未指定 nwriters_stress,则读取者和写入者都将是在线 CPU 的数量。
- torture_type
要进行压力测试的锁的类型。 默认情况下,仅对自旋锁进行压力测试。 此模块可以对以下锁进行压力测试,字符串值如下:
- “lock_busted”
模拟有缺陷的锁实现。
- “spin_lock”
spin_lock() 和 spin_unlock() 对。
- “spin_lock_irq”
spin_lock_irq() 和 spin_unlock_irq() 对。
- “rw_lock”
读/写 lock() 和 unlock() rwlock 对。
- “rw_lock_irq”
读/写 lock_irq() 和 unlock_irq() rwlock 对。
- “mutex_lock”
- “rtmutex_lock”
rtmutex_lock() 和 rtmutex_unlock() 对。 内核必须具有 CONFIG_RT_MUTEXES=y。
- “rwsem_lock”
读/写 down() 和 up() 信号量对。
压力测试框架 (RCU + 锁)¶
- shutdown_secs
在终止测试并关闭系统之前运行测试的秒数。 默认为零,这将禁用测试终止和系统关闭。 此功能对于自动化测试很有用。
- onoff_interval
每次尝试执行随机选择的 CPU 热插拔操作之间的秒数。 默认为零,这将禁用 CPU 热插拔。 在 CONFIG_HOTPLUG_CPU=n 内核中,无论为 onoff_interval 指定什么值,locktorture 都会默默地拒绝执行任何 CPU 热插拔操作。
- onoff_holdoff
等待开始 CPU 热插拔操作的秒数。 通常仅当 locktorture 构建到内核中并在启动时自动启动时才使用此选项,在这种情况下,它可以避免启动时代码与 CPU 来来往往混淆。 仅当启用 CONFIG_HOTPLUG_CPU 时,此参数才有用。
- stat_interval
与统计相关的
printk()
之间的秒数。 默认情况下,locktorture 将每 60 秒报告一次统计信息。 将间隔设置为零会导致仅在卸载模块时打印统计信息。- stutter
在暂停相同的时间段之前运行测试的时间长度。 默认为“stutter=5”,以便运行和暂停(大约)五秒的间隔。 指定“stutter=0”会导致测试持续运行而不暂停。
- shuffle_interval
将测试线程保持与 CPU 的特定子集相关的秒数,默认为 3 秒。 与 test_no_idle_hz 结合使用。
- verbose
启用详细调试打印,通过
printk()
。 默认启用。 这些额外信息主要与来自主“压力测试”框架的高级错误和报告相关。
统计¶
统计信息以以下格式打印
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.
用法¶
以下脚本可用于压力测试锁
#!/bin/sh
modprobe locktorture
sleep 3600
rmmod locktorture
dmesg | grep torture:
可以手动检查输出中的错误标志“!!!”。 当然,可以创建一个更详细的脚本来自动检查此类错误。“rmmod”命令强制 printk()
打印“SUCCESS”、“FAILURE”或“RCU_HOTPLUG”指示。 前两个是不言自明的,而最后一个表示虽然没有锁定失败,但检测到 CPU 热插拔问题。
另请参阅: RCU 压力测试操作