blob: d1c55ba19577987ce9d9252f630c14a59aafc0d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
Patch-Source: https://github.com/void-linux/void-packages/blob/c907a54de30ad0b19fbf9f37d5b67cabe5c7744d/srcpkgs/llvm12/patches/compiler-rt-xray-ppc64-musl.patch
--- a/lib/xray/xray_powerpc64.inc
+++ b/lib/xray/xray_powerpc64.inc
@@ -12,7 +12,13 @@
#include <cstdint>
#include <mutex>
+#ifdef __GLIBC__
#include <sys/platform/ppc.h>
+#else
+#include <cctype>
+#include <cstring>
+#include <cstdlib>
+#endif
#include "xray_defs.h"
@@ -20,13 +26,45 @@ namespace __xray {
ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
CPU = 0;
+#ifdef __GLIBC__
return __ppc_get_timebase();
+#else
+ return __builtin_ppc_get_timebase();
+#endif
}
inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
static std::mutex M;
std::lock_guard<std::mutex> Guard(M);
+#ifdef __GLIBC__
return __ppc_get_timebase_freq();
+#else
+ /* FIXME: a less dirty implementation? */
+ static uint64_t base;
+ if (!base) {
+ FILE *f = fopen("/proc/cpuinfo", "rb");
+ if (f) {
+ ssize_t nr;
+ /* virtually always big enough to hold the line */
+ char buf[512];
+ while (fgets(buf, sizeof(buf), f)) {
+ char *ret = strstr(buf, "timebase");
+ if (!ret) {
+ continue;
+ }
+ ret += sizeof("timebase") - 1;
+ ret = strchr(ret, ':');
+ if (!ret) {
+ continue;
+ }
+ base = strtoul(ret + 1, nullptr, 10);
+ break;
+ }
+ fclose(f);
+ }
+ }
+ return base;
+#endif
}
inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT {
|