Skip to contentSkip to conversation

eal: move rte_cpu definitions to os specific files

PATCH Applied Pallavi Kadam 3 participants 3 messages Sep 30, 2019 – Oct 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: move rte_cpu definitions to os specific files

Moving RTE_CPU* definitions from the common code to the Linux, FreeBSD rte_os.h file to avoid #ifdef clutter.

---
 lib/librte_eal/common/include/rte_lcore.h   | 44 ---------------------
 lib/librte_eal/freebsd/eal/include/rte_os.h | 27 +++++++++++++
 lib/librte_eal/linux/eal/include/rte_os.h   | 19 +++++++++
 3 files changed, 46 insertions(+), 44 deletions(-)
lib/librte_eal/common/include/rte_lcore.h +0 -44
index c86f72eb1..63ad4af13 100644
@@ -22,50 +22,6 @@ extern "C" {
 
 #define LCORE_ID_ANY     UINT32_MAX       /**< Any lcore. */
 
-#if defined(__linux__)
-typedef	cpu_set_t rte_cpuset_t;
-#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
-#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
-#define RTE_CPU_FILL(set) do \
-{ \
-	unsigned int i; \
-	CPU_ZERO(set); \
-	for (i = 0; i < CPU_SETSIZE; i++) \
-		CPU_SET(i, set); \
-} while (0)
-#define RTE_CPU_NOT(dst, src) do \
-{ \
-	cpu_set_t tmp; \
-	RTE_CPU_FILL(&tmp); \
-	CPU_XOR(dst, &tmp, src); \
-} while (0)
-#elif defined(__FreeBSD__)
-#include <pthread_np.h>
-typedef cpuset_t rte_cpuset_t;
-#define RTE_CPU_AND(dst, src1, src2) do \
-{ \
-	cpuset_t tmp; \
-	CPU_COPY(src1, &tmp); \
-	CPU_AND(&tmp, src2); \
-	CPU_COPY(&tmp, dst); \
-} while (0)
-#define RTE_CPU_OR(dst, src1, src2) do \
-{ \
-	cpuset_t tmp; \
-	CPU_COPY(src1, &tmp); \
-	CPU_OR(&tmp, src2); \
-	CPU_COPY(&tmp, dst); \
-} while (0)
-#define RTE_CPU_FILL(set) CPU_FILL(set)
-#define RTE_CPU_NOT(dst, src) do \
-{ \
-	cpuset_t tmp; \
-	CPU_FILL(&tmp); \
-	CPU_NAND(&tmp, src); \
-	CPU_COPY(&tmp, dst); \
-} while (0)
-#endif
-
 /**
  * Structure storing internal configuration (per-lcore)
  */
lib/librte_eal/freebsd/eal/include/rte_os.h +27 -0
index 49cd4d4d9..b414f6989 100644
@@ -11,4 +11,31 @@
  * freebsd OS. Functions will be added in future releases.
  */
 
+#include <rte_per_lcore.h>
+#include <pthread_np.h>
+
+typedef cpuset_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) do \
+{ \
+	cpuset_t tmp; \
+	CPU_COPY(src1, &tmp); \
+	CPU_AND(&tmp, src2); \
+	CPU_COPY(&tmp, dst); \
+} while (0)
+#define RTE_CPU_OR(dst, src1, src2) do \
+{ \
+	cpuset_t tmp; \
+	CPU_COPY(src1, &tmp); \
+	CPU_OR(&tmp, src2); \
+	CPU_COPY(&tmp, dst); \
+} while (0)
+#define RTE_CPU_FILL(set) CPU_FILL(set)
+#define RTE_CPU_NOT(dst, src) do \
+{ \
+	cpuset_t tmp; \
+	CPU_FILL(&tmp); \
+	CPU_NAND(&tmp, src); \
+	CPU_COPY(&tmp, dst); \
+} while (0)
+
 #endif /* _RTE_OS_H_ */
lib/librte_eal/linux/eal/include/rte_os.h +19 -0
index bc6ad14d2..dd487a830 100644
@@ -11,4 +11,23 @@
  * linux OS. Functions will be added in future releases.
  */
 
+#include <rte_per_lcore.h>
+
+typedef	cpu_set_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
+#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
+#define RTE_CPU_FILL(set) do \
+{ \
+	unsigned int i; \
+	CPU_ZERO(set); \
+	for (i = 0; i < CPU_SETSIZE; i++) \
+		CPU_SET(i, set); \
+} while (0)
+#define RTE_CPU_NOT(dst, src) do \
+{ \
+	cpu_set_t tmp; \
+	RTE_CPU_FILL(&tmp); \
+	CPU_XOR(dst, &tmp, src); \
+} while (0)
+
 #endif /* _RTE_OS_H_ */
Signature · 1 line
2.18.0.windows.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Pallavi Kadam

Moving RTE_CPU* definitions from the common code to the Linux, FreeBSD rte_os.h file to avoid #ifdef clutter.

Nit:

[master][dpdk.org] $ ./devtools/check-git-log.sh Wrong headline format:
eal: move rte_cpu definitions to os specific files

probably, we could fix the above warning with following or similar headline

eal: move OS-specific CPU operations from common code

With check-git-log.sh fix:

Quoted 128 lines
---
 lib/librte_eal/common/include/rte_lcore.h   | 44 ---------------------
 lib/librte_eal/freebsd/eal/include/rte_os.h | 27 +++++++++++++
 lib/librte_eal/linux/eal/include/rte_os.h   | 19 +++++++++
 3 files changed, 46 insertions(+), 44 deletions(-)
lib/librte_eal/common/include/rte_lcore.h +0 -44
index c86f72eb1..63ad4af13 100644
@@ -22,50 +22,6 @@ extern "C" {
 
 #define LCORE_ID_ANY     UINT32_MAX       /**< Any lcore. */
 
-#if defined(__linux__)
-typedef        cpu_set_t rte_cpuset_t;
-#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
-#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
-#define RTE_CPU_FILL(set) do \
-{ \
-       unsigned int i; \
-       CPU_ZERO(set); \
-       for (i = 0; i < CPU_SETSIZE; i++) \
-               CPU_SET(i, set); \
-} while (0)
-#define RTE_CPU_NOT(dst, src) do \
-{ \
-       cpu_set_t tmp; \
-       RTE_CPU_FILL(&tmp); \
-       CPU_XOR(dst, &tmp, src); \
-} while (0)
-#elif defined(__FreeBSD__)
-#include <pthread_np.h>
-typedef cpuset_t rte_cpuset_t;
-#define RTE_CPU_AND(dst, src1, src2) do \
-{ \
-       cpuset_t tmp; \
-       CPU_COPY(src1, &tmp); \
-       CPU_AND(&tmp, src2); \
-       CPU_COPY(&tmp, dst); \
-} while (0)
-#define RTE_CPU_OR(dst, src1, src2) do \
-{ \
-       cpuset_t tmp; \
-       CPU_COPY(src1, &tmp); \
-       CPU_OR(&tmp, src2); \
-       CPU_COPY(&tmp, dst); \
-} while (0)
-#define RTE_CPU_FILL(set) CPU_FILL(set)
-#define RTE_CPU_NOT(dst, src) do \
-{ \
-       cpuset_t tmp; \
-       CPU_FILL(&tmp); \
-       CPU_NAND(&tmp, src); \
-       CPU_COPY(&tmp, dst); \
-} while (0)
-#endif
-
 /**
  * Structure storing internal configuration (per-lcore)
  */
lib/librte_eal/freebsd/eal/include/rte_os.h +27 -0
index 49cd4d4d9..b414f6989 100644
@@ -11,4 +11,31 @@
  * freebsd OS. Functions will be added in future releases.
  */
 
+#include <rte_per_lcore.h>
+#include <pthread_np.h>
+
+typedef cpuset_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) do \
+{ \
+       cpuset_t tmp; \
+       CPU_COPY(src1, &tmp); \
+       CPU_AND(&tmp, src2); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
+#define RTE_CPU_OR(dst, src1, src2) do \
+{ \
+       cpuset_t tmp; \
+       CPU_COPY(src1, &tmp); \
+       CPU_OR(&tmp, src2); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
+#define RTE_CPU_FILL(set) CPU_FILL(set)
+#define RTE_CPU_NOT(dst, src) do \
+{ \
+       cpuset_t tmp; \
+       CPU_FILL(&tmp); \
+       CPU_NAND(&tmp, src); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
+
 #endif /* _RTE_OS_H_ */
lib/librte_eal/linux/eal/include/rte_os.h +19 -1
index bc6ad14d2..dd487a830 100644
@@ -11,4 +11,23 @@
  * linux OS. Functions will be added in future releases.
  */
 
+#include <rte_per_lcore.h>
+
+typedef        cpu_set_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
+#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
+#define RTE_CPU_FILL(set) do \
+{ \
+       unsigned int i; \
+       CPU_ZERO(set); \
+       for (i = 0; i < CPU_SETSIZE; i++) \
+               CPU_SET(i, set); \
+} while (0)
+#define RTE_CPU_NOT(dst, src) do \
+{ \
+       cpu_set_t tmp; \
+       RTE_CPU_FILL(&tmp); \
+       CPU_XOR(dst, &tmp, src); \
+} while (0)
+
 #endif /* _RTE_OS_H_ */
--

2.18.0.windows.1

Reviewed-by Jerin Jacob on v1 1/1 Applied
#2 lore raw
In reply to Pallavi Kadam
Quoted 7 lines · Pallavi Kadam

Moving RTE_CPU* definitions from the common code to the Linux, FreeBSD rte_os.h file to avoid #ifdef clutter.

Took into account Jerin suggestion for title.

Quoted 66 lines
---
 lib/librte_eal/common/include/rte_lcore.h   | 44 ---------------------
 lib/librte_eal/freebsd/eal/include/rte_os.h | 27 +++++++++++++
 lib/librte_eal/linux/eal/include/rte_os.h   | 19 +++++++++
 3 files changed, 46 insertions(+), 44 deletions(-)
lib/librte_eal/common/include/rte_lcore.h +0 -44
index c86f72eb1..63ad4af13 100644
@@ -22,50 +22,6 @@ extern "C" {
 
 #define LCORE_ID_ANY     UINT32_MAX       /**< Any lcore. */
 
-#if defined(__linux__)
-typedef        cpu_set_t rte_cpuset_t;
-#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
-#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
-#define RTE_CPU_FILL(set) do \
-{ \
-       unsigned int i; \
-       CPU_ZERO(set); \
-       for (i = 0; i < CPU_SETSIZE; i++) \
-               CPU_SET(i, set); \
-} while (0)
-#define RTE_CPU_NOT(dst, src) do \
-{ \
-       cpu_set_t tmp; \
-       RTE_CPU_FILL(&tmp); \
-       CPU_XOR(dst, &tmp, src); \
-} while (0)
-#elif defined(__FreeBSD__)
-#include <pthread_np.h>
-typedef cpuset_t rte_cpuset_t;
-#define RTE_CPU_AND(dst, src1, src2) do \
-{ \
-       cpuset_t tmp; \
-       CPU_COPY(src1, &tmp); \
-       CPU_AND(&tmp, src2); \
-       CPU_COPY(&tmp, dst); \
-} while (0)
-#define RTE_CPU_OR(dst, src1, src2) do \
-{ \
-       cpuset_t tmp; \
-       CPU_COPY(src1, &tmp); \
-       CPU_OR(&tmp, src2); \
-       CPU_COPY(&tmp, dst); \
-} while (0)
-#define RTE_CPU_FILL(set) CPU_FILL(set)
-#define RTE_CPU_NOT(dst, src) do \
-{ \
-       cpuset_t tmp; \
-       CPU_FILL(&tmp); \
-       CPU_NAND(&tmp, src); \
-       CPU_COPY(&tmp, dst); \
-} while (0)
-#endif
-
 /**
  * Structure storing internal configuration (per-lcore)
  */
lib/librte_eal/freebsd/eal/include/rte_os.h +0 -0
index 49cd4d4d9..b414f6989 100644

lib/librte_eal/freebsd/eal/include/rte_os.h line 15

Quoted 5 lines
lib/librte_eal/freebsd/eal/include/rte_os.h +2 -0
@@ -11,4 +11,31 @@
  * freebsd OS. Functions will be added in future releases.
  */
 
+#include <rte_per_lcore.h>
+#include <pthread_np.h>

Including pthread_np.h is enough.

Quoted 31 lines
lib/librte_eal/freebsd/eal/include/rte_os.h +25 -0
+
+typedef cpuset_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) do \
+{ \
+       cpuset_t tmp; \
+       CPU_COPY(src1, &tmp); \
+       CPU_AND(&tmp, src2); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
+#define RTE_CPU_OR(dst, src1, src2) do \
+{ \
+       cpuset_t tmp; \
+       CPU_COPY(src1, &tmp); \
+       CPU_OR(&tmp, src2); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
+#define RTE_CPU_FILL(set) CPU_FILL(set)
+#define RTE_CPU_NOT(dst, src) do \
+{ \
+       cpuset_t tmp; \
+       CPU_FILL(&tmp); \
+       CPU_NAND(&tmp, src); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
+
 #endif /* _RTE_OS_H_ */
lib/librte_eal/linux/eal/include/rte_os.h +0 -0
index bc6ad14d2..dd487a830 100644

lib/librte_eal/linux/eal/include/rte_os.h line 14

Quoted 4 lines
lib/librte_eal/linux/eal/include/rte_os.h +1 -0
@@ -11,4 +11,23 @@
  * linux OS. Functions will be added in future releases.
  */
 
+#include <rte_per_lcore.h>

cpu_set_t and the CPU macros come from sched.h.
No need for rte_per_lcore.h.

lib/librte_eal/linux/eal/include/rte_os.h line 16

Quoted 2 lines
lib/librte_eal/linux/eal/include/rte_os.h +2 -0
+
+typedef        cpu_set_t rte_cpuset_t;

Fixed indent.

Quoted 18 lines
lib/librte_eal/linux/eal/include/rte_os.h +16 -1
+#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
+#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
+#define RTE_CPU_FILL(set) do \
+{ \
+       unsigned int i; \
+       CPU_ZERO(set); \
+       for (i = 0; i < CPU_SETSIZE; i++) \
+               CPU_SET(i, set); \
+} while (0)
+#define RTE_CPU_NOT(dst, src) do \
+{ \
+       cpu_set_t tmp; \
+       RTE_CPU_FILL(&tmp); \
+       CPU_XOR(dst, &tmp, src); \
+} while (0)
+
 #endif /* _RTE_OS_H_ */
--
Quoted 2 lines

2.18.0.windows.1

Applied, thanks.

--
David Marchand