A few quick tips and essential commands to view lock statistics are as follows (this assumes, of course, that CONFIG_LOCK_STAT is on):
Do what? | Command |
Clear lock stats | sudo sh -c "echo 0 > /proc/lock_stat" |
Enable lock stats | sudo sh -c "echo 1 > /proc/sys/kernel/lock_stat" |
Disable lock stats | sudo sh -c "echo 0 > /proc/sys/kernel/lock_stat" |
Â
Next, a simple demo to see locking statistics: we write a very simple Bash script, ch13/3_lockdep/lock_stats_demo.sh (check out its code in this book's GitHub repo). It clears and enables locking statistics, then simply runs the cat /proc/self/cmdline command. This will actually trigger a chain of code to run deep within the kernel (within fs/proc mostly); several global – shared writable – data structures will need to be looked up. This will constitute a critical section and thus locks will be acquired. Our script will...