1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>wq_has_sleeper</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Networking and Network Devices APIs"><link rel="up" href="ch01s02.html" title="Socket Buffer Functions"><link rel="prev" href="API-sk-has-allocations.html" title="sk_has_allocations"><link rel="next" href="API-sock-poll-wait.html" title="sock_poll_wait"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">wq_has_sleeper</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-sk-has-allocations.html">Prev</a>&#160;</td><th width="60%" align="center">Socket Buffer Functions</th><td width="20%" align="right">&#160;<a accesskey="n" href="API-sock-poll-wait.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-wq-has-sleeper"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>wq_has_sleeper &#8212; 
2     check if there are any waiting processes
3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">bool <b class="fsfunc">wq_has_sleeper </b>(</code></td><td>struct socket_wq * <var class="pdparam">wq</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1095907068"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>wq</code></em></span></dt><dd><p>
4     struct socket_wq
5    </p></dd></dl></div></div><div class="refsect1"><a name="idp1095908596"></a><h2>Description</h2><p>
6   Returns true if socket_wq has waiting processes
7   </p><p>
8
9   The purpose of the wq_has_sleeper and sock_poll_wait is to wrap the memory
10   barrier call. They were added due to the race found within the tcp code.
11</p></div><div class="refsect1"><a name="idp1095909532"></a><h2>Consider following tcp code paths</h2><p>
12   </p><p>
13
14   CPU1                  CPU2
15   </p><p>
16
17   sys_select            receive packet
18   ...                 ...
19   __add_wait_queue    update tp-&gt;rcv_nxt
20   ...                 ...
21   tp-&gt;rcv_nxt check   sock_def_readable
22   ...                 {
23   schedule               <code class="function">rcu_read_lock</code>;
24   wq = rcu_dereference(sk-&gt;sk_wq);
25   if (wq &amp;&amp; waitqueue_active(<span class="structname">wq</span>-&gt;wait))
26   wake_up_interruptible(<span class="structname">wq</span>-&gt;wait)
27   ...
28   }
29   </p><p>
30
31   The race for tcp fires when the __add_wait_queue changes done by CPU1 stay
32   in its cache, and so does the tp-&gt;rcv_nxt update on CPU2 side.  The CPU1
33   could then endup calling schedule and sleep forever if there are no more
34   data on the socket.
35</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-sk-has-allocations.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="ch01s02.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="API-sock-poll-wait.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">sk_has_allocations</span>&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;<span class="phrase">sock_poll_wait</span></td></tr></table></div></body></html>
36