Skip to content

Commit

Permalink
[portsorch]: Add asymmetric PFC support (sonic-net#460)
Browse files Browse the repository at this point in the history
* [portsorch]: Add asymmetric PFC support

* Implement asymmetric PFC feature
* Implement unit test on top of virtual switch

Signed-off-by: Volodymyr Samotiy <volodymyrs@mellanox.com>

* [portsorch]: Add asymmetric PFC support

* Fix review comments

Signed-off-by: Volodymyr Samotiy <volodymyrs@mellanox.com>

* [portsorch]: Add asymmetric PFC support

* Fix review comments

Signed-off-by: Volodymyr Samotiy <volodymyrs@mellanox.com>
  • Loading branch information
Volodymyr Samotiy authored and sihuihan88 committed Aug 22, 2018
1 parent 4c97271 commit 7e27af9
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 66 deletions.
22 changes: 6 additions & 16 deletions orchagent/countercheckorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ void CounterCheckOrch::mcCounterCheck()
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;

for (auto& i : m_mcCountersMap)
{
auto oid = i.first;
auto mcCounters = i.second;
uint8_t pfcMask = 0;

Port port;
if (!gPortsOrch->getPort(oid, port))
Expand All @@ -69,15 +67,12 @@ void CounterCheckOrch::mcCounterCheck()

auto newMcCounters = getQueueMcCounters(port);

sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s: %d", port.m_alias.c_str(), status);
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
continue;
}

uint8_t pfcMask = attr.value.u8;

for (size_t prio = 0; prio != mcCounters.size(); prio++)
{
bool isLossy = ((1 << prio) & pfcMask) == 0;
Expand All @@ -104,14 +99,12 @@ void CounterCheckOrch::pfcFrameCounterCheck()
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;

for (auto& i : m_pfcFrameCountersMap)
{
auto oid = i.first;
auto counters = i.second;
auto newCounters = getPfcFrameCounters(oid);
uint8_t pfcMask = 0;

Port port;
if (!gPortsOrch->getPort(oid, port))
Expand All @@ -120,15 +113,12 @@ void CounterCheckOrch::pfcFrameCounterCheck()
continue;
}

sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s: %d", port.m_alias.c_str(), status);
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
continue;
}

uint8_t pfcMask = attr.value.u8;

for (size_t prio = 0; prio != counters.size(); prio++)
{
bool isLossy = ((1 << prio) & pfcMask) == 0;
Expand Down
36 changes: 12 additions & 24 deletions orchagent/pfcactionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,49 +321,37 @@ PfcWdLossyHandler::PfcWdLossyHandler(sai_object_id_t port, sai_object_id_t queue
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;
uint8_t pfcMask = 0;

sai_status_t status = sai_port_api->get_port_attribute(port, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(port, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx: %d", port, status);
SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx", port);
}

uint8_t pfcMask = attr.value.u8;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;
attr.value.u8 = static_cast<uint8_t>(pfcMask & ~(1 << queueId));
pfcMask = static_cast<uint8_t>(pfcMask & (1 << queueId));

status = sai_port_api->set_port_attribute(port, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->setPortPfc(port, pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx: %d", port, status);
SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%lx", port);
}
}

PfcWdLossyHandler::~PfcWdLossyHandler(void)
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;
uint8_t pfcMask = 0;

sai_status_t status = sai_port_api->get_port_attribute(getPort(), 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(getPort(), &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx: %d", getPort(), status);
return;
SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx", getPort());
}

uint8_t pfcMask = attr.value.u8;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;
attr.value.u8 = static_cast<uint8_t>(pfcMask | (1 << getQueueId()));
pfcMask = static_cast<uint8_t>(pfcMask | (1 << getQueueId()));

status = sai_port_api->set_port_attribute(getPort(), &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->setPortPfc(getPort(), pfcMask))
{
SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%lx: %d", getPort(), status);
return;
SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%lx", getPort());
}
}

Expand Down
28 changes: 10 additions & 18 deletions orchagent/pfcwdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,24 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::enableBigRedSwitchMode()
m_bigRedSwitchFlag = true;
// Write to database that each queue enables BIG_RED_SWITCH
auto allPorts = gPortsOrch->getAllPorts();
sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;

for (auto &it: allPorts)
{
Port port = it.second;
uint8_t pfcMask = 0;

if (port.m_type != Port::PHY)
{
SWSS_LOG_INFO("Skip non-phy port %s", port.m_alias.c_str());
continue;
}

// use portorch api to get lossless tc in future.
sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s: %d", port.m_alias.c_str(), status);
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
return;
}

uint8_t pfcMask = attr.value.u8;
for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++)
{
sai_object_id_t queueId = port.m_queue_ids[i];
Expand Down Expand Up @@ -403,21 +399,20 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::enableBigRedSwitchMode()
for (auto & it: allPorts)
{
Port port = it.second;
uint8_t pfcMask = 0;

if (port.m_type != Port::PHY)
{
SWSS_LOG_INFO("Skip non-phy port %s", port.m_alias.c_str());
continue;
}

// use portorch api to get lossless tc in future after asym PFC is available.
sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s: %d", port.m_alias.c_str(), status);
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
return;
}

uint8_t pfcMask = attr.value.u8;
for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++)
{
if ((pfcMask & (1 << i)) == 0)
Expand Down Expand Up @@ -456,18 +451,15 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;
uint8_t pfcMask = 0;

sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s: %d", port.m_alias.c_str(), status);
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
return;
}

set<uint8_t> losslessTc;
uint8_t pfcMask = attr.value.u8;
for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++)
{
if ((pfcMask & (1 << i)) == 0)
Expand Down
2 changes: 2 additions & 0 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Port
std::set<std::string> m_members;
std::vector<sai_object_id_t> m_queue_ids;
std::vector<sai_object_id_t> m_priority_group_ids;
sai_port_priority_flow_control_mode_t m_pfc_asym = SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED;
uint8_t m_pfc_bitmask = 0;
};

}
Expand Down
144 changes: 144 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ static map<string, sai_port_fec_mode_t> fec_mode_map =
{ "fc", SAI_PORT_FEC_MODE_FC }
};

static map<string, sai_port_priority_flow_control_mode_t> pfc_asym_map =
{
{ "on", SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE },
{ "off", SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED }
};

const vector<sai_port_stat_t> portStatIds =
{
SAI_PORT_STAT_IF_IN_OCTETS,
Expand Down Expand Up @@ -515,6 +521,125 @@ bool PortsOrch::setPortFec(sai_object_id_t id, sai_port_fec_mode_t mode)
return true;
}

bool PortsOrch::getPortPfc(sai_object_id_t portId, uint8_t *pfc_bitmask)
{
SWSS_LOG_ENTER();

Port p;

if (!getPort(portId, p))
{
SWSS_LOG_ERROR("Failed to get port object for port id 0x%lx", portId);
return false;
}

*pfc_bitmask = p.m_pfc_bitmask;

return true;
}

bool PortsOrch::setPortPfc(sai_object_id_t portId, uint8_t pfc_bitmask)
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
Port p;

if (!getPort(portId, p))
{
SWSS_LOG_ERROR("Failed to get port object for port id 0x%lx", portId);
return false;
}

if (p.m_pfc_asym == SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED)
{
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL;
}
else if (p.m_pfc_asym == SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE)
{
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX;
}
else
{
SWSS_LOG_ERROR("Incorrect asymmetric PFC mode: %u", p.m_pfc_asym);
return false;
}

attr.value.u8 = pfc_bitmask;

sai_status_t status = sai_port_api->set_port_attribute(portId, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set PFC 0x%x to port id 0x%lx (rc:%d)", attr.value.u8, portId, status);
return false;
}

if (p.m_pfc_bitmask != pfc_bitmask)
{
p.m_pfc_bitmask = pfc_bitmask;
m_portList[p.m_alias] = p;
}

return true;
}

bool PortsOrch::setPortPfcAsym(Port &port, string pfc_asym)
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
uint8_t pfc = 0;

if (!getPortPfc(port.m_port_id, &pfc))
{
return false;
}

try
{
port.m_pfc_asym = pfc_asym_map.at(pfc_asym);
}
catch (...)
{
SWSS_LOG_ERROR("Incorrect asymmetric PFC mode: %s", pfc_asym.c_str());
return false;
}

m_portList[port.m_alias] = port;

attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE;
attr.value.s32 = (int32_t) port.m_pfc_asym;

sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set PFC mode %d to port id 0x%lx (rc:%d)", port.m_pfc_asym, port.m_port_id, status);
return false;
}

if (!setPortPfc(port.m_port_id, pfc))
{
return false;
}

if (port.m_pfc_asym == SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE)
{
attr.id = SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX;
attr.value.u8 = static_cast<uint8_t>(0xff);

sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set RX PFC 0x%x to port id 0x%lx (rc:%d)", attr.value.u8, port.m_port_id, status);
return false;
}
}

SWSS_LOG_INFO("Set asymmetric PFC %s to port id 0x%lx", pfc_asym.c_str(), port.m_port_id);

return true;
}

bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_object_id_t &group_member_oid, acl_stage_type_t acl_stage)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -1282,6 +1407,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
set<int> lane_set;
string admin_status;
string fec_mode;
string pfc_asym;
uint32_t mtu = 0;
uint32_t speed = 0;
int an = -1;
Expand Down Expand Up @@ -1326,6 +1452,10 @@ void PortsOrch::doPortTask(Consumer &consumer)
fec_mode = fvValue(i);
}

/* Set port asymmetric PFC */
if (fvField(i) == "pfc_asym")
pfc_asym = fvValue(i);

/* Set autoneg and ignore the port speed setting */
if (fvField(i) == "autoneg")
{
Expand Down Expand Up @@ -1594,6 +1724,20 @@ void PortsOrch::doPortTask(Consumer &consumer)
SWSS_LOG_ERROR("Unknown fec mode %s", fec_mode.c_str());
}
}

if (pfc_asym != "")
{
if (setPortPfcAsym(p, pfc_asym))
{
SWSS_LOG_NOTICE("Set port %s asymmetric PFC to %s", alias.c_str(), pfc_asym.c_str());
}
else
{
SWSS_LOG_ERROR("Failed to set port %s asymmetric PFC to %s", alias.c_str(), pfc_asym.c_str());
it++;
continue;
}
}
}
}
else
Expand Down
Loading

0 comments on commit 7e27af9

Please sign in to comment.