From patchwork Thu Nov 20 14:38:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 3811 Received: (qmail 27884 invoked by alias); 20 Nov 2014 14:38:26 -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 27873 invoked by uid 89); 20 Nov 2014 14:38:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Message-ID: <546DFCDC.301@redhat.com> Date: Thu, 20 Nov 2014 09:38:20 -0500 From: "Carlos O'Donell" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Roland McGrath , "GNU C. Library" Subject: Re: [PATCH roland/nptl] NPTL: Don't (re)validate sched_priority in pthread_create. References: <20141118205213.90CF92C3B21@topped-with-meat.com> <546C19D4.6060409@redhat.com> <20141120012434.A1F4C2C3AD8@topped-with-meat.com> <20141120014145.6AF582C3B18@topped-with-meat.com> In-Reply-To: <20141120014145.6AF582C3B18@topped-with-meat.com> On 11/19/2014 08:41 PM, Roland McGrath wrote: > I've committed the change (after committing the new test and verifying it > passes both before and after). If you'd like to review the one change > remaining on roland/nptl (freshly rebased) soon, that would be great. > After a day or two, I'll take silence as assent. :-) LGTM. OK. Cheers, Carlos. diff --git a/ChangeLog b/ChangeLog index 6199b7e..e207ce4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2014-11-19 Roland McGrath + * nptl/default-sched.h: New file. + * sysdeps/unix/sysv/linux/default-sched.h: New file. + * nptl/pthread_create.c: Include it. + (__pthread_create_2_1): Use collect_default_sched instead of making + Linux syscalls here directly. OK. + +2014-11-19 Roland McGrath + * nptl/pthread_create.c (__pthread_create_2_1): Don't try to validate the sched_priority value here. It was already checked when the user called pthread_attr_setschedparam. diff --git a/nptl/default-sched.h b/nptl/default-sched.h new file mode 100644 index 0000000..fb33e7c --- /dev/null +++ b/nptl/default-sched.h @@ -0,0 +1,35 @@ +/* Determine calling thread's scheduling parameters. Stub version. + Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +#include + +/* This should fill in PD->schedpolicy if PD->flags does not contain + ATTR_FLAG_POLICY_SET, and set it; and PD->schedparam if PD->flags does + not contain ATTR_FLAG_SCHED_SET, and set it. It won't be called at all + if both bits are already set. */ + +static void +collect_default_sched (struct pthread *pd) +{ + assert ((pd->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) != 0); + + /* The generic/stub version is a no-op rather than just using the + __sched_getscheduler and __sched_getparam functions so that there + won't be stub warnings for those functions just because pthread_create + was called without actually calling those. */ +} OK. diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 1dd1b95..3d4b8cd 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -593,26 +594,16 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg) if (__builtin_expect ((iattr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0, 0) && (iattr->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) != 0) { - INTERNAL_SYSCALL_DECL (scerr); - /* Use the scheduling parameters the user provided. */ if (iattr->flags & ATTR_FLAG_POLICY_SET) pd->schedpolicy = iattr->schedpolicy; - else if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0) - { - pd->schedpolicy = INTERNAL_SYSCALL (sched_getscheduler, scerr, 1, 0); - pd->flags |= ATTR_FLAG_POLICY_SET; - } - if (iattr->flags & ATTR_FLAG_SCHED_SET) /* The values were validated in pthread_attr_setschedparam. */ - memcpy (&pd->schedparam, &iattr->schedparam, - sizeof (struct sched_param)); - else if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0) - { - INTERNAL_SYSCALL (sched_getparam, scerr, 2, 0, &pd->schedparam); - pd->flags |= ATTR_FLAG_SCHED_SET; - } + pd->schedparam = iattr->schedparam; + + if ((pd->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) + != (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) + collect_default_sched (pd); OK, pd->flags will have been updated earlier and thus will either be set here or it won't be and we call collect_default_sched. } /* Pass the descriptor to the caller. */ diff --git a/sysdeps/unix/sysv/linux/default-sched.h b/sysdeps/unix/sysv/linux/default-sched.h new file mode 100644 index 0000000..c25778f --- /dev/null +++ b/sysdeps/unix/sysv/linux/default-sched.h @@ -0,0 +1,42 @@ +/* Determine calling thread's scheduling parameters. Linux version. + Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +#include + +/* This should fill in PD->schedpolicy if PD->flags does not contain + ATTR_FLAG_POLICY_SET, and set it; and PD->schedparam if PD->flags does + not contain ATTR_FLAG_SCHED_SET, and set it. It won't be called at all + if both bits are already set. */ + +static void +collect_default_sched (struct pthread *pd) +{ + INTERNAL_SYSCALL_DECL (scerr); + + if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0) + { + pd->schedpolicy = INTERNAL_SYSCALL (sched_getscheduler, scerr, 1, 0); + pd->flags |= ATTR_FLAG_POLICY_SET; + } + + if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0) + { + INTERNAL_SYSCALL (sched_getparam, scerr, 2, 0, &pd->schedparam); + pd->flags |= ATTR_FLAG_SCHED_SET; + } +}