Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
fbe96f29 | 2 | #include <sys/types.h> |
f67001a4 | 3 | #include <errno.h> |
fbe96f29 SE |
4 | #include <unistd.h> |
5 | #include <stdio.h> | |
6 | #include <stdlib.h> | |
7 | #include <string.h> | |
531d2410 | 8 | #include <linux/stringify.h> |
379649cf | 9 | #include "header.h" |
33583e69 | 10 | #include "utils_header.h" |
1e1a873d KJ |
11 | #include "metricgroup.h" |
12 | #include <api/fs/fs.h> | |
54f9aa10 AR |
13 | #include <sys/auxv.h> |
14 | ||
15 | static bool is_compat_mode(void) | |
16 | { | |
7e442be7 LK |
17 | unsigned long base_platform = getauxval(AT_BASE_PLATFORM); |
18 | unsigned long platform = getauxval(AT_PLATFORM); | |
54f9aa10 AR |
19 | |
20 | if (!strcmp((char *)platform, (char *)base_platform)) | |
21 | return false; | |
22 | ||
23 | return true; | |
24 | } | |
fbe96f29 | 25 | |
fbe96f29 | 26 | int |
cec0d657 | 27 | get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) |
fbe96f29 SE |
28 | { |
29 | unsigned long pvr; | |
30 | int nb; | |
31 | ||
32 | pvr = mfspr(SPRN_PVR); | |
33 | ||
e7f01d1e | 34 | nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); |
fbe96f29 SE |
35 | |
36 | /* look for end marker to ensure the entire data fit */ | |
37 | if (strchr(buffer, '$')) { | |
38 | buffer[nb-1] = '\0'; | |
39 | return 0; | |
40 | } | |
f67001a4 | 41 | return ENOBUFS; |
fbe96f29 | 42 | } |
ce88f27c SB |
43 | |
44 | char * | |
494c403f | 45 | get_cpuid_str(struct perf_cpu cpu __maybe_unused) |
ce88f27c SB |
46 | { |
47 | char *bufp; | |
54f9aa10 AR |
48 | unsigned long pvr; |
49 | ||
50 | /* | |
51 | * IBM Power System supports compatible mode. That is | |
52 | * Nth generation platform can support previous generation | |
53 | * OS in a mode called compatibile mode. For ex. LPAR can be | |
54 | * booted in a Power9 mode when the system is a Power10. | |
55 | * | |
56 | * In the compatible mode, care must be taken when generating | |
57 | * PVR value. When read, PVR will be of the AT_BASE_PLATFORM | |
58 | * To support generic events, return 0x00ffffff as pvr when | |
59 | * booted in compat mode. Based on this pvr value, json will | |
60 | * pick events from pmu-events/arch/powerpc/compat | |
61 | */ | |
62 | if (!is_compat_mode()) | |
63 | pvr = mfspr(SPRN_PVR); | |
64 | else | |
65 | pvr = 0x00ffffff; | |
ce88f27c | 66 | |
54f9aa10 | 67 | if (asprintf(&bufp, "0x%.8lx", pvr) < 0) |
ce88f27c SB |
68 | bufp = NULL; |
69 | ||
70 | return bufp; | |
71 | } | |
1e1a873d | 72 | |
db95818e | 73 | int arch_get_runtimeparam(const struct pmu_metric *pm) |
1e1a873d KJ |
74 | { |
75 | int count; | |
f5a489dc KJ |
76 | char path[PATH_MAX] = "/devices/hv_24x7/interface/"; |
77 | ||
1fa0c371 | 78 | strcat(path, pm->aggr_mode == PerChip ? "sockets" : "coresperchip"); |
f5a489dc | 79 | return sysfs__read_int(path, &count) < 0 ? 1 : count; |
1e1a873d | 80 | } |