[Mesa-dev] [PATCH] src: replace RTLD_NOW with RTLD_LAZY

Rob Clark robdclark at gmail.com
Sat Aug 6 02:34:27 UTC 2016


On Fri, Aug 5, 2016 at 8:42 PM, Jan Ziak <0xe2.0x9a.0x9b at gmail.com> wrote:
> Mesa source code prior to this patch uses both RTLD_NOW and RTLD_LAZY.
> This patch removes all RTLD_NOW in favor of RTLD_LAZY.
>
> In comparison to early binding, lazy binding reduces CPU instruction count
> of small GL apps (e.g: glxinfo) by 6 million instructions.
> Larger apps won't notice the difference.

tbh, I don't know the background of existing places that use RTLD_LAZY
instead of RTLD_NOW (but my experience w/ xserver using LAZY has not
been positive, so I think going the other direction seems like a good
idea).. But I'm not sure that optimizing for glxinfo is the best goal.
I know that at least for freedreno a lot of the startup time for small
real gl apps (ie. something that mostly matters for piglit runs) goes
to constructing regalloc interference graph..  maybe there is some way
to leverage what is being done for on-disk shader cache to cache some
of this up-front work and make a meaningful reduction in startup cost
for things that actually do a bit more than glxinfo.  (Plus speeding
up piglit runs is actually a real world benefit..)

BR,
-R


> Signed-off-by: Jan Ziak (http://atom-symbol.net) <0xe2.0x9a.0x9b at gmail.com>
> ---
>  src/egl/drivers/dri2/egl_dri2.c |  6 +++---
>  src/gbm/backends/dri/gbm_dri.c  |  6 +++---
>  src/glx/apple/apple_cgl.c       |  2 +-
>  src/glx/dri_common.c            | 10 +++++-----
>  4 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index a5cab68..3c9f58e 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -449,12 +449,12 @@ dri2_open_driver(_EGLDisplay *disp)
>  #if GLX_USE_TLS
>        snprintf(path, sizeof path,
>                "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name);
> -      dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
> +      dri2_dpy->driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
>  #endif
>        if (dri2_dpy->driver == NULL) {
>          snprintf(path, sizeof path,
>                   "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name);
> -        dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
> +        dri2_dpy->driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
>          if (dri2_dpy->driver == NULL)
>             _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror());
>        }
> @@ -464,7 +464,7 @@ dri2_open_driver(_EGLDisplay *disp)
>
>  #ifdef ANDROID
>        snprintf(path, sizeof path, "%.*s/gallium_dri.so", len, p);
> -      dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
> +      dri2_dpy->driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
>        if (dri2_dpy->driver == NULL)
>           _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror());
>        else
> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
> index c3626e3..a1921b7 100644
> --- a/src/gbm/backends/dri/gbm_dri.c
> +++ b/src/gbm/backends/dri/gbm_dri.c
> @@ -332,12 +332,12 @@ dri_open_driver(struct gbm_dri_device *dri)
>  #if GLX_USE_TLS
>        snprintf(path, sizeof path,
>                 "%.*s/tls/%s_dri.so", len, p, dri->base.driver_name);
> -      dri->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
> +      dri->driver = dlopen(path, RTLD_LAZY| RTLD_GLOBAL);
>  #endif
>        if (dri->driver == NULL) {
>           snprintf(path, sizeof path,
>                    "%.*s/%s_dri.so", len, p, dri->base.driver_name);
> -         dri->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
> +         dri->driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
>        }
>        /* not need continue to loop all paths once the driver is found */
>        if (dri->driver != NULL)
> @@ -345,7 +345,7 @@ dri_open_driver(struct gbm_dri_device *dri)
>
>  #ifdef ANDROID
>        snprintf(path, sizeof path, "%.*s/gallium_dri.so", len, p);
> -      dri->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
> +      dri->driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
>        if (dri->driver == NULL)
>           sprintf("failed to open %s: %s\n", path, dlerror());
>        else
> diff --git a/src/glx/apple/apple_cgl.c b/src/glx/apple/apple_cgl.c
> index 648ed86..a458d34 100644
> --- a/src/glx/apple/apple_cgl.c
> +++ b/src/glx/apple/apple_cgl.c
> @@ -75,7 +75,7 @@ apple_cgl_init(void)
>     }
>
>     (void) dlerror();            /*drain dlerror */
> -   h = dlopen(opengl_framework_path, RTLD_NOW);
> +   h = dlopen(opengl_framework_path, RTLD_LAZY);
>
>     if (NULL == h) {
>        fprintf(stderr, "error: unable to dlopen %s : %s\n",
> diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
> index 6728d38..c7b7562 100644
> --- a/src/glx/dri_common.c
> +++ b/src/glx/dri_common.c
> @@ -42,8 +42,8 @@
>  #include "dri_common.h"
>  #include "loader.h"
>
> -#ifndef RTLD_NOW
> -#define RTLD_NOW 0
> +#ifndef RTLD_LAZY
> +#define RTLD_LAZY 0
>  #endif
>  #ifndef RTLD_GLOBAL
>  #define RTLD_GLOBAL 0
> @@ -103,7 +103,7 @@ driOpenDriver(const char *driverName)
>     int len;
>
>     /* Attempt to make sure libGL symbols will be visible to the driver */
> -   glhandle = dlopen(GL_LIB_NAME, RTLD_NOW | RTLD_GLOBAL);
> +   glhandle = dlopen(GL_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
>
>     libPaths = NULL;
>     if (geteuid() == getuid()) {
> @@ -131,14 +131,14 @@ driOpenDriver(const char *driverName)
>        snprintf(realDriverName, sizeof realDriverName,
>                 "%.*s/tls/%s_dri.so", len, p, driverName);
>        InfoMessageF("OpenDriver: trying %s\n", realDriverName);
> -      handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
> +      handle = dlopen(realDriverName, RTLD_LAZY | RTLD_GLOBAL);
>  #endif
>
>        if (handle == NULL) {
>           snprintf(realDriverName, sizeof realDriverName,
>                    "%.*s/%s_dri.so", len, p, driverName);
>           InfoMessageF("OpenDriver: trying %s\n", realDriverName);
> -         handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
> +         handle = dlopen(realDriverName, RTLD_LAZY | RTLD_GLOBAL);
>        }
>
>        if (handle != NULL)
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list