Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/virtio/balloon/virtio_balloon.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | #define VTBALLOON_FLAG_DETACH 0x01 | ||||
struct thread *vtballoon_td; | struct thread *vtballoon_td; | ||||
uint32_t *vtballoon_page_frames; | uint32_t *vtballoon_page_frames; | ||||
int vtballoon_timeout; | int vtballoon_timeout; | ||||
}; | }; | ||||
static struct virtio_feature_desc vtballoon_feature_desc[] = { | static struct virtio_feature_desc vtballoon_feature_desc[] = { | ||||
{ VIRTIO_BALLOON_F_MUST_TELL_HOST, "MustTellHost" }, | { VIRTIO_BALLOON_F_MUST_TELL_HOST, "MustTellHost" }, | ||||
{ VIRTIO_BALLOON_F_STATS_VQ, "StatsVq" }, | { VIRTIO_BALLOON_F_STATS_VQ, "StatsVq" }, | ||||
{ VIRTIO_BALLOON_F_DEFLATE_ON_OOM, "DeflateOnOOM" }, | |||||
{ 0, NULL } | { 0, NULL } | ||||
}; | }; | ||||
static int vtballoon_probe(device_t); | static int vtballoon_probe(device_t); | ||||
static int vtballoon_attach(device_t); | static int vtballoon_attach(device_t); | ||||
static int vtballoon_detach(device_t); | static int vtballoon_detach(device_t); | ||||
static int vtballoon_config_change(device_t); | static int vtballoon_config_change(device_t); | ||||
Show All 14 Lines | |||||
static vm_page_t | static vm_page_t | ||||
vtballoon_alloc_page(struct vtballoon_softc *); | vtballoon_alloc_page(struct vtballoon_softc *); | ||||
static void vtballoon_free_page(struct vtballoon_softc *, vm_page_t); | static void vtballoon_free_page(struct vtballoon_softc *, vm_page_t); | ||||
static int vtballoon_sleep(struct vtballoon_softc *); | static int vtballoon_sleep(struct vtballoon_softc *); | ||||
static void vtballoon_thread(void *); | static void vtballoon_thread(void *); | ||||
static void vtballoon_add_sysctl(struct vtballoon_softc *); | static void vtballoon_add_sysctl(struct vtballoon_softc *); | ||||
#define vtballoon_modern(_sc) \ | |||||
(((_sc)->vtballoon_features & VIRTIO_F_VERSION_1) != 0) | |||||
/* Features desired/implemented by this driver. */ | /* Features desired/implemented by this driver. */ | ||||
#define VTBALLOON_FEATURES 0 | #define VTBALLOON_FEATURES VIRTIO_BALLOON_F_MUST_TELL_HOST | ||||
/* Timeout between retries when the balloon needs inflating. */ | /* Timeout between retries when the balloon needs inflating. */ | ||||
#define VTBALLOON_LOWMEM_TIMEOUT hz | #define VTBALLOON_LOWMEM_TIMEOUT hz | ||||
/* | /* | ||||
* Maximum number of pages we'll request to inflate or deflate | * Maximum number of pages we'll request to inflate or deflate | ||||
* the balloon in one virtqueue request. Both Linux and NetBSD | * the balloon in one virtqueue request. Both Linux and NetBSD | ||||
* have settled on 256, doing up to 1MB at a time. | * have settled on 256, doing up to 1MB at a time. | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
vtballoon_negotiate_features(struct vtballoon_softc *sc) | vtballoon_negotiate_features(struct vtballoon_softc *sc) | ||||
{ | { | ||||
device_t dev; | device_t dev; | ||||
uint64_t features; | uint64_t features; | ||||
dev = sc->vtballoon_dev; | dev = sc->vtballoon_dev; | ||||
features = virtio_negotiate_features(dev, VTBALLOON_FEATURES); | features = VTBALLOON_FEATURES; | ||||
sc->vtballoon_features = features; | |||||
sc->vtballoon_features = virtio_negotiate_features(dev, features); | |||||
virtio_finalize_features(dev); | |||||
} | } | ||||
static int | static int | ||||
vtballoon_alloc_virtqueues(struct vtballoon_softc *sc) | vtballoon_alloc_virtqueues(struct vtballoon_softc *sc) | ||||
{ | { | ||||
device_t dev; | device_t dev; | ||||
struct vq_alloc_info vq_info[2]; | struct vq_alloc_info vq_info[2]; | ||||
int nvqs; | int nvqs; | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | vtballoon_stop(struct vtballoon_softc *sc) | ||||
virtio_stop(sc->vtballoon_dev); | virtio_stop(sc->vtballoon_dev); | ||||
} | } | ||||
static vm_page_t | static vm_page_t | ||||
vtballoon_alloc_page(struct vtballoon_softc *sc) | vtballoon_alloc_page(struct vtballoon_softc *sc) | ||||
{ | { | ||||
vm_page_t m; | vm_page_t m; | ||||
m = vm_page_alloc(NULL, 0, VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ); | m = vm_page_alloc(NULL, 0, | ||||
VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_NODUMP); | |||||
if (m != NULL) | if (m != NULL) | ||||
sc->vtballoon_current_npages++; | sc->vtballoon_current_npages++; | ||||
return (m); | return (m); | ||||
} | } | ||||
static void | static void | ||||
vtballoon_free_page(struct vtballoon_softc *sc, vm_page_t m) | vtballoon_free_page(struct vtballoon_softc *sc, vm_page_t m) | ||||
{ | { | ||||
vm_page_free(m); | vm_page_free(m); | ||||
sc->vtballoon_current_npages--; | sc->vtballoon_current_npages--; | ||||
} | } | ||||
static uint32_t | static uint32_t | ||||
vtballoon_desired_size(struct vtballoon_softc *sc) | vtballoon_desired_size(struct vtballoon_softc *sc) | ||||
{ | { | ||||
uint32_t desired; | uint32_t desired; | ||||
desired = virtio_read_dev_config_4(sc->vtballoon_dev, | desired = virtio_read_dev_config_4(sc->vtballoon_dev, | ||||
offsetof(struct virtio_balloon_config, num_pages)); | offsetof(struct virtio_balloon_config, num_pages)); | ||||
if (vtballoon_modern(sc)) | |||||
return (desired); | |||||
else | |||||
return (le32toh(desired)); | return (le32toh(desired)); | ||||
} | } | ||||
static void | static void | ||||
vtballoon_update_size(struct vtballoon_softc *sc) | vtballoon_update_size(struct vtballoon_softc *sc) | ||||
{ | { | ||||
uint32_t npages; | |||||
npages = sc->vtballoon_current_npages; | |||||
if (!vtballoon_modern(sc)) | |||||
npages = htole32(npages); | |||||
virtio_write_dev_config_4(sc->vtballoon_dev, | virtio_write_dev_config_4(sc->vtballoon_dev, | ||||
offsetof(struct virtio_balloon_config, actual), | offsetof(struct virtio_balloon_config, actual), npages); | ||||
htole32(sc->vtballoon_current_npages)); | |||||
} | } | ||||
static int | static int | ||||
vtballoon_sleep(struct vtballoon_softc *sc) | vtballoon_sleep(struct vtballoon_softc *sc) | ||||
{ | { | ||||
int rc, timeout; | int rc, timeout; | ||||
uint32_t current, desired; | uint32_t current, desired; | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |