Hi All,<br><br>I appreciate if somebody can tell me why spinlock and semaphore are utilized to protect work queue in drbd worker thread. I have some performance issue with regard to the use of this semaphore. Specifically, <span style="background-color: rgb(255, 255, 0);">down_interruptible takes too long to be waked up. </span>Here is the detail:<br>
<br>In drbd_worker.c, function int drbd_worker(struct drbd_thread *thi).<br><br>int drbd_worker(struct drbd_thread *thi)<br>{<br>....<br>                if (<span style="background-color: rgb(255, 255, 0);">down_trylock(&amp;mdev-&gt;data.work.s</span>)) {<br>
                        mutex_lock(&amp;mdev-&gt;data.mutex);<br>                        if (mdev-&gt;data.socket &amp;&amp; !mdev-&gt;net_conf-&gt;no_cork)<br>                                drbd_tcp_uncork(mdev-&gt;data.socket);<br>
                        mutex_unlock(&amp;mdev-&gt;data.mutex);<br><br>                        intr = <span style="background-color: rgb(255, 255, 0);">down_interruptible(&amp;mdev-&gt;data.work.s);</span><br><br>                        mutex_lock(&amp;mdev-&gt;data.mutex);<br>
                        if (mdev-&gt;data.socket  &amp;&amp; !mdev-&gt;net_conf-&gt;no_cork)<br>                                drbd_tcp_cork(mdev-&gt;data.socket);<br>                        mutex_unlock(&amp;mdev-&gt;data.mutex);<br>
                }<br><br>....<br>               w = NULL;<br>                spin_lock_irq(&amp;mdev-&gt;data.work.q_lock);<br>                ERR_IF(list_empty(&amp;mdev-&gt;data.work.q)) {<br>  <span style="background-color: rgb(255, 255, 0);">                      /* something terribly wrong in our logic.</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">                         * we were able to down() the semaphore,</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">                         * but the list is empty... doh.</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">                         *</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">                         * what is the best thing to do now?</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">                         * try again from scratch, restarting the receiver,</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">                         * asender, whatnot? could break even more ugly,</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">                         * e.g. when we are primary, but no good local data.</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">                         *</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">                         * I&#39;ll try to get away just starting over this loop.</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">                         */</span><br>
                        spin_unlock_irq(&amp;mdev-&gt;data.work.q_lock);<br>                        continue;<br>                }<br>...<br>}<br><br>I tried to get rid of semaphore in above as well as in drbd_queue_work in drbd_ini.h. Somehow, the code breaks ugly. I guess I still don`t get the design rational here. Any help is appreciated.<br>
<br>Thanks<br>Ben<br clear="all">Commit yourself to constant self-improvement<br>