Multiple changes for June release
[samplevnf.git] / VNFs / DPPD-PROX / thread_nop.c
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <rte_cycles.h>
18
19 #include "log.h"
20 #include "lconf.h"
21 #include "thread_nop.h"
22 #include "handle_nop.h"
23 #include "stats.h"
24 #include "lconf.h"
25 #include "defines.h"
26
27 int thread_nop(struct lcore_cfg *lconf)
28 {
29         struct task_base *tasks[MAX_TASKS_PER_CORE];
30         struct rte_mbuf **mbufs;
31         uint64_t cur_tsc = rte_rdtsc();
32         uint64_t term_tsc = cur_tsc;
33         uint64_t drain_tsc = cur_tsc;
34         uint8_t n_tasks_run = 0;
35
36         for (;;) {
37                 cur_tsc = rte_rdtsc();
38                 if (cur_tsc > term_tsc) {
39                         term_tsc = cur_tsc + TERM_TIMEOUT;
40                         if (lconf_is_req(lconf) && lconf_do_flags(lconf)) {
41                                 n_tasks_run = lconf->n_tasks_run;
42
43                                 if (!n_tasks_run)
44                                         return 0;
45                                 for (int i = 0; i < lconf->n_tasks_run; ++i) {
46                                         tasks[i] = lconf->tasks_run[i];
47                                 }
48                         }
49                 }
50                 if (cur_tsc > drain_tsc) {
51                         drain_tsc = cur_tsc + DRAIN_TIMEOUT;
52                         lconf_flush_all_queues(lconf);
53                 }
54
55                 for (uint8_t task_id = 0; task_id < n_tasks_run; ++task_id) {
56                         struct task_base *t = tasks[task_id];
57                         uint16_t nb_rx = t->rx_pkt(t, &mbufs);
58
59                         if (likely(nb_rx)) {
60                                 handle_nop_bulk(t, mbufs, nb_rx);
61                         }
62                 }
63         }
64
65         return 0;
66 }