Hi,

In ecore_wl_init(), adding wayland display fd with ECORE_FD_WRITE flag
make CPU usage 100%. This is true for all efl app running on wayland.

The proper way to monitor the ECORE_FD_WRITE is when the
wl_display_flush() return value < 0 and errno == EAGAIN. And if
wl_display_flush() return, we remove ECORE_FD_WRITE flag from the
display fd.

Patch attached.

From 24f4698235d1a0b75ac963f53e00085a00fea0ef Mon Sep 17 00:00:00 2001
From: Alex Wu <[email protected]>
Date: Fri, 7 Dec 2012 11:17:16 +0800
Subject: [PATCH] ecore-wayland: Fix monitoring ECORE_FD_WRITE defaultly on
 wayland                display fd lead to 100% cpu usage

In ecore_wl_init(), adding wayland display fd with ECORE_FD_WRITE
flag make CPU usage 100%. The proper way to monitor the ECORE_FD_WRITE
is when the wl_display_flush() return value < 0 and errno == EAGAIN.
And if wl_display_flush() return, we remove ECORE_FD_WRITE flag from
the display fd.
---
 trunk/efl/src/lib/ecore_wayland/ecore_wl.c |   36 ++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/trunk/efl/src/lib/ecore_wayland/ecore_wl.c 
b/trunk/efl/src/lib/ecore_wayland/ecore_wl.c
index 7f06a1d..861f6e4 100644
--- a/trunk/efl/src/lib/ecore_wayland/ecore_wl.c
+++ b/trunk/efl/src/lib/ecore_wayland/ecore_wl.c
@@ -7,6 +7,7 @@
 
 /* local function prototypes */
 static Eina_Bool _ecore_wl_shutdown(Eina_Bool close);
+static Eina_Bool _ecore_wl_cb_idle_enterer(void *data);
 static Eina_Bool _ecore_wl_cb_handle_data(void *data, Ecore_Fd_Handler *hdl);
 static void _ecore_wl_cb_handle_global(void *data, struct wl_registry 
*registry, unsigned int id, const char *interface, unsigned int version 
EINA_UNUSED);
 static Eina_Bool _ecore_wl_xkb_init(Ecore_Wl_Display *ewd);
@@ -138,10 +139,11 @@ ecore_wl_init(const char *name)
 
    _ecore_wl_disp->fd_hdl =
      ecore_main_fd_handler_add(_ecore_wl_disp->fd,
-                               ECORE_FD_READ | ECORE_FD_WRITE,
+                               ECORE_FD_READ,
                                _ecore_wl_cb_handle_data, _ecore_wl_disp,
                                NULL, NULL);
 
+   ecore_idle_enterer_add(_ecore_wl_cb_idle_enterer, _ecore_wl_disp);
    wl_list_init(&_ecore_wl_disp->inputs);
    wl_list_init(&_ecore_wl_disp->outputs);
 
@@ -396,10 +398,32 @@ _ecore_wl_shutdown(Eina_Bool close)
    return _ecore_wl_init_count;
 }
 
+static Eina_Bool 
+_ecore_wl_cb_idle_enterer(void *data)
+{
+   Ecore_Wl_Display *ewd;
+   int ret;
+
+   if (!(ewd = data)) return ECORE_CALLBACK_RENEW;
+
+   ret = wl_display_flush(ewd->wl.display);
+   if (ret < 0 && errno == EAGAIN)
+     {
+        ecore_main_fd_handler_active_set(ewd->fd_hdl, ECORE_FD_READ | 
ECORE_FD_WRITE);
+     } 
+   else if (ret < 0) 
+     {
+      /* FIXME: need do error processing? */
+     }
+
+   return ECORE_CALLBACK_RENEW;
+}
+
 static Eina_Bool
 _ecore_wl_cb_handle_data(void *data, Ecore_Fd_Handler *hdl)
 {
    Ecore_Wl_Display *ewd;
+   int ret;
 
    /* LOGFN(__FILE__, __LINE__, __FUNCTION__); */
 
@@ -412,7 +436,15 @@ _ecore_wl_cb_handle_data(void *data, Ecore_Fd_Handler *hdl)
    if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_READ))
      wl_display_dispatch(ewd->wl.display);
    else if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_WRITE))
-     wl_display_flush(ewd->wl.display);
+     {
+        ret = wl_display_flush(ewd->wl.display);
+        if (ret == 0)
+          ecore_main_fd_handler_active_set(hdl, ECORE_FD_READ);
+        else if (ret == -1 && errno != EAGAIN)
+          {
+            /* FIXME: need do error processing? */
+          }
+     }
 
    return ECORE_CALLBACK_RENEW;
 }
-- 
1.7.9.5

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to