header.c 1002 B

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