Lines Matching +full:cpu +full:- +full:map
1 // SPDX-License-Identifier: GPL-2.0
21 * CPU number.
33 return (data->mask32_data.long_size == 4) in perf_record_cpu_map_data__test_bit()
34 ? (bit_word32 < data->mask32_data.nr) && in perf_record_cpu_map_data__test_bit()
35 (data->mask32_data.mask[bit_word32] & bit_mask32) != 0 in perf_record_cpu_map_data__test_bit()
36 : (bit_word64 < data->mask64_data.nr) && in perf_record_cpu_map_data__test_bit()
37 (data->mask64_data.mask[bit_word64] & bit_mask64) != 0; in perf_record_cpu_map_data__test_bit()
40 /* Read ith mask value from data into the given 64-bit sized bitmap */
45 if (data->mask32_data.long_size == 4) in perf_record_cpu_map_data__read_one_mask()
46 bitmap[0] = data->mask32_data.mask[i]; in perf_record_cpu_map_data__read_one_mask()
48 bitmap[0] = data->mask64_data.mask[i]; in perf_record_cpu_map_data__read_one_mask()
50 if (data->mask32_data.long_size == 4) { in perf_record_cpu_map_data__read_one_mask()
51 bitmap[0] = data->mask32_data.mask[i]; in perf_record_cpu_map_data__read_one_mask()
55 bitmap[0] = (unsigned long)(data->mask64_data.mask[i] >> 32); in perf_record_cpu_map_data__read_one_mask()
56 bitmap[1] = (unsigned long)data->mask64_data.mask[i]; in perf_record_cpu_map_data__read_one_mask()
58 bitmap[0] = (unsigned long)data->mask64_data.mask[i]; in perf_record_cpu_map_data__read_one_mask()
59 bitmap[1] = (unsigned long)(data->mask64_data.mask[i] >> 32); in perf_record_cpu_map_data__read_one_mask()
66 struct perf_cpu_map *map; in cpu_map__from_entries() local
68 map = perf_cpu_map__empty_new(data->cpus_data.nr); in cpu_map__from_entries()
69 if (map) { in cpu_map__from_entries()
72 for (i = 0; i < data->cpus_data.nr; i++) { in cpu_map__from_entries()
74 * Special treatment for -1, which is not real cpu number, in cpu_map__from_entries()
75 * and we need to use (int) -1 to initialize map[i], in cpu_map__from_entries()
78 if (data->cpus_data.cpu[i] == (u16) -1) in cpu_map__from_entries()
79 map->map[i].cpu = -1; in cpu_map__from_entries()
81 map->map[i].cpu = (int) data->cpus_data.cpu[i]; in cpu_map__from_entries()
85 return map; in cpu_map__from_entries()
91 int weight = 0, mask_nr = data->mask32_data.nr; in cpu_map__from_mask()
92 struct perf_cpu_map *map; in cpu_map__from_mask() local
99 map = perf_cpu_map__empty_new(weight); in cpu_map__from_mask()
100 if (!map) in cpu_map__from_mask()
104 int cpus_per_i = (i * data->mask32_data.long_size * BITS_PER_BYTE); in cpu_map__from_mask()
105 int cpu; in cpu_map__from_mask() local
108 for_each_set_bit(cpu, local_copy, 64) in cpu_map__from_mask()
109 map->map[j++].cpu = cpu + cpus_per_i; in cpu_map__from_mask()
111 return map; in cpu_map__from_mask()
117 struct perf_cpu_map *map; in cpu_map__from_range() local
120 map = perf_cpu_map__empty_new(data->range_cpu_data.end_cpu - in cpu_map__from_range()
121 data->range_cpu_data.start_cpu + 1 + data->range_cpu_data.any_cpu); in cpu_map__from_range()
122 if (!map) in cpu_map__from_range()
125 if (data->range_cpu_data.any_cpu) in cpu_map__from_range()
126 map->map[i++].cpu = -1; in cpu_map__from_range()
128 for (int cpu = data->range_cpu_data.start_cpu; cpu <= data->range_cpu_data.end_cpu; in cpu_map__from_range() local
129 i++, cpu++) in cpu_map__from_range()
130 map->map[i].cpu = cpu; in cpu_map__from_range()
132 return map; in cpu_map__from_range()
137 switch (data->type) { in cpu_map__new_data()
145 pr_err("cpu_map__new_data unknown type %d\n", data->type); in cpu_map__new_data()
150 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp) in cpu_map__fprintf() argument
155 cpu_map__snprint(map, buf, sizeof(buf)); in cpu_map__fprintf()
167 cpus->nr = nr; in perf_cpu_map__empty_new()
169 cpus->map[i].cpu = -1; in perf_cpu_map__empty_new()
171 refcount_set(&cpus->refcnt, 1); in perf_cpu_map__empty_new()
184 cpus->nr = nr; in cpu_aggr_map__empty_new()
186 cpus->map[i] = aggr_cpu_id__empty(); in cpu_aggr_map__empty_new()
188 refcount_set(&cpus->refcnt, 1); in cpu_aggr_map__empty_new()
194 static int cpu__get_topology_int(int cpu, const char *name, int *value) in cpu__get_topology_int() argument
199 "devices/system/cpu/cpu%d/topology/%s", cpu, name); in cpu__get_topology_int()
204 int cpu__get_socket_id(struct perf_cpu cpu) in cpu__get_socket_id() argument
206 int value, ret = cpu__get_topology_int(cpu.cpu, "physical_package_id", &value); in cpu__get_socket_id()
210 struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data __maybe_unused) in aggr_cpu_id__socket() argument
214 id.socket = cpu__get_socket_id(cpu); in aggr_cpu_id__socket()
223 if (a->node != b->node) in aggr_cpu_id__cmp()
224 return a->node - b->node; in aggr_cpu_id__cmp()
225 else if (a->socket != b->socket) in aggr_cpu_id__cmp()
226 return a->socket - b->socket; in aggr_cpu_id__cmp()
227 else if (a->die != b->die) in aggr_cpu_id__cmp()
228 return a->die - b->die; in aggr_cpu_id__cmp()
229 else if (a->core != b->core) in aggr_cpu_id__cmp()
230 return a->core - b->core; in aggr_cpu_id__cmp()
232 return a->thread_idx - b->thread_idx; in aggr_cpu_id__cmp()
240 struct perf_cpu cpu; in cpu_aggr_map__new() local
241 struct cpu_aggr_map *c = cpu_aggr_map__empty_new(cpus->nr); in cpu_aggr_map__new()
247 c->nr = 0; in cpu_aggr_map__new()
249 perf_cpu_map__for_each_cpu(cpu, idx, cpus) { in cpu_aggr_map__new()
251 struct aggr_cpu_id cpu_id = get_id(cpu, data); in cpu_aggr_map__new()
253 for (int j = 0; j < c->nr; j++) { in cpu_aggr_map__new()
254 if (aggr_cpu_id__equal(&cpu_id, &c->map[j])) { in cpu_aggr_map__new()
260 c->map[c->nr] = cpu_id; in cpu_aggr_map__new()
261 c->nr++; in cpu_aggr_map__new()
265 if (c->nr != cpus->nr) { in cpu_aggr_map__new()
268 sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id) * c->nr); in cpu_aggr_map__new()
274 qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); in cpu_aggr_map__new()
280 int cpu__get_die_id(struct perf_cpu cpu) in cpu__get_die_id() argument
282 int value, ret = cpu__get_topology_int(cpu.cpu, "die_id", &value); in cpu__get_die_id()
287 struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data) in aggr_cpu_id__die() argument
292 die = cpu__get_die_id(cpu); in aggr_cpu_id__die()
294 if (die == -1) in aggr_cpu_id__die()
302 id = aggr_cpu_id__socket(cpu, data); in aggr_cpu_id__die()
310 int cpu__get_core_id(struct perf_cpu cpu) in cpu__get_core_id() argument
312 int value, ret = cpu__get_topology_int(cpu.cpu, "core_id", &value); in cpu__get_core_id()
316 struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data) in aggr_cpu_id__core() argument
319 int core = cpu__get_core_id(cpu); in aggr_cpu_id__core()
322 id = aggr_cpu_id__die(cpu, data); in aggr_cpu_id__core()
335 struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data) in aggr_cpu_id__cpu() argument
340 id = aggr_cpu_id__core(cpu, data); in aggr_cpu_id__cpu()
344 id.cpu = cpu; in aggr_cpu_id__cpu()
349 struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data __maybe_unused) in aggr_cpu_id__node() argument
353 id.node = cpu__get_node(cpu); in aggr_cpu_id__node()
357 /* setup simple routines to easily access node numbers given a cpu number */
365 return -1; in get_max_num()
370 while (--num) { in get_max_num()
371 if ((buf[num] == ',') || (buf[num] == '-')) { in get_max_num()
377 err = -1; in get_max_num()
381 /* convert from 0-based to 1-based */ in get_max_num()
389 /* Determine highest possible cpu in the system for sparse allocation */
394 int ret = -1; in set_max_cpu_num()
397 max_cpu_num.cpu = 4096; in set_max_cpu_num()
398 max_present_cpu_num.cpu = 4096; in set_max_cpu_num()
404 /* get the highest possible cpu number for a sparse allocation */ in set_max_cpu_num()
405 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt); in set_max_cpu_num()
411 ret = get_max_num(path, &max_cpu_num.cpu); in set_max_cpu_num()
415 /* get the highest present cpu number for a sparse allocation */ in set_max_cpu_num()
416 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); in set_max_cpu_num()
422 ret = get_max_num(path, &max_present_cpu_num.cpu); in set_max_cpu_num()
426 pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num.cpu); in set_max_cpu_num()
434 int ret = -1; in set_max_node_num()
443 /* get the highest possible cpu number for a sparse allocation */ in set_max_node_num()
467 if (unlikely(!max_cpu_num.cpu)) in cpu__max_cpu()
475 if (unlikely(!max_present_cpu_num.cpu)) in cpu__max_present_cpu()
482 int cpu__get_node(struct perf_cpu cpu) in cpu__get_node() argument
486 return -1; in cpu__get_node()
489 return cpunode_map[cpu.cpu]; in cpu__get_node()
499 cpunode_map = calloc(max_cpu_num.cpu, sizeof(int)); in init_cpunode_map()
502 return -1; in init_cpunode_map()
505 for (i = 0; i < max_cpu_num.cpu; i++) in init_cpunode_map()
506 cpunode_map[i] = -1; in init_cpunode_map()
515 unsigned int cpu, mem; in cpu__setup_cpunode_map() local
523 return -1; in cpu__setup_cpunode_map()
532 return -1; in cpu__setup_cpunode_map()
539 /* walk tree and setup map */ in cpu__setup_cpunode_map()
541 if (dent1->d_type != DT_DIR || sscanf(dent1->d_name, "node%u", &mem) < 1) in cpu__setup_cpunode_map()
544 n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name); in cpu__setup_cpunode_map()
554 if (dent2->d_type != DT_LNK || sscanf(dent2->d_name, "cpu%u", &cpu) < 1) in cpu__setup_cpunode_map()
556 cpunode_map[cpu] = mem; in cpu__setup_cpunode_map()
564 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) in cpu_map__snprint() argument
566 int i, start = -1; in cpu_map__snprint()
572 for (i = 0; i < map->nr + 1; i++) { in cpu_map__snprint()
573 struct perf_cpu cpu = { .cpu = INT_MAX }; in cpu_map__snprint() local
574 bool last = i == map->nr; in cpu_map__snprint()
577 cpu = map->map[i]; in cpu_map__snprint()
579 if (start == -1) { in cpu_map__snprint()
582 ret += snprintf(buf + ret, size - ret, in cpu_map__snprint()
584 map->map[i].cpu); in cpu_map__snprint()
586 } else if (((i - start) != (cpu.cpu - map->map[start].cpu)) || last) { in cpu_map__snprint()
587 int end = i - 1; in cpu_map__snprint()
590 ret += snprintf(buf + ret, size - ret, in cpu_map__snprint()
592 map->map[start].cpu); in cpu_map__snprint()
594 ret += snprintf(buf + ret, size - ret, in cpu_map__snprint()
595 "%s%d-%d", COMMA, in cpu_map__snprint()
596 map->map[start].cpu, map->map[end].cpu); in cpu_map__snprint()
614 return val - 10 + 'a'; in hex_char()
618 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) in cpu_map__snprint_mask() argument
620 int i, cpu; in cpu_map__snprint_mask() local
623 struct perf_cpu last_cpu = perf_cpu_map__cpu(map, map->nr - 1); in cpu_map__snprint_mask()
628 bitmap = zalloc(last_cpu.cpu / 8 + 1); in cpu_map__snprint_mask()
634 for (i = 0; i < map->nr; i++) { in cpu_map__snprint_mask()
635 cpu = perf_cpu_map__cpu(map, i).cpu; in cpu_map__snprint_mask()
636 bitmap[cpu / 8] |= 1 << (cpu % 8); in cpu_map__snprint_mask()
639 for (cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) { in cpu_map__snprint_mask()
640 unsigned char bits = bitmap[cpu / 8]; in cpu_map__snprint_mask()
642 if (cpu % 8) in cpu_map__snprint_mask()
648 if ((cpu % 32) == 0 && cpu > 0) in cpu_map__snprint_mask()
654 buf[size - 1] = '\0'; in cpu_map__snprint_mask()
655 return ptr - buf; in cpu_map__snprint_mask()
663 online = perf_cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */ in cpu_map__online()
670 return a->thread_idx == b->thread_idx && in aggr_cpu_id__equal()
671 a->node == b->node && in aggr_cpu_id__equal()
672 a->socket == b->socket && in aggr_cpu_id__equal()
673 a->die == b->die && in aggr_cpu_id__equal()
674 a->core == b->core && in aggr_cpu_id__equal()
675 a->cpu.cpu == b->cpu.cpu; in aggr_cpu_id__equal()
680 return a->thread_idx == -1 && in aggr_cpu_id__is_empty()
681 a->node == -1 && in aggr_cpu_id__is_empty()
682 a->socket == -1 && in aggr_cpu_id__is_empty()
683 a->die == -1 && in aggr_cpu_id__is_empty()
684 a->core == -1 && in aggr_cpu_id__is_empty()
685 a->cpu.cpu == -1; in aggr_cpu_id__is_empty()
691 .thread_idx = -1, in aggr_cpu_id__empty()
692 .node = -1, in aggr_cpu_id__empty()
693 .socket = -1, in aggr_cpu_id__empty()
694 .die = -1, in aggr_cpu_id__empty()
695 .core = -1, in aggr_cpu_id__empty()
696 .cpu = (struct perf_cpu){ .cpu = -1 }, in aggr_cpu_id__empty()