[dpdk-dev,05/13] mbuf: introduce a flag to indicate a control mbuf
diff mbox

Message ID 1409759378-10113-6-git-send-email-bruce.richardson@intel.com
State Superseded, archived
Headers show

Commit Message

Bruce Richardson Sept. 3, 2014, 3:49 p.m. UTC
Since the flags field is now 64-bits, we can allow one bit to be used to
indicate a control i.e. non-packet mbuf. Dedicate the high bit (bit 63)
for this purpose and add in a utility macro to test if a given mbuf has
the bit set or not.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_mbuf/rte_mbuf.c |  2 ++
 lib/librte_mbuf/rte_mbuf.h | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)

Comments

Olivier Matz Sept. 8, 2014, 11:53 a.m. UTC | #1
Hi Bruce,

On 09/03/2014 05:49 PM, Bruce Richardson wrote:
> Since the flags field is now 64-bits, we can allow one bit to be used to
> indicate a control i.e. non-packet mbuf. Dedicate the high bit (bit 63)
> for this purpose and add in a utility macro to test if a given mbuf has
> the bit set or not.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> [...]
>
> +/**
> + * Tests if an mbuf is a control mbuf
> + *
> + * @param m
> + *   The mbuf.to be tested
> + * @return
> + *   - True (1) if the mbuf is a control mbuf
> + *   - False(0) otherwise
> + */

Typo s/mbuf.to/mbuf to/


Acked-by: Olivier Matz <olivier.matz@6wind.com>

Patch
diff mbox

diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index 9dfcac3..52e7574 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -69,7 +69,9 @@  rte_ctrlmbuf_init(struct rte_mempool *mp,
 		void *_m,
 		__attribute__((unused)) unsigned i)
 {
+	struct rte_mbuf *m = _m;
 	rte_pktmbuf_init(mp, opaque_arg, _m, i);
+	m->ol_flags |= CTRL_MBUF_FLAG;
 }
 
 /*
diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 6af5b2f..7b0b4f2 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -91,6 +91,7 @@  extern "C" {
 #define PKT_TX_IPV4_CSUM     0x1000 /**< Alias of PKT_TX_IP_CKSUM. */
 #define PKT_TX_IPV4          PKT_RX_IPV4_HDR /**< IPv4 with no IP checksum offload. */
 #define PKT_TX_IPV6          PKT_RX_IPV6_HDR /**< IPv6 packet */
+
 /*
  * Bit 14~13 used for L4 packet type with checksum enabled.
  *     00: Reserved
@@ -106,6 +107,9 @@  extern "C" {
 /* Bit 15 */
 #define PKT_TX_IEEE1588_TMST 0x8000 /**< TX IEEE1588 packet to timestamp. */
 
+/* Use final bit of flags to indicate a control mbuf */
+#define CTRL_MBUF_FLAG       (1ULL << 63)
+
 /**
  * Bit Mask to indicate what bits required for building TX context
  */
@@ -466,6 +470,21 @@  void rte_ctrlmbuf_init(struct rte_mempool *mp, void *opaque_arg,
  */
 #define rte_ctrlmbuf_len(m) rte_pktmbuf_data_len(m)
 
+/**
+ * Tests if an mbuf is a control mbuf
+ *
+ * @param m
+ *   The mbuf.to be tested
+ * @return
+ *   - True (1) if the mbuf is a control mbuf
+ *   - False(0) otherwise
+ */
+static inline int
+rte_is_ctrlmbuf(struct rte_mbuf *m)
+{
+	return (!!(m->ol_flags & CTRL_MBUF_FLAG));
+}
+
 /* Operations on pkt mbuf */
 
 /**