env/vtophys: register all DPDK memory at startup

Change-Id: Ibb37a7ea520c79ad9fe9089af7419c192fba5477
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2017-02-21 15:42:50 -07:00
parent 7336c0036e
commit b49de91ef2
4 changed files with 27 additions and 17 deletions

View File

@ -70,4 +70,6 @@ int spdk_pci_enumerate(struct spdk_pci_enum_ctx *ctx, spdk_pci_enum_cb enum_cb,
int spdk_pci_device_attach(struct spdk_pci_enum_ctx *ctx, spdk_pci_enum_cb enum_cb, void *enum_ctx,
struct spdk_pci_addr *pci_address);
void spdk_vtophys_register_dpdk_mem(void);
#endif

View File

@ -31,7 +31,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "spdk/env.h"
#include "env_internal.h"
#include <assert.h>
#include <errno.h>
@ -309,4 +309,6 @@ void spdk_env_init(const struct spdk_env_opts *opts)
fprintf(stderr, "Failed to initialize DPDK\n");
exit(-1);
}
spdk_vtophys_register_dpdk_mem();
}

View File

@ -31,6 +31,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "env_internal.h"
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
@ -41,8 +43,6 @@
#include <rte_config.h>
#include <rte_eal_memconfig.h>
#include "spdk/env.h"
/* x86-64 userspace virtual addresses use only the low 47 bits [0..46],
* which is enough to cover 128 TB.
*/
@ -312,6 +312,25 @@ spdk_vtophys_unregister(void *vaddr, uint64_t len)
}
}
void
spdk_vtophys_register_dpdk_mem(void)
{
struct rte_mem_config *mcfg;
size_t seg_idx;
mcfg = rte_eal_get_configuration()->mem_config;
for (seg_idx = 0; seg_idx < RTE_MAX_MEMSEG; seg_idx++) {
struct rte_memseg *seg = &mcfg->memseg[seg_idx];
if (seg->addr == NULL) {
break;
}
spdk_vtophys_register(seg->addr, seg->len);
}
}
uint64_t
spdk_vtophys(void *buf)
{
@ -333,16 +352,7 @@ spdk_vtophys(void *buf)
paddr_2mb = map_2mb->paddr_2mb;
if (paddr_2mb == SPDK_VTOPHYS_ERROR) {
uint64_t paddr;
paddr = vtophys_get_paddr(vaddr);
if (paddr == SPDK_VTOPHYS_ERROR) {
return SPDK_VTOPHYS_ERROR;
}
/* For now, assume all valid addressess are part of 2MB or larger pages. */
paddr_2mb = paddr & ~MASK_2MB;
map_2mb->paddr_2mb = paddr_2mb;
return SPDK_VTOPHYS_ERROR;
}
return paddr_2mb | ((uint64_t)buf & MASK_2MB);

View File

@ -41,14 +41,11 @@
static int
vtophys_negative_test(void)
{
#if 0
void *p = NULL;
int i;
unsigned int size = 1;
#endif
int rc = 0;
#if 0 /* Temporarily disabled until DPDK memory is registered at startup */
for (i = 0; i < 31; i++) {
p = malloc(size);
if (p == NULL)
@ -64,7 +61,6 @@ vtophys_negative_test(void)
free(p);
size = size << 1;
}
#endif
/* Test addresses that are not in the valid x86-64 usermode range */