Skip to content

Commit 640547a

Browse files
leoli-npslguohan
authored andcommitted
[Pfc-wd]: Add pfc-wd support for nephos (sonic-net#817)
* [Pfc-wd]: Add pfc-wd support for nephos * [Pfc-wd]: Update pfc_detect_nephos.lua according to the modification of PR#794
1 parent e329dbd commit 640547a

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

orchagent/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dist_swss_DATA = \
88
pfc_detect_mellanox.lua \
99
pfc_detect_broadcom.lua \
1010
pfc_detect_barefoot.lua \
11+
pfc_detect_nephos.lua \
1112
pfc_restore.lua \
1213
watermark_queue.lua \
1314
watermark_pg.lua

orchagent/orch.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const char state_db_key_delimiter = '|';
3636
#define BRCM_PLATFORM_SUBSTRING "broadcom"
3737
#define BFN_PLATFORM_SUBSTRING "barefoot"
3838
#define VS_PLATFORM_SUBSTRING "vs"
39+
#define NPS_PLATFORM_SUBSTRING "nephos"
3940

4041
#define CONFIGDB_KEY_SEPARATOR "|"
4142
#define DEFAULT_KEY_SEPARATOR ":"

orchagent/orchdaemon.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ bool OrchDaemon::init()
217217
CFG_PFC_WD_TABLE_NAME
218218
};
219219

220-
if (platform == MLNX_PLATFORM_SUBSTRING)
220+
if (platform == MLNX_PLATFORM_SUBSTRING
221+
|| platform == NPS_PLATFORM_SUBSTRING)
221222
{
222223

223224
static const vector<sai_port_stat_t> portStatIds =

orchagent/pfc_detect_nephos.lua

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
-- KEYS - queue IDs
2+
-- ARGV[1] - counters db index
3+
-- ARGV[2] - counters table name
4+
-- ARGV[3] - poll time interval
5+
-- return queue Ids that satisfy criteria
6+
7+
local counters_db = ARGV[1]
8+
local counters_table_name = ARGV[2]
9+
local poll_time = tonumber(ARGV[3])
10+
11+
local rets = {}
12+
13+
redis.call('SELECT', counters_db)
14+
15+
-- Iterate through each queue
16+
local n = table.getn(KEYS)
17+
for i = n, 1, -1 do
18+
local counter_keys = redis.call('HKEYS', counters_table_name .. ':' .. KEYS[i])
19+
local counter_num = 0
20+
local old_counter_num = 0
21+
local is_deadlock = false
22+
local pfc_wd_status = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'PFC_WD_STATUS')
23+
local pfc_wd_action = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'PFC_WD_ACTION')
24+
local big_red_switch_mode = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'BIG_RED_SWITCH_MODE')
25+
if not big_red_switch_mode and (pfc_wd_status == 'operational' or pfc_wd_action == 'alert') then
26+
local detection_time = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'PFC_WD_DETECTION_TIME')
27+
if detection_time then
28+
detection_time = tonumber(detection_time)
29+
local time_left = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'PFC_WD_DETECTION_TIME_LEFT')
30+
if not time_left then
31+
time_left = detection_time
32+
else
33+
time_left = tonumber(time_left)
34+
end
35+
36+
local queue_index = redis.call('HGET', 'COUNTERS_QUEUE_INDEX_MAP', KEYS[i])
37+
local port_id = redis.call('HGET', 'COUNTERS_QUEUE_PORT_MAP', KEYS[i])
38+
local pfc_rx_pkt_key = 'SAI_PORT_STAT_PFC_' .. queue_index .. '_RX_PKTS'
39+
local pfc_duration_key = 'SAI_PORT_STAT_PFC_' .. queue_index .. '_RX_PAUSE_DURATION'
40+
41+
-- Get all counters
42+
local occupancy_bytes = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES')
43+
local packets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_QUEUE_STAT_PACKETS')
44+
local pfc_rx_packets = redis.call('HGET', counters_table_name .. ':' .. port_id, pfc_rx_pkt_key)
45+
local pfc_duration = redis.call('HGET', counters_table_name .. ':' .. port_id, pfc_duration_key)
46+
47+
if occupancy_bytes and packets and pfc_rx_packets and pfc_duration then
48+
occupancy_bytes = tonumber(occupancy_bytes)
49+
packets = tonumber(packets)
50+
pfc_rx_packets = tonumber(pfc_rx_packets)
51+
pfc_duration = tonumber(pfc_duration)
52+
53+
local packets_last = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_QUEUE_STAT_PACKETS_last')
54+
local pfc_rx_packets_last = redis.call('HGET', counters_table_name .. ':' .. port_id, pfc_rx_pkt_key .. '_last')
55+
local pfc_duration_last = redis.call('HGET', counters_table_name .. ':' .. port_id, pfc_duration_key .. '_last')
56+
-- DEBUG CODE START. Uncomment to enable
57+
local debug_storm = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'DEBUG_STORM')
58+
-- DEBUG CODE END.
59+
60+
-- If this is not a first run, then we have last values available
61+
if packets_last and pfc_rx_packets_last and pfc_duration_last then
62+
packets_last = tonumber(packets_last)
63+
pfc_rx_packets_last = tonumber(pfc_rx_packets_last)
64+
pfc_duration_last = tonumber(pfc_duration_last)
65+
66+
-- Check actual condition of queue being in PFC storm
67+
if (occupancy_bytes > 0 and packets - packets_last == 0 and pfc_rx_packets - pfc_rx_packets_last > 0) or
68+
-- DEBUG CODE START. Uncomment to enable
69+
(debug_storm == "enabled") or
70+
-- DEBUG CODE END.
71+
(occupancy_bytes == 0 and packets - packets_last == 0 and (pfc_duration - pfc_duration_last) > poll_time * 0.8) then
72+
if time_left <= poll_time then
73+
redis.call('PUBLISH', 'PFC_WD_ACTION', '["' .. KEYS[i] .. '","storm"]')
74+
is_deadlock = true
75+
time_left = detection_time
76+
else
77+
time_left = time_left - poll_time
78+
end
79+
else
80+
if pfc_wd_action == 'alert' and pfc_wd_status ~= 'operational' then
81+
redis.call('PUBLISH', 'PFC_WD_ACTION', '["' .. KEYS[i] .. '","restore"]')
82+
end
83+
time_left = detection_time
84+
end
85+
end
86+
87+
-- Save values for next run
88+
redis.call('HSET', counters_table_name .. ':' .. KEYS[i], 'SAI_QUEUE_STAT_PACKETS_last', packets)
89+
redis.call('HSET', counters_table_name .. ':' .. KEYS[i], 'PFC_WD_DETECTION_TIME_LEFT', time_left)
90+
redis.call('HSET', counters_table_name .. ':' .. port_id, pfc_rx_pkt_key .. '_last', pfc_rx_packets)
91+
redis.call('HDEL', counters_table_name .. ':' .. port_id, pfc_duration_key .. '_last')
92+
redis.call('HSET', counters_table_name .. ':' .. port_id, pfc_duration_key .. '_last', pfc_duration)
93+
end
94+
end
95+
end
96+
end
97+
98+
return rets
99+

0 commit comments

Comments
 (0)