Skip to content

Commit a3f4fbb

Browse files
authored
Combine PGs in buffermgrd (sonic-net#2281)
* Combine PG3 and PG4 to PG3-4 Signed-off-by: bingwang <[email protected]>
1 parent ad8f5e4 commit a3f4fbb

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

cfgmgr/buffermgr.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "exec.h"
1212
#include "shellcmd.h"
1313
#include "warm_restart.h"
14+
#include "converter.h"
1415

1516
using namespace std;
1617
using namespace swss;
@@ -175,10 +176,27 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
175176
string profile_ref = buffer_profile_key;
176177

177178
vector<string> lossless_pgs = tokenize(pfc_enable, ',');
179+
// Convert to bitmap
180+
unsigned long lossless_pg_id = 0;
181+
for (auto pg : lossless_pgs)
182+
{
183+
try
184+
{
185+
uint8_t cur_pg = to_uint<uint8_t>(pg);
186+
lossless_pg_id |= (1<<cur_pg);
187+
}
188+
catch (const std::invalid_argument &e)
189+
{
190+
// Ignore invalid value
191+
continue;
192+
}
193+
}
194+
// Although we have up to 8 PGs for now, the range to check is expanded to 32 support more PGs
195+
set<string> lossless_pg_combinations = generateIdListFromMap(lossless_pg_id, sizeof(lossless_pg_id));
178196

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

254-
for (auto lossless_pg : lossless_pgs)
272+
for (auto lossless_pg : lossless_pg_combinations)
255273
{
256274
vector<FieldValueTuple> fvVectorPg;
257275
string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + lossless_pg;
258276

259277
m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);
260-
278+
bool profile_existing = false;
261279
/* Check if PG Mapping is already then log message and return. */
262280
for (auto& prop : fvVectorPg)
263281
{
264282
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
265283
{
266284
SWSS_LOG_NOTICE("PG to Buffer Profile Mapping %s already present", buffer_pg_key.c_str());
267-
continue;
285+
profile_existing = true;
286+
break;
268287
}
269288
}
270-
289+
if (profile_existing)
290+
{
291+
continue;
292+
}
271293
fvVectorPg.clear();
272294

273295
fvVectorPg.push_back(make_pair("profile", profile_ref));

tests/test_buffer_traditional.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ def get_pg_name_map(self):
7979
def setup_teardown_test(self, dvs):
8080
try:
8181
self.setup_db(dvs)
82-
self.set_port_qos_table(self.INTF, '2,3,4,6')
83-
pg_name_map = self.get_pg_name_map()
84-
yield pg_name_map
82+
self.set_port_qos_table(self.INTF, '3,4')
83+
self.lossless_pg_combinations = ['3-4']
8584
finally:
8685
self.teardown()
8786

8887
def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
89-
self.pg_name_map = setup_teardown_test
9088
orig_cable_len = None
9189
orig_speed = None
9290
try:
@@ -112,6 +110,7 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
112110
# Make sure the buffer PG has been created
113111
orig_lossless_profile = "pg_lossless_{}_{}_profile".format(orig_speed, cable_len_before_test)
114112
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", orig_lossless_profile)
113+
self.pg_name_map = self.get_pg_name_map()
115114
self.orig_profiles = self.get_asic_buf_profile()
116115

117116
# 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):
136135
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", test_lossless_profile)
137136

138137
# buffer pgs should still point to the original buffer profile
139-
for pg in self.lossless_pgs:
138+
for pg in self.lossless_pg_combinations:
140139
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", self.INTF + ":" + pg, {"profile": orig_lossless_profile})
141140
fvs = dict()
142141
for pg in self.pg_name_map:
@@ -174,7 +173,6 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test):
174173
# To verify the BUFFER_PG is not hardcoded to 3,4
175174
# buffermgrd will read 'pfc_enable' entry and apply lossless profile to that queue
176175
def test_buffer_pg_update(self, dvs, setup_teardown_test):
177-
self.pg_name_map = setup_teardown_test
178176
orig_cable_len = None
179177
orig_speed = None
180178
test_speed = None
@@ -203,6 +201,7 @@ def test_buffer_pg_update(self, dvs, setup_teardown_test):
203201
# Make sure the buffer PG has been created
204202
orig_lossless_profile = "pg_lossless_{}_{}_profile".format(orig_speed, cable_len_for_test)
205203
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", orig_lossless_profile)
204+
self.pg_name_map = self.get_pg_name_map()
206205
self.orig_profiles = self.get_asic_buf_profile()
207206

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

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

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

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

0 commit comments

Comments
 (0)