[dpdk-dev] [PATCH] Add an API to query enabled core index

Patrick Lu Patrick.Lu at intel.com
Wed Jun 11 22:45:09 CEST 2014


EAL -c option allows the user to enable any lcore in the system.
Oftentimes, the user app wants to know 1st enabled core, 2nd
enabled core, etc, rather than phyical core ID (rte_lcore_id().)

The new API rte_lcore_id2() will return an index from enabled lcores
starting from zero.
---
 lib/librte_eal/common/include/rte_lcore.h                | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c                        |  1 +
 lib/librte_eal/linuxapp/eal/include/exec-env/rte_lcore.h |  1 +
 3 files changed, 14 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_lcore.h b/lib/librte_eal/common/include/rte_lcore.h
index 3802a28..f0682ce 100644
--- a/lib/librte_eal/common/include/rte_lcore.h
+++ b/lib/librte_eal/common/include/rte_lcore.h
@@ -92,6 +92,18 @@ rte_lcore_count(void)
 #include <exec-env/rte_lcore.h>
 
 /**
+ * Return the index of the enabled lcore starting from zero.
+ *
+ * @return
+ *   the ID of current lcoreid's index
+ */
+static inline unsigned
+rte_lcore_id2(void)
+{
+       return lcore_config[rte_lcore_id()].core_id2;
+}
+
+/**
  * Return the ID of the physical socket of the logical core we are
  * running on.
  * @return
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 070bdc9..a9c9e6c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -444,6 +444,7 @@ eal_parse_coremask(const char *coremask)
 					return -1;
 				}
 				cfg->lcore_role[idx] = ROLE_RTE;
+				lcore_config[idx].core_id2 = count;
 				if(count == 0)
 					cfg->master_lcore = idx;
 				count++;
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_lcore.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_lcore.h
index e19ab54..9316b05 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_lcore.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_lcore.h
@@ -57,6 +57,7 @@ struct lcore_config {
 	volatile enum rte_lcore_state_t state; /**< lcore state */
 	unsigned socket_id;        /**< physical socket id for this lcore */
 	unsigned core_id;          /**< core number on socket for this lcore */
+	unsigned core_id2;         /**< DPDK core index, starting from 0 */
 };
 
 /**
-- 
2.0.0



More information about the dev mailing list