Skip to content

Commit c96f2d7

Browse files
committed
Factor out function for auto-discovery parsing of host pipes
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
1 parent 633761c commit c96f2d7

File tree

1 file changed

+64
-53
lines changed

1 file changed

+64
-53
lines changed

src/acl_auto_configure.cpp

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,69 @@ read_global_mem_defs(const std::string &config_str,
372372
return result;
373373
}
374374

375+
static bool
376+
read_hostpipe_infos(const std::string &config_str,
377+
std::string::size_type &curr_pos,
378+
std::vector<acl_hostpipe_info_t> &hostpipe_infos,
379+
std::vector<int> &counters) noexcept {
380+
auto num_hostpipes = 0U;
381+
bool result =
382+
read_uint_counters(config_str, curr_pos, num_hostpipes, counters);
383+
384+
// read total number of fields in hostpipes
385+
int total_fields_hostpipes = 0;
386+
if (result) {
387+
result = read_int_counters(config_str, curr_pos, total_fields_hostpipes,
388+
counters);
389+
}
390+
391+
for (unsigned i = 0; result && (i < num_hostpipes); i++) {
392+
counters.emplace_back(total_fields_hostpipes);
393+
std::string name;
394+
395+
auto hostpipe_is_host_to_dev = 0U;
396+
auto hostpipe_is_dev_to_host = 0U;
397+
auto hostpipe_width = 0U;
398+
auto hostpipe_max_buffer_depth = 0U;
399+
result =
400+
result && read_string_counters(config_str, curr_pos, name, counters) &&
401+
read_uint_counters(config_str, curr_pos, hostpipe_is_host_to_dev,
402+
counters) &&
403+
read_uint_counters(config_str, curr_pos, hostpipe_is_dev_to_host,
404+
counters) &&
405+
read_uint_counters(config_str, curr_pos, hostpipe_width, counters) &&
406+
read_uint_counters(config_str, curr_pos, hostpipe_max_buffer_depth,
407+
counters);
408+
// is_host_to_dev and is_dev_to_host are exclusive because of the enum
409+
// Type
410+
acl_hostpipe_info_t acl_hostpipe_info;
411+
acl_hostpipe_info.name = name;
412+
acl_hostpipe_info.is_host_to_dev = hostpipe_is_host_to_dev;
413+
acl_hostpipe_info.is_dev_to_host = hostpipe_is_dev_to_host;
414+
acl_hostpipe_info.data_width = hostpipe_width;
415+
acl_hostpipe_info.max_buffer_depth = hostpipe_max_buffer_depth;
416+
hostpipe_infos.push_back(acl_hostpipe_info);
417+
418+
/*****************************************************************
419+
Since the introduction of autodiscovery forwards-compatibility,
420+
new entries for the 'hostpipe' section start here.
421+
****************************************************************/
422+
423+
// forward compatibility: bypassing remaining fields at the end of
424+
// hostpipes
425+
while (result && counters.size() > 0 &&
426+
counters.back() > 0) { // total_fields_hostpipes>0
427+
std::string tmp;
428+
result =
429+
result && read_string_counters(config_str, curr_pos, tmp, counters);
430+
check_section_counters(counters);
431+
}
432+
counters.pop_back(); // removing total_fields_hostpipes
433+
}
434+
435+
return result;
436+
}
437+
375438
static bool read_device_global_mem_defs(
376439
const std::string &config_str, std::string::size_type &curr_pos,
377440
std::unordered_map<std::string, acl_device_global_mem_def_t>
@@ -913,60 +976,8 @@ bool acl_load_device_def_from_str(const std::string &config_str,
913976

914977
// Set up hostpipe information
915978
if (result) {
916-
auto num_hostpipes = 0U;
917-
result = read_uint_counters(config_str, curr_pos, num_hostpipes, counters);
918-
919-
// read total number of fields in hostpipes
920-
int total_fields_hostpipes = 0;
921-
if (result) {
922-
result = read_int_counters(config_str, curr_pos, total_fields_hostpipes,
979+
result = read_hostpipe_infos(config_str, curr_pos, devdef.acl_hostpipe_info,
923980
counters);
924-
}
925-
926-
for (unsigned i = 0; result && (i < num_hostpipes); i++) {
927-
counters.emplace_back(total_fields_hostpipes);
928-
std::string name;
929-
930-
auto hostpipe_is_host_to_dev = 0U;
931-
auto hostpipe_is_dev_to_host = 0U;
932-
auto hostpipe_width = 0U;
933-
auto hostpipe_max_buffer_depth = 0U;
934-
result =
935-
result &&
936-
read_string_counters(config_str, curr_pos, name, counters) &&
937-
read_uint_counters(config_str, curr_pos, hostpipe_is_host_to_dev,
938-
counters) &&
939-
read_uint_counters(config_str, curr_pos, hostpipe_is_dev_to_host,
940-
counters) &&
941-
read_uint_counters(config_str, curr_pos, hostpipe_width, counters) &&
942-
read_uint_counters(config_str, curr_pos, hostpipe_max_buffer_depth,
943-
counters);
944-
// is_host_to_dev and is_dev_to_host are exclusive because of the enum
945-
// Type
946-
acl_hostpipe_info_t acl_hostpipe_info;
947-
acl_hostpipe_info.name = name;
948-
acl_hostpipe_info.is_host_to_dev = hostpipe_is_host_to_dev;
949-
acl_hostpipe_info.is_dev_to_host = hostpipe_is_dev_to_host;
950-
acl_hostpipe_info.data_width = hostpipe_width;
951-
acl_hostpipe_info.max_buffer_depth = hostpipe_max_buffer_depth;
952-
devdef.acl_hostpipe_info.push_back(acl_hostpipe_info);
953-
954-
/*****************************************************************
955-
Since the introduction of autodiscovery forwards-compatibility,
956-
new entries for the 'hostpipe' section start here.
957-
****************************************************************/
958-
959-
// forward compatibility: bypassing remaining fields at the end of
960-
// hostpipes
961-
while (result && counters.size() > 0 &&
962-
counters.back() > 0) { // total_fields_hostpipes>0
963-
std::string tmp;
964-
result =
965-
result && read_string_counters(config_str, curr_pos, tmp, counters);
966-
check_section_counters(counters);
967-
}
968-
counters.pop_back(); // removing total_fields_hostpipes
969-
}
970981
}
971982

972983
/*****************************************************************

0 commit comments

Comments
 (0)