locktorture.txt 5.7 KB

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