Skip to content

Commit 1c79481

Browse files
stephenxsraphaelt-nvidia
authored andcommitted
[buffermgr] Support maximum port headroom checking (sonic-net#1607)
* Support maximum port headroom checking - Fetch the maximum port headroom via fetching the port attribute SAI_PORT_ATTR_QOS_MAXIMUM_HEADROOM_SIZE when the orchagent starts and push the data into STATE_DB - Check the accumulative port headroom against the maximum headroom in buffer_check_headroom_<vendor>.lua On Mellanox platform, this PR depends on PR #6566 to be merged. In that PR the required SAI attribute is supported. On other platforms, there is no dependency. Signed-off-by: Stephen Sun stephens@nvidia.com Why I did it On some platforms, the SAI will notify orchagent shut down if a headroom size that causes the accumulative port headroom to exceed its limit is programmed to SAI. To avoid that, we need to check this before programming it to SAI. How I verified it Run the regression test.
1 parent 4a0ea93 commit 1c79481

4 files changed

Lines changed: 29 additions & 26 deletions

File tree

cfgmgr/buffer_check_headroom_mellanox.lua

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,15 @@ local new_pg = ARGV[3]
1010
local accumulative_size = 0
1111

1212
local appl_db = "0"
13-
local config_db = "4"
1413
local state_db = "6"
1514

1615
local ret_true = {}
17-
local ret_false = {}
1816
local ret = {}
1917
local default_ret = {}
2018

2119
table.insert(ret_true, "result:true")
22-
table.insert(ret_false, "result:false")
2320

24-
-- Fetch the cable length from CONFIG_DB
25-
redis.call('SELECT', config_db)
26-
local cable_length_keys = redis.call('KEYS', 'CABLE_LENGTH*')
27-
if #cable_length_keys == 0 then
28-
return ret_true
29-
end
30-
31-
-- Check whether cable length exceeds 300m (maximum value in the non-dynamic-buffer solution)
32-
local cable_length_str = redis.call('HGET', cable_length_keys[1], port)
33-
if cable_length_str == nil then
34-
return ret_true
35-
end
36-
local cable_length = tonumber(string.sub(cable_length_str, 1, -2))
37-
if cable_length > 300 then
38-
default_ret = ret_false
39-
else
40-
default_ret = ret_true
41-
end
42-
table.insert(default_ret, 'debug:no max_headroom_size configured, check cable length instead')
21+
default_ret = ret_true
4322

4423
local speed = redis.call('HGET', 'PORT|' .. port, 'speed')
4524

@@ -67,7 +46,6 @@ local function get_number_of_pgs(keyname)
6746
local range = string.match(keyname, "Ethernet%d+:([^%s]+)$")
6847
local size
6948
if range == nil then
70-
table.insert(debuginfo, "debug:invalid pg:" .. keyname)
7149
return 0
7250
end
7351
if string.len(range) == 1 then
@@ -119,11 +97,9 @@ if max_headroom_size > accumulative_size then
11997
table.insert(ret, "result:true")
12098
else
12199
table.insert(ret, "result:false")
100+
table.insert(ret, "debug:Accumulative headroom on port " .. accumulative_size .. " exceeds the maximum available headroom which is " .. max_headroom_size)
122101
end
123102

124-
table.insert(ret, "debug:max headroom:" .. max_headroom_size)
125-
table.insert(ret, "debug:accumulative headroom:" .. accumulative_size)
126-
127103
for i = 1, #debuginfo do
128104
table.insert(ret, debuginfo[i])
129105
end

orchagent/port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class Port
124124
uint32_t m_vnid = VNID_NONE;
125125
uint32_t m_fdb_count = 0;
126126
uint32_t m_up_member_count = 0;
127+
uint32_t m_maximum_headroom = 0;
127128

128129
/*
129130
* Following two bit vectors are used to lock

orchagent/portsorch.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames)
257257
m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE));
258258
m_flexCounterGroupTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE));
259259

260+
m_state_db = shared_ptr<DBConnector>(new DBConnector("STATE_DB", 0));
261+
m_stateBufferMaximumValueTable = unique_ptr<Table>(new Table(m_state_db.get(), STATE_BUFFER_MAXIMUM_VALUE_TABLE));
262+
260263
initGearbox();
261264

262265
string queueWmSha, pgWmSha;
@@ -3291,6 +3294,25 @@ void PortsOrch::initializePriorityGroups(Port &port)
32913294
SWSS_LOG_INFO("Get priority groups for port %s", port.m_alias.c_str());
32923295
}
32933296

3297+
void PortsOrch::initializePortMaximumHeadroom(Port &port)
3298+
{
3299+
sai_attribute_t attr;
3300+
3301+
attr.id = SAI_PORT_ATTR_QOS_MAXIMUM_HEADROOM_SIZE;
3302+
3303+
sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
3304+
if (status != SAI_STATUS_SUCCESS)
3305+
{
3306+
SWSS_LOG_NOTICE("Unable to get the maximum headroom for port %s rv:%d, ignored", port.m_alias.c_str(), status);
3307+
return;
3308+
}
3309+
3310+
vector<FieldValueTuple> fvVector;
3311+
port.m_maximum_headroom = attr.value.u32;
3312+
fvVector.emplace_back("max_headroom_size", to_string(port.m_maximum_headroom));
3313+
m_stateBufferMaximumValueTable->set(port.m_alias, fvVector);
3314+
}
3315+
32943316
bool PortsOrch::initializePort(Port &port)
32953317
{
32963318
SWSS_LOG_ENTER();
@@ -3299,6 +3321,7 @@ bool PortsOrch::initializePort(Port &port)
32993321

33003322
initializePriorityGroups(port);
33013323
initializeQueues(port);
3324+
initializePortMaximumHeadroom(port);
33023325

33033326
/* Create host interface */
33043327
if (!addHostIntfs(port, port.m_alias, port.m_hif_id))

orchagent/portsorch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class PortsOrch : public Orch, public Subject
155155
unique_ptr<Table> m_pgTable;
156156
unique_ptr<Table> m_pgPortTable;
157157
unique_ptr<Table> m_pgIndexTable;
158+
unique_ptr<Table> m_stateBufferMaximumValueTable;
158159
unique_ptr<ProducerTable> m_flexCounterTable;
159160
unique_ptr<ProducerTable> m_flexCounterGroupTable;
160161

@@ -164,6 +165,7 @@ class PortsOrch : public Orch, public Subject
164165

165166
shared_ptr<DBConnector> m_counter_db;
166167
shared_ptr<DBConnector> m_flex_db;
168+
shared_ptr<DBConnector> m_state_db;
167169

168170
FlexCounterManager port_stat_manager;
169171
FlexCounterManager port_buffer_drop_stat_manager;
@@ -226,6 +228,7 @@ class PortsOrch : public Orch, public Subject
226228

227229
bool initializePort(Port &port);
228230
void initializePriorityGroups(Port &port);
231+
void initializePortMaximumHeadroom(Port &port);
229232
void initializeQueues(Port &port);
230233

231234
bool addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id);

0 commit comments

Comments
 (0)