VDSOsupport cleanup

This patch cleans up unused VDSO getcpu racking from VDSOsupport class,
since the code is not used anywhere in gperftools and symbol name is not
architecture independent.
This commit is contained in:
Adhemerval Zanella 2014-03-31 23:12:07 -05:00
parent 6967ae8d5e
commit 75685f539a
2 changed files with 0 additions and 69 deletions

View File

@ -57,7 +57,6 @@ using base::subtle::MemoryBarrier;
namespace base {
const void *VDSOSupport::vdso_base_ = ElfMemImage::kInvalidBase;
VDSOSupport::GetCpuFn VDSOSupport::getcpu_fn_ = &InitAndGetCPU;
VDSOSupport::VDSOSupport()
// If vdso_base_ is still set to kInvalidBase, we got here
// before VDSOSupport::Init has been called. Call it now.
@ -81,14 +80,12 @@ const void *VDSOSupport::Init() {
// Valgrind zapping. So we check for Valgrind separately.
if (RunningOnValgrind()) {
vdso_base_ = NULL;
getcpu_fn_ = &GetCPUViaSyscall;
return NULL;
}
int fd = open("/proc/self/auxv", O_RDONLY);
if (fd == -1) {
// Kernel too old to have a VDSO.
vdso_base_ = NULL;
getcpu_fn_ = &GetCPUViaSyscall;
return NULL;
}
ElfW(auxv_t) aux;
@ -106,20 +103,6 @@ const void *VDSOSupport::Init() {
vdso_base_ = NULL;
}
}
GetCpuFn fn = &GetCPUViaSyscall; // default if VDSO not present.
if (vdso_base_) {
VDSOSupport vdso;
SymbolInfo info;
if (vdso.LookupSymbol("__vdso_getcpu", "LINUX_2.6", STT_FUNC, &info)) {
// Casting from an int to a pointer is not legal C++. To emphasize
// this, we use a C-style cast rather than a C++-style cast.
fn = (GetCpuFn)(info.address);
}
}
// Subtle: this code runs outside of any locks; prevent compiler
// from assigning to getcpu_fn_ more than once.
base::subtle::MemoryBarrier();
getcpu_fn_ = fn;
return vdso_base_;
}
@ -128,8 +111,6 @@ const void *VDSOSupport::SetBase(const void *base) {
const void *old_base = vdso_base_;
vdso_base_ = base;
image_.Init(base);
// Also reset getcpu_fn_, so GetCPU could be tested with simulated VDSO.
getcpu_fn_ = &InitAndGetCPU;
return old_base;
}
@ -145,33 +126,6 @@ bool VDSOSupport::LookupSymbolByAddress(const void *address,
return image_.LookupSymbolByAddress(address, info_out);
}
// NOLINT on 'long' because this routine mimics kernel api.
long VDSOSupport::GetCPUViaSyscall(unsigned *cpu, void *, void *) { // NOLINT
#if defined(__NR_getcpu)
return sys_getcpu(cpu, NULL, NULL);
#else
// x86_64 never implemented sys_getcpu(), except as a VDSO call.
errno = ENOSYS;
return -1;
#endif
}
// Use fast __vdso_getcpu if available.
long VDSOSupport::InitAndGetCPU(unsigned *cpu, void *x, void *y) { // NOLINT
Init();
CHECK_NE(getcpu_fn_, &InitAndGetCPU); // << "Init() did not set getcpu_fn_";
return (*getcpu_fn_)(cpu, x, y);
}
// This function must be very fast, and may be called from very
// low level (e.g. tcmalloc). Hence I avoid things like
// GoogleOnceInit() and ::operator new.
int GetCPU(void) {
unsigned cpu;
int ret_code = (*VDSOSupport::getcpu_fn_)(&cpu, NULL, NULL);
return ret_code == 0 ? cpu : ret_code;
}
// We need to make sure VDSOSupport::Init() is called before
// the main() runs, since it might do something like setuid or
// chroot. If VDSOSupport

View File

@ -122,32 +122,9 @@ class VDSOSupport {
// page-aligned.
static const void *vdso_base_;
// NOLINT on 'long' because these routines mimic kernel api.
// The 'cache' parameter may be used by some versions of the kernel,
// and should be NULL or point to a static buffer containing at
// least two 'long's.
static long InitAndGetCPU(unsigned *cpu, void *cache, // NOLINT 'long'.
void *unused);
static long GetCPUViaSyscall(unsigned *cpu, void *cache, // NOLINT 'long'.
void *unused);
typedef long (*GetCpuFn)(unsigned *cpu, void *cache, // NOLINT 'long'.
void *unused);
// This function pointer may point to InitAndGetCPU,
// GetCPUViaSyscall, or __vdso_getcpu at different stages of initialization.
static GetCpuFn getcpu_fn_;
friend int GetCPU(void); // Needs access to getcpu_fn_.
DISALLOW_COPY_AND_ASSIGN(VDSOSupport);
};
// Same as sched_getcpu() on later glibc versions.
// Return current CPU, using (fast) __vdso_getcpu@LINUX_2.6 if present,
// otherwise use syscall(SYS_getcpu,...).
// May return -1 with errno == ENOSYS if the kernel doesn't
// support SYS_getcpu.
int GetCPU();
} // namespace base
#endif // HAVE_ELF_MEM_IMAGE