Skip to content

Commit 407d048

Browse files
stepanblyschaklguohan
authored andcommitted
[mellanox] convert logic to use quanta in pfc_detect_mellanox.lua (sonic-net#930)
Convert quanta to us in lua script by getting configured speed from ASIC DB, since SONiC supports only signle speed mode, admin speed == oper speed Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 67c0940 commit 407d048

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

orchagent/pfc_detect_mellanox.lua

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,26 @@ local counters_db = ARGV[1]
88
local counters_table_name = ARGV[2]
99
local poll_time = tonumber(ARGV[3])
1010

11+
local asic_db = "1"
12+
local asic_db_port_table = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"
13+
14+
local quanta_size = 512
15+
1116
local rets = {}
1217

1318
redis.call('SELECT', counters_db)
1419

20+
local function port_speed_get(port_id)
21+
redis.call('SELECT', asic_db)
22+
local port_speed = redis.call('HGET', asic_db_port_table .. ':' .. port_id, 'SAI_PORT_ATTR_SPEED')
23+
redis.call('SELECT', counters_db)
24+
return tonumber(port_speed)
25+
end
26+
27+
local function quantatous(quanta, port_id)
28+
return quanta * quanta_size / port_speed_get(port_id)
29+
end
30+
1531
-- Iterate through each queue
1632
local n = table.getn(KEYS)
1733
for i = n, 1, -1 do
@@ -63,13 +79,14 @@ for i = n, 1, -1 do
6379
packets_last = tonumber(packets_last)
6480
pfc_rx_packets_last = tonumber(pfc_rx_packets_last)
6581
pfc_duration_last = tonumber(pfc_duration_last)
82+
local storm_condition = ((quantatous(pfc_duration, port_id) - quantatous(pfc_duration_last, port_id)) > poll_time * 0.8)
6683

6784
-- Check actual condition of queue being in PFC storm
6885
if (occupancy_bytes > 0 and packets - packets_last == 0 and pfc_rx_packets - pfc_rx_packets_last > 0) or
6986
-- DEBUG CODE START. Uncomment to enable
7087
(debug_storm == "enabled") or
7188
-- DEBUG CODE END.
72-
(occupancy_bytes == 0 and packets - packets_last == 0 and (pfc_duration - pfc_duration_last) > poll_time * 0.8) then
89+
(occupancy_bytes == 0 and packets - packets_last == 0 and storm_condition) then
7390
if time_left <= poll_time then
7491
redis.call('HDEL', counters_table_name .. ':' .. port_id, pfc_rx_pkt_key .. '_last')
7592
redis.call('HDEL', counters_table_name .. ':' .. port_id, pfc_duration_key .. '_last')

0 commit comments

Comments
 (0)