Skip to content

Commit 99ae409

Browse files
author
Damir Zainullin
committed
CTT - Terminate all worker threads at once
1 parent a635144 commit 99ae409

5 files changed

Lines changed: 46 additions & 9 deletions

File tree

‎src/core/ipfixprobe.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ bool process_plugin_args(ipxp_conf_t& conf, IpfixprobeOptParser& parser)
448448
conf.iqueue_size,
449449
conf.max_pkts,
450450
input_res,
451-
input_stats),
451+
input_stats,
452+
pipeline_idx,
453+
&conf.finished_workers),
452454
input_res,
453455
input_stats},
454456
{storagePlugin, storage_process_plugins}};

‎src/core/ipfixprobe.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ struct ipxp_conf_t {
325325
} active;
326326

327327
std::vector<WorkPipeline> pipelines;
328+
FinishedWorkers finished_workers;
328329
std::vector<OutputWorker> outputs;
329330

330331
std::vector<std::atomic<InputStats>*> input_stats;

‎src/core/workers.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ void input_storage_worker(
4343
size_t queue_size,
4444
uint64_t pkt_limit,
4545
std::promise<WorkerResult>* out,
46-
std::atomic<InputStats>* out_stats)
46+
std::atomic<InputStats>* out_stats,
47+
size_t worker_id,
48+
FinishedWorkers* finished_workers)
4749
{
4850
struct timespec start_cache;
4951
struct timespec end_cache;
@@ -54,6 +56,7 @@ void input_storage_worker(
5456
InputPlugin::Result ret;
5557
InputStats stats = {0, 0, 0, 0, 0};
5658
WorkerResult res = {false, ""};
59+
finished_workers->mark_in_progress(worker_id);
5760

5861
PacketBlock block(queue_size);
5962

@@ -63,10 +66,13 @@ void input_storage_worker(
6366
const clockid_t clk_id = CLOCK_MONOTONIC;
6467
#endif
6568

66-
while (storagePlugin->requires_input()) {
69+
while (!finished_workers->all_finished()) {
6770
if (terminate_input) {
6871
storagePlugin->terminate_input();
6972
}
73+
if (!storagePlugin->requires_input()) {
74+
finished_workers->mark_finished(worker_id);
75+
}
7076
block.cnt = 0;
7177
block.bytes = 0;
7278

‎src/core/workers.hpp‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,46 @@ struct OutputWorker {
7171
ipx_ring_t* queue;
7272
};
7373

74+
class FinishedWorkers {
75+
constexpr static size_t MAX_WORKERS = 64;
76+
enum class WorkerStatus : uint8_t {
77+
IN_PROGRESS = 0,
78+
FINISHED = 1
79+
};
80+
std::array<WorkerStatus, MAX_WORKERS> workers_status;
81+
82+
public:
83+
FinishedWorkers() noexcept
84+
{
85+
workers_status.fill(WorkerStatus::FINISHED);
86+
}
87+
88+
void mark_in_progress(size_t worker_id) noexcept
89+
{
90+
workers_status[worker_id] = WorkerStatus::IN_PROGRESS;
91+
}
92+
93+
void mark_finished(size_t worker_id) noexcept
94+
{
95+
workers_status[worker_id] = WorkerStatus::FINISHED;
96+
}
97+
98+
bool all_finished() const noexcept
99+
{
100+
return std::all_of(workers_status.begin(), workers_status.end(),
101+
[](WorkerStatus status) { return status == WorkerStatus::FINISHED; });
102+
}
103+
};
104+
74105
void input_storage_worker(
75106
std::shared_ptr<InputPlugin> inputPlugin,
76107
std::shared_ptr<StoragePlugin> storagePlugin,
77108
size_t queue_size,
78109
uint64_t pkt_limit,
79110
std::promise<WorkerResult>* out,
80-
std::atomic<InputStats>* out_stats);
111+
std::atomic<InputStats>* out_stats,
112+
size_t worker_id,
113+
FinishedWorkers* finished_workers);
81114
void output_worker(
82115
std::shared_ptr<OutputPlugin> outputPlugin,
83116
ipx_ring_t* queue,

‎src/plugins/storage/cache-ctt/src/cacheCtt.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ void NHTFlowCacheCtt::flush_ctt(const timeval now) noexcept
168168
m_table_flushed = !m_ctt_flow_seen;
169169
m_ctt_flow_seen = false;
170170
}
171-
172-
if (m_ctt_flows_flushed >= 16) {
173-
m_ctt_flows_flushed = 0;
174-
usleep(400);
175-
}
176171
}
177172

178173
std::optional<feta::OffloadMode> NHTFlowCacheCtt::get_offload_mode(size_t flow_index) noexcept

0 commit comments

Comments
 (0)