Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / arch / powerpc / util / header.c
blob58b2d610aadbfd0b4d14ffb82835ebeac81d55d3
1 // SPDX-License-Identifier: GPL-2.0
2 #include <sys/types.h>
3 #include <errno.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <linux/stringify.h>
9 #include "header.h"
10 #include "utils_header.h"
11 #include "metricgroup.h"
12 #include <api/fs/fs.h>
14 int
15 get_cpuid(char *buffer, size_t sz)
17 unsigned long pvr;
18 int nb;
20 pvr = mfspr(SPRN_PVR);
22 nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));
24 /* look for end marker to ensure the entire data fit */
25 if (strchr(buffer, '$')) {
26 buffer[nb-1] = '\0';
27 return 0;
29 return ENOBUFS;
32 char *
33 get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
35 char *bufp;
37 if (asprintf(&bufp, "%.8lx", mfspr(SPRN_PVR)) < 0)
38 bufp = NULL;
40 return bufp;
43 int arch_get_runtimeparam(struct pmu_event *pe)
45 int count;
46 char path[PATH_MAX] = "/devices/hv_24x7/interface/";
48 atoi(pe->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, "coresperchip");
49 return sysfs__read_int(path, &count) < 0 ? 1 : count;