Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / tools / perf / arch / nds32 / util / header.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <api/fs/fs.h>
7 #include "header.h"
8
9 #define STR_LEN 1024
10
11 char *get_cpuid_str(struct perf_pmu *pmu)
12 {
13         /* In nds32, we only have one cpu */
14         char *buf = NULL;
15         struct cpu_map *cpus;
16         const char *sysfs = sysfs__mountpoint();
17
18         if (!sysfs || !pmu || !pmu->cpus)
19                 return NULL;
20
21         buf = malloc(STR_LEN);
22         if (!buf)
23                 return NULL;
24
25         cpus = cpu_map__get(pmu->cpus);
26         sprintf(buf, "0x%x", cpus->nr - 1);
27         cpu_map__put(cpus);
28         return buf;
29 }