[dpdk-dev,v6,05/19] eal: add support parsing socket_id from cpuset

Message ID 1423791501-1555-6-git-send-email-cunming.liang@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Cunming Liang Feb. 13, 2015, 1:38 a.m. UTC
It returns the socket_id if all cpus in the cpuset belongs
to the same NUMA node, otherwise it will return SOCKET_ID_ANY.

Signed-off-by: Cunming Liang <cunming.liang@intel.com>
---
 v5 changes:
   expose cpu_socket_id as eal_cpu_socket_id for linuxapp
   eal_cpuset_socket_id() remove static inline and move to c file

 lib/librte_eal/bsdapp/eal/eal_lcore.c   |  7 +++++++
 lib/librte_eal/common/eal_thread.h      | 11 +++++++++++
 lib/librte_eal/linuxapp/eal/eal_lcore.c |  7 ++++---
 3 files changed, 22 insertions(+), 3 deletions(-)
  

Comments

Neil Horman Feb. 13, 2015, 1:51 p.m. UTC | #1
On Fri, Feb 13, 2015 at 09:38:07AM +0800, Cunming Liang wrote:
> It returns the socket_id if all cpus in the cpuset belongs
> to the same NUMA node, otherwise it will return SOCKET_ID_ANY.
> 
> Signed-off-by: Cunming Liang <cunming.liang@intel.com>
> ---
>  v5 changes:
>    expose cpu_socket_id as eal_cpu_socket_id for linuxapp
>    eal_cpuset_socket_id() remove static inline and move to c file
> 
>  lib/librte_eal/bsdapp/eal/eal_lcore.c   |  7 +++++++
>  lib/librte_eal/common/eal_thread.h      | 11 +++++++++++
>  lib/librte_eal/linuxapp/eal/eal_lcore.c |  7 ++++---
>  3 files changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c
> index 72f8ac2..162fb4f 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c
> @@ -41,6 +41,7 @@
>  #include <rte_debug.h>
>  
>  #include "eal_private.h"
> +#include "eal_thread.h"
>  
>  /* No topology information available on FreeBSD including NUMA info */
>  #define cpu_core_id(X) 0
> @@ -112,3 +113,9 @@ rte_eal_cpu_init(void)
>  
>  	return 0;
>  }
> +
> +unsigned
> +eal_cpu_socket_id(__rte_unused unsigned cpu_id)
> +{
> +	return cpu_socket_id(cpu_id);
> +}
> diff --git a/lib/librte_eal/common/eal_thread.h b/lib/librte_eal/common/eal_thread.h
> index b53b84d..f1ce0bd 100644
> --- a/lib/librte_eal/common/eal_thread.h
> +++ b/lib/librte_eal/common/eal_thread.h
> @@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void *arg);
>   */
>  void eal_thread_init_master(unsigned lcore_id);
>  
> +/**
> + * Get the NUMA socket id from cpu id.
> + * This function is private to EAL.
> + *
> + * @param cpu_id
> + *   The logical process id.
> + * @return
> + *   socket_id or SOCKET_ID_ANY
> + */
> +unsigned eal_cpu_socket_id(unsigned cpu_id);
> +
>  #endif /* EAL_THREAD_H */
> diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c
> index 29615f8..ef8c433 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_lcore.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c
> @@ -45,6 +45,7 @@
>  
>  #include "eal_private.h"
>  #include "eal_filesystem.h"
> +#include "eal_thread.h"
>  
>  #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"
>  #define CORE_ID_FILE "topology/core_id"
> @@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)
>   * Note: physical package id != NUMA node, but we use it as a
>   * fallback for kernels which don't create a nodeY link
>   */
> -static unsigned
> -cpu_socket_id(unsigned lcore_id)
> +unsigned
> +eal_cpu_socket_id(unsigned lcore_id)
If you want to export this symbol, then you need to add it to the version map.

Neil
  
Cunming Liang Feb. 15, 2015, 1:16 a.m. UTC | #2
> -----Original Message-----
> From: Neil Horman [mailto:nhorman@tuxdriver.com]
> Sent: Friday, February 13, 2015 9:52 PM
> To: Liang, Cunming
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v6 05/19] eal: add support parsing socket_id
> from cpuset
> 
> On Fri, Feb 13, 2015 at 09:38:07AM +0800, Cunming Liang wrote:
> > It returns the socket_id if all cpus in the cpuset belongs
> > to the same NUMA node, otherwise it will return SOCKET_ID_ANY.
> >
> > Signed-off-by: Cunming Liang <cunming.liang@intel.com>
> > ---
> >  v5 changes:
> >    expose cpu_socket_id as eal_cpu_socket_id for linuxapp
> >    eal_cpuset_socket_id() remove static inline and move to c file
> >
> >  lib/librte_eal/bsdapp/eal/eal_lcore.c   |  7 +++++++
> >  lib/librte_eal/common/eal_thread.h      | 11 +++++++++++
> >  lib/librte_eal/linuxapp/eal/eal_lcore.c |  7 ++++---
> >  3 files changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c
> b/lib/librte_eal/bsdapp/eal/eal_lcore.c
> > index 72f8ac2..162fb4f 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c
> > @@ -41,6 +41,7 @@
> >  #include <rte_debug.h>
> >
> >  #include "eal_private.h"
> > +#include "eal_thread.h"
> >
> >  /* No topology information available on FreeBSD including NUMA info */
> >  #define cpu_core_id(X) 0
> > @@ -112,3 +113,9 @@ rte_eal_cpu_init(void)
> >
> >  	return 0;
> >  }
> > +
> > +unsigned
> > +eal_cpu_socket_id(__rte_unused unsigned cpu_id)
> > +{
> > +	return cpu_socket_id(cpu_id);
> > +}
> > diff --git a/lib/librte_eal/common/eal_thread.h
> b/lib/librte_eal/common/eal_thread.h
> > index b53b84d..f1ce0bd 100644
> > --- a/lib/librte_eal/common/eal_thread.h
> > +++ b/lib/librte_eal/common/eal_thread.h
> > @@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void
> *arg);
> >   */
> >  void eal_thread_init_master(unsigned lcore_id);
> >
> > +/**
> > + * Get the NUMA socket id from cpu id.
> > + * This function is private to EAL.
> > + *
> > + * @param cpu_id
> > + *   The logical process id.
> > + * @return
> > + *   socket_id or SOCKET_ID_ANY
> > + */
> > +unsigned eal_cpu_socket_id(unsigned cpu_id);
> > +
> >  #endif /* EAL_THREAD_H */
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c
> b/lib/librte_eal/linuxapp/eal/eal_lcore.c
> > index 29615f8..ef8c433 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_lcore.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c
> > @@ -45,6 +45,7 @@
> >
> >  #include "eal_private.h"
> >  #include "eal_filesystem.h"
> > +#include "eal_thread.h"
> >
> >  #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"
> >  #define CORE_ID_FILE "topology/core_id"
> > @@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)
> >   * Note: physical package id != NUMA node, but we use it as a
> >   * fallback for kernels which don't create a nodeY link
> >   */
> > -static unsigned
> > -cpu_socket_id(unsigned lcore_id)
> > +unsigned
> > +eal_cpu_socket_id(unsigned lcore_id)
> If you want to export this symbol, then you need to add it to the version map.
[LCM] They're all EAL internal function, won't plan to expose as EAL API.
> 
> Neil
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c
index 72f8ac2..162fb4f 100644
--- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
+++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c
@@ -41,6 +41,7 @@ 
 #include <rte_debug.h>
 
 #include "eal_private.h"
+#include "eal_thread.h"
 
 /* No topology information available on FreeBSD including NUMA info */
 #define cpu_core_id(X) 0
@@ -112,3 +113,9 @@  rte_eal_cpu_init(void)
 
 	return 0;
 }
+
+unsigned
+eal_cpu_socket_id(__rte_unused unsigned cpu_id)
+{
+	return cpu_socket_id(cpu_id);
+}
diff --git a/lib/librte_eal/common/eal_thread.h b/lib/librte_eal/common/eal_thread.h
index b53b84d..f1ce0bd 100644
--- a/lib/librte_eal/common/eal_thread.h
+++ b/lib/librte_eal/common/eal_thread.h
@@ -50,4 +50,15 @@  __attribute__((noreturn)) void *eal_thread_loop(void *arg);
  */
 void eal_thread_init_master(unsigned lcore_id);
 
+/**
+ * Get the NUMA socket id from cpu id.
+ * This function is private to EAL.
+ *
+ * @param cpu_id
+ *   The logical process id.
+ * @return
+ *   socket_id or SOCKET_ID_ANY
+ */
+unsigned eal_cpu_socket_id(unsigned cpu_id);
+
 #endif /* EAL_THREAD_H */
diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c
index 29615f8..ef8c433 100644
--- a/lib/librte_eal/linuxapp/eal/eal_lcore.c
+++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c
@@ -45,6 +45,7 @@ 
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
+#include "eal_thread.h"
 
 #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"
 #define CORE_ID_FILE "topology/core_id"
@@ -71,8 +72,8 @@  cpu_detected(unsigned lcore_id)
  * Note: physical package id != NUMA node, but we use it as a
  * fallback for kernels which don't create a nodeY link
  */
-static unsigned
-cpu_socket_id(unsigned lcore_id)
+unsigned
+eal_cpu_socket_id(unsigned lcore_id)
 {
 	const char node_prefix[] = "node";
 	const size_t prefix_len = sizeof(node_prefix) - 1;
@@ -174,7 +175,7 @@  rte_eal_cpu_init(void)
 		/* By default, each detected core is enabled */
 		config->lcore_role[lcore_id] = ROLE_RTE;
 		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
+		lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id);
 		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
 #ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
 			lcore_config[lcore_id].socket_id = 0;