• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0
33 cpus->map[i] = i; in cpu_map__default_new()
35 cpus->nr = nr_cpus; in cpu_map__default_new()
36 refcount_set(&cpus->refcnt, 1); in cpu_map__default_new()
48 cpus->nr = nr_cpus; in cpu_map__trim_new()
49 memcpy(cpus->map, tmp_cpus, payload_size); in cpu_map__trim_new()
50 refcount_set(&cpus->refcnt, 1); in cpu_map__trim_new()
62 int n, cpu, prev; in cpu_map__read() local
66 prev = -1; in cpu_map__read()
68 n = fscanf(file, "%u%c", &cpu, &sep); in cpu_map__read()
72 int new_max = nr_cpus + cpu - prev - 1; in cpu_map__read()
82 while (++prev < cpu) in cpu_map__read()
93 tmp_cpus[nr_cpus++] = cpu; in cpu_map__read()
94 if (n == 2 && sep == '-') in cpu_map__read()
95 prev = cpu; in cpu_map__read()
97 prev = -1; in cpu_map__read()
116 onlnf = fopen("/sys/devices/system/cpu/online", "r"); in cpu_map__read_all_cpu_map()
139 * TOPOLOGY header for NUMA nodes with no CPU in cpu_map__new()
140 * ( e.g., because of CPU hotplug) in cpu_map__new()
149 || (*p != '\0' && *p != ',' && *p != '-')) in cpu_map__new()
152 if (*p == '-') { in cpu_map__new()
203 map = cpu_map__empty_new(cpus->nr); in cpu_map__from_entries()
207 for (i = 0; i < cpus->nr; i++) { in cpu_map__from_entries()
209 * Special treatment for -1, which is not real cpu number, in cpu_map__from_entries()
210 * and we need to use (int) -1 to initialize map[i], in cpu_map__from_entries()
213 if (cpus->cpu[i] == (u16) -1) in cpu_map__from_entries()
214 map->map[i] = -1; in cpu_map__from_entries()
216 map->map[i] = (int) cpus->cpu[i]; in cpu_map__from_entries()
226 int nr, nbits = mask->nr * mask->long_size * BITS_PER_BYTE; in cpu_map__from_mask() local
228 nr = bitmap_weight(mask->mask, nbits); in cpu_map__from_mask()
230 map = cpu_map__empty_new(nr); in cpu_map__from_mask()
232 int cpu, i = 0; in cpu_map__from_mask() local
234 for_each_set_bit(cpu, mask->mask, nbits) in cpu_map__from_mask()
235 map->map[i++] = cpu; in cpu_map__from_mask()
243 if (data->type == PERF_CPU_MAP__CPUS) in cpu_map__new_data()
244 return cpu_map__from_entries((struct cpu_map_entries *)data->data); in cpu_map__new_data()
246 return cpu_map__from_mask((struct cpu_map_mask *)data->data); in cpu_map__new_data()
264 cpus->nr = 1; in cpu_map__dummy_new()
265 cpus->map[0] = -1; in cpu_map__dummy_new()
266 refcount_set(&cpus->refcnt, 1); in cpu_map__dummy_new()
272 struct cpu_map *cpu_map__empty_new(int nr) in cpu_map__empty_new() argument
274 struct cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr); in cpu_map__empty_new()
279 cpus->nr = nr; in cpu_map__empty_new()
280 for (i = 0; i < nr; i++) in cpu_map__empty_new()
281 cpus->map[i] = -1; in cpu_map__empty_new()
283 refcount_set(&cpus->refcnt, 1); in cpu_map__empty_new()
292 WARN_ONCE(refcount_read(&map->refcnt) != 0, in cpu_map__delete()
301 refcount_inc(&map->refcnt); in cpu_map__get()
307 if (map && refcount_dec_and_test(&map->refcnt)) in cpu_map__put()
311 static int cpu__get_topology_int(int cpu, const char *name, int *value) in cpu__get_topology_int() argument
316 "devices/system/cpu/cpu%d/topology/%s", cpu, name); in cpu__get_topology_int()
321 int cpu_map__get_socket_id(int cpu) in cpu_map__get_socket_id() argument
323 int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value); in cpu_map__get_socket_id()
329 int cpu; in cpu_map__get_socket() local
331 if (idx > map->nr) in cpu_map__get_socket()
332 return -1; in cpu_map__get_socket()
334 cpu = map->map[idx]; in cpu_map__get_socket()
336 return cpu_map__get_socket_id(cpu); in cpu_map__get_socket()
341 return *(int *)a - *(int *)b; in cmp_ids()
345 int (*f)(struct cpu_map *map, int cpu, void *data), in cpu_map__build_map()
349 int nr = cpus->nr; in cpu_map__build_map() local
350 int cpu, s1, s2; in cpu_map__build_map() local
353 c = calloc(1, sizeof(*c) + nr * sizeof(int)); in cpu_map__build_map()
355 return -1; in cpu_map__build_map()
357 for (cpu = 0; cpu < nr; cpu++) { in cpu_map__build_map()
358 s1 = f(cpus, cpu, data); in cpu_map__build_map()
359 for (s2 = 0; s2 < c->nr; s2++) { in cpu_map__build_map()
360 if (s1 == c->map[s2]) in cpu_map__build_map()
363 if (s2 == c->nr) { in cpu_map__build_map()
364 c->map[c->nr] = s1; in cpu_map__build_map()
365 c->nr++; in cpu_map__build_map()
369 qsort(c->map, c->nr, sizeof(int), cmp_ids); in cpu_map__build_map()
371 refcount_set(&c->refcnt, 1); in cpu_map__build_map()
376 int cpu_map__get_core_id(int cpu) in cpu_map__get_core_id() argument
378 int value, ret = cpu__get_topology_int(cpu, "core_id", &value); in cpu_map__get_core_id()
384 int cpu, s; in cpu_map__get_core() local
386 if (idx > map->nr) in cpu_map__get_core()
387 return -1; in cpu_map__get_core()
389 cpu = map->map[idx]; in cpu_map__get_core()
391 cpu = cpu_map__get_core_id(cpu); in cpu_map__get_core()
394 if (s == -1) in cpu_map__get_core()
395 return -1; in cpu_map__get_core()
403 return (s << 16) | (cpu & 0xffff); in cpu_map__get_core()
416 /* setup simple routines to easily access node numbers given a cpu number */
424 return -1; in get_max_num()
429 while (--num) { in get_max_num()
430 if ((buf[num] == ',') || (buf[num] == '-')) { in get_max_num()
436 err = -1; in get_max_num()
440 /* convert from 0-based to 1-based */ in get_max_num()
448 /* Determine highest possible cpu in the system for sparse allocation */
453 int ret = -1; in set_max_cpu_num()
463 /* get the highest possible cpu number for a sparse allocation */ in set_max_cpu_num()
464 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt); in set_max_cpu_num()
474 /* get the highest present cpu number for a sparse allocation */ in set_max_cpu_num()
475 ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); in set_max_cpu_num()
493 int ret = -1; in set_max_node_num()
502 /* get the highest possible cpu number for a sparse allocation */ in set_max_node_num()
541 int cpu__get_node(int cpu) in cpu__get_node() argument
545 return -1; in cpu__get_node()
548 return cpunode_map[cpu]; in cpu__get_node()
561 return -1; in init_cpunode_map()
565 cpunode_map[i] = -1; in init_cpunode_map()
574 unsigned int cpu, mem; in cpu__setup_cpunode_map() local
582 return -1; in cpu__setup_cpunode_map()
591 return -1; in cpu__setup_cpunode_map()
600 if (dent1->d_type != DT_DIR || sscanf(dent1->d_name, "node%u", &mem) < 1) in cpu__setup_cpunode_map()
603 n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name); in cpu__setup_cpunode_map()
613 if (dent2->d_type != DT_LNK || sscanf(dent2->d_name, "cpu%u", &cpu) < 1) in cpu__setup_cpunode_map()
615 cpunode_map[cpu] = mem; in cpu__setup_cpunode_map()
623 bool cpu_map__has(struct cpu_map *cpus, int cpu) in cpu_map__has() argument
625 return cpu_map__idx(cpus, cpu) != -1; in cpu_map__has()
628 int cpu_map__idx(struct cpu_map *cpus, int cpu) in cpu_map__idx() argument
632 for (i = 0; i < cpus->nr; ++i) { in cpu_map__idx()
633 if (cpus->map[i] == cpu) in cpu_map__idx()
637 return -1; in cpu_map__idx()
642 return cpus->map[idx]; in cpu_map__cpu()
647 int i, cpu, start = -1; in cpu_map__snprint() local
653 for (i = 0; i < map->nr + 1; i++) { in cpu_map__snprint()
654 bool last = i == map->nr; in cpu_map__snprint()
656 cpu = last ? INT_MAX : map->map[i]; in cpu_map__snprint()
658 if (start == -1) { in cpu_map__snprint()
661 ret += snprintf(buf + ret, size - ret, in cpu_map__snprint()
663 map->map[i]); in cpu_map__snprint()
665 } else if (((i - start) != (cpu - map->map[start])) || last) { in cpu_map__snprint()
666 int end = i - 1; in cpu_map__snprint()
669 ret += snprintf(buf + ret, size - ret, in cpu_map__snprint()
671 map->map[start]); in cpu_map__snprint()
673 ret += snprintf(buf + ret, size - ret, in cpu_map__snprint()
674 "%s%d-%d", COMMA, in cpu_map__snprint()
675 map->map[start], map->map[end]); in cpu_map__snprint()
693 return val - 10 + 'a'; in hex_char()
699 int i, cpu; in cpu_map__snprint_mask() local
702 int last_cpu = cpu_map__cpu(map, map->nr - 1); in cpu_map__snprint_mask()
713 for (i = 0; i < map->nr; i++) { in cpu_map__snprint_mask()
714 cpu = cpu_map__cpu(map, i); in cpu_map__snprint_mask()
715 bitmap[cpu / 8] |= 1 << (cpu % 8); in cpu_map__snprint_mask()
718 for (cpu = last_cpu / 4 * 4; cpu >= 0; cpu -= 4) { in cpu_map__snprint_mask()
719 unsigned char bits = bitmap[cpu / 8]; in cpu_map__snprint_mask()
721 if (cpu % 8) in cpu_map__snprint_mask()
727 if ((cpu % 32) == 0 && cpu > 0) in cpu_map__snprint_mask()
733 buf[size - 1] = '\0'; in cpu_map__snprint_mask()
734 return ptr - buf; in cpu_map__snprint_mask()