Merge "Avoid a system call in 'gettid'."

This commit is contained in:
Elliott Hughes 2014-06-02 17:43:27 +00:00 committed by Gerrit Code Review
commit 2deef73fe1
10 changed files with 47 additions and 117 deletions

View file

@ -28,3 +28,14 @@ static void BM_unistd_getpid(int iters) {
StopBenchmarkTiming();
}
BENCHMARK(BM_unistd_getpid);
static void BM_unistd_gettid(int iters) {
StartBenchmarkTiming();
for (int i = 0; i < iters; ++i) {
gettid();
}
StopBenchmarkTiming();
}
BENCHMARK(BM_unistd_gettid);

View file

@ -128,6 +128,7 @@ libc_bionic_src_files := \
bionic/getauxval.cpp \
bionic/getcwd.cpp \
bionic/getpgrp.cpp \
bionic/gettid.cpp \
bionic/inotify_init.cpp \
bionic/lchown.cpp \
bionic/lfs64_support.cpp \

View file

@ -38,7 +38,6 @@ uid_t getresuid:getresuid32(uid_t* ruid, uid_t* euid, uid_t* suid) arm,x86
uid_t getresuid:getresuid(uid_t* ruid, uid_t* euid, uid_t* suid) arm64,mips,mips64,x86_64
gid_t getresgid:getresgid32(gid_t* rgid, gid_t* egid, gid_t* sgid) arm,x86
gid_t getresgid:getresgid(gid_t* rgid, gid_t* egid, gid_t* sgid) arm64,mips,mips64,x86_64
pid_t gettid() all
ssize_t readahead(int, off64_t, size_t) all
int getgroups:getgroups32(int, gid_t*) arm,x86
int getgroups:getgroups(int, gid_t*) arm64,mips,mips64,x86_64

View file

@ -1,14 +0,0 @@
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
ENTRY(gettid)
mov ip, r7
ldr r7, =__NR_gettid
swi #0
mov r7, ip
cmn r0, #(MAX_ERRNO + 1)
bxls lr
neg r0, r0
b __set_errno
END(gettid)

View file

@ -1,25 +0,0 @@
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
ENTRY(gettid)
stp x29, x30, [sp, #-16]!
.cfi_def_cfa_offset 16
.cfi_rel_offset x29, 0
.cfi_rel_offset x30, 8
mov x29, sp
mov x8, __NR_gettid
svc #0
ldp x29, x30, [sp], #16
.cfi_def_cfa_offset 0
.cfi_restore x29
.cfi_restore x30
cmn x0, #(MAX_ERRNO + 1)
cneg x0, x0, hi
b.hi __set_errno
ret
END(gettid)

View file

@ -1,19 +0,0 @@
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
ENTRY(gettid)
.set noreorder
.cpload t9
li v0, __NR_gettid
syscall
bnez a3, 1f
move a0, v0
j ra
nop
1:
la t9,__set_errno
j t9
nop
.set reorder
END(gettid)

View file

@ -1,25 +0,0 @@
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
ENTRY(gettid)
.set push
.set noreorder
li v0, __NR_gettid
syscall
bnez a3, 1f
move a0, v0
j ra
nop
1:
move t0, ra
bal 2f
nop
2:
.cpsetup ra, t1, 2b
LA t9,__set_errno
.cpreturn
j t9
move ra, t0
.set pop
END(gettid)

View file

@ -1,17 +0,0 @@
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
ENTRY(gettid)
movl $__NR_gettid, %eax
int $0x80
cmpl $-MAX_ERRNO, %eax
jb 1f
negl %eax
pushl %eax
call __set_errno
addl $4, %esp
orl $-1, %eax
1:
ret
END(gettid)

View file

@ -1,16 +0,0 @@
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
ENTRY(gettid)
movl $__NR_gettid, %eax
syscall
cmpq $-MAX_ERRNO, %rax
jb 1f
negl %eax
movl %eax, %edi
call __set_errno
orq $-1, %rax
1:
ret
END(gettid)

35
libc/bionic/gettid.cpp Normal file
View file

@ -0,0 +1,35 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <unistd.h>
#include "pthread_internal.h"
pid_t gettid() {
return __get_thread()->tid;
}