X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_mbuf%2Frte_mbuf.h;h=42db8e3df958ef12ee2e50cb0cdfb6b76bc406b6;hb=bbd778248985e542175e9b4ce560f2d379e78c4e;hp=6b1e50d4f64446c1a237f2910d0d33802dfd5a6e;hpb=4769bc5a27ccaeb736542c4064ffc182bbd7e439;p=dpdk.git diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6b1e50d4f6..42db8e3df9 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -64,8 +64,9 @@ extern "C" { #endif -/* deprecated feature, renamed in RTE_MBUF_REFCNT */ +/* deprecated options */ #pragma GCC poison RTE_MBUF_SCATTER_GATHER +#pragma GCC poison RTE_MBUF_REFCNT /* * Packet Offload Features Flags. It also carry packet type information. @@ -285,11 +286,10 @@ struct rte_mbuf { PKT_RX_FDIR_* flag in ol_flags. */ } fdir; /**< Filter identifier if FDIR enabled */ uint32_t sched; /**< Hierarchical scheduler */ - uint32_t usr; /**< User defined tags. See @rte_distributor_process */ + uint32_t usr; /**< User defined tags. See rte_distributor_process() */ } hash; /**< hash information */ - /* sequence number - field used in distributor and reorder library */ - uint32_t seqn; + uint32_t seqn; /**< Sequence number. See also rte_reorder_insert() */ /* second cache line - fields only used in slow path or on TX */ MARKER cacheline1 __rte_cache_aligned; @@ -348,7 +348,8 @@ struct rte_mbuf { * appended after the mempool structure (in private data). */ struct rte_pktmbuf_pool_private { - uint16_t mbuf_data_room_size; /**< Size of data space in each mbuf.*/ + uint16_t mbuf_data_room_size; /**< Size of data space in each mbuf. */ + uint16_t mbuf_priv_size; /**< Size of private area in each mbuf. */ }; #ifdef RTE_LIBRTE_MBUF_DEBUG @@ -640,6 +641,87 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg, */ void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg); +/** + * Create a mbuf pool. + * + * This function creates and initializes a packet mbuf pool. It is + * a wrapper to rte_mempool_create() with the proper packet constructor + * and mempool constructor. + * + * @param name + * The name of the mbuf pool. + * @param n + * The number of elements in the mbuf pool. The optimum size (in terms + * of memory usage) for a mempool is when n is a power of two minus one: + * n = (2^q - 1). + * @param cache_size + * Size of the per-core object cache. See rte_mempool_create() for + * details. + * @param priv_size + * Size of application private are between the rte_mbuf structure + * and the data buffer. + * @param data_room_size + * Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM. + * @param socket_id + * The socket identifier where the memory should be allocated. The + * value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the + * reserved zone. + * @return + * The pointer to the new allocated mempool, on success. NULL on error + * with rte_errno set appropriately. Possible rte_errno values include: + * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure + * - E_RTE_SECONDARY - function was called from a secondary process instance + * - EINVAL - cache size provided is too large + * - ENOSPC - the maximum number of memzones has already been allocated + * - EEXIST - a memzone with the same name already exists + * - ENOMEM - no appropriate memory area found in which to create memzone + */ +struct rte_mempool * +rte_pktmbuf_pool_create(const char *name, unsigned n, + unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, + int socket_id); + +/** + * Get the data room size of mbufs stored in a pktmbuf_pool + * + * The data room size is the amount of data that can be stored in a + * mbuf including the headroom (RTE_PKTMBUF_HEADROOM). + * + * @param mp + * The packet mbuf pool. + * @return + * The data room size of mbufs stored in this mempool. + */ +static inline uint16_t +rte_pktmbuf_data_room_size(struct rte_mempool *mp) +{ + struct rte_pktmbuf_pool_private *mbp_priv; + + mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp); + return mbp_priv->mbuf_data_room_size; +} + +/** + * Get the application private size of mbufs stored in a pktmbuf_pool + * + * The private size of mbuf is a zone located between the rte_mbuf + * structure and the data buffer where an application can store data + * associated to a packet. + * + * @param mp + * The packet mbuf pool. + * @return + * The private size of mbufs stored in this mempool. + */ +static inline uint16_t +rte_pktmbuf_priv_size(struct rte_mempool *mp) +{ + struct rte_pktmbuf_pool_private *mbp_priv; + + mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp); + return mbp_priv->mbuf_priv_size; +} + /** * Reset the fields of a packet mbuf to their default values. * @@ -765,6 +847,16 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) { __rte_mbuf_sanity_check(m, 0); + /* + * Check to see if this is the last reference to the mbuf. + * Note: the double check here is deliberate. If the ref_cnt is "atomic" + * the call to "refcnt_update" is a very expensive operation, so we + * don't want to call it in the case where we know we are the holder + * of the last reference to this mbuf i.e. ref_cnt == 1. + * If however, ref_cnt != 1, it's still possible that we may still be + * the final decrementer of the count, so we need to check that + * result also, to make sure the mbuf is freed properly. + */ if (likely (rte_mbuf_refcnt_read(m) == 1) || likely (rte_mbuf_refcnt_update(m, -1) == 0)) {