From patchwork Sun Mar 1 14:05:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 5387 Received: (qmail 77598 invoked by alias); 2 Mar 2015 08:40:27 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 77566 invoked by uid 89); 2 Mar 2015 08:40:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, DATE_IN_PAST_12_24, SPF_HELO_PASS, T_RP_MATCHES_RCVD, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Message-Id: <080236bd5f23d9be4c47794ad23e96d52d380f5d.1425285061.git.fweimer@redhat.com> In-Reply-To: References: From: Florian Weimer Date: Sun, 1 Mar 2015 15:05:09 +0100 Subject: [PATCH 02/25] pthread_setaffinity (Linux variant): Rewrite to use VLA instead of alloca To: libc-alpha@sourceware.org extend_alloca was used to emulate VLA deallocation. --- sysdeps/unix/sysv/linux/pthread_setaffinity.c | 37 ++++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/sysdeps/unix/sysv/linux/pthread_setaffinity.c b/sysdeps/unix/sysv/linux/pthread_setaffinity.c index 37997e9..69a9a37 100644 --- a/sysdeps/unix/sysv/linux/pthread_setaffinity.c +++ b/sysdeps/unix/sysv/linux/pthread_setaffinity.c @@ -16,7 +16,6 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include @@ -27,27 +26,29 @@ size_t __kernel_cpumask_size attribute_hidden; -/* Determine the current affinity. As a side affect we learn - about the size of the cpumask_t in the kernel. */ +/* Determine the size of cpumask_t in the kernel. */ int __determine_cpumask_size (pid_t tid) { - INTERNAL_SYSCALL_DECL (err); - int res; - size_t psize = 128; - void *p = alloca (psize); - - while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, tid, psize, p), - INTERNAL_SYSCALL_ERROR_P (res, err) - && INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL) - p = extend_alloca (p, psize, 2 * psize); - - if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err)) - return INTERNAL_SYSCALL_ERRNO (res, err); - - __kernel_cpumask_size = res; - + while (1) + { + char buf[psize]; + INTERNAL_SYSCALL_DECL (err); + int res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, tid, psize, buf); + if (INTERNAL_SYSCALL_ERROR_P (res, err) + && INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL) + /* Retry with larger size. */ + psize *= 2; + else if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err)) + return INTERNAL_SYSCALL_ERRNO (res, err); + else + { + /* Size has been determined. */ + __kernel_cpumask_size = res; + break; + } + } return 0; }