From patchwork Tue Nov 18 23:02:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 3799 Received: (qmail 1076 invoked by alias); 18 Nov 2014 23:02:50 -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 1065 invoked by uid 89); 18 Nov 2014 23:02:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [PATCH roland/nptl] NPTL: Refactor scheduler setup in pthread_create. Message-Id: <20141118230246.7DCAC2C3B23@topped-with-meat.com> Date: Tue, 18 Nov 2014 15:02:46 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=mDV3o1hIAAAA:8 a=93RoAVIf8BS8La40s6kA:9 a=PwUs5zBHx-TAvniL:21 a=pynC2AVVnGggc5i-:21 a=CjuIK1q_8ugA:10 This eliminates the last unconditional Linuxism from pthread_create.c. It should not change any behavior. Tested x86_64-linux-gnu. Thanks, Roland * 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. --- /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. */ +} --- 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); } /* Pass the descriptor to the caller. */ --- /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; + } +}