Skip to content

Commit f4c3579

Browse files
authored
Enhance dynamic buffer calculation and bug fixes (#1601)
* Enhancement and bug fixes for dynamic buffer calculation What I did - Remove make_pair when calling emplace_back. - The pool size isn't recalculated when a port with headroom override but without speed or cable length configured being shutdown. - Remove the current PG from the old referenced profile only if its name isn't empty, otherwise an entry with empty name will be inserted into m_bufferProfileLookup - Don't try removing statically configured profiles with dynamic headroom from the APPL_DB because they were not programmed to APPL_DB. - Setting a buffer PG to the same profile as it was causes the referenced dynamic profile unable to be removed once it isn't referenced any more How I verified it Run regression and vs test Signed-off-by: Stephen Sun <[email protected]>
1 parent e800c9f commit f4c3579

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

cfgmgr/buffermgrdyn.cpp

+54-39
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void BufferMgrDynamic::checkSharedBufferPoolSize()
384384
if (m_firstTimeCalculateBufferPool)
385385
{
386386
// It's something like a placeholder especially for warm reboot flow
387-
// without all buffer pools created, buffer profiles are unable to be cureated,
387+
// without all buffer pools created, buffer profiles are unable to be created,
388388
// which in turn causes buffer pgs and buffer queues unable to be created,
389389
// which prevents the port from being ready and eventually fails the warm reboot
390390
// After the buffer pools are created for the first time, we won't touch it
@@ -435,14 +435,14 @@ void BufferMgrDynamic::updateBufferProfileToDb(const string &name, const buffer_
435435
m_applBufferProfileTable.getTableNameSeparator() +
436436
INGRESS_LOSSLESS_PG_POOL_NAME;
437437

438-
fvVector.emplace_back(make_pair("xon", profile.xon));
438+
fvVector.emplace_back("xon", profile.xon);
439439
if (!profile.xon_offset.empty()) {
440-
fvVector.emplace_back(make_pair("xon_offset", profile.xon_offset));
440+
fvVector.emplace_back("xon_offset", profile.xon_offset);
441441
}
442-
fvVector.emplace_back(make_pair("xoff", profile.xoff));
443-
fvVector.emplace_back(make_pair("size", profile.size));
444-
fvVector.emplace_back(make_pair("pool", "[" + pg_pool_reference + "]"));
445-
fvVector.emplace_back(make_pair(mode, profile.threshold));
442+
fvVector.emplace_back("xoff", profile.xoff);
443+
fvVector.emplace_back("size", profile.size);
444+
fvVector.emplace_back("pool", "[" + pg_pool_reference + "]");
445+
fvVector.emplace_back(mode, profile.threshold);
446446

447447
m_applBufferProfileTable.set(name, fvVector);
448448
m_stateBufferProfileTable.set(name, fvVector);
@@ -721,18 +721,20 @@ task_process_status BufferMgrDynamic::refreshPriorityGroupsForPort(const string
721721
{
722722
// Need to remove the reference to the old profile
723723
// and create the reference to the new one
724-
m_bufferProfileLookup[oldProfile].port_pgs.erase(key);
725724
m_bufferProfileLookup[newProfile].port_pgs.insert(key);
726725
SWSS_LOG_INFO("Move profile reference for %s from [%s] to [%s]", key.c_str(), oldProfile.c_str(), newProfile.c_str());
727726

728-
// buffer pg needs to be updated as well
729-
portPg.running_profile_name = newProfile;
730-
731727
// Add the old profile to "to be removed" set
732728
if (!oldProfile.empty())
729+
{
733730
profilesToBeReleased.insert(oldProfile);
731+
m_bufferProfileLookup[oldProfile].port_pgs.erase(key);
732+
}
734733
}
735734

735+
// buffer pg needs to be updated as well
736+
portPg.running_profile_name = newProfile;
737+
736738
//appl_db Database operation: set item BUFFER_PG|<port>|<pg>
737739
updateBufferPgToDb(key, newProfile, true);
738740
isHeadroomUpdated = true;
@@ -811,12 +813,6 @@ task_process_status BufferMgrDynamic::doUpdatePgTask(const string &pg_key, const
811813
return task_process_status::task_success;
812814
}
813815

814-
if (bufferPg.static_configured && bufferPg.dynamic_calculated)
815-
{
816-
auto &profile = m_bufferProfileLookup[bufferPg.configured_profile_name];
817-
profile.port_pgs.insert(pg_key);
818-
}
819-
820816
return task_process_status::task_success;
821817
}
822818

@@ -843,12 +839,6 @@ task_process_status BufferMgrDynamic::doRemovePgTask(const string &pg_key, const
843839
SWSS_LOG_NOTICE("try removing the original profile %s", bufferPg.running_profile_name.c_str());
844840
releaseProfile(bufferPg.running_profile_name);
845841

846-
if (bufferPg.static_configured && bufferPg.dynamic_calculated)
847-
{
848-
auto &profile = m_bufferProfileLookup[bufferPg.configured_profile_name];
849-
profile.port_pgs.erase(pg_key);
850-
}
851-
852842
return task_process_status::task_success;
853843
}
854844

@@ -1099,15 +1089,18 @@ task_process_status BufferMgrDynamic::handlePortTable(KeyOpFieldsValuesTuple &tu
10991089
string &mtu = portInfo.mtu;
11001090
string &speed = portInfo.speed;
11011091

1102-
if (cable_length.empty() || speed.empty())
1103-
{
1104-
SWSS_LOG_WARN("Cable length for %s hasn't been configured yet, unable to calculate headroom", port.c_str());
1105-
// We don't retry here because it doesn't make sense until the cable length is configured.
1106-
return task_process_status::task_success;
1107-
}
1108-
11091092
if (speed_updated || mtu_updated)
11101093
{
1094+
if (cable_length.empty() || speed.empty())
1095+
{
1096+
// we still need to update pool size when port with headroom override is shut down
1097+
// even if its cable length or speed isn't configured
1098+
// so cable length and speed isn't tested for shutdown
1099+
SWSS_LOG_WARN("Cable length for %s hasn't been configured yet, unable to calculate headroom", port.c_str());
1100+
// We don't retry here because it doesn't make sense until the cable length is configured.
1101+
return task_process_status::task_success;
1102+
}
1103+
11111104
SWSS_LOG_INFO("Updating BUFFER_PG for port %s due to speed or port updated", port.c_str());
11121105

11131106
//Try updating the buffer information
@@ -1295,7 +1288,7 @@ task_process_status BufferMgrDynamic::handleBufferProfileTable(KeyOpFieldsValues
12951288
profileApp.ingress = true;
12961289
}
12971290
}
1298-
fvVector.emplace_back(FieldValueTuple(field, value));
1291+
fvVector.emplace_back(field, value);
12991292
SWSS_LOG_INFO("Inserting BUFFER_PROFILE table field %s value %s", field.c_str(), value.c_str());
13001293
}
13011294
// don't insert dynamically calculated profiles into APPL_DB
@@ -1353,13 +1346,20 @@ task_process_status BufferMgrDynamic::handleBufferProfileTable(KeyOpFieldsValues
13531346
return task_process_status::task_invalid_entry;
13541347
}
13551348
}
1356-
}
13571349

1358-
m_applBufferProfileTable.del(profileName);
1359-
m_stateBufferProfileTable.del(profileName);
1350+
if (!profile.static_configured || !profile.dynamic_calculated)
1351+
{
1352+
m_applBufferProfileTable.del(profileName);
1353+
m_stateBufferProfileTable.del(profileName);
1354+
}
13601355

1361-
m_bufferProfileLookup.erase(profileName);
1362-
m_bufferProfileIgnored.erase(profileName);
1356+
m_bufferProfileLookup.erase(profileName);
1357+
m_bufferProfileIgnored.erase(profileName);
1358+
}
1359+
else
1360+
{
1361+
SWSS_LOG_ERROR("Profile %s not found while being removed", profileName.c_str());
1362+
}
13631363
}
13641364
else
13651365
{
@@ -1387,6 +1387,12 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
13871387

13881388
bufferPg.dynamic_calculated = true;
13891389
bufferPg.static_configured = false;
1390+
if (!bufferPg.configured_profile_name.empty())
1391+
{
1392+
m_bufferProfileLookup[bufferPg.configured_profile_name].port_pgs.erase(key);
1393+
bufferPg.configured_profile_name = "";
1394+
}
1395+
13901396
for (auto i = kfvFieldsValues(tuple).begin(); i != kfvFieldsValues(tuple).end(); i++)
13911397
{
13921398
const string &field = fvField(*i);
@@ -1418,7 +1424,7 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
14181424
}
14191425
else
14201426
{
1421-
// In this case, we shouldn't set the dynamc calculated flat to true
1427+
// In this case, we shouldn't set the dynamic calculated flag to true
14221428
// It will be updated when its profile configured.
14231429
bufferPg.dynamic_calculated = false;
14241430
SWSS_LOG_WARN("Profile %s hasn't been configured yet, skip", profileName.c_str());
@@ -1435,7 +1441,7 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
14351441
bufferPg.static_configured = true;
14361442
bufferPg.configured_profile_name = profileName;
14371443
}
1438-
fvVector.emplace_back(FieldValueTuple(field, value));
1444+
fvVector.emplace_back(field, value);
14391445
SWSS_LOG_INFO("Inserting BUFFER_PG table field %s value %s", field.c_str(), value.c_str());
14401446
}
14411447

@@ -1449,6 +1455,11 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
14491455
if (!ignored && bufferPg.lossless)
14501456
{
14511457
doUpdatePgTask(key, port);
1458+
1459+
if (!bufferPg.configured_profile_name.empty())
1460+
{
1461+
m_bufferProfileLookup[bufferPg.configured_profile_name].port_pgs.insert(key);
1462+
}
14521463
}
14531464
else
14541465
{
@@ -1464,6 +1475,10 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
14641475
string &profileName = bufferPg.running_profile_name;
14651476

14661477
m_bufferProfileLookup[profileName].port_pgs.erase(key);
1478+
if (!bufferPg.configured_profile_name.empty())
1479+
{
1480+
m_bufferProfileLookup[bufferPg.configured_profile_name].port_pgs.erase(key);
1481+
}
14671482

14681483
if (bufferPg.lossless)
14691484
{
@@ -1589,7 +1604,7 @@ task_process_status BufferMgrDynamic::doBufferTableTask(KeyOpFieldsValuesTuple &
15891604
transformReference(fvValue(i));
15901605
if (fvField(i) == "profile_list")
15911606
transformReference(fvValue(i));
1592-
fvVector.emplace_back(FieldValueTuple(fvField(i), fvValue(i)));
1607+
fvVector.emplace_back(fvField(i), fvValue(i));
15931608
SWSS_LOG_INFO("Inserting field %s value %s", fvField(i).c_str(), fvValue(i).c_str());
15941609
}
15951610
applTable.set(key, fvVector);

0 commit comments

Comments
 (0)