From a3f4fbb446c932c210f6c12a5ff09affccb0c6d7 Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Thu, 9 Jun 2022 19:51:21 +0800 Subject: [PATCH] Combine PGs in buffermgrd (#2281) * Combine PG3 and PG4 to PG3-4 Signed-off-by: bingwang --- cfgmgr/buffermgr.cpp | 32 +++++++++++++++++++++++++++----- tests/test_buffer_traditional.py | 16 ++++++++-------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/cfgmgr/buffermgr.cpp b/cfgmgr/buffermgr.cpp index 5c7d6ae9e64e..c81980e363e1 100644 --- a/cfgmgr/buffermgr.cpp +++ b/cfgmgr/buffermgr.cpp @@ -11,6 +11,7 @@ #include "exec.h" #include "shellcmd.h" #include "warm_restart.h" +#include "converter.h" using namespace std; using namespace swss; @@ -175,10 +176,27 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port) string profile_ref = buffer_profile_key; vector 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(pg); + lossless_pg_id |= (1< 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 fvVectorPg; @@ -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 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)); diff --git a/tests/test_buffer_traditional.py b/tests/test_buffer_traditional.py index 3d2285fd7b07..31d1afbbd893 100644 --- a/tests/test_buffer_traditional.py +++ b/tests/test_buffer_traditional.py @@ -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: @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 = {} @@ -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: