mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
Replace qemu_real_host_page variables with inlined functions
Replace the global variables with inlined helper functions. getpagesize() is very likely annotated with a "const" function attribute (at least with glibc), and thus optimization should apply even better. This avoids the need for a constructor initialization too. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220323155743.1585078-12-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
b307e5052d
commit
8e3b0cbb72
53 changed files with 150 additions and 162 deletions
|
@ -11,7 +11,7 @@
|
|||
#include "qemu/iova-tree.h"
|
||||
#include "vhost-iova-tree.h"
|
||||
|
||||
#define iova_min_addr qemu_real_host_page_size
|
||||
#define iova_min_addr qemu_real_host_page_size()
|
||||
|
||||
/**
|
||||
* VhostIOVATree, able to:
|
||||
|
@ -86,7 +86,7 @@ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree,
|
|||
int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map)
|
||||
{
|
||||
/* Some vhost devices do not like addr 0. Skip first page */
|
||||
hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size;
|
||||
hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size();
|
||||
|
||||
if (map->translated_addr + map->size < map->translated_addr ||
|
||||
map->perm == IOMMU_NONE) {
|
||||
|
|
|
@ -471,14 +471,14 @@ size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq)
|
|||
size_t avail_size = offsetof(vring_avail_t, ring) +
|
||||
sizeof(uint16_t) * svq->vring.num;
|
||||
|
||||
return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size);
|
||||
return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size());
|
||||
}
|
||||
|
||||
size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq)
|
||||
{
|
||||
size_t used_size = offsetof(vring_used_t, ring) +
|
||||
sizeof(vring_used_elem_t) * svq->vring.num;
|
||||
return ROUND_UP(used_size, qemu_real_host_page_size);
|
||||
return ROUND_UP(used_size, qemu_real_host_page_size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -533,11 +533,11 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
|
|||
svq->vring.num = virtio_queue_get_num(vdev, virtio_get_queue_index(vq));
|
||||
driver_size = vhost_svq_driver_area_size(svq);
|
||||
device_size = vhost_svq_device_area_size(svq);
|
||||
svq->vring.desc = qemu_memalign(qemu_real_host_page_size, driver_size);
|
||||
svq->vring.desc = qemu_memalign(qemu_real_host_page_size(), driver_size);
|
||||
desc_size = sizeof(vring_desc_t) * svq->vring.num;
|
||||
svq->vring.avail = (void *)((char *)svq->vring.desc + desc_size);
|
||||
memset(svq->vring.desc, 0, driver_size);
|
||||
svq->vring.used = qemu_memalign(qemu_real_host_page_size, device_size);
|
||||
svq->vring.used = qemu_memalign(qemu_real_host_page_size(), device_size);
|
||||
memset(svq->vring.used, 0, device_size);
|
||||
svq->ring_id_maps = g_new0(VirtQueueElement *, svq->vring.num);
|
||||
for (unsigned i = 0; i < svq->vring.num - 1; i++) {
|
||||
|
|
|
@ -1166,7 +1166,7 @@ static int vhost_user_set_vring_num(struct vhost_dev *dev,
|
|||
static void vhost_user_host_notifier_free(VhostUserHostNotifier *n)
|
||||
{
|
||||
assert(n && n->unmap_addr);
|
||||
munmap(n->unmap_addr, qemu_real_host_page_size);
|
||||
munmap(n->unmap_addr, qemu_real_host_page_size());
|
||||
n->unmap_addr = NULL;
|
||||
}
|
||||
|
||||
|
@ -1503,7 +1503,7 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev,
|
|||
int fd)
|
||||
{
|
||||
int queue_idx = area->u64 & VHOST_USER_VRING_IDX_MASK;
|
||||
size_t page_size = qemu_real_host_page_size;
|
||||
size_t page_size = qemu_real_host_page_size();
|
||||
struct vhost_user *u = dev->opaque;
|
||||
VhostUserState *user = u->user;
|
||||
VirtIODevice *vdev = dev->vdev;
|
||||
|
|
|
@ -468,7 +468,7 @@ err:
|
|||
static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
|
||||
int queue_index)
|
||||
{
|
||||
size_t page_size = qemu_real_host_page_size;
|
||||
size_t page_size = qemu_real_host_page_size();
|
||||
struct vhost_vdpa *v = dev->opaque;
|
||||
VirtIODevice *vdev = dev->vdev;
|
||||
VhostVDPAHostNotifier *n;
|
||||
|
@ -485,7 +485,7 @@ static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
|
|||
|
||||
static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
|
||||
{
|
||||
size_t page_size = qemu_real_host_page_size;
|
||||
size_t page_size = qemu_real_host_page_size();
|
||||
struct vhost_vdpa *v = dev->opaque;
|
||||
VirtIODevice *vdev = dev->vdev;
|
||||
VhostVDPAHostNotifier *n;
|
||||
|
@ -875,7 +875,7 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v,
|
|||
return false;
|
||||
}
|
||||
|
||||
size = ROUND_UP(result->size, qemu_real_host_page_size);
|
||||
size = ROUND_UP(result->size, qemu_real_host_page_size());
|
||||
r = vhost_vdpa_dma_unmap(v, result->iova, size);
|
||||
return r == 0;
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ static uint32_t virtio_mem_default_thp_size(void)
|
|||
#if defined(__x86_64__) || defined(__arm__) || defined(__powerpc64__)
|
||||
default_thp_size = 2 * MiB;
|
||||
#elif defined(__aarch64__)
|
||||
if (qemu_real_host_page_size == 4 * KiB) {
|
||||
if (qemu_real_host_page_size() == 4 * KiB) {
|
||||
default_thp_size = 2 * MiB;
|
||||
} else if (qemu_real_host_page_size == 16 * KiB) {
|
||||
} else if (qemu_real_host_page_size() == 16 * KiB) {
|
||||
default_thp_size = 32 * MiB;
|
||||
} else if (qemu_real_host_page_size == 64 * KiB) {
|
||||
} else if (qemu_real_host_page_size() == 64 * KiB) {
|
||||
default_thp_size = 512 * MiB;
|
||||
}
|
||||
#endif
|
||||
|
@ -120,7 +120,7 @@ static uint64_t virtio_mem_default_block_size(RAMBlock *rb)
|
|||
const uint64_t page_size = qemu_ram_pagesize(rb);
|
||||
|
||||
/* We can have hugetlbfs with a page size smaller than the THP size. */
|
||||
if (page_size == qemu_real_host_page_size) {
|
||||
if (page_size == qemu_real_host_page_size()) {
|
||||
return MAX(page_size, virtio_mem_thp_size());
|
||||
}
|
||||
return MAX(page_size, VIRTIO_MEM_MIN_BLOCK_SIZE);
|
||||
|
@ -135,7 +135,7 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
|
|||
* fresh page, consuming actual memory.
|
||||
*/
|
||||
return !qemu_ram_is_shared(rb) && rb->fd < 0 &&
|
||||
qemu_ram_pagesize(rb) == qemu_real_host_page_size;
|
||||
qemu_ram_pagesize(rb) == qemu_real_host_page_size();
|
||||
}
|
||||
#endif /* VIRTIO_MEM_HAS_LEGACY_GUESTS */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue