From 3cf37bbfbc581495b50e5fb52c36584628386127 Mon Sep 17 00:00:00 2001 From: "dongx.yi" Date: Wed, 25 Dec 2019 09:45:04 -0500 Subject: [PATCH] vhost: Inline the calculation of vhost session memory region. There are for loops to do these calculations for vhost session memory region. we can inline these for both in vhost_session_mem_register and vhost_session_mem_unregister. It not only removed the duplicated codes but also reduced the stack consumption. Signed-off-by: dongx.yi Change-Id: Idb9f5ea13e09aef6b24fa27a2bb809b15ece50e2 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478820 Tested-by: SPDK CI Jenkins Community-CI: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/vhost/rte_vhost_compat.c | 39 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/vhost/rte_vhost_compat.c b/lib/vhost/rte_vhost_compat.c index 0597300a2c..24696f40f2 100644 --- a/lib/vhost/rte_vhost_compat.c +++ b/lib/vhost/rte_vhost_compat.c @@ -49,23 +49,29 @@ #include "spdk_internal/vhost_user.h" #include "spdk_internal/memory.h" +static inline void +vhost_session_mem_region_calc(uint64_t *previous_start, uint64_t *start, uint64_t *end, + uint64_t *len, struct rte_vhost_mem_region *region) +{ + *start = FLOOR_2MB(region->mmap_addr); + *end = CEIL_2MB(region->mmap_addr + region->mmap_size); + if (*start == *previous_start) { + *start += (size_t) VALUE_2MB; + } + *previous_start = *start; + *len = *end - *start; +} + void vhost_session_mem_register(struct rte_vhost_memory *mem) { - struct rte_vhost_mem_region *region; + uint64_t start, end, len; uint32_t i; uint64_t previous_start = UINT64_MAX; + for (i = 0; i < mem->nregions; i++) { - uint64_t start, end, len; - region = &mem->regions[i]; - start = FLOOR_2MB(region->mmap_addr); - end = CEIL_2MB(region->mmap_addr + region->mmap_size); - if (start == previous_start) { - start += (size_t) VALUE_2MB; - } - previous_start = start; - len = end - start; + vhost_session_mem_region_calc(&previous_start, &start, &end, &len, &mem->regions[i]); SPDK_INFOLOG(SPDK_LOG_VHOST, "Registering VM memory for vtophys translation - 0x%jx len:0x%jx\n", start, len); @@ -80,21 +86,12 @@ vhost_session_mem_register(struct rte_vhost_memory *mem) void vhost_session_mem_unregister(struct rte_vhost_memory *mem) { - struct rte_vhost_mem_region *region; + uint64_t start, end, len; uint32_t i; uint64_t previous_start = UINT64_MAX; for (i = 0; i < mem->nregions; i++) { - uint64_t start, end, len; - region = &mem->regions[i]; - start = FLOOR_2MB(region->mmap_addr); - end = CEIL_2MB(region->mmap_addr + region->mmap_size); - if (start == previous_start) { - start += (size_t) VALUE_2MB; - } - previous_start = start; - len = end - start; - + vhost_session_mem_region_calc(&previous_start, &start, &end, &len, &mem->regions[i]); if (spdk_vtophys((void *) start, NULL) == SPDK_VTOPHYS_ERROR) { continue; /* region has not been registered */ }