Skip to content

Commit

Permalink
Report fb303 stats for all PFC priorities
Browse files Browse the repository at this point in the history
Summary: To catch PFC related bugs, report fb303 stats for all PFC priorities 0..7, even if they are not supposedly enabled.

Differential Revision: D66481592

fbshipit-source-id: 642f83bb2962c8e46996c5821d60a69a50744acf
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Nov 27, 2024
1 parent 4d395c4 commit 5e288ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
22 changes: 15 additions & 7 deletions fboss/agent/hw/bcm/BcmPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ static const std::string getFdrStatsKey(int errorsPerCodeword) {
return folly::to<std::string>(kErrorsPerCodeword(), ".", errorsPerCodeword);
}

static const std::vector<PfcPriority> allPfcPriorities() {
static std::vector<PfcPriority> 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 {
Expand Down Expand Up @@ -355,7 +366,7 @@ void BcmPort::reinitPortPfcStats(const std::shared_ptr<Port>& 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);
Expand Down Expand Up @@ -1064,15 +1075,13 @@ void BcmPort::setupStatsIfNeeded(const std::shared_ptr<Port>& 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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ SaiPortTraits::AdapterHostKey getPortAdapterHostKeyFromAttr(
return portKey;
}

static const std::vector<PfcPriority> allPfcPriorities() {
static std::vector<PfcPriority> 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) {
Expand Down Expand Up @@ -246,7 +257,7 @@ PortSaiId SaiPortManager::addPortImpl(const std::shared_ptr<Port>& swPort) {
portStats_.emplace(
swPort->getID(),
std::make_unique<HwPortFb303Stats>(
swPort->getName(), queueId2Name, swPort->getPfcPriorities()));
swPort->getName(), queueId2Name, allPfcPriorities()));
}

bool samplingMirror = swPort->getSampleDestination().has_value() &&
Expand Down

0 comments on commit 5e288ae

Please sign in to comment.