xfce4-mailwatch-plugin pegging the CPU usage meter.

Grant Edwards grante at visi.com
Sat Oct 18 17:26:23 CEST 2008


On 2008-10-17, Grant Edwards <grante at visi.com> wrote:

> Right.  But, a select that blocks for a second, checks a
> timeout, then blocks for another second will use a negligible
> amount of CPU.  So that's not actually what's going on.  I
> suspect that when the select() wakes up, the subsequent loop
> that's calling gnutls_*_recv() is spinning without ever
> returning to the top of the outer loop where the select()
> happens.  When I have an hour or two to spare, I'm going to
> take a look at it...

Yup.  That was the problem.  They busy-wait loops in
xfce_mailwatch_net_conn_recv_internal() that spin calling
recv() and gnutls_record_recv() were burning up a lot of CPU
time.  The attached patch drastically reduces CPU usage by
sleeping for 50ms each time through the busy-wait loop.

-- 
Grant


-------------- next part --------------
Index: libmailwatch-core/mailwatch-net-conn.c
===================================================================
--- libmailwatch-core/mailwatch-net-conn.c	(revision 5653)
+++ libmailwatch-core/mailwatch-net-conn.c	(working copy)
@@ -798,8 +798,9 @@
                     return -1;
                 ret = GNUTLS_E_AGAIN;
             }
+            
         } while((GNUTLS_E_INTERRUPTED == ret || GNUTLS_E_AGAIN == ret)
-                && !TIMER_EXPIRED(RECV_TIMEOUT) && SHOULD_CONTINUE(net_conn));
+                && !TIMER_EXPIRED(RECV_TIMEOUT) && SHOULD_CONTINUE(net_conn) && (usleep(50000),1));
         
         if(ret < 0) {
             if(error) {
@@ -829,7 +830,7 @@
         do {
             ret = recv(net_conn->fd, buf, buf_len, MSG_NOSIGNAL);
         } while(ret < 0 && (EINTR == errno || EAGAIN == errno)
-                && !TIMER_EXPIRED(RECV_TIMEOUT) && SHOULD_CONTINUE(net_conn));
+                && !TIMER_EXPIRED(RECV_TIMEOUT) && SHOULD_CONTINUE(net_conn) && (usleep(50000),1));
 
         if(ret < 0) {
             if(error) {


More information about the Xfce mailing list