Merge "Add l3 support for tasks without physical tx ports"
[samplevnf.git] / VNFs / DPPD-PROX / prefetch.h
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 #ifndef _PREFETCH_H_
18 #define _PREFETCH_H_
19
20 #include <rte_mbuf.h>
21
22 static inline void prefetch_nta(volatile void *p)
23 {
24         asm volatile ("prefetchnta %[p]" : [p] "+m" (*(volatile char *)p));
25 }
26
27 #ifdef PROX_PREFETCH_OFFSET
28 #define PREFETCH0(p)            rte_prefetch0(p)
29 #define PREFETCH_OFFSET         PROX_PREFETCH_OFFSET
30 #else
31 #define PREFETCH0(p)            do {} while (0)
32 #define PREFETCH_OFFSET         0
33 #endif
34
35 static inline void prefetch_pkts(__attribute__((unused)) struct rte_mbuf **mbufs, __attribute__((unused)) uint16_t n_pkts)
36 {
37 #ifdef PROX_PREFETCH_OFFSET
38         for (uint16_t j = 0; j < PROX_PREFETCH_OFFSET && j < n_pkts; ++j) {
39                 PREFETCH0(mbufs[j]);
40         }
41         for (uint16_t j = PROX_PREFETCH_OFFSET; j < n_pkts; ++j) {
42                 PREFETCH0(mbufs[j]);
43                 PREFETCH0(rte_pktmbuf_mtod(mbufs[j - PROX_PREFETCH_OFFSET], void*));
44         }
45         for (uint16_t j = n_pkts - PROX_PREFETCH_OFFSET; j < n_pkts; ++j) {
46                 PREFETCH0(rte_pktmbuf_mtod(mbufs[j], void*));
47         }
48 #endif
49 }
50
51 static inline void prefetch_first(__attribute__((unused)) struct rte_mbuf **mbufs, __attribute__((unused)) uint16_t n_pkts)
52 {
53 #ifdef PROX_PREFETCH_OFFSET
54         for (uint16_t j = 0; j < PROX_PREFETCH_OFFSET && j < n_pkts; ++j) {
55                 PREFETCH0(mbufs[j]);
56         }
57         for (uint16_t j = 1; j < PROX_PREFETCH_OFFSET && j < n_pkts; ++j) {
58                 PREFETCH0(rte_pktmbuf_mtod(mbufs[j - 1], void *));
59         }
60 #endif
61 }
62
63 #endif /* _PREFETCH_H_ */