Lines Matching +full:cpu +full:- +full:nr

1 // SPDX-License-Identifier: GPL-2.0
22 * CPU number.
34 return (data->mask32_data.long_size == 4)
35 ? (bit_word32 < data->mask32_data.nr) &&
36 (data->mask32_data.mask[bit_word32] & bit_mask32) != 0
37 : (bit_word64 < data->mask64_data.nr) &&
38 (data->mask64_data.mask[bit_word64] & bit_mask64) != 0;
41 /* Read ith mask value from data into the given 64-bit sized bitmap */
46 if (data->mask32_data.long_size == 4)
47 bitmap[0] = data->mask32_data.mask[i];
49 bitmap[0] = data->mask64_data.mask[i];
51 if (data->mask32_data.long_size == 4) {
52 bitmap[0] = data->mask32_data.mask[i];
56 bitmap[0] = (unsigned long)(data->mask64_data.mask[i] >> 32);
57 bitmap[1] = (unsigned long)data->mask64_data.mask[i];
59 bitmap[0] = (unsigned long)data->mask64_data.mask[i];
60 bitmap[1] = (unsigned long)(data->mask64_data.mask[i] >> 32);
69 map = perf_cpu_map__empty_new(data->cpus_data.nr);
73 for (unsigned int i = 0; i < data->cpus_data.nr; i++) {
75 * Special treatment for -1, which is not real cpu number,
76 * and we need to use (int) -1 to initialize map[i],
79 if (data->cpus_data.cpu[i] == (u16) -1) {
80 RC_CHK_ACCESS(map)->map[i].cpu = -1;
81 } else if (data->cpus_data.cpu[i] < INT16_MAX) {
82 RC_CHK_ACCESS(map)->map[i].cpu = (int16_t) data->cpus_data.cpu[i];
84 pr_err("Invalid cpumap entry %u\n", data->cpus_data.cpu[i]);
96 int weight = 0, mask_nr = data->mask32_data.nr;
109 int cpus_per_i = (i * data->mask32_data.long_size * BITS_PER_BYTE);
110 int cpu;
113 for_each_set_bit(cpu, local_copy, 64) {
114 if (cpu + cpus_per_i < INT16_MAX) {
115 RC_CHK_ACCESS(map)->map[j++].cpu = cpu + cpus_per_i;
117 pr_err("Invalid cpumap entry %d\n", cpu + cpus_per_i);
132 map = perf_cpu_map__empty_new(data->range_cpu_data.end_cpu -
133 data->range_cpu_data.start_cpu + 1 + data->range_cpu_data.any_cpu);
137 if (data->range_cpu_data.any_cpu)
138 RC_CHK_ACCESS(map)->map[i++].cpu = -1;
140 for (int cpu = data->range_cpu_data.start_cpu; cpu <= data->range_cpu_data.end_cpu;
141 i++, cpu++) {
142 if (cpu < INT16_MAX) {
143 RC_CHK_ACCESS(map)->map[i].cpu = cpu;
145 pr_err("Invalid cpumap entry %d\n", cpu);
156 switch (data->type) {
164 pr_err("cpu_map__new_data unknown type %d\n", data->type);
179 struct perf_cpu_map *perf_cpu_map__empty_new(int nr)
181 struct perf_cpu_map *cpus = perf_cpu_map__alloc(nr);
184 for (int i = 0; i < nr; i++)
185 RC_CHK_ACCESS(cpus)->map[i].cpu = -1;
191 struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr)
193 struct cpu_aggr_map *cpus = malloc(sizeof(*cpus) + sizeof(struct aggr_cpu_id) * nr);
198 cpus->nr = nr;
199 for (i = 0; i < nr; i++)
200 cpus->map[i] = aggr_cpu_id__empty();
206 static int cpu__get_topology_int(int cpu, const char *name, int *value)
211 "devices/system/cpu/cpu%d/topology/%s", cpu, name);
216 int cpu__get_socket_id(struct perf_cpu cpu)
218 int value, ret = cpu__get_topology_int(cpu.cpu, "physical_package_id", &value);
222 struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data __maybe_unused)
226 id.socket = cpu__get_socket_id(cpu);
235 if (a->node != b->node)
236 return a->node - b->node;
237 else if (a->socket != b->socket)
238 return a->socket - b->socket;
239 else if (a->die != b->die)
240 return a->die - b->die;
241 else if (a->cluster != b->cluster)
242 return a->cluster - b->cluster;
243 else if (a->cache_lvl != b->cache_lvl)
244 return a->cache_lvl - b->cache_lvl;
245 else if (a->cache != b->cache)
246 return a->cache - b->cache;
247 else if (a->core != b->core)
248 return a->core - b->core;
250 return a->thread_idx - b->thread_idx;
258 struct perf_cpu cpu;
265 c->nr = 0;
267 perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
269 struct aggr_cpu_id cpu_id = get_id(cpu, data);
271 for (int j = 0; j < c->nr; j++) {
272 if (aggr_cpu_id__equal(&cpu_id, &c->map[j])) {
278 c->map[c->nr] = cpu_id;
279 c->nr++;
283 if (c->nr != perf_cpu_map__nr(cpus)) {
286 sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id) * c->nr);
294 qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp);
300 int cpu__get_die_id(struct perf_cpu cpu)
302 int value, ret = cpu__get_topology_int(cpu.cpu, "die_id", &value);
307 struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data)
312 die = cpu__get_die_id(cpu);
322 id = aggr_cpu_id__socket(cpu, data);
330 int cpu__get_cluster_id(struct perf_cpu cpu)
332 int value, ret = cpu__get_topology_int(cpu.cpu, "cluster_id", &value);
337 struct aggr_cpu_id aggr_cpu_id__cluster(struct perf_cpu cpu, void *data)
339 int cluster = cpu__get_cluster_id(cpu);
346 id = aggr_cpu_id__die(cpu, data);
354 int cpu__get_core_id(struct perf_cpu cpu)
356 int value, ret = cpu__get_topology_int(cpu.cpu, "core_id", &value);
360 struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data)
363 int core = cpu__get_core_id(cpu);
366 id = aggr_cpu_id__cluster(cpu, data);
379 struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data)
384 id = aggr_cpu_id__core(cpu, data);
388 id.cpu = cpu;
393 struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data __maybe_unused)
397 id.node = cpu__get_node(cpu);
401 struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data __maybe_unused)
405 /* it always aggregates to the cpu 0 */
406 cpu.cpu = 0;
407 id.cpu = cpu;
411 /* setup simple routines to easily access node numbers given a cpu number */
419 return -1;
424 while (--num) {
425 if ((buf[num] == ',') || (buf[num] == '-')) {
431 err = -1;
435 /* convert from 0-based to 1-based */
443 /* Determine highest possible cpu in the system for sparse allocation */
448 int max, ret = -1;
451 max_cpu_num.cpu = 4096;
452 max_present_cpu_num.cpu = 4096;
458 /* get the highest possible cpu number for a sparse allocation */
459 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
469 max_cpu_num.cpu = max;
471 /* get the highest present cpu number for a sparse allocation */
472 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt);
482 ret = -1;
485 max_present_cpu_num.cpu = (int16_t)max;
488 pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num.cpu);
496 int ret = -1;
505 /* get the highest possible cpu number for a sparse allocation */
529 if (unlikely(!max_cpu_num.cpu))
537 if (unlikely(!max_present_cpu_num.cpu))
544 int cpu__get_node(struct perf_cpu cpu)
548 return -1;
551 return cpunode_map[cpu.cpu];
561 cpunode_map = calloc(max_cpu_num.cpu, sizeof(int));
564 return -1;
567 for (i = 0; i < max_cpu_num.cpu; i++)
568 cpunode_map[i] = -1;
577 unsigned int cpu, mem;
585 return -1;
594 return -1;
603 if (dent1->d_type != DT_DIR || sscanf(dent1->d_name, "node%u", &mem) < 1)
606 n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name);
616 if (dent2->d_type != DT_LNK || sscanf(dent2->d_name, "cpu%u", &cpu) < 1)
618 cpunode_map[cpu] = mem;
628 int i, start = -1;
635 struct perf_cpu cpu = { .cpu = INT16_MAX };
639 cpu = perf_cpu_map__cpu(map, i);
641 if (start == -1) {
644 ret += snprintf(buf + ret, size - ret,
646 perf_cpu_map__cpu(map, i).cpu);
648 } else if (((i - start) != (cpu.cpu - perf_cpu_map__cpu(map, start).cpu)) || last) {
649 int end = i - 1;
652 ret += snprintf(buf + ret, size - ret,
654 perf_cpu_map__cpu(map, start).cpu);
656 ret += snprintf(buf + ret, size - ret,
657 "%s%d-%d", COMMA,
658 perf_cpu_map__cpu(map, start).cpu, perf_cpu_map__cpu(map, end).cpu);
676 return val - 10 + 'a';
690 bitmap = zalloc(last_cpu.cpu / 8 + 1);
697 bitmap[c.cpu / 8] |= 1 << (c.cpu % 8);
699 for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) {
700 unsigned char bits = bitmap[cpu / 8];
702 if (cpu % 8)
708 if ((cpu % 32) == 0 && cpu > 0)
714 buf[size - 1] = '\0';
715 return ptr - buf;
723 online = perf_cpu_map__new_online_cpus(); /* from /sys/devices/system/cpu/online */
730 return a->thread_idx == b->thread_idx &&
731 a->node == b->node &&
732 a->socket == b->socket &&
733 a->die == b->die &&
734 a->cluster == b->cluster &&
735 a->cache_lvl == b->cache_lvl &&
736 a->cache == b->cache &&
737 a->core == b->core &&
738 a->cpu.cpu == b->cpu.cpu;
743 return a->thread_idx == -1 &&
744 a->node == -1 &&
745 a->socket == -1 &&
746 a->die == -1 &&
747 a->cluster == -1 &&
748 a->cache_lvl == -1 &&
749 a->cache == -1 &&
750 a->core == -1 &&
751 a->cpu.cpu == -1;
757 .thread_idx = -1,
758 .node = -1,
759 .socket = -1,
760 .die = -1,
761 .cluster = -1,
762 .cache_lvl = -1,
763 .cache = -1,
764 .core = -1,
765 .cpu = (struct perf_cpu){ .cpu = -1 },