歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux Kernel 當前運行中 鎖的狀態信息

Linux Kernel 當前運行中 鎖的狀態信息

日期:2017/3/1 10:45:57   编辑:Linux編程

Linux Kernel 當前運行中 鎖的狀態信息【適用於調試模式】。

俺的設備死機的時候,發現是因為鎖導致的,這時候相當郁悶的是沒地方看系統相關鎖的信息,當找到內核文檔下的相關信息後,

大驚:原來開發者已經為俺考慮好這些東東了:進入調試模式就是這麼簡單:

鎖統計信息信息
LOCK STATISTICS

- WHY
鎖競爭會嚴重地影響性能和表現
Because things like lock contention can severely impact performance.

- HOW
如何實現

Lockdep already has hooks in the lock functions and maps lock instances to
lock classes. We build on that. The graph below shows the relation between
the lock functions and the various hooks therein.


__acquire
|
lock _____
| \
| __contended
| |
| <wait>
| _______/
|/
|
__acquired
|
.
<hold>
.
|
__release
|
unlock


lock, unlock - the regular lock functions
__* - the hooks
<> - states

With these hooks we provide the following statistics:
con-bounces - number of lock contention that involved x-cpu data
contentions - number of lock acquisitions that had to wait
wait time min - shortest (non-0) time we ever had to wait for a lock
max - longest time we ever had to wait for a lock
total - total time we spend waiting on this lock
acq-bounces - number of lock acquisitions that involved x-cpu data
acquisitions - number of times we took the lock
hold time min - shortest (non-0) time we ever held the lock
max - longest time we ever held the lock
total - total time this lock was held

From these number various other statistics can be derived, such as:

hold time average = hold time total / acquisitions

These numbers are gathered per lock class, per read/write state (when
applicable).


It also tracks 4 contention points per class. A contention point is a call site
that had to wait on lock acquisition.

- USAGE

Look at the current lock statistics:

( line numbers not part of actual output, done for clarity in the explanation
below )

# less /proc/lock_stat

  1. 01 lock_stat version 0.3
  2. 02 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  3. 03 class name con-bounces contentions waittime-min waittime-max waittime-total acq-bounces acquisitions holdtime-min holdtime-max holdtime-total
  4. 04 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  5. 05
  6. 06 &mm->mmap_sem-W: 233 538 18446744073708 22924.27 607243.51 1342 45806 1.71 8595.89 1180582.34
  7. 07 &mm->mmap_sem-R: 205 587 18446744073708 28403.36 731975.00 1940 412426 0.58 187825.45 6307502.88
  8. 08 ---------------
  9. 09 &mm->mmap_sem 487 [<ffffffff8053491f>] do_page_fault+0x466/0x928
  10. 10 &mm->mmap_sem 179 [<ffffffff802a6200>] sys_mprotect+0xcd/0x21d
  11. 11 &mm->mmap_sem 279 [<ffffffff80210a57>] sys_mmap+0x75/0xce
  12. 12 &mm->mmap_sem 76 [<ffffffff802a490b>] sys_munmap+0x32/0x59
  13. 13 ---------------
  14. 14 &mm->mmap_sem 270 [<ffffffff80210a57>] sys_mmap+0x75/0xce
  15. 15 &mm->mmap_sem 431 [<ffffffff8053491f>] do_page_fault+0x466/0x928
  16. 16 &mm->mmap_sem 138 [<ffffffff802a490b>] sys_munmap+0x32/0x59
  17. 17 &mm->mmap_sem 145 [<ffffffff802a6200>] sys_mprotect+0xcd/0x21d
  18. 18
  19. 19 ...............................................................................................................................................................................................
  20. 20
  21. 21 dcache_lock: 621 623 0.52 118.26 1053.02 6745 91930 0.29 316.29 118423.41
  22. 22 -----------
  23. 23 dcache_lock 179 [<ffffffff80378274>] _atomic_dec_and_lock+0x34/0x54
  24. 24 dcache_lock 113 [<ffffffff802cc17b>] d_alloc+0x19a/0x1eb
  25. 25 dcache_lock 99 [<ffffffff802ca0dc>] d_rehash+0x1b/0x44
  26. 26 dcache_lock 104 [<ffffffff802cbca0>] d_instantiate+0x36/0x8a
  27. 27 -----------
  28. 28 dcache_lock 192 [<ffffffff80378274>] _atomic_dec_and_lock+0x34/0x54
  29. 29 dcache_lock 98 [<ffffffff802ca0dc>] d_rehash+0x1b/0x44
  30. 30 dcache_lock 72 [<ffffffff802cc17b>] d_alloc+0x19a/0x1eb
  31. 31 dcache_lock 112 [<ffffffff802cbca0>] d_instantiate+0x36/0x8a
Copyright © Linux教程網 All Rights Reserved