qemu/include/hw/virtio/virtio-balloon.h
<<
>>
Prefs
   1/*
   2 * Virtio Support
   3 *
   4 * Copyright IBM, Corp. 2007-2008
   5 *
   6 * Authors:
   7 *  Anthony Liguori   <aliguori@us.ibm.com>
   8 *  Rusty Russell     <rusty@rustcorp.com.au>
   9 *
  10 * This work is licensed under the terms of the GNU GPL, version 2.  See
  11 * the COPYING file in the top-level directory.
  12 *
  13 */
  14
  15#ifndef QEMU_VIRTIO_BALLOON_H
  16#define QEMU_VIRTIO_BALLOON_H
  17
  18#include "standard-headers/linux/virtio_balloon.h"
  19#include "hw/virtio/virtio.h"
  20#include "sysemu/iothread.h"
  21
  22#define TYPE_VIRTIO_BALLOON "virtio-balloon-device"
  23#define VIRTIO_BALLOON(obj) \
  24        OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
  25
  26#define VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN 0x80000000
  27
  28typedef struct virtio_balloon_stat VirtIOBalloonStat;
  29
  30typedef struct virtio_balloon_stat_modern {
  31       uint16_t tag;
  32       uint8_t reserved[6];
  33       uint64_t val;
  34} VirtIOBalloonStatModern;
  35
  36enum virtio_balloon_free_page_report_status {
  37    FREE_PAGE_REPORT_S_STOP = 0,
  38    FREE_PAGE_REPORT_S_REQUESTED = 1,
  39    FREE_PAGE_REPORT_S_START = 2,
  40    FREE_PAGE_REPORT_S_DONE = 3,
  41};
  42
  43typedef struct VirtIOBalloon {
  44    VirtIODevice parent_obj;
  45    VirtQueue *ivq, *dvq, *svq, *free_page_vq;
  46    uint32_t free_page_report_status;
  47    uint32_t num_pages;
  48    uint32_t actual;
  49    uint32_t free_page_report_cmd_id;
  50    uint64_t stats[VIRTIO_BALLOON_S_NR];
  51    VirtQueueElement *stats_vq_elem;
  52    size_t stats_vq_offset;
  53    QEMUTimer *stats_timer;
  54    IOThread *iothread;
  55    QEMUBH *free_page_bh;
  56    /*
  57     * Lock to synchronize threads to access the free page reporting related
  58     * fields (e.g. free_page_report_status).
  59     */
  60    QemuMutex free_page_lock;
  61    QemuCond  free_page_cond;
  62    /*
  63     * Set to block iothread to continue reading free page hints as the VM is
  64     * stopped.
  65     */
  66    bool block_iothread;
  67    NotifierWithReturn free_page_report_notify;
  68    int64_t stats_last_update;
  69    int64_t stats_poll_interval;
  70    uint32_t host_features;
  71
  72    bool qemu_4_0_config_size;
  73} VirtIOBalloon;
  74
  75#endif
  76