]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
tools/xenstore: try to get minimum thread stack size for watch thread
authorJuergen Gross <jgross@suse.com>
Mon, 26 Feb 2018 08:46:12 +0000 (09:46 +0100)
committerWei Liu <wei.liu2@citrix.com>
Fri, 2 Mar 2018 17:26:57 +0000 (17:26 +0000)
When creating a pthread in xs_watch() try to get the minimal needed
size of the thread from glibc instead of using a constant. This avoids
problems when the library is used in programs with large per-thread
memory.

Use dlsym() to get the pointer to __pthread_get_minstack() in order to
avoid linkage problems and fall back to the current constant size if
not found.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Tested-by: Jim Fehlig <jfehlig@suse.com>
tools/xenstore/Makefile
tools/xenstore/xs.c

index 2b99d2bc1b2b97ddcb7d0078aaa137a516a50ea2..0831be0b6fb00e737d5b874eb1b2bf0e0b1c07ef 100644 (file)
@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR)
        ln -sf $< $@
 
 xs.opic: CFLAGS += -DUSE_PTHREAD
+ifeq ($(CONFIG_Linux),y)
+xs.opic: CFLAGS += -DUSE_DLSYM
+libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl
+endif
 
 libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
        $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
index abffd9cd808dddadf27be42b6cda1847822d6849..77700bff2bd264ea1385c047121b5aacc75fb12f 100644 (file)
@@ -16,6 +16,8 @@
     License along with this library; If not, see <http://www.gnu.org/licenses/>.
 */
 
+#define _GNU_SOURCE
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -47,6 +49,10 @@ struct xs_stored_msg {
 
 #include <pthread.h>
 
+#ifdef USE_DLSYM
+#include <dlfcn.h>
+#endif
+
 struct xs_handle {
        /* Communications channel to xenstore daemon. */
        int fd;
@@ -810,12 +816,25 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)
        if (!h->read_thr_exists) {
                sigset_t set, old_set;
                pthread_attr_t attr;
+               static size_t stack_size;
+#ifdef USE_DLSYM
+               size_t (*getsz)(pthread_attr_t *attr);
+#endif
 
                if (pthread_attr_init(&attr) != 0) {
                        mutex_unlock(&h->request_mutex);
                        return false;
                }
-               if (pthread_attr_setstacksize(&attr, READ_THREAD_STACKSIZE) != 0) {
+               if (!stack_size) {
+#ifdef USE_DLSYM
+                       getsz = dlsym(RTLD_DEFAULT, "__pthread_get_minstack");
+                       if (getsz)
+                               stack_size = getsz(&attr);
+#endif
+                       if (stack_size < READ_THREAD_STACKSIZE)
+                               stack_size = READ_THREAD_STACKSIZE;
+               }
+               if (pthread_attr_setstacksize(&attr, stack_size) != 0) {
                        pthread_attr_destroy(&attr);
                        mutex_unlock(&h->request_mutex);
                        return false;