// The __get_cpu_count function needs a 4096 byte buffer to match a page size // to avoid malloc/free when reading from a file. #pragma clang diagnostic ignored "-Wframe-larger-than="
int __get_cpu_count(constchar* sys_file) { int cpu_count = 1; int fd = open(sys_file, O_RDONLY | O_CLOEXEC); if (fd >= 0) { // DEVICE_ATTR sysfs attributes are limited to a single page in size. // Setting this buffer at 4096 bytes handles systems with hundreds // of cores and meets the page size. char buf[4096] __attribute__((__uninitialized__));
ssize_t rc = read(fd, buf, sizeof(buf)); if (rc > 0) {
cpu_count = GetCpuCountFromString(buf);
}
close(fd);
} return cpu_count;
}
int get_nprocs_conf() { // It's unclear to me whether this is intended to be "possible" or "present", // but on mobile they're unlikely to differ. return __get_cpu_count("/sys/devices/system/cpu/possible");
}
int get_nprocs() { return __get_cpu_count("/sys/devices/system/cpu/online");
}
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.