Skip to content

Commit

Permalink
Implement PG buffer profile removal flow on SAI
Browse files Browse the repository at this point in the history
Summary: Implement PG buffer profile removal flow on SAI

Reviewed By: nivinl

Differential Revision:
D67122815

Privacy Context Container: L1125642

fbshipit-source-id: 682b9ac193d7a3579b7833db93a419ede7b2a180
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Dec 13, 2024
1 parent 9cd6c8d commit a6f5d6a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
47 changes: 37 additions & 10 deletions fboss/agent/hw/sai/switch/SaiPortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,18 +896,23 @@ SaiPortManager::getIngressPriorityGroupSaiIds(
return ingressPgSaiIds;
}

void SaiPortManager::programPfcBuffers(const std::shared_ptr<Port>& swPort) {
void SaiPortManager::changePfcBuffers(
std::shared_ptr<Port> oldPort,
std::shared_ptr<Port> newPort) {
if (!platform_->getAsic()->isSupported(HwAsic::Feature::BUFFER_POOL)) {
return;
}
SaiPortHandle* portHandle = getPortHandle(swPort->getID());
const auto& portPgCfgs = swPort->getPortPgConfigs();
if (portPgCfgs) {
const auto& ingressPgSaiIds = getIngressPriorityGroupSaiIds(swPort);
SaiPortHandle* portHandle = getPortHandle(newPort->getID());
auto& configuredIpgs = portHandle->configuredIngressPriorityGroups;

const auto& newPortPgCfgs = newPort->getPortPgConfigs();
std::set<int> programmedPgIds;
if (newPortPgCfgs) {
const auto& ingressPgSaiIds = getIngressPriorityGroupSaiIds(newPort);
auto ingressPriorityGroupHandles =
managerTable_->bufferManager().loadIngressPriorityGroups(
ingressPgSaiIds);
for (const auto& portPgCfg : *portPgCfgs) {
for (const auto& portPgCfg : *newPortPgCfgs) {
// THRIFT_COPY
auto portPgCfgThrift = portPgCfg->toThrift();
auto pgId = *portPgCfgThrift.id();
Expand All @@ -918,10 +923,32 @@ void SaiPortManager::programPfcBuffers(const std::shared_ptr<Port>& swPort) {
ingressPriorityGroupHandles[pgId]->ingressPriorityGroup,
bufferProfile);
// Keep track of ingressPriorityGroupHandle and bufferProfile per PG ID
portHandle
->configuredIngressPriorityGroups[static_cast<IngressPriorityGroupID>(
pgId)] = SaiIngressPriorityGroupHandleAndProfile{
std::move(ingressPriorityGroupHandles[pgId]), bufferProfile};
configuredIpgs[static_cast<IngressPriorityGroupID>(pgId)] =
SaiIngressPriorityGroupHandleAndProfile{
std::move(ingressPriorityGroupHandles[pgId]), bufferProfile};
programmedPgIds.insert(pgId);
}
}

// Delete removed buffer profiles.
if (oldPort != nullptr) {
const auto& oldPortPgCfgs = oldPort->getPortPgConfigs();
if (oldPortPgCfgs) {
for (const auto& portPgCfg : *oldPortPgCfgs) {
// THRIFT_COPY
auto portPgCfgThrift = portPgCfg->toThrift();
auto pgId = *portPgCfgThrift.id();
if (programmedPgIds.find(pgId) == programmedPgIds.end()) {
auto ipgInfo =
configuredIpgs.find(static_cast<IngressPriorityGroupID>(pgId));
if (ipgInfo != configuredIpgs.end()) {
managerTable_->bufferManager().setIngressPriorityGroupBufferProfile(
ipgInfo->second.pgHandle->ingressPriorityGroup,
std::nullptr_t());
configuredIpgs.erase(ipgInfo);
}
}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion fboss/agent/hw/sai/switch/SaiPortManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ class SaiPortManager {
const std::shared_ptr<Port>& newPort);
void removePfcWatchdog(const std::shared_ptr<Port>& swPort);
void setPortType(PortID portId, cfg::PortType portType);
void programPfcBuffers(const std::shared_ptr<Port>& swPort);
void changePfcBuffers(
std::shared_ptr<Port> oldPort,
std::shared_ptr<Port> newPort);
void removePfcBuffers(const std::shared_ptr<Port>& swPort);
sai_port_prbs_config_t getSaiPortPrbsConfig(bool enabled) const;
void initAsicPrbsStats(const std::shared_ptr<Port>& swPort);
Expand Down
4 changes: 2 additions & 2 deletions fboss/agent/hw/sai/switch/npu/SaiPortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ PortSaiId SaiPortManager::addPortImpl(const std::shared_ptr<Port>& swPort) {
addSamplePacket(swPort);
addNode(swPort);
addPfc(swPort);
programPfcBuffers(swPort);
changePfcBuffers(nullptr, swPort);

// set platform port's speed
auto platformPort = platform_->getPort(swPort->getID());
Expand Down Expand Up @@ -355,7 +355,7 @@ void SaiPortManager::changePortImpl(
changePfc(oldPort, newPort);
changeRxLaneSquelch(oldPort, newPort);
changeTxEnable(oldPort, newPort);
programPfcBuffers(newPort);
changePfcBuffers(oldPort, newPort);

if (newPort->isEnabled()) {
if (!oldPort->isEnabled()) {
Expand Down

0 comments on commit a6f5d6a

Please sign in to comment.