mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
virtio-balloon: free page hinting cleanups
Let's compress the code a bit to improve readability. We can drop the vm_running check in virtio_balloon_free_page_start() as it's already properly checked in the single caller. Cc: Wei Wang <wei.w.wang@intel.com> Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Cc: Alexander Duyck <alexander.duyck@gmail.com> Cc: Juan Quintela <quintela@redhat.com> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Cc: Peter Xu <peterx@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com> Message-Id: <20210708095339.20274-3-david@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
fd51e54fa1
commit
2d050ed07c
1 changed files with 8 additions and 20 deletions
|
@ -534,23 +534,19 @@ static bool get_free_page_hints(VirtIOBalloon *dev)
|
||||||
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED &&
|
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED &&
|
||||||
id == dev->free_page_hint_cmd_id) {
|
id == dev->free_page_hint_cmd_id) {
|
||||||
dev->free_page_hint_status = FREE_PAGE_HINT_S_START;
|
dev->free_page_hint_status = FREE_PAGE_HINT_S_START;
|
||||||
} else {
|
} else if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
|
||||||
/*
|
/*
|
||||||
* Stop the optimization only when it has started. This
|
* Stop the optimization only when it has started. This
|
||||||
* avoids a stale stop sign for the previous command.
|
* avoids a stale stop sign for the previous command.
|
||||||
*/
|
*/
|
||||||
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
|
|
||||||
dev->free_page_hint_status = FREE_PAGE_HINT_S_STOP;
|
dev->free_page_hint_status = FREE_PAGE_HINT_S_STOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (elem->in_num) {
|
if (elem->in_num && dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
|
||||||
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
|
|
||||||
qemu_guest_free_page_hint(elem->in_sg[0].iov_base,
|
qemu_guest_free_page_hint(elem->in_sg[0].iov_base,
|
||||||
elem->in_sg[0].iov_len);
|
elem->in_sg[0].iov_len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
virtqueue_push(vq, elem, 1);
|
virtqueue_push(vq, elem, 1);
|
||||||
|
@ -592,16 +588,10 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s)
|
||||||
{
|
{
|
||||||
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
||||||
|
|
||||||
/* For the stop and copy phase, we don't need to start the optimization */
|
|
||||||
if (!vdev->vm_running) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_mutex_lock(&s->free_page_lock);
|
qemu_mutex_lock(&s->free_page_lock);
|
||||||
|
|
||||||
if (s->free_page_hint_cmd_id == UINT_MAX) {
|
if (s->free_page_hint_cmd_id == UINT_MAX) {
|
||||||
s->free_page_hint_cmd_id =
|
s->free_page_hint_cmd_id = VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
|
||||||
VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
|
|
||||||
} else {
|
} else {
|
||||||
s->free_page_hint_cmd_id++;
|
s->free_page_hint_cmd_id++;
|
||||||
}
|
}
|
||||||
|
@ -649,8 +639,7 @@ static void virtio_balloon_free_page_done(VirtIOBalloon *s)
|
||||||
static int
|
static int
|
||||||
virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data)
|
virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data)
|
||||||
{
|
{
|
||||||
VirtIOBalloon *dev = container_of(n, VirtIOBalloon,
|
VirtIOBalloon *dev = container_of(n, VirtIOBalloon, free_page_hint_notify);
|
||||||
free_page_hint_notify);
|
|
||||||
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||||
PrecopyNotifyData *pnd = data;
|
PrecopyNotifyData *pnd = data;
|
||||||
|
|
||||||
|
@ -919,8 +908,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
|
||||||
s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
|
s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
|
||||||
s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
|
s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
|
||||||
|
|
||||||
if (virtio_has_feature(s->host_features,
|
if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
|
||||||
VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
|
|
||||||
s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
|
s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
|
||||||
virtio_balloon_handle_free_page_vq);
|
virtio_balloon_handle_free_page_vq);
|
||||||
precopy_add_notifier(&s->free_page_hint_notify);
|
precopy_add_notifier(&s->free_page_hint_notify);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue