Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdpa/virtio: Optimize device close time #10

Merged
merged 2 commits into from
Aug 15, 2022

Conversation

kailiangz1
Copy link
Collaborator

Move DMA unmap and state resoter work to work thread

Signed-off-by: Kailiang Zhou kailiangz@nvidia.com

Copy link

@LiZhang-2020 LiZhang-2020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

priv->dev_work_flag = 0;

Please use macro instead of 0

Copy link

@LiZhang-2020 LiZhang-2020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (priv->dev_work_flag == VIRTIO_VDPA_DEV_CLOSE_WORK_ERR) {
DRV_LOG(ERR, "%s is dev close work had err", vdev->device->name);
return -EINVAL;
}

Why not check VIRTIO_VDPA_DEV_CLOSE_WORK_DONE?
If it still work on it no done yeah.

@kailiangz1 kailiangz1 force-pushed the dev_close_async branch 2 times, most recently from 5b94962 to b6bd8e6 Compare July 28, 2022 08:17
Move DMA unmap and state resoter work to work thread

Signed-off-by: Kailiang Zhou <kailiangz@nvidia.com>
}
static inline bool
virtio_vdpa_find_mem_reg(struct rte_vhost_mem_region *key,struct rte_vhost_memory *mem)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white space before struct rte_vhost_memory

uint32_t i = 0;
struct rte_vhost_mem_region *reg;

if (mem == NULL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calller cannot pass null. please remove this check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can pass null when no mem map

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kailiangz1 , who can pass null? vhost from qemu side?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 669, if previous no mem map, it will be NULL

static inline bool
virtio_vdpa_find_mem_reg(struct rte_vhost_mem_region *key,struct rte_vhost_memory *mem)
{
uint32_t i = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to zero initialize here, below for loop already doe it.

}
static inline bool
virtio_vdpa_find_mem_reg(struct rte_vhost_mem_region *key,struct rte_vhost_memory *mem)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make key and mem const pointer as this search routine is not going to modify anything.

if (priv->mem) {
for (i = 0; i < priv->mem->nregions; i++) {
reg = &priv->mem->regions[i];
if (virtio_vdpa_find_mem_reg(reg, cur_mem)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsing the code in the else to do the actual work is very confusing.

do it as,

ret = virtio_vdpa_find_mem_reg();
if (ret == 0) {
unmap code()
} else {
debug print
}

DRV_LOG(ERR, "%s DMA unmap failed ret:%d",
priv->vdev->device->name, ret);
/* Map reagion dind't exsit in privious */
for (i = 0; i < cur_mem->nregions; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also have the error unwinding routine label to unmap or map the memory if the for loop fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not necessary to unwinding because mem map is to map the mem, if it exist, we will no map them. caller can call again to recover. Map exist mem no harm.

if (ret < 0) {
DRV_LOG(ERR, "%s DMA unmap failed ret:%d",
priv->vdev->device->name, ret);
/* Map reagion dind't exsit in privious */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment should be,

/* Map the region if it doesn't exist yet */

priv->vdev->device->name, ret);
goto exit;
/* Unmap reagion dind't exsit in current */
if (priv->mem) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to have two different helper routines for map and unmap and call them here.

@@ -1445,6 +1445,9 @@ vhost_user_set_mem_table(struct virtio_net **pdev,
if (dev->async_copy && rte_vfio_is_enabled("vfio"))
async_dma_map(dev, true);

if ((dev->vdpa_dev) && (dev->vdpa_dev->ops->set_mem_table))
dev->vdpa_dev->ops->set_mem_table(dev->vdpa_dev);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work to have explicit call, instead of doing implicit in the dev_config.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not understand. Can you show me the code example?

@kailiangz1 kailiangz1 force-pushed the dev_close_async branch 2 times, most recently from d3db83c to 638afe8 Compare August 3, 2022 10:00
Add new set mem operation, save dma map time when device
config

Signed-off-by: Kailiang Zhou <kailiangz@nvidia.com>
@kailiangz1 kailiangz1 merged commit 97359a3 into Mellanox:main Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants