Skip to content

Commit 044547e

Browse files
Ron Hemeta-codesync[bot]
authored andcommitted
Take SAI API lock while registering callback
Summary: While trying to make sure no regression in Sai Replayer refactoring, noticed that a few SAI API calls are interleaving with each other. E.g. ``` memset(s_a,0,ATTR_SIZE*4096); s_a[0].id=536870926; rv=switch_api->set_switch_attribute(9840384019236126720U,s_a); memset(s_a,0,ATTR_SIZE*4096); s_a[0].id=120; rv=switch_api->set_switch_attribute(9840384019236126720U,s_a); rvCheck(rv,0,1952); rvCheck(rv,0,1953); ``` This is because when we register callbacks, the call directly goes to SDK instead of going through Sai API. To fix this, also take the SaiAPILock while registering callback. Reviewed By: daiwei1983 Differential Revision: D85834616 Privacy Context Container: L1297311 fbshipit-source-id: a52dc77be208ece5f80e3310b2642953c8ae493b
1 parent 5ee31a3 commit 044547e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fboss/agent/hw/sai/api/SwitchApi.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void SwitchApi::registerRxCallback(
2828
sai_attribute_t attr;
2929
attr.id = SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY;
3030
attr.value.ptr = (void*)rx_cb;
31+
auto g{SaiApiLock::getInstance()->lock()};
3132
auto rv = _setAttribute(id, &attr);
3233
saiApiCheckError(
3334
rv,
@@ -43,6 +44,7 @@ void SwitchApi::registerPortStateChangeCallback(
4344
sai_attribute_t attr;
4445
attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
4546
attr.value.ptr = (void*)port_state_change_cb;
47+
auto g{SaiApiLock::getInstance()->lock()};
4648
auto rv = _setAttribute(id, &attr);
4749
saiApiCheckError(
4850
rv,
@@ -58,6 +60,7 @@ void SwitchApi::registerFdbEventCallback(
5860
sai_attribute_t attr;
5961
attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
6062
attr.value.ptr = (void*)fdb_event_cb;
63+
auto g{SaiApiLock::getInstance()->lock()};
6164
auto rv = _setAttribute(id, &attr);
6265
saiApiCheckError(
6366
rv,
@@ -73,6 +76,7 @@ void SwitchApi::registerTamEventCallback(
7376
sai_attribute_t attr;
7477
attr.id = SAI_SWITCH_ATTR_TAM_EVENT_NOTIFY;
7578
attr.value.ptr = (void*)tam_event_cb;
79+
auto g{SaiApiLock::getInstance()->lock()};
7680
auto rv = _setAttribute(id, &attr);
7781
saiLogError(
7882
rv,
@@ -89,6 +93,7 @@ void SwitchApi::registerQueuePfcDeadlockNotificationCallback(
8993
sai_attribute_t attr;
9094
attr.id = SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY;
9195
attr.value.ptr = (void*)queue_pfc_deadlock_notification_cb;
96+
auto g{SaiApiLock::getInstance()->lock()};
9297
auto rv = _setAttribute(id, &attr);
9398
saiLogError(
9499
rv,
@@ -105,6 +110,7 @@ void SwitchApi::registerTxReadyStatusChangeCallback(
105110
sai_attribute_t attr;
106111
attr.id = SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY;
107112
attr.value.ptr = (void*)tx_ready_status_cb;
113+
auto g{SaiApiLock::getInstance()->lock()};
108114
auto rv = _setAttribute(id, &attr);
109115
saiApiCheckError(
110116
rv,
@@ -123,6 +129,7 @@ void SwitchApi::registerSwitchAsicSdkHealthEventCallback(
123129
attr.id = SAI_SWITCH_ATTR_SWITCH_ASIC_SDK_HEALTH_EVENT_NOTIFY;
124130
attr.value.ptr = (void*)function;
125131

132+
auto g{SaiApiLock::getInstance()->lock()};
126133
auto rv = _setAttribute(id, &attr);
127134
saiApiCheckError(
128135
rv,
@@ -140,6 +147,8 @@ void SwitchApi::registerVendorSwitchEventNotifyCallback(
140147
sai_attribute_t attr;
141148
attr.id = SAI_SWITCH_ATTR_VENDOR_SWITCH_EVENT_NOTIFY;
142149
attr.value.ptr = (void*)event_notify_cb;
150+
151+
auto g{SaiApiLock::getInstance()->lock()};
143152
auto rv = _setAttribute(id, &attr);
144153
saiApiCheckError(
145154
rv,
@@ -156,6 +165,7 @@ void SwitchApi::registerSwitchHardResetNotifyCallback(
156165
sai_attribute_t attr;
157166
attr.id = SAI_SWITCH_ATTR_SWITCH_HARD_RESET_EVENT_NOTIFY;
158167
attr.value.ptr = event_notify_cb;
168+
auto g{SaiApiLock::getInstance()->lock()};
159169
auto rv = _setAttribute(id, &attr);
160170
saiApiCheckError(
161171
rv,

0 commit comments

Comments
 (0)