bcma: claim only 14e4:4365 PCI Dell card with SoftMAC BCM43142
[linux/fpc-iii.git] / tools / perf / util / env.c
blob7dd5939dea2e58385bd374a3e59aecf766e799c1
1 #include "cpumap.h"
2 #include "env.h"
3 #include "util.h"
5 struct perf_env perf_env;
7 void perf_env__exit(struct perf_env *env)
9 zfree(&env->hostname);
10 zfree(&env->os_release);
11 zfree(&env->version);
12 zfree(&env->arch);
13 zfree(&env->cpu_desc);
14 zfree(&env->cpuid);
15 zfree(&env->cmdline);
16 zfree(&env->cmdline_argv);
17 zfree(&env->sibling_cores);
18 zfree(&env->sibling_threads);
19 zfree(&env->numa_nodes);
20 zfree(&env->pmu_mappings);
21 zfree(&env->cpu);
24 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
26 int i;
28 /* do not include NULL termination */
29 env->cmdline_argv = calloc(argc, sizeof(char *));
30 if (env->cmdline_argv == NULL)
31 goto out_enomem;
34 * Must copy argv contents because it gets moved around during option
35 * parsing:
37 for (i = 0; i < argc ; i++) {
38 env->cmdline_argv[i] = argv[i];
39 if (env->cmdline_argv[i] == NULL)
40 goto out_free;
43 env->nr_cmdline = argc;
45 return 0;
46 out_free:
47 zfree(&env->cmdline_argv);
48 out_enomem:
49 return -ENOMEM;
52 int perf_env__read_cpu_topology_map(struct perf_env *env)
54 int cpu, nr_cpus;
56 if (env->cpu != NULL)
57 return 0;
59 if (env->nr_cpus_avail == 0)
60 env->nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF);
62 nr_cpus = env->nr_cpus_avail;
63 if (nr_cpus == -1)
64 return -EINVAL;
66 env->cpu = calloc(nr_cpus, sizeof(env->cpu[0]));
67 if (env->cpu == NULL)
68 return -ENOMEM;
70 for (cpu = 0; cpu < nr_cpus; ++cpu) {
71 env->cpu[cpu].core_id = cpu_map__get_core_id(cpu);
72 env->cpu[cpu].socket_id = cpu_map__get_socket_id(cpu);
75 env->nr_cpus_avail = nr_cpus;
76 return 0;