From 18632a3e84de380ad29a671a6496018cfd1cd540 Mon Sep 17 00:00:00 2001 From: Dante Su Date: Mon, 23 May 2022 12:22:49 +0000 Subject: [PATCH] optimize port state refresh logic Signed-off-by: Dante Su --- orchagent/portsorch.cpp | 52 ++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 0b8d9a0549..dfe75e5069 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -6005,36 +6005,17 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status) if (port.m_type == Port::PHY) { updateDbPortOperStatus(port, status); - if (port.m_admin_state_up && port.m_autoneg > 0) + + /* Refresh the port states and reschedule the poller tasks */ + if (port.m_autoneg > 0) { - if (status == SAI_PORT_OPER_STATUS_UP) - { - /* Refresh AN port states */ - refreshPortStateAutoNeg(port); - /* Stop port state polling for AN */ - updatePortStatePoll(port, PORT_STATE_POLL_AN, false); - } - else - { - /* Restart autoneg state polling upon link down event */ - m_portStateTable.hdel(port.m_alias, "rmt_adv_speeds"); - updatePortStatePoll(port, PORT_STATE_POLL_AN, true); - } + refreshPortStateAutoNeg(port); + updatePortStatePoll(port, PORT_STATE_POLL_AN, !(status == SAI_PORT_OPER_STATUS_UP)); } - if (port.m_admin_state_up && port.m_link_training > 0) + if (port.m_link_training > 0) { - /* Refresh LT port states for both link up and down */ refreshPortStateLinkTraining(port); - if (status == SAI_PORT_OPER_STATUS_UP) - { - /* Stop port state polling for LT */ - updatePortStatePoll(port, PORT_STATE_POLL_LT, false); - } - else - { - /* Restart port state polling upon link down event */ - updatePortStatePoll(port, PORT_STATE_POLL_LT, true); - } + updatePortStatePoll(port, PORT_STATE_POLL_LT, !(status == SAI_PORT_OPER_STATUS_UP)); } } port.m_oper_status = status; @@ -7231,17 +7212,18 @@ void PortsOrch::refreshPortStateAutoNeg(const Port &port) return; } - string adv_speeds; + string adv_speeds = "N/A"; - if (getPortAdvSpeeds(port, true, adv_speeds)) - { - m_portStateTable.hset(port.m_alias, "rmt_adv_speeds", adv_speeds); - } - else + if (port.m_admin_state_up) { - m_portStateTable.hset(port.m_alias, "rmt_adv_speeds", "N/A"); - updatePortStatePoll(port, PORT_STATE_POLL_AN, false); + if (!getPortAdvSpeeds(port, true, adv_speeds)) + { + adv_speeds = "N/A"; + updatePortStatePoll(port, PORT_STATE_POLL_AN, false); + } } + + m_portStateTable.hset(port.m_alias, "rmt_adv_speeds", adv_speeds); } /* Refresh the per-port Link-Training operational states */ @@ -7256,7 +7238,7 @@ void PortsOrch::refreshPortStateLinkTraining(const Port &port) string status = "off"; - if ((port.m_link_training > 0) && (port.m_cap_lt > 0)) + if (port.m_admin_state_up && port.m_link_training > 0 && port.m_cap_lt > 0) { sai_port_link_training_rx_status_t rx_status; sai_port_link_training_failure_status_t failure;