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 <dongx.yi@intel.com> Change-Id: Idb9f5ea13e09aef6b24fa27a2bb809b15ece50e2 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478820 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
1a5d78e32e
commit
3cf37bbfbc
@ -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 */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user