4 .\" The contents of this file are subject to the terms of the
5 .\" Common Development and Distribution License (the "License").
6 .\" You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 .\" or http://www.opensolaris.org/os/licensing.
10 .\" See the License for the specific language governing permissions
11 .\" and limitations under the License.
13 .\" When distributing Covered Code, include this CDDL HEADER in each
14 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 .\" If applicable, add the following below this CDDL HEADER, with the
16 .\" fields enclosed by brackets "[]" replaced with your own identifying
17 .\" information: Portions Copyright [yyyy] [name of copyright owner]
20 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
21 .TH lockstat 1M "28 Feb 2008" "SunOS 5.11" "System Administration Commands"
23 lockstat \- report kernel lock and profiling statistics
27 \fBlockstat\fR [\fB-ACEHI\fR] [\fB-e\fR \fIevent_list\fR] [\fB-i\fR \fIrate\fR]
28 [\fB-b\fR | \fB-t\fR | \fB-h\fR | \fB-s\fR \fIdepth\fR] [\fB-n\fR \fInrecords\fR]
29 [\fB-l\fR \fIlock\fR [, \fIsize\fR]] [\fB-d\fR \fIduration\fR]
30 [\fB-f\fR \fIfunction\fR [, \fIsize\fR]] [\fB-T\fR] [\fB-ckgwWRpP\fR] [\fB-D\fR \fIcount\fR]
31 [\fB-o\fR \fIfilename\fR] [\fB-x\fR \fIopt\fR [=val]] \fIcommand\fR [\fIargs\fR]
37 The \fBlockstat\fR utility gathers and displays kernel locking and profiling statistics. \fBlockstat\fR allows you to specify which events to watch (for example, spin on adaptive mutex, block on read access to rwlock due to waiting writers, and so forth) how much
38 data to gather for each event, and how to display the data. By default, \fBlockstat\fR monitors all lock contention events, gathers frequency and timing data about those events, and displays the data in decreasing frequency order, so that the most common events appear first.
41 \fBlockstat\fR gathers data until the specified command completes. For example, to gather statistics for a fixed-time interval, use \fBsleep\fR(1) as
42 the command, as follows:
45 \fBexample#\fR \fBlockstat\fR \fBsleep\fR \fB5\fR
48 When the \fB-I\fR option is specified, \fBlockstat\fR establishes a per-processor high-level periodic interrupt source to gather profiling data. The interrupt handler simply generates a \fBlockstat\fR event whose caller is the interrupted PC (program counter).
49 The profiling event is just like any other \fBlockstat\fR event, so all of the normal \fBlockstat\fR options are applicable.
52 \fBlockstat\fR relies on DTrace to modify the running kernel's text to intercept events of interest. This imposes a small but measurable overhead on all system activity, so access to \fBlockstat\fR is restricted to super-user by default. The system administrator
53 can permit other users to use \fBlockstat\fR by granting them additional DTrace privileges. Refer to the \fISolaris Dynamic Tracing Guide\fR for more information about DTrace security features.
57 The following options are supported:
61 If no event selection options are specified, the default is \fB-C\fR.
70 Watch all lock events. \fB-A\fR is equivalent to \fB-CH\fR.
81 Watch contention events.
99 \fB\fB\fR\fB-e\fR \fIevent_list\fR\fR
103 Only watch the specified events. \fIevent\fR \fIlist\fR is a comma-separated list of events or ranges of events such as 1,4-7,35. Run \fBlockstat\fR with no arguments to get a brief description of all events.
125 Watch profiling interrupt events.
132 \fB\fB\fR\fB-i\fR \fIrate\fR\fR
136 Interrupt rate (per second) for \fB-I\fR. The default is 97 Hz, so that profiling doesn't run in lockstep with the clock interrupt (which runs at 100 Hz).
144 \fB\fB-x\fR \fIarg\fR[=\fIval\fR]\fR
148 Enable or modify a DTrace runtime option or D compiler option. The list of options is found in the \fI\fR. Boolean options are enabled by specifying their name. Options with values are set by separating the option name and
149 value with an equals sign (=).
152 .SS "Data Gathering (Mutually Exclusive)"
161 Basic statistics: lock, caller, number of events.
172 Histogram: Timing plus time-distribution histograms.
179 \fB\fB\fR\fB-s\fR \fIdepth\fR\fR
183 Stack trace: Histogram plus stack traces up to \fIdepth\fR frames deep.
194 Timing: Basic plus timing for all events [default].
202 \fB\fB\fR\fB-d\fR \fIduration\fR\fR
206 Only watch events longer than \fIduration\fR.
213 \fB\fB\fR\fB-f\fR \fIfunc[,size]\fR\fR
217 Only watch events generated by \fIfunc\fR, which can be specified as a symbolic name or hex address. \fIsize\fR defaults to the \fBELF\fR symbol size if available, or \fB1\fR if not.
224 \fB\fB\fR\fB-l\fR \fIlock[,size]\fR\fR
228 Only watch \fIlock\fR, which can be specified as a symbolic name or hex address. \fBsize\fR defaults to the \fBELF\fR symbol size or \fB1\fR if the symbol size is not available.
235 \fB\fB\fR\fB-n\fR \fInrecords\fR\fR
239 Maximum number of data records.
250 Trace (rather than sample) events [off by default].
262 Coalesce lock data for lock arrays (for example, \fBpse_mutex[]\fR).
269 \fB\fB\fR\fB-D\fR \fIcount\fR\fR
273 Only display the top \fIcount\fR events of each type.
284 Show total events generated by function. For example, if \fBfoo()\fR calls \fBbar()\fR in a loop, the work done by \fBbar()\fR counts as work generated by \fBfoo()\fR (along with any work done by \fBfoo()\fR itself).
285 The \fB-g\fR option works by counting the total number of stack frames in which each function appears. This implies two things: (1) the data reported by \fB-g\fR can be misleading if the stack traces are not deep enough, and (2) functions that are called recursively might show
286 greater than 100% activity. In light of issue (1), the default data gathering mode when using \fB-g\fR is \fB-s\fR \fB50\fR.
297 Coalesce PCs within functions.
304 \fB\fB\fR\fB-o\fR \fIfilename\fR\fR
308 Direct output to \fIfilename\fR.
319 Sort data by (\fIcount * time\fR) product.
330 Parsable output format.
341 Display rates (events per second) rather than counts.
352 Whichever: distinguish events only by caller, not by lock.
363 Wherever: distinguish events only by lock, not by caller.
369 The following headers appear over various columns of data.
374 \fB\fBCount\fR or \fBops/s\fR\fR
378 Number of times this event occurred, or the rate (times per second) if \fB-R\fR was specified.
389 Percentage of all events represented by this individual event.
400 Percentage of all events generated by this function.
411 Cumulative percentage; a running total of the individuals.
422 Average reference count. This will always be \fB1\fR for exclusive locks (mutexes, spin locks, rwlocks held as writer) but can be greater than \fB1\fR for shared locks (rwlocks held as reader).
433 Average duration of the events in nanoseconds, as appropriate for the event. For the profiling event, duration means interrupt latency.
444 Address of the lock; displayed symbolically if possible.
455 \fBCPU\fR plus processor interrupt level (\fBPIL\fR). For example, if \fBCPU\fR 4 is interrupted while at \fBPIL\fR 6, this will be reported as \fBcpu[4]+6\fR.
466 Address of the caller; displayed symbolically if possible.
471 \fBExample 1 \fRMeasuring Kernel Lock Contention
475 example# \fBlockstat sleep 5\fR
476 Adaptive mutex spin: 2210 events in 5.055 seconds (437 events/sec)
484 Count indv cuml rcnt nsec Lock Caller
485 ------------------------------------------------------------------------
486 269 12% 12% 1.00 2160 service_queue background+0xdc
487 249 11% 23% 1.00 86 service_queue qenable_locked+0x64
488 228 10% 34% 1.00 131 service_queue background+0x15c
489 68 3% 37% 1.00 79 0x30000024070 untimeout+0x1c
490 59 3% 40% 1.00 384 0x300066fa8e0 background+0xb0
491 43 2% 41% 1.00 30 rqcred_lock svc_getreq+0x3c
492 42 2% 43% 1.00 341 0x30006834eb8 background+0xb0
493 41 2% 45% 1.00 135 0x30000021058 untimeout+0x1c
494 40 2% 47% 1.00 39 rqcred_lock svc_getreq+0x260
495 37 2% 49% 1.00 2372 0x300068e83d0 hmestart+0x1c4
496 36 2% 50% 1.00 77 0x30000021058 timeout_common+0x4
497 36 2% 52% 1.00 354 0x300066fa120 background+0xb0
498 32 1% 53% 1.00 97 0x30000024070 timeout_common+0x4
499 31 1% 55% 1.00 2923 0x300069883d0 hmestart+0x1c4
500 29 1% 56% 1.00 366 0x300066fb290 background+0xb0
501 28 1% 57% 1.00 117 0x3000001e040 untimeout+0x1c
502 25 1% 59% 1.00 93 0x3000001e040 timeout_common+0x4
503 22 1% 60% 1.00 25 0x30005161110 sync_stream_buf+0xdc
504 21 1% 60% 1.00 291 0x30006834eb8 putq+0xa4
505 19 1% 61% 1.00 43 0x3000515dcb0 mdf_alloc+0xc
506 18 1% 62% 1.00 456 0x30006834eb8 qenable+0x8
507 18 1% 63% 1.00 61 service_queue queuerun+0x168
508 17 1% 64% 1.00 268 0x30005418ee8 vmem_free+0x3c
511 R/W reader blocked by writer: 76 events in 5.055 seconds (15 events/sec)
513 Count indv cuml rcnt nsec Lock Caller
514 ------------------------------------------------------------------------
515 23 30% 30% 1.00 22590137 0x300098ba358 ufs_dirlook+0xd0
516 17 22% 53% 1.00 5820995 0x3000ad815e8 find_bp+0x10
517 13 17% 70% 1.00 2639918 0x300098ba360 ufs_iget+0x198
518 4 5% 75% 1.00 3193015 0x300098ba360 ufs_getattr+0x54
519 3 4% 79% 1.00 7953418 0x3000ad817c0 find_bp+0x10
520 3 4% 83% 1.00 935211 0x3000ad815e8 find_read_lof+0x14
521 2 3% 86% 1.00 16357310 0x300073a4720 find_bp+0x10
522 2 3% 88% 1.00 2072433 0x300073a4720 find_read_lof+0x14
523 2 3% 91% 1.00 1606153 0x300073a4370 find_bp+0x10
524 1 1% 92% 1.00 2656909 0x300107e7400 ufs_iget+0x198
531 \fBExample 2 \fRMeasuring Hold Times
535 example# \fBlockstat -H -D 10 sleep 1\fR
536 Adaptive mutex spin: 513 events
544 Count indv cuml rcnt nsec Lock Caller
545 -------------------------------------------------------------------------
546 480 5% 5% 1.00 1136 0x300007718e8 putnext+0x40
547 286 3% 9% 1.00 666 0x3000077b430 getf+0xd8
548 271 3% 12% 1.00 537 0x3000077b430 msgio32+0x2fc
549 270 3% 15% 1.00 3670 0x300007718e8 strgetmsg+0x3d4
550 270 3% 18% 1.00 1016 0x300007c38b0 getq_noenab+0x200
551 264 3% 20% 1.00 1649 0x300007718e8 strgetmsg+0xa70
552 216 2% 23% 1.00 6251 tcp_mi_lock tcp_snmp_get+0xfc
553 206 2% 25% 1.00 602 thread_free_lock clock+0x250
554 138 2% 27% 1.00 485 0x300007c3998 putnext+0xb8
555 138 2% 28% 1.00 3706 0x300007718e8 strrput+0x5b8
556 -------------------------------------------------------------------------
563 \fBExample 3 \fRMeasuring Hold Times for Stack Traces Containing a Specific Function
567 example# \fBlockstat -H -f tcp_rput_data -s 50 -D 10 sleep 1\fR
568 Adaptive mutex spin: 11 events in 1.023 seconds (11
577 -------------------------------------------------------------------------
578 Count indv cuml rcnt nsec Lock Caller
579 9 82% 82% 1.00 2540 0x30000031380 tcp_rput_data+0x2b90
581 nsec ------ Time Distribution ------ count Stack
582 256 |@@@@@@@@@@@@@@@@ 5 tcp_rput_data+0x2b90
583 512 |@@@@@@ 2 putnext+0x78
584 1024 |@@@ 1 ip_rput+0xec4
585 2048 | 0 _c_putnext+0x148
586 4096 | 0 hmeread+0x31c
587 8192 | 0 hmeintr+0x36c
589 sbus_intr_wrapper+0x30
592 Count indv cuml rcnt nsec Lock Caller
593 1 9% 91% 1.00 1036 0x30000055380 freemsg+0x44
595 nsec ------ Time Distribution ------ count Stack
596 1024 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1 freemsg+0x44
604 sbus_intr_wrapper+0x30
605 -------------------------------------------------------------------------
612 \fBExample 4 \fRBasic Kernel Profiling
615 For basic profiling, we don't care whether the profiling interrupt sampled \fBfoo()\fR\fB+0x4c\fR or \fBfoo()\fR\fB+0x78\fR; we care only that it sampled somewhere in \fBfoo()\fR, so we use \fB-k\fR. The \fBCPU\fR and \fBPIL\fR aren't relevant to basic profiling because we are measuring the system as a whole, not a particular \fBCPU\fR or interrupt level, so we use \fB-W\fR.
620 example# \fBlockstat -kIW -D 20 ./polltest\fR
621 Profiling interrupt: 82 events in 0.424 seconds (194
630 Count indv cuml rcnt nsec Hottest CPU+PIL Caller
631 -----------------------------------------------------------------------
632 8 10% 10% 1.00 698 cpu[1] utl0
633 6 7% 17% 1.00 299 cpu[0] read
634 5 6% 23% 1.00 124 cpu[1] getf
635 4 5% 28% 1.00 327 cpu[0] fifo_read
636 4 5% 33% 1.00 112 cpu[1] poll
637 4 5% 38% 1.00 212 cpu[1] uiomove
638 4 5% 43% 1.00 361 cpu[1] mutex_tryenter
639 3 4% 46% 1.00 682 cpu[0] write
640 3 4% 50% 1.00 89 cpu[0] pcache_poll
641 3 4% 54% 1.00 118 cpu[1] set_active_fd
642 3 4% 57% 1.00 105 cpu[0] syscall_trap32
643 3 4% 61% 1.00 640 cpu[1] (usermode)
644 2 2% 63% 1.00 127 cpu[1] fifo_poll
645 2 2% 66% 1.00 300 cpu[1] fifo_write
646 2 2% 68% 1.00 669 cpu[0] releasef
647 2 2% 71% 1.00 112 cpu[1] bt_getlowbit
648 2 2% 73% 1.00 247 cpu[1] splx
649 2 2% 76% 1.00 503 cpu[0] mutex_enter
650 2 2% 78% 1.00 467 cpu[0]+10 disp_lock_enter
651 2 2% 80% 1.00 139 cpu[1] default_copyin
652 -----------------------------------------------------------------------
659 \fBExample 5 \fRGenerated-load Profiling
662 In the example above, 5% of the samples were in \fBpoll()\fR. This tells us how much time was spent inside \fBpoll()\fR itself, but tells us nothing about how much work was \fBgenerated\fR by \fBpoll()\fR; that is, how much time we spent
663 in functions called by \fBpoll()\fR. To determine that, we use the \fB-g\fR option. The example below shows that although \fBpolltest\fR spends only 5% of its time in \fBpoll()\fR itself, \fBpoll()\fR-induced work accounts for 34% of
668 Note that the functions that generate the profiling interrupt (\fBlockstat_intr()\fR, \fBcyclic_fire()\fR, and so forth) appear in every stack trace, and therefore are considered to have generated 100% of the load. This illustrates an important point: the generated
669 load percentages do \fBnot\fR add up to 100% because they are not independent. If 72% of all stack traces contain both \fBfoo()\fR and \fBbar()\fR, then both \fBfoo()\fR and \fBbar()\fR are 72% load generators.
674 example# \fBlockstat -kgIW -D 20 ./polltest\fR
675 Profiling interrupt: 80 events in 0.412 seconds (194 events/sec)
683 Count genr cuml rcnt nsec Hottest CPU+PIL Caller
684 -------------------------------------------------------------------------
685 80 100% ---- 1.00 310 cpu[1] lockstat_intr
686 80 100% ---- 1.00 310 cpu[1] cyclic_fire
687 80 100% ---- 1.00 310 cpu[1] cbe_level14
688 80 100% ---- 1.00 310 cpu[1] current_thread
689 27 34% ---- 1.00 176 cpu[1] poll
690 20 25% ---- 1.00 221 cpu[0] write
691 19 24% ---- 1.00 249 cpu[1] read
692 17 21% ---- 1.00 232 cpu[0] write32
693 17 21% ---- 1.00 207 cpu[1] pcache_poll
694 14 18% ---- 1.00 319 cpu[0] fifo_write
695 13 16% ---- 1.00 214 cpu[1] read32
696 10 12% ---- 1.00 208 cpu[1] fifo_read
697 10 12% ---- 1.00 787 cpu[1] utl0
698 9 11% ---- 1.00 178 cpu[0] pcacheset_resolve
699 9 11% ---- 1.00 262 cpu[0] uiomove
700 7 9% ---- 1.00 506 cpu[1] (usermode)
701 5 6% ---- 1.00 195 cpu[1] fifo_poll
702 5 6% ---- 1.00 136 cpu[1] syscall_trap32
703 4 5% ---- 1.00 139 cpu[0] releasef
704 3 4% ---- 1.00 277 cpu[1] polllock
705 -------------------------------------------------------------------------
712 \fBExample 6 \fRGathering Lock Contention and Profiling Data for a Specific Module
715 In this example we use the \fB-f\fR option not to specify a single function, but rather to specify the entire text space of the \fBsbus\fR module. We gather both lock contention and profiling statistics so that contention can be correlated with overall load on the
721 example# \fBmodinfo | grep sbus\fR
722 24 102a8b6f b8b4 59 1 sbus (SBus (sysio) nexus driver)
730 example# \fBlockstat -kICE -f 0x102a8b6f,0xb8b4 sleep 10\fR
731 Adaptive mutex spin: 39 events in 10.042 seconds (4 events/sec)
739 Count indv cuml rcnt nsec Lock Caller
740 -------------------------------------------------------------------------
741 15 38% 38% 1.00 206 0x30005160528 sync_stream_buf
742 7 18% 56% 1.00 14 0x30005160d18 sync_stream_buf
743 6 15% 72% 1.00 27 0x300060c3118 sync_stream_buf
744 5 13% 85% 1.00 24 0x300060c3510 sync_stream_buf
745 2 5% 90% 1.00 29 0x300060c2d20 sync_stream_buf
746 2 5% 95% 1.00 24 0x30005161cf8 sync_stream_buf
747 1 3% 97% 1.00 21 0x30005161110 sync_stream_buf
748 1 3% 100% 1.00 23 0x30005160130 sync_stream_buf
751 Adaptive mutex block: 9 events in 10.042 seconds (1 events/sec)
753 Count indv cuml rcnt nsec Lock Caller
754 -------------------------------------------------------------------------
755 4 44% 44% 1.00 156539 0x30005160528 sync_stream_buf
756 2 22% 67% 1.00 763516 0x30005160d18 sync_stream_buf
757 1 11% 78% 1.00 462130 0x300060c3510 sync_stream_buf
758 1 11% 89% 1.00 288749 0x30005161110 sync_stream_buf
759 1 11% 100% 1.00 1015374 0x30005160130 sync_stream_buf
762 Profiling interrupt: 229 events in 10.042 seconds (23 events/sec)
764 Count indv cuml rcnt nsec Hottest CPU+PIL Caller
766 -------------------------------------------------------------------------
767 89 39% 39% 1.00 426 cpu[0]+6 sync_stream_buf
768 64 28% 67% 1.00 398 cpu[0]+6 sbus_intr_wrapper
769 23 10% 77% 1.00 324 cpu[0]+6 iommu_dvma_kaddr_load
770 21 9% 86% 1.00 512 cpu[0]+6 iommu_tlb_flush
771 14 6% 92% 1.00 342 cpu[0]+6 iommu_dvma_unload
772 13 6% 98% 1.00 306 cpu[1] iommu_dvma_sync
773 5 2% 100% 1.00 389 cpu[1] iommu_dma_bindhdl
774 -------------------------------------------------------------------------
781 \fBExample 7 \fRDetermining the Average PIL (processor interrupt level) for a CPU
785 example# \fBlockstat -Iw -l cpu[3] ./testprog\fR
787 Profiling interrupt: 14791 events in 152.463 seconds (97 events/sec)
789 Count indv cuml rcnt nsec CPU+PIL Hottest Caller
791 -----------------------------------------------------------------------
792 13641 92% 92% 1.00 253 cpu[3] (usermode)
793 579 4% 96% 1.00 325 cpu[3]+6 ip_ocsum+0xe8
794 375 3% 99% 1.00 411 cpu[3]+10 splx
795 154 1% 100% 1.00 527 cpu[3]+4 fas_intr_svc+0x80
796 41 0% 100% 1.00 293 cpu[3]+13 send_mondo+0x18
797 1 0% 100% 1.00 266 cpu[3]+12 zsa_rxint+0x400
798 -----------------------------------------------------------------------
805 \fBExample 8 \fRDetermining which Subsystem is Causing the System to be Busy
809 example# \fBlockstat -s 10 -I sleep 20\fR
811 Profiling interrupt: 4863 events in 47.375 seconds (103 events/sec)
813 Count indv cuml rcnt nsec CPU+PIL Caller
815 -----------------------------------------------------------------------
816 1929 40% 40% 0.00 3215 cpu[0] usec_delay+0x78
817 nsec ------ Time Distribution ------ count Stack
818 4096 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1872 ata_wait+0x90
819 8192 | 27 acersb_get_intr_status+0x34
820 16384 | 29 ata_set_feature+0x124
821 32768 | 1 ata_disk_start+0x15c
823 ghd_waitq_process_and \e
825 ghd_waitq_process_and \e
828 ata_disk_tran_start+0x108
829 -----------------------------------------------------------------------
838 See \fBattributes\fR(5) for descriptions of the following attributes:
847 ATTRIBUTE TYPE
\aATTRIBUTE VALUE
849 Availability
\aSUNWdtrc
855 \fBdtrace\fR(1M), \fBplockstat\fR(1M), \fBattributes\fR(5), \fBlockstat\fR(7D), \fBmutex\fR(9F), \fBrwlock\fR(9F)
858 \fISolaris Dynamic Tracing Guide\fR
862 The profiling support provided by \fBlockstat\fR \fB-I\fR replaces the old (and undocumented) \fB/usr/bin/kgmon\fR and \fB/dev/profile\fR.
865 Tail-call elimination can affect call sites. For example, if \fBfoo()\fR\fB+0x50\fR calls \fBbar()\fR and the last thing \fBbar()\fR does is call \fBmutex_exit()\fR, the compiler can arrange for \fBbar()\fR to
866 branch to \fBmutex_exit()\fRwith a return address of \fBfoo()\fR\fB+0x58\fR. Thus, the \fBmutex_exit()\fR in \fBbar()\fR will appear as though it occurred at \fBfoo()\fR\fB+0x58\fR.
869 The \fBPC\fR in the stack frame in which an interrupt occurs can be bogus because, between function calls, the compiler is free to use the return address register for local storage.
872 When using the \fB-I\fR and \fB-s\fR options together, the interrupted PC will usually not appear anywhere in the stack since the interrupt handler is entered asynchronously, not by a function call from that \fBPC\fR.
875 The \fBlockstat\fR technology is provided on an as-is basis. The format and content of \fBlockstat\fR output reflect the current Solaris kernel implementation and are therefore subject to change in future releases.