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> | |
fbe96f29 | 13 | |
fbe96f29 SE |
14 | int |
15 | get_cpuid(char *buffer, size_t sz) | |
16 | { | |
17 | unsigned long pvr; | |
18 | int nb; | |
19 | ||
20 | pvr = mfspr(SPRN_PVR); | |
21 | ||
e7f01d1e | 22 | nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); |
fbe96f29 SE |
23 | |
24 | /* look for end marker to ensure the entire data fit */ | |
25 | if (strchr(buffer, '$')) { | |
26 | buffer[nb-1] = '\0'; | |
27 | return 0; | |
28 | } | |
f67001a4 | 29 | return ENOBUFS; |
fbe96f29 | 30 | } |
ce88f27c SB |
31 | |
32 | char * | |
54e32dc0 | 33 | get_cpuid_str(struct perf_pmu *pmu __maybe_unused) |
ce88f27c SB |
34 | { |
35 | char *bufp; | |
36 | ||
f6a66ff9 | 37 | if (asprintf(&bufp, "0x%.8lx", mfspr(SPRN_PVR)) < 0) |
ce88f27c SB |
38 | bufp = NULL; |
39 | ||
40 | return bufp; | |
41 | } | |
1e1a873d | 42 | |
db95818e | 43 | int arch_get_runtimeparam(const struct pmu_metric *pm) |
1e1a873d KJ |
44 | { |
45 | int count; | |
f5a489dc KJ |
46 | char path[PATH_MAX] = "/devices/hv_24x7/interface/"; |
47 | ||
1fa0c371 | 48 | strcat(path, pm->aggr_mode == PerChip ? "sockets" : "coresperchip"); |
f5a489dc | 49 | return sysfs__read_int(path, &count) < 0 ? 1 : count; |
1e1a873d | 50 | } |