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 10 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
253 changes: 195 additions & 58 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
*/
task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
{
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
string cable;
string speed;
string pfc_enable;
string applied_lossless_pg_status;
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved

if (m_cableLenLookup.count(port) == 0)
{
Expand All @@ -152,96 +153,194 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
return task_process_status::task_success;
}

speed = m_speedLookup[port];
if (m_portPfcStatus.count(port) == 0)
{
// PORT_QOS_MAP is not ready yet. retry is required
SWSS_LOG_INFO("pfc_enable status is not available for port %s", port.c_str());
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
return task_process_status::task_need_retry;
}
pfc_enable = m_portPfcStatus[port];

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

m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);
vector<string> lossless_pgs = tokenize(pfc_enable, ',');

if (!admin_up && m_platform == "mellanox")
{
// Remove the entry in BUFFER_PG table if any
if (!fvVectorPg.empty())
for (auto lossless_pg : lossless_pgs)
{
for (auto &prop : fvVectorPg)
// Remove the entry in BUFFER_PG table if any
vector<FieldValueTuple> fvVectorPg;
string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + lossless_pg;

m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);
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());
}
}
}
}
}

// Clear applied recorded
if (m_portLosslessPgs.count(port) != 0)
{
m_portLosslessPgs.erase(port);
};
// Clear recorded pg for admin_down port
if (m_portPgLookup.count(port) != 0)
{
m_portPgLookup.erase(port);
}
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
return task_process_status::task_success;
}

if (m_pgProfileLookup.count(speed) == 0 || m_pgProfileLookup[speed].count(cable) == 0)
for (auto lossless_pg : lossless_pgs)
{
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;
}
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + lossless_pg;

// 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());
m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);

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());

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));
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("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);

/* 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
{
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.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
// Save the applied lossless PG
m_portLosslessPgs[port] = pfc_enable;
// Save the profile_ref
m_portPgLookup[port] = profile_ref;
}
else
return task_process_status::task_success;
}

void BufferMgr::updatePortLosslessPg(const string &port)
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
{
string applied_lossless_pg_status;
// Read the lossless profile that has been applied to port
auto iter = m_portLosslessPgs.find(port);
if (iter == m_portLosslessPgs.end())
{
// No lossless pg is applied to port yet, no need to update
return;
}
applied_lossless_pg_status = iter->second;

string new_pfc_enable_flag = m_portPfcStatus[port];

vector<string> new_lossless_pgs = tokenize(new_pfc_enable_flag, ',');
std::sort(new_lossless_pgs.begin(), new_lossless_pgs.end());

vector<string> applied_lossless_pgs = tokenize(applied_lossless_pg_status, ',');
std::sort(applied_lossless_pgs.begin(), applied_lossless_pgs.end());

// Compare the sorted items, and update if diff is found
if (new_lossless_pgs == applied_lossless_pgs)
{
SWSS_LOG_NOTICE("Reusing existing profile '%s'", buffer_profile_key.c_str());
// No diff detected
return;
}

/* Check if PG Mapping is already then log message and return. */
for (auto& prop : fvVectorPg)

iter = m_portPgLookup.find(port);
if (iter == m_portPgLookup.end())
{
// Ignore if PG profile is not generated for the port
return;
}
string profile_ref = m_portPgLookup[port];
string buffer_pg_key;
vector<FieldValueTuple> fvVectorPg;
// Remove the already applied BUFFER_PG
for (auto pg : applied_lossless_pgs)
{
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + pg;
fvVectorPg.clear();
m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);

// Remove the entry in BUFFER_PG table if any
if (!fvVectorPg.empty())
{
SWSS_LOG_NOTICE("PG to Buffer Profile Mapping %s already present", buffer_pg_key.c_str());
return task_process_status::task_success;
m_cfgBufferPgTable.del(buffer_pg_key);
}
SWSS_LOG_INFO("Removed stale PG profile for port %s PG %s", port.c_str(), pg.c_str());
}

fvVectorPg.clear();

fvVectorPg.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
return task_process_status::task_success;
// Apply PG profile to new lossless pgs
for (auto pg : new_lossless_pgs)
{
buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + pg;
fvVectorPg.clear();
fvVectorPg.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
SWSS_LOG_INFO("Applied PG profile for port %s PG %s", port.c_str(), pg.c_str());
}
// Record the PGs
m_portLosslessPgs[port] = new_pfc_enable_flag;
}

void BufferMgr::transformSeperator(string &name)
Expand Down Expand Up @@ -346,6 +445,39 @@ void BufferMgr::doBufferMetaTask(Consumer &consumer)
}
}

/*
Parse PORT_QOS_MAP to retrieve on which queue PFC is enable, and
cached in a map
*/
void BufferMgr::doPortQosTableTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple tuple = it->second;
string port_name = kfvKey(tuple);
string op = kfvOp(tuple);
if (op == SET_COMMAND)
{
for (auto itp : kfvFieldsValues(tuple))
{
if (fvField(itp) == "pfc_enable")
{
m_portPfcStatus[port_name] = fvValue(itp);
SWSS_LOG_INFO("Got pfc enable status for port %s status %s", port_name.c_str(), fvValue(itp).c_str());
// Check if pfc_enable flag is updated
updatePortLosslessPg(port_name);
break;
}
}
}
it = consumer.m_toSync.erase(it);
}

}

void BufferMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -399,6 +531,12 @@ void BufferMgr::doTask(Consumer &consumer)
return;
}

if (table_name == CFG_PORT_QOS_MAP_TABLE_NAME)
{
doPortQosTableTask(consumer);
return;
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
}

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand Down Expand Up @@ -437,7 +575,6 @@ void BufferMgr::doTask(Consumer &consumer)

if (m_speedLookup.count(port) != 0)
{
// create/update profile for port
task_status = doSpeedUpdateTask(port, admin_up);
}

Expand Down
10 changes: 10 additions & 0 deletions cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ typedef std::map<std::string, speed_map_t> pg_profile_lookup_t;

typedef std::map<std::string, std::string> port_cable_length_t;
typedef std::map<std::string, std::string> port_speed_t;
typedef std::map<std::string, std::string> port_pfc_status_t;
typedef std::map<std::string, std::string> port_pg_profile_t;

class BufferMgr : public Orch
{
Expand Down Expand Up @@ -67,6 +69,14 @@ class BufferMgr : public Orch

void doTask(Consumer &consumer);
void doBufferMetaTask(Consumer &consumer);

port_pfc_status_t m_portPfcStatus;
port_pfc_status_t m_portLosslessPgs;
void doPortQosTableTask(Consumer &consumer);

port_pg_profile_t m_portPgLookup;
void updatePortLosslessPg(const std::string &port_name);

};

}
Expand Down
3 changes: 2 additions & 1 deletion cfgmgr/buffermgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ int main(int argc, char **argv)
CFG_BUFFER_QUEUE_TABLE_NAME,
CFG_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME,
CFG_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME,
CFG_DEVICE_METADATA_TABLE_NAME
CFG_DEVICE_METADATA_TABLE_NAME,
CFG_PORT_QOS_MAP_TABLE_NAME
};
cfgOrchList.emplace_back(new BufferMgr(&cfgDb, &applDb, pg_lookup_file, cfg_buffer_tables));
}
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
Loading