From 407d04835c5f6d01637fa0f7791fa626a317ae84 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Wed, 19 Jun 2019 12:06:20 +0300 Subject: [PATCH] [mellanox] convert logic to use quanta in pfc_detect_mellanox.lua (#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 --- orchagent/pfc_detect_mellanox.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/orchagent/pfc_detect_mellanox.lua b/orchagent/pfc_detect_mellanox.lua index e77137b2879a..f436808451fa 100644 --- a/orchagent/pfc_detect_mellanox.lua +++ b/orchagent/pfc_detect_mellanox.lua @@ -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 @@ -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')