add additional checks for bad cache information in VM (#21059)

* add additional checks for bad cache information in VM

* update implementation
This commit is contained in:
Wanglei Shen 2023-11-27 07:51:44 +08:00 committed by GitHub
parent 91660b1c05
commit 72cb4e4820
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -353,6 +353,16 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
_processors = system_info_table.size(); _processors = system_info_table.size();
_cpu_mapping_table.resize(_processors, std::vector<int>(CPU_MAP_TABLE_SIZE, -1)); _cpu_mapping_table.resize(_processors, std::vector<int>(CPU_MAP_TABLE_SIZE, -1));
auto clean_up_output = [&]() {
_processors = 0;
_cores = 0;
_numa_nodes = 0;
_sockets = 0;
_cpu_mapping_table.clear();
_proc_type_table.clear();
return;
};
auto update_proc_map_info = [&](const int nproc) { auto update_proc_map_info = [&](const int nproc) {
if (-1 == _cpu_mapping_table[nproc][CPU_MAP_CORE_ID]) { if (-1 == _cpu_mapping_table[nproc][CPU_MAP_CORE_ID]) {
int core_1 = 0; int core_1 = 0;
@ -367,6 +377,10 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
core_1 = std::stoi(sub_str); core_1 = std::stoi(sub_str);
sub_str = system_info_table[nproc][0].substr(endpos + 1); sub_str = system_info_table[nproc][0].substr(endpos + 1);
core_2 = std::stoi(sub_str); core_2 = std::stoi(sub_str);
if ((core_1 != nproc) && (core_2 != nproc)) {
clean_up_output();
return;
}
_cpu_mapping_table[core_1][CPU_MAP_PROCESSOR_ID] = core_1; _cpu_mapping_table[core_1][CPU_MAP_PROCESSOR_ID] = core_1;
_cpu_mapping_table[core_2][CPU_MAP_PROCESSOR_ID] = core_2; _cpu_mapping_table[core_2][CPU_MAP_PROCESSOR_ID] = core_2;
@ -460,6 +474,9 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
_cpu_mapping_table[m][CPU_MAP_SOCKET_ID] = _sockets; _cpu_mapping_table[m][CPU_MAP_SOCKET_ID] = _sockets;
_cpu_mapping_table[m][CPU_MAP_NUMA_NODE_ID] = _cpu_mapping_table[m][CPU_MAP_SOCKET_ID]; _cpu_mapping_table[m][CPU_MAP_NUMA_NODE_ID] = _cpu_mapping_table[m][CPU_MAP_SOCKET_ID];
update_proc_map_info(m); update_proc_map_info(m);
if (_processors == 0) {
return;
};
} }
} else if (pos != std::string::npos) { } else if (pos != std::string::npos) {
sub_str = system_info_table[n][2].substr(pos); sub_str = system_info_table[n][2].substr(pos);
@ -467,6 +484,9 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
_cpu_mapping_table[core_1][CPU_MAP_SOCKET_ID] = _sockets; _cpu_mapping_table[core_1][CPU_MAP_SOCKET_ID] = _sockets;
_cpu_mapping_table[core_1][CPU_MAP_NUMA_NODE_ID] = _cpu_mapping_table[core_1][CPU_MAP_SOCKET_ID]; _cpu_mapping_table[core_1][CPU_MAP_NUMA_NODE_ID] = _cpu_mapping_table[core_1][CPU_MAP_SOCKET_ID];
update_proc_map_info(core_1); update_proc_map_info(core_1);
if (_processors == 0) {
return;
};
endpos = pos; endpos = pos;
} }

View File

@ -1172,6 +1172,28 @@ LinuxCpuMapTestCase cache_1sockets_6cores_hyperthreading = {
}, },
{}, {},
}; };
LinuxCpuMapTestCase cache_VM_cache_0 = {
0,
0,
0,
0,
{},
{},
{
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
{{"0-31"}, {"0-31"}, {"0-31"}}, {{"0-31"}, {"0-31"}, {"0-31"}},
},
{},
};
TEST_P(LinuxCpuMapCacheParserTests, LinuxCache) {} TEST_P(LinuxCpuMapCacheParserTests, LinuxCache) {}
@ -1192,7 +1214,8 @@ INSTANTIATE_TEST_SUITE_P(CPUMap,
cache_1sockets_14cores_hyperthreading_1, cache_1sockets_14cores_hyperthreading_1,
cache_1sockets_10cores_hyperthreading, cache_1sockets_10cores_hyperthreading,
cache_1sockets_8cores_hyperthreading, cache_1sockets_8cores_hyperthreading,
cache_1sockets_6cores_hyperthreading)); cache_1sockets_6cores_hyperthreading,
cache_VM_cache_0));
TEST_P(LinuxGetCpuMapFromCoresTests, LinuxCore) {} TEST_P(LinuxGetCpuMapFromCoresTests, LinuxCore) {}