From: VMware, Inc <> Date: Fri, 18 Sep 2009 21:24:41 +0000 (-0700) Subject: Commenting of all Unixes vmballoon X-Git-Tag: 2009.09.18-193784~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c4fe61ba1f80b42cf8f7a748149935a9ffb3f990;p=thirdparty%2Fopen-vm-tools.git Commenting of all Unixes vmballoon Cleaning/adding missing comment so that code looks nicer Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/modules/freebsd/vmmemctl/os.c b/open-vm-tools/modules/freebsd/vmmemctl/os.c index 337768429..4ae21bb0d 100644 --- a/open-vm-tools/modules/freebsd/vmmemctl/os.c +++ b/open-vm-tools/modules/freebsd/vmmemctl/os.c @@ -26,8 +26,8 @@ * Compile-Time Options */ -#define OS_DISABLE_UNLOAD (0) -#define OS_DEBUG (1) +#define OS_DISABLE_UNLOAD 0 +#define OS_DEBUG 1 /* * Includes @@ -56,10 +56,6 @@ #include "os.h" #include "vmballoon.h" -/* - * Constants - */ - /* * Types */ @@ -324,12 +320,13 @@ OS_ReservedPageGetPPN(PageHandle handle) // IN: A valid page handle } -static void os_pmap_alloc(os_pmap *p) +static void +os_pmap_alloc(os_pmap *p) // IN { /* number of pages (div. 8) */ p->size = (cnt.v_page_count + 7) / 8; - /* + /* * expand to nearest word boundary * XXX: bitmap can be greater than total number of pages in system */ @@ -339,17 +336,21 @@ static void os_pmap_alloc(os_pmap *p) p->bitmap = (unsigned long *)kmem_alloc(kernel_map, p->size); } -static void os_pmap_free(os_pmap *p) + +static void +os_pmap_free(os_pmap *p) // IN { kmem_free(kernel_map, (vm_offset_t)p->bitmap, p->size); p->size = 0; p->bitmap = NULL; } -static void os_pmap_init(os_pmap *p) + +static void +os_pmap_init(os_pmap *p) // IN { /* alloc bitmap for pages in system */ - os_pmap_alloc(p); + os_pmap_alloc(p); if (!p->bitmap) { p->size = 0; p->bitmap = NULL; @@ -361,7 +362,9 @@ static void os_pmap_init(os_pmap *p) p->hint = 0; } -static vm_pindex_t os_pmap_getindex(os_pmap *p) + +static vm_pindex_t +os_pmap_getindex(os_pmap *p) // IN { int i; unsigned long bitidx, wordidx; @@ -393,14 +396,19 @@ static vm_pindex_t os_pmap_getindex(os_pmap *p) return (vm_pindex_t)-1; } -static void os_pmap_putindex(os_pmap *p, vm_pindex_t pindex) + +static void +os_pmap_putindex(os_pmap *p, // IN + vm_pindex_t pindex) // IN { /* unset bit */ - p->bitmap[pindex / (8*sizeof(unsigned long))] &= + p->bitmap[pindex / (8*sizeof(unsigned long))] &= ~(1<<(pindex % (8*sizeof(unsigned long)))); } -static void os_kmem_free(vm_page_t page) + +static void +os_kmem_free(vm_page_t page) // IN { os_state *state = &global_state; os_pmap *pmap = &state->pmap; @@ -413,7 +421,9 @@ static void os_kmem_free(vm_page_t page) vm_page_free(page); } -static vm_page_t os_kmem_alloc(int alloc_normal_failed) + +static vm_page_t +os_kmem_alloc(int alloc_normal_failed) // IN { vm_page_t page; vm_pindex_t pindex; @@ -446,12 +456,16 @@ static vm_page_t os_kmem_alloc(int alloc_normal_failed) return page; } -static void os_balloonobject_delete(void) + +static void +os_balloonobject_delete(void) { vm_object_deallocate(global_state.vmobject); } -static void os_balloonobject_create(void) + +static void +os_balloonobject_create(void) { global_state.vmobject = vm_object_allocate(OBJT_DEFAULT, OFF_TO_IDX(VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS)); @@ -513,7 +527,8 @@ OS_ReservedPageFree(PageHandle handle) // IN: A valid page handle } -static void os_timer_internal(void *data) +static void +os_timer_internal(void *data) // IN { os_timer *t = (os_timer *) data; @@ -614,10 +629,29 @@ OS_Yield(void) /* Do nothing. */ } + +/* + *----------------------------------------------------------------------------- + * + * OS_Init -- + * + * Called at driver startup, initializes the balloon state and structures. + * + * XXX : this function should return a value to indicate success or failure + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + void -OS_Init(const char *name, - const char *name_verbose, - OSStatusHandler *handler) +OS_Init(const char *name, // IN + const char *nameVerbose, // IN + OSStatusHandler *handler) // IN { os_state *state = &global_state; os_pmap *pmap = &state->pmap; @@ -637,7 +671,7 @@ OS_Init(const char *name, /* initialize status state */ state->status.handler = handler; state->status.name = name; - state->status.name_verbose = name_verbose; + state->status.name_verbose = nameVerbose; os_pmap_init(pmap); os_balloonobject_create(); @@ -648,6 +682,23 @@ OS_Init(const char *name, printf("%s initialized\n", state->status.name_verbose); } + +/* + *----------------------------------------------------------------------------- + * + * OS_Cleanup -- + * + * Called when the driver is terminating, cleanup initialized structures. + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + void OS_Cleanup(void) { @@ -664,11 +715,16 @@ OS_Cleanup(void) printf("%s unloaded\n", status->name_verbose); } + /* * Module Load/Unload Operations */ -static int vmmemctl_load(module_t mod, int cmd, void *arg) + +static int +vmmemctl_load(module_t mod, // IN: Unused + int cmd, // IN + void *arg) // IN: Unused { int err = 0; @@ -681,7 +737,7 @@ static int vmmemctl_load(module_t mod, int cmd, void *arg) case MOD_UNLOAD: if (OS_DISABLE_UNLOAD) { - /* prevent moudle unload */ + /* prevent module unload */ err = EBUSY; } else { Balloon_ModuleCleanup(); diff --git a/open-vm-tools/modules/freebsd/vmmemctl/vmballoon.c b/open-vm-tools/modules/freebsd/vmmemctl/vmballoon.c index 283e791a5..977a17aad 100644 --- a/open-vm-tools/modules/freebsd/vmmemctl/vmballoon.c +++ b/open-vm-tools/modules/freebsd/vmmemctl/vmballoon.c @@ -38,10 +38,10 @@ extern "C" { * Compile-Time Options */ -#define BALLOON_RATE_ADAPT (1) +#define BALLOON_RATE_ADAPT 1 -#define BALLOON_DEBUG (1) -#define BALLOON_DEBUG_VERBOSE (0) +#define BALLOON_DEBUG 1 +#define BALLOON_DEBUG_VERBOSE 0 #define BALLOON_STATS #define BALLOON_STATS_PROCFS @@ -53,7 +53,6 @@ extern "C" { #include "os.h" #include "backdoor.h" #include "backdoor_balloon.h" - #include "vmballoon.h" /* @@ -67,27 +66,27 @@ extern "C" { #define BALLOON_NAME "vmmemctl" #define BALLOON_NAME_VERBOSE "VMware memory control driver" -#define BALLOON_PROTOCOL_VERSION (2) +#define BALLOON_PROTOCOL_VERSION 2 -#define BALLOON_CHUNK_PAGES (1000) +#define BALLOON_CHUNK_PAGES 1000 -#define BALLOON_NOSLEEP_ALLOC_MAX (16384) +#define BALLOON_NOSLEEP_ALLOC_MAX 16384 -#define BALLOON_RATE_ALLOC_MIN (512) -#define BALLOON_RATE_ALLOC_MAX (2048) -#define BALLOON_RATE_ALLOC_INC (16) +#define BALLOON_RATE_ALLOC_MIN 512 +#define BALLOON_RATE_ALLOC_MAX 2048 +#define BALLOON_RATE_ALLOC_INC 16 -#define BALLOON_RATE_FREE_MIN (512) -#define BALLOON_RATE_FREE_MAX (16384) -#define BALLOON_RATE_FREE_INC (16) +#define BALLOON_RATE_FREE_MIN 512 +#define BALLOON_RATE_FREE_MAX 16384 +#define BALLOON_RATE_FREE_INC 16 -#define BALLOON_ERROR_PAGES (16) +#define BALLOON_ERROR_PAGES 16 /* * When guest is under memory pressure, use a reduced page allocation * rate for next several cycles. */ -#define SLOW_PAGE_ALLOCATION_CYCLES (4) +#define SLOW_PAGE_ALLOCATION_CYCLES 4 /* * Move it to bora/public/balloon_def.h later, if needed. Note that @@ -95,10 +94,10 @@ extern "C" { * distinguishing page allocation failures from monitor-backdoor errors. * We use value 1000 because all monitor-backdoor error codes are < 1000. */ -#define BALLOON_PAGE_ALLOC_FAILURE (1000) +#define BALLOON_PAGE_ALLOC_FAILURE 1000 // Maximum number of page allocations without yielding processor -#define BALLOON_ALLOC_YIELD_THRESHOLD (1024) +#define BALLOON_ALLOC_YIELD_THRESHOLD 1024 /* @@ -151,21 +150,22 @@ static Balloon globalBalloon; static Bool timerStarted; /* - * Forward Declarations + * Balloon operations */ - -static int Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType); -static int Balloon_FreePage(Balloon *b, int monitorUnlock); -static int Balloon_AdjustSize(Balloon *b, uint32 target); -static void Balloon_Reset(Balloon *b); - +static int BalloonPageAlloc(Balloon *b, BalloonPageAllocType allocType); +static int BalloonPageFree(Balloon *b, int monitorUnlock); +static int BalloonAdjustSize(Balloon *b, uint32 target); +static void BalloonReset(Balloon *b); static void BalloonTimerHandler(void *clientData); -static int Balloon_MonitorStart(Balloon *b); -static int Balloon_MonitorGuestType(Balloon *b); -static int Balloon_MonitorGetTarget(Balloon *b, uint32 *nPages); -static int Balloon_MonitorLockPage(Balloon *b, PageHandle handle); -static int Balloon_MonitorUnlockPage(Balloon *b, PageHandle handle); +/* + * Backdoor Operations + */ +static int BalloonMonitorStart(Balloon *b); +static int BalloonMonitorGuestType(Balloon *b); +static int BalloonMonitorGetTarget(Balloon *b, uint32 *nPages); +static int BalloonMonitorLockPage(Balloon *b, PageHandle handle); +static int BalloonMonitorUnlockPage(Balloon *b, PageHandle handle); /* * Macros @@ -217,10 +217,6 @@ static void OBJ ## _Remove(OBJ **head, OBJ *obj) \ GENERATE_LIST_INSERT(BalloonChunk); GENERATE_LIST_REMOVE(BalloonChunk); -/* - * Procfs Operations - */ - /* *---------------------------------------------------------------------- @@ -241,7 +237,7 @@ GENERATE_LIST_REMOVE(BalloonChunk); */ static int -BalloonProcRead(char *buf, // OUT +BalloonProcRead(char *buf, // OUT size_t size) // IN { int len = 0; @@ -297,10 +293,6 @@ BalloonProcRead(char *buf, // OUT return len; } -/* - * Utility Operations - */ - /* *---------------------------------------------------------------------- @@ -396,17 +388,14 @@ BalloonChunk_Create(void) * *---------------------------------------------------------------------- */ + static void -BalloonChunk_Destroy(BalloonChunk *chunk) +BalloonChunk_Destroy(BalloonChunk *chunk) // IN { /* reclaim storage */ OS_Free(chunk, sizeof *chunk); } -/* - * Balloon operations - */ - /* *---------------------------------------------------------------------- @@ -423,8 +412,9 @@ BalloonChunk_Destroy(BalloonChunk *chunk) * *---------------------------------------------------------------------- */ + static int -Balloon_Init(Balloon *b) +Balloon_Init(Balloon *b) // IN { /* clear state */ OS_MemZero(b, sizeof *b); @@ -439,6 +429,7 @@ Balloon_Init(Balloon *b) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -454,14 +445,15 @@ Balloon_Init(Balloon *b) * *---------------------------------------------------------------------- */ + static void -Balloon_Deallocate(Balloon *b) +Balloon_Deallocate(Balloon *b) // IN { unsigned int cnt = 0; /* free all pages, skipping monitor unlock */ while (b->nChunks > 0) { - (void) Balloon_FreePage(b, FALSE); + (void) BalloonPageFree(b, FALSE); if (++cnt >= b->rateFree) { cnt = 0; OS_Yield(); @@ -469,10 +461,11 @@ Balloon_Deallocate(Balloon *b) } } + /* *---------------------------------------------------------------------- * - * Balloon_Reset -- + * BalloonReset -- * * Resets balloon "b" to empty state. Frees all allocated pages * and attempts to reset contact with the monitor. @@ -485,8 +478,9 @@ Balloon_Deallocate(Balloon *b) * *---------------------------------------------------------------------- */ + static void -Balloon_Reset(Balloon *b) +BalloonReset(Balloon *b) // IN { uint32 status; @@ -494,16 +488,17 @@ Balloon_Reset(Balloon *b) Balloon_Deallocate(b); /* send start command */ - status = Balloon_MonitorStart(b); + status = BalloonMonitorStart(b); if (status == BALLOON_SUCCESS) { /* clear flag */ b->resetFlag = 0; /* report guest type */ - (void) Balloon_MonitorGuestType(b); + (void) BalloonMonitorGuestType(b); } } + /* *---------------------------------------------------------------------- * @@ -522,8 +517,9 @@ Balloon_Reset(Balloon *b) * *---------------------------------------------------------------------- */ + static void -BalloonTimerHandler(void *clientData) +BalloonTimerHandler(void *clientData) // IN { Balloon *b = (Balloon *) clientData; uint32 target = 0; // Silence compiler warning. @@ -534,11 +530,11 @@ BalloonTimerHandler(void *clientData) /* reset, if specified */ if (b->resetFlag) { - Balloon_Reset(b); + BalloonReset(b); } /* contact monitor via backdoor */ - status = Balloon_MonitorGetTarget(b, &target); + status = BalloonMonitorGetTarget(b, &target); /* decrement slowPageAllocationCycles counter */ if (b->slowPageAllocationCycles > 0) { @@ -548,7 +544,7 @@ BalloonTimerHandler(void *clientData) if (status == BALLOON_SUCCESS) { /* update target, adjust size */ b->nPagesTarget = target; - (void) Balloon_AdjustSize(b, target); + (void) BalloonAdjustSize(b, target); } } @@ -556,7 +552,7 @@ BalloonTimerHandler(void *clientData) /* *---------------------------------------------------------------------- * - * Balloon_ErrorPagesAlloc -- + * BalloonErrorPagesAlloc -- * * Attempt to add "page" to list of non-balloonable pages * associated with "b". @@ -570,8 +566,10 @@ BalloonTimerHandler(void *clientData) * *---------------------------------------------------------------------- */ + static int -Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) +BalloonErrorPagesAlloc(Balloon *b, // IN + PageHandle page) // IN { /* fail if list already full */ if (b->errors.nextPage >= BALLOON_ERROR_PAGES) { @@ -588,7 +586,7 @@ Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) /* *---------------------------------------------------------------------- * - * Balloon_ErrorPagesFree -- + * BalloonErrorPagesFree -- * * Deallocates all pages on the list of non-balloonable pages * associated with "b". @@ -601,10 +599,11 @@ Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) * *---------------------------------------------------------------------- */ + static void -Balloon_ErrorPagesFree(Balloon *b) +BalloonErrorPagesFree(Balloon *b) // IN { - int i; + unsigned int i; /* free all non-balloonable "error" pages */ for (i = 0; i < b->errors.nextPage; i++) { @@ -615,10 +614,11 @@ Balloon_ErrorPagesFree(Balloon *b) b->errors.nextPage = 0; } + /* *---------------------------------------------------------------------- * - * Balloon_AllocPage -- + * BalloonPageAlloc -- * * Attempts to allocate a physical page, inflating balloon "b". * Informs monitor of PPN for allocated page via backdoor. @@ -631,8 +631,10 @@ Balloon_ErrorPagesFree(Balloon *b) * *---------------------------------------------------------------------- */ + static int -Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) +BalloonPageAlloc(Balloon *b, // IN + BalloonPageAllocType allocType) // IN { BalloonChunk *chunk; PageHandle page; @@ -677,11 +679,11 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) } /* inform monitor via backdoor */ - status = Balloon_MonitorLockPage(b, page); + status = BalloonMonitorLockPage(b, page); if (status != BALLOON_SUCCESS) { /* place on list of non-balloonable pages, retry allocation */ if ((status != BALLOON_ERROR_RESET) && - (Balloon_ErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) { + (BalloonErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) { goto retry; } @@ -700,10 +702,11 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * - * Balloon_FreePage -- + * BalloonPageFree -- * * Attempts to deallocate a physical page, deflating balloon "b". * Informs monitor of PPN for deallocated page via backdoor if @@ -717,8 +720,10 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) * *---------------------------------------------------------------------- */ + static int -Balloon_FreePage(Balloon *b, int monitorUnlock) +BalloonPageFree(Balloon *b, // IN + int monitorUnlock) // IN { BalloonChunk *chunk; PageHandle page; @@ -747,7 +752,7 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) /* inform monitor via backdoor */ if (monitorUnlock) { - status = Balloon_MonitorUnlockPage(b, page); + status = BalloonMonitorUnlockPage(b, page); if (status != BALLOON_SUCCESS) { /* reset next pointer, fail */ chunk->nextPage++; @@ -775,6 +780,7 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -792,14 +798,16 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) * *---------------------------------------------------------------------- */ + static void -BalloonDecreaseRateAlloc(Balloon *b) +BalloonDecreaseRateAlloc(Balloon *b) // IN { if (BALLOON_RATE_ADAPT) { b->rateAlloc = MAX(b->rateAlloc / 2, BALLOON_RATE_ALLOC_MIN); } } + /* *---------------------------------------------------------------------- * @@ -829,8 +837,10 @@ BalloonDecreaseRateAlloc(Balloon *b) * *---------------------------------------------------------------------- */ + static void -BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc) +BalloonIncreaseRateAlloc(Balloon *b, // IN + uint32 nAlloc) // IN { if (BALLOON_RATE_ADAPT) { if (nAlloc >= b->rateAlloc) { @@ -859,7 +869,8 @@ BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc) */ static int -BalloonInflate(Balloon *b, uint32 target) +BalloonInflate(Balloon *b, // IN + uint32 target) // IN { int status, allocations = 0; uint32 i, nAllocNoSleep, nAllocCanSleep; @@ -886,14 +897,14 @@ BalloonInflate(Balloon *b, uint32 target) for (i = 0; i < nAllocNoSleep; i++) { /* Try NOSLEEP allocation */ - status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_NOSLEEP); + status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_NOSLEEP); if (status != BALLOON_SUCCESS) { if (status != BALLOON_PAGE_ALLOC_FAILURE) { /* * Not a page allocation failure, so release non-balloonable * pages, and fail. */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(status); } /* @@ -918,7 +929,7 @@ BalloonInflate(Balloon *b, uint32 target) if (i == nAllocNoSleep) { BalloonIncreaseRateAlloc(b, nAllocNoSleep); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } else { /* @@ -929,7 +940,7 @@ BalloonInflate(Balloon *b, uint32 target) if (i > b->rateAlloc) { BalloonIncreaseRateAlloc(b, i); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } else { /* update successful NOSLEEP allocations, and proceed */ @@ -951,7 +962,7 @@ BalloonInflate(Balloon *b, uint32 target) for (i = 0; i < nAllocCanSleep; i++) { /* Try CANSLEEP allocation */ - status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_CANSLEEP); + status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_CANSLEEP); if(status != BALLOON_SUCCESS) { if (status == BALLOON_PAGE_ALLOC_FAILURE) { /* @@ -961,7 +972,7 @@ BalloonInflate(Balloon *b, uint32 target) BalloonDecreaseRateAlloc(b); } /* release non-balloonable pages, fail */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(status); } @@ -978,7 +989,7 @@ BalloonInflate(Balloon *b, uint32 target) BalloonIncreaseRateAlloc(b, nAllocNoSleep + nAllocCanSleep); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } @@ -1000,7 +1011,8 @@ BalloonInflate(Balloon *b, uint32 target) */ static int -BalloonDeflate(Balloon *b, uint32 target) +BalloonDeflate(Balloon *b, // IN + uint32 target) // IN { int status, i; uint32 nFree = b->nPages - target; @@ -1010,7 +1022,8 @@ BalloonDeflate(Balloon *b, uint32 target) /* free pages to reach target */ for (i = 0; i < nFree; i++) { - if ((status = Balloon_FreePage(b, TRUE)) != BALLOON_SUCCESS) { + status = BalloonPageFree(b, TRUE); + if (status != BALLOON_SUCCESS) { if (BALLOON_RATE_ADAPT) { /* quickly decrease rate if error */ b->rateFree = MAX(b->rateFree / 2, BALLOON_RATE_FREE_MIN); @@ -1032,7 +1045,7 @@ BalloonDeflate(Balloon *b, uint32 target) /* *---------------------------------------------------------------------- * - * Balloon_AdjustSize -- + * BalloonAdjustSize -- * * Attempts to allocate or deallocate physical pages in order * to reach desired "target" size for balloon "b". @@ -1047,7 +1060,8 @@ BalloonDeflate(Balloon *b, uint32 target) */ static int -Balloon_AdjustSize(Balloon *b, uint32 target) +BalloonAdjustSize(Balloon *b, // IN + uint32 target) // IN { /* done if already at target */ if (b->nPages == target) { @@ -1068,14 +1082,11 @@ Balloon_AdjustSize(Balloon *b, uint32 target) return(BALLOON_FAILURE); } -/* - * Backdoor Operations - */ /* *---------------------------------------------------------------------- * - * Balloon_MonitorStart -- + * BalloonMonitorStart -- * * Attempts to contact monitor via backdoor to begin operation. * @@ -1089,7 +1100,7 @@ Balloon_AdjustSize(Balloon *b, uint32 target) */ static int -Balloon_MonitorStart(Balloon *b) +BalloonMonitorStart(Balloon *b) // IN { uint32 status, target; Backdoor_proto bp; @@ -1118,7 +1129,7 @@ Balloon_MonitorStart(Balloon *b) /* *---------------------------------------------------------------------- * - * Balloon_MonitorGuestType -- + * BalloonMonitorGuestType -- * * Attempts to contact monitor and report guest OS identity. * @@ -1132,7 +1143,7 @@ Balloon_MonitorStart(Balloon *b) */ static int -Balloon_MonitorGuestType(Balloon *b) +BalloonMonitorGuestType(Balloon *b) // IN { uint32 status, target; BalloonGuest identity; @@ -1170,7 +1181,7 @@ Balloon_MonitorGuestType(Balloon *b) /* *---------------------------------------------------------------------- * - * Balloon_MonitorGetTarget -- + * BalloonMonitorGetTarget -- * * Attempts to contact monitor via backdoor to obtain desired * balloon size. @@ -1196,7 +1207,7 @@ Balloon_MonitorGuestType(Balloon *b) */ static int -Balloon_MonitorGetTarget(Balloon *b, // IN +BalloonMonitorGetTarget(Balloon *b, // IN uint32 *target) // OUT { Backdoor_proto bp; @@ -1241,7 +1252,7 @@ Balloon_MonitorGetTarget(Balloon *b, // IN /* *---------------------------------------------------------------------- * - * Balloon_MonitorLockPage -- + * BalloonMonitorLockPage -- * * Attempts to contact monitor and add PPN corresponding to * the page handle to set of "balloon locked" pages. @@ -1256,7 +1267,7 @@ Balloon_MonitorGetTarget(Balloon *b, // IN */ static int -Balloon_MonitorLockPage(Balloon *b, // IN +BalloonMonitorLockPage(Balloon *b, // IN PageHandle handle) // IN { unsigned long ppn; @@ -1297,10 +1308,11 @@ Balloon_MonitorLockPage(Balloon *b, // IN return status; } + /* *---------------------------------------------------------------------- * - * Balloon_MonitorUnlockPage -- + * BalloonMonitorUnlockPage -- * * Attempts to contact monitor and remove PPN corresponding to * the page handle from set of "balloon locked" pages. @@ -1313,8 +1325,9 @@ Balloon_MonitorLockPage(Balloon *b, // IN * *---------------------------------------------------------------------- */ + static int -Balloon_MonitorUnlockPage(Balloon *b, // IN +BalloonMonitorUnlockPage(Balloon *b, // IN PageHandle handle) // IN { unsigned long ppn; @@ -1401,6 +1414,7 @@ Balloon_ModuleInit(void) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -1432,7 +1446,7 @@ Balloon_ModuleCleanup(void) * Reset connection before deallocating memory to avoid potential for * additional spurious resets from guest touching deallocated pages. */ - Balloon_MonitorStart(b); + BalloonMonitorStart(b); Balloon_Deallocate(b); /* os-specific cleanup */ diff --git a/open-vm-tools/modules/linux/vmmemctl/os.c b/open-vm-tools/modules/linux/vmmemctl/os.c index a83dba68b..4ef965b31 100644 --- a/open-vm-tools/modules/linux/vmmemctl/os.c +++ b/open-vm-tools/modules/linux/vmmemctl/os.c @@ -26,8 +26,8 @@ * Compile-Time Options */ -#define OS_DISABLE_UNLOAD (0) -#define OS_DEBUG (1) +#define OS_DISABLE_UNLOAD 0 +#define OS_DEBUG 1 /* * Includes @@ -43,11 +43,11 @@ #include #include -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_FS #include #include #include -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_PROC_FS */ #include "compat_sched.h" @@ -538,9 +538,10 @@ OS_Yield(void) } -#ifdef CONFIG_PROC_FS -static int os_proc_show(struct seq_file *f, - void *data) +#ifdef CONFIG_PROC_FS +static int +os_proc_show(struct seq_file *f, // IN + void *data) // IN: Unused { os_status *s = &global_state.status; char *buf = NULL; @@ -573,19 +574,37 @@ static int os_proc_show(struct seq_file *f, } -static int os_proc_open(struct inode *inode, - struct file *file) +static int +os_proc_open(struct inode *inode, // IN: Unused + struct file *file) // IN { return single_open(file, os_proc_show, NULL); } +#endif /* CONFIG_PROC_FS */ -#endif +/* + *----------------------------------------------------------------------------- + * + * OS_Init -- + * + * Called at driver startup, initializes the balloon state and structures. + * + * XXX : this function should return a value to indicate success or failure + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ void -OS_Init(const char *name, - const char *name_verbose, - OSStatusHandler *handler) +OS_Init(const char *name, // IN + const char *nameVerbose, // IN + OSStatusHandler *handler) // IN { os_state *state = &global_state; static int initialized = 0; @@ -606,21 +625,37 @@ OS_Init(const char *name, /* initialize status state */ state->status.handler = handler; state->status.name = name; - state->status.name_verbose = name_verbose; + state->status.name_verbose = nameVerbose; -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_FS /* register procfs device */ global_proc_entry = create_proc_entry("vmmemctl", S_IFREG | S_IRUGO, NULL); if (global_proc_entry != NULL) { global_proc_entry->proc_fops = &global_proc_fops; } -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_PROC_FS */ /* log device load */ printk(KERN_INFO "%s initialized\n", state->status.name_verbose); } +/* + *----------------------------------------------------------------------------- + * + * OS_Cleanup -- + * + * Called when the driver is terminating, cleanup initialized structures. + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + void OS_Cleanup(void) { diff --git a/open-vm-tools/modules/linux/vmmemctl/vmballoon.c b/open-vm-tools/modules/linux/vmmemctl/vmballoon.c index 283e791a5..977a17aad 100644 --- a/open-vm-tools/modules/linux/vmmemctl/vmballoon.c +++ b/open-vm-tools/modules/linux/vmmemctl/vmballoon.c @@ -38,10 +38,10 @@ extern "C" { * Compile-Time Options */ -#define BALLOON_RATE_ADAPT (1) +#define BALLOON_RATE_ADAPT 1 -#define BALLOON_DEBUG (1) -#define BALLOON_DEBUG_VERBOSE (0) +#define BALLOON_DEBUG 1 +#define BALLOON_DEBUG_VERBOSE 0 #define BALLOON_STATS #define BALLOON_STATS_PROCFS @@ -53,7 +53,6 @@ extern "C" { #include "os.h" #include "backdoor.h" #include "backdoor_balloon.h" - #include "vmballoon.h" /* @@ -67,27 +66,27 @@ extern "C" { #define BALLOON_NAME "vmmemctl" #define BALLOON_NAME_VERBOSE "VMware memory control driver" -#define BALLOON_PROTOCOL_VERSION (2) +#define BALLOON_PROTOCOL_VERSION 2 -#define BALLOON_CHUNK_PAGES (1000) +#define BALLOON_CHUNK_PAGES 1000 -#define BALLOON_NOSLEEP_ALLOC_MAX (16384) +#define BALLOON_NOSLEEP_ALLOC_MAX 16384 -#define BALLOON_RATE_ALLOC_MIN (512) -#define BALLOON_RATE_ALLOC_MAX (2048) -#define BALLOON_RATE_ALLOC_INC (16) +#define BALLOON_RATE_ALLOC_MIN 512 +#define BALLOON_RATE_ALLOC_MAX 2048 +#define BALLOON_RATE_ALLOC_INC 16 -#define BALLOON_RATE_FREE_MIN (512) -#define BALLOON_RATE_FREE_MAX (16384) -#define BALLOON_RATE_FREE_INC (16) +#define BALLOON_RATE_FREE_MIN 512 +#define BALLOON_RATE_FREE_MAX 16384 +#define BALLOON_RATE_FREE_INC 16 -#define BALLOON_ERROR_PAGES (16) +#define BALLOON_ERROR_PAGES 16 /* * When guest is under memory pressure, use a reduced page allocation * rate for next several cycles. */ -#define SLOW_PAGE_ALLOCATION_CYCLES (4) +#define SLOW_PAGE_ALLOCATION_CYCLES 4 /* * Move it to bora/public/balloon_def.h later, if needed. Note that @@ -95,10 +94,10 @@ extern "C" { * distinguishing page allocation failures from monitor-backdoor errors. * We use value 1000 because all monitor-backdoor error codes are < 1000. */ -#define BALLOON_PAGE_ALLOC_FAILURE (1000) +#define BALLOON_PAGE_ALLOC_FAILURE 1000 // Maximum number of page allocations without yielding processor -#define BALLOON_ALLOC_YIELD_THRESHOLD (1024) +#define BALLOON_ALLOC_YIELD_THRESHOLD 1024 /* @@ -151,21 +150,22 @@ static Balloon globalBalloon; static Bool timerStarted; /* - * Forward Declarations + * Balloon operations */ - -static int Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType); -static int Balloon_FreePage(Balloon *b, int monitorUnlock); -static int Balloon_AdjustSize(Balloon *b, uint32 target); -static void Balloon_Reset(Balloon *b); - +static int BalloonPageAlloc(Balloon *b, BalloonPageAllocType allocType); +static int BalloonPageFree(Balloon *b, int monitorUnlock); +static int BalloonAdjustSize(Balloon *b, uint32 target); +static void BalloonReset(Balloon *b); static void BalloonTimerHandler(void *clientData); -static int Balloon_MonitorStart(Balloon *b); -static int Balloon_MonitorGuestType(Balloon *b); -static int Balloon_MonitorGetTarget(Balloon *b, uint32 *nPages); -static int Balloon_MonitorLockPage(Balloon *b, PageHandle handle); -static int Balloon_MonitorUnlockPage(Balloon *b, PageHandle handle); +/* + * Backdoor Operations + */ +static int BalloonMonitorStart(Balloon *b); +static int BalloonMonitorGuestType(Balloon *b); +static int BalloonMonitorGetTarget(Balloon *b, uint32 *nPages); +static int BalloonMonitorLockPage(Balloon *b, PageHandle handle); +static int BalloonMonitorUnlockPage(Balloon *b, PageHandle handle); /* * Macros @@ -217,10 +217,6 @@ static void OBJ ## _Remove(OBJ **head, OBJ *obj) \ GENERATE_LIST_INSERT(BalloonChunk); GENERATE_LIST_REMOVE(BalloonChunk); -/* - * Procfs Operations - */ - /* *---------------------------------------------------------------------- @@ -241,7 +237,7 @@ GENERATE_LIST_REMOVE(BalloonChunk); */ static int -BalloonProcRead(char *buf, // OUT +BalloonProcRead(char *buf, // OUT size_t size) // IN { int len = 0; @@ -297,10 +293,6 @@ BalloonProcRead(char *buf, // OUT return len; } -/* - * Utility Operations - */ - /* *---------------------------------------------------------------------- @@ -396,17 +388,14 @@ BalloonChunk_Create(void) * *---------------------------------------------------------------------- */ + static void -BalloonChunk_Destroy(BalloonChunk *chunk) +BalloonChunk_Destroy(BalloonChunk *chunk) // IN { /* reclaim storage */ OS_Free(chunk, sizeof *chunk); } -/* - * Balloon operations - */ - /* *---------------------------------------------------------------------- @@ -423,8 +412,9 @@ BalloonChunk_Destroy(BalloonChunk *chunk) * *---------------------------------------------------------------------- */ + static int -Balloon_Init(Balloon *b) +Balloon_Init(Balloon *b) // IN { /* clear state */ OS_MemZero(b, sizeof *b); @@ -439,6 +429,7 @@ Balloon_Init(Balloon *b) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -454,14 +445,15 @@ Balloon_Init(Balloon *b) * *---------------------------------------------------------------------- */ + static void -Balloon_Deallocate(Balloon *b) +Balloon_Deallocate(Balloon *b) // IN { unsigned int cnt = 0; /* free all pages, skipping monitor unlock */ while (b->nChunks > 0) { - (void) Balloon_FreePage(b, FALSE); + (void) BalloonPageFree(b, FALSE); if (++cnt >= b->rateFree) { cnt = 0; OS_Yield(); @@ -469,10 +461,11 @@ Balloon_Deallocate(Balloon *b) } } + /* *---------------------------------------------------------------------- * - * Balloon_Reset -- + * BalloonReset -- * * Resets balloon "b" to empty state. Frees all allocated pages * and attempts to reset contact with the monitor. @@ -485,8 +478,9 @@ Balloon_Deallocate(Balloon *b) * *---------------------------------------------------------------------- */ + static void -Balloon_Reset(Balloon *b) +BalloonReset(Balloon *b) // IN { uint32 status; @@ -494,16 +488,17 @@ Balloon_Reset(Balloon *b) Balloon_Deallocate(b); /* send start command */ - status = Balloon_MonitorStart(b); + status = BalloonMonitorStart(b); if (status == BALLOON_SUCCESS) { /* clear flag */ b->resetFlag = 0; /* report guest type */ - (void) Balloon_MonitorGuestType(b); + (void) BalloonMonitorGuestType(b); } } + /* *---------------------------------------------------------------------- * @@ -522,8 +517,9 @@ Balloon_Reset(Balloon *b) * *---------------------------------------------------------------------- */ + static void -BalloonTimerHandler(void *clientData) +BalloonTimerHandler(void *clientData) // IN { Balloon *b = (Balloon *) clientData; uint32 target = 0; // Silence compiler warning. @@ -534,11 +530,11 @@ BalloonTimerHandler(void *clientData) /* reset, if specified */ if (b->resetFlag) { - Balloon_Reset(b); + BalloonReset(b); } /* contact monitor via backdoor */ - status = Balloon_MonitorGetTarget(b, &target); + status = BalloonMonitorGetTarget(b, &target); /* decrement slowPageAllocationCycles counter */ if (b->slowPageAllocationCycles > 0) { @@ -548,7 +544,7 @@ BalloonTimerHandler(void *clientData) if (status == BALLOON_SUCCESS) { /* update target, adjust size */ b->nPagesTarget = target; - (void) Balloon_AdjustSize(b, target); + (void) BalloonAdjustSize(b, target); } } @@ -556,7 +552,7 @@ BalloonTimerHandler(void *clientData) /* *---------------------------------------------------------------------- * - * Balloon_ErrorPagesAlloc -- + * BalloonErrorPagesAlloc -- * * Attempt to add "page" to list of non-balloonable pages * associated with "b". @@ -570,8 +566,10 @@ BalloonTimerHandler(void *clientData) * *---------------------------------------------------------------------- */ + static int -Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) +BalloonErrorPagesAlloc(Balloon *b, // IN + PageHandle page) // IN { /* fail if list already full */ if (b->errors.nextPage >= BALLOON_ERROR_PAGES) { @@ -588,7 +586,7 @@ Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) /* *---------------------------------------------------------------------- * - * Balloon_ErrorPagesFree -- + * BalloonErrorPagesFree -- * * Deallocates all pages on the list of non-balloonable pages * associated with "b". @@ -601,10 +599,11 @@ Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) * *---------------------------------------------------------------------- */ + static void -Balloon_ErrorPagesFree(Balloon *b) +BalloonErrorPagesFree(Balloon *b) // IN { - int i; + unsigned int i; /* free all non-balloonable "error" pages */ for (i = 0; i < b->errors.nextPage; i++) { @@ -615,10 +614,11 @@ Balloon_ErrorPagesFree(Balloon *b) b->errors.nextPage = 0; } + /* *---------------------------------------------------------------------- * - * Balloon_AllocPage -- + * BalloonPageAlloc -- * * Attempts to allocate a physical page, inflating balloon "b". * Informs monitor of PPN for allocated page via backdoor. @@ -631,8 +631,10 @@ Balloon_ErrorPagesFree(Balloon *b) * *---------------------------------------------------------------------- */ + static int -Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) +BalloonPageAlloc(Balloon *b, // IN + BalloonPageAllocType allocType) // IN { BalloonChunk *chunk; PageHandle page; @@ -677,11 +679,11 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) } /* inform monitor via backdoor */ - status = Balloon_MonitorLockPage(b, page); + status = BalloonMonitorLockPage(b, page); if (status != BALLOON_SUCCESS) { /* place on list of non-balloonable pages, retry allocation */ if ((status != BALLOON_ERROR_RESET) && - (Balloon_ErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) { + (BalloonErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) { goto retry; } @@ -700,10 +702,11 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * - * Balloon_FreePage -- + * BalloonPageFree -- * * Attempts to deallocate a physical page, deflating balloon "b". * Informs monitor of PPN for deallocated page via backdoor if @@ -717,8 +720,10 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) * *---------------------------------------------------------------------- */ + static int -Balloon_FreePage(Balloon *b, int monitorUnlock) +BalloonPageFree(Balloon *b, // IN + int monitorUnlock) // IN { BalloonChunk *chunk; PageHandle page; @@ -747,7 +752,7 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) /* inform monitor via backdoor */ if (monitorUnlock) { - status = Balloon_MonitorUnlockPage(b, page); + status = BalloonMonitorUnlockPage(b, page); if (status != BALLOON_SUCCESS) { /* reset next pointer, fail */ chunk->nextPage++; @@ -775,6 +780,7 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -792,14 +798,16 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) * *---------------------------------------------------------------------- */ + static void -BalloonDecreaseRateAlloc(Balloon *b) +BalloonDecreaseRateAlloc(Balloon *b) // IN { if (BALLOON_RATE_ADAPT) { b->rateAlloc = MAX(b->rateAlloc / 2, BALLOON_RATE_ALLOC_MIN); } } + /* *---------------------------------------------------------------------- * @@ -829,8 +837,10 @@ BalloonDecreaseRateAlloc(Balloon *b) * *---------------------------------------------------------------------- */ + static void -BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc) +BalloonIncreaseRateAlloc(Balloon *b, // IN + uint32 nAlloc) // IN { if (BALLOON_RATE_ADAPT) { if (nAlloc >= b->rateAlloc) { @@ -859,7 +869,8 @@ BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc) */ static int -BalloonInflate(Balloon *b, uint32 target) +BalloonInflate(Balloon *b, // IN + uint32 target) // IN { int status, allocations = 0; uint32 i, nAllocNoSleep, nAllocCanSleep; @@ -886,14 +897,14 @@ BalloonInflate(Balloon *b, uint32 target) for (i = 0; i < nAllocNoSleep; i++) { /* Try NOSLEEP allocation */ - status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_NOSLEEP); + status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_NOSLEEP); if (status != BALLOON_SUCCESS) { if (status != BALLOON_PAGE_ALLOC_FAILURE) { /* * Not a page allocation failure, so release non-balloonable * pages, and fail. */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(status); } /* @@ -918,7 +929,7 @@ BalloonInflate(Balloon *b, uint32 target) if (i == nAllocNoSleep) { BalloonIncreaseRateAlloc(b, nAllocNoSleep); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } else { /* @@ -929,7 +940,7 @@ BalloonInflate(Balloon *b, uint32 target) if (i > b->rateAlloc) { BalloonIncreaseRateAlloc(b, i); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } else { /* update successful NOSLEEP allocations, and proceed */ @@ -951,7 +962,7 @@ BalloonInflate(Balloon *b, uint32 target) for (i = 0; i < nAllocCanSleep; i++) { /* Try CANSLEEP allocation */ - status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_CANSLEEP); + status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_CANSLEEP); if(status != BALLOON_SUCCESS) { if (status == BALLOON_PAGE_ALLOC_FAILURE) { /* @@ -961,7 +972,7 @@ BalloonInflate(Balloon *b, uint32 target) BalloonDecreaseRateAlloc(b); } /* release non-balloonable pages, fail */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(status); } @@ -978,7 +989,7 @@ BalloonInflate(Balloon *b, uint32 target) BalloonIncreaseRateAlloc(b, nAllocNoSleep + nAllocCanSleep); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } @@ -1000,7 +1011,8 @@ BalloonInflate(Balloon *b, uint32 target) */ static int -BalloonDeflate(Balloon *b, uint32 target) +BalloonDeflate(Balloon *b, // IN + uint32 target) // IN { int status, i; uint32 nFree = b->nPages - target; @@ -1010,7 +1022,8 @@ BalloonDeflate(Balloon *b, uint32 target) /* free pages to reach target */ for (i = 0; i < nFree; i++) { - if ((status = Balloon_FreePage(b, TRUE)) != BALLOON_SUCCESS) { + status = BalloonPageFree(b, TRUE); + if (status != BALLOON_SUCCESS) { if (BALLOON_RATE_ADAPT) { /* quickly decrease rate if error */ b->rateFree = MAX(b->rateFree / 2, BALLOON_RATE_FREE_MIN); @@ -1032,7 +1045,7 @@ BalloonDeflate(Balloon *b, uint32 target) /* *---------------------------------------------------------------------- * - * Balloon_AdjustSize -- + * BalloonAdjustSize -- * * Attempts to allocate or deallocate physical pages in order * to reach desired "target" size for balloon "b". @@ -1047,7 +1060,8 @@ BalloonDeflate(Balloon *b, uint32 target) */ static int -Balloon_AdjustSize(Balloon *b, uint32 target) +BalloonAdjustSize(Balloon *b, // IN + uint32 target) // IN { /* done if already at target */ if (b->nPages == target) { @@ -1068,14 +1082,11 @@ Balloon_AdjustSize(Balloon *b, uint32 target) return(BALLOON_FAILURE); } -/* - * Backdoor Operations - */ /* *---------------------------------------------------------------------- * - * Balloon_MonitorStart -- + * BalloonMonitorStart -- * * Attempts to contact monitor via backdoor to begin operation. * @@ -1089,7 +1100,7 @@ Balloon_AdjustSize(Balloon *b, uint32 target) */ static int -Balloon_MonitorStart(Balloon *b) +BalloonMonitorStart(Balloon *b) // IN { uint32 status, target; Backdoor_proto bp; @@ -1118,7 +1129,7 @@ Balloon_MonitorStart(Balloon *b) /* *---------------------------------------------------------------------- * - * Balloon_MonitorGuestType -- + * BalloonMonitorGuestType -- * * Attempts to contact monitor and report guest OS identity. * @@ -1132,7 +1143,7 @@ Balloon_MonitorStart(Balloon *b) */ static int -Balloon_MonitorGuestType(Balloon *b) +BalloonMonitorGuestType(Balloon *b) // IN { uint32 status, target; BalloonGuest identity; @@ -1170,7 +1181,7 @@ Balloon_MonitorGuestType(Balloon *b) /* *---------------------------------------------------------------------- * - * Balloon_MonitorGetTarget -- + * BalloonMonitorGetTarget -- * * Attempts to contact monitor via backdoor to obtain desired * balloon size. @@ -1196,7 +1207,7 @@ Balloon_MonitorGuestType(Balloon *b) */ static int -Balloon_MonitorGetTarget(Balloon *b, // IN +BalloonMonitorGetTarget(Balloon *b, // IN uint32 *target) // OUT { Backdoor_proto bp; @@ -1241,7 +1252,7 @@ Balloon_MonitorGetTarget(Balloon *b, // IN /* *---------------------------------------------------------------------- * - * Balloon_MonitorLockPage -- + * BalloonMonitorLockPage -- * * Attempts to contact monitor and add PPN corresponding to * the page handle to set of "balloon locked" pages. @@ -1256,7 +1267,7 @@ Balloon_MonitorGetTarget(Balloon *b, // IN */ static int -Balloon_MonitorLockPage(Balloon *b, // IN +BalloonMonitorLockPage(Balloon *b, // IN PageHandle handle) // IN { unsigned long ppn; @@ -1297,10 +1308,11 @@ Balloon_MonitorLockPage(Balloon *b, // IN return status; } + /* *---------------------------------------------------------------------- * - * Balloon_MonitorUnlockPage -- + * BalloonMonitorUnlockPage -- * * Attempts to contact monitor and remove PPN corresponding to * the page handle from set of "balloon locked" pages. @@ -1313,8 +1325,9 @@ Balloon_MonitorLockPage(Balloon *b, // IN * *---------------------------------------------------------------------- */ + static int -Balloon_MonitorUnlockPage(Balloon *b, // IN +BalloonMonitorUnlockPage(Balloon *b, // IN PageHandle handle) // IN { unsigned long ppn; @@ -1401,6 +1414,7 @@ Balloon_ModuleInit(void) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -1432,7 +1446,7 @@ Balloon_ModuleCleanup(void) * Reset connection before deallocating memory to avoid potential for * additional spurious resets from guest touching deallocated pages. */ - Balloon_MonitorStart(b); + BalloonMonitorStart(b); Balloon_Deallocate(b); /* os-specific cleanup */ diff --git a/open-vm-tools/modules/solaris/vmmemctl/os.c b/open-vm-tools/modules/solaris/vmmemctl/os.c index a39b82976..f93582d50 100644 --- a/open-vm-tools/modules/solaris/vmmemctl/os.c +++ b/open-vm-tools/modules/solaris/vmmemctl/os.c @@ -20,9 +20,6 @@ * Wrappers for Solaris system functions required by "vmmemctl". */ -/* - * Includes - */ #include #include #include @@ -58,7 +55,7 @@ extern void memscrub_disable(void); * Constants */ -#define ONE_SECOND_IN_MICROSECONDS 1000000 +#define ONE_SECOND_IN_MICROSECONDS 1000000 /* * Types @@ -440,11 +437,26 @@ OS_ReservedPageFree(PageHandle handle) // IN: A valid page handle /* - * Worker thread that periodically calls the timer handler. This is - * executed by a user context thread so that it can block waiting for - * memory without fear of deadlock. + *----------------------------------------------------------------------------- + * + * os_worker -- + * + * Worker thread that periodically calls the timer handler. This is + * executed by a user context thread so that it can block waiting for + * memory without fear of deadlock. + * + * Results: + * On success: 0 + * On failure: error code + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- */ -static int os_worker(void) + +static int +os_worker(void) { os_timer *t = &global_state.timer; clock_t timeout; @@ -544,7 +556,9 @@ OS_TimerStop(void) mutex_exit(&t->lock); } -static void os_timer_cleanup(void) + +static void +os_timer_cleanup(void) { os_timer *timer = &global_state.timer; @@ -575,9 +589,29 @@ OS_Yield(void) /* Do nothing. */ } -void OS_Init(const char *name, - const char *name_verbose, - OSStatusHandler *handler) + +/* + *----------------------------------------------------------------------------- + * + * OS_Init -- + * + * Called at driver startup, initializes the balloon state and structures. + * + * XXX : this function should return a value to indicate success or failure + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +OS_Init(const char *name, // IN + const char *nameVerbose, // IN + OSStatusHandler *handler) // IN { os_state *state = &global_state; static int initialized = 0; @@ -593,7 +627,7 @@ void OS_Init(const char *name, state->kstats = BalloonKstatCreate(); state->id_space = id_space_create("vmmemctl", 0, INT_MAX); state->name = name; - state->name_verbose = name_verbose; + state->name_verbose = nameVerbose; /* disable memscrubber */ #if defined(SOL9) @@ -603,10 +637,28 @@ void OS_Init(const char *name, #endif /* log device load */ - cmn_err(CE_CONT, "!%s initialized\n", name_verbose); + cmn_err(CE_CONT, "!%s initialized\n", nameVerbose); } -void OS_Cleanup(void) + +/* + *----------------------------------------------------------------------------- + * + * OS_Cleanup -- + * + * Called when the driver is terminating, cleanup initialized structures. + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +OS_Cleanup(void) { os_state *state = &global_state; @@ -622,7 +674,11 @@ void OS_Cleanup(void) /* * Device configuration entry points */ -static int vmmemctl_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) + + +static int +vmmemctl_attach(dev_info_t *dip, // IN + ddi_attach_cmd_t cmd) // IN { switch (cmd) { case DDI_ATTACH: @@ -638,7 +694,10 @@ static int vmmemctl_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) } } -static int vmmemctl_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) + +static int +vmmemctl_detach(dev_info_t *dip, // IN + ddi_detach_cmd_t cmd) // IN { switch (cmd) { case DDI_DETACH: @@ -650,13 +709,33 @@ static int vmmemctl_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) } } + /* - * Commands used by the user level daemon to control the driver. - * Since the daemon is single threaded, we use a simple monitor to - * make sure that only one thread is executing here at a time. + *----------------------------------------------------------------------------- + * + * vmmemctl_ioctl -- + * + * Commands used by the user level daemon to control the driver. + * Since the daemon is single threaded, we use a simple monitor to + * make sure that only one thread is executing here at a time. + * + * Results: + * On success: 0 + * On failure: error code + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- */ -static int vmmemctl_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, - cred_t *cred, int *rvalp) + +static int +vmmemctl_ioctl(dev_t dev, // IN: Unused + int cmd, // IN + intptr_t arg, // IN: Unused + int mode, // IN: Unused + cred_t *cred, // IN + int *rvalp) // IN: Unused { int error = 0; static int busy = 0; /* set when a thread is in this function */ @@ -741,7 +820,9 @@ static struct modlinkage vmmodlinkage = { {&vmmodldrv, NULL} }; -int _init(void) + +int +_init(void) { int error; @@ -755,12 +836,16 @@ int _init(void) return error; } -int _info(struct modinfo *modinfop) + +int +_info(struct modinfo *modinfop) // IN { return mod_info(&vmmodlinkage, modinfop); } -int _fini(void) + +int +_fini(void) { int error; diff --git a/open-vm-tools/modules/solaris/vmmemctl/vmballoon.c b/open-vm-tools/modules/solaris/vmmemctl/vmballoon.c index d74ab2024..2080e7b95 100644 --- a/open-vm-tools/modules/solaris/vmmemctl/vmballoon.c +++ b/open-vm-tools/modules/solaris/vmmemctl/vmballoon.c @@ -36,10 +36,10 @@ extern "C" { * Compile-Time Options */ -#define BALLOON_RATE_ADAPT (1) +#define BALLOON_RATE_ADAPT 1 -#define BALLOON_DEBUG (1) -#define BALLOON_DEBUG_VERBOSE (0) +#define BALLOON_DEBUG 1 +#define BALLOON_DEBUG_VERBOSE 0 #define BALLOON_STATS #define BALLOON_STATS_PROCFS @@ -51,7 +51,6 @@ extern "C" { #include "os.h" #include "backdoor.h" #include "backdoor_balloon.h" - #include "vmballoon.h" /* @@ -65,27 +64,27 @@ extern "C" { #define BALLOON_NAME "vmmemctl" #define BALLOON_NAME_VERBOSE "VMware memory control driver" -#define BALLOON_PROTOCOL_VERSION (2) +#define BALLOON_PROTOCOL_VERSION 2 -#define BALLOON_CHUNK_PAGES (1000) +#define BALLOON_CHUNK_PAGES 1000 -#define BALLOON_NOSLEEP_ALLOC_MAX (16384) +#define BALLOON_NOSLEEP_ALLOC_MAX 16384 -#define BALLOON_RATE_ALLOC_MIN (512) -#define BALLOON_RATE_ALLOC_MAX (2048) -#define BALLOON_RATE_ALLOC_INC (16) +#define BALLOON_RATE_ALLOC_MIN 512 +#define BALLOON_RATE_ALLOC_MAX 2048 +#define BALLOON_RATE_ALLOC_INC 16 -#define BALLOON_RATE_FREE_MIN (512) -#define BALLOON_RATE_FREE_MAX (16384) -#define BALLOON_RATE_FREE_INC (16) +#define BALLOON_RATE_FREE_MIN 512 +#define BALLOON_RATE_FREE_MAX 16384 +#define BALLOON_RATE_FREE_INC 16 -#define BALLOON_ERROR_PAGES (16) +#define BALLOON_ERROR_PAGES 16 /* * When guest is under memory pressure, use a reduced page allocation * rate for next several cycles. */ -#define SLOW_PAGE_ALLOCATION_CYCLES (4) +#define SLOW_PAGE_ALLOCATION_CYCLES 4 /* * Move it to bora/public/balloon_def.h later, if needed. Note that @@ -93,10 +92,10 @@ extern "C" { * distinguishing page allocation failures from monitor-backdoor errors. * We use value 1000 because all monitor-backdoor error codes are < 1000. */ -#define BALLOON_PAGE_ALLOC_FAILURE (1000) +#define BALLOON_PAGE_ALLOC_FAILURE 1000 // Maximum number of page allocations without yielding processor -#define BALLOON_ALLOC_YIELD_THRESHOLD (1024) +#define BALLOON_ALLOC_YIELD_THRESHOLD 1024 /* @@ -149,21 +148,22 @@ static Balloon globalBalloon; static Bool timerStarted; /* - * Forward Declarations + * Balloon operations */ - -static int Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType); -static int Balloon_FreePage(Balloon *b, int monitorUnlock); -static int Balloon_AdjustSize(Balloon *b, uint32 target); -static void Balloon_Reset(Balloon *b); - +static int BalloonPageAlloc(Balloon *b, BalloonPageAllocType allocType); +static int BalloonPageFree(Balloon *b, int monitorUnlock); +static int BalloonAdjustSize(Balloon *b, uint32 target); +static void BalloonReset(Balloon *b); static void BalloonTimerHandler(void *clientData); -static int Balloon_MonitorStart(Balloon *b); -static int Balloon_MonitorGuestType(Balloon *b); -static int Balloon_MonitorGetTarget(Balloon *b, uint32 *nPages); -static int Balloon_MonitorLockPage(Balloon *b, PageHandle handle); -static int Balloon_MonitorUnlockPage(Balloon *b, PageHandle handle); +/* + * Backdoor Operations + */ +static int BalloonMonitorStart(Balloon *b); +static int BalloonMonitorGuestType(Balloon *b); +static int BalloonMonitorGetTarget(Balloon *b, uint32 *nPages); +static int BalloonMonitorLockPage(Balloon *b, PageHandle handle); +static int BalloonMonitorUnlockPage(Balloon *b, PageHandle handle); /* * Macros @@ -215,10 +215,6 @@ static void OBJ ## _Remove(OBJ **head, OBJ *obj) \ GENERATE_LIST_INSERT(BalloonChunk); GENERATE_LIST_REMOVE(BalloonChunk); -/* - * Procfs Operations - */ - /* *---------------------------------------------------------------------- @@ -239,7 +235,7 @@ GENERATE_LIST_REMOVE(BalloonChunk); */ static int -BalloonProcRead(char *buf, // OUT +BalloonProcRead(char *buf, // OUT size_t size) // IN { int len = 0; @@ -295,10 +291,6 @@ BalloonProcRead(char *buf, // OUT return len; } -/* - * Utility Operations - */ - /* *---------------------------------------------------------------------- @@ -394,17 +386,14 @@ BalloonChunk_Create(void) * *---------------------------------------------------------------------- */ + static void -BalloonChunk_Destroy(BalloonChunk *chunk) +BalloonChunk_Destroy(BalloonChunk *chunk) // IN { /* reclaim storage */ OS_Free(chunk, sizeof *chunk); } -/* - * Balloon operations - */ - /* *---------------------------------------------------------------------- @@ -421,8 +410,9 @@ BalloonChunk_Destroy(BalloonChunk *chunk) * *---------------------------------------------------------------------- */ + static int -Balloon_Init(Balloon *b) +Balloon_Init(Balloon *b) // IN { /* clear state */ OS_MemZero(b, sizeof *b); @@ -437,6 +427,7 @@ Balloon_Init(Balloon *b) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -452,14 +443,15 @@ Balloon_Init(Balloon *b) * *---------------------------------------------------------------------- */ + static void -Balloon_Deallocate(Balloon *b) +Balloon_Deallocate(Balloon *b) // IN { unsigned int cnt = 0; /* free all pages, skipping monitor unlock */ while (b->nChunks > 0) { - (void) Balloon_FreePage(b, FALSE); + (void) BalloonPageFree(b, FALSE); if (++cnt >= b->rateFree) { cnt = 0; OS_Yield(); @@ -467,10 +459,11 @@ Balloon_Deallocate(Balloon *b) } } + /* *---------------------------------------------------------------------- * - * Balloon_Reset -- + * BalloonReset -- * * Resets balloon "b" to empty state. Frees all allocated pages * and attempts to reset contact with the monitor. @@ -483,8 +476,9 @@ Balloon_Deallocate(Balloon *b) * *---------------------------------------------------------------------- */ + static void -Balloon_Reset(Balloon *b) +BalloonReset(Balloon *b) // IN { uint32 status; @@ -492,16 +486,17 @@ Balloon_Reset(Balloon *b) Balloon_Deallocate(b); /* send start command */ - status = Balloon_MonitorStart(b); + status = BalloonMonitorStart(b); if (status == BALLOON_SUCCESS) { /* clear flag */ b->resetFlag = 0; /* report guest type */ - (void) Balloon_MonitorGuestType(b); + (void) BalloonMonitorGuestType(b); } } + /* *---------------------------------------------------------------------- * @@ -520,8 +515,9 @@ Balloon_Reset(Balloon *b) * *---------------------------------------------------------------------- */ + static void -BalloonTimerHandler(void *clientData) +BalloonTimerHandler(void *clientData) // IN { Balloon *b = (Balloon *) clientData; uint32 target = 0; // Silence compiler warning. @@ -532,11 +528,11 @@ BalloonTimerHandler(void *clientData) /* reset, if specified */ if (b->resetFlag) { - Balloon_Reset(b); + BalloonReset(b); } /* contact monitor via backdoor */ - status = Balloon_MonitorGetTarget(b, &target); + status = BalloonMonitorGetTarget(b, &target); /* decrement slowPageAllocationCycles counter */ if (b->slowPageAllocationCycles > 0) { @@ -546,7 +542,7 @@ BalloonTimerHandler(void *clientData) if (status == BALLOON_SUCCESS) { /* update target, adjust size */ b->nPagesTarget = target; - (void) Balloon_AdjustSize(b, target); + (void) BalloonAdjustSize(b, target); } } @@ -554,7 +550,7 @@ BalloonTimerHandler(void *clientData) /* *---------------------------------------------------------------------- * - * Balloon_ErrorPagesAlloc -- + * BalloonErrorPagesAlloc -- * * Attempt to add "page" to list of non-balloonable pages * associated with "b". @@ -568,8 +564,10 @@ BalloonTimerHandler(void *clientData) * *---------------------------------------------------------------------- */ + static int -Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) +BalloonErrorPagesAlloc(Balloon *b, // IN + PageHandle page) // IN { /* fail if list already full */ if (b->errors.nextPage >= BALLOON_ERROR_PAGES) { @@ -586,7 +584,7 @@ Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) /* *---------------------------------------------------------------------- * - * Balloon_ErrorPagesFree -- + * BalloonErrorPagesFree -- * * Deallocates all pages on the list of non-balloonable pages * associated with "b". @@ -599,10 +597,11 @@ Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page) * *---------------------------------------------------------------------- */ + static void -Balloon_ErrorPagesFree(Balloon *b) +BalloonErrorPagesFree(Balloon *b) // IN { - int i; + unsigned int i; /* free all non-balloonable "error" pages */ for (i = 0; i < b->errors.nextPage; i++) { @@ -613,10 +612,11 @@ Balloon_ErrorPagesFree(Balloon *b) b->errors.nextPage = 0; } + /* *---------------------------------------------------------------------- * - * Balloon_AllocPage -- + * BalloonPageAlloc -- * * Attempts to allocate a physical page, inflating balloon "b". * Informs monitor of PPN for allocated page via backdoor. @@ -629,8 +629,10 @@ Balloon_ErrorPagesFree(Balloon *b) * *---------------------------------------------------------------------- */ + static int -Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) +BalloonPageAlloc(Balloon *b, // IN + BalloonPageAllocType allocType) // IN { BalloonChunk *chunk; PageHandle page; @@ -675,11 +677,11 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) } /* inform monitor via backdoor */ - status = Balloon_MonitorLockPage(b, page); + status = BalloonMonitorLockPage(b, page); if (status != BALLOON_SUCCESS) { /* place on list of non-balloonable pages, retry allocation */ if ((status != BALLOON_ERROR_RESET) && - (Balloon_ErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) { + (BalloonErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) { goto retry; } @@ -698,10 +700,11 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * - * Balloon_FreePage -- + * BalloonPageFree -- * * Attempts to deallocate a physical page, deflating balloon "b". * Informs monitor of PPN for deallocated page via backdoor if @@ -715,8 +718,10 @@ Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType) * *---------------------------------------------------------------------- */ + static int -Balloon_FreePage(Balloon *b, int monitorUnlock) +BalloonPageFree(Balloon *b, // IN + int monitorUnlock) // IN { BalloonChunk *chunk; PageHandle page; @@ -745,7 +750,7 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) /* inform monitor via backdoor */ if (monitorUnlock) { - status = Balloon_MonitorUnlockPage(b, page); + status = BalloonMonitorUnlockPage(b, page); if (status != BALLOON_SUCCESS) { /* reset next pointer, fail */ chunk->nextPage++; @@ -773,6 +778,7 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -790,14 +796,16 @@ Balloon_FreePage(Balloon *b, int monitorUnlock) * *---------------------------------------------------------------------- */ + static void -BalloonDecreaseRateAlloc(Balloon *b) +BalloonDecreaseRateAlloc(Balloon *b) // IN { if (BALLOON_RATE_ADAPT) { b->rateAlloc = MAX(b->rateAlloc / 2, BALLOON_RATE_ALLOC_MIN); } } + /* *---------------------------------------------------------------------- * @@ -827,8 +835,10 @@ BalloonDecreaseRateAlloc(Balloon *b) * *---------------------------------------------------------------------- */ + static void -BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc) +BalloonIncreaseRateAlloc(Balloon *b, // IN + uint32 nAlloc) // IN { if (BALLOON_RATE_ADAPT) { if (nAlloc >= b->rateAlloc) { @@ -857,7 +867,8 @@ BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc) */ static int -BalloonInflate(Balloon *b, uint32 target) +BalloonInflate(Balloon *b, // IN + uint32 target) // IN { int status, allocations = 0; uint32 i, nAllocNoSleep, nAllocCanSleep; @@ -884,14 +895,14 @@ BalloonInflate(Balloon *b, uint32 target) for (i = 0; i < nAllocNoSleep; i++) { /* Try NOSLEEP allocation */ - status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_NOSLEEP); + status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_NOSLEEP); if (status != BALLOON_SUCCESS) { if (status != BALLOON_PAGE_ALLOC_FAILURE) { /* * Not a page allocation failure, so release non-balloonable * pages, and fail. */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(status); } /* @@ -916,7 +927,7 @@ BalloonInflate(Balloon *b, uint32 target) if (i == nAllocNoSleep) { BalloonIncreaseRateAlloc(b, nAllocNoSleep); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } else { /* @@ -927,7 +938,7 @@ BalloonInflate(Balloon *b, uint32 target) if (i > b->rateAlloc) { BalloonIncreaseRateAlloc(b, i); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } else { /* update successful NOSLEEP allocations, and proceed */ @@ -949,7 +960,7 @@ BalloonInflate(Balloon *b, uint32 target) for (i = 0; i < nAllocCanSleep; i++) { /* Try CANSLEEP allocation */ - status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_CANSLEEP); + status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_CANSLEEP); if(status != BALLOON_SUCCESS) { if (status == BALLOON_PAGE_ALLOC_FAILURE) { /* @@ -959,7 +970,7 @@ BalloonInflate(Balloon *b, uint32 target) BalloonDecreaseRateAlloc(b); } /* release non-balloonable pages, fail */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(status); } @@ -976,7 +987,7 @@ BalloonInflate(Balloon *b, uint32 target) BalloonIncreaseRateAlloc(b, nAllocNoSleep + nAllocCanSleep); /* release non-balloonable pages, succeed */ - Balloon_ErrorPagesFree(b); + BalloonErrorPagesFree(b); return(BALLOON_SUCCESS); } @@ -998,7 +1009,8 @@ BalloonInflate(Balloon *b, uint32 target) */ static int -BalloonDeflate(Balloon *b, uint32 target) +BalloonDeflate(Balloon *b, // IN + uint32 target) // IN { int status, i; uint32 nFree = b->nPages - target; @@ -1008,7 +1020,8 @@ BalloonDeflate(Balloon *b, uint32 target) /* free pages to reach target */ for (i = 0; i < nFree; i++) { - if ((status = Balloon_FreePage(b, TRUE)) != BALLOON_SUCCESS) { + status = BalloonPageFree(b, TRUE); + if (status != BALLOON_SUCCESS) { if (BALLOON_RATE_ADAPT) { /* quickly decrease rate if error */ b->rateFree = MAX(b->rateFree / 2, BALLOON_RATE_FREE_MIN); @@ -1030,7 +1043,7 @@ BalloonDeflate(Balloon *b, uint32 target) /* *---------------------------------------------------------------------- * - * Balloon_AdjustSize -- + * BalloonAdjustSize -- * * Attempts to allocate or deallocate physical pages in order * to reach desired "target" size for balloon "b". @@ -1045,7 +1058,8 @@ BalloonDeflate(Balloon *b, uint32 target) */ static int -Balloon_AdjustSize(Balloon *b, uint32 target) +BalloonAdjustSize(Balloon *b, // IN + uint32 target) // IN { /* done if already at target */ if (b->nPages == target) { @@ -1066,14 +1080,11 @@ Balloon_AdjustSize(Balloon *b, uint32 target) return(BALLOON_FAILURE); } -/* - * Backdoor Operations - */ /* *---------------------------------------------------------------------- * - * Balloon_MonitorStart -- + * BalloonMonitorStart -- * * Attempts to contact monitor via backdoor to begin operation. * @@ -1087,7 +1098,7 @@ Balloon_AdjustSize(Balloon *b, uint32 target) */ static int -Balloon_MonitorStart(Balloon *b) +BalloonMonitorStart(Balloon *b) // IN { uint32 status, target; Backdoor_proto bp; @@ -1116,7 +1127,7 @@ Balloon_MonitorStart(Balloon *b) /* *---------------------------------------------------------------------- * - * Balloon_MonitorGuestType -- + * BalloonMonitorGuestType -- * * Attempts to contact monitor and report guest OS identity. * @@ -1130,7 +1141,7 @@ Balloon_MonitorStart(Balloon *b) */ static int -Balloon_MonitorGuestType(Balloon *b) +BalloonMonitorGuestType(Balloon *b) // IN { uint32 status, target; BalloonGuest identity; @@ -1168,7 +1179,7 @@ Balloon_MonitorGuestType(Balloon *b) /* *---------------------------------------------------------------------- * - * Balloon_MonitorGetTarget -- + * BalloonMonitorGetTarget -- * * Attempts to contact monitor via backdoor to obtain desired * balloon size. @@ -1194,7 +1205,7 @@ Balloon_MonitorGuestType(Balloon *b) */ static int -Balloon_MonitorGetTarget(Balloon *b, // IN +BalloonMonitorGetTarget(Balloon *b, // IN uint32 *target) // OUT { Backdoor_proto bp; @@ -1239,7 +1250,7 @@ Balloon_MonitorGetTarget(Balloon *b, // IN /* *---------------------------------------------------------------------- * - * Balloon_MonitorLockPage -- + * BalloonMonitorLockPage -- * * Attempts to contact monitor and add PPN corresponding to * the page handle to set of "balloon locked" pages. @@ -1254,7 +1265,7 @@ Balloon_MonitorGetTarget(Balloon *b, // IN */ static int -Balloon_MonitorLockPage(Balloon *b, // IN +BalloonMonitorLockPage(Balloon *b, // IN PageHandle handle) // IN { unsigned long ppn; @@ -1295,10 +1306,11 @@ Balloon_MonitorLockPage(Balloon *b, // IN return status; } + /* *---------------------------------------------------------------------- * - * Balloon_MonitorUnlockPage -- + * BalloonMonitorUnlockPage -- * * Attempts to contact monitor and remove PPN corresponding to * the page handle from set of "balloon locked" pages. @@ -1311,8 +1323,9 @@ Balloon_MonitorLockPage(Balloon *b, // IN * *---------------------------------------------------------------------- */ + static int -Balloon_MonitorUnlockPage(Balloon *b, // IN +BalloonMonitorUnlockPage(Balloon *b, // IN PageHandle handle) // IN { unsigned long ppn; @@ -1399,6 +1412,7 @@ Balloon_ModuleInit(void) return BALLOON_SUCCESS; } + /* *---------------------------------------------------------------------- * @@ -1430,7 +1444,7 @@ Balloon_ModuleCleanup(void) * Reset connection before deallocating memory to avoid potential for * additional spurious resets from guest touching deallocated pages. */ - Balloon_MonitorStart(b); + BalloonMonitorStart(b); Balloon_Deallocate(b); /* os-specific cleanup */