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

Update orchagent to support new field pfcwd_sw_enable #2171

Merged
merged 17 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
155 changes: 88 additions & 67 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using namespace swss;
BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *applDb, string pg_lookup_file, const vector<string> &tableNames) :
Orch(cfgDb, tableNames),
m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME),
m_cfgPortQosMapTable(cfgDb, CFG_PORT_QOS_MAP_TABLE_NAME),
m_cfgCableLenTable(cfgDb, CFG_PORT_CABLE_LEN_TABLE_NAME),
m_cfgBufferProfileTable(cfgDb, CFG_BUFFER_PROFILE_TABLE_NAME),
m_cfgBufferPgTable(cfgDb, CFG_BUFFER_PG_TABLE_NAME),
Expand Down Expand Up @@ -133,9 +134,8 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
}
}
*/
task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up, const string& pfc_enable)
{
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
string cable;
string speed;

Expand All @@ -153,94 +153,99 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
}

speed = m_speedLookup[port];

string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + LOSSLESS_PGS;
// key format is pg_lossless_<speed>_<cable>_profile
string buffer_profile_key = "pg_lossless_" + speed + "_" + cable + "_profile";
string profile_ref = buffer_profile_key;

vector<string> lossless_pgs = tokenize(pfc_enable, ',');
for (auto lossless_pg : lossless_pgs)
{
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + lossless_pg;

m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);
m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);

if (!admin_up && m_platform == "mellanox")
{
// Remove the entry in BUFFER_PG table if any
if (!fvVectorPg.empty())
if (!admin_up && m_platform == "mellanox")
neethajohn marked this conversation as resolved.
Show resolved Hide resolved
{
for (auto &prop : fvVectorPg)
// Remove the entry in BUFFER_PG table if any
if (!fvVectorPg.empty())
{
if (fvField(prop) == "profile")
for (auto &prop : fvVectorPg)
{
if (fvValue(prop) == profile_ref)
{
SWSS_LOG_NOTICE("Removing PG %s from port %s which is administrative down", buffer_pg_key.c_str(), port.c_str());
m_cfgBufferPgTable.del(buffer_pg_key);
}
else
if (fvField(prop) == "profile")
{
SWSS_LOG_NOTICE("Not default profile %s is configured on PG %s, won't reclaim buffer", fvValue(prop).c_str(), buffer_pg_key.c_str());
if (fvValue(prop) == profile_ref)
{
SWSS_LOG_NOTICE("Removing PG %s from port %s which is administrative down", buffer_pg_key.c_str(), port.c_str());
m_cfgBufferPgTable.del(buffer_pg_key);
}
else
{
SWSS_LOG_NOTICE("Not default profile %s is configured on PG %s, won't reclaim buffer", fvValue(prop).c_str(), buffer_pg_key.c_str());
}
}
}
}
}

return task_process_status::task_success;
}

if (m_pgProfileLookup.count(speed) == 0 || m_pgProfileLookup[speed].count(cable) == 0)
{
SWSS_LOG_ERROR("Unable to create/update PG profile for port %s. No PG profile configured for speed %s and cable length %s",
port.c_str(), speed.c_str(), cable.c_str());
return task_process_status::task_invalid_entry;
}

// check if profile already exists - if yes - skip creation
m_cfgBufferProfileTable.get(buffer_profile_key, fvVectorProfile);
// Create record in BUFFER_PROFILE table
if (fvVectorProfile.size() == 0)
{
SWSS_LOG_NOTICE("Creating new profile '%s'", buffer_profile_key.c_str());
continue;
}

string mode = getPgPoolMode();
if (mode.empty())
if (m_pgProfileLookup.count(speed) == 0 || m_pgProfileLookup[speed].count(cable) == 0)
{
// this should never happen if switch initialized properly
SWSS_LOG_INFO("PG lossless pool is not yet created");
return task_process_status::task_need_retry;
SWSS_LOG_ERROR("Unable to create/update PG profile for port %s. No PG profile configured for speed %s and cable length %s",
port.c_str(), speed.c_str(), cable.c_str());
return task_process_status::task_invalid_entry;
}

// profile threshold field name
mode += "_th";
// check if profile already exists - if yes - skip creation
m_cfgBufferProfileTable.get(buffer_profile_key, fvVectorProfile);
// Create record in BUFFER_PROFILE table
if (fvVectorProfile.size() == 0)
{
SWSS_LOG_NOTICE("Creating new profile '%s'", buffer_profile_key.c_str());

string mode = getPgPoolMode();
if (mode.empty())
{
// this should never happen if switch initialized properly
SWSS_LOG_INFO("PG lossless pool is not yet created");
return task_process_status::task_need_retry;
}

// profile threshold field name
mode += "_th";

fvVectorProfile.push_back(make_pair("pool", INGRESS_LOSSLESS_PG_POOL_NAME));
fvVectorProfile.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
if (m_pgProfileLookup[speed][cable].xon_offset.length() > 0) {
fvVectorProfile.push_back(make_pair("xon_offset",
m_pgProfileLookup[speed][cable].xon_offset));
fvVectorProfile.push_back(make_pair("pool", INGRESS_LOSSLESS_PG_POOL_NAME));
fvVectorProfile.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
if (m_pgProfileLookup[speed][cable].xon_offset.length() > 0) {
fvVectorProfile.push_back(make_pair("xon_offset",
m_pgProfileLookup[speed][cable].xon_offset));
}
fvVectorProfile.push_back(make_pair("xoff", m_pgProfileLookup[speed][cable].xoff));
fvVectorProfile.push_back(make_pair("size", m_pgProfileLookup[speed][cable].size));
fvVectorProfile.push_back(make_pair(mode, m_pgProfileLookup[speed][cable].threshold));
m_cfgBufferProfileTable.set(buffer_profile_key, fvVectorProfile);
}
else
{
SWSS_LOG_NOTICE("Reusing existing profile '%s'", buffer_profile_key.c_str());
}
fvVectorProfile.push_back(make_pair("xoff", m_pgProfileLookup[speed][cable].xoff));
fvVectorProfile.push_back(make_pair("size", m_pgProfileLookup[speed][cable].size));
fvVectorProfile.push_back(make_pair(mode, m_pgProfileLookup[speed][cable].threshold));
m_cfgBufferProfileTable.set(buffer_profile_key, fvVectorProfile);
}
else
{
SWSS_LOG_NOTICE("Reusing existing profile '%s'", buffer_profile_key.c_str());
}

/* Check if PG Mapping is already then log message and return. */
for (auto& prop : fvVectorPg)
{
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
/* Check if PG Mapping is already then log message and return. */
for (auto& prop : fvVectorPg)
neethajohn marked this conversation as resolved.
Show resolved Hide resolved
{
SWSS_LOG_NOTICE("PG to Buffer Profile Mapping %s already present", buffer_pg_key.c_str());
return task_process_status::task_success;
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
{
SWSS_LOG_NOTICE("PG to Buffer Profile Mapping %s already present", buffer_pg_key.c_str());
continue;
}
}
}

fvVectorPg.clear();
fvVectorPg.clear();

fvVectorPg.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
fvVectorPg.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
}
return task_process_status::task_success;
}

Expand Down Expand Up @@ -346,6 +351,21 @@ void BufferMgr::doBufferMetaTask(Consumer &consumer)
}
}

/*
Read pfc_enable entry from PORT_QOS_MAP to decide on which queue to
apply lossless PG.
Return the hardcoded value '3-4' if failed to get that value
*/
string BufferMgr::getPfcEnableQueuesForPort(std::string port)
{
string pfc_enable;
if (!m_cfgPortQosMapTable.hget(port, "pfc_enable", pfc_enable))
{
return LOSSLESS_PGS;
}
return pfc_enable;
}

void BufferMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -438,7 +458,8 @@ void BufferMgr::doTask(Consumer &consumer)
if (m_speedLookup.count(port) != 0)
{
// create/update profile for port
task_status = doSpeedUpdateTask(port, admin_up);
string lossless_pgs = getPfcEnableQueuesForPort(port);
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
task_status = doSpeedUpdateTask(port, admin_up, lossless_pgs);
}

if (task_status != task_process_status::task_success)
Expand Down
4 changes: 3 additions & 1 deletion cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BufferMgr : public Orch
Table m_cfgBufferProfileTable;
Table m_cfgBufferPgTable;
Table m_cfgLosslessPgPoolTable;
Table m_cfgPortQosMapTable;

ProducerStateTable m_applBufferProfileTable;
ProducerStateTable m_applBufferPgTable;
Expand All @@ -60,13 +61,14 @@ class BufferMgr : public Orch
std::string getPgPoolMode();
void readPgProfileLookupFile(std::string);
task_process_status doCableTask(std::string port, std::string cable_length);
task_process_status doSpeedUpdateTask(std::string port, bool admin_up);
task_process_status doSpeedUpdateTask(std::string port, bool admin_up, const std::string &pfc_enable);
void doBufferTableTask(Consumer &consumer, ProducerStateTable &applTable);

void transformSeperator(std::string &name);

void doTask(Consumer &consumer);
void doBufferMetaTask(Consumer &consumer);
std::string getPfcEnableQueuesForPort(std::string port);
};

}
Expand Down
10 changes: 5 additions & 5 deletions orchagent/pfcwdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::enableBigRedSwitchMode()
continue;
}

if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
if (!gPortsOrch->getPortPfcWatchdogStatus(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
SWSS_LOG_ERROR("Failed to get PFC watchdog mask on port %s", port.m_alias.c_str());
return;
}

Expand Down Expand Up @@ -443,9 +443,9 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::enableBigRedSwitchMode()
continue;
}

if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
if (!gPortsOrch->getPortPfcWatchdogStatus(port.m_port_id, &pfcMask))
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
SWSS_LOG_ERROR("Failed to get PFC watchdog mask on port %s", port.m_alias.c_str());
return;
}

Expand Down Expand Up @@ -489,7 +489,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,

uint8_t pfcMask = 0;

if (!gPortsOrch->getPortPfc(port.m_port_id, &pfcMask))
if (!gPortsOrch->getPortPfcWatchdogStatus(port.m_port_id, &pfcMask))
neethajohn marked this conversation as resolved.
Show resolved Hide resolved
{
SWSS_LOG_ERROR("Failed to get PFC mask on port %s", port.m_alias.c_str());
return false;
Expand Down
3 changes: 2 additions & 1 deletion orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class Port
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;
uint8_t m_pfc_bitmask = 0; // PFC enable bit mask
uint8_t m_pfcwd_sw_bitmask = 0; // PFC software watchdog enable
uint16_t m_tpid = DEFAULT_TPID;
uint32_t m_nat_zone_id = 0;
uint32_t m_vnid = VNID_NONE;
Expand Down
37 changes: 37 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,43 @@ bool PortsOrch::setPortPfc(sai_object_id_t portId, uint8_t pfc_bitmask)
return true;
}

bool PortsOrch::setPortPfcWatchdogStatus(sai_object_id_t portId, uint8_t pfcwd_bitmask)
{
SWSS_LOG_ENTER();

Port p;

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

p.m_pfcwd_sw_bitmask = pfcwd_bitmask;

m_portList[p.m_alias] = p;

SWSS_LOG_INFO("Set PFC watchdog port id=0x%" PRIx64 ", bitmast=0x%x", portId, pfcwd_bitmask);
return true;
}

bool PortsOrch::getPortPfcWatchdogStatus(sai_object_id_t portId, uint8_t *pfcwd_bitmask)
{
SWSS_LOG_ENTER();

Port p;

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

*pfcwd_bitmask = p.m_pfcwd_sw_bitmask;

return true;
}

bool PortsOrch::setPortPfcAsym(Port &port, string pfc_asym)
{
SWSS_LOG_ENTER();
Expand Down
3 changes: 3 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class PortsOrch : public Orch, public Subject
bool getPortPfc(sai_object_id_t portId, uint8_t *pfc_bitmask);
bool setPortPfc(sai_object_id_t portId, uint8_t pfc_bitmask);

bool setPortPfcWatchdogStatus(sai_object_id_t portId, uint8_t pfc_bitmask);
bool getPortPfcWatchdogStatus(sai_object_id_t portId, uint8_t *pfc_bitmask);

void generateQueueMap();
void generatePriorityGroupMap();
void generatePortCounterMap();
Expand Down
18 changes: 16 additions & 2 deletions orchagent/qosorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,7 @@ task_process_status QosOrch::handlePortQosMapTable(Consumer& consumer)
string op = kfvOp(tuple);

sai_uint8_t pfc_enable = 0;
sai_uint8_t pfcwd_sw_enable = 0;
map<sai_port_attr_t, pair<string, sai_object_id_t>> update_list;
for (auto it = kfvFieldsValues(tuple).begin(); it != kfvFieldsValues(tuple).end(); it++)
{
Expand All @@ -1648,14 +1649,24 @@ task_process_status QosOrch::handlePortQosMapTable(Consumer& consumer)
update_list[qos_to_attr_map[map_type_name]] = make_pair(map_name, id);
}

if (fvField(*it) == pfc_enable_name)
else if (fvField(*it) == pfc_enable_name || fvField(*it) == pfcwd_sw_enable_name)
{
sai_uint8_t bitmask = 0;
vector<string> queue_indexes;
queue_indexes = tokenize(fvValue(*it), list_item_delimiter);
for(string q_ind : queue_indexes)
{
sai_uint8_t q_val = (uint8_t)stoi(q_ind);
pfc_enable |= (uint8_t)(1 << q_val);
bitmask |= (uint8_t)(1 << q_val);
}

if (fvField(*it) == pfc_enable_name)
{
pfc_enable = bitmask;
}
else
{
pfcwd_sw_enable = bitmask;
}
}
}
Expand Down Expand Up @@ -1708,6 +1719,9 @@ task_process_status QosOrch::handlePortQosMapTable(Consumer& consumer)

SWSS_LOG_INFO("Applied PFC bits 0x%x to port %s", pfc_enable, port_name.c_str());
}

// Save pfd_wd bitmask unconditionally
gPortsOrch->setPortPfcWatchdogStatus(port.m_port_id, pfcwd_sw_enable);
}

SWSS_LOG_NOTICE("Applied QoS maps to ports");
Expand Down
1 change: 1 addition & 0 deletions orchagent/qosorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const string dot1p_to_tc_field_name = "dot1p_to_tc_map";
const string pfc_to_pg_map_name = "pfc_to_pg_map";
const string pfc_to_queue_map_name = "pfc_to_queue_map";
const string pfc_enable_name = "pfc_enable";
const string pfcwd_sw_enable_name = "pfcwd_sw_enable";
const string tc_to_pg_map_field_name = "tc_to_pg_map";
const string tc_to_queue_field_name = "tc_to_queue_map";
const string scheduler_field_name = "scheduler";
Expand Down
Loading