Skip to content

Commit

Permalink
DLB: SAI switch impl for ARS profile
Browse files Browse the repository at this point in the history
Summary: ARS profile manager implementation with add/remove/update APIs

Reviewed By: srikrishnagopu

Differential Revision: D54755165

fbshipit-source-id: 3202808dbcdd0dae9751635c2e04957835833ff1
  • Loading branch information
Ravi Vantipalli authored and facebook-github-bot committed Aug 14, 2024
1 parent c144257 commit b00506d
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmake/AgentHwSaiSwitch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(SAI_SWITCH_SRC
fboss/agent/hw/sai/switch/SaiAclTableGroupManager.cpp
fboss/agent/hw/sai/switch/SaiAclTableManager.cpp
fboss/agent/hw/sai/switch/SaiArsManager.cpp
fboss/agent/hw/sai/switch/SaiArsProfileManager.cpp
fboss/agent/hw/sai/switch/SaiBridgeManager.cpp
fboss/agent/hw/sai/switch/SaiBufferManager.cpp
fboss/agent/hw/sai/switch/SaiCounterManager.cpp
Expand Down
4 changes: 2 additions & 2 deletions fboss/agent/hw/sai/api/ArsProfileApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct SaiArsProfileTraits {
using PortLoadPastWeight = SaiAttribute<
EnumType,
SAI_ARS_PROFILE_ATTR_PORT_LOAD_PAST_WEIGHT,
sai_uint32_t>;
sai_uint8_t>;
using LoadPastMinVal = SaiAttribute<
EnumType,
SAI_ARS_PROFILE_ATTR_LOAD_PAST_MIN_VAL,
Expand All @@ -67,7 +67,7 @@ struct SaiArsProfileTraits {
using PortLoadFutureWeight = SaiAttribute<
EnumType,
SAI_ARS_PROFILE_ATTR_PORT_LOAD_FUTURE_WEIGHT,
sai_uint32_t>;
sai_uint8_t>;
using LoadFutureMinVal = SaiAttribute<
EnumType,
SAI_ARS_PROFILE_ATTR_LOAD_FUTURE_MIN_VAL,
Expand Down
99 changes: 99 additions & 0 deletions fboss/agent/hw/sai/switch/SaiArsProfileManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#include "fboss/agent/hw/sai/switch/SaiArsProfileManager.h"

#include "fboss/agent/hw/sai/store/SaiStore.h"
#include "fboss/agent/hw/sai/switch/SaiManagerTable.h"

#include "fboss/agent/platforms/sai/SaiPlatform.h"

namespace facebook::fboss {

SaiArsProfileManager::SaiArsProfileManager(
SaiStore* saiStore,
SaiManagerTable* managerTable,
const SaiPlatform* platform)
: saiStore_(saiStore), managerTable_(managerTable), platform_(platform) {
#if SAI_API_VERSION >= SAI_VERSION(1, 14, 0)
arsProfileHandle_ = std::make_unique<SaiArsProfileHandle>();
#endif
}

#if SAI_API_VERSION >= SAI_VERSION(1, 14, 0)

SaiArsProfileTraits::CreateAttributes SaiArsProfileManager::createAttributes(
const std::shared_ptr<FlowletSwitchingConfig>& flowletSwitchConfig) {
auto samplingInterval = flowletSwitchConfig->getDynamicSampleRate();
sai_uint32_t randomSeed = 0x5555;
auto portLoadPastWeight = flowletSwitchConfig->getDynamicEgressLoadExponent();
auto portLoadFutureWeight = flowletSwitchConfig->getDynamicQueueExponent();
auto portLoadExponent =
flowletSwitchConfig->getDynamicPhysicalQueueExponent();
auto loadPastMinVal =
flowletSwitchConfig->getDynamicEgressMinThresholdBytes();
auto loadPastMaxVal =
flowletSwitchConfig->getDynamicEgressMaxThresholdBytes();
auto loadFutureMinVal =
flowletSwitchConfig->getDynamicQueueMinThresholdBytes();
auto loadFutureMaxVal =
flowletSwitchConfig->getDynamicQueueMaxThresholdBytes();
// this is per ITM and should be half of newDynamicQueueMinThresholdBytes
// above (as we have 2 ITMs)
auto loadCurrentMinVal =
flowletSwitchConfig->getDynamicQueueMinThresholdBytes() >> 1;
auto loadCurrentMaxVal =
flowletSwitchConfig->getDynamicQueueMaxThresholdBytes() >> 1;
SaiArsProfileTraits::CreateAttributes attributes{
SAI_ARS_PROFILE_ALGO_EWMA,
samplingInterval,
randomSeed,
false, // EnableIPv4
false, // EnableIPv6
true,
portLoadPastWeight,
loadPastMinVal,
loadPastMaxVal,
true,
portLoadFutureWeight,
loadFutureMinVal,
loadFutureMaxVal,
true,
portLoadExponent,
loadCurrentMinVal,
loadCurrentMaxVal};

return attributes;
}

void SaiArsProfileManager::addArsProfile(
const std::shared_ptr<FlowletSwitchingConfig>& flowletSwitchConfig) {
auto attributes = createAttributes(flowletSwitchConfig);
auto& store = saiStore_->get<SaiArsProfileTraits>();
arsProfileHandle_->arsProfile = store.setObject(std::monostate{}, attributes);
}

void SaiArsProfileManager::removeArsProfile(
const std::shared_ptr<FlowletSwitchingConfig>& flowletSwitchConfig) {
arsProfileHandle_.reset();
}

void SaiArsProfileManager::changeArsProfile(
const std::shared_ptr<FlowletSwitchingConfig>& oldFlowletSwitchConfig,
const std::shared_ptr<FlowletSwitchingConfig>& newFlowletSwitchConfig) {
addArsProfile(newFlowletSwitchConfig);
}

SaiArsProfileHandle* SaiArsProfileManager::getArsProfileHandle() {
return arsProfileHandle_.get();
}
#endif

} // namespace facebook::fboss
65 changes: 65 additions & 0 deletions fboss/agent/hw/sai/switch/SaiArsProfileManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#pragma once

#include "fboss/agent/hw/sai/api/ArsProfileApi.h"
#include "fboss/agent/hw/sai/api/Types.h"
#include "fboss/agent/hw/sai/store/SaiObject.h"
#include "fboss/agent/state/FlowletSwitchingConfig.h"
#include "fboss/agent/types.h"

#include <memory>

namespace facebook::fboss {

class SaiManagerTable;
class SaiPlatform;
class SaiStore;

#if SAI_API_VERSION >= SAI_VERSION(1, 14, 0)
using SaiArsProfile = SaiObject<SaiArsProfileTraits>;
#endif

struct SaiArsProfileHandle {
#if SAI_API_VERSION >= SAI_VERSION(1, 14, 0)
std::shared_ptr<SaiArsProfile> arsProfile;
#endif
};

class SaiArsProfileManager {
public:
SaiArsProfileManager(
SaiStore* saiStore,
SaiManagerTable* managerTable,
const SaiPlatform* platform);
#if SAI_API_VERSION >= SAI_VERSION(1, 14, 0)
void addArsProfile(
const std::shared_ptr<FlowletSwitchingConfig>& flowletSwitchingConfig);
void removeArsProfile(
const std::shared_ptr<FlowletSwitchingConfig>& flowletSwitchingConfig);
void changeArsProfile(
const std::shared_ptr<FlowletSwitchingConfig>& oldFlowletSwitchingConfig,
const std::shared_ptr<FlowletSwitchingConfig>& newFlowletSwitchingConfig);
SaiArsProfileHandle* getArsProfileHandle();
#endif

private:
SaiStore* saiStore_;
SaiManagerTable* managerTable_;
const SaiPlatform* platform_;
#if SAI_API_VERSION >= SAI_VERSION(1, 14, 0)
SaiArsProfileTraits::CreateAttributes createAttributes(
const std::shared_ptr<FlowletSwitchingConfig>& flowletSwitchingConfig);
std::unique_ptr<SaiArsProfileHandle> arsProfileHandle_;
#endif
};

} // namespace facebook::fboss
11 changes: 11 additions & 0 deletions fboss/agent/hw/sai/switch/SaiManagerTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "fboss/agent/hw/sai/switch/SaiAclTableGroupManager.h"
#include "fboss/agent/hw/sai/switch/SaiAclTableManager.h"
#include "fboss/agent/hw/sai/switch/SaiArsManager.h"
#include "fboss/agent/hw/sai/switch/SaiArsProfileManager.h"
#include "fboss/agent/hw/sai/switch/SaiBridgeManager.h"
#include "fboss/agent/hw/sai/switch/SaiBufferManager.h"
#include "fboss/agent/hw/sai/switch/SaiCounterManager.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ void SaiManagerTable::createSaiTableManagers(
aclTableManager_ =
std::make_unique<SaiAclTableManager>(saiStore, this, platform);
arsManager_ = std::make_unique<SaiArsManager>(saiStore, this, platform);
arsProfileManager_ =
std::make_unique<SaiArsProfileManager>(saiStore, this, platform);
bridgeManager_ = std::make_unique<SaiBridgeManager>(saiStore, this, platform);
bufferManager_ = std::make_unique<SaiBufferManager>(saiStore, this, platform);
counterManager_ =
Expand Down Expand Up @@ -175,6 +178,7 @@ void SaiManagerTable::reset(bool skipSwitchManager) {
switchManager_->resetQosMaps();
samplePacketManager_.reset();

arsProfileManager_.reset();
arsManager_.reset();

// ACL Table Group is going away, reset ingressACL pointing to it
Expand Down Expand Up @@ -242,6 +246,13 @@ const SaiArsManager& SaiManagerTable::arsManager() const {
return *arsManager_;
}

SaiArsProfileManager& SaiManagerTable::arsProfileManager() {
return *arsProfileManager_;
}
const SaiArsProfileManager& SaiManagerTable::arsProfileManager() const {
return *arsProfileManager_;
}

SaiBridgeManager& SaiManagerTable::bridgeManager() {
return *bridgeManager_;
}
Expand Down
5 changes: 5 additions & 0 deletions fboss/agent/hw/sai/switch/SaiManagerTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct ConcurrentIndices;
class SaiAclTableGroupManager;
class SaiAclTableManager;
class SaiArsManager;
class SaiArsProfileManager;
class SaiBridgeManager;
class SaiBufferManager;
class SaiCounterManager;
Expand Down Expand Up @@ -78,6 +79,9 @@ class SaiManagerTable {
SaiArsManager& arsManager();
const SaiArsManager& arsManager() const;

SaiArsProfileManager& arsProfileManager();
const SaiArsProfileManager& arsProfileManager() const;

SaiAclTableGroupManager& aclTableGroupManager();
const SaiAclTableGroupManager& aclTableGroupManager() const;

Expand Down Expand Up @@ -177,6 +181,7 @@ class SaiManagerTable {
std::unique_ptr<SaiAclTableGroupManager> aclTableGroupManager_;
std::unique_ptr<SaiAclTableManager> aclTableManager_;
std::unique_ptr<SaiArsManager> arsManager_;
std::unique_ptr<SaiArsProfileManager> arsProfileManager_;
std::unique_ptr<SaiBridgeManager> bridgeManager_;
std::unique_ptr<SaiBufferManager> bufferManager_;
std::unique_ptr<SaiCounterManager> counterManager_;
Expand Down
1 change: 1 addition & 0 deletions fboss/agent/hw/sai/switch/switch.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _COMMON_SRCS = [
"SaiAclTableGroupManager.cpp",
"SaiAclTableManager.cpp",
"SaiArsManager.cpp",
"SaiArsProfileManager.cpp",
"SaiBridgeManager.cpp",
"SaiBufferManager.cpp",
"SaiCounterManager.cpp",
Expand Down

0 comments on commit b00506d

Please sign in to comment.