Multiple changes for June release
[samplevnf.git] / VNFs / DPPD-PROX / handle_read.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_ip.h>
18
19 #include "task_base.h"
20 #include "task_init.h"
21 #include "defines.h"
22 #include "prefetch.h"
23 #include "log.h"
24
25 struct task_read {
26         struct task_base    base;
27 };
28
29 static int handle_read_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts)
30 {
31         struct task_read *task = (struct task_read *)tbase;
32         uint8_t out[MAX_PKT_BURST];
33         uint16_t j;
34         uint64_t *first;
35
36 #ifdef PROX_PREFETCH_OFFSET
37         for (j = 0; j < PROX_PREFETCH_OFFSET && j < n_pkts; ++j) {
38                 PREFETCH0(mbufs[j]);
39         }
40         for (j = 1; j < PROX_PREFETCH_OFFSET && j < n_pkts; ++j) {
41                 PREFETCH0(rte_pktmbuf_mtod(mbufs[j - 1], void *));
42         }
43 #endif
44         for (j = 0; j + PREFETCH_OFFSET < n_pkts; ++j) {
45 #ifdef PROX_PREFETCH_OFFSET
46                 PREFETCH0(mbufs[j + PREFETCH_OFFSET]);
47                 PREFETCH0(rte_pktmbuf_mtod(mbufs[j + PREFETCH_OFFSET - 1], void *));
48 #endif
49                 first = rte_pktmbuf_mtod(mbufs[j], uint64_t *);
50                 out[j] = *first != 0? 0: OUT_DISCARD;
51         }
52 #ifdef PROX_PREFETCH_OFFSET
53         prefetch_nta(rte_pktmbuf_mtod(mbufs[n_pkts - 1], void *));
54         for (; j < n_pkts; ++j) {
55                 first = rte_pktmbuf_mtod(mbufs[j], uint64_t *);
56                 out[j] = *first != 0? 0: OUT_DISCARD;
57         }
58 #endif
59
60         return task->base.tx_pkt(&task->base, mbufs, n_pkts, out);
61 }
62
63 static void init_task_read(__attribute__((unused)) struct task_base *tbase,
64                            __attribute__((unused)) struct task_args *targ)
65 {
66 }
67
68 static struct task_init task_init_read = {
69         .mode_str = "read",
70         .init = init_task_read,
71         .handle = handle_read_bulk,
72         .size = sizeof(struct task_read)
73 };
74
75 __attribute__((constructor)) static void reg_task_read(void)
76 {
77         reg_task(&task_init_read);
78 }