-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_lb.c
executable file
·93 lines (79 loc) · 3.29 KB
/
thread_lb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Copyright(c) 2010-2014 Intel Corporation.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <rte_cycles.h>
#include "thread_lb.h"
#include "stats.h"
#include "control.h"
#include "defines.h"
int thread_lb(struct lcore_cfg *lconf)
{
struct rte_mbuf *rx_mbuf[MAX_RING_BURST] __rte_cache_aligned;
struct task_base *task[MAX_TASKS_PER_CORE];
uint64_t cur_tsc = rte_rdtsc();
uint64_t next_term_tsc = cur_tsc + TERM_TIMEOUT;
uint64_t drain_tsc = cur_tsc + DRAIN_TIMEOUT;
const uint8_t nb_tasks = lconf->nb_tasks;
for (uint8_t task_id = 0; task_id < nb_tasks; ++task_id) {
task[task_id] = lconf->task[task_id];
}
for (;;) {
cur_tsc = rte_rdtsc();
if (cur_tsc > drain_tsc) {
drain_tsc = cur_tsc + DRAIN_TIMEOUT;
FLUSH_STATS(lconf);
/* check for termination request every timeout */
if (cur_tsc > next_term_tsc) {
next_term_tsc = cur_tsc + TERM_TIMEOUT;
if (is_terminated(lconf)) {
break;
}
}
for (uint8_t task_id = 0; task_id < nb_tasks; ++task_id) {
if (!(task[task_id]->flags & (FLAG_TX_FLUSH | FLAG_NEVER_FLUSH))) {
// Do not flush packets if we transmitted packets in last drain_timeout
// This avoid flushing queue under load every x seconds
task[task_id]->flags |= FLAG_TX_FLUSH;
continue;
}
/* This part of the code is only run on low load - when we need to flush,
i.e. when we did not send a bulk packets within last drain_timeout (16kpps if DRAIN_TIMEOUT=2msec).
All queues are flushed in this case */
task[task_id]->flush_queues(task[task_id]);
}
}
for (uint8_t task_id = 0; task_id < nb_tasks; ++task_id) {
uint16_t nb_rx = task[task_id]->rx_pkt(rx_mbuf, task[task_id]);
if (likely(nb_rx)) {
INCR_NBRX(nb_rx);
INCR_RX_PKT_COUNT(task[task_id]->stats, nb_rx);
task[task_id]->handle_pkt_bulk(rx_mbuf, task[task_id], nb_rx);
}
}
}
return 0;
}