Commit 5d573868 authored by Seth Howell's avatar Seth Howell Committed by Jim Harris
Browse files

env_dpdk: spdk_mem_map_translate informs user of translation size.



This function will now check for whether or not a memory region is
contiguous accross 2MB map entries and return the total length of that
contiguous buffer up to the size specified by the user.

Also includes unittests
This series of changes is aimed at enabling spdk_mem_map_translate to
report back to the user the length of the valid mem_map up to the
function that requested the translation.
This will be useful when retrieving memory regions associated with I/O
buffers in NVMe-oF. For large I/O it will be possible that the buffer is
split over multiple MRs and the I/O will have to be split into multiple
SGLs.
Change-Id: I2ce582427d451be5a317808d0825c770e12e9a69
Signed-off-by: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/425329


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 4e06bb5e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -979,11 +979,14 @@ typedef int (*spdk_mem_map_notify_cb)(void *cb_ctx, struct spdk_mem_map *map,
				      enum spdk_mem_map_notify_action action,
				      void *vaddr, size_t size);

typedef int (*spdk_mem_map_contiguous_translations)(uint64_t addr_1, uint64_t addr_2);

/**
 * A function table to be implemented by each memory map.
 */
struct spdk_mem_map_ops {
	spdk_mem_map_notify_cb notify_cb;
	spdk_mem_map_contiguous_translations are_contiguous;
};

/**
+33 −2
Original line number Diff line number Diff line
@@ -484,8 +484,12 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t
	uint64_t idx_256tb;
	uint64_t idx_1gb;
	uint64_t vfn_2mb;
	uint64_t total_size = 0;
	uint64_t cur_size;
	uint64_t prev_translation;

	if (size != NULL) {
		total_size = *size;
		*size = 0;
	}

@@ -503,14 +507,41 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t
		return map->default_translation;
	}

	map_2mb = &map_1gb->map[idx_1gb];
	cur_size = VALUE_2MB;
	if (size != NULL) {
		*size = VALUE_2MB;
	}

	map_2mb = &map_1gb->map[idx_1gb];
	if (size == NULL || map->ops.are_contiguous == NULL ||
	    map_2mb->translation_2mb == map->default_translation) {
		return map_2mb->translation_2mb;
	}

	prev_translation = map_2mb->translation_2mb;;
	while (cur_size < total_size) {
		vfn_2mb++;
		idx_256tb = MAP_256TB_IDX(vfn_2mb);
		idx_1gb = MAP_1GB_IDX(vfn_2mb);

		map_1gb = map->map_256tb.map[idx_256tb];
		if (spdk_unlikely(!map_1gb)) {
			break;
		}

		map_2mb = &map_1gb->map[idx_1gb];
		if (!map->ops.are_contiguous(prev_translation, map_2mb->translation_2mb)) {
			break;
		}

		cur_size += VALUE_2MB;
		prev_translation = map_2mb->translation_2mb;
	}

	*size = cur_size;
	return prev_translation;
}

#if RTE_VERSION >= RTE_VERSION_NUM(18, 05, 0, 0)
static void
memory_hotplug_cb(enum rte_mem_event event_type,
+2 −1
Original line number Diff line number Diff line
@@ -605,7 +605,8 @@ int
spdk_vtophys_init(void)
{
	const struct spdk_mem_map_ops vtophys_map_ops = {
		.notify_cb = spdk_vtophys_notify
		.notify_cb = spdk_vtophys_notify,
		.are_contiguous = NULL
	};

#if SPDK_VFIO_ENABLED
+2 −1
Original line number Diff line number Diff line
@@ -637,7 +637,8 @@ nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair)
	struct ibv_pd *pd = rqpair->cm_id->qp->pd;
	struct spdk_nvme_rdma_mr_map *mr_map;
	const struct spdk_mem_map_ops nvme_rdma_map_ops = {
		.notify_cb = nvme_rdma_mr_map_notify
		.notify_cb = nvme_rdma_mr_map_notify,
		.are_contiguous = NULL
	};

	pthread_mutex_lock(&g_rdma_mr_maps_mutex);
+2 −1
Original line number Diff line number Diff line
@@ -1635,7 +1635,8 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_transport_opts *opts)
	uint32_t			sge_count;

	const struct spdk_mem_map_ops nvmf_rdma_map_ops = {
		.notify_cb = spdk_nvmf_rdma_mem_notify
		.notify_cb = spdk_nvmf_rdma_mem_notify,
		.are_contiguous = NULL
	};

	rtransport = calloc(1, sizeof(*rtransport));
Loading