Sophie

Sophie

distrib > Fedora > 17 > i386 > by-pkgid > e2ec330d3ecf5110b4aa890342e53d96 > files > 734

systemtap-client-2.1-2.fc17.i686.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>5.4. Identifying Contended User-Space Locks</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta name="generator" content="publican 2.8" /><meta name="package" content="Systemtap-SystemTap_Beginners_Guide-2.1-en-US-2.1-2" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="useful-systemtap-scripts.html" title="Chapter 5. Useful SystemTap Scripts" /><link rel="prev" href="syscallsbyprocpidsect.html" title="5.3.6. Tracking System Call Volume Per Process" /><link rel="next" href="errors.html" title="Chapter 6. Understanding SystemTap Errors" /></head><body><p id="title"><a class="left" href="http://www.fedoraproject.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://docs.fedoraproject.org"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="syscallsbyprocpidsect.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="errors.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" id="futexcontentionsect" lang="en-US"><div class="titlepage"><div><div keep-together.within-column="always"><h2 class="title" id="futexcontentionsect">5.4. Identifying Contended User-Space Locks</h2></div></div></div><a id="idp1241200" class="indexterm"></a><a id="idm3461488" class="indexterm"></a><a id="idp39087520" class="indexterm"></a><a id="idp6078064" class="indexterm"></a><div class="para">
		This section describes how to identify contended user-space locks throughout the system within a specific time period. The ability to identify contended user-space locks can help you investigate poor program performance that you suspect may be caused by <code class="command">futex</code> contentions.
	</div><a id="idm3317416" class="indexterm"></a><a id="idp332568" class="indexterm"></a><a id="idp503280" class="indexterm"></a><a id="idp8803792" class="indexterm"></a><a id="idm9536400" class="indexterm"></a><div class="para">
		Simply put, <code class="command">futex</code> contention occurs when multiple processes are trying to access the same lock variable at the same time. This can result in a poor performance because the lock serializes execution; one process obtains the lock while the other processes must wait for the lock variable to become available again.
	</div><a id="idm20663392" class="indexterm"></a><a id="idm2653088" class="indexterm"></a><a id="idp39031360" class="indexterm"></a><div class="para">
		The <a class="xref" href="futexcontentionsect.html#futexcontention">futexes.stp</a> script probes the <code class="command">futex</code> system call to show lock contention.
	</div><div class="formalpara" id="futexcontention"><h5 class="formalpara">futexes.stp</h5>
			
<pre class="programlisting">#! /usr/bin/env stap

# This script tries to identify contended user-space locks by hooking
# into the futex system call.

global FUTEX_WAIT = 0 /*, FUTEX_WAKE = 1 */
global FUTEX_PRIVATE_FLAG = 128 /* linux 2.6.22+ */
global FUTEX_CLOCK_REALTIME = 256 /* linux 2.6.29+ */

global lock_waits # long-lived stats on (tid,lock) blockage elapsed time
global process_names # long-lived pid-to-execname mapping

probe syscall.futex.return {  
  if (($op &amp; ~(FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME)) != FUTEX_WAIT) next
  process_names[pid()] = execname()
  elapsed = gettimeofday_us() - @entry(gettimeofday_us())
  lock_waits[pid(), $uaddr] &lt;&lt;&lt; elapsed
}

probe end {
  foreach ([pid+, lock] in lock_waits) 
    printf ("%s[%d] lock %p contended %d times, %d avg us\n",
            process_names[pid], pid, lock, @count(lock_waits[pid,lock]),
            @avg(lock_waits[pid,lock]))
}
</pre>
		</div><div class="para">
		<a class="xref" href="futexcontentionsect.html#futexcontention">futexes.stp</a> needs to be manually stopped; upon exit, it prints the following information:
	</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
				Name and ID of the process responsible for a contention
			</div></li><li class="listitem"><div class="para">
				The location of the contested lock variable
			</div></li><li class="listitem"><div class="para">
				How many times the lock variable was contended
			</div></li><li class="listitem"><div class="para">
				Average time of contention throughout the probe
			</div></li></ul></div><div class="para">
		<a class="xref" href="futexcontentionsect.html#futexcontentionoutput">Example 5.19, “futexes.stp Sample Output”</a> contains an excerpt from the output of <a class="xref" href="futexcontentionsect.html#futexcontention">futexes.stp</a> upon exiting the script (after approximately 20 seconds).
	</div><div class="example" id="futexcontentionoutput"><h6>Example 5.19. <a class="xref" href="futexcontentionsect.html#futexcontention">futexes.stp</a> Sample Output</h6><div class="example-contents"><pre class="screen">[...]
automount[2825] lock 0x00bc7784 contended 18 times, 999931 avg us
synergyc[3686] lock 0x0861e96c contended 192 times, 101991 avg us
synergyc[3758] lock 0x08d98744 contended 192 times, 101990 avg us
synergyc[3938] lock 0x0982a8b4 contended 192 times, 101997 avg us
[...]</pre></div></div><br class="example-break" /></div><ul class="docnav"><li class="previous"><a accesskey="p" href="syscallsbyprocpidsect.html"><strong>Prev</strong>5.3.6. Tracking System Call Volume Per Process</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="errors.html"><strong>Next</strong>Chapter 6. Understanding SystemTap Errors</a></li></ul></body></html>