Add sysctls to display the total and free amount of hard-wired mem for VMs
# sysctl hw.vmm hw.vmm.mem_free: 2145386496 hw.vmm.mem_total: 2145386496 Submitted by: Takeshi HASEGAWA hasegaw at gmail com
This commit is contained in:
parent
75106bd298
commit
6c5ad005be
@ -117,6 +117,30 @@ vm_destroy(struct vmctx *vm)
|
||||
free(vm);
|
||||
}
|
||||
|
||||
size_t
|
||||
vmm_get_mem_total(void)
|
||||
{
|
||||
size_t mem_total = 0;
|
||||
size_t oldlen = sizeof(mem_total);
|
||||
int error;
|
||||
error = sysctlbyname("hw.vmm.mem_total", &mem_total, &oldlen, NULL, 0);
|
||||
if (error)
|
||||
return -1;
|
||||
return mem_total;
|
||||
}
|
||||
|
||||
size_t
|
||||
vmm_get_mem_free(void)
|
||||
{
|
||||
size_t mem_free = 0;
|
||||
size_t oldlen = sizeof(mem_free);
|
||||
int error;
|
||||
error = sysctlbyname("hw.vmm.mem_free", &mem_free, &oldlen, NULL, 0);
|
||||
if (error)
|
||||
return -1;
|
||||
return mem_free;
|
||||
}
|
||||
|
||||
int
|
||||
vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa,
|
||||
vm_paddr_t *ret_hpa, size_t *ret_len)
|
||||
|
@ -34,6 +34,8 @@ struct vmctx;
|
||||
int vm_create(const char *name);
|
||||
struct vmctx *vm_open(const char *name);
|
||||
void vm_destroy(struct vmctx *ctx);
|
||||
size_t vmm_get_mem_total(void);
|
||||
size_t vmm_get_mem_free(void);
|
||||
int vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa,
|
||||
vm_paddr_t *ret_hpa, size_t *ret_len);
|
||||
/*
|
||||
|
@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/vmm.h>
|
||||
#include "vmm_lapic.h"
|
||||
#include "vmm_stat.h"
|
||||
#include "vmm_mem.h"
|
||||
#include "io/ppt.h"
|
||||
#include <machine/vmm_dev.h>
|
||||
|
||||
@ -458,6 +459,24 @@ sysctl_vmm_create(SYSCTL_HANDLER_ARGS)
|
||||
SYSCTL_PROC(_hw_vmm, OID_AUTO, create, CTLTYPE_STRING | CTLFLAG_RW,
|
||||
NULL, 0, sysctl_vmm_create, "A", NULL);
|
||||
|
||||
static int
|
||||
sysctl_vmm_mem_total(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
size_t val = vmm_mem_get_mem_total();
|
||||
return sysctl_handle_long(oidp, &val, 0, req);
|
||||
}
|
||||
SYSCTL_PROC(_hw_vmm, OID_AUTO, mem_total, CTLTYPE_LONG | CTLFLAG_RD,
|
||||
0, 0, sysctl_vmm_mem_total, "LU", "Amount of Total memory");
|
||||
|
||||
static int
|
||||
sysctl_vmm_mem_free(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
size_t val = vmm_mem_get_mem_free();
|
||||
return sysctl_handle_long(oidp, &val, 0, req);
|
||||
}
|
||||
SYSCTL_PROC(_hw_vmm, OID_AUTO, mem_free, CTLTYPE_LONG | CTLFLAG_RD,
|
||||
0, 0, sysctl_vmm_mem_free, "LU", "Amount of Free memory");
|
||||
|
||||
void
|
||||
vmmdev_init(void)
|
||||
{
|
||||
|
@ -63,6 +63,7 @@ static struct {
|
||||
} vmm_mem_avail[VMM_MEM_MAXSEGS];
|
||||
|
||||
static int vmm_mem_nsegs;
|
||||
size_t vmm_mem_total_bytes;
|
||||
|
||||
static vm_paddr_t maxaddr;
|
||||
|
||||
@ -96,6 +97,7 @@ vmm_mem_steal_memory(void)
|
||||
smapsize = *((uint32_t *)smapbase - 1);
|
||||
smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize);
|
||||
|
||||
vmm_mem_total_bytes = 0;
|
||||
nsegs = 0;
|
||||
for (smap = smapbase; smap < smapend; smap++) {
|
||||
/*
|
||||
@ -131,6 +133,7 @@ vmm_mem_steal_memory(void)
|
||||
|
||||
vmm_mem_avail[nsegs].base = base;
|
||||
vmm_mem_avail[nsegs].length = length;
|
||||
vmm_mem_total_bytes += length;
|
||||
|
||||
if (base + length > maxaddr)
|
||||
maxaddr = base + length;
|
||||
@ -344,6 +347,27 @@ vmm_mem_alloc(size_t size)
|
||||
return (addr);
|
||||
}
|
||||
|
||||
size_t
|
||||
vmm_mem_get_mem_total(void)
|
||||
{
|
||||
return vmm_mem_total_bytes;
|
||||
}
|
||||
|
||||
size_t
|
||||
vmm_mem_get_mem_free(void)
|
||||
{
|
||||
size_t length = 0;
|
||||
int i;
|
||||
|
||||
mtx_lock(&vmm_mem_mtx);
|
||||
for (i = 0; i < vmm_mem_nsegs; i++) {
|
||||
length += vmm_mem_avail[i].length;
|
||||
}
|
||||
mtx_unlock(&vmm_mem_mtx);
|
||||
|
||||
return(length);
|
||||
}
|
||||
|
||||
void
|
||||
vmm_mem_free(vm_paddr_t base, size_t length)
|
||||
{
|
||||
|
@ -35,4 +35,7 @@ void vmm_mem_free(vm_paddr_t start, size_t size);
|
||||
vm_paddr_t vmm_mem_maxaddr(void);
|
||||
void vmm_mem_dump(void);
|
||||
|
||||
size_t vmm_mem_get_mem_total(void);
|
||||
size_t vmm_mem_get_mem_free(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user