Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 95299258dbdf9a86cefd89b97c0d81e5 > files > 100

systemtap-1.2-1.fc13.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>4.4. Identifying Contended User-Space Locks</title><link rel="stylesheet" href="./Common_Content/css/default.css" type="text/css" /><meta name="generator" content="publican 1.6" /><meta name="package" content="Systemtap-SystemTap_Beginners_Guide-1.0-en-US-2.0-2" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="useful-systemtap-scripts.html" title="Chapter 4. Useful SystemTap Scripts" /><link rel="prev" href="syscallsbyprocpidsect.html" title="4.3.6. Tracking System Call Volume Per Process" /><link rel="next" href="errors.html" title="Chapter 5. Understanding SystemTap Errors" /></head><body class=""><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" title="4.4. Identifying Contended User-Space Locks" lang="en-US"><div class="titlepage"><div><div><h2 class="title" id="futexcontentionsect">4.4. Identifying Contended User-Space Locks</h2></div></div></div><a id="id2915305" class="indexterm"></a><a id="id3094669" class="indexterm"></a><a id="id3063442" class="indexterm"></a><a id="id3007878" 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 hangs that you suspect may be caused by <code class="command">futex</code> contentions.
	</div><a id="id3020550" class="indexterm"></a><a id="id4359825" class="indexterm"></a><a id="id2999981" class="indexterm"></a><a id="id2741174" class="indexterm"></a><a id="id3108392" class="indexterm"></a><div class="para">
		Simply put, a <code class="command">futex</code> contention occurs when multiple processes are trying to access the same region of memory. In some cases, this can result in a deadlock between the processes in contention, thereby appearing as an application hang.
	</div><a id="id2818660" class="indexterm"></a><a id="id3003343" class="indexterm"></a><a id="id3107312" class="indexterm"></a><div class="para">
		To do this, <a class="xref" href="futexcontentionsect.html#futexcontention" title="futexes.stp">futexes.stp</a> probes the <code class="command">futex</code> system call.
	</div><div class="formalpara"><h5 class="formalpara" id="futexcontention">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 thread_thislock # short
global thread_blocktime # 
global FUTEX_WAIT = 0 /*, FUTEX_WAKE = 1 */

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

probe syscall.futex {  
  if (op != FUTEX_WAIT) next # don't care about WAKE event originator
  t = tid ()
  process_names[pid()] = execname()
  thread_thislock[t] = $uaddr
  thread_blocktime[t] = gettimeofday_us()
}

probe syscall.futex.return {  
  t = tid()
  ts = thread_blocktime[t]
  if (ts) {
    elapsed = gettimeofday_us() - ts
    lock_waits[pid(), thread_thislock[t]] &lt;&lt;&lt; elapsed
    delete thread_blocktime[t]
    delete thread_thislock[t]
  }
}

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" title="futexes.stp">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 region of memory it contested
			</div></li><li class="listitem"><div class="para">
				How many times the region of memory 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" title="Example 4.19. futexes.stp Sample Output">Example 4.19, “futexes.stp Sample Output”</a> contains an excerpt from the output of <a class="xref" href="futexcontentionsect.html#futexcontention" title="futexes.stp">futexes.stp</a> upon exiting the script (after approximately 20 seconds).
	</div><div class="example" id="futexcontentionoutput"><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><h6>Example 4.19. <a class="xref" href="futexcontentionsect.html#futexcontention" title="futexes.stp">futexes.stp</a> Sample Output</h6></div><br class="example-break" /></div><ul class="docnav"><li class="previous"><a accesskey="p" href="syscallsbyprocpidsect.html"><strong>Prev</strong>4.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 5. Understanding SystemTap Errors</a></li></ul></body></html>