Skip to content

Commit c1096da

Browse files
authored
Merge pull request sonic-net#3 from YonatanPitz/sonic_bm_tor_cli
Add toggles for cache thresholds
2 parents 24b9f19 + 93e4ce1 commit c1096da

File tree

3 files changed

+120
-49
lines changed

3 files changed

+120
-49
lines changed

orchagent/bmt_cache_debug.cpp

+96-33
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,32 @@
88
#include <iostream>
99
#include <sstream>
1010
#include <map>
11+
#include <cstring>
12+
#include <deque>
1113

1214
#include "bmt_common.h"
1315
#include "logger.h"
14-
#include "bmt_common.h"
16+
#include "bmt_orch_constants.h"
1517

1618
extern global_config_t g;
1719
pthread_t debug_thread;
1820
int sock = 0;
1921

22+
template<typename O> void split(const std::string &s, char delim, O result) {
23+
std::stringstream ss;
24+
ss.str(s);
25+
std::string item;
26+
while (getline(ss, item, delim)) {
27+
if (!item.empty()) *(result++) = item;
28+
}
29+
}
30+
31+
std::deque<std::string> split(const std::string &s, char delim) {
32+
std::deque<std::string> elems;
33+
split(s, delim, back_inserter(elems));
34+
return elems;
35+
}
36+
2037
/**
2138
* Simple command mapping:
2239
* INPUT CFG OUTPUT
@@ -26,39 +43,85 @@ int sock = 0;
2643
*
2744
*/
2845
void dispatch(std::string &input, global_config_t* cfg, std::ostringstream &stream) {
29-
(void)cfg;
30-
if (!input.compare("evac-stop")) {
31-
cfg->exitFlag = true;
32-
stream << "Exiting evacuator thread";
33-
}
34-
else if (!input.compare("insert-stop")) {
35-
cfg->scanDpdkPort = true;
36-
stream << "Exiting inserter thread";
37-
}
38-
else if (!input.compare("flush")) {
39-
cfg->flushCache = true;
40-
stream << "Flushing the cache";
41-
}
42-
else if (!input.compare("pause")) {
43-
cfg->pauseCacheInsertion = true;
44-
stream << "Insertion paused";
45-
}
46-
else if (!input.compare("resume")) {
47-
cfg->pauseCacheInsertion = false;
48-
stream << "Insertion resumed";
49-
}
50-
else if (!input.compare("status") || !input.compare("s")) {
51-
stream << "sampler init status " << cfg->sampler_init_status << std::endl;
52-
stream << "inserter is " << (cfg->pauseCacheInsertion ? "paused" : "running") << std::endl;
53-
stream << "cacheInsertCount " << cfg->cacheInsertCount << std::endl;
54-
stream << "cacheInsertSkip " << cfg->cacheInsertSkip << std::endl;
55-
stream << "cacheRemoveCount " << cfg->cacheRemoveCount << std::endl;
56-
stream << "flushCache " << cfg->flushCache << std::endl;
57-
stream << "exitFlag " << cfg->exitFlag << std::endl;
58-
stream << "scanDpdkPort " << cfg->scanDpdkPort << std::endl;
46+
try {
47+
std::deque<std::string> input_args;
48+
input_args = split(input,' ');
49+
if (input_args.empty()) {
50+
stream << input << "??? Try - status, flush, pause, resume, window, ithresh, ethresh, evac-stop, insert-stop";
51+
}
52+
else {
53+
std::string first = input_args.front();
54+
input_args.pop_front();
55+
if (!first.compare("evac-stop")) {
56+
cfg->exitFlag = true;
57+
stream << "Exiting evacuator thread";
58+
}
59+
else if (!first.compare("insert-stop")) {
60+
cfg->scanDpdkPort = true;
61+
stream << "Exiting inserter thread";
62+
}
63+
else if (!first.compare("flush")) {
64+
cfg->flushCache = true;
65+
stream << "Flushing the cache";
66+
}
67+
else if (!first.compare("pause")) {
68+
cfg->pauseCacheInsertion = true;
69+
stream << "Insertion paused";
70+
}
71+
else if (!first.compare("resume")) {
72+
cfg->pauseCacheInsertion = false;
73+
stream << "Insertion resumed";
74+
}
75+
else if (!first.compare("window")) {
76+
if (!input_args.empty()) {
77+
std::string value = input_args.front();
78+
cfg->insertionWindowSize = (uint32_t) stoul(value,nullptr,0);
79+
input_args.pop_front();
80+
}
81+
stream << "Insertion window size is " << cfg->insertionWindowSize;
82+
}
83+
else if (!first.compare("ithresh")) {
84+
if (!input_args.empty()) {
85+
std::string value = input_args.front();
86+
cfg->insertionThreshold = (uint32_t) stoul(value,nullptr,0);
87+
input_args.pop_front();
88+
}
89+
stream << "Insertion threshold is " << cfg->insertionThreshold;
90+
91+
}
92+
else if (!first.compare("ethresh")) {
93+
if (!input_args.empty()) {
94+
std::string value = input_args.front();
95+
cfg->evacuationThreshold = (uint32_t) stoul(value,nullptr,0);
96+
input_args.pop_front();
97+
}
98+
stream << "Evacuation threshold is " << cfg->evacuationThreshold;
99+
}
100+
else if (!first.compare("status") || !input.compare("s")) {
101+
stream << "sampler init status " << cfg->sampler_init_status << std::endl;
102+
stream << "inserter is " << (cfg->pauseCacheInsertion ? "paused" : "running") << std::endl;
103+
stream << "insert window size " << cfg->insertionWindowSize << std::endl;
104+
stream << "insert threshold " << cfg->insertionThreshold << std::endl;
105+
stream << "evacuation threshold " << cfg->evacuationThreshold << std::endl;
106+
stream << "cache inserts " << cfg->cacheInsertCount
107+
<< ", skip " << cfg->cacheInsertSkip
108+
<< ", remove " << cfg->cacheRemoveCount << std::endl;
109+
stream << "entry counter ";
110+
for (int i = 0; i < VHOST_TABLE_SIZE; i++) {
111+
stream << "#" << i << ": "<< cfg->entryCounters[i] << ", ";
112+
}
113+
stream << std::endl;
114+
stream << "flushCache " << cfg->flushCache << std::endl;
115+
stream << "exitFlag " << cfg->exitFlag << std::endl;
116+
stream << "scanDpdkPort " << cfg->scanDpdkPort << std::endl;
117+
}
118+
else {
119+
stream << input << "??? Try - status, flush, pause, resume, evac-stop, insert-stop";
120+
}
121+
}
59122
}
60-
else {
61-
stream << input << "??? Try - status, flush, pause, resume, evac-stop, insert-stop";
123+
catch (const std::exception &e) {
124+
stream << "Invalid command \"" << input << "\"" << ": " << e.what() << std::endl;
62125
}
63126
}
64127

orchagent/bmt_cache_inserter.cpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,17 @@ int bmt_cache_inserter(void)
519519
pkt_map.clear();
520520
while(g.scanDpdkPort) {
521521
pkt_map.clear();
522-
SWSS_LOG_NOTICE("[inserter] listening to %d packets...", INSERTER_WINDOW_SIZE);
523-
pcap_loop(handle, INSERTER_WINDOW_SIZE, bmt_parse_packet, (u_char *) &pkt_map);
522+
SWSS_LOG_NOTICE("[inserter] listening to %d packets...", g.insertionWindowSize);
523+
pcap_loop(handle, g.insertionWindowSize, bmt_parse_packet, (u_char *) &pkt_map);
524524
for(auto const &it_pkt : pkt_map) {
525-
if (it_pkt.second.second > INSERTER_THRESH){
525+
if (it_pkt.second.second > g.insertionThreshold){
526526
SWSS_LOG_NOTICE("[inserter] flow insertion, was seen %d times in the window",it_pkt.second.second);
527527
if (!g.pauseCacheInsertion) {
528528
sai_status_t status = bmt_cache_insert_vhost_entry(it_pkt.first.second, it_pkt.second.first, it_pkt.first.first);
529529
SWSS_LOG_NOTICE("[inserter] [recv] bmt_cache_insert_vhost_entry. status = %d",status);
530530
if (status != SAI_STATUS_SUCCESS)
531531
SWSS_LOG_ERROR("[inserter] can't add entry to vhost table");
532-
else
532+
else
533533
g.cacheInsertCount++;
534534
}
535535
} else {
@@ -644,7 +644,7 @@ void bmt_cache_evacuator(){
644644
}
645645
for (uint32_t i=batch_start ; i<batch_end; i++ ){
646646
SWSS_LOG_NOTICE("counter %d (bytes): 0x%lx", i, counter_diff[i-batch_start]);
647-
if ((vhost_table.entry[i].valid) && (counter_diff[i-batch_start] < EVAC_TRESH)){
647+
if ((vhost_table.entry[i].valid) && (counter_diff[i-batch_start] < g.evacuationThreshold)){
648648
evac_candidates.push_back(i);
649649
SWSS_LOG_NOTICE("[evac] INFO: added evac candidate: offset: %d , counter delta: 0x%lx",i,counter_diff[i-batch_start]);
650650
}
@@ -660,17 +660,16 @@ void bmt_cache_evacuator(){
660660

661661

662662
void bmt_cache_counters_read() {
663-
uint64_t counter;
664-
while (!g.exitFlag) {
665-
{
666-
lock_guard<mutex> guard(vhost_table.free_offset_mutex);
667-
//SWSS_LOG_NOTICE("reading counters from all entries");
668-
for (uint32_t i=0; i<VHOST_TABLE_SIZE; i++) {
669-
counter_read_by_offset(i, &counter);
670-
}
671-
}
672-
sleep(1);
673-
}
663+
while (!g.exitFlag) {
664+
{
665+
lock_guard<mutex> guard(vhost_table.free_offset_mutex);
666+
//SWSS_LOG_NOTICE("reading counters from all entries");
667+
for (uint32_t i=0; i<VHOST_TABLE_SIZE; i++) {
668+
counter_read_by_offset(i, &g.entryCounters[i]);
669+
}
670+
}
671+
sleep(1);
672+
}
674673
}
675674

676675
void bmt_cache_start() {

orchagent/bmt_common.h

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ extern "C" {
1414

1515
#include "macaddress.h"
1616

17+
#include "bmt_orch_constants.h"
18+
1719

1820
typedef struct bmt_init_status_t{
1921
bool tunnel_encap_map_created = false;
@@ -49,14 +51,21 @@ typedef struct app_config {
4951
std::ofstream recordOfs;
5052
std::string recordFile;
5153

54+
// controls
5255
bool exitFlag = false;
5356
bool scanDpdkPort = true;
5457
bool flushCache = false;
5558
bool pauseCacheInsertion = false;
5659
int sampler_init_status = -1;
60+
uint32_t insertionWindowSize = INSERTER_WINDOW_SIZE;
61+
uint32_t insertionThreshold = INSERTER_THRESH;
62+
uint32_t evacuationThreshold = EVAC_TRESH;
63+
64+
// stats
5765
uint32_t cacheInsertCount = 0;
5866
uint32_t cacheInsertSkip = 0;
5967
uint32_t cacheRemoveCount = 0;
68+
uint64_t entryCounters[VHOST_TABLE_SIZE];
6069

6170
/* Global database mutex */
6271
std::mutex dbMutex;

0 commit comments

Comments
 (0)