aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/env.c')
-rw-r--r--tools/perf/util/env.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 6276b340f893..6d311868d850 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -1,8 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include "cpumap.h" 2#include "cpumap.h"
3#include "env.h" 3#include "env.h"
4#include "sane_ctype.h"
4#include "util.h" 5#include "util.h"
5#include <errno.h> 6#include <errno.h>
7#include <sys/utsname.h>
6 8
7struct perf_env perf_env; 9struct perf_env perf_env;
8 10
@@ -93,3 +95,48 @@ void cpu_cache_level__free(struct cpu_cache_level *cache)
93 free(cache->map); 95 free(cache->map);
94 free(cache->size); 96 free(cache->size);
95} 97}
98
99/*
100 * Return architecture name in a normalized form.
101 * The conversion logic comes from the Makefile.
102 */
103static const char *normalize_arch(char *arch)
104{
105 if (!strcmp(arch, "x86_64"))
106 return "x86";
107 if (arch[0] == 'i' && arch[2] == '8' && arch[3] == '6')
108 return "x86";
109 if (!strcmp(arch, "sun4u") || !strncmp(arch, "sparc", 5))
110 return "sparc";
111 if (!strcmp(arch, "aarch64") || !strcmp(arch, "arm64"))
112 return "arm64";
113 if (!strncmp(arch, "arm", 3) || !strcmp(arch, "sa110"))
114 return "arm";
115 if (!strncmp(arch, "s390", 4))
116 return "s390";
117 if (!strncmp(arch, "parisc", 6))
118 return "parisc";
119 if (!strncmp(arch, "powerpc", 7) || !strncmp(arch, "ppc", 3))
120 return "powerpc";
121 if (!strncmp(arch, "mips", 4))
122 return "mips";
123 if (!strncmp(arch, "sh", 2) && isdigit(arch[2]))
124 return "sh";
125
126 return arch;
127}
128
129const char *perf_env__arch(struct perf_env *env)
130{
131 struct utsname uts;
132 char *arch_name;
133
134 if (!env) { /* Assume local operation */
135 if (uname(&uts) < 0)
136 return NULL;
137 arch_name = uts.machine;
138 } else
139 arch_name = env->arch;
140
141 return normalize_arch(arch_name);
142}