| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 3 |
]> |
| 4 |
|
| 5 |
|
| 6 |
<section id="futexcontentionsect"> |
| 7 |
<title>Identifying Contended User-Space Locks</title> |
| 8 |
|
| 9 |
<indexterm> |
| 10 |
<primary>script examples</primary> |
| 11 |
<secondary>identifying contended user-space locks (futex contentions)</secondary> |
| 12 |
</indexterm> |
| 13 |
|
| 14 |
<indexterm> |
| 15 |
<primary>examples of SystemTap scripts</primary> |
| 16 |
<secondary>identifying contended user-space locks (futex contentions)</secondary> |
| 17 |
</indexterm> |
| 18 |
|
| 19 |
<indexterm> |
| 20 |
<primary>identifying contended user-space locks (futex contentions)</primary> |
| 21 |
<secondary>examples of SystemTap scripts</secondary> |
| 22 |
</indexterm> |
| 23 |
|
| 24 |
<indexterm> |
| 25 |
<primary>contended user-space locks (futex contentions), identifying</primary> |
| 26 |
<secondary>examples of SystemTap scripts</secondary> |
| 27 |
</indexterm> |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
<remark> |
| 32 |
WAR STORY: Futex contention http://sourceware.org/systemtap/wiki/WSFutexContention?highlight=((WarStories)) |
| 33 |
</remark> |
| 34 |
|
| 35 |
<para>This section describes how to identify contended |
| 36 |
user-space locks throughout the system within a specific time |
| 37 |
period. The ability to identify contended user-space locks can help |
| 38 |
you investigate poor program performance that you suspect may be |
| 39 |
caused by <command>futex</command> contentions.</para> |
| 40 |
<indexterm> |
| 41 |
<primary>futex contentions, identifying</primary> |
| 42 |
<secondary>examples of SystemTap scripts</secondary> |
| 43 |
</indexterm> |
| 44 |
|
| 45 |
<indexterm> |
| 46 |
<primary>futex contention, definition</primary> |
| 47 |
<secondary>examples of SystemTap scripts</secondary> |
| 48 |
</indexterm> |
| 49 |
|
| 50 |
<indexterm> |
| 51 |
<primary>script examples</primary> |
| 52 |
<secondary>futex (lock) contentions</secondary> |
| 53 |
</indexterm> |
| 54 |
|
| 55 |
<indexterm> |
| 56 |
<primary>examples of SystemTap scripts</primary> |
| 57 |
<secondary>futex (lock) contentions</secondary> |
| 58 |
</indexterm> |
| 59 |
|
| 60 |
<indexterm> |
| 61 |
<primary>futex (lock) contentions</primary> |
| 62 |
<secondary>examples of SystemTap scripts</secondary> |
| 63 |
</indexterm> |
| 64 |
|
| 65 |
<para>Simply put, <command>futex</command> contention occurs |
| 66 |
when multiple processes are trying to access the same lock |
| 67 |
variable at the same time. This can result in a poor |
| 68 |
performance because the lock serializes execution; one process obtains |
| 69 |
the lock while the other processes must wait for the lock |
| 70 |
variable to become available again.</para> |
| 71 |
<!-- next 2 indexterms for futex system call --> |
| 72 |
|
| 73 |
<indexterm> |
| 74 |
<primary>script examples</primary> |
| 75 |
<secondary>futex system call</secondary> |
| 76 |
</indexterm> |
| 77 |
|
| 78 |
<indexterm> |
| 79 |
<primary>examples of SystemTap scripts</primary> |
| 80 |
<secondary>futex system call</secondary> |
| 81 |
</indexterm> |
| 82 |
|
| 83 |
<indexterm> |
| 84 |
<primary>futex system call</primary> |
| 85 |
<secondary>examples of SystemTap scripts</secondary> |
| 86 |
</indexterm> |
| 87 |
|
| 88 |
<para>The <xref linkend="futexcontention"/> script probes the <command>futex</command> system call to show lock contention.</para> |
| 89 |
|
| 90 |
<formalpara id="futexcontention"> |
| 91 |
<title>futexes.stp</title> |
| 92 |
<para> |
| 93 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/process/futexes.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 94 |
</para> |
| 95 |
</formalpara> |
| 96 |
|
| 97 |
<para><xref linkend="futexcontention"/> needs to be manually stopped; upon exit, it prints the following information:</para> |
| 98 |
|
| 99 |
<itemizedlist> |
| 100 |
<listitem><para>Name and ID of the process responsible for a contention</para></listitem> |
| 101 |
<listitem><para>The location of the contested lock variable</para></listitem> |
| 102 |
<listitem><para>How many times the lock variable was contended</para></listitem> |
| 103 |
<listitem><para>Average time of contention throughout the probe</para></listitem> |
| 104 |
</itemizedlist> |
| 105 |
|
| 106 |
<para><xref linkend="futexcontentionoutput"/> contains an excerpt from the output of <xref linkend="futexcontention"/> upon exiting the script (after approximately 20 seconds).</para> |
| 107 |
|
| 108 |
|
| 109 |
<example id="futexcontentionoutput"> |
| 110 |
<title><xref linkend="futexcontention"/> Sample Output</title> |
| 111 |
<screen>[...] |
| 112 |
automount[2825] lock 0x00bc7784 contended 18 times, 999931 avg us |
| 113 |
synergyc[3686] lock 0x0861e96c contended 192 times, 101991 avg us |
| 114 |
synergyc[3758] lock 0x08d98744 contended 192 times, 101990 avg us |
| 115 |
synergyc[3938] lock 0x0982a8b4 contended 192 times, 101997 avg us |
| 116 |
[...]</screen> |
| 117 |
</example> |
| 118 |
|
| 119 |
<!-- global thread_thislock # short |
| 120 |
global thread_blocktime # |
| 121 |
global FUTEX_WAIT = 0, FUTEX_WAKE = 1 |
| 122 |
|
| 123 |
global lock_waits # long-lived stats on (tid,lock) blockage elapsed time |
| 124 |
global process_names # long-lived pid-to-execname mapping |
| 125 |
|
| 126 |
probe syscall.futex { |
| 127 |
if (op != FUTEX_WAIT) next # we don't care about originators of WAKE events |
| 128 |
t = tid () |
| 129 |
process_names[pid()] = execname() |
| 130 |
thread_thislock[t] = $uaddr |
| 131 |
thread_blocktime[t] = gettimeofday_us() |
| 132 |
} |
| 133 |
|
| 134 |
probe syscall.futex.return { |
| 135 |
t = tid() |
| 136 |
ts = thread_blocktime[t] |
| 137 |
if (ts) { |
| 138 |
elapsed = gettimeofday_us() - ts |
| 139 |
lock_waits[pid(), thread_thislock[t]] <<< elapsed |
| 140 |
delete thread_blocktime[t] |
| 141 |
delete thread_thislock[t] |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
probe end { |
| 146 |
foreach ([pid+, lock] in lock_waits) |
| 147 |
printf ("%s[%d] lock %p contended %d times, %d avg us\n", |
| 148 |
process_names[pid], pid, lock, @count(lock_waits[pid,lock]), @avg(lock_waits[pid,lock])) |
| 149 |
} --> |
| 150 |
</section> |
| 151 |
|