
Summary: This change simplifies the XRay Allocator implementation to self-manage an mmap'ed memory segment instead of using the internal allocator implementation in sanitizer_common. We've found through benchmarks and profiling these benchmarks in D48879 that using the internal allocator in sanitizer_common introduces a bottleneck on allocating memory through a central spinlock. This change allows thread-local allocators to eliminate contention on the centralized allocator. To get the most benefit from this approach, we also use a managed allocator for the chunk elements used by the segmented array implementation. This gives us the chance to amortize the cost of allocating memory when creating these internal segmented array data structures. We also took the opportunity to remove the preallocation argument from the allocator API, simplifying the usage of the allocator throughout the profiling implementation. In this change we also tweak some of the flag values to reduce the amount of maximum memory we use/need for each thread, when requesting memory through mmap. Depends on D48956. Reviewers: kpw, eizan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49217 llvm-svn: 337342
70 lines
2.1 KiB
C++
70 lines
2.1 KiB
C++
//===-- xray_utils.h --------------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file is a part of XRay, a dynamic runtime instrumentation system.
|
|
//
|
|
// Some shared utilities for the XRay runtime implementation.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#ifndef XRAY_UTILS_H
|
|
#define XRAY_UTILS_H
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <sys/types.h>
|
|
#include <utility>
|
|
|
|
namespace __xray {
|
|
|
|
// Default implementation of the reporting interface for sanitizer errors.
|
|
void printToStdErr(const char *Buffer);
|
|
|
|
// EINTR-safe write routine, provided a file descriptor and a character range.
|
|
void retryingWriteAll(int Fd, const char *Begin, const char *End);
|
|
|
|
// Reads a long long value from a provided file.
|
|
bool readValueFromFile(const char *Filename, long long *Value);
|
|
|
|
// EINTR-safe read routine, providing a file descriptor and a character range.
|
|
std::pair<ssize_t, bool> retryingReadSome(int Fd, char *Begin, char *End);
|
|
|
|
// EINTR-safe open routine, uses flag-provided values for initialising a log
|
|
// file.
|
|
int getLogFD();
|
|
|
|
constexpr size_t gcd(size_t a, size_t b) {
|
|
return (b == 0) ? a : gcd(b, a % b);
|
|
}
|
|
|
|
constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
|
|
|
|
constexpr size_t nearest_boundary(size_t number, size_t multiple) {
|
|
return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
|
|
}
|
|
|
|
constexpr size_t next_pow2_helper(size_t num, size_t acc) {
|
|
return (1u << acc) >= num ? (1u << acc) : next_pow2_helper(num, acc + 1);
|
|
}
|
|
|
|
constexpr size_t next_pow2(size_t number) {
|
|
return next_pow2_helper(number, 1);
|
|
}
|
|
|
|
template <class T> constexpr T &max(T &A, T &B) { return A > B ? A : B; }
|
|
|
|
template <class T> constexpr T &min(T &A, T &B) { return A <= B ? A : B; }
|
|
|
|
constexpr ptrdiff_t diff(uintptr_t A, uintptr_t B) {
|
|
return max(A, B) - min(A, B);
|
|
}
|
|
|
|
} // namespace __xray
|
|
|
|
#endif // XRAY_UTILS_H
|