enable proc_type_table on MacOS for both ARM and x86 (#17427)

* enable proc_type_table on MacOS for both ARM and x86

* fix code style issue

* update for comments
This commit is contained in:
Wanglei Shen 2023-05-22 16:29:05 +08:00 committed by GitHub
parent 9b52a77531
commit 2302e10d3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -186,6 +186,59 @@ std::vector<std::vector<int>> reserve_available_cpus(const std::vector<std::vect
}
void set_cpu_used(const std::vector<int>& cpu_ids, const int used) {}
int parse_processor_info_macos(int& _processors,
int& _numa_nodes,
int& _cores,
std::vector<std::vector<int>>& _proc_type_table) {
uint64_t output = 0;
size_t size = sizeof(output);
_processors = 0;
_numa_nodes = 0;
_cores = 0;
if (sysctlbyname("hw.ncpu", &output, &size, NULL, 0) < 0) {
return -1;
} else {
_processors = output;
}
if (sysctlbyname("hw.physicalcpu", &output, &size, NULL, 0) < 0) {
_processors = 0;
return -1;
} else {
_cores = output;
}
_numa_nodes = 1;
if (sysctlbyname("hw.optional.arm64", &output, &size, NULL, 0) < 0) {
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_proc_type_table[0][ALL_PROC] = _processors;
_proc_type_table[0][MAIN_CORE_PROC] = _cores;
_proc_type_table[0][HYPER_THREADING_PROC] = _processors - _cores;
} else {
if (sysctlbyname("hw.perflevel0.physicalcpu", &output, &size, NULL, 0) < 0) {
_processors = 0;
_cores = 0;
_numa_nodes = 0;
return -1;
} else {
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_proc_type_table[0][ALL_PROC] = _processors;
_proc_type_table[0][MAIN_CORE_PROC] = output;
}
if (sysctlbyname("hw.perflevel1.physicalcpu", &output, &size, NULL, 0) < 0) {
return 0;
} else {
_proc_type_table[0][EFFICIENT_CORE_PROC] = output;
}
}
return 0;
}
#else
# ifndef _WIN32