Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 1 | #include "cpumap.h" |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 2 | #include "env.h" |
| 3 | #include "util.h" |
| 4 | |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 5 | struct perf_env perf_env; |
| 6 | |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 7 | void perf_env__exit(struct perf_env *env) |
| 8 | { |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 9 | int i; |
| 10 | |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 11 | zfree(&env->hostname); |
| 12 | zfree(&env->os_release); |
| 13 | zfree(&env->version); |
| 14 | zfree(&env->arch); |
| 15 | zfree(&env->cpu_desc); |
| 16 | zfree(&env->cpuid); |
| 17 | zfree(&env->cmdline); |
| 18 | zfree(&env->cmdline_argv); |
| 19 | zfree(&env->sibling_cores); |
| 20 | zfree(&env->sibling_threads); |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 21 | zfree(&env->pmu_mappings); |
| 22 | zfree(&env->cpu); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 23 | |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame^] | 24 | for (i = 0; i < env->nr_numa_nodes; i++) |
| 25 | cpu_map__put(env->numa_nodes[i].map); |
| 26 | zfree(&env->numa_nodes); |
| 27 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 28 | for (i = 0; i < env->caches_cnt; i++) |
| 29 | cpu_cache_level__free(&env->caches[i]); |
| 30 | zfree(&env->caches); |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 31 | } |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 32 | |
| 33 | int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) |
| 34 | { |
| 35 | int i; |
| 36 | |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 37 | /* do not include NULL termination */ |
| 38 | env->cmdline_argv = calloc(argc, sizeof(char *)); |
| 39 | if (env->cmdline_argv == NULL) |
| 40 | goto out_enomem; |
| 41 | |
| 42 | /* |
| 43 | * Must copy argv contents because it gets moved around during option |
| 44 | * parsing: |
| 45 | */ |
| 46 | for (i = 0; i < argc ; i++) { |
| 47 | env->cmdline_argv[i] = argv[i]; |
| 48 | if (env->cmdline_argv[i] == NULL) |
| 49 | goto out_free; |
| 50 | } |
| 51 | |
| 52 | env->nr_cmdline = argc; |
| 53 | |
| 54 | return 0; |
| 55 | out_free: |
| 56 | zfree(&env->cmdline_argv); |
| 57 | out_enomem: |
| 58 | return -ENOMEM; |
| 59 | } |
Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 60 | |
| 61 | int perf_env__read_cpu_topology_map(struct perf_env *env) |
| 62 | { |
| 63 | int cpu, nr_cpus; |
| 64 | |
| 65 | if (env->cpu != NULL) |
| 66 | return 0; |
| 67 | |
| 68 | if (env->nr_cpus_avail == 0) |
| 69 | env->nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF); |
| 70 | |
| 71 | nr_cpus = env->nr_cpus_avail; |
| 72 | if (nr_cpus == -1) |
| 73 | return -EINVAL; |
| 74 | |
| 75 | env->cpu = calloc(nr_cpus, sizeof(env->cpu[0])); |
| 76 | if (env->cpu == NULL) |
| 77 | return -ENOMEM; |
| 78 | |
| 79 | for (cpu = 0; cpu < nr_cpus; ++cpu) { |
| 80 | env->cpu[cpu].core_id = cpu_map__get_core_id(cpu); |
| 81 | env->cpu[cpu].socket_id = cpu_map__get_socket_id(cpu); |
| 82 | } |
| 83 | |
| 84 | env->nr_cpus_avail = nr_cpus; |
| 85 | return 0; |
| 86 | } |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 87 | |
| 88 | void cpu_cache_level__free(struct cpu_cache_level *cache) |
| 89 | { |
| 90 | free(cache->type); |
| 91 | free(cache->map); |
| 92 | free(cache->size); |
| 93 | } |