Skip to content

Commit 0de80c3

Browse files
[FC] Set FC delay in command line parameters (#3814)
* [FC] Set FC delay in command line parameters Signed-off-by: Stepan Blyschak <[email protected]> * static_cast to time_t Signed-off-by: Stepan Blyschak <[email protected]> * Remove unnecessary whitespace in flexcounterorch.cpp --------- Signed-off-by: Stepan Blyschak <[email protected]> Co-authored-by: Sudharsan Dhamal Gopalarathnam <[email protected]>
1 parent 34ccdcb commit 0de80c3

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

orchagent/flexcounterorch.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern Srv6Orch *gSrv6Orch;
3939
extern SwitchOrch *gSwitchOrch;
4040
extern sai_object_id_t gSwitchId;
4141

42-
#define FLEX_COUNTER_DELAY_SEC 60
42+
int gFlexCounterDelaySec;
4343

4444
#define BUFFER_POOL_WATERMARK_KEY "BUFFER_POOL_WATERMARK"
4545
#define PORT_KEY "PORT"
@@ -116,11 +116,12 @@ FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames):
116116
SWSS_LOG_ERROR("System error reading create_only_config_db_buffers: %s", e.what());
117117
}
118118

119-
m_delayTimer = std::make_unique<SelectableTimer>(timespec{.tv_sec = FLEX_COUNTER_DELAY_SEC, .tv_nsec = 0});
120-
if (WarmStart::isWarmStart())
119+
SWSS_LOG_NOTICE("Counter delay is %d seconds", gFlexCounterDelaySec);
120+
if (gFlexCounterDelaySec > 0)
121121
{
122-
m_delayExecutor = std::make_unique<ExecutableTimer>(m_delayTimer.get(), this, "FLEX_COUNTER_DELAY");
123-
Orch::addExecutor(m_delayExecutor.get());
122+
m_delayTimer = new SelectableTimer(timespec{.tv_sec = static_cast<time_t>(gFlexCounterDelaySec), .tv_nsec = 0});
123+
auto delayExecutor = new ExecutableTimer(m_delayTimer, this, "FLEX_COUNTER_DELAY");
124+
Orch::addExecutor(delayExecutor);
124125
m_delayTimer->start();
125126
}
126127
else

orchagent/flexcounterorch.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ extern "C" {
1111
#include "sai.h"
1212
}
1313

14+
// Delay in seconds before flex counter processing begins after orchagent startup.
15+
//
16+
// This delay improves boot time by prioritizing data plane configuration over
17+
// counter initialization. Systems with many ports, priority groups (PGs), and
18+
// queues require significant time to generate counter maps, which is not
19+
// immediately necessary during boot.
20+
// Value of 0 will process flex counters immediately.
21+
//
22+
// Configured via orchagent command line argument: -D <delay_sec>
23+
//
24+
extern int gFlexCounterDelaySec;
25+
1426
const std::string createAllAvailableBuffersStr = "create_all_available_buffers";
1527

1628
class FlexCounterQueueStates
@@ -75,8 +87,7 @@ class FlexCounterOrch: public Orch
7587
Table m_bufferQueueConfigTable;
7688
Table m_bufferPgConfigTable;
7789
Table m_deviceMetadataConfigTable;
78-
std::unique_ptr<SelectableTimer> m_delayTimer;
79-
std::unique_ptr<Executor> m_delayExecutor;
90+
SelectableTimer* m_delayTimer;
8091
std::unordered_set<std::string> m_groupsWithBulkChunkSize;
8192

8293
bool m_createOnlyConfigDbBuffers = false;

orchagent/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void usage()
103103
cout << " -v vrf: VRF name (default empty)" << endl;
104104
cout << " -I heart_beat_interval: Heart beat interval in millisecond (default 10)" << endl;
105105
cout << " -R enable the ring thread feature" << endl;
106+
cout << " -D Delay in seconds before flex counter processing begins after orchagent startup (default 0)" << endl;
106107
}
107108

108109
void sighup_handler(int signo)
@@ -369,7 +370,7 @@ int main(int argc, char **argv)
369370
int record_type = 3; // Only swss and sairedis recordings enabled by default.
370371
long heartBeatInterval = HEART_BEAT_INTERVAL_MSECS_DEFAULT;
371372

372-
while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:q:c:t:v:I:R")) != -1)
373+
while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:q:c:t:v:I:R:D:")) != -1)
373374
{
374375
switch (opt)
375376
{
@@ -487,6 +488,7 @@ int main(int argc, char **argv)
487488
case 'R':
488489
gRingMode = true;
489490
break;
491+
case 'D': { gFlexCounterDelaySec = swss::to_int<int>(optarg); } break;
490492
default: /* '?' */
491493
exit(EXIT_FAILURE);
492494
}

tests/mock_tests/flexcounter_ut.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,7 @@ namespace flexcounter_test
274274
sai_switch_api = pold_sai_switch_api;
275275
}
276276

277-
enum class StartType
278-
{
279-
Cold,
280-
Warm,
281-
};
282-
283-
struct FlexCounterTest : public ::testing::TestWithParam<std::tuple<bool, bool, StartType>>
277+
struct FlexCounterTest : public ::testing::TestWithParam<std::tuple<bool, bool, uint32_t>>
284278
{
285279
shared_ptr<swss::DBConnector> m_app_db;
286280
shared_ptr<swss::DBConnector> m_config_db;
@@ -290,7 +284,6 @@ namespace flexcounter_test
290284
shared_ptr<swss::DBConnector> m_asic_db;
291285
shared_ptr<swss::DBConnector> m_flex_counter_db;
292286
bool create_only_config_db_buffers;
293-
StartType m_start_type;
294287

295288
FlexCounterTest()
296289
{
@@ -317,7 +310,7 @@ namespace flexcounter_test
317310

318311
gTraditionalFlexCounter = get<0>(GetParam());
319312
create_only_config_db_buffers = get<1>(GetParam());
320-
m_start_type = get<2>(GetParam());
313+
gFlexCounterDelaySec = get<2>(GetParam());
321314

322315
if (gTraditionalFlexCounter)
323316
{
@@ -364,18 +357,8 @@ namespace flexcounter_test
364357
CFG_FLEX_COUNTER_TABLE_NAME
365358
};
366359

367-
if (m_start_type == StartType::Warm)
368-
{
369-
WarmStart::getInstance().m_enabled = true;
370-
}
371-
372360
auto* flexCounterOrch = new FlexCounterOrch(m_config_db.get(), flex_counter_tables);
373361

374-
if (m_start_type == StartType::Warm)
375-
{
376-
WarmStart::getInstance().m_enabled = false;
377-
}
378-
379362
gDirectory.set(flexCounterOrch);
380363

381364
vector<string> buffer_tables = { APP_BUFFER_POOL_TABLE_NAME,
@@ -441,6 +424,9 @@ namespace flexcounter_test
441424
gDirectory.m_values.clear();
442425

443426
_unhook_sai_switch_api();
427+
428+
// reset flex counter delay sec
429+
gFlexCounterDelaySec = 0;
444430
}
445431

446432
static void SetUpTestCase()
@@ -641,7 +627,7 @@ namespace flexcounter_test
641627
flexCounterOrch->addExistingData(&flexCounterCfg);
642628
static_cast<Orch *>(flexCounterOrch)->doTask();
643629

644-
if (m_start_type == StartType::Warm)
630+
if (gFlexCounterDelaySec > 0)
645631
{
646632
// Expire timer
647633
flexCounterOrch->doTask(*flexCounterOrch->m_delayTimer);
@@ -1015,14 +1001,16 @@ namespace flexcounter_test
10151001
FlexCounterTests,
10161002
FlexCounterTest,
10171003
::testing::Values(
1018-
std::make_tuple(false, true, StartType::Cold),
1019-
std::make_tuple(false, false, StartType::Cold),
1020-
std::make_tuple(true, true, StartType::Cold),
1021-
std::make_tuple(true, false, StartType::Cold),
1022-
std::make_tuple(false, true, StartType::Warm),
1023-
std::make_tuple(false, false, StartType::Warm),
1024-
std::make_tuple(true, true, StartType::Warm),
1025-
std::make_tuple(true, false, StartType::Warm))
1004+
// traditional_flex_counter, create_only_config_db_buffers, flex_counter_delay_sec
1005+
std::make_tuple(false, true, 0),
1006+
std::make_tuple(false, false, 0),
1007+
std::make_tuple(true, true, 0),
1008+
std::make_tuple(true, false, 0),
1009+
std::make_tuple(false, true, 120),
1010+
std::make_tuple(false, false, 120),
1011+
std::make_tuple(true, true, 120),
1012+
std::make_tuple(true, false, 120)
1013+
)
10261014
);
10271015

10281016
using namespace mock_orch_test;

0 commit comments

Comments
 (0)