Skip to content

Commit 911601d

Browse files
authored
[muxcable] Fix Redis Selectable Processing (sonic-net#173)
Selectable object can return multiple fields, however current code processes only the first field and wait till the next selectable is triggered. This PR consumes all fields that were returned by a selectable object. This results in reducing processing time from order of seconds to order of milliseconds. signed-off-by: Tamer Ahmed <[email protected]>
1 parent c4d4790 commit 911601d

File tree

1 file changed

+58
-53
lines changed

1 file changed

+58
-53
lines changed

sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py

+58-53
Original file line numberDiff line numberDiff line change
@@ -1054,66 +1054,71 @@ def task_worker(self):
10541054
namespace = redisSelectObj.getDbConnector().getNamespace()
10551055
asic_index = multi_asic.get_asic_index_from_namespace(namespace)
10561056

1057-
(port, op, fvp) = status_tbl[asic_index].pop()
1058-
if fvp:
1059-
# This check might be redundant, to check, the presence of this Port in keys
1060-
# in logical_port_list but keep for now for coherency
1061-
# also skip checking in logical_port_list inside sfp_util
1062-
if port not in y_cable_tbl_keys[asic_index]:
1063-
continue
1064-
1065-
fvp_dict = dict(fvp)
1066-
1067-
if "state" in fvp_dict:
1068-
# got a state change
1069-
new_status = fvp_dict["state"]
1070-
(status, fvs) = y_cable_tbl[asic_index].get(port)
1071-
if status is False:
1072-
helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format(
1073-
port, y_cable_tbl[asic_index]))
1057+
while True:
1058+
(port, op, fvp) = status_tbl[asic_index].pop()
1059+
if not port:
1060+
break
1061+
if fvp:
1062+
# This check might be redundant, to check, the presence of this Port in keys
1063+
# in logical_port_list but keep for now for coherency
1064+
# also skip checking in logical_port_list inside sfp_util
1065+
if port not in y_cable_tbl_keys[asic_index]:
10741066
continue
1075-
mux_port_dict = dict(fvs)
1076-
old_status = mux_port_dict.get("state")
1077-
read_side = mux_port_dict.get("read_side")
1078-
# Now whatever is the state requested, toggle the mux appropriately
1079-
active_side = update_tor_active_side(read_side, new_status, port)
1080-
if active_side == -1:
1081-
helper_logger.log_warning("ERR: Got a change event for toggle but could not toggle the mux-direction for port {} state from {} to {}, writing unknown".format(
1082-
port, old_status, new_status))
1083-
new_status = 'unknown'
1084-
1085-
fvs_updated = swsscommon.FieldValuePairs([('state', new_status),
1086-
('read_side',
1087-
read_side),
1088-
('active_side', str(active_side))])
1089-
y_cable_tbl[asic_index].set(port, fvs_updated)
1090-
helper_logger.log_info("Got a change event for toggle the mux-direction active side for port {} state from {} to {}".format(
1091-
port, old_status, new_status))
1092-
else:
1093-
helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format(
1094-
port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME))
1095-
1096-
(port_m, op_m, fvp_m) = mux_cable_command_tbl[asic_index].pop()
1097-
if fvp_m:
1098-
1099-
if port_m not in y_cable_tbl_keys[asic_index]:
1100-
continue
1101-
1102-
fvp_dict = dict(fvp_m)
11031067

1104-
if "command" in fvp_dict:
1105-
# check if xcvrd got a probe command
1106-
probe_identifier = fvp_dict["command"]
1068+
fvp_dict = dict(fvp)
11071069

1108-
if probe_identifier == "probe":
1109-
(status, fv) = y_cable_tbl[asic_index].get(port_m)
1070+
if "state" in fvp_dict:
1071+
# got a state change
1072+
new_status = fvp_dict["state"]
1073+
(status, fvs) = y_cable_tbl[asic_index].get(port)
11101074
if status is False:
11111075
helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format(
1112-
port_m, y_cable_tbl[asic_index]))
1076+
port, y_cable_tbl[asic_index]))
11131077
continue
1114-
mux_port_dict = dict(fv)
1078+
mux_port_dict = dict(fvs)
1079+
old_status = mux_port_dict.get("state")
11151080
read_side = mux_port_dict.get("read_side")
1116-
update_appdb_port_mux_cable_response_table(port_m, asic_index, appl_db, int(read_side))
1081+
# Now whatever is the state requested, toggle the mux appropriately
1082+
active_side = update_tor_active_side(read_side, new_status, port)
1083+
if active_side == -1:
1084+
helper_logger.log_warning("ERR: Got a change event for toggle but could not toggle the mux-direction for port {} state from {} to {}, writing unknown".format(
1085+
port, old_status, new_status))
1086+
new_status = 'unknown'
1087+
1088+
fvs_updated = swsscommon.FieldValuePairs([('state', new_status),
1089+
('read_side', read_side),
1090+
('active_side', str(active_side))])
1091+
y_cable_tbl[asic_index].set(port, fvs_updated)
1092+
helper_logger.log_info("Got a change event for toggle the mux-direction active side for port {} state from {} to {}".format(
1093+
port, old_status, new_status))
1094+
else:
1095+
helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format(
1096+
port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME))
1097+
1098+
while True:
1099+
(port_m, op_m, fvp_m) = mux_cable_command_tbl[asic_index].pop()
1100+
if not port_m:
1101+
break
1102+
if fvp_m:
1103+
1104+
if port_m not in y_cable_tbl_keys[asic_index]:
1105+
continue
1106+
1107+
fvp_dict = dict(fvp_m)
1108+
1109+
if "command" in fvp_dict:
1110+
# check if xcvrd got a probe command
1111+
probe_identifier = fvp_dict["command"]
1112+
1113+
if probe_identifier == "probe":
1114+
(status, fv) = y_cable_tbl[asic_index].get(port_m)
1115+
if status is False:
1116+
helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format(
1117+
port_m, y_cable_tbl[asic_index]))
1118+
continue
1119+
mux_port_dict = dict(fv)
1120+
read_side = mux_port_dict.get("read_side")
1121+
update_appdb_port_mux_cable_response_table(port_m, asic_index, appl_db, int(read_side))
11171122

11181123
def task_run(self):
11191124
self.task_thread = threading.Thread(target=self.task_worker)

0 commit comments

Comments
 (0)