From 29911b6e76a81a0e52473fb3bc9a8c81ad99328e Mon Sep 17 00:00:00 2001 From: BrandonCheng0121 Date: Thu, 25 Jun 2026 16:07:13 +0800 Subject: [PATCH] [Accton][wedge800cact] Fix warmboot VerifyHostToQueueMappingClassID failure Regarding the T1 warmboot.AgentQueuePerHostL2Test.VerifyHostToQueueMappingClassID failure, the issue is a warmboot stats race condition. The test gets stale cached ACL stats within milliseconds of warmboot completing because the background stats thread only updates every 1 second. Solution: Explicitly call updateStats() in SwSwitch::initialConfigApplied() after warmboot completes to immediately sync hardware stats to software cache. --- fboss/agent/SwSwitch.cpp | 14 ++++++++++++++ .../agent_hw_tests/AgentQueuePerHostL2Tests.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/fboss/agent/SwSwitch.cpp b/fboss/agent/SwSwitch.cpp index 706777ee77f21..7d89057be8b0d 100644 --- a/fboss/agent/SwSwitch.cpp +++ b/fboss/agent/SwSwitch.cpp @@ -1649,6 +1649,20 @@ void SwSwitch::initialConfigApplied( sendNeighborSolicitationForConfiguredInterfaces("warm boot"); sendArpRequestForConfiguredInterfaces("warm boot"); + // After warmboot completes, immediately synchronize hardware stats to + // software cache (hwSwitchStats_). This ensures that tests reading stats + // immediately after warmboot get correct values instead of stale cached + // data. The background stats thread normally updates cache every 1 second, + // but tests may read stats within milliseconds of warmboot completing. + + try { + XLOG(DBG2) << "Warm boot: synchronizing hardware stats to software cache"; + updateStats(); + XLOG(DBG2) << "Warm boot: stats synchronization completed"; + } catch (const std::exception& ex) { + XLOG(ERR) << "Warm boot: stats synchronization failed: " << ex.what(); + } + if (flags_ & SwitchFlags::PUBLISH_STATS) { stats()->switchConfiguredMs( duration_cast( diff --git a/fboss/agent/test/agent_hw_tests/AgentQueuePerHostL2Tests.cpp b/fboss/agent/test/agent_hw_tests/AgentQueuePerHostL2Tests.cpp index e1a3bac626964..a5041b4f873f6 100644 --- a/fboss/agent/test/agent_hw_tests/AgentQueuePerHostL2Tests.cpp +++ b/fboss/agent/test/agent_hw_tests/AgentQueuePerHostL2Tests.cpp @@ -47,6 +47,8 @@ class AgentQueuePerHostL2Test : public AgentHwTest { auto ttlCounterName = utility::getQueuePerHostTtlCounterName(); auto statBefore = utility::getAclInOutPackets(getSw(), ttlCounterName); + XLOG(DBG2) << "ACL counter '" << ttlCounterName + << "' statBefore = " << statBefore; std::map beforeQueueOutPkts; for (const auto& queueId : utility::kQueuePerhostQueueIds()) { @@ -132,6 +134,10 @@ class AgentQueuePerHostL2Test : public AgentHwTest { auto statAfter = utility::getAclInOutPackets(this->getSw(), ttlCounterName); + XLOG(DBG2) << "ACL counter '" << ttlCounterName + << "' statBefore = " << statBefore + << ", statAfter = " << statAfter + << ", delta = " << (statAfter - statBefore); /* * counts ttl >= 128 packet only * but L2 traffic (so TTL is not decremented, and thus looped back