Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fboss/agent/hw/sai/switch/SaiPortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,7 @@ void SaiPortManager::removePort(const std::shared_ptr<Port>& swPort) {
addRemovedHandle(itr->first);
handles_.erase(itr);
portStats_.erase(swId);
disabledPortStats_.erase(swId);
port2SupportedStats_.erase(swId);
port2PortType_.erase(swId);
port2ClmEnabled_.erase(swId);
Expand Down Expand Up @@ -3356,9 +3357,19 @@ void SaiPortManager::clearStats(PortID port) {
auto now = duration_cast<seconds>(system_clock::now().time_since_epoch());
portStatItr->second->updateStats(curPortStats, now);
}
auto savedItr = disabledPortStats_.find(port);
if (savedItr != disabledPortStats_.end()) {
savedItr->second.inDiscards_() = 0;
}
}

void SaiPortManager::clearInterfacePhyCounters(const PortID& portId) {
auto savedItr = disabledPortStats_.find(portId);
if (savedItr != disabledPortStats_.end()) {
savedItr->second.fecCorrectableErrors() = 0;
savedItr->second.fecUncorrectableErrors() = 0;
savedItr->second.fecCorrectedSymbols_() = 0;
}
auto portStatItr = portStats_.find(portId);
if (portStatItr == portStats_.end()) {
return;
Expand Down
4 changes: 4 additions & 0 deletions fboss/agent/hw/sai/switch/SaiPortManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ class SaiPortManager {
// retain removed port handle so it does not invoke remove port api.
Handles removedHandles_;
Stats portStats_;
// Last stats of admin-disabled ports, used to seed portStats_ on re-enable so
// software-accumulated counters (inDiscards_, clear-on-read FEC/PFC duration)
// stay monotonic like the HW-cumulative ones.
std::unordered_map<PortID, HwPortStats> disabledPortStats_;
std::map<PortID, PrbsStatsTable> portAsicPrbsStats_;

std::optional<SaiPortTraits::Attributes::PtpMode> getPtpMode() const;
Expand Down
20 changes: 19 additions & 1 deletion fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "fboss/agent/AgentFeatures.h"
#include "fboss/agent/FbossError.h"
#include "fboss/agent/hw/HwPortFb303Stats.h"
#include "fboss/agent/hw/gen-cpp2/hardware_stats_constants.h"
#include "fboss/agent/hw/sai/store/SaiStore.h"
#include "fboss/agent/hw/sai/switch/ConcurrentIndices.h"
#include "fboss/agent/hw/sai/switch/SaiAclTableManager.h"
Expand Down Expand Up @@ -571,6 +572,15 @@ void SaiPortManager::changePortImpl(
HwAsic::Feature::SLL_HLL_DISCARD_COUNTERS),
platform_->getAsic()->isSupported(
HwAsic::Feature::PORT_LATCH_STATUS)));
auto savedItr = disabledPortStats_.find(newPort->getID());
if (savedItr != disabledPortStats_.end()) {
auto& savedStats = savedItr->second;
savedStats.portName_() = newPort->getName();
portStats_.find(newPort->getID())
->second->updateStats(
savedStats, std::chrono::seconds(*savedStats.timestamp_()));
disabledPortStats_.erase(savedItr);
}
} else if (oldPort->getName() != newPort->getName()) {
// Port was already enabled, but Port name changed - update stats
portStats_.find(newPort->getID())
Expand All @@ -583,7 +593,15 @@ void SaiPortManager::changePortImpl(
}
} else if (oldPort->isEnabled()) {
// Port transitioned from enabled to disabled, remove stats
portStats_.erase(newPort->getID());
auto statsItr = portStats_.find(newPort->getID());
if (statsItr != portStats_.end()) {
const auto& lastStats = statsItr->second->portStats();
if (*lastStats.timestamp_() !=
hardware_stats_constants::STAT_UNINITIALIZED()) {
disabledPortStats_[newPort->getID()] = lastStats;
}
portStats_.erase(statsItr);
}
}
// Before the qos policy: on TU1, VC create on a second port of an input
// buffer fails with INVALID PARAMETER once QUEUE_TO_VC is bound to it.
Expand Down
52 changes: 52 additions & 0 deletions fboss/agent/hw/sai/switch/tests/PortManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,58 @@ TEST_F(PortManagerTest, collectStatsAfterPortDisable) {
checkCounterExport(swPort->getName(), ExpectExport::NO_EXPORT);
}

class PortManagerAccumulatedStatsTest : public PortManagerTest {
protected:
// Seeds the software-accumulated counters, then admin-disables the port.
std::shared_ptr<Port> addPortAndDisable() {
std::shared_ptr<Port> swPort = makePort(p0);
saiManagerTable->portManager().addPort(swPort);
saiManagerTable->portManager().updateStats(swPort->getID());
auto* portStat = const_cast<HwPortFb303Stats*>(
saiManagerTable->portManager().getLastPortStat(swPort->getID()));
CHECK(portStat);
auto stats = portStat->portStats();
stats.inDiscards_() = 1000;
stats.fecCorrectableErrors() = 20;
portStat->updateStats(stats, std::chrono::seconds{*stats.timestamp_()});
auto disabledPort = swPort->clone();
disabledPort->setAdminState(cfg::PortState::DISABLED);
saiManagerTable->portManager().changePort(swPort, disabledPort);
return disabledPort;
}

void enable(const std::shared_ptr<Port>& disabledPort) {
auto enabledPort = disabledPort->clone();
enabledPort->setAdminState(cfg::PortState::ENABLED);
saiManagerTable->portManager().changePort(disabledPort, enabledPort);
}

const HwPortStats& lastStats(PortID port) {
auto* portStat = saiManagerTable->portManager().getLastPortStat(port);
CHECK(portStat);
return portStat->portStats();
}
};

TEST_F(PortManagerAccumulatedStatsTest, preservedAcrossDisableEnable) {
auto port = addPortAndDisable();
enable(port);
EXPECT_EQ(*lastStats(port->getID()).inDiscards_(), 1000);
EXPECT_EQ(*lastStats(port->getID()).fecCorrectableErrors(), 20);
saiManagerTable->portManager().updateStats(port->getID());
EXPECT_EQ(*lastStats(port->getID()).inDiscards_(), 1000);
EXPECT_EQ(*lastStats(port->getID()).fecCorrectableErrors(), 20);
}

TEST_F(PortManagerAccumulatedStatsTest, clearWhileDisabled) {
auto port = addPortAndDisable();
saiManagerTable->portManager().clearStats(port->getID());
saiManagerTable->portManager().clearInterfacePhyCounters(port->getID());
enable(port);
EXPECT_EQ(*lastStats(port->getID()).inDiscards_(), 0);
EXPECT_EQ(*lastStats(port->getID()).fecCorrectableErrors(), 0);
}

TEST_F(PortManagerTest, subsumedPorts) {
// Port P0 has a port ID 0 and only be configured with all speeds.
checkSubsumedPorts(p0, cfg::PortSpeed::XG, {});
Expand Down
Loading