0001
0002 #include <sys/types.h>
0003 #include <errno.h>
0004 #include <unistd.h>
0005 #include <stdio.h>
0006 #include <stdlib.h>
0007 #include <string.h>
0008 #include <linux/stringify.h>
0009 #include "header.h"
0010 #include "utils_header.h"
0011 #include "metricgroup.h"
0012 #include <api/fs/fs.h>
0013
0014 int
0015 get_cpuid(char *buffer, size_t sz)
0016 {
0017 unsigned long pvr;
0018 int nb;
0019
0020 pvr = mfspr(SPRN_PVR);
0021
0022 nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));
0023
0024
0025 if (strchr(buffer, '$')) {
0026 buffer[nb-1] = '\0';
0027 return 0;
0028 }
0029 return ENOBUFS;
0030 }
0031
0032 char *
0033 get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
0034 {
0035 char *bufp;
0036
0037 if (asprintf(&bufp, "%.8lx", mfspr(SPRN_PVR)) < 0)
0038 bufp = NULL;
0039
0040 return bufp;
0041 }
0042
0043 int arch_get_runtimeparam(const struct pmu_event *pe)
0044 {
0045 int count;
0046 char path[PATH_MAX] = "/devices/hv_24x7/interface/";
0047
0048 atoi(pe->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, "coresperchip");
0049 return sysfs__read_int(path, &count) < 0 ? 1 : count;
0050 }