bool perf_record_cpu_map_data__test_bit(int i, conststruct perf_record_cpu_map_data *data)
{ int bit_word32 = i / 32;
__u32 bit_mask32 = 1U << (i & 31); int bit_word64 = i / 64;
__u64 bit_mask64 = ((__u64)1) << (i & 63);
/* aggr_cpu_id__die returns a struct with socket die, and cluster set. */
id = aggr_cpu_id__cluster(cpu, data); if (aggr_cpu_id__is_empty(&id)) return id;
/* it always aggregates to the cpu 0 */
cpu.cpu = 0;
id.cpu = cpu; return id;
}
/* setup simple routines to easily access node numbers given a cpu number */ staticint get_max_num(char *path, int *max)
{
size_t num; char *buf; int err = 0;
if (filename__read_str(path, &buf, &num)) return -1;
buf[num] = '\0';
/* start on the right, to find highest node num */ while (--num) { if ((buf[num] == ',') || (buf[num] == '-')) {
num++; break;
}
} if (sscanf(&buf[num], "%d", max) < 1) {
err = -1; goto out;
}
/* convert from 0-based to 1-based */
(*max)++;
out:
free(buf); return err;
}
/* Determine highest possible cpu in the system for sparse allocation */ staticvoid set_max_cpu_num(void)
{ constchar *mnt; char path[PATH_MAX]; int max, ret = -1;
/* set up default */
max_cpu_num.cpu = 4096;
max_present_cpu_num.cpu = 4096;
mnt = sysfs__mountpoint(); if (!mnt) goto out;
/* get the highest possible cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt); if (ret >= PATH_MAX) {
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); goto out;
}
ret = get_max_num(path, &max); if (ret) goto out;
max_cpu_num.cpu = max;
/* get the highest present cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); if (ret >= PATH_MAX) {
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); goto out;
}
ret = get_max_num(path, &max);
if (!ret && max > INT16_MAX) {
pr_err("Read out of bounds max cpus of %d\n", max);
ret = -1;
} if (!ret)
max_present_cpu_num.cpu = (int16_t)max;
out: if (ret)
pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num.cpu);
}
/* Determine highest possible node in the system for sparse allocation */ staticvoid set_max_node_num(void)
{ constchar *mnt; char path[PATH_MAX]; int ret = -1;
/* set up default */
max_node_num = 8;
mnt = sysfs__mountpoint(); if (!mnt) goto out;
/* get the highest possible cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/node/possible", mnt); if (ret >= PATH_MAX) {
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); goto out;
}
ret = get_max_num(path, &max_node_num);
out: if (ret)
pr_err("Failed to read max nodes, using default of %d\n", max_node_num);
}
int cpu__max_node(void)
{ if (unlikely(!max_node_num))
set_max_node_num();
return max_node_num;
}
struct perf_cpu cpu__max_cpu(void)
{ if (unlikely(!max_cpu_num.cpu))
set_max_cpu_num();
return max_cpu_num;
}
struct perf_cpu cpu__max_present_cpu(void)
{ if (unlikely(!max_present_cpu_num.cpu))
set_max_cpu_num();
return max_present_cpu_num;
}
int cpu__get_node(struct perf_cpu cpu)
{ if (unlikely(cpunode_map == NULL)) {
pr_debug("cpu_map not initialized\n"); return -1;
}
for (i = 0; i < max_cpu_num.cpu; i++)
cpunode_map[i] = -1;
return0;
}
int cpu__setup_cpunode_map(void)
{ struct dirent *dent1, *dent2;
DIR *dir1, *dir2; unsignedint cpu, mem; char buf[PATH_MAX]; char path[PATH_MAX]; constchar *mnt; int n;
/* initialize globals */ if (init_cpunode_map()) return -1;
mnt = sysfs__mountpoint(); if (!mnt) return0;
n = snprintf(path, PATH_MAX, "%s/devices/system/node", mnt); if (n >= PATH_MAX) {
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); return -1;
}
dir1 = opendir(path); if (!dir1) return0;
/* walk tree and setup map */ while ((dent1 = readdir(dir1)) != NULL) { if (dent1->d_type != DT_DIR || sscanf(dent1->d_name, "node%u", &mem) < 1) continue;
n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name); if (n >= PATH_MAX) {
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.