4 * Copyright IBM, Corp. 2007-2008
7 * Anthony Liguori <aliguori@us.ibm.com>
8 * Rusty Russell <rusty@rustcorp.com.au>
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
15 #ifndef QEMU_VIRTIO_BALLOON_H
16 #define QEMU_VIRTIO_BALLOON_H
18 #include "standard-headers/linux/virtio_balloon.h"
19 #include "hw/virtio/virtio.h"
20 #include "sysemu/iothread.h"
22 #define TYPE_VIRTIO_BALLOON "virtio-balloon-device"
23 #define VIRTIO_BALLOON(obj) \
24 OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
26 #define VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN 0x80000000
28 typedef struct virtio_balloon_stat VirtIOBalloonStat
;
30 typedef struct virtio_balloon_stat_modern
{
34 } VirtIOBalloonStatModern
;
36 typedef struct PartiallyBalloonedPage PartiallyBalloonedPage
;
38 enum virtio_balloon_free_page_report_status
{
39 FREE_PAGE_REPORT_S_STOP
= 0,
40 FREE_PAGE_REPORT_S_REQUESTED
= 1,
41 FREE_PAGE_REPORT_S_START
= 2,
42 FREE_PAGE_REPORT_S_DONE
= 3,
45 typedef struct VirtIOBalloon
{
46 VirtIODevice parent_obj
;
47 VirtQueue
*ivq
, *dvq
, *svq
, *free_page_vq
;
48 uint32_t free_page_report_status
;
51 uint32_t free_page_report_cmd_id
;
52 uint64_t stats
[VIRTIO_BALLOON_S_NR
];
53 VirtQueueElement
*stats_vq_elem
;
54 size_t stats_vq_offset
;
55 QEMUTimer
*stats_timer
;
59 * Lock to synchronize threads to access the free page reporting related
60 * fields (e.g. free_page_report_status).
62 QemuMutex free_page_lock
;
63 QemuCond free_page_cond
;
65 * Set to block iothread to continue reading free page hints as the VM is
69 NotifierWithReturn free_page_report_notify
;
70 int64_t stats_last_update
;
71 int64_t stats_poll_interval
;
72 uint32_t host_features
;
73 PartiallyBalloonedPage
*pbp
;