Skip to content

Commit

Permalink
[mellanox] convert logic to use quanta in pfc_detect_mellanox.lua (#930)
Browse files Browse the repository at this point in the history
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 <stepanb@mellanox.com>
  • Loading branch information
stepanblyschak authored and lguohan committed Jun 19, 2019
1 parent 67c0940 commit 407d048
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion orchagent/pfc_detect_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ local counters_db = ARGV[1]
local counters_table_name = ARGV[2]
local poll_time = tonumber(ARGV[3])

local asic_db = "1"
local asic_db_port_table = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"

local quanta_size = 512

local rets = {}

redis.call('SELECT', counters_db)

local function port_speed_get(port_id)
redis.call('SELECT', asic_db)
local port_speed = redis.call('HGET', asic_db_port_table .. ':' .. port_id, 'SAI_PORT_ATTR_SPEED')
redis.call('SELECT', counters_db)
return tonumber(port_speed)
end

local function quantatous(quanta, port_id)
return quanta * quanta_size / port_speed_get(port_id)
end

-- Iterate through each queue
local n = table.getn(KEYS)
for i = n, 1, -1 do
Expand Down Expand Up @@ -63,13 +79,14 @@ for i = n, 1, -1 do
packets_last = tonumber(packets_last)
pfc_rx_packets_last = tonumber(pfc_rx_packets_last)
pfc_duration_last = tonumber(pfc_duration_last)
local storm_condition = ((quantatous(pfc_duration, port_id) - quantatous(pfc_duration_last, port_id)) > poll_time * 0.8)

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

0 comments on commit 407d048

Please sign in to comment.