From patchwork Sun Mar 1 14:05:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 444987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7162F1400EA for ; Mon, 2 Mar 2015 20:27:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=KUaFDVdP; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:in-reply-to:references:from:date :subject:to; q=dns; s=default; b=wo79iXvUnwiqwg14A5FUmaWGUJZnFm4 2Vpxm/cBkvDLRiKykRWH9eMQgCuSg99Dxjhq64iOa7Ssj8Z/CqQ21/5udUH8LwKi 5/2Ur2XGBzD2R5F8tUv0Qw45qtZRKv/5WWHIEf3CmL6ROR6Gz9vbbrIDGrCVM9Jr EXTOGbWJo9/o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:in-reply-to:references:from:date :subject:to; s=default; bh=I5DztfADjxNhweYVM+Le8aHTi4s=; b=KUaFD VdP33V0GBCgwkIsqBo4f2ExY20b+o5aYsOYG5YV0h5r6oP3jnMhMJu9ELFxlNkfc J8IiyPZjHSeTEvB15X0I9H2iSLQ89P06JDyL/MKmmM7FPc4+yurTi74v6fBeoRrc Cz+SdWY4EepcWampC7FBhnDfIqOa0L8jN/RHZc= Received: (qmail 112429 invoked by alias); 2 Mar 2015 09:26:42 -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 112341 invoked by uid 89); 2 Mar 2015 09:26:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 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: <206ddd5496c544ce29259ef18f4cbadc6fe0619e.1425285061.git.fweimer@redhat.com> In-Reply-To: References: From: Florian Weimer Date: Sun, 1 Mar 2015 15:05:41 +0100 Subject: [PATCH 04/25] sched_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/sched_setaffinity.c | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/sysdeps/unix/sysv/linux/sched_setaffinity.c b/sysdeps/unix/sysv/linux/sched_setaffinity.c index b528617..a9299d8 100644 --- a/sysdeps/unix/sysv/linux/sched_setaffinity.c +++ b/sysdeps/unix/sysv/linux/sched_setaffinity.c @@ -22,7 +22,6 @@ #include #include #include -#include #ifdef __NR_sched_setaffinity @@ -34,25 +33,29 @@ __sched_setaffinity_new (pid_t pid, size_t cpusetsize, const cpu_set_t *cpuset) { if (__glibc_unlikely (__kernel_cpumask_size == 0)) { - INTERNAL_SYSCALL_DECL (err); - int res; - size_t psize = 128; - void *p = alloca (psize); - - while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, getpid (), - 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)) + while (1) { - __set_errno (INTERNAL_SYSCALL_ERRNO (res, err)); - return -1; + char buf[psize]; + INTERNAL_SYSCALL_DECL (err); + int res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, getpid (), + 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)) + { + __set_errno (INTERNAL_SYSCALL_ERRNO (res, err)); + return -1; + } + else + { + /* Size has been determined. */ + __kernel_cpumask_size = res; + break; + } } - - __kernel_cpumask_size = res; } /* We now know the size of the kernel cpumask_t. Make sure the user