mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00

When a machine is first booted, all virtio balloon stats are initialized to their default value -1 (18446744073709551615 when represented as unsigned). They remain that way while the firmware is loading, and early phase of guest OS boot, until the virtio-balloon driver is activated. Thereafter the reported stats reflect the guest OS activity. When a machine reset is performed, however, the virtio-balloon stats are left unchanged by QEMU, despite the guest OS no longer updating them, nor indeed even still existing. IOW, the mgmt app keeps getting stale stats until the guest OS starts once more and loads the virtio-balloon driver (if ever). At that point the app will see a discontinuity in the reported values as they sudden jump from the stale value to the new value. This jump is indigituishable from a valid data update. While there is an "last-updated" field to report on the freshness of the stats, that does not unambiguously tell the mgmt app whether the stats are still conceptually relevant to the current running workload. It is more conceptually useful to reset the stats to their default values on machine reset, given that the previous guest workload the stats reflect no longer exists. The mgmt app can now clearly identify that there are is no stats information available from the current executing workload. The 'last-updated' time is also reset back to 0. IOW, on every machine reset, the virtio stats are in the same clean state they were when the macine first powered on. A functional test is added to validate this behaviour with a real world guest OS. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20250204094202.2183262-1-berrange@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
80 lines
2 KiB
C
80 lines
2 KiB
C
/*
|
|
* Virtio Support
|
|
*
|
|
* Copyright IBM, Corp. 2007-2008
|
|
*
|
|
* Authors:
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
* Rusty Russell <rusty@rustcorp.com.au>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
* the COPYING file in the top-level directory.
|
|
*
|
|
*/
|
|
|
|
#ifndef QEMU_VIRTIO_BALLOON_H
|
|
#define QEMU_VIRTIO_BALLOON_H
|
|
|
|
#include "standard-headers/linux/virtio_balloon.h"
|
|
#include "hw/resettable.h"
|
|
#include "hw/virtio/virtio.h"
|
|
#include "system/iothread.h"
|
|
#include "qom/object.h"
|
|
|
|
#define TYPE_VIRTIO_BALLOON "virtio-balloon-device"
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBalloon, VIRTIO_BALLOON)
|
|
|
|
#define VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN 0x80000000
|
|
|
|
typedef struct virtio_balloon_stat VirtIOBalloonStat;
|
|
|
|
typedef struct virtio_balloon_stat_modern {
|
|
uint16_t tag;
|
|
uint8_t reserved[6];
|
|
uint64_t val;
|
|
} VirtIOBalloonStatModern;
|
|
|
|
enum virtio_balloon_free_page_hint_status {
|
|
FREE_PAGE_HINT_S_STOP = 0,
|
|
FREE_PAGE_HINT_S_REQUESTED = 1,
|
|
FREE_PAGE_HINT_S_START = 2,
|
|
FREE_PAGE_HINT_S_DONE = 3,
|
|
};
|
|
|
|
struct VirtIOBalloon {
|
|
VirtIODevice parent_obj;
|
|
VirtQueue *ivq, *dvq, *svq, *free_page_vq, *reporting_vq;
|
|
uint32_t free_page_hint_status;
|
|
uint32_t num_pages;
|
|
uint32_t actual;
|
|
uint32_t free_page_hint_cmd_id;
|
|
uint64_t stats[VIRTIO_BALLOON_S_NR];
|
|
VirtQueueElement *stats_vq_elem;
|
|
size_t stats_vq_offset;
|
|
QEMUTimer *stats_timer;
|
|
IOThread *iothread;
|
|
QEMUBH *free_page_bh;
|
|
/*
|
|
* Lock to synchronize threads to access the free page reporting related
|
|
* fields (e.g. free_page_hint_status).
|
|
*/
|
|
QemuMutex free_page_lock;
|
|
QemuCond free_page_cond;
|
|
/*
|
|
* Set to block iothread to continue reading free page hints as the VM is
|
|
* stopped.
|
|
*/
|
|
bool block_iothread;
|
|
NotifierWithReturn free_page_hint_notify;
|
|
int64_t stats_last_update;
|
|
int64_t stats_poll_interval;
|
|
uint32_t host_features;
|
|
|
|
bool qemu_4_0_config_size;
|
|
uint32_t poison_val;
|
|
|
|
/* State of the resettable container */
|
|
ResettableState reset_state;
|
|
};
|
|
|
|
#endif
|