Skip to content

Commit 3b70292

Browse files
authored
Move timestamps out of counter table to avoid update too frequently (sonic-net#75)
<!-- Please make sure you have read and understood the contribution guildlines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md 1. Make sure your commit includes a signature generted with `git commit -s` 2. Make sure your commit title follows the correct format: [component]: description 3. Make sure your commit message contains enough details about the change and related tests 4. Make sure your pull request adds related reviewers, asignees, labels Please also provide the following information in this pull request: --> **What I did** The timestamp of PFC watchdog polling is moved out of the COUNTER table. The PFC watchdog Lua plugin should be adjusted accordingly. **Why I did it** **How I verified it** **Details if related**
1 parent 3fa0d72 commit 3b70292

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

orchagent/pfc_detect_mellanox.lua

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,22 @@ if timestamp_last ~= false then
2525
redis.call('HSET', 'TIMESTAMP', 'effective_pfcwd_poll_time_last', global_effective_poll_time)
2626
end
2727

28+
-- Get timestamp from TIME_STAMP table for PFC_WD counters
29+
-- Use a field name without spaces to avoid issues
30+
local port_timestamp_current = tonumber(redis.call('HGET', 'COUNTERS:TIME_STAMP', 'PFC_WD_Port_Counter_time_stamp'))
31+
local port_timestamp_last = tonumber(redis.call('HGET', 'COUNTERS:TIME_STAMP', 'PFC_WD_Port_Counter_time_stamp_last'))
32+
33+
-- Update the last timestamp for all ports at once
34+
if port_timestamp_current ~= nil then
35+
redis.call('HSET', 'COUNTERS:TIME_STAMP', 'PFC_WD_Port_Counter_time_stamp_last', port_timestamp_current)
36+
end
37+
2838
local effective_poll_time
29-
local effective_poll_time_lasttime
30-
local port_timestamp_last_cache = {}
39+
if port_timestamp_current ~= nil and port_timestamp_last ~= nil then
40+
effective_poll_time = (port_timestamp_current - port_timestamp_last) / 1000
41+
else
42+
effective_poll_time = global_effective_poll_time
43+
end
3144

3245
local debug_storm_global = redis.call('HGET', 'DEBUG_STORM', 'enabled') == 'true'
3346
local debug_storm_threshold = tonumber(redis.call('HGET', 'DEBUG_STORM', 'threshold'))
@@ -63,27 +76,6 @@ for i = n, 1, -1 do
6376
local pfc_rx_pkt_key = 'SAI_PORT_STAT_PFC_' .. queue_index .. '_RX_PKTS'
6477
local pfc_duration_key = 'SAI_PORT_STAT_PFC_' .. queue_index .. '_RX_PAUSE_DURATION_US'
6578

66-
-- Get port specific timestamp
67-
local port_timestamp_current = tonumber(redis.call('HGET', counters_table_name .. ':' .. port_id, 'PFC_WD_time_stamp'))
68-
if port_timestamp_current ~= nil then
69-
local port_timestamp_lasttime = port_timestamp_last_cache[port_id]
70-
if port_timestamp_lasttime == nil then
71-
port_timestamp_lasttime = tonumber(redis.call('HGET', counters_table_name .. ':' .. port_id, 'PFC_WD_time_stamp_last'))
72-
port_timestamp_last_cache[port_id] = port_timestamp_lasttime
73-
redis.call('HSET', counters_table_name .. ':' .. port_id, 'PFC_WD_time_stamp_last', port_timestamp_current)
74-
end
75-
76-
if port_timestamp_lasttime ~= nil then
77-
effective_poll_time = (port_timestamp_current - port_timestamp_lasttime) / 1000
78-
else
79-
effective_poll_time = global_effective_poll_time
80-
end
81-
effective_poll_time_lasttime = false
82-
else
83-
effective_poll_time = global_effective_poll_time
84-
effective_poll_time_lasttime = global_effective_poll_time_lasttime
85-
end
86-
8779
-- Get all counters
8880
local occupancy_bytes = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES')
8981
local packets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_QUEUE_STAT_PACKETS')
@@ -132,8 +124,8 @@ for i = n, 1, -1 do
132124
local pfc_rx_packets_string = '"pfc_rx_packets","' .. tostring(pfc_rx_packets) .. '","pfc_rx_packets_last","' .. tostring(pfc_rx_packets_last) .. '",'
133125
local storm_condition_string = '"pfc_duration","' .. tostring(pfc_duration) .. '","pfc_duration_last","' .. tostring(pfc_duration_last) .. '",'
134126
local timestamps = '"timestamp","' .. timestamp_string .. '","timestamp_last","' .. timestamp_last .. '","effective_poll_time","' .. effective_poll_time .. '"'
135-
if effective_poll_time_lasttime ~= false then
136-
timestamps = timestamps .. ',"effective_pfcwd_poll_time_last","' .. effective_poll_time_lasttime .. '"'
127+
if global_effective_poll_time_lasttime ~= false then
128+
timestamps = timestamps .. ',"effective_pfcwd_poll_time_last","' .. global_effective_poll_time_lasttime .. '"'
137129
end
138130
redis.call('PUBLISH', 'PFC_WD_ACTION', '["' .. KEYS[i] .. '","storm",' .. occupancy_string .. packets_string .. pfc_rx_packets_string .. storm_condition_string .. timestamps .. ']')
139131
is_deadlock = true

0 commit comments

Comments
 (0)