Skip to contentSkip to conversation

Move common functions in EAL

PATCH Superseded Ravi Kerur 2 participants 22 messages Apr 9, 2015 – Apr 16, 2015 10 messages not in the archive

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ravi Kerur

author
#0 lore raw

v5 cover Move common functions in EAL

Changes include moving common functions in BSD and Linux into common directory.
Use appropriate wrapper functions to mask minor differences.

Testing:
Linux - Ubuntu x86_64 14.04
Compilation successful (x86_64-native-linuxapp-gcc). "make test" results match baseline code. testpmd utility on I217/I218 Intel chipset.

FreeBSD 10.0 x86_64
Compilation successful (x86_64-native-bsdapp-gcc). helloworld.

Ravi Kerur (6):
Move common functions in eal_thread.c
Move common functions in eal.c
Move common functions in eal_lcore.c
Move common functions in eal_timer.c
Move common functions in eal_memory.c
Move common functions in eal_pci.c

 lib/librte_eal/bsdapp/eal/Makefile              |   6 +-
 lib/librte_eal/bsdapp/eal/eal.c                 | 271 +++-------------------
 lib/librte_eal/bsdapp/eal/eal_lcore.c           |  72 ++----
 lib/librte_eal/bsdapp/eal/eal_memory.c          |  47 ++--
 lib/librte_eal/bsdapp/eal/eal_pci.c             | 122 ++--------
 lib/librte_eal/bsdapp/eal/eal_thread.c          | 152 ------------
 lib/librte_eal/bsdapp/eal/eal_timer.c           |  52 +----
 lib/librte_eal/common/eal_common_lcore.c        | 107 +++++++++
 lib/librte_eal/common/eal_common_memory.c       |  38 ++-
 lib/librte_eal/common/eal_common_pci.c          | 130 ++++++++++-
 lib/librte_eal/common/eal_common_runtime.c      | 201 ++++++++++++++++
 lib/librte_eal/common/eal_common_system.c       | 203 ++++++++++++++++
 lib/librte_eal/common/eal_common_thread.c       | 158 +++++++++++++
 lib/librte_eal/common/eal_common_timer.c        | 101 ++++++++
 lib/librte_eal/common/eal_hugepages.h           |   1 +
 lib/librte_eal/common/eal_private.h             | 186 +++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         |   4 +
 lib/librte_eal/common/include/rte_pci_dev_ids.h |   8 +-
 lib/librte_eal/linuxapp/eal/Makefile            |   5 +
 lib/librte_eal/linuxapp/eal/eal.c               | 295 ++++--------------------
 lib/librte_eal/linuxapp/eal/eal_lcore.c         |  66 +-----
 lib/librte_eal/linuxapp/eal/eal_memory.c        |  36 +--
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 100 +-------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h      |   6 -
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  36 +--
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  17 +-
 lib/librte_eal/linuxapp/eal/eal_thread.c        | 152 ------------
 lib/librte_eal/linuxapp/eal/eal_timer.c         |  55 +----
 28 files changed, 1355 insertions(+), 1332 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c
 create mode 100644 lib/librte_eal/common/eal_common_runtime.c
 create mode 100644 lib/librte_eal/common/eal_common_system.c
 create mode 100644 lib/librte_eal/common/eal_common_timer.c
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608301-31033-1-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#2 lore raw

v5 cover Move common functions in EAL

Changes include moving common functions in BSD and Linux into common directory.
Use appropriate wrapper functions to mask minor differences.

Testing:
Linux - Ubuntu x86_64 14.04
Compilation successful (x86_64-native-linuxapp-gcc). "make test" results match baseline code. testpmd utility on I217/I218 Intel chipset.

FreeBSD 10.0 x86_64
Compilation successful (x86_64-native-bsdapp-gcc). helloworld.

Ravi Kerur (6):
Move common functions in eal_thread.c
Move common functions in eal.c
Move common functions in eal_lcore.c
Move common functions in eal_timer.c
Move common functions in eal_memory.c
Move common functions in eal_pci.c

 lib/librte_eal/bsdapp/eal/Makefile              |   6 +-
 lib/librte_eal/bsdapp/eal/eal.c                 | 271 +++-------------------
 lib/librte_eal/bsdapp/eal/eal_lcore.c           |  72 ++----
 lib/librte_eal/bsdapp/eal/eal_memory.c          |  47 ++--
 lib/librte_eal/bsdapp/eal/eal_pci.c             | 122 ++--------
 lib/librte_eal/bsdapp/eal/eal_thread.c          | 152 ------------
 lib/librte_eal/bsdapp/eal/eal_timer.c           |  52 +----
 lib/librte_eal/common/eal_common_lcore.c        | 107 +++++++++
 lib/librte_eal/common/eal_common_memory.c       |  38 ++-
 lib/librte_eal/common/eal_common_pci.c          | 130 ++++++++++-
 lib/librte_eal/common/eal_common_runtime.c      | 201 ++++++++++++++++
 lib/librte_eal/common/eal_common_system.c       | 203 ++++++++++++++++
 lib/librte_eal/common/eal_common_thread.c       | 158 +++++++++++++
 lib/librte_eal/common/eal_common_timer.c        | 101 ++++++++
 lib/librte_eal/common/eal_hugepages.h           |   1 +
 lib/librte_eal/common/eal_private.h             | 186 +++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         |   4 +
 lib/librte_eal/common/include/rte_pci_dev_ids.h |   8 +-
 lib/librte_eal/linuxapp/eal/Makefile            |   5 +
 lib/librte_eal/linuxapp/eal/eal.c               | 295 ++++--------------------
 lib/librte_eal/linuxapp/eal/eal_lcore.c         |  66 +-----
 lib/librte_eal/linuxapp/eal/eal_memory.c        |  36 +--
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 100 +-------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h      |   6 -
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  36 +--
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  17 +-
 lib/librte_eal/linuxapp/eal/eal_thread.c        | 152 ------------
 lib/librte_eal/linuxapp/eal/eal_timer.c         |  55 +----
 28 files changed, 1355 insertions(+), 1332 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c
 create mode 100644 lib/librte_eal/common/eal_common_runtime.c
 create mode 100644 lib/librte_eal/common/eal_common_system.c
 create mode 100644 lib/librte_eal/common/eal_common_timer.c
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-1-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#4 lore raw

PATCH v5 1/8 Move common functions in eal_thread.c

Changes in v5
Rebase to latest code.

Changes in v4
None

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
None

Changes in v1
eal_thread.c has minor differences between Linux and BSD, move entire file into common directory.
Use RTE_EXEC_ENV_BSDAPP to differentiate on minor differences. Rename eal_thread.c to eal_common_thread.c
Makefile changes to reflect file move and name change. Fix checkpatch warnings.

---
 lib/librte_eal/bsdapp/eal/Makefile        |   2 +-
 lib/librte_eal/bsdapp/eal/eal_thread.c    | 152 ----------------------------
 lib/librte_eal/common/eal_common_thread.c | 158 ++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_thread.c  | 152 ----------------------------
 4 files changed, 159 insertions(+), 305 deletions(-)
lib/librte_eal/bsdapp/eal/Makefile +1 -1
index 2357cfa..55971b9 100644
@@ -87,7 +87,7 @@ CFLAGS_eal_common_log.o := -D_GNU_SOURCE
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
-CFLAGS_eal_thread.o += -Wno-return-type
+CFLAGS_eal_common_thread.o += -Wno-return-type
 CFLAGS_eal_hpet.o += -Wno-return-type
 endif
 
lib/librte_eal/bsdapp/eal/eal_thread.c +0 -152

163 lines not on this page · raw message

lib/librte_eal/common/eal_common_thread.c +158 -0

182 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/eal_thread.c +0 -152

164 lines not on this page · raw message

Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-2-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

Re: [PATCH v5 1/8] Move common functions in eal_thread.c

Hi Ravi,

2015-04-09 12:40, Ravi Kerur:

Quoted 2 lines
lib/librte_eal/common/eal_common_thread.c +0 -0

[...]

Quoted 6 lines
lib/librte_eal/common/eal_common_thread.c +5 -0
+#ifdef RTE_EXEC_ENV_BSDAPP
+#include <pthread_np.h>
+#include <sys/thr.h>
+#else /* RTE_EXEC_ENV_BSDAPP */
 #include <pthread.h>
+#endif /* RTE_EXEC_ENV_BSDAPP */

[...]

lib/librte_eal/common/eal_common_thread.c exit: · line 278

Quoted 7 lines
lib/librte_eal/common/eal_common_thread.c +7 -0
+#ifdef RTE_EXEC_ENV_BSDAPP
+	RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
+		lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
+#else /* RTE_EXEC_ENV_BSDAPP */
+	RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%x;cpuset=[%s%s])\n",
+		lcore_id, (int)thread_id, cpuset, ret == 0 ? "" : "...");
+#endif /* RTE_EXEC_ENV_BSDAPP */

These lines should stay in bsdapp and linuxapp directory. You can add a new function to eal_thread.h to format the thread id, so you'll be able to use %s in generic log above.

author
#7 lore raw

Re: [PATCH v5 1/8] Move common functions in eal_thread.c

Quoted 13 lines · Thomas Monjalon

Hi Ravi,

2015-04-09 12:40, Ravi Kerur:

Quoted 2 lines
lib/librte_eal/common/eal_common_thread.c +0 -0

[...]

Quoted 6 lines
lib/librte_eal/common/eal_common_thread.c +5 -0
+#ifdef RTE_EXEC_ENV_BSDAPP
+#include <pthread_np.h>
+#include <sys/thr.h>
+#else /* RTE_EXEC_ENV_BSDAPP */
 #include <pthread.h>
+#endif /* RTE_EXEC_ENV_BSDAPP */

[...]

Quoted 12 lines

lib/librte_eal/common/eal_common_thread.c exit: · line 278

Quoted 7 lines
lib/librte_eal/common/eal_common_thread.c +7 -0
+#ifdef RTE_EXEC_ENV_BSDAPP
+     RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
+             lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
+#else /* RTE_EXEC_ENV_BSDAPP */
+     RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%x;cpuset=[%s%s])\n",
+             lcore_id, (int)thread_id, cpuset, ret == 0 ? "" : "...");
+#endif /* RTE_EXEC_ENV_BSDAPP */

These lines should stay in bsdapp and linuxapp directory. You can add a new function to eal_thread.h to format the thread id, so you'll be able to use %s in generic log above.

Thomas, sure will make the changes. I will wait for additional comments if any for other patches and send v6 together.

Thanks.

A message that is not in the archive (sent off-list or not yet received): CAFb4SLBUrSviEu3+f-vv3j4OktjodM5Dy0AUbxrpa2QtxpAVWQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

author
#9 lore raw

Re: [PATCH v5 1/8] Move common functions in eal_thread.c

Quoted 31 lines · Ravi Kerur
Quoted 13 lines · Thomas Monjalon

Hi Ravi,

2015-04-09 12:40, Ravi Kerur:

Quoted 2 lines
lib/librte_eal/common/eal_common_thread.c +0 -0

[...]

Quoted 6 lines
lib/librte_eal/common/eal_common_thread.c +5 -0
+#ifdef RTE_EXEC_ENV_BSDAPP
+#include <pthread_np.h>
+#include <sys/thr.h>
+#else /* RTE_EXEC_ENV_BSDAPP */
 #include <pthread.h>
+#endif /* RTE_EXEC_ENV_BSDAPP */

[...]

Quoted 12 lines

lib/librte_eal/common/eal_common_thread.c exit: · line 278

Quoted 7 lines
lib/librte_eal/common/eal_common_thread.c +7 -0
+#ifdef RTE_EXEC_ENV_BSDAPP
+     RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
+             lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
+#else /* RTE_EXEC_ENV_BSDAPP */
+     RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%x;cpuset=[%s%s])\n",
+             lcore_id, (int)thread_id, cpuset, ret == 0 ? "" : "...");
+#endif /* RTE_EXEC_ENV_BSDAPP */

These lines should stay in bsdapp and linuxapp directory. You can add a new function to eal_thread.h to format the thread id, so you'll be able to use %s in generic log above.

Quoted 6 lines

Thomas, sure will make the changes. I will wait for additional comments if any for other patches and send v6 together.

Thanks.

I plan to use pthread_setname_np after pthread_create and use pthread_getname_np in RTE_LOG. Both these library calls are available in BSD and Linux. Let me know if this is ok??

author
#10 lore raw

PATCH v5 2/8 Move common functions in eal.c

In reply to a message not in the archive

Changes in v5
Rebase to latest code.

Changes in v4
Remove eal_externs.h file, instead use _get_ and _set_ APIS to access those variables.
Split eal_common.c into eal_common_system.c and
and eal_common_runtime.c
rte_eal prefix functions are moved to _runtime_ and eal prefix functions are moved to _system_ files respectively.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
In function rte_eal_config_create remove #ifdef _BSDAPP_ and initialize mem_cfg_addr unconditionally.

Changes in v1
Move common functions in eal.c to librte_eal/common/eal_common.c.

Following functions are moved to eal_common.c file.

struct rte_config *rte_eal_get_configuration(void);
int eal_parse_sysfs_value(const char *filename, unsigned long *val); static void rte_eal_config_create(void);
enum rte_proc_type_t eal_proc_type_detect(void);
void rte_eal_config_init(void);
rte_usage_hook_t rte_set_application_usage_hook(rte_usage_hook_t usage_func); inline size_t eal_get_hugepage_mem_size(void);
void eal_check_mem_on_local_socket(void);
int sync_func(__attribute__((unused)) void *arg);
inline void rte_eal_mcfg_complete(void);
int rte_eal_has_hugepages(void);
enum rte_lcore_role_t rte_eal_lcore_role(unsigned lcore_id);
enum rte_proc_type_t rte_eal_process_type(void);

Makefile changes to reflect new files added.
Fix checkpatch warnings and errors.

---
 lib/librte_eal/bsdapp/eal/Makefile         |   2 +
 lib/librte_eal/bsdapp/eal/eal.c            | 271 ++++----------------------
 lib/librte_eal/common/eal_common_runtime.c | 201 ++++++++++++++++++++
 lib/librte_eal/common/eal_common_system.c  | 203 ++++++++++++++++++++
 lib/librte_eal/common/eal_hugepages.h      |   1 +
 lib/librte_eal/common/eal_private.h        |  78 ++++++++
 lib/librte_eal/common/include/rte_eal.h    |   4 +
 lib/librte_eal/linuxapp/eal/Makefile       |   2 +
 lib/librte_eal/linuxapp/eal/eal.c          | 295 ++++-------------------------
 9 files changed, 566 insertions(+), 491 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_runtime.c
 create mode 100644 lib/librte_eal/common/eal_common_system.c
lib/librte_eal/bsdapp/eal/Makefile +2 -0
index 55971b9..d0a7c43 100644
@@ -78,6 +78,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_system.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_runtime.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/bsdapp/eal/eal.c +33 -238

342 lines not on this page · raw message

lib/librte_eal/common/eal_common_runtime.c new file +201 -0

201 lines not on this page · raw message

lib/librte_eal/common/eal_common_system.c new file +203 -0

203 lines not on this page · raw message

lib/librte_eal/common/eal_hugepages.h +1 -0
index 38edac0..0b4d7a2 100644
@@ -63,5 +63,6 @@ struct hugepage_file {
  * for the EAL to use
  */
 int eal_hugepage_info_init(void);
+inline size_t eal_get_hugepage_mem_size(void);
 
 #endif /* EAL_HUGEPAGES_H */
lib/librte_eal/common/eal_private.h +78 -0

88 lines not on this page · raw message

lib/librte_eal/common/include/rte_eal.h +4 -0
index 1385a73..daf2ee0 100644
@@ -51,6 +51,10 @@ extern "C" {
 
 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
 
+#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
+
+#define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
+
 /**
  * The lcore role (used in RTE or not).
  */
lib/librte_eal/linuxapp/eal/Makefile +2 -0
index 01f7b70..c36d5f4 100644
@@ -90,6 +90,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_system.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_runtime.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal.c +42 -253

406 lines not on this page · raw message

Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-3-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#12 lore raw

Re: [PATCH v5 2/8] Move common functions in eal.c

Hi Ravi,

I think this patch is too complex and move too many different things:
- sysfs
- mem_cfg
- proc_type
- application_usage
Please split them up.

I'm not sure the classification in eal_common_runtime.c and eal_common_system.c new file is clear.

2015-04-09 12:40, Ravi Kerur:

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 120

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +1 -0
+	mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),

Why this cast is needed?

author
#13 lore raw

Re: [PATCH v5 2/8] Move common functions in eal.c

Quoted 9 lines · Thomas Monjalon

Hi Ravi,

I think this patch is too complex and move too many different things:
- sysfs
- mem_cfg
- proc_type
- application_usage
Please split them up.

Quoted 4 lines

I'm not sure the classification in eal_common_runtime.c and eal_common_system.c
new file is clear.

I chose most system related functions (hugepages, lcore sockets, sysfs) into eal_common_system.c file. Rest I moved them to eal_common_runtime.c file for lack of better name. You want more fine grained control and divide them into 4 files??

Quoted 7 lines

2015-04-09 12:40, Ravi Kerur:

Quoted 1 line

+ mem_config = (struct rte_mem_config *) mmap(NULL,

sizeof(*mem_config),

Why this cast is needed?

Linux has it, BSD doesn't. I just chose Linux version.

A message that is not in the archive (sent off-list or not yet received): CAFb4SLCt6HAnL7tb7HJB2HBvHPoMghkv-e-pCiK_EyjYB_p9ew-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

author
#15 lore raw

Re: [PATCH v5 2/8] Move common functions in eal.c

Thomas, Thanks for the review so far, I will make necessary changes and send out v6.

Thanks, Ravi

Quoted 35 lines · Ravi Kerur
Quoted 9 lines · Thomas Monjalon

Hi Ravi,

I think this patch is too complex and move too many different things:
- sysfs
- mem_cfg
- proc_type
- application_usage
Please split them up.

Quoted 4 lines

I'm not sure the classification in eal_common_runtime.c and eal_common_system.c
new file is clear.

I chose most system related functions (hugepages, lcore sockets, sysfs) into eal_common_system.c file. Rest I moved them to eal_common_runtime.c file for lack of better name. You want more fine grained control and divide them into 4 files??

Quoted 7 lines

2015-04-09 12:40, Ravi Kerur:

Quoted 1 line

+ mem_config = (struct rte_mem_config *) mmap(NULL,

sizeof(*mem_config),

Why this cast is needed?

Linux has it, BSD doesn't. I just chose Linux version.

author
#16 lore raw

PATCH v5 3/8 Move common functions in eal_lcore.c

In reply to a message not in the archive

Changes in v5
Rebase to latest code.

Changes in v4
Implement cpu_detected() for BSD.
Have common RTE_LOG for Linux and BSD in rte_eal_cpu_init(). Remove RTE_EXEC_ENV_BSDAPP in common file.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
None

Changes in v1
Move common function in eal_lcore.c to librte_eal/common/ eal_common_lcore.c file.

Following function is moved to eal_common_lcore.c file

int rte_eal_cpu_init(void);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function.
Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

---
 lib/librte_eal/bsdapp/eal/Makefile       |   1 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c    |  72 +++++----------------
 lib/librte_eal/common/eal_common_lcore.c | 107 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h      |  14 ++++
 lib/librte_eal/linuxapp/eal/Makefile     |   2 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c  |  66 ++-----------------
 6 files changed, 143 insertions(+), 119 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index d0a7c43..a28ead3 100644
@@ -80,6 +80,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_system.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_runtime.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/bsdapp/eal/eal_lcore.c +15 -57

89 lines not on this page · raw message

lib/librte_eal/common/eal_common_lcore.c new file +107 -0

107 lines not on this page · raw message

lib/librte_eal/common/eal_private.h +14 -0
index cdcf4b9..458e8c1 100644
@@ -310,4 +310,18 @@ void rte_eal_config_attach(void);
  */
 void rte_eal_config_reattach(void);
 
+/**
+ * This function gets cpu core_id
+ *
+ * This function is private to the EAL.
+ */
+unsigned eal_cpu_core_id(unsigned lcore_id);
+
+/**
+ * This function check if cpu is present
+ *
+ * This function is private to the EAL.
+ */
+int eal_cpu_detected(unsigned lcore_id);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/linuxapp/eal/Makefile +2 -0
index c36d5f4..8ae23a0 100644
@@ -92,6 +92,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_system.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_runtime.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
@@ -106,6 +107,7 @@ CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE
 CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE
 CFLAGS_eal_common_options.o := -D_GNU_SOURCE
 CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
+CFLAGS_eal_common_lcore.o := -D_GNU_SOURCE
 
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
lib/librte_eal/linuxapp/eal/eal_lcore.c +4 -62

81 lines not on this page · raw message

Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-4-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#18 lore raw

Re: [PATCH v5 3/8] Move common functions in eal_lcore.c

2015-04-09 12:40, Ravi Kerur:

Quoted 28 lines

Changes in v5
Rebase to latest code.

Changes in v4
Implement cpu_detected() for BSD.
Have common RTE_LOG for Linux and BSD in rte_eal_cpu_init(). Remove RTE_EXEC_ENV_BSDAPP in common file.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
None

Changes in v1
Move common function in eal_lcore.c to librte_eal/common/ eal_common_lcore.c file.

Following function is moved to eal_common_lcore.c file

int rte_eal_cpu_init(void);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function.
Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

[...]

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_lcore.c +0 -0

[...]

lib/librte_eal/bsdapp/eal/eal_lcore.c line 54

Quoted 3 lines

static int

lib/librte_eal/bsdapp/eal/eal_lcore.c +1 -1
-get_ncpus(void)
+eal_get_ncpus(void)

Why not keep it static as it seems to be specific to BSD handling?

Quoted 6 lines

{

lib/librte_eal/bsdapp/eal/eal_lcore.c +0 -0
 	int mib[2] = {CTL_HW, HW_NCPU};
 	int ncpu;
@@ -59,63 +62,18 @@ get_ncpus(void)
 	return ncpu;
 }

[...]

Quoted 12 lines
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -3
-unsigned
-eal_cpu_socket_id(__rte_unused unsigned cpu_id)
+/* Check if a cpu is present by the presence of the
+ * cpu information for it.
+ */
+int
+eal_cpu_detected(unsigned lcore_id)
 {
-	return cpu_socket_id(cpu_id);
+	const unsigned ncpus = eal_get_ncpus();
+	return (lcore_id < ncpus);
 }
author
#19 lore raw

Re: [PATCH v5 3/8] Move common functions in eal_lcore.c

Quoted 30 lines · Thomas Monjalon

2015-04-09 12:40, Ravi Kerur:

Quoted 28 lines

Changes in v5
Rebase to latest code.

Changes in v4
Implement cpu_detected() for BSD.
Have common RTE_LOG for Linux and BSD in rte_eal_cpu_init(). Remove RTE_EXEC_ENV_BSDAPP in common file.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
None

Changes in v1
Move common function in eal_lcore.c to librte_eal/common/ eal_common_lcore.c file.

Following function is moved to eal_common_lcore.c file

int rte_eal_cpu_init(void);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function.
Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

[...]

Quoted 9 lines
Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_lcore.c +0 -0

[...]

lib/librte_eal/bsdapp/eal/eal_lcore.c line 54

Quoted 3 lines

static int

lib/librte_eal/bsdapp/eal/eal_lcore.c +1 -1
-get_ncpus(void)
+eal_get_ncpus(void)

Why not keep it static as it seems to be specific to BSD handling?

It is static with the changes, "name" is changed from "get_ncpus" to "eal_get_ncpus".

Quoted 24 lines
Quoted 7 lines
 {
      int mib[2] = {CTL_HW, HW_NCPU};
      int ncpu;
lib/librte_eal/bsdapp/eal/eal_lcore.c +0 -0
@@ -59,63 +62,18 @@ get_ncpus(void)
      return ncpu;
 }

[...]

Quoted 12 lines
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -3
-unsigned
-eal_cpu_socket_id(__rte_unused unsigned cpu_id)
+/* Check if a cpu is present by the presence of the
+ * cpu information for it.
+ */
+int
+eal_cpu_detected(unsigned lcore_id)
 {
-     return cpu_socket_id(cpu_id);
+     const unsigned ncpus = eal_get_ncpus();
+     return (lcore_id < ncpus);
 }
author
#20 lore raw

PATCH v5 4/8 Move common functions in eal_timer.c

In reply to a message not in the archive

Changes in v5
Rebase to latest code.

Changes in v4
Removed extern declaration of eal_tsc_resolution_hz, instead provided _set_ API.
Make set_tsc_freq_from_clock as wrapper function for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function name set_tsc_freq_from_sysctl for BSD and Linux. Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_timer.c to librte_eal/common/ eal_common_timer.c file.

Following functions are moved to eal_common_timer.c file

void rte_delay_us(unsigned us);
uint64_t rte_get_tsc_hz(void);
static void set_tsc_freq_fallback(void);
void set_tsc_freq(void);

Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

---
 lib/librte_eal/bsdapp/eal/Makefile       |   1 +
 lib/librte_eal/bsdapp/eal/eal_timer.c    |  52 +++-------------
 lib/librte_eal/common/eal_common_timer.c | 101 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h      |  24 ++++++++
 lib/librte_eal/linuxapp/eal/Makefile     |   1 +
 lib/librte_eal/linuxapp/eal/eal_timer.c  |  55 ++---------------
 6 files changed, 139 insertions(+), 95 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_timer.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index a28ead3..48ba39a 100644
@@ -81,6 +81,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_system.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_runtime.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/bsdapp/eal/eal_timer.c +8 -44

79 lines not on this page · raw message

lib/librte_eal/common/eal_common_timer.c new file +101 -0

101 lines not on this page · raw message

lib/librte_eal/common/eal_private.h +24 -0
index 458e8c1..7ee1eb2 100644
@@ -324,4 +324,28 @@ unsigned eal_cpu_core_id(unsigned lcore_id);
  */
 int eal_cpu_detected(unsigned lcore_id);
 
+/**
+ * This function measures TSC frequency
+ *
+ * This function is private to the EAL.
+ */
+void set_tsc_freq(void);
+
+/**
+ * This function sets TSC frequency from sysctl
+ * for BSD and from clock for Linux.
+ * Is a wrapper function for BSD which will
+ * internally call set_tsc_freq_from_sysctl.
+ *
+ * This function is private to the EAL.
+ */
+int set_tsc_freq_from_clock(void);
+
+/**
+ * This function sets TSC frequency
+ *
+ * This function is private to the EAL.
+ */
+void rte_set_tsc_hz(uint64_t tsc_hz);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 8ae23a0..2c18eee 100644
@@ -93,6 +93,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_system.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_runtime.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal_timer.c +4 -51

91 lines not on this page · raw message

Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-5-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#22 lore raw

Re: [PATCH v5 4/8] Move common functions in eal_timer.c

2015-04-09 12:40, Ravi Kerur:

Quoted 26 lines

Changes in v5
Rebase to latest code.

Changes in v4
Removed extern declaration of eal_tsc_resolution_hz, instead provided _set_ API.
Make set_tsc_freq_from_clock as wrapper function for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function name set_tsc_freq_from_sysctl for BSD and Linux. Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_timer.c to librte_eal/common/ eal_common_timer.c file.

Following functions are moved to eal_common_timer.c file

void rte_delay_us(unsigned us);
uint64_t rte_get_tsc_hz(void);
static void set_tsc_freq_fallback(void);
void set_tsc_freq(void);

Quoted 4 lines

Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

Seems good.

Minor nit, a blank line is missing:

Quoted 3 lines

+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <string.h>

author
#23 lore raw

Re: [PATCH v5 4/8] Move common functions in eal_timer.c

Quoted 30 lines · Thomas Monjalon

2015-04-09 12:40, Ravi Kerur:

Quoted 29 lines

Changes in v5
Rebase to latest code.

Changes in v4
Removed extern declaration of eal_tsc_resolution_hz, instead provided _set_ API.
Make set_tsc_freq_from_clock as wrapper function for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function name set_tsc_freq_from_sysctl for BSD and Linux. Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_timer.c to librte_eal/common/ eal_common_timer.c file.

Following functions are moved to eal_common_timer.c file

void rte_delay_us(unsigned us);
uint64_t rte_get_tsc_hz(void);
static void set_tsc_freq_fallback(void);
void set_tsc_freq(void);

Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

Quoted 7 lines
Quoted 1 line

Seems good.

Minor nit, a blank line is missing:

Will fix this in next version.

Quoted 5 lines
Quoted 1 line

+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

DAMAGE.

Quoted 2 lines

+ */
+#include <string.h>

author
#24 lore raw

PATCH v5 5/8 Move common functions in eal_memory.c

In reply to a message not in the archive

Changes in v5
Rebase to latest code.

Changes in v4
Make rte_eal_hugepage_init and rte_eal_hugepage_attach as wrapper functions for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function names rte_eal_hugepage_init and rte_eal_hugepage_attach for BSD and Linux. Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_memory.c to librte_eal/common/ eal_common_memory.c file.

Following functions are moved to eal_common_memory.c file

static int rte_eal_memdevice_init(void); int rte_eal_memory_init(void);

Fix checkpatch warnings and errors.

---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 47 +++++++++++--------------------
 lib/librte_eal/common/eal_common_memory.c | 38 +++++++++++++++++++++++--
 lib/librte_eal/common/eal_private.h       | 22 +++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 36 ++---------------------
 4 files changed, 76 insertions(+), 67 deletions(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +16 -31
index 33ebd0f..77c27b3 100644
@@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
 	return RTE_BAD_PHYS_ADDR;
 }
 
-static int
+static inline int
 rte_eal_contigmem_init(void)
 {
 	struct rte_mem_config *mcfg;
@@ -131,7 +131,16 @@ rte_eal_contigmem_init(void)
 	return 0;
 }
 
-static int
+/*
+ * Wrapper function to initialize contigmem.
+ */
+int
+rte_eal_hugepage_init(void)
+{
+	return rte_eal_contigmem_init();
+}
+
+static inline int
 rte_eal_contigmem_attach(void)
 {
 	const struct hugepage_info *hpi;
@@ -192,35 +201,11 @@ error:
 	return -1;
 }
 
-
-static int
-rte_eal_memdevice_init(void)
-{
-	struct rte_config *config;
-
-	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-		return 0;
-
-	config = rte_eal_get_configuration();
-	config->mem_config->nchannel = internal_config.force_nchannel;
-	config->mem_config->nrank = internal_config.force_nrank;
-
-	return 0;
-}
-
-/* init memory subsystem */
+/*
+ * Wrapper function to attach contigmem.
+ */
 int
-rte_eal_memory_init(void)
+rte_eal_hugepage_attach(void)
 {
-	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
-	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
-			rte_eal_contigmem_init() :
-			rte_eal_contigmem_attach();
-	if (retval < 0)
-		return -1;
-
-	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
-		return -1;
-
-	return 0;
+	return rte_eal_contigmem_attach();
 }
lib/librte_eal/common/eal_common_memory.c +36 -2
index 9a07b1e..10ff0bc 100644
@@ -45,6 +45,7 @@
 #include <rte_log.h>
 
 #include "eal_private.h"
+#include "eal_internal_cfg.h"
 
 /*
  * Return a pointer to a read-only table of struct rte_physmem_desc
@@ -69,7 +70,7 @@ rte_eal_get_physmem_size(void)
 	/* get pointer to global configuration */
 	mcfg = rte_eal_get_configuration()->mem_config;
 
-	for (i=0; i<RTE_MAX_MEMSEG; i++) {
+	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
 		if (mcfg->memseg[i].addr == NULL)
 			break;
 
@@ -89,7 +90,7 @@ rte_dump_physmem_layout(FILE *f)
 	/* get pointer to global configuration */
 	mcfg = rte_eal_get_configuration()->mem_config;
 
-	for (i=0; i<RTE_MAX_MEMSEG; i++) {
+	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
 		if (mcfg->memseg[i].addr == NULL)
 			break;
 
@@ -118,3 +119,36 @@ unsigned rte_memory_get_nrank(void)
 {
 	return rte_eal_get_configuration()->mem_config->nrank;
 }
+
+static int
+rte_eal_memdevice_init(void)
+{
+	struct rte_config *config;
+
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
+		return 0;
+
+	config = rte_eal_get_configuration();
+	config->mem_config->nchannel = internal_config.force_nchannel;
+	config->mem_config->nrank = internal_config.force_nrank;
+
+	return 0;
+}
+
+/* init memory subsystem */
+int
+rte_eal_memory_init(void)
+{
+	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
+	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
+			rte_eal_hugepage_init() :
+			rte_eal_hugepage_attach();
+
+	if (retval < 0)
+		return -1;
+
+	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
+		return -1;
+
+	return 0;
+}
lib/librte_eal/common/eal_private.h +22 -0
index 7ee1eb2..fde1fc9 100644
@@ -348,4 +348,26 @@ int set_tsc_freq_from_clock(void);
  */
 void rte_set_tsc_hz(uint64_t tsc_hz);
 
+/**
+ * This function prepares physical memory mapping
+ * i.e. hugepages on Linux and
+ *      contigmem on BSD.
+ * It is a wrapper function for BSD which will
+ * internally call contigmem_init.
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_init(void);
+
+/**
+ * This function creates memory mapping in secondary
+ * i.e. hugepages on Linux and
+ *      contigmem on BSD.
+ * It is a wrapper function for BSD which will
+ * internally call contigmem_attach.
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_attach(void);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/linuxapp/eal/eal_memory.c +2 -34
index 5f9f92e..c83a2cb 100644
@@ -1030,7 +1030,7 @@ calc_num_pages_per_socket(uint64_t * memory,
  *  6. unmap the first mapping
  *  7. fill memsegs in configuration with contiguous zones
  */
-static int
+int
 rte_eal_hugepage_init(void)
 {
 	struct rte_mem_config *mcfg;
@@ -1368,7 +1368,7 @@ getFileSize(int fd)
  * configuration and finds the hugepages which form that segment, mapping them
  * in order to form a contiguous block in the virtual memory space
  */
-static int
+int
 rte_eal_hugepage_attach(void)
 {
 	const struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
@@ -1529,35 +1529,3 @@ error:
 	return -1;
 }
 
-static int
-rte_eal_memdevice_init(void)
-{
-	struct rte_config *config;
-
-	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-		return 0;
-
-	config = rte_eal_get_configuration();
-	config->mem_config->nchannel = internal_config.force_nchannel;
-	config->mem_config->nrank = internal_config.force_nrank;
-
-	return 0;
-}
-
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-	RTE_LOG(INFO, EAL, "Setting up memory...\n");
-	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
-			rte_eal_hugepage_init() :
-			rte_eal_hugepage_attach();
-	if (retval < 0)
-		return -1;
-
-	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
-		return -1;
-
-	return 0;
-}
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-6-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#26 lore raw

Re: [PATCH v5 5/8] Move common functions in eal_memory.c

2015-04-09 12:40, Ravi Kerur:

Quoted 26 lines

Changes in v5
Rebase to latest code.

Changes in v4
Make rte_eal_hugepage_init and rte_eal_hugepage_attach as wrapper functions for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function names rte_eal_hugepage_init and rte_eal_hugepage_attach for BSD and Linux. Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_memory.c to librte_eal/common/ eal_common_memory.c file.

Following functions are moved to eal_common_memory.c file

static int rte_eal_memdevice_init(void); int rte_eal_memory_init(void);

Fix checkpatch warnings and errors.

[...]

Quoted 4 lines

+/**
+ * This function prepares physical memory mapping
+ * i.e. hugepages on Linux and
+ * contigmem on BSD.

OK

Quoted 2 lines

+ * It is a wrapper function for BSD which will
+ * internally call contigmem_init.

Please avoid such comment which is difficult to maintain and not really useful.

Quoted 2 lines

+ * It is a wrapper function for BSD which will
+ * internally call contigmem_attach.

Same comment.

Except the above comments, it seems goods.

Thanks

author
#27 lore raw

Re: [PATCH v5 5/8] Move common functions in eal_memory.c

Quoted 44 lines · Thomas Monjalon

2015-04-09 12:40, Ravi Kerur:

Quoted 26 lines

Changes in v5
Rebase to latest code.

Changes in v4
Make rte_eal_hugepage_init and rte_eal_hugepage_attach as wrapper functions for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function names rte_eal_hugepage_init and rte_eal_hugepage_attach for BSD and Linux. Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_memory.c to librte_eal/common/ eal_common_memory.c file.

Following functions are moved to eal_common_memory.c file

static int rte_eal_memdevice_init(void); int rte_eal_memory_init(void);

Fix checkpatch warnings and errors.

[...]

Quoted 4 lines

+/**
+ * This function prepares physical memory mapping
+ * i.e. hugepages on Linux and
+ * contigmem on BSD.

OK

Quoted 2 lines

+ * It is a wrapper function for BSD which will
+ * internally call contigmem_init.

Please avoid such comment which is difficult to maintain and not really useful.

Quoted 2 lines

+ * It is a wrapper function for BSD which will
+ * internally call contigmem_attach.

Quoted 7 lines

Same comment.

Except the above comments, it seems goods.

Thanks

Will fix comments in next version.

author
#28 lore raw

PATCH v5 6/8 Move common functions in eal_pci.c

In reply to a message not in the archive

Changes in v5
Rebase to latest code.
Removed RTE_EXEC_ENV_BSDAPP from earlier changes.

Changes in v4
Move common functions in eal_pci.c to librte_eal/common/ eal_common_pci.c file.

Following functions are moved to eal_common_pci.c file.

void *pci_map_resource(void *requested_addr, const int vfio_fd,

      const char *devname, off_t offset, size_t size);
int pci_addr_comparison(struct rte_pci_addr *addr,
                        struct rte_pci_addr *addr2);
int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
                        struct rte_pci_device *dev);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function.
Fix checkpatch warnings and errors.

Changes in v3
N/A

Changes in v2
N/A

Changes in v1
N/A

---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 122 ++++-----------------------
 lib/librte_eal/common/eal_common_pci.c     | 130 ++++++++++++++++++++++++++++-
 lib/librte_eal/common/eal_private.h        |  48 +++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 100 +---------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 --
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  36 ++------
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c |  17 ++--
 7 files changed, 212 insertions(+), 247 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +17 -105
index 30f0232..5669592 100644
@@ -111,7 +111,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
 EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 {
 	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
@@ -119,45 +119,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-/* map a particular resource from a file */
-static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
-{
-	int fd;
-	void *mapaddr;
-
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-
-fail:
-	return NULL;
-}
-
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
@@ -172,10 +133,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
+			if (pci_map_resource(uio_res->maps[i].addr, INT_MIN,
 					     uio_res->path,
 					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
+					     (size_t)uio_res->maps[i].size, 0)
 			    != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
 					"Cannot mmap device resource\n");
@@ -190,7 +151,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 }
 
 /* map the PCI resource of a PCI device in virtual memory */
-static int
+int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, j;
@@ -257,8 +218,9 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		maps[j].phaddr = dev->mem_resource[i].phys_addr;
 		maps[j].size = dev->mem_resource[i].len;
 		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
+		    (mapaddr = pci_map_resource(NULL, INT_MIN, devname,
+						(off_t)offset,
+						(size_t)maps[j].size, 0)
 		    ) == NULL) {
 			rte_free(uio_res);
 			return (-1);
@@ -274,6 +236,13 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return (0);
 }
 
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	return pci_uio_map_resource(dev);
+}
+
 /* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
 pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
@@ -426,68 +395,11 @@ error:
 }
 
 /*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
+ * This function is a no-op in BSD.
  */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+void
+pci_config_space_set(struct rte_pci_device *dev __rte_unused)
 {
-	struct rte_pci_id *id_table;
-	int ret;
-
-	for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
-
-		/* check if device's identifiers match the driver's ones */
-		if (id_table->vendor_id != dev->id.vendor_id &&
-				id_table->vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->device_id != dev->id.device_id &&
-				id_table->device_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-				id_table->subsystem_vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-				id_table->subsystem_device_id != PCI_ANY_ID)
-			continue;
-
-		struct rte_pci_addr *loc = &dev->addr;
-
-		RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 0;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio */
-			ret = pci_uio_map_resource(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
 }
 
 /* Init the PCI EAL subsystem */
lib/librte_eal/common/eal_common_pci.c +127 -3

140 lines not on this page · raw message

lib/librte_eal/common/eal_private.h +48 -0

58 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/eal_pci.c +3 -97

130 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/eal_pci_init.h +0 -6
index aa7b755..b8556c3 100644
@@ -65,12 +65,6 @@ TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-	       size_t size, int additional_flags);
-
-/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
-
 void pci_unmap_resource(void *requested_addr, size_t size);
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +7 -29
index 2d1c69b..ad3f84f 100644
@@ -48,6 +48,7 @@
 #include "rte_pci_dev_ids.h"
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
+#include "eal_private.h"
 
 void *pci_map_addr = NULL;
 
@@ -90,7 +91,7 @@ pci_uio_set_bus_master(int dev_fd)
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	int fd, i;
+	int i;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
@@ -101,18 +102,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
 
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
+			void *mapaddr = pci_map_resource(
+					uio_res->maps[i].addr, INT_MIN,
+					uio_res->maps[i].path,
+					(off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
 				if (mapaddr == MAP_FAILED)
@@ -126,11 +120,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 							uio_res->maps[i].path,
 							uio_res->maps[i].addr);
 
-				close(fd);
 				return -1;
 			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
 		}
 		return 0;
 	}
@@ -330,7 +321,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	/* Map all BARs */
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
 		int fail = 0;
 
 		/* skip empty BAR */
@@ -345,21 +335,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			return -1;
-		}
-
 		/* try mapping somewhere close to the end of hugepages */
 		if (pci_map_addr == NULL)
 			pci_map_addr = pci_find_max_end_va();
 
-		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+		mapaddr = pci_map_resource(pci_map_addr, INT_MIN, devname, 0,
 				(size_t)dev->mem_resource[i].len, 0);
 		if (mapaddr == MAP_FAILED)
 			fail = 1;
@@ -373,10 +353,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		if (fail) {
 			rte_free(uio_res);
-			close(fd);
 			return -1;
 		}
-		close(fd);
 
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +10 -7
index aea1fb1..01250ae 100644
@@ -48,6 +48,7 @@
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
 #include "eal_vfio.h"
+#include "eal_private.h"
 
 /**
  * @file
@@ -799,10 +800,11 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 			void *map_addr = NULL;
 			if (memreg[0].size) {
 				/* actual map of first part */
-				map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
-							    memreg[0].offset,
-							    memreg[0].size,
-							    MAP_FIXED);
+				map_addr = pci_map_resource(bar_addr,
+						vfio_dev_fd, NULL,
+						memreg[0].offset,
+						memreg[0].size,
+						MAP_FIXED);
 			}
 
 			/* if there's a second part, try to map it */
@@ -810,9 +812,10 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 			    && memreg[1].offset && memreg[1].size) {
 				void *second_addr = RTE_PTR_ADD(bar_addr, memreg[1].offset);
 				map_addr = pci_map_resource(second_addr,
-							    vfio_dev_fd, memreg[1].offset,
-							    memreg[1].size,
-							    MAP_FIXED);
+						vfio_dev_fd, NULL,
+						memreg[1].offset,
+						memreg[1].size,
+						MAP_FIXED);
 			}
 
 			if (map_addr == MAP_FAILED || !map_addr) {
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1428608412-31191-7-git-send-email-rkerur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#30 lore raw

Re: [PATCH v5 6/8] Move common functions in eal_pci.c

This patch is very sensible and difficult to follow. I'm really afraid that some nasty bugs could be hidden. Please could you try to split it in several steps? Thanks

2015-04-09 12:40, Ravi Kerur:

Quoted 40 lines

Changes in v5
Rebase to latest code.
Removed RTE_EXEC_ENV_BSDAPP from earlier changes.

Changes in v4
Move common functions in eal_pci.c to librte_eal/common/ eal_common_pci.c file.

Following functions are moved to eal_common_pci.c file.

void *pci_map_resource(void *requested_addr, const int vfio_fd,

      const char *devname, off_t offset, size_t size);
int pci_addr_comparison(struct rte_pci_addr *addr,
                        struct rte_pci_addr *addr2);
int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
                        struct rte_pci_device *dev);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function.
Fix checkpatch warnings and errors.

Changes in v3
N/A

Changes in v2
N/A

Changes in v1
N/A

---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 122 ++++-----------------------
 lib/librte_eal/common/eal_common_pci.c     | 130 ++++++++++++++++++++++++++++-
 lib/librte_eal/common/eal_private.h        |  48 +++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 100 +---------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 --
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  36 ++------
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c |  17 ++--
 7 files changed, 212 insertions(+), 247 deletions(-)
author
#31 lore raw

Re: [PATCH v5 6/8] Move common functions in eal_pci.c

Quoted 5 lines · Thomas Monjalon

This patch is very sensible and difficult to follow. I'm really afraid that some nasty bugs could be hidden. Please could you try to split it in several steps? Thanks

Sure, will drop eal_pci_uio.c and eal_pci_vfio.c changes and will send out new version.

Quoted 46 lines

2015-04-09 12:40, Ravi Kerur:

Quoted 27 lines

Changes in v5
Rebase to latest code.
Removed RTE_EXEC_ENV_BSDAPP from earlier changes.

Changes in v4
Move common functions in eal_pci.c to librte_eal/common/ eal_common_pci.c file.

Following functions are moved to eal_common_pci.c file.

void *pci_map_resource(void *requested_addr, const int vfio_fd,

      const char *devname, off_t offset, size_t size);
int pci_addr_comparison(struct rte_pci_addr *addr,
                        struct rte_pci_addr *addr2);
int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
                        struct rte_pci_device *dev);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function.
Fix checkpatch warnings and errors.

Changes in v3
N/A

Changes in v2
N/A

Quoted 6 lines

Changes in v1
N/A

---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 122

++++-----------------------

Quoted 1 line
 lib/librte_eal/common/eal_common_pci.c     | 130

++++++++++++++++++++++++++++-

Quoted 6 lines
 lib/librte_eal/common/eal_private.h        |  48 +++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 100 +---------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 --
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  36 ++------
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c |  17 ++--
 7 files changed, 212 insertions(+), 247 deletions(-)