核心鎖壓力測試操作¶
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 壓力測試操作