From patchwork Thu Apr 23 21:21:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 47478 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 798A42121F for ; Thu, 23 Apr 2015 21:22:03 +0000 (UTC) Received: by lbbrr5 with SMTP id rr5sf7298750lbb.3 for ; Thu, 23 Apr 2015 14:22:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-subscribe:list-archive:list-post:list-help :sender:delivered-to:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding:x-original-sender :x-original-authentication-results; bh=HJcSHgundCVkRyoD9t+4PtisWIWsKRAJDpkUtyHnFJo=; b=V4ZCfwZQxFzEbiQ8b8izbri80NzVRiJ63D0uxWB+0XEBv6bnPwIzmNTnzzq7nEgglf tELSX7bmgUGsQ+eCbNevBFAzEUtq24mdA1ROYQRqinvmN2kiMWGbiBec8M/pB29Sv9lW vYP6yt1fi0YMcMqO8eBvDuvFedRgxFEfOUNZ8YIxWiNgtsRk4/qt51mFQLAmh2BVdiYQ 0g3EzaRBmSkllpeHFaYJeL+mstUpGTtv1M36SCNCMcNyF+tJQO+lVbJbz33I62NaTsQq UYeirGzEW3KlrPHvcdOYv34McLj/41v1UycZAP9BvF665i41KubKsvEeGDxBiLLiu1UK n2sA== X-Gm-Message-State: ALoCoQlW2Z2MvbIBOzLrEUwWVNnWuA5MkoVrKcvsMk2lzLrOgxBy9HtRbNdMHUrOadU5dNrYM9qJ X-Received: by 10.180.107.33 with SMTP id gz1mr147596wib.3.1429824122415; Thu, 23 Apr 2015 14:22:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.39 with SMTP id kv7ls419926lac.63.gmail; Thu, 23 Apr 2015 14:22:02 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr4142951lbb.112.1429824122251; Thu, 23 Apr 2015 14:22:02 -0700 (PDT) Received: from mail-lb0-x22a.google.com (mail-lb0-x22a.google.com. [2a00:1450:4010:c04::22a]) by mx.google.com with ESMTPS id p5si6817278lah.22.2015.04.23.14.22.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 14:22:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22a as permitted sender) client-ip=2a00:1450:4010:c04::22a; Received: by lbbqq2 with SMTP id qq2so22914632lbb.3 for ; Thu, 23 Apr 2015 14:22:01 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr4221841lbc.86.1429824121808; Thu, 23 Apr 2015 14:22:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp815202lbt; Thu, 23 Apr 2015 14:22:00 -0700 (PDT) X-Received: by 10.68.136.134 with SMTP id qa6mr9076030pbb.66.1429824119628; Thu, 23 Apr 2015 14:21:59 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id bb5si14260166pbb.24.2015.04.23.14.21.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 14:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-58544-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 1833 invoked by alias); 23 Apr 2015 21:21:48 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 1812 invoked by uid 89); 23 Apr 2015 21:21:47 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f170.google.com X-Received: by 10.55.22.194 with SMTP id 63mr2313744qkw.3.1429824102751; Thu, 23 Apr 2015 14:21:42 -0700 (PDT) Message-ID: <55396257.5020305@linaro.org> Date: Thu, 23 Apr 2015 18:21:27 -0300 From: Adhemerval Zanella User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: GNU C Library Subject: [PATCH] Consolidate sched_getcpu X-Original-Sender: adhemerval.zanella@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22a as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 Hi This patch consolidates the sched_getcpu implementations across all arches (except tile, which requires its own). This patch removes the powerpc, x86_64 and x32 specific files and change the default linux one to use INLINE_VSYSCALL where possible (for ports that implements it). For x86 is add some more cleanups: * There is no need for __syscall_clock_gettime anymore, since the VSYSCALL_INLINE will call the syscall version directly. So the fallback mechanism could be removed. * The x86_64 fallback mechanism is to use the vsyscall, which is nowadays is not a recommended interface to access the kernel. The patch removes it and a subsequent patch removes all vsyscall usage. * x86_64 and x32 can use the same init-first.c now. * There is no need to specific static file for sched_getcpu for x32. Tested on i686, x86_64, and x32. I also check the build for ppc32 and ppc64le. --- * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h (HAVE_GETCPU_VSYSCALL): Define. * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h (HAVE_GETCPU_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/powerpc/sched_getcpu.c: Remove file. * sysdeps/unix/sysv/linux/sched_getcpu.c (HAVE_VSYSCALL): Define if HAVE_GETCPU_VSYSCALL and include sysdep-vdso. (sched_getcpu): Use INLINE_VSYSCALL instead of INLINE_SYSCALL. * sysdeps/unix/sysv/linux/x86/libc-vdso.h (getcpu): Add vDSO prototype. * sysdeps/unix/sysv/linux/x86_64/init-first.c (__syscall_clock_gettime): Remove prototype. (__vdso_platform_setup): Remove vsyscall getcpu fallback. * sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S: Remove file. * sysdeps/unix/sysv/linux/x86_64/syscalls.list (__syscall_clock_gettime): Remove defintion. * sysdeps/unix/sysv/linux/x86_64/sysdep.h (HAVE_GETCPU_VSYSCALL): Define. * sysdeps/unix/sysv/linux/x86_64/x32/Makefile: Remove file. * sysdeps/unix/sysv/linux/x86_64/x32/init-first.c: Likewise. * sysdeps/unix//sysv/linux/x86_64/x32/sched_getcpu-static.c: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu.S: Likewise. --- -- diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h index 8bd42ec..f52f1a9 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h @@ -165,6 +165,7 @@ /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETRES_VSYSCALL 1 # define HAVE_CLOCK_GETTIME_VSYSCALL 1 +# define HAVE_GETCPU_VSYSCALL 1 # define LOADARGS_0(name, dummy) \ diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h index 1bad856..e2205f9 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h @@ -80,6 +80,7 @@ /* List of system calls which are supported as vsyscalls. */ #define HAVE_CLOCK_GETRES_VSYSCALL 1 #define HAVE_CLOCK_GETTIME_VSYSCALL 1 +#define HAVE_GETCPU_VSYSCALL 1 /* Define a macro which expands inline into the wrapper code for a system call. This use is for internal calls that do not need to handle errors diff --git a/sysdeps/unix/sysv/linux/powerpc/sched_getcpu.c b/sysdeps/unix/sysv/linux/powerpc/sched_getcpu.c deleted file mode 100644 index f93be01..0000000 --- a/sysdeps/unix/sysv/linux/powerpc/sched_getcpu.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2013-2015 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 Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -int -sched_getcpu (void) -{ - unsigned int cpu; - int r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL); - - return r == -1 ? r : cpu; -} diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c index 09f0816..a485d36 100644 --- a/sysdeps/unix/sysv/linux/sched_getcpu.c +++ b/sysdeps/unix/sysv/linux/sched_getcpu.c @@ -19,13 +19,17 @@ #include #include +#ifdef HAVE_GETCPU_VSYSCALL +# define HAVE_VSYSCALL +#endif +#include int sched_getcpu (void) { #ifdef __NR_getcpu unsigned int cpu; - int r = INLINE_SYSCALL (getcpu, 3, &cpu, NULL, NULL); + int r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL); return r == -1 ? r : cpu; #else diff --git a/sysdeps/unix/sysv/linux/x86/libc-vdso.h b/sysdeps/unix/sysv/linux/x86/libc-vdso.h index fea9c2b..f3a8f07 100644 --- a/sysdeps/unix/sysv/linux/x86/libc-vdso.h +++ b/sysdeps/unix/sysv/linux/x86/libc-vdso.h @@ -29,6 +29,8 @@ extern long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *) attribute_hidden; +extern long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *); + #endif #endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c index b7bdbd1..d83b04b 100644 --- a/sysdeps/unix/sysv/linux/x86_64/init-first.c +++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c @@ -27,25 +27,16 @@ long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *) long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) attribute_hidden; -extern long int __syscall_clock_gettime (clockid_t, struct timespec *); - - static inline void __vdso_platform_setup (void) { PREPARE_VERSION (linux26, "LINUX_2.6", 61765110); void *p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26); - if (p == NULL) - p = __syscall_clock_gettime; PTR_MANGLE (p); VDSO_SYMBOL(clock_gettime) = p; p = _dl_vdso_vsym ("__vdso_getcpu", &linux26); - /* If the vDSO is not available we fall back on the old vsyscall. */ -#define VSYSCALL_ADDR_vgetcpu 0xffffffffff600800 - if (p == NULL) - p = (void *) VSYSCALL_ADDR_vgetcpu; PTR_MANGLE (p); VDSO_SYMBOL(getcpu) = p; } diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S deleted file mode 100644 index b87f803..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S +++ /dev/null @@ -1,74 +0,0 @@ -/* Copyright (C) 2007-2015 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 Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#define _ERRNO_H 1 -#include -#include - -/* For the calculation see asm/vsyscall.h. */ -#define VSYSCALL_ADDR_vgetcpu 0xffffffffff600800 - - -ENTRY (sched_getcpu) - /* Align stack and create local variable for result. */ - sub $0x8, %rsp - cfi_adjust_cfa_offset(8) - - movq %rsp, %rdi - xorl %esi, %esi - movl $VGETCPU_CACHE_OFFSET, %edx - addq %fs:0, %rdx - -#ifdef SHARED - movq __vdso_getcpu(%rip), %rax - PTR_DEMANGLE (%rax) - callq *%rax -#else -# ifdef __NR_getcpu - movl $__NR_getcpu, %eax - syscall -# ifndef __ASSUME_GETCPU_SYSCALL - cmpq $-ENOSYS, %rax - jne 1f -# endif -# endif -# ifndef __ASSUME_GETCPU_SYSCALL - movq $VSYSCALL_ADDR_vgetcpu, %rax - callq *%rax -1: -# else -# ifndef __NR_getcpu -# error "cannot happen" -# endif -# endif -#endif - - /* Local variable is result if the call is successful. */ - movl (%rsp), %edx - /* Restore stack pointer before we might jump to - SYSCALL_ERROR_LABEL which returns to the caller. */ - add $0x8, %rsp - cfi_adjust_cfa_offset(-8) - - cmpq $-4095, %rax - jae SYSCALL_ERROR_LABEL - - movl %edx, %eax - ret -PSEUDO_END(sched_getcpu) diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list index 2e4135f..b4f2075 100644 --- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list +++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list @@ -14,7 +14,6 @@ semop - semop i:ipi __semop semop semtimedop - semtimedop i:ipip semtimedop semget - semget i:iii __semget semget semctl - semctl i:iiii __semctl semctl -syscall_clock_gettime EXTRA clock_gettime Ei:ip __syscall_clock_gettime # proper socket implementations: diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index bea3192..5a62cce 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -255,6 +255,7 @@ /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL 1 # define HAVE_GETTIMEOFDAY_VSYSCALL 1 +# define HAVE_GETCPU_VSYSCALL 1 # define LOAD_ARGS_0() # define LOAD_REGS_0 diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/Makefile b/sysdeps/unix/sysv/linux/x86_64/x32/Makefile index ecbdefb..8c3253b 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/Makefile +++ b/sysdeps/unix/sysv/linux/x86_64/x32/Makefile @@ -4,7 +4,3 @@ default-abi := x32 ifeq ($(subdir),misc) sysdep_routines += arch_prctl endif - -ifeq ($(subdir),posix) -sysdep_routines += getcpu sched_getcpu-static -endif diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c b/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c deleted file mode 100644 index 31ec80f..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Initialization code run first thing by the ELF startup code. Linux/x32. - Copyright (C) 2012-2015 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 Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef SHARED -# include -# include - -long int (*__vdso_clock_gettime) (clockid_t, struct timespec *) - attribute_hidden; - -static inline void -_libc_vdso_platform_setup (void) -{ - PREPARE_VERSION (linux26, "LINUX_2.6", 61765110); - - void *p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26); - PTR_MANGLE (p); - __vdso_clock_gettime = p; -} - -# define VDSO_SETUP _libc_vdso_platform_setup -#endif - -#include diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu-static.c b/sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu-static.c deleted file mode 100644 index 38bbf9a..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu-static.c +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef SHARED -#include "../../sched_getcpu.c" -#endif diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu.S deleted file mode 100644 index 35ad01b..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/x32/sched_getcpu.S +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2012-2015 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 Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef SHARED -#include -#include -#define _ERRNO_H 1 -#include - -ENTRY (sched_getcpu) - /* Align stack and create local variable for result. */ - sub $0x8, %esp - cfi_adjust_cfa_offset(8) - - mov %esp, %edi - xor %esi, %esi - mov $VGETCPU_CACHE_OFFSET, %edx - add %fs:0, %edx - - call __getcpu - - /* Local variable is result if the call is successful. */ - mov (%rsp), %edx - /* Restore stack pointer before we might jump to - SYSCALL_ERROR_LABEL which returns to the caller. */ - add $0x8, %esp - cfi_adjust_cfa_offset(-8) - - cmp $-4095, %eax - jae SYSCALL_ERROR_LABEL - - mov %edx, %eax - ret -PSEUDO_END(sched_getcpu) -#endif