env/vtophys: Add a macro for debug prints

This code can't use our standard logging mechanism, but the
if DEBUG statements were making it hard to read. Add a
basic macro to clean it up.

Change-Id: I1d5c87df60d212ffe2b2455cc2169036dcb9e807
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/375246
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Ben Walker 2017-08-22 14:49:25 -07:00 committed by Jim Harris
parent d9a2fd3a41
commit a10779ca75

View File

@ -45,6 +45,12 @@
#include "spdk/queue.h" #include "spdk/queue.h"
#include "spdk/util.h" #include "spdk/util.h"
#if DEBUG
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#endif
/* x86-64 userspace virtual addresses use only the low 47 bits [0..46], /* x86-64 userspace virtual addresses use only the low 47 bits [0..46],
* which is enough to cover 128 TB. * which is enough to cover 128 TB.
*/ */
@ -288,9 +294,7 @@ spdk_mem_map_get_map_1gb(struct spdk_mem_map *map, uint64_t vfn_2mb)
pthread_mutex_unlock(&map->mutex); pthread_mutex_unlock(&map->mutex);
if (!map_1gb) { if (!map_1gb) {
#ifdef DEBUG DEBUG_PRINT("allocation failed\n");
printf("allocation failed\n");
#endif
return NULL; return NULL;
} }
} }
@ -317,9 +321,7 @@ spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t
while (size) { while (size) {
map_1gb = spdk_mem_map_get_map_1gb(map, vfn_2mb); map_1gb = spdk_mem_map_get_map_1gb(map, vfn_2mb);
if (!map_1gb) { if (!map_1gb) {
#ifdef DEBUG DEBUG_PRINT("could not get %p map\n", (void *)vaddr);
fprintf(stderr, "could not get %p map\n", (void *)vaddr);
#endif
return -ENOMEM; return -ENOMEM;
} }
@ -328,10 +330,8 @@ spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t
ref_count = &map_1gb->ref_count[idx_1gb]; ref_count = &map_1gb->ref_count[idx_1gb];
if (*ref_count == VTOPHYS_MAX_REF_COUNT) { if (*ref_count == VTOPHYS_MAX_REF_COUNT) {
#ifdef DEBUG DEBUG_PRINT("ref count for %p already at %d\n",
fprintf(stderr, "ref count for %p already at %d\n",
(void *)vaddr, VTOPHYS_MAX_REF_COUNT); (void *)vaddr, VTOPHYS_MAX_REF_COUNT);
#endif
return -EBUSY; return -EBUSY;
} }
@ -364,9 +364,7 @@ spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_
while (size) { while (size) {
map_1gb = spdk_mem_map_get_map_1gb(map, vfn_2mb); map_1gb = spdk_mem_map_get_map_1gb(map, vfn_2mb);
if (!map_1gb) { if (!map_1gb) {
#ifdef DEBUG DEBUG_PRINT("could not get %p map\n", (void *)vaddr);
fprintf(stderr, "could not get %p map\n", (void *)vaddr);
#endif
return -ENOMEM; return -ENOMEM;
} }
@ -375,9 +373,7 @@ spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_
ref_count = &map_1gb->ref_count[idx_1gb]; ref_count = &map_1gb->ref_count[idx_1gb];
if (*ref_count == 0) { if (*ref_count == 0) {
#ifdef DEBUG DEBUG_PRINT("vaddr %p not registered\n", (void *)vaddr);
fprintf(stderr, "vaddr %p not registered\n", (void *)vaddr);
#endif
return -EINVAL; return -EINVAL;
} }
@ -403,9 +399,7 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr)
uint64_t vfn_2mb; uint64_t vfn_2mb;
if (spdk_unlikely(vaddr & ~MASK_128TB)) { if (spdk_unlikely(vaddr & ~MASK_128TB)) {
#ifdef DEBUG DEBUG_PRINT("invalid usermode virtual address %p\n", (void *)vaddr);
printf("invalid usermode virtual address %p\n", (void *)vaddr);
#endif
return map->default_translation; return map->default_translation;
} }
@ -465,9 +459,7 @@ vtophys_get_paddr(uint64_t vaddr)
return paddr; return paddr;
} }
#ifdef DEBUG DEBUG_PRINT("could not find vaddr 0x%" PRIx64 " in DPDK mem config\n", vaddr);
fprintf(stderr, "could not find vaddr 0x%" PRIx64 " in DPDK mem config\n", vaddr);
#endif
return SPDK_VTOPHYS_ERROR; return SPDK_VTOPHYS_ERROR;
} }
@ -478,17 +470,13 @@ spdk_vtophys_register(void *vaddr, uint64_t len)
int rc; int rc;
if ((uintptr_t)vaddr & ~MASK_128TB) { if ((uintptr_t)vaddr & ~MASK_128TB) {
#ifdef DEBUG DEBUG_PRINT("invalid usermode virtual address %p\n", vaddr);
printf("invalid usermode virtual address %p\n", vaddr);
#endif
return -EINVAL; return -EINVAL;
} }
if (((uintptr_t)vaddr & MASK_2MB) || (len & MASK_2MB)) { if (((uintptr_t)vaddr & MASK_2MB) || (len & MASK_2MB)) {
#ifdef DEBUG DEBUG_PRINT("invalid %s parameters, vaddr=%p len=%ju\n",
fprintf(stderr, "invalid %s parameters, vaddr=%p len=%ju\n",
__func__, vaddr, len); __func__, vaddr, len);
#endif
return -EINVAL; return -EINVAL;
} }
@ -500,16 +488,12 @@ spdk_vtophys_register(void *vaddr, uint64_t len)
uint64_t paddr = vtophys_get_paddr(vaddr); uint64_t paddr = vtophys_get_paddr(vaddr);
if (paddr == RTE_BAD_PHYS_ADDR) { if (paddr == RTE_BAD_PHYS_ADDR) {
#ifdef DEBUG DEBUG_PRINT("could not get phys addr for 0x%" PRIx64 "\n", vaddr);
fprintf(stderr, "could not get phys addr for 0x%" PRIx64 "\n", vaddr);
#endif
return -EFAULT; return -EFAULT;
} }
if (paddr & MASK_2MB) { if (paddr & MASK_2MB) {
#ifdef DEBUG DEBUG_PRINT("invalid paddr 0x%" PRIx64 " - must be 2MB aligned\n", paddr);
fprintf(stderr, "invalid paddr 0x%" PRIx64 " - must be 2MB aligned\n", paddr);
#endif
return -EINVAL; return -EINVAL;
} }
@ -531,17 +515,13 @@ spdk_vtophys_unregister(void *vaddr, uint64_t len)
int rc; int rc;
if ((uintptr_t)vaddr & ~MASK_128TB) { if ((uintptr_t)vaddr & ~MASK_128TB) {
#ifdef DEBUG DEBUG_PRINT("invalid usermode virtual address %p\n", vaddr);
printf("invalid usermode virtual address %p\n", vaddr);
#endif
return -EINVAL; return -EINVAL;
} }
if (((uintptr_t)vaddr & MASK_2MB) || (len & MASK_2MB)) { if (((uintptr_t)vaddr & MASK_2MB) || (len & MASK_2MB)) {
#ifdef DEBUG DEBUG_PRINT("invalid %s parameters, vaddr=%p len=%ju\n",
fprintf(stderr, "invalid %s parameters, vaddr=%p len=%ju\n",
__func__, vaddr, len); __func__, vaddr, len);
#endif
return -EINVAL; return -EINVAL;
} }
@ -589,7 +569,7 @@ spdk_vtophys_register_dpdk_mem(void)
g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, spdk_vtophys_notify, NULL); g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, spdk_vtophys_notify, NULL);
if (g_vtophys_map == NULL) { if (g_vtophys_map == NULL) {
fprintf(stderr, "vtophys map allocation failed\n"); DEBUG_PRINT("vtophys map allocation failed\n");
abort(); abort();
} }