summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dpdk.c26
-rw-r--r--src/main.c16
-rw-r--r--src/main.h5
3 files changed, 34 insertions, 13 deletions
diff --git a/src/dpdk.c b/src/dpdk.c
index 955763b..5cbc0fd 100644
--- a/src/dpdk.c
+++ b/src/dpdk.c
@@ -12,6 +12,7 @@
#include <rte_version.h>
#include <rte_ethdev.h>
#include <rte_log.h>
+#include <rte_errno.h>
#include "main.h"
@@ -62,29 +63,20 @@ char** fill_eal_args(const struct cmd_opts* opts, const struct cpus_bindings* cp
const struct dpdk_ctx* dpdk, int* eal_args_ac)
{
char buf_coremask[30];
- char socket_mem_arg[32];
char** eal_args;
- int i, cpt, mempool;
+ int i, cpt;
if (!opts || !cpus || !dpdk)
return (NULL);
- mempool = dpdk->pool_sz * 1024;
/* Set EAL init parameters */
snprintf(buf_coremask, 20, "0x%lx", cpus->coremask);
- if (cpus->numacores == 1)
- snprintf(socket_mem_arg, sizeof(socket_mem_arg), "--socket-mem=%i", mempool);
- else if (cpus->numacore == 0)
- snprintf(socket_mem_arg, sizeof(socket_mem_arg), "--socket-mem=%i,0", mempool);
- else
- snprintf(socket_mem_arg, sizeof(socket_mem_arg), "--socket-mem=0,%i", mempool);
char *pre_eal_args[] = {
"./dpdk-replay",
"-c", strdup(buf_coremask),
"-n", "1", /* NUM MEM CHANNELS */
"--proc-type", "auto",
"--file-prefix", "dpdkreplay_",
- strdup(socket_mem_arg),
NULL
};
/* fill pci whitelist args */
@@ -230,8 +222,18 @@ int init_dpdk_eal_mempool(const struct cmd_opts* opts,
cpus->numacore,
0);
if (dpdk->pktmbuf_pool == NULL) {
- fprintf(stderr, "DPDK: RTE Mempool creation failed\n");
- return (1);
+ fprintf(stderr, "DPDK: RTE Mempool creation failed (%s)\n",
+ rte_strerror(rte_errno));
+#if API_AT_LEAST_AS_RECENT_AS(18, 05)
+ if (rte_errno == ENOMEM
+ && (dpdk->nb_mbuf * dpdk->mbuf_sz /1024/1024) > RTE_MAX_MEM_MB_PER_LIST)
+ fprintf(stderr, "Your version of DPDK was configured to use at maximum"
+ " %u Mo, or you try to allocate ~%lu Mo.\n"
+ "Try to recompile DPDK by setting CONFIG_RTE_MAX_MEM_MB_PER_LIST"
+ " according to your needs.\n", RTE_MAX_MEM_MB_PER_LIST,
+ dpdk->nb_mbuf * dpdk->mbuf_sz /1024/1024);
+#endif /* API_AT_LEAST_AS_RECENT_AS(18, 05) */
+ return (rte_errno);
}
return (0);
}
diff --git a/src/main.c b/src/main.c
index f6009ae..8b33aea 100644
--- a/src/main.c
+++ b/src/main.c
@@ -115,7 +115,6 @@ int parse_options(const int ac, char** av, struct cmd_opts* opts)
/* if no nb runs is specified */
if (i + 1 >= ac - 2)
return (ENOENT);
-
opts->nbruns = atoi(av[i + 1]);
if (opts->nbruns <= 0)
return (EPROTO);
@@ -162,6 +161,7 @@ int check_needed_memory(const struct cmd_opts* opts, const struct pcap_ctx* pcap
printf("-> Needed MBUF size: %lu\n", dpdk->mbuf_sz);
/* # CALCULATE THE NEEDED NUMBER OF MBUFS */
+#ifdef DPDK_RECOMMANDATIONS
/* For number of pkts to be allocated on the mempool, DPDK says: */
/* The optimum size (in terms of memory usage) for a mempool is when n is a
power of two minus one: n = (2^q - 1). */
@@ -170,6 +170,20 @@ int check_needed_memory(const struct cmd_opts* opts, const struct pcap_ctx* pcap
"(nb pkts * nb ports)");
#endif /* DEBUG */
dpdk->nb_mbuf = get_next_power_of_2(pcap->nb_pkts * opts->nb_pcicards) - 1;
+#else /* !DPDK_RECOMMANDATIONS */
+ /*
+ Some tests shown that the perf are not so much impacted when allocating the
+ exact number of wanted mbufs. I keep it simple for now to reduce the needed
+ memory on large pcap.
+ */
+ dpdk->nb_mbuf = pcap->nb_pkts * opts->nb_pcicards;
+#endif /* DPDK_RECOMMANDATIONS */
+ /*
+ If we have a pcap with very few packets, we need to allocate more mbufs
+ than necessary to avoid rte_mempool_create failure.
+ */
+ if (dpdk->nb_mbuf < (MBUF_CACHE_SZ * 2))
+ dpdk->nb_mbuf = MBUF_CACHE_SZ * 4;
printf("-> Needed number of MBUFS: %lu\n", dpdk->nb_mbuf);
/* # CALCULATE THE TOTAL NEEDED MEMORY SIZE */
diff --git a/src/main.h b/src/main.h
index 7f388dc..e1265e2 100644
--- a/src/main.h
+++ b/src/main.h
@@ -31,6 +31,11 @@
&& defined RTE_VER_MONTH && RTE_VER_MONTH < month) \
|| defined RTE_VER_YEAR && RTE_VER_YEAR < year)
+#define API_AT_LEAST_AS_RECENT_AS(year, month) \
+ ((defined RTE_VER_YEAR && RTE_VER_YEAR == year \
+ && defined RTE_VER_MONTH && RTE_VER_MONTH >= month) \
+ || defined RTE_VER_YEAR && RTE_VER_YEAR >= year)
+
/* struct to store the command line args */
struct cmd_opts {
char** pcicards;