1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <?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 xmlns:d="http://docbook.org/ns/docbook">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 xmlns:d="http://docbook.org/ns/docbook" name="generator" content="publican v4.1.3" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="SystemTap-SystemTap_Beginners_Guide-2.7-en-US-2.0-1" /><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="https://fedorahosted.org/publican"><img alt="Product Site" src="Common_Content/images//image_left.png" /></a><a class="right" href="https://fedorahosted.org/publican"><img alt="Documentation Site" src="Common_Content/images//image_right.png" /></a></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="syscallsbyprocpidsect.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="errors.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" lang="en-US"><div class="titlepage"><div><div><h2 class="title"><a id="futexcontentionsect"> </a>5.4. Identifying Contended User-Space Locks</h2></div></div></div><a id="idm47723009245584" class="indexterm"></a><a id="idm47722997199504" class="indexterm"></a><a id="idm47722990893216" class="indexterm"></a><a id="idm47723005881056" 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="idm47722999373344" class="indexterm"></a><a id="idm47722995665296" class="indexterm"></a><a id="idm47722999295728" class="indexterm"></a><a id="idm47722993160928" class="indexterm"></a><a id="idm47722993159552" 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="idm47722987638896" class="indexterm"></a><a id="idm47722951877984" class="indexterm"></a><a id="idm47723001271840" 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="para"><div xmlns:d="http://docbook.org/ns/docbook" class="title">futexes.stp</div> <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 & ~(FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME)) != FUTEX_WAIT) next process_names[pid()] = execname() elapsed = gettimeofday_us() - @entry(gettimeofday_us()) lock_waits[pid(), $uaddr] <<< 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 xmlns:d="http://docbook.org/ns/docbook" 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"><a id="futexcontentionoutput"> </a><p class="title"><strong>Example 5.19. <a class="xref" href="futexcontentionsect.html#futexcontention">futexes.stp</a> Sample Output</strong></p><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></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>
|