Lines Matching +full:cpu +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0
22 * CPU number.
30 __u32 bit_mask32 = 1U << (i & 31);
32 __u64 bit_mask64 = ((__u64)1) << (i & 63);
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];
53 bitmap[1] = 0;
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 (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;
82 RC_CHK_ACCESS(map)->map[i].cpu = (int) data->cpus_data.cpu[i];
92 int weight = 0, mask_nr = data->mask32_data.nr;
105 int cpus_per_i = (i * data->mask32_data.long_size * BITS_PER_BYTE);
106 int cpu;
109 for_each_set_bit(cpu, local_copy, 64)
110 RC_CHK_ACCESS(map)->map[j++].cpu = cpu + cpus_per_i;
121 map = perf_cpu_map__empty_new(data->range_cpu_data.end_cpu -
122 data->range_cpu_data.start_cpu + 1 + data->range_cpu_data.any_cpu);
126 if (data->range_cpu_data.any_cpu)
127 RC_CHK_ACCESS(map)->map[i++].cpu = -1;
129 for (int cpu = data->range_cpu_data.start_cpu; cpu <= data->range_cpu_data.end_cpu;
130 i++, cpu++)
131 RC_CHK_ACCESS(map)->map[i].cpu = cpu;
138 switch (data->type) {
146 pr_err("cpu_map__new_data unknown type %d\n", data->type);
167 RC_CHK_ACCESS(cpus)->map[i].cpu = -1;
180 cpus->nr = nr;
182 cpus->map[i] = aggr_cpu_id__empty();
188 static int cpu__get_topology_int(int cpu, const char *name, int *value)
193 "devices/system/cpu/cpu%d/topology/%s", cpu, name);
198 int cpu__get_socket_id(struct perf_cpu cpu)
200 int value, ret = cpu__get_topology_int(cpu.cpu, "physical_package_id", &value);
204 struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data __maybe_unused)
208 id.socket = cpu__get_socket_id(cpu);
217 if (a->node != b->node)
218 return a->node - b->node;
219 else if (a->socket != b->socket)
220 return a->socket - b->socket;
221 else if (a->die != b->die)
222 return a->die - b->die;
223 else if (a->cluster != b->cluster)
224 return a->cluster - b->cluster;
225 else if (a->cache_lvl != b->cache_lvl)
226 return a->cache_lvl - b->cache_lvl;
227 else if (a->cache != b->cache)
228 return a->cache - b->cache;
229 else if (a->core != b->core)
230 return a->core - b->core;
232 return a->thread_idx - b->thread_idx;
240 struct perf_cpu cpu;
247 c->nr = 0;
249 perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
251 struct aggr_cpu_id cpu_id = get_id(cpu, data);
253 for (int j = 0; j < c->nr; j++) {
254 if (aggr_cpu_id__equal(&cpu_id, &c->map[j])) {
260 c->map[c->nr] = cpu_id;
261 c->nr++;
265 if (c->nr != perf_cpu_map__nr(cpus)) {
268 sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id) * c->nr);
276 qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp);
282 int cpu__get_die_id(struct perf_cpu cpu)
284 int value, ret = cpu__get_topology_int(cpu.cpu, "die_id", &value);
289 struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data)
294 die = cpu__get_die_id(cpu);
296 if (die == -1)
304 id = aggr_cpu_id__socket(cpu, data);
312 int cpu__get_cluster_id(struct perf_cpu cpu)
314 int value, ret = cpu__get_topology_int(cpu.cpu, "cluster_id", &value);
319 struct aggr_cpu_id aggr_cpu_id__cluster(struct perf_cpu cpu, void *data)
321 int cluster = cpu__get_cluster_id(cpu);
325 if (cluster == -1)
328 id = aggr_cpu_id__die(cpu, data);
336 int cpu__get_core_id(struct perf_cpu cpu)
338 int value, ret = cpu__get_topology_int(cpu.cpu, "core_id", &value);
342 struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data)
345 int core = cpu__get_core_id(cpu);
348 id = aggr_cpu_id__cluster(cpu, data);
361 struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data)
366 id = aggr_cpu_id__core(cpu, data);
370 id.cpu = cpu;
375 struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data __maybe_unused)
379 id.node = cpu__get_node(cpu);
383 struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data __maybe_unused)
387 /* it always aggregates to the cpu 0 */
388 cpu.cpu = 0;
389 id.cpu = cpu;
393 /* setup simple routines to easily access node numbers given a cpu number */
401 return -1;
406 while (--num) {
407 if ((buf[num] == ',') || (buf[num] == '-')) {
412 if (sscanf(&buf[num], "%d", max) < 1) {
413 err = -1;
417 /* convert from 0-based to 1-based */
425 /* Determine highest possible cpu in the system for sparse allocation */
430 int ret = -1;
433 max_cpu_num.cpu = 4096;
434 max_present_cpu_num.cpu = 4096;
440 /* get the highest possible cpu number for a sparse allocation */
441 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
447 ret = get_max_num(path, &max_cpu_num.cpu);
451 /* get the highest present cpu number for a sparse allocation */
452 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt);
458 ret = get_max_num(path, &max_present_cpu_num.cpu);
462 pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num.cpu);
470 int ret = -1;
479 /* get the highest possible cpu number for a sparse allocation */
503 if (unlikely(!max_cpu_num.cpu))
511 if (unlikely(!max_present_cpu_num.cpu))
518 int cpu__get_node(struct perf_cpu cpu)
522 return -1;
525 return cpunode_map[cpu.cpu];
535 cpunode_map = calloc(max_cpu_num.cpu, sizeof(int));
538 return -1;
541 for (i = 0; i < max_cpu_num.cpu; i++)
542 cpunode_map[i] = -1;
551 unsigned int cpu, mem;
559 return -1;
568 return -1;
577 if (dent1->d_type != DT_DIR || sscanf(dent1->d_name, "node%u", &mem) < 1)
580 n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name);
590 if (dent2->d_type != DT_LNK || sscanf(dent2->d_name, "cpu%u", &cpu) < 1)
592 cpunode_map[cpu] = mem;
602 int i, start = -1;
608 for (i = 0; i < perf_cpu_map__nr(map) + 1; i++) {
609 struct perf_cpu cpu = { .cpu = INT_MAX };
613 cpu = perf_cpu_map__cpu(map, i);
615 if (start == -1) {
618 ret += snprintf(buf + ret, size - ret,
620 perf_cpu_map__cpu(map, i).cpu);
622 } else if (((i - start) != (cpu.cpu - perf_cpu_map__cpu(map, start).cpu)) || last) {
623 int end = i - 1;
626 ret += snprintf(buf + ret, size - ret,
628 perf_cpu_map__cpu(map, start).cpu);
630 ret += snprintf(buf + ret, size - ret,
631 "%s%d-%d", COMMA,
632 perf_cpu_map__cpu(map, start).cpu, perf_cpu_map__cpu(map, end).cpu);
650 return val - 10 + 'a';
664 bitmap = zalloc(last_cpu.cpu / 8 + 1);
671 bitmap[c.cpu / 8] |= 1 << (c.cpu % 8);
673 for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) {
674 unsigned char bits = bitmap[cpu / 8];
676 if (cpu % 8)
682 if ((cpu % 32) == 0 && cpu > 0)
688 buf[size - 1] = '\0';
689 return ptr - buf;
697 online = perf_cpu_map__new_online_cpus(); /* from /sys/devices/system/cpu/online */
704 return a->thread_idx == b->thread_idx &&
705 a->node == b->node &&
706 a->socket == b->socket &&
707 a->die == b->die &&
708 a->cluster == b->cluster &&
709 a->cache_lvl == b->cache_lvl &&
710 a->cache == b->cache &&
711 a->core == b->core &&
712 a->cpu.cpu == b->cpu.cpu;
717 return a->thread_idx == -1 &&
718 a->node == -1 &&
719 a->socket == -1 &&
720 a->die == -1 &&
721 a->cluster == -1 &&
722 a->cache_lvl == -1 &&
723 a->cache == -1 &&
724 a->core == -1 &&
725 a->cpu.cpu == -1;
731 .thread_idx = -1,
732 .node = -1,
733 .socket = -1,
734 .die = -1,
735 .cluster = -1,
736 .cache_lvl = -1,
737 .cache = -1,
738 .core = -1,
739 .cpu = (struct perf_cpu){ .cpu = -1 },