Skip to content

Commit

Permalink
Combine PGs in buffermgrd (sonic-net#2281)
Browse files Browse the repository at this point in the history
* Combine PG3 and PG4 to PG3-4

Signed-off-by: bingwang <wang.bing@microsoft.com>
  • Loading branch information
bingwang-ms authored Jun 9, 2022
1 parent ad8f5e4 commit a3f4fbb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
32 changes: 27 additions & 5 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "exec.h"
#include "shellcmd.h"
#include "warm_restart.h"
#include "converter.h"

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -175,10 +176,27 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
string profile_ref = buffer_profile_key;

vector<string> lossless_pgs = tokenize(pfc_enable, ',');
// Convert to bitmap
unsigned long lossless_pg_id = 0;
for (auto pg : lossless_pgs)
{
try
{
uint8_t cur_pg = to_uint<uint8_t>(pg);
lossless_pg_id |= (1<<cur_pg);
}
catch (const std::invalid_argument &e)
{
// Ignore invalid value
continue;
}
}
// Although we have up to 8 PGs for now, the range to check is expanded to 32 support more PGs
set<string> lossless_pg_combinations = generateIdListFromMap(lossless_pg_id, sizeof(lossless_pg_id));

if (m_portStatusLookup[port] == "down" && m_platform == "mellanox")
{
for (auto lossless_pg : lossless_pgs)
for (auto lossless_pg : lossless_pg_combinations)
{
// Remove the entry in BUFFER_PG table if any
vector<FieldValueTuple> fvVectorPg;
Expand Down Expand Up @@ -251,23 +269,27 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
SWSS_LOG_NOTICE("Reusing existing profile '%s'", buffer_profile_key.c_str());
}

for (auto lossless_pg : lossless_pgs)
for (auto lossless_pg : lossless_pg_combinations)
{
vector<FieldValueTuple> fvVectorPg;
string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + lossless_pg;

m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);

bool profile_existing = false;
/* Check if PG Mapping is already then log message and return. */
for (auto& prop : fvVectorPg)
{
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;
profile_existing = true;
break;
}
}

if (profile_existing)
{
continue;
}
fvVectorPg.clear();

fvVectorPg.push_back(make_pair("profile", profile_ref));
Expand Down
16 changes: 8 additions & 8 deletions tests/test_buffer_traditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@ def get_pg_name_map(self):
def setup_teardown_test(self, dvs):
try:
self.setup_db(dvs)
self.set_port_qos_table(self.INTF, '2,3,4,6')
pg_name_map = self.get_pg_name_map()
yield pg_name_map
self.set_port_qos_table(self.INTF, '3,4')
self.lossless_pg_combinations = ['3-4']
finally:
self.teardown()

def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
self.pg_name_map = setup_teardown_test
orig_cable_len = None
orig_speed = None
try:
Expand All @@ -112,6 +110,7 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
# Make sure the buffer PG has been created
orig_lossless_profile = "pg_lossless_{}_{}_profile".format(orig_speed, cable_len_before_test)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", orig_lossless_profile)
self.pg_name_map = self.get_pg_name_map()
self.orig_profiles = self.get_asic_buf_profile()

# check if the lossless profile for the test speed is already present
Expand All @@ -136,7 +135,7 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", test_lossless_profile)

# buffer pgs should still point to the original buffer profile
for pg in self.lossless_pgs:
for pg in self.lossless_pg_combinations:
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", self.INTF + ":" + pg, {"profile": orig_lossless_profile})
fvs = dict()
for pg in self.pg_name_map:
Expand Down Expand Up @@ -174,7 +173,6 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
# To verify the BUFFER_PG is not hardcoded to 3,4
# buffermgrd will read 'pfc_enable' entry and apply lossless profile to that queue
def test_buffer_pg_update(self, dvs, setup_teardown_test):
self.pg_name_map = setup_teardown_test
orig_cable_len = None
orig_speed = None
test_speed = None
Expand Down Expand Up @@ -203,6 +201,7 @@ def test_buffer_pg_update(self, dvs, setup_teardown_test):
# Make sure the buffer PG has been created
orig_lossless_profile = "pg_lossless_{}_{}_profile".format(orig_speed, cable_len_for_test)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", orig_lossless_profile)
self.pg_name_map = self.get_pg_name_map()
self.orig_profiles = self.get_asic_buf_profile()

# get the orig buf profiles attached to the pgs
Expand All @@ -221,7 +220,7 @@ def test_buffer_pg_update(self, dvs, setup_teardown_test):
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", new_lossless_profile)

# Verify BUFFER_PG is updated
for pg in self.lossless_pgs:
for pg in self.lossless_pg_combinations:
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", self.INTF + ":" + pg, {"profile": new_lossless_profile})

fvs_negative = {}
Expand All @@ -232,9 +231,10 @@ def test_buffer_pg_update(self, dvs, setup_teardown_test):

# Add pfc_enable field for extra port
self.set_port_qos_table(extra_port, '2,3,4,6')
self.lossless_pg_combinations = ['2-4', '6']
time.sleep(1)
# Verify BUFFER_PG is updated when pfc_enable is available
for pg in self.lossless_pgs:
for pg in self.lossless_pg_combinations:
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", extra_port + ":" + pg, {"profile": new_lossless_profile})
finally:
if orig_cable_len:
Expand Down

0 comments on commit a3f4fbb

Please sign in to comment.