0010-lib-ovs-thread-Ensure-that-thread-stacks-are-always-.patch (2424B)
1 From 8147cec9ee8feea9440cf79365709ddc32ff57d5 Mon Sep 17 00:00:00 2001 2 From: Alexandru Ardelean <ardeleanalex@gmail.com> 3 Date: Thu, 4 Feb 2016 09:20:34 +0200 4 Subject: [PATCH] lib/ovs-thread: Ensure that thread stacks are always at least 5 512 kB. 6 7 This makes a difference for libc implementations (such as musl libc) that 8 have a really small default pthread stack size. 9 10 Will reference this discussion: 11 http://patchwork.ozlabs.org/patch/572340/ 12 13 Reported-by: Robert McKay <robert@mckay.com> 14 Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com> 15 [blp@ovn.org made style changes] 16 Signed-off-by: Ben Pfaff <blp@ovn.org> 17 --- 18 lib/ovs-thread.c | 29 +++++++++++++++++++++++++++++ 19 1 file changed, 29 insertions(+) 20 21 diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c 22 index 6ebda07..b0e10ee 100644 23 --- a/lib/ovs-thread.c 24 +++ b/lib/ovs-thread.c 25 @@ -340,6 +340,25 @@ ovsthread_wrapper(void *aux_) 26 return aux.start(aux.arg); 27 } 28 29 +static void 30 +set_min_stack_size(pthread_attr_t *attr, size_t min_stacksize) 31 +{ 32 + size_t stacksize; 33 + int error; 34 + 35 + error = pthread_attr_getstacksize(attr, &stacksize); 36 + if (error) { 37 + ovs_abort(error, "pthread_attr_getstacksize failed"); 38 + } 39 + 40 + if (stacksize < min_stacksize) { 41 + error = pthread_attr_setstacksize(attr, min_stacksize); 42 + if (error) { 43 + ovs_abort(error, "pthread_attr_setstacksize failed"); 44 + } 45 + } 46 +} 47 + 48 /* Starts a thread that calls 'start(arg)'. Sets the thread's name to 'name' 49 * (suffixed by its ovsthread_id()). Returns the new thread's pthread_t. */ 50 pthread_t 51 @@ -358,10 +377,20 @@ ovs_thread_create(const char *name, void *(*start)(void *), void *arg) 52 aux->arg = arg; 53 ovs_strlcpy(aux->name, name, sizeof aux->name); 54 55 - error = pthread_create(&thread, NULL, ovsthread_wrapper, aux); 56 + /* Some small systems use a default stack size as small as 80 kB, but OVS 57 + * requires approximately 384 kB according to the following analysis: 58 + * http://openvswitch.org/pipermail/dev/2016-January/065049.html 59 + * 60 + * We use 512 kB to give us some margin of error. */ 61 + pthread_attr_t attr; 62 + pthread_attr_init(&attr); 63 + set_min_stack_size(&attr, 512 * 1024); 64 + 65 + error = pthread_create(&thread, &attr, ovsthread_wrapper, aux); 66 if (error) { 67 ovs_abort(error, "pthread_create failed"); 68 } 69 + pthread_attr_destroy(&attr); 70 return thread; 71 } 72 73 -- 74 2.1.4 75