diff --git a/fboss/agent/hw/bcm/BcmPort.cpp b/fboss/agent/hw/bcm/BcmPort.cpp index 77fc7a2e47617..ec4e051f3813f 100644 --- a/fboss/agent/hw/bcm/BcmPort.cpp +++ b/fboss/agent/hw/bcm/BcmPort.cpp @@ -243,6 +243,17 @@ static const std::string getFdrStatsKey(int errorsPerCodeword) { return folly::to(kErrorsPerCodeword(), ".", errorsPerCodeword); } +static const std::vector allPfcPriorities() { + static std::vector priorities; + if (priorities.empty()) { + for (int i = 0; i <= cfg::switch_config_constants::PFC_PRIORITY_VALUE_MAX(); + i++) { + priorities.push_back(PfcPriority(i)); + } + } + return priorities; +} + } // namespace namespace facebook::fboss { @@ -355,7 +366,7 @@ void BcmPort::reinitPortPfcStats(const std::shared_ptr& swPort) { XLOG(DBG3) << "Reinitializing PFC stats for " << portName; // Reinit per priority PFC statistics - for (auto priority : swPort->getPfcPriorities()) { + for (auto priority : allPfcPriorities()) { reinitPortStat(getPfcPriorityStatsKey(kInPfc(), priority), portName); reinitPortStat(getPfcPriorityStatsKey(kInPfcXon(), priority), portName); reinitPortStat(getPfcPriorityStatsKey(kOutPfc(), priority), portName); @@ -1064,15 +1075,13 @@ void BcmPort::setupStatsIfNeeded(const std::shared_ptr& swPort) { // - updated (2,6 -> 2,7) // Clear the existing counters and reinit the new list if (savedPort) { - auto pfcPriorities = savedPort->getPfcPriorities(); - removePortPfcStatsLocked(lockedPortStatsPtr, swPort, pfcPriorities); + removePortPfcStatsLocked(lockedPortStatsPtr, swPort, allPfcPriorities()); } reinitPortStatsLocked(lockedPortStatsPtr, swPort); } if (savedPort && hasPfcStatusChangedToDisabled(savedPort, swPort)) { // Remove stats in case PFC is disabled for previously enabled priorities - auto pfcPriorities = savedPort->getPfcPriorities(); - removePortPfcStatsLocked(lockedPortStatsPtr, swPort, pfcPriorities); + removePortPfcStatsLocked(lockedPortStatsPtr, swPort, allPfcPriorities()); } // Set bcmPortControlStatOversize to max frame size so that we don't trigger @@ -1469,8 +1478,7 @@ void BcmPort::updateStats() { // InDiscards will be read along with PFC if PFC is enabled if (settings && settings->getPfc().has_value()) { - auto pfcPriorities = settings->getPfcPriorities(); - updatePortPfcStats(now, curPortStats, pfcPriorities); + updatePortPfcStats(now, curPortStats, allPfcPriorities()); } else { updateStat( now, diff --git a/fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp b/fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp index c5a099dd518aa..d31874efcbc72 100644 --- a/fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp +++ b/fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp @@ -84,6 +84,17 @@ SaiPortTraits::AdapterHostKey getPortAdapterHostKeyFromAttr( return portKey; } +static const std::vector allPfcPriorities() { + static std::vector priorities; + if (priorities.empty()) { + for (int i = 0; i <= cfg::switch_config_constants::PFC_PRIORITY_VALUE_MAX(); + i++) { + priorities.push_back(PfcPriority(i)); + } + } + return priorities; +} + } // namespace void SaiPortManager::fillInSupportedStats(PortID port) { @@ -246,7 +257,7 @@ PortSaiId SaiPortManager::addPortImpl(const std::shared_ptr& swPort) { portStats_.emplace( swPort->getID(), std::make_unique( - swPort->getName(), queueId2Name, swPort->getPfcPriorities())); + swPort->getName(), queueId2Name, allPfcPriorities())); } bool samplingMirror = swPort->getSampleDestination().has_value() &&