2 // Copyright (c) 2010-2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _LOCAL_MBUF_H_
18 #define _LOCAL_MBUF_H_
19 #define LOCAL_MBUF_COUNT 64
22 struct rte_mempool *mempool;
24 struct rte_mbuf *new_pkts[LOCAL_MBUF_COUNT];
27 static struct rte_mbuf **local_mbuf_take(struct local_mbuf *local_mbuf, uint32_t count)
29 PROX_ASSERT(local_mbuf->n_new_pkts >= count);
31 const uint32_t start_pos = local_mbuf->n_new_pkts - count;
32 struct rte_mbuf **ret = &local_mbuf->new_pkts[start_pos];
34 local_mbuf->n_new_pkts -= count;
38 static int local_mbuf_refill(struct local_mbuf *local_mbuf)
40 const uint32_t fill = LOCAL_MBUF_COUNT - local_mbuf->n_new_pkts;
41 struct rte_mbuf **fill_mbuf = &local_mbuf->new_pkts[local_mbuf->n_new_pkts];
43 if (rte_mempool_get_bulk(local_mbuf->mempool, (void **)fill_mbuf, fill) < 0)
45 local_mbuf->n_new_pkts += fill;
49 /* Ensures that count or more mbufs are available. Returns pointer to
50 count allocated mbufs or NULL if not enough mbufs are available. */
51 static struct rte_mbuf **local_mbuf_refill_and_take(struct local_mbuf *local_mbuf, uint32_t count)
53 PROX_ASSERT(count <= LOCAL_MBUF_COUNT);
54 if (local_mbuf->n_new_pkts >= count)
55 return local_mbuf_take(local_mbuf, count);
57 if (local_mbuf_refill(local_mbuf) == 0)
58 return local_mbuf_take(local_mbuf, count);
62 #endif /* _LOCAL_MBUF_H_ */