Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Commit d08b74f

Browse files
committed
[AWIBOF-5236] Reserve vector memory before latency logging
- Adjust dynamic rebalancing to latency token for memory optimization - Reserve enough vector memory before latency logging so that memory allocation(in vector push_back) will not occur during logging Signed-off-by: isaac.baek <isaac.baek@samsung.com>
1 parent 19ddc15 commit d08b74f

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

src/collection/SwitchGear.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ collection::SwitchGear::_CheckDeadline(lib::Data* data)
6868
lat_data->start_deadline--;
6969
if (0 >= lat_data->start_deadline)
7070
{
71-
lat_data->start_token = lib::LAT_TOKEN_SIZE;
71+
lat_data->start_token = lat_data->start_token_size;
7272
lat_data->start_state = lib::TimeLogState::RUN;
7373
}
7474
}
@@ -78,7 +78,6 @@ collection::SwitchGear::_CheckDeadline(lib::Data* data)
7878
if (-9 > lat_data->start_deadline)
7979
{
8080
lat_data->start_state = lib::TimeLogState::STOP;
81-
lat_data->access = false;
8281
}
8382
}
8483

@@ -87,7 +86,7 @@ collection::SwitchGear::_CheckDeadline(lib::Data* data)
8786
lat_data->end_deadline--;
8887
if (0 >= lat_data->end_deadline)
8988
{
90-
lat_data->end_token = lib::LAT_TOKEN_SIZE;
89+
lat_data->end_token = lat_data->end_token_size;
9190
lat_data->end_state = lib::TimeLogState::RUN;
9291
}
9392
}
@@ -97,7 +96,6 @@ collection::SwitchGear::_CheckDeadline(lib::Data* data)
9796
if (-9 > lat_data->end_deadline)
9897
{
9998
lat_data->end_state = lib::TimeLogState::STOP;
100-
lat_data->access = false;
10199
}
102100
}
103101
}

src/lib/Data.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace lib
3737
const uint32_t IDLE_THRESHOLD {5};
3838
const uint32_t MAX_PACKET_CNT_SIZE {10};
3939
const uint32_t TIMELAG_SIZE {100};
40-
const int32_t LAT_TOKEN_SIZE {1000};
4140

4241
struct Data
4342
{
@@ -91,11 +90,13 @@ struct LatencyData : public Data
9190
std::vector<struct TimeLog> start_v;
9291
TimeLogState start_state {TimeLogState::IDLE};
9392
int32_t start_token {0};
93+
int32_t start_token_size {static_cast<int32_t>(TIMELAG_SIZE)};
9494
int32_t start_deadline {-45};
9595

9696
std::vector<struct TimeLog> end_v;
9797
TimeLogState end_state {TimeLogState::IDLE};
9898
int32_t end_token {0};
99+
int32_t end_token_size {static_cast<int32_t>(TIMELAG_SIZE)};
99100
int32_t end_deadline {-45};
100101
};
101102

src/process/TimingDistributor.cpp

+55-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ process::TimingDistributor::SetTiming(
4040
uint32_t index_size = node_meta_getter->IndexSize(nid);
4141
uint32_t filter_size = node_meta_getter->FilterSize(nid);
4242

43-
if (node_meta_getter->ProcessorType(nid) == air::ProcessorType::LATENCY)
43+
if (air::ProcessorType::LATENCY == node_meta_getter->ProcessorType(nid))
4444
{
4545
for (uint32_t hash_index = 0; hash_index < index_size; hash_index++)
4646
{
@@ -53,6 +53,8 @@ process::TimingDistributor::SetTiming(
5353
lib::LatencyData* from = static_cast<lib::LatencyData*>(
5454
kv.second->node[nid]->GetUserDataByHashIndex(
5555
hash_index, filter_index));
56+
lib::AccLatencyData* acc = node_manager->GetAccLatData(
57+
nid, hash_index, filter_index);
5658

5759
uint64_t key {0};
5860
int32_t value {0};
@@ -66,23 +68,72 @@ process::TimingDistributor::SetTiming(
6668
timing_map.insert({key, value});
6769
}
6870

69-
_ResetTiming(from, to, timing_map[key]);
71+
_ResetTiming(from, to, timing_map[key], acc->sample_count);
7072
}
7173
}
7274
}
7375
}
7476
}
77+
78+
for (uint32_t nid = 0; nid < MAX_NID_SIZE; nid++)
79+
{
80+
if (node_meta_getter->ProcessorType(nid) == air::ProcessorType::LATENCY)
81+
{
82+
uint32_t index_size = node_meta_getter->IndexSize(nid);
83+
for (uint32_t hash_index = 0; hash_index < index_size; hash_index++)
84+
{
85+
uint32_t filter_size = node_meta_getter->FilterSize(nid);
86+
for (uint32_t filter_index = 0; filter_index < filter_size - 1;
87+
filter_index++)
88+
{
89+
lib::AccLatencyData* acc =
90+
node_manager->GetAccLatData(nid, hash_index, filter_index);
91+
acc->sample_count = 0;
92+
}
93+
}
94+
}
95+
}
7596
}
7697

7798
void
78-
process::TimingDistributor::_ResetTiming(
79-
lib::LatencyData* curr_data, lib::LatencyData* next_data, int32_t time_value)
99+
process::TimingDistributor::_ResetTiming(lib::LatencyData* curr_data,
100+
lib::LatencyData* next_data, int32_t time_value, uint32_t sampled_count)
80101
{
102+
int32_t token {curr_data->start_token_size};
103+
uint32_t minimum_sampled_count {lib::TIMELAG_SIZE / 4}; // 25%
104+
uint32_t enough_sampled_count {(lib::TIMELAG_SIZE * 97) / 100}; // 97%
105+
if (minimum_sampled_count > sampled_count)
106+
{
107+
if (MAX_TOKEN > token)
108+
{
109+
token += MIN_TOKEN;
110+
}
111+
}
112+
else if (enough_sampled_count < sampled_count)
113+
{
114+
if (MIN_TOKEN < token)
115+
{
116+
token -= MIN_TOKEN;
117+
}
118+
}
119+
81120
curr_data->start_deadline = time_value;
82121
curr_data->start_v.clear();
122+
if (curr_data->access)
123+
{
124+
curr_data->start_v.reserve(token + 4);
125+
}
126+
curr_data->start_token_size = token;
83127
curr_data->start_state = lib::TimeLogState::IDLE;
128+
curr_data->access = false;
84129

85130
next_data->end_deadline = time_value;
86131
next_data->end_v.clear();
132+
if (next_data->access)
133+
{
134+
next_data->end_v.reserve(token + 4);
135+
}
136+
next_data->end_token_size = token;
87137
next_data->end_state = lib::TimeLogState::IDLE;
138+
next_data->access = false;
88139
}

src/process/TimingDistributor.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ class TimingDistributor
4747

4848
private:
4949
void _ResetTiming(lib::LatencyData* curr_data, lib::LatencyData* next_data,
50-
int32_t time_value);
50+
int32_t time_value, uint32_t sampled_count);
5151
std::random_device rand_device;
5252
std::default_random_engine rand_engine {rand_device()};
5353
std::uniform_int_distribution<int32_t> dist {1, 10};
5454
const uint32_t MAX_NID_SIZE {
5555
cfg::GetSentenceCount(config::ParagraphType::NODE)};
56+
const int32_t MIN_TOKEN {static_cast<int32_t>(lib::TIMELAG_SIZE)};
57+
const int32_t MAX_TOKEN {10 * static_cast<int32_t>(lib::TIMELAG_SIZE)};
5658
};
5759

5860
} // namespace process

src/process/processor/LatencyProcessor.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ process::LatencyProcessor::_InitData(lib::Data* air_data, lib::AccData* acc_data
157157
acc_lat_data->median = 0;
158158
acc_lat_data->lower_quartile = 0;
159159
acc_lat_data->upper_quartile = 0;
160-
acc_lat_data->sample_count = 0;
161160
for (uint32_t i {0}; i < lib::TIMELAG_SIZE; i++)
162161
{
163162
acc_lat_data->timelag[i] = 0;

0 commit comments

Comments
 (0)