[dpdk-dev] distributor: add comments to make code more readable

Message ID 1415282132-11056-1-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Bruce Richardson Nov. 6, 2014, 1:55 p.m. UTC
  From: "Bruce Richardson" <bruce.richardson@intel.com>

Add in some additional comments around more complex areas of the code
so as to make the code easier to read and understand.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_distributor/rte_distributor.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Thomas Monjalon Nov. 7, 2014, 2:08 p.m. UTC | #1
2014-11-06 13:55, Bruce Richardson:
> From: "Bruce Richardson" <bruce.richardson@intel.com>
> 
> Add in some additional comments around more complex areas of the code
> so as to make the code easier to read and understand.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Applied

Qinglai, if you change the design, you'll now have some comments to update ;)

Thanks
  
Qinglai Xiao Nov. 7, 2014, 2:31 p.m. UTC | #2
Hi Thomas,

Thanks for the reminder. I didn't notice the change in comments yet.

thx &
rgds,
-qinglai

On Fri, Nov 7, 2014 at 4:08 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2014-11-06 13:55, Bruce Richardson:
> > From: "Bruce Richardson" <bruce.richardson@intel.com>
> >
> > Add in some additional comments around more complex areas of the code
> > so as to make the code easier to read and understand.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
>
> Applied
>
> Qinglai, if you change the design, you'll now have some comments to update
> ;)
>
> Thanks
> --
> Thomas
>
  

Patch

diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
index 585ff88..656ee5c 100644
--- a/lib/librte_distributor/rte_distributor.c
+++ b/lib/librte_distributor/rte_distributor.c
@@ -92,6 +92,7 @@  struct rte_distributor {
 	unsigned num_workers;                 /**< Number of workers polling */
 
 	uint32_t in_flight_tags[RTE_MAX_LCORE];
+		/**< Tracks the tag being processed per core, 0 == no pkt */
 	struct rte_distributor_backlog backlog[RTE_MAX_LCORE];
 
 	union rte_distributor_buffer bufs[RTE_MAX_LCORE];
@@ -282,10 +283,22 @@  rte_distributor_process(struct rte_distributor *d,
 			next_mb = mbufs[next_idx++];
 			next_value = (((int64_t)(uintptr_t)next_mb)
 					<< RTE_DISTRIB_FLAG_BITS);
+			/*
+			 * Set the low bit on the tag, so we can guarantee that
+			 * we never store a tag value of zero. That means we can
+			 * use the zero-value to indicate that no packet is
+			 * being processed by a worker.
+			 */
 			new_tag = (next_mb->hash.rss | 1);
 
 			uint32_t match = 0;
 			unsigned i;
+			/*
+			 * to scan for a match use "xor" and "not" to get a 0/1
+			 * value, then use shifting to merge to single "match"
+			 * variable, where a one-bit indicates a match for the
+			 * worker given by the bit-position
+			 */
 			for (i = 0; i < d->num_workers; i++)
 				match |= (!(d->in_flight_tags[i] ^ new_tag)
 					<< i);