@@ -1862,6 +1862,14 @@ task_process_status BufferMgrDynamic::handleBufferMaxParam(KeyOpFieldsValuesTupl
1862
1862
SWSS_LOG_INFO (" BUFFER_MAX_PARAM: Got port %s's max priority group %s" , key.c_str (), value.c_str ());
1863
1863
1864
1864
portInfo.maximum_buffer_objects [BUFFER_PG] = (sai_uint32_t )pgCount;
1865
+
1866
+ if (m_bufferCompletelyInitialized && portInfo.state == PORT_ADMIN_DOWN)
1867
+ {
1868
+ // This is mostly for the case where the port is created only-the-fly
1869
+ // The maximum buffer parameters can be received after buffer items
1870
+ reclaimReservedBufferForPort (key, m_portPgLookup, BUFFER_PG);
1871
+ SWSS_LOG_NOTICE (" Admin-down port %s is handled after maximum buffer parameter has been received" , key.c_str ());
1872
+ }
1865
1873
}
1866
1874
else if (fvField (i) == " max_queues" )
1867
1875
{
@@ -1875,6 +1883,14 @@ task_process_status BufferMgrDynamic::handleBufferMaxParam(KeyOpFieldsValuesTupl
1875
1883
SWSS_LOG_INFO (" BUFFER_MAX_PARAM: Got port %s's max queue %s" , key.c_str (), value.c_str ());
1876
1884
1877
1885
portInfo.maximum_buffer_objects [BUFFER_QUEUE] = (sai_uint32_t )queueCount;
1886
+
1887
+ if (m_bufferCompletelyInitialized && portInfo.state == PORT_ADMIN_DOWN)
1888
+ {
1889
+ // This is mostly for the case where the port is created only-the-fly
1890
+ // The maximum buffer parameters can be received after buffer items
1891
+ reclaimReservedBufferForPort (key, m_portQueueLookup, BUFFER_QUEUE);
1892
+ SWSS_LOG_NOTICE (" Admin-down port %s is handled after maximum buffer parameter has been received" , key.c_str ());
1893
+ }
1878
1894
}
1879
1895
}
1880
1896
}
@@ -1961,6 +1977,7 @@ task_process_status BufferMgrDynamic::handleCableLenTable(KeyOpFieldsValuesTuple
1961
1977
int failed_item_count = 0 ;
1962
1978
if (op == SET_COMMAND)
1963
1979
{
1980
+ m_cableLengths.clear ();
1964
1981
for (auto i : kfvFieldsValues (tuple))
1965
1982
{
1966
1983
// receive and cache cable length table
@@ -1975,6 +1992,8 @@ task_process_status BufferMgrDynamic::handleCableLenTable(KeyOpFieldsValuesTuple
1975
1992
port.c_str (),
1976
1993
portInfo.effective_speed .c_str (), portInfo.cable_length .c_str (), portInfo.gearbox_model .c_str ());
1977
1994
1995
+ m_cableLengths[port] = cable_length;
1996
+
1978
1997
if (portInfo.cable_length == cable_length)
1979
1998
{
1980
1999
continue ;
@@ -2183,6 +2202,11 @@ task_process_status BufferMgrDynamic::handlePortTable(KeyOpFieldsValuesTuple &tu
2183
2202
string &mtu = portInfo.mtu ;
2184
2203
string &effective_speed = portInfo.effective_speed ;
2185
2204
2205
+ if (cable_length.empty () && !m_cableLengths[port].empty ())
2206
+ {
2207
+ cable_length = m_cableLengths[port];
2208
+ }
2209
+
2186
2210
bool need_refresh_all_buffer_objects = false , need_handle_admin_down = false , was_admin_down = false ;
2187
2211
2188
2212
if (effective_speed_updated || mtu_updated)
@@ -2304,6 +2328,28 @@ task_process_status BufferMgrDynamic::handlePortTable(KeyOpFieldsValuesTuple &tu
2304
2328
task_status = refreshPgsForPort (port, portInfo.effective_speed , portInfo.cable_length , portInfo.mtu );
2305
2329
}
2306
2330
}
2331
+ else if (op == DEL_COMMAND)
2332
+ {
2333
+ cleanUpItemsForReclaimingBuffer (port);
2334
+ if ((m_portPgLookup.find (port) != m_portPgLookup.end ()
2335
+ && !m_portPgLookup[port].empty ())
2336
+ || (m_portQueueLookup.find (port) != m_portQueueLookup.end ()
2337
+ && !m_portQueueLookup[port].empty ())
2338
+ || (m_portProfileListLookups[BUFFER_INGRESS].find (port) != m_portProfileListLookups[BUFFER_INGRESS].end ()
2339
+ && !m_portProfileListLookups[BUFFER_INGRESS][port].empty ())
2340
+ || (m_portProfileListLookups[BUFFER_EGRESS].find (port) != m_portProfileListLookups[BUFFER_EGRESS].end ()
2341
+ && !m_portProfileListLookups[BUFFER_EGRESS][port].empty ()))
2342
+ {
2343
+ SWSS_LOG_INFO (" Port %s can't be removed before buffer items have been removed" , port.c_str ());
2344
+ return task_process_status::task_need_retry;
2345
+ }
2346
+ m_portPgLookup.erase (port);
2347
+ m_portQueueLookup.erase (port);
2348
+ m_portProfileListLookups[BUFFER_INGRESS].erase (port);
2349
+ m_portProfileListLookups[BUFFER_EGRESS].erase (port);
2350
+ m_portInfoLookup.erase (port);
2351
+ SWSS_LOG_NOTICE (" Port %s is removed" , port.c_str ());
2352
+ }
2307
2353
2308
2354
return task_status;
2309
2355
}
@@ -2401,6 +2447,28 @@ task_process_status BufferMgrDynamic::handleBufferPoolTable(KeyOpFieldsValuesTup
2401
2447
m_applBufferPoolTable.del (pool);
2402
2448
m_stateBufferPoolTable.del (pool);
2403
2449
m_bufferPoolLookup.erase (pool);
2450
+ if (pool == INGRESS_LOSSLESS_PG_POOL_NAME)
2451
+ {
2452
+ m_configuredSharedHeadroomPoolSize.clear ();
2453
+ }
2454
+
2455
+ if (m_bufferPoolReady && m_bufferPoolLookup.empty ())
2456
+ {
2457
+ for (auto &port : m_adminDownPorts)
2458
+ {
2459
+ cleanUpItemsForReclaimingBuffer (port);
2460
+ }
2461
+
2462
+ // Zero profiles must be unloaded once all pools have been uploaded
2463
+ // This can be resulted from "config qos reload"
2464
+ // Any zero profile left can leads to buffer pool not able to be cleared
2465
+ unloadZeroPoolAndProfiles ();
2466
+
2467
+ m_bufferPoolReady = false ;
2468
+ m_bufferCompletelyInitialized = false ;
2469
+
2470
+ m_pendingApplyZeroProfilePorts = m_adminDownPorts;
2471
+ }
2404
2472
}
2405
2473
else
2406
2474
{
@@ -2634,6 +2702,12 @@ void BufferMgrDynamic::handleSetSingleBufferObjectOnAdminDownPort(buffer_directi
2634
2702
{
2635
2703
if (idsToZero.empty ())
2636
2704
{
2705
+ // Happens only after "config qos reload"
2706
+ if (!m_zeroProfilesLoaded)
2707
+ {
2708
+ loadZeroPoolAndProfiles ();
2709
+ }
2710
+
2637
2711
// If initialization finished, no extra handle required.
2638
2712
// Check whether the key overlaps with supported but not configured map
2639
2713
auto const &idsToAdd = parseObjectNameFromKey (key, 1 );
@@ -2749,6 +2823,14 @@ void BufferMgrDynamic::handleDelSingleBufferObjectOnAdminDownPort(buffer_directi
2749
2823
2750
2824
if (idsToZero.empty ())
2751
2825
{
2826
+ if (!m_bufferPoolReady)
2827
+ {
2828
+ // Reclaiming buffer has not started yet so just remove it.
2829
+ // Do not add it to "supported but not configured" set
2830
+ updateBufferObjectToDb (key, " " , false , direction);
2831
+ return ;
2832
+ }
2833
+
2752
2834
// For admin down ports, if zero profiles have been applied to all configured items
2753
2835
// do NOT remove it otherwise SDK default value will be set for the items
2754
2836
// Move the key to supported_but_not_configured_items so that the slice of items
@@ -3125,6 +3207,22 @@ task_process_status BufferMgrDynamic::handleSingleBufferPortProfileListEntry(con
3125
3207
// For admin-down ports, zero profile list has been applied on the port when it entered admin-down state
3126
3208
updateBufferObjectListToDb (key, profileListLookup[port], dir);
3127
3209
}
3210
+ else
3211
+ {
3212
+ const auto &profileList = m_portProfileListLookups[dir][port];
3213
+ if (!profileList.empty ())
3214
+ {
3215
+ // Happens only after "config qos reload"
3216
+ if (!m_zeroProfilesLoaded)
3217
+ {
3218
+ loadZeroPoolAndProfiles ();
3219
+ }
3220
+ vector<FieldValueTuple> fvVector;
3221
+ const string &zeroProfileNameList = constructZeroProfileListFromNormalProfileList (profileList, port);
3222
+ fvVector.emplace_back (buffer_profile_list_field_name, zeroProfileNameList);
3223
+ m_applBufferProfileListTables[dir].set (port, fvVector);
3224
+ }
3225
+ }
3128
3226
}
3129
3227
else if (op == DEL_COMMAND)
3130
3228
{
@@ -3462,9 +3560,25 @@ void BufferMgrDynamic::handlePendingBufferObjects()
3462
3560
}
3463
3561
}
3464
3562
3563
+ void BufferMgrDynamic::cleanUpItemsForReclaimingBuffer (const string &port)
3564
+ {
3565
+ // Clean up zero buffers when the buffer pools or a port has been removed
3566
+ if (!m_bufferObjectIdsToZero[BUFFER_PG].empty ())
3567
+ {
3568
+ updateBufferObjectToDb (port + delimiter + m_bufferObjectIdsToZero[BUFFER_PG], " " , false , BUFFER_PG);
3569
+ }
3570
+ if (!m_bufferObjectIdsToZero[BUFFER_QUEUE].empty ())
3571
+ {
3572
+ updateBufferObjectToDb (port + delimiter + m_bufferObjectIdsToZero[BUFFER_QUEUE], " " , false , BUFFER_QUEUE);
3573
+ }
3574
+ removeSupportedButNotConfiguredItemsOnPort (m_portInfoLookup[port], port);
3575
+ }
3576
+
3465
3577
void BufferMgrDynamic::doTask (SelectableTimer &timer)
3466
3578
{
3467
3579
checkSharedBufferPoolSize (true );
3468
3580
if (!m_bufferCompletelyInitialized)
3581
+ {
3469
3582
handlePendingBufferObjects ();
3583
+ }
3470
3584
}
0 commit comments