[v7] eal: make lcore_config private

Message ID 20190925161013.3656-1-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series [v7] eal: make lcore_config private |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/iol-dpdk_compile_spdk success Compile Testing PASS
ci/iol-dpdk_compile_ovs success Compile Testing PASS
ci/iol-dpdk_compile success Compile Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Sept. 25, 2019, 4:10 p.m. UTC
  The internal structure of lcore_config is no longer be part of
visible API/ABI. Make it private to EAL.

Rearrange and resize the fields in the structure so it takes
less memory (and cache footprint).

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v7 - add eal_private.h to windows

 lib/librte_eal/common/eal_common_launch.c |  2 ++
 lib/librte_eal/common/eal_private.h       | 22 +++++++++++++++++++++
 lib/librte_eal/common/include/rte_lcore.h | 24 -----------------------
 lib/librte_eal/common/rte_service.c       |  2 ++
 lib/librte_eal/rte_eal_version.map        |  1 -
 lib/librte_eal/windows/eal/eal_thread.c   |  1 +
 6 files changed, 27 insertions(+), 25 deletions(-)
  

Comments

David Marchand Oct. 2, 2019, 8:15 a.m. UTC | #1
Thanks for working on this.

On Wed, Sep 25, 2019 at 6:10 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> The internal structure of lcore_config is no longer be part of
> visible API/ABI. Make it private to EAL.
>
> Rearrange and resize the fields in the structure so it takes
> less memory (and cache footprint).

This patch is missing the release notes update.


>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> v7 - add eal_private.h to windows
>
>  lib/librte_eal/common/eal_common_launch.c |  2 ++
>  lib/librte_eal/common/eal_private.h       | 22 +++++++++++++++++++++
>  lib/librte_eal/common/include/rte_lcore.h | 24 -----------------------
>  lib/librte_eal/common/rte_service.c       |  2 ++
>  lib/librte_eal/rte_eal_version.map        |  1 -
>  lib/librte_eal/windows/eal/eal_thread.c   |  1 +
>  6 files changed, 27 insertions(+), 25 deletions(-)
>
> diff --git a/lib/librte_eal/common/eal_common_launch.c b/lib/librte_eal/common/eal_common_launch.c
> index fe0ba3f0d617..cf52d717f68e 100644
> --- a/lib/librte_eal/common/eal_common_launch.c
> +++ b/lib/librte_eal/common/eal_common_launch.c
> @@ -15,6 +15,8 @@
>  #include <rte_per_lcore.h>
>  #include <rte_lcore.h>
>
> +#include "eal_private.h"
> +
>  /*
>   * Wait until a lcore finished its job.
>   */
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index 798ede553b21..25e80547904f 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -10,6 +10,28 @@
>  #include <stdio.h>
>
>  #include <rte_dev.h>
> +#include <rte_lcore.h>
> +
> +/**
> + * Structure storing internal configuration (per-lcore)
> + */
> +struct lcore_config {
> +       uint32_t core_id;      /**< core number on socket for this lcore */
> +       uint32_t core_index;   /**< relative index, starting from 0 */
> +       uint16_t socket_id;    /**< physical socket id for this lcore */
> +       uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
> +       uint8_t detected;          /**< true if lcore was detected */
> +       volatile enum rte_lcore_state_t state; /**< lcore state */
> +       rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
> +       pthread_t thread_id;       /**< pthread identifier */
> +       int pipe_master2slave[2];  /**< communication pipe with master */
> +       int pipe_slave2master[2];  /**< communication pipe with master */
> +       lcore_function_t * volatile f;         /**< function to call */
> +       void * volatile arg;       /**< argument of function */
> +       volatile int ret;          /**< return value of function */
> +};
> +
> +extern struct lcore_config lcore_config[RTE_MAX_LCORE];

Everything but cpuset can fit in a cache line.
You could just move the cpuset field at the end of the structure and
change detected to uint8_t.
This gives the following layout:

struct lcore_config {
    pthread_t                  thread_id;            /*     0     8 */
    int                        pipe_master2slave[2]; /*     8     8 */
    int                        pipe_slave2master[2]; /*    16     8 */
    volatile lcore_function_t *  f;                  /*    24     8 */
    volatile void *            arg;                  /*    32     8 */
    volatile int               ret;                  /*    40     4 */
    volatile enum rte_lcore_state_t  state;          /*    44     4 */
    unsigned int               socket_id;            /*    48     4 */
    unsigned int               core_id;              /*    52     4 */
    int                        core_index;           /*    56     4 */
    uint8_t                    detected;             /*    60     1 */
    uint8_t                    core_role;            /*    61     1 */

    /* XXX 2 bytes hole, try to pack */

    /* --- cacheline 1 boundary (64 bytes) --- */
    rte_cpuset_t               cpuset;               /*    64   128 */
    /* --- cacheline 3 boundary (192 bytes) --- */

    /* size: 192, cachelines: 3, members: 13 */
    /* sum members: 190, holes: 1, sum holes: 2 */
};

The resulting structure is only two bytes bigger than your proposal
and does not touch existing integer types (avoiding the risk of some
integer conversion on socket_id for example).
  

Patch

diff --git a/lib/librte_eal/common/eal_common_launch.c b/lib/librte_eal/common/eal_common_launch.c
index fe0ba3f0d617..cf52d717f68e 100644
--- a/lib/librte_eal/common/eal_common_launch.c
+++ b/lib/librte_eal/common/eal_common_launch.c
@@ -15,6 +15,8 @@ 
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
 
+#include "eal_private.h"
+
 /*
  * Wait until a lcore finished its job.
  */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 798ede553b21..25e80547904f 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -10,6 +10,28 @@ 
 #include <stdio.h>
 
 #include <rte_dev.h>
+#include <rte_lcore.h>
+
+/**
+ * Structure storing internal configuration (per-lcore)
+ */
+struct lcore_config {
+	uint32_t core_id;      /**< core number on socket for this lcore */
+	uint32_t core_index;   /**< relative index, starting from 0 */
+	uint16_t socket_id;    /**< physical socket id for this lcore */
+	uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
+	uint8_t detected;          /**< true if lcore was detected */
+	volatile enum rte_lcore_state_t state; /**< lcore state */
+	rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
+	pthread_t thread_id;       /**< pthread identifier */
+	int pipe_master2slave[2];  /**< communication pipe with master */
+	int pipe_slave2master[2];  /**< communication pipe with master */
+	lcore_function_t * volatile f;         /**< function to call */
+	void * volatile arg;       /**< argument of function */
+	volatile int ret;          /**< return value of function */
+};
+
+extern struct lcore_config lcore_config[RTE_MAX_LCORE];
 
 /**
  * Initialize the memzone subsystem (private to eal).
diff --git a/lib/librte_eal/common/include/rte_lcore.h b/lib/librte_eal/common/include/rte_lcore.h
index c86f72eb12a8..0c683919564e 100644
--- a/lib/librte_eal/common/include/rte_lcore.h
+++ b/lib/librte_eal/common/include/rte_lcore.h
@@ -66,30 +66,6 @@  typedef cpuset_t rte_cpuset_t;
 } while (0)
 #endif
 
-/**
- * Structure storing internal configuration (per-lcore)
- */
-struct lcore_config {
-	unsigned detected;         /**< true if lcore was detected */
-	pthread_t thread_id;       /**< pthread identifier */
-	int pipe_master2slave[2];  /**< communication pipe with master */
-	int pipe_slave2master[2];  /**< communication pipe with master */
-	lcore_function_t * volatile f;         /**< function to call */
-	void * volatile arg;       /**< argument of function */
-	volatile int ret;          /**< return value of function */
-	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 */
-	int core_index;            /**< relative index, starting from 0 */
-	rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
-	uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
-};
-
-/**
- * Internal configuration (per-lcore)
- */
-extern struct lcore_config lcore_config[RTE_MAX_LCORE];
-
 RTE_DECLARE_PER_LCORE(unsigned, _lcore_id);  /**< Per thread "lcore id". */
 RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset); /**< Per thread "cpuset". */
 
diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c
index c3653ebae46c..6e21f549051b 100644
--- a/lib/librte_eal/common/rte_service.c
+++ b/lib/librte_eal/common/rte_service.c
@@ -21,6 +21,8 @@ 
 #include <rte_memory.h>
 #include <rte_malloc.h>
 
+#include "eal_private.h"
+
 #define RTE_SERVICE_NUM_MAX 64
 
 #define SERVICE_F_REGISTERED    (1 << 0)
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 7cbf82d37b0a..aeedf397764f 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -4,7 +4,6 @@  DPDK_2.0 {
 	__rte_panic;
 	eal_parse_sysfs_value;
 	eal_timer_source;
-	lcore_config;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 906502f90982..0591d4c7fb06 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -12,6 +12,7 @@ 
 #include <rte_common.h>
 #include <eal_thread.h>
 
+#include "eal_private.h"
 
 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;