From 69a9662f84bf5abe27b1f844776a2632aaeeb8d5 Mon Sep 17 00:00:00 2001 From: zbud-msft Date: Wed, 14 Sep 2022 00:08:49 +0000 Subject: [PATCH 1/3] Remove if and log messages for event_publish --- orchagent/crmorch.cpp | 4 +--- orchagent/pfcwdorch.cpp | 4 +--- orchagent/portsorch.cpp | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 3f5835f963..0bd2c3e0fb 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -772,9 +772,7 @@ void CrmOrch::checkCrmThresholds() SWSS_LOG_WARN("%s THRESHOLD_EXCEEDED for %s %u%% Used count %u free count %u", res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter); - if (0 != event_publish(m_events_handle, "chk_crm_threshold", ¶ms)) { - SWSS_LOG_WARN("Failed to publish event for if-state"); - } + event_publish(m_events_handle, "chk_crm_threshold", ¶ms); res.exceededLogCounter++; } diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index ca40010558..b5977f0775 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -952,9 +952,7 @@ void PfcWdSwOrch::report_pfc_storm( id, entry->portId); - if (0 != event_publish(m_events_handle, "pfc-storm", ¶ms)) { - SWSS_LOG_WARN("Failed to publish event for pfc-storm"); - } + event_publish(m_events_handle, "pfc-storm", ¶ms); } template diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 6a7f1e8af9..6fed8ec5d5 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -2540,9 +2540,7 @@ bool PortsOrch::setHostIntfsOperStatus(const Port& port, bool isUp) const isUp ? "UP" : "DOWN", port.m_alias.c_str()); event_params_t params = {{"ifname",port.m_alias},{"status",isUp ? "up" : "down"}}; - if (0 != event_publish(m_events_handle, "if-state", ¶ms)) { - SWSS_LOG_WARN("Failed to publish event for if-state"); - } + event_publish(m_events_handle, "if-state", ¶ms); return true; } From a248ba520563d2cf24158c0da3452d42fa736175 Mon Sep 17 00:00:00 2001 From: zbud-msft Date: Wed, 14 Sep 2022 21:39:44 +0000 Subject: [PATCH 2/3] Remove event_handle_t from signature and add globally --- orchagent/crmorch.cpp | 6 ++--- orchagent/crmorch.h | 3 +-- orchagent/orchdaemon.cpp | 29 ++++++++++-------------- orchagent/orchdaemon.h | 1 - orchagent/p4orch/tests/fake_portorch.cpp | 2 +- orchagent/pfcwdorch.cpp | 8 +++---- orchagent/pfcwdorch.h | 5 +--- orchagent/portsorch.cpp | 6 ++--- orchagent/portsorch.h | 3 +-- 9 files changed, 26 insertions(+), 37 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 0bd2c3e0fb..f954bd1637 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -18,6 +18,7 @@ extern sai_object_id_t gSwitchId; extern sai_switch_api_t *sai_switch_api; extern sai_acl_api_t *sai_acl_api; +extern event_handle_t g_events_handle; using namespace std; using namespace swss; @@ -241,9 +242,8 @@ const map crmUsedCntsTableMap = { "crm_stats_nexthop_group_map_used", CrmResourceType::CRM_NEXTHOP_GROUP_MAP }, }; -CrmOrch::CrmOrch(DBConnector *db, string tableName, event_handle_t handle): +CrmOrch::CrmOrch(DBConnector *db, string tableName): Orch(db, tableName), - m_events_handle(handle), m_countersDb(new DBConnector("COUNTERS_DB", 0)), m_countersCrmTable(new Table(m_countersDb.get(), COUNTERS_CRM_TABLE)), m_timer(new SelectableTimer(timespec { .tv_sec = CRM_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 })) @@ -772,7 +772,7 @@ void CrmOrch::checkCrmThresholds() SWSS_LOG_WARN("%s THRESHOLD_EXCEEDED for %s %u%% Used count %u free count %u", res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter); - event_publish(m_events_handle, "chk_crm_threshold", ¶ms); + event_publish(g_events_handle, "chk_crm_threshold", ¶ms); res.exceededLogCounter++; } diff --git a/orchagent/crmorch.h b/orchagent/crmorch.h index 9b671b8703..a9c32a83bd 100644 --- a/orchagent/crmorch.h +++ b/orchagent/crmorch.h @@ -52,7 +52,7 @@ enum class CrmResourceStatus class CrmOrch : public Orch { public: - CrmOrch(swss::DBConnector *db, std::string tableName, event_handle_t handle = NULL); + CrmOrch(swss::DBConnector *db, std::string tableName); void incCrmResUsedCounter(CrmResourceType resource); void decCrmResUsedCounter(CrmResourceType resource); // Increment "used" counter for the ACL table/group CRM resources @@ -65,7 +65,6 @@ class CrmOrch : public Orch void decCrmAclTableUsedCounter(CrmResourceType resource, sai_object_id_t tableId); private: - event_handle_t m_events_handle; std::shared_ptr m_countersDb = nullptr; std::shared_ptr m_countersCrmTable = nullptr; swss::SelectableTimer *m_timer = nullptr; diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 104e8c2ab9..0d5a5a8f73 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -22,6 +22,8 @@ extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; extern bool gSaiRedisLogRotate; +extern event_handle_t g_events_handle; + extern void syncd_apply_view(); /* * Global orch daemon variables @@ -62,7 +64,6 @@ bool gIsNatSupported = false; size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE; OrchDaemon::OrchDaemon(DBConnector *applDb, DBConnector *configDb, DBConnector *stateDb, DBConnector *chassisAppDb) : - m_events_handle(NULL), m_applDb(applDb), m_configDb(configDb), m_stateDb(stateDb), @@ -91,7 +92,7 @@ OrchDaemon::~OrchDaemon() } delete m_select; - events_deinit_publisher(m_events_handle); + events_deinit_publisher(g_events_handle); } bool OrchDaemon::init() @@ -100,9 +101,9 @@ bool OrchDaemon::init() string platform = getenv("platform") ? getenv("platform") : ""; - m_events_handle = events_init_publisher("sonic-events-swss"); + g_events_handle = events_init_publisher("sonic-events-swss"); - gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME, m_events_handle); + gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME); TableConnector stateDbSwitchTable(m_stateDb, "SWITCH_CAPABILITY"); TableConnector app_switch_table(m_applDb, APP_SWITCH_TABLE_NAME); @@ -131,7 +132,7 @@ bool OrchDaemon::init() { APP_MCLAG_FDB_TABLE_NAME, FdbOrch::fdborch_pri} }; - gPortsOrch = new PortsOrch(m_applDb, m_stateDb, ports_tables, m_chassisAppDb, m_events_handle); + gPortsOrch = new PortsOrch(m_applDb, m_stateDb, ports_tables, m_chassisAppDb); TableConnector stateDbFdb(m_stateDb, STATE_FDB_TABLE_NAME); TableConnector stateMclagDbFdb(m_stateDb, STATE_MCLAG_REMOTE_FDB_TABLE_NAME); gFdbOrch = new FdbOrch(m_applDb, app_fdb_tables, stateDbFdb, stateMclagDbFdb, gPortsOrch); @@ -513,8 +514,7 @@ bool OrchDaemon::init() portStatIds, queueStatIds, queueAttrIds, - PFC_WD_POLL_MSECS, - m_events_handle)); + PFC_WD_POLL_MSECS)); } else if ((platform == INVM_PLATFORM_SUBSTRING) || (platform == BFN_PLATFORM_SUBSTRING) @@ -557,8 +557,7 @@ bool OrchDaemon::init() portStatIds, queueStatIds, queueAttrIds, - PFC_WD_POLL_MSECS, - m_events_handle)); + PFC_WD_POLL_MSECS)); } else if (platform == BFN_PLATFORM_SUBSTRING) { @@ -568,8 +567,7 @@ bool OrchDaemon::init() portStatIds, queueStatIds, queueAttrIds, - PFC_WD_POLL_MSECS, - m_events_handle)); + PFC_WD_POLL_MSECS)); } } else if (platform == BRCM_PLATFORM_SUBSTRING) @@ -613,8 +611,7 @@ bool OrchDaemon::init() portStatIds, queueStatIds, queueAttrIds, - PFC_WD_POLL_MSECS, - m_events_handle)); + PFC_WD_POLL_MSECS)); } else { @@ -624,8 +621,7 @@ bool OrchDaemon::init() portStatIds, queueStatIds, queueAttrIds, - PFC_WD_POLL_MSECS, - m_events_handle)); + PFC_WD_POLL_MSECS)); } } else if (platform == CISCO_8000_PLATFORM_SUBSTRING) { @@ -647,8 +643,7 @@ bool OrchDaemon::init() portStatIds, queueStatIds, queueAttrIds, - PFC_WD_POLL_MSECS, - m_events_handle)); + PFC_WD_POLL_MSECS)); } m_orchList.push_back(&CounterCheckOrch::getInstance(m_configDb)); diff --git a/orchagent/orchdaemon.h b/orchagent/orchdaemon.h index 8cc6a0cfc6..def4b78629 100644 --- a/orchagent/orchdaemon.h +++ b/orchagent/orchdaemon.h @@ -68,7 +68,6 @@ class OrchDaemon m_fabricEnabled = enabled; } private: - event_handle_t m_events_handle; DBConnector *m_applDb; DBConnector *m_configDb; DBConnector *m_stateDb; diff --git a/orchagent/p4orch/tests/fake_portorch.cpp b/orchagent/p4orch/tests/fake_portorch.cpp index 5bb50f78e8..5224ec55af 100644 --- a/orchagent/p4orch/tests/fake_portorch.cpp +++ b/orchagent/p4orch/tests/fake_portorch.cpp @@ -13,7 +13,7 @@ extern "C" #define QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000 PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector &tableNames, - DBConnector *chassisAppDb, event_handle_t) + DBConnector *chassisAppDb) : Orch(db, tableNames), m_portStateTable(stateDb, STATE_PORT_TABLE_NAME), port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true), diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index b5977f0775..9242558028 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -32,6 +32,8 @@ extern sai_switch_api_t* sai_switch_api; extern sai_port_api_t *sai_port_api; extern sai_queue_api_t *sai_queue_api; +extern event_handle_t g_events_handle; + extern SwitchOrch *gSwitchOrch; extern PortsOrch *gPortsOrch; @@ -686,10 +688,8 @@ PfcWdSwOrch::PfcWdSwOrch( const vector &portStatIds, const vector &queueStatIds, const vector &queueAttrIds, - int pollInterval, - event_handle_t handle): + int pollInterval): PfcWdOrch(db, tableNames), - m_events_handle(handle), m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)), m_flexCounterTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_TABLE)), m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)), @@ -952,7 +952,7 @@ void PfcWdSwOrch::report_pfc_storm( id, entry->portId); - event_publish(m_events_handle, "pfc-storm", ¶ms); + event_publish(g_events_handle, "pfc-storm", ¶ms); } template diff --git a/orchagent/pfcwdorch.h b/orchagent/pfcwdorch.h index f1930c1227..ff493405b9 100644 --- a/orchagent/pfcwdorch.h +++ b/orchagent/pfcwdorch.h @@ -73,8 +73,7 @@ class PfcWdSwOrch: public PfcWdOrch const vector &portStatIds, const vector &queueStatIds, const vector &queueAttrIds, - int pollInterval, - event_handle_t handle = NULL); + int pollInterval); virtual ~PfcWdSwOrch(void); void doTask(Consumer& consumer) override; @@ -93,8 +92,6 @@ class PfcWdSwOrch: public PfcWdOrch bool startWdActionOnQueue(const string &event, sai_object_id_t queueId) override; private: - event_handle_t m_events_handle; - struct PfcWdQueueEntry { PfcWdQueueEntry( diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 6fed8ec5d5..0f19f6b1e3 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -55,6 +55,7 @@ extern string gMySwitchType; extern int32_t gVoqMySwitchId; extern string gMyHostName; extern string gMyAsicName; +extern event_handle_t g_events_handle; #define DEFAULT_SYSTEM_PORT_MTU 9100 #define VLAN_PREFIX "Vlan" @@ -353,9 +354,8 @@ static bool isValidPortTypeForLagMember(const Port& port) * default VLAN and all ports removed from .1Q bridge. */ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector &tableNames, - DBConnector *chassisAppDb, event_handle_t events_handle) : + DBConnector *chassisAppDb) : Orch(db, tableNames), - m_events_handle(events_handle), m_portStateTable(stateDb, STATE_PORT_TABLE_NAME), port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false), gb_port_stat_manager("GB_FLEX_COUNTER_DB", @@ -2540,7 +2540,7 @@ bool PortsOrch::setHostIntfsOperStatus(const Port& port, bool isUp) const isUp ? "UP" : "DOWN", port.m_alias.c_str()); event_params_t params = {{"ifname",port.m_alias},{"status",isUp ? "up" : "down"}}; - event_publish(m_events_handle, "if-state", ¶ms); + event_publish(g_events_handle, "if-state", ¶ms); return true; } diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 227bf514bf..d28a347e08 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -78,7 +78,7 @@ struct VlanMemberUpdate class PortsOrch : public Orch, public Subject { public: - PortsOrch(DBConnector *db, DBConnector *stateDb, vector &tableNames, DBConnector *chassisAppDb, event_handle_t handle = NULL); + PortsOrch(DBConnector *db, DBConnector *stateDb, vector &tableNames, DBConnector *chassisAppDb); bool allPortsReady(); bool isInitDone(); @@ -189,7 +189,6 @@ class PortsOrch : public Orch, public Subject bool isMACsecPort(sai_object_id_t port_id) const; private: - event_handle_t m_events_handle; unique_ptr m_counterTable; unique_ptr
m_counterLagTable; unique_ptr
m_portTable; From 082a260c9703534c83e30e133e16306976d54d97 Mon Sep 17 00:00:00 2001 From: zbud-msft Date: Wed, 14 Sep 2022 21:51:11 +0000 Subject: [PATCH 3/3] Remove extern orchdaemon.cpp --- orchagent/orchdaemon.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 0d5a5a8f73..68032d1689 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -22,8 +22,6 @@ extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; extern bool gSaiRedisLogRotate; -extern event_handle_t g_events_handle; - extern void syncd_apply_view(); /* * Global orch daemon variables @@ -59,6 +57,7 @@ FlowCounterRouteOrch *gFlowCounterRouteOrch; DebugCounterOrch *gDebugCounterOrch; bool gIsNatSupported = false; +event_handle_t g_events_handle; #define DEFAULT_MAX_BULK_SIZE 1000 size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE;