Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify blocked cores on Linux #27774

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/inference/src/os/cpu_map_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void parse_node_info_linux(const std::vector<std::string> node_info_table,
* @param[out] _numa_nodes total number for nodes in system
* @param[out] _sockets total number for sockets in system
* @param[out] _cores total number for physical CPU cores in system
* @param[out] _blocked_cores total number for blocked processors in system
* @param[out] _proc_type_table summary table of number of processors per type
* @param[out] _cpu_mapping_table CPU mapping table for each processor
* @return
Expand All @@ -124,6 +125,7 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
int& _numa_nodes,
int& _sockets,
int& _cores,
int& _blocked_cores,
std::vector<std::vector<int>>& _proc_type_table,
std::vector<std::vector<int>>& _cpu_mapping_table);

Expand Down
47 changes: 43 additions & 4 deletions src/inference/src/os/lin/lin_system_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ CPU::CPU() {
int cache_files = 3;

std::vector<std::string> one_info(cache_files);
std::string cache_info;

while (1) {
for (int n = 0; n < cache_files; n++) {
cache_index = (n == 0) ? n : n + 1;
cache_info.clear();

std::ifstream cache_file("/sys/devices/system/cpu/cpu" + std::to_string(cpu_index) + "/cache/index" +
std::to_string(cache_index) + "/shared_cpu_list");
if (!cache_file.is_open()) {
if (cache_file.is_open()) {
std::getline(cache_file, cache_info);
} else if (cache_index == 0) {
cache_index = -1;
break;
}
std::string cache_info;
std::getline(cache_file, cache_info);
one_info[n] = std::move(cache_info);
}

Expand Down Expand Up @@ -208,6 +210,7 @@ CPU::CPU() {
_numa_nodes,
_sockets,
_cores,
_blocked_cores,
_proc_type_table,
_cpu_mapping_table);
}
Expand Down Expand Up @@ -365,6 +368,7 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
int& _numa_nodes,
int& _sockets,
int& _cores,
int& _blocked_cores,
std::vector<std::vector<int>>& _proc_type_table,
std::vector<std::vector<int>>& _cpu_mapping_table) {
int n_group = 0;
Expand All @@ -377,6 +381,7 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
_cores = 0;
_numa_nodes = 0;
_sockets = 0;
_blocked_cores = 0;
_cpu_mapping_table.clear();
_proc_type_table.clear();
return;
Expand Down Expand Up @@ -488,7 +493,34 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
}

while (1) {
if ((endpos = system_info_table[n][2].find('-', pos)) != std::string::npos) {
if (system_info_table[n][2].size() == 0) {
if ((endpos = system_info_table[n][1].find('-', pos)) != std::string::npos) {
sub_str = system_info_table[n][1].substr(pos, endpos - pos);
core_1 = std::stoi(sub_str);
sub_str = system_info_table[n][1].substr(endpos + 1);
core_2 = std::stoi(sub_str);

if (core_2 - core_1 == 1) {
_cpu_mapping_table[n][CPU_MAP_PROCESSOR_ID] = n;
_cpu_mapping_table[n][CPU_MAP_CORE_ID] = _cores++;
_cpu_mapping_table[n][CPU_MAP_CORE_TYPE] = EFFICIENT_CORE_PROC;
_cpu_mapping_table[n][CPU_MAP_SOCKET_ID] = _sockets;
_cpu_mapping_table[n][CPU_MAP_NUMA_NODE_ID] = _cpu_mapping_table[n][CPU_MAP_SOCKET_ID];
_cpu_mapping_table[n][CPU_MAP_GROUP_ID] = CPU_BLOCKED;
_cpu_mapping_table[n][CPU_MAP_USED_FLAG] = CPU_BLOCKED;
_blocked_cores++;
} else {
for (int m = core_1; m <= core_2; m++) {
_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];
update_proc_map_info(m);
if (_processors == 0) {
return;
};
}
}
}
} else if ((endpos = system_info_table[n][2].find('-', pos)) != std::string::npos) {
sub_str = system_info_table[n][2].substr(pos, endpos - pos);
core_1 = std::stoi(sub_str);
sub_str = system_info_table[n][2].substr(endpos + 1);
Expand Down Expand Up @@ -521,6 +553,10 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
}
}
_sockets++;
if (_proc_type_table[0][ALL_PROC] == 0) {
_proc_type_table.erase(_proc_type_table.begin());
_sockets--;
}
}
}

Expand All @@ -540,6 +576,9 @@ void parse_cache_info_linux(const std::vector<std::vector<std::string>> system_i
_numa_nodes = node_info_table.size();
parse_node_info_linux(node_info_table, _numa_nodes, _sockets, _proc_type_table, _cpu_mapping_table);
}

_processors -= _blocked_cores;
_cores -= _blocked_cores;
};

void get_cpu_mapping_from_cores(const int _processors,
Expand Down
66 changes: 66 additions & 0 deletions src/inference/tests/unit/cpu_map_parser/cache_parser_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct LinuxCpuMapTestCase {
int _numa_nodes;
int _sockets;
int _cores;
int _blocked_cores;
std::vector<std::vector<int>> _proc_type_table;
std::vector<std::vector<int>> _cpu_mapping_table;
std::vector<std::vector<std::string>> system_info_table;
Expand All @@ -36,6 +37,7 @@ class LinuxCpuMapCacheParserTests : public ov::test::TestsCommon,
int test_numa_nodes = 0;
int test_sockets = 0;
int test_cores = 0;
int test_blocked_cores = 0;
std::vector<std::vector<int>> test_proc_type_table;
std::vector<std::vector<int>> test_cpu_mapping_table;

Expand All @@ -45,13 +47,15 @@ class LinuxCpuMapCacheParserTests : public ov::test::TestsCommon,
test_numa_nodes,
test_sockets,
test_cores,
test_blocked_cores,
test_proc_type_table,
test_cpu_mapping_table);

ASSERT_EQ(test_data._processors, test_processors);
ASSERT_EQ(test_data._numa_nodes, test_numa_nodes);
ASSERT_EQ(test_data._sockets, test_sockets);
ASSERT_EQ(test_data._cores, test_cores);
ASSERT_EQ(test_data._blocked_cores, test_blocked_cores);
ASSERT_EQ(test_data._proc_type_table, test_proc_type_table);
ASSERT_EQ(test_data._cpu_mapping_table, test_cpu_mapping_table);
}
Expand Down Expand Up @@ -82,6 +86,7 @@ LinuxCpuMapTestCase cache_2sockets_104cores_hyperthreading = {
2, // param[expected out]: total 2 numa nodes on this simulated platform
2, // param[expected out]: total 2 sockets on this simulated platform
104, // param[expected out]: total 104 CPU cores on this simulated platform
0, // param[expected out]: total 0 blocked cores on this simulated platform
{{208, 104, 0, 104, -1, -1},
{104, 52, 0, 52, 0, 0},
{104, 52, 0, 52, 1, 1}}, // param[expected out]: The proc_type_table of this simulated platform
Expand Down Expand Up @@ -304,6 +309,7 @@ LinuxCpuMapTestCase cache_1sockets_96cores = {
1,
1,
96,
0,
{{96, 0, 96, 0, 0, 0}},
{
{0, 0, 0, 0, EFFICIENT_CORE_PROC, 0, -1}, {1, 0, 0, 1, EFFICIENT_CORE_PROC, 0, -1},
Expand Down Expand Up @@ -390,6 +396,7 @@ LinuxCpuMapTestCase cache_2sockets_48cores_hyperthreading = {
2,
2,
48,
0,
{{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 1, HYPER_THREADING_PROC, 1, -1},
Expand Down Expand Up @@ -482,6 +489,7 @@ LinuxCpuMapTestCase cache_2sockets_48cores_hyperthreading_1 = {
4,
2,
48,
0,
{{96, 48, 0, 48, -1, -1},
{24, 12, 0, 12, 0, 0},
{24, 12, 0, 12, 1, 0},
Expand Down Expand Up @@ -578,6 +586,7 @@ LinuxCpuMapTestCase cache_2sockets_24cores_hyperthreading = {
2,
2,
24,
0,
{{48, 24, 0, 24, -1, -1}, {24, 12, 0, 12, 0, 0}, {24, 12, 0, 12, 1, 1}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 1, 1, 12, HYPER_THREADING_PROC, 12, -1},
Expand Down Expand Up @@ -663,6 +672,7 @@ LinuxCpuMapTestCase cache_2sockets_24cores_hyperthreading_1 = {
4,
2,
24,
0,
{{48, 24, 0, 24, -1, -1}, {12, 6, 0, 6, 0, 0}, {12, 6, 0, 6, 1, 0}, {12, 6, 0, 6, 2, 1}, {12, 6, 0, 6, 3, 1}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 2, 1, 12, HYPER_THREADING_PROC, 12, -1},
Expand Down Expand Up @@ -750,6 +760,7 @@ LinuxCpuMapTestCase cache_2sockets_48cores = {
2,
2,
48,
0,
{{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}},
{
{0, 0, 0, 0, MAIN_CORE_PROC, 0, -1}, {1, 0, 0, 1, MAIN_CORE_PROC, 1, -1},
Expand Down Expand Up @@ -802,6 +813,7 @@ LinuxCpuMapTestCase cache_2sockets_48cores_1 = {
2,
2,
48,
0,
{{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}},
{
{0, 0, 0, 0, MAIN_CORE_PROC, 0, -1}, {1, 0, 0, 1, MAIN_CORE_PROC, 1, -1},
Expand Down Expand Up @@ -854,6 +866,7 @@ LinuxCpuMapTestCase cache_2sockets_48cores_2 = {
4,
2,
48,
0,
{{48, 48, 0, 0, -1, -1}, {12, 12, 0, 0, 0, 0}, {12, 12, 0, 0, 1, 0}, {12, 12, 0, 0, 2, 1}, {12, 12, 0, 0, 3, 1}},
{
{0, 0, 0, 0, MAIN_CORE_PROC, 0, -1}, {1, 0, 0, 1, MAIN_CORE_PROC, 1, -1},
Expand Down Expand Up @@ -906,6 +919,7 @@ LinuxCpuMapTestCase cache_2sockets_20cores_hyperthreading = {
2,
2,
20,
0,
{{40, 20, 0, 20, -1, -1}, {20, 10, 0, 10, 0, 0}, {20, 10, 0, 10, 1, 1}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 1, HYPER_THREADING_PROC, 1, -1},
Expand Down Expand Up @@ -958,6 +972,7 @@ LinuxCpuMapTestCase cache_2sockets_20cores_hyperthreading_1 = {
2,
2,
20,
0,
{{40, 20, 0, 20, -1, -1}, {20, 10, 0, 10, 0, 0}, {20, 10, 0, 10, 1, 1}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 1, HYPER_THREADING_PROC, 1, -1},
Expand Down Expand Up @@ -1005,11 +1020,55 @@ LinuxCpuMapTestCase cache_2sockets_20cores_hyperthreading_1 = {
},
{},
};
LinuxCpuMapTestCase cache_1sockets_16cores_hyperthreading = {
20,
1,
1,
14,
2,
{{20, 6, 8, 6, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1},
{1, 0, 0, 1, HYPER_THREADING_PROC, 1, -1},
{2, 0, 0, 1, MAIN_CORE_PROC, 1, -1},
{3, 0, 0, 2, HYPER_THREADING_PROC, 2, -1},
{4, 0, 0, 2, MAIN_CORE_PROC, 2, -1},
{5, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
{6, 0, 0, 3, HYPER_THREADING_PROC, 3, -1},
{7, 0, 0, 3, MAIN_CORE_PROC, 3, -1},
{8, 0, 0, 4, HYPER_THREADING_PROC, 4, -1},
{9, 0, 0, 4, MAIN_CORE_PROC, 4, -1},
{10, 0, 0, 5, HYPER_THREADING_PROC, 5, -1},
{11, 0, 0, 5, MAIN_CORE_PROC, 5, -1},
{12, 0, 0, 6, EFFICIENT_CORE_PROC, 6, -1},
{13, 0, 0, 7, EFFICIENT_CORE_PROC, 6, -1},
{14, 0, 0, 8, EFFICIENT_CORE_PROC, 6, -1},
{15, 0, 0, 9, EFFICIENT_CORE_PROC, 6, -1},
{16, 0, 0, 10, EFFICIENT_CORE_PROC, 7, -1},
{17, 0, 0, 11, EFFICIENT_CORE_PROC, 7, -1},
{18, 0, 0, 12, EFFICIENT_CORE_PROC, 7, -1},
{19, 0, 0, 13, EFFICIENT_CORE_PROC, 7, -1},
{20, 1, 1, 14, EFFICIENT_CORE_PROC, CPU_BLOCKED, CPU_BLOCKED},
{21, 1, 1, 15, EFFICIENT_CORE_PROC, CPU_BLOCKED, CPU_BLOCKED},
},
{
{"0,5", "0,5", "0-19"}, {"1-2", "1-2", "0-19"}, {"1-2", "1-2", "0-19"}, {"3-4", "3-4", "0-19"},
{"3-4", "3-4", "0-19"}, {"0,5", "0,5", "0-19"}, {"6-7", "6-7", "0-19"}, {"6-7", "6-7", "0-19"},
{"8-9", "8-9", "0-19"}, {"8-9", "8-9", "0-19"}, {"10-11", "10-11", "0-19"}, {"10-11", "10-11", "0-19"},
{"12", "12-15", "0-19"}, {"13", "12-15", "0-19"}, {"14", "12-15", "0-19"}, {"15", "12-15", "0-19"},
{"16", "16-19", "0-19"}, {"17", "16-19", "0-19"}, {"18", "16-19", "0-19"}, {"19", "16-19", "0-19"},
{"20", "20-21", ""}, {"21", "20-21", ""},
},
{
{"0-21"},
},
};
LinuxCpuMapTestCase cache_1sockets_14cores_hyperthreading = {
20,
1,
1,
14,
0,
{{20, 6, 8, 6, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
Expand Down Expand Up @@ -1039,6 +1098,7 @@ LinuxCpuMapTestCase cache_1sockets_14cores_hyperthreading_1 = {
1,
1,
14,
0,
{{20, 6, 8, 6, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
Expand Down Expand Up @@ -1068,6 +1128,7 @@ LinuxCpuMapTestCase cache_1sockets_10cores_hyperthreading = {
1,
1,
10,
0,
{{12, 2, 8, 2, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1},
Expand Down Expand Up @@ -1104,6 +1165,7 @@ LinuxCpuMapTestCase cache_1sockets_8cores_hyperthreading = {
1,
1,
8,
0,
{{12, 4, 4, 4, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1},
Expand Down Expand Up @@ -1140,6 +1202,7 @@ LinuxCpuMapTestCase cache_1sockets_6cores_hyperthreading = {
1,
1,
6,
0,
{{12, 6, 0, 6, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1},
Expand Down Expand Up @@ -1176,6 +1239,7 @@ LinuxCpuMapTestCase cache_1sockets_4cores = {
1,
1,
4,
0,
{{4, 4, 0, 0, 0, 0}},
{
{0, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
Expand All @@ -1196,6 +1260,7 @@ LinuxCpuMapTestCase cache_VM_cache_0 = {
0,
0,
0,
0,
{},
{},
{
Expand Down Expand Up @@ -1229,6 +1294,7 @@ INSTANTIATE_TEST_SUITE_P(CPUMap,
cache_2sockets_48cores_2,
cache_2sockets_20cores_hyperthreading,
cache_2sockets_20cores_hyperthreading_1,
cache_1sockets_16cores_hyperthreading,
cache_1sockets_14cores_hyperthreading,
cache_1sockets_14cores_hyperthreading_1,
cache_1sockets_10cores_hyperthreading,
Expand Down
33 changes: 22 additions & 11 deletions src/inference/tests/unit/cpu_map_parser/parser_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,17 +1689,28 @@ WinCpuMapTestCase _1sockets_22cores_hyperthreading = {
2,
{{20, 6, 8, 6, 0, 0}},
{
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
{2, 0, 0, 1, EFFICIENT_CORE_PROC, 1, -1}, {3, 0, 0, 2, EFFICIENT_CORE_PROC, 1, -1},
{4, 0, 0, 3, EFFICIENT_CORE_PROC, 1, -1}, {5, 0, 0, 4, EFFICIENT_CORE_PROC, 1, -1},
{6, 0, 0, 5, EFFICIENT_CORE_PROC, 2, -1}, {7, 0, 0, 6, EFFICIENT_CORE_PROC, 2, -1},
{8, 0, 0, 7, EFFICIENT_CORE_PROC, 2, -1}, {9, 0, 0, 8, EFFICIENT_CORE_PROC, 2, -1},
{10, 0, 0, 9, HYPER_THREADING_PROC, 3, -1}, {11, 0, 0, 9, MAIN_CORE_PROC, 3, -1},
{12, 0, 0, 10, HYPER_THREADING_PROC, 4, -1}, {13, 0, 0, 10, MAIN_CORE_PROC, 4, -1},
{14, 0, 0, 11, HYPER_THREADING_PROC, 5, -1}, {15, 0, 0, 11, MAIN_CORE_PROC, 5, -1},
{16, 0, 0, 12, HYPER_THREADING_PROC, 6, -1}, {17, 0, 0, 12, MAIN_CORE_PROC, 6, -1},
{18, 0, 0, 13, HYPER_THREADING_PROC, 7, -1}, {19, 0, 0, 13, MAIN_CORE_PROC, 7, -1},
{20, 0, 0, 14, EFFICIENT_CORE_PROC, -100, -100}, {21, 0, 0, 15, EFFICIENT_CORE_PROC, -100, -100},
{0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1},
{1, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
{2, 0, 0, 1, EFFICIENT_CORE_PROC, 1, -1},
{3, 0, 0, 2, EFFICIENT_CORE_PROC, 1, -1},
{4, 0, 0, 3, EFFICIENT_CORE_PROC, 1, -1},
{5, 0, 0, 4, EFFICIENT_CORE_PROC, 1, -1},
{6, 0, 0, 5, EFFICIENT_CORE_PROC, 2, -1},
{7, 0, 0, 6, EFFICIENT_CORE_PROC, 2, -1},
{8, 0, 0, 7, EFFICIENT_CORE_PROC, 2, -1},
{9, 0, 0, 8, EFFICIENT_CORE_PROC, 2, -1},
{10, 0, 0, 9, HYPER_THREADING_PROC, 3, -1},
{11, 0, 0, 9, MAIN_CORE_PROC, 3, -1},
{12, 0, 0, 10, HYPER_THREADING_PROC, 4, -1},
{13, 0, 0, 10, MAIN_CORE_PROC, 4, -1},
{14, 0, 0, 11, HYPER_THREADING_PROC, 5, -1},
{15, 0, 0, 11, MAIN_CORE_PROC, 5, -1},
{16, 0, 0, 12, HYPER_THREADING_PROC, 6, -1},
{17, 0, 0, 12, MAIN_CORE_PROC, 6, -1},
{18, 0, 0, 13, HYPER_THREADING_PROC, 7, -1},
{19, 0, 0, 13, MAIN_CORE_PROC, 7, -1},
{20, 0, 0, 14, EFFICIENT_CORE_PROC, CPU_BLOCKED, CPU_BLOCKED},
{21, 0, 0, 15, EFFICIENT_CORE_PROC, CPU_BLOCKED, CPU_BLOCKED},
},
{"0300000030000000000000000000000000000000000000000000000000000100ffff3f0000000000000000000000000000000000300000000"
"10100000000000000000000000000000000000000000100030000000000000000000000000000000700000030000000000000000000000000"
Expand Down
Loading
Loading