Skip to content
Merged
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
7 changes: 7 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ namespace sairedis
virtual sai_log_level_t logGet(
_In_ sai_api_t api);

public: // non SAI API

// BROADCOM_LEGACY_SAI_COMPAT: Platforms that crash when sai_get_stats_ext is called on
// switch objects (e.g. Tomahawk-1/BCM56960 legacy) can set
// SAI_STATS_EXT_SWITCH_SUPPORTED=0 in sai.profile to disable it.
virtual bool isSwitchStatsExtSupported() const { return true; }

public: // non SAI API - options helper

std::shared_ptr<SaiOptions> getOptions(
Expand Down
4 changes: 3 additions & 1 deletion syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3399,7 +3399,9 @@ std::shared_ptr<BaseCounterContext> FlexCounter::createCounterContext(
auto context = std::make_shared<CounterContext<sai_switch_stat_t>>(context_name, instance, SAI_OBJECT_TYPE_SWITCH, m_vendorSai.get(), m_statsMode);
context->always_check_supported_counters = true;
context->use_sai_stats_capa_query = true;
context->use_sai_stats_ext = true;
// BROADCOM_LEGACY_SAI_COMPAT: sai_get_stats_ext crashes on some legacy ASICs for switch objects;
// platform can set SAI_STATS_EXT_SWITCH_SUPPORTED=0 in sai.profile to disable.
context->use_sai_stats_ext = m_vendorSai->isSwitchStatsExtSupported();
return context;
}

Expand Down
24 changes: 24 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ VendorSai::VendorSai()
SWSS_LOG_ENTER();

m_apiInitialized = false;
m_switchStatsExtSupported = true;

memset(&m_apis, 0, sizeof(m_apis));

Expand Down Expand Up @@ -166,6 +167,22 @@ sai_status_t VendorSai::apiInitialize(
}
#endif

// BROADCOM_LEGACY_SAI_COMPAT: Allow platforms to disable sai_get_stats_ext for switch objects
// via sai.profile key SAI_STATS_EXT_SWITCH_SUPPORTED=0.
// Needed for legacy ASICs (e.g. Tomahawk-1/BCM56960) where sai_get_stats_ext
// on SAI_OBJECT_TYPE_SWITCH causes a crash during FlexCounter polling.
if (m_service_method_table.profile_get_value != nullptr)
{
const char *extVal = m_service_method_table.profile_get_value(
0, "SAI_STATS_EXT_SWITCH_SUPPORTED");
if (extVal != nullptr && std::string(extVal) == "0")
{
SWSS_LOG_NOTICE("SAI_STATS_EXT_SWITCH_SUPPORTED=0 in sai.profile,"
" disabling sai_get_stats_ext for switch object type");
m_switchStatsExtSupported = false;
}
}

m_apiInitialized = true;

return status;
Expand Down Expand Up @@ -2290,3 +2307,10 @@ sai_log_level_t VendorSai::logGet(

return SAI_LOG_LEVEL_NOTICE;
}

bool VendorSai::isSwitchStatsExtSupported() const
{
SWSS_LOG_ENTER();
return m_switchStatsExtSupported;
}

4 changes: 4 additions & 0 deletions syncd/VendorSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ namespace syncd
virtual sai_log_level_t logGet(
_In_ sai_api_t api) override;

virtual bool isSwitchStatsExtSupported() const override;

private:

bool m_apiInitialized;
Expand All @@ -237,5 +239,7 @@ namespace syncd
sai_global_apis_t m_globalApis;

std::map<sai_api_t, sai_log_level_t> m_logLevelMap;

bool m_switchStatsExtSupported;
};
}
38 changes: 38 additions & 0 deletions unittest/syncd/TestVendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,26 @@ TEST_F(VendorSaiTest, bulk_eni_trusted_vni_entry)

// BROADCOM_LEGACY_SAI_COMPAT tests ------------------------------------------------------------------------------------

static const char* profile_get_value_no_switch_stats_ext(
_In_ sai_switch_profile_id_t profile_id,
_In_ const char* variable)
{
SWSS_LOG_ENTER();

if (variable == NULL)
return NULL;

if (std::string(variable) == "SAI_STATS_EXT_SWITCH_SUPPORTED")
return "0";

return nullptr;
}

static sai_service_method_table_t test_services_no_switch_stats_ext = {
profile_get_value_no_switch_stats_ext,
profile_get_next_value
};

static const char* profile_get_value_no_st_capability(
_In_ sai_switch_profile_id_t profile_id,
_In_ const char* variable)
Expand All @@ -1830,6 +1850,24 @@ static sai_service_method_table_t test_services_no_st_capability = {
profile_get_next_value
};

TEST(VendorSai, isSwitchStatsExtSupportedDefault)
{
// BROADCOM_LEGACY_SAI_COMPAT: isSwitchStatsExtSupported() defaults to true when
// SAI_STATS_EXT_SWITCH_SUPPORTED key is absent from sai.profile
VendorSai sai;
sai.apiInitialize(0, &test_services);
EXPECT_TRUE(sai.isSwitchStatsExtSupported());
}

TEST(VendorSai, isSwitchStatsExtDisabledViaProfile)
{
// BROADCOM_LEGACY_SAI_COMPAT: SAI_STATS_EXT_SWITCH_SUPPORTED=0 in sai.profile
// disables sai_get_stats_ext for switch objects (needed for TH1/BCM56960 legacy)
VendorSai sai;
sai.apiInitialize(0, &test_services_no_switch_stats_ext);
EXPECT_FALSE(sai.isSwitchStatsExtSupported());
}

TEST(VendorSai, statsStCapabilityProfileKeyProcessed)
{
// BROADCOM_LEGACY_SAI_COMPAT: SAI_STATS_ST_CAPABILITY_SUPPORTED=0 in sai.profile
Expand Down
Loading