From: Peter Dinda Date: Tue, 20 Aug 2013 23:25:18 +0000 (-0500) Subject: Made memory manager reset distinct from removal of memory X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=d1026ce50fd8b517ef69944eba5db7f838820b40;p=palacios.releases.git Made memory manager reset distinct from removal of memory --- diff --git a/linux_module/main.c b/linux_module/main.c index 425e08f..7ec627b 100644 --- a/linux_module/main.c +++ b/linux_module/main.c @@ -222,9 +222,13 @@ out_err: case V3_RESET_MEMORY: { DEBUG("Resetting memory\n"); if (palacios_deinit_mm() == -1) { - ERROR("Error resetting Palacios memory\n"); + ERROR("Error deiniting the Palacios memory manager\n"); return -EFAULT; } + if (palacios_init_mm()) { + ERROR("Error initing the Palacios memory manager\n"); + return -EFAULT; + } break; } diff --git a/linux_usr/Makefile b/linux_usr/Makefile index f586bb7..2d60e5a 100644 --- a/linux_usr/Makefile +++ b/linux_usr/Makefile @@ -11,7 +11,7 @@ STATIC = 0 # Executables that implement core functionality # BASE_EXECS = v3_mem \ - v3_mem_free \ + v3_mem_reset \ v3_create \ v3_create_bind \ v3_free \ @@ -194,7 +194,7 @@ v3_x0vncserver : else \ echo "In order to use v3_vncclient/server you must have" ; \ echo "previously built or received palacios/linux_usr/x0vncserver" ; \ - echo "To learn more about this, look in palacios/linux_usr/vnc"; \ + echo "To learn more about this, look in palacios/linux_usr/vnc"; \ fi; # diff --git a/linux_usr/v3_mem_free.c b/linux_usr/v3_mem_free.c deleted file mode 100644 index 16afaef..0000000 --- a/linux_usr/v3_mem_free.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "v3_ctrl.h" - -int main(void) -{ - FILE * fp; - char * filepath = "/proc/v3vee/v3-mem"; - char line[255]; - unsigned long base_addr = 0; - unsigned long long num_pages = 0; - unsigned long amount_allocated = 0; - unsigned long long block_size = 0; - int i = 0; - int v3_fd; - - fp = fopen(filepath, "r"); - if(fp == NULL) { - fprintf(stderr, "Could not open %s\n", filepath); - return -1; - } - memset(line, 0, 255); - fgets(line, 255, fp); - base_addr = strtoul(line, NULL, 16); - base_addr = base_addr / (1024*1024); - memset(line, 0, 255); - fgets(line, 255, fp); - num_pages = strtoull(line, NULL, 10); - amount_allocated = (num_pages*4096)/(1024*1024); - - fclose(fp); - - /* now get the block size */ - fp = fopen("/sys/devices/system/memory/block_size_bytes", "r"); - if(fp == NULL) { - fprintf(stderr, "Cannot lookup bytes per block size\n"); - return -1; - } - memset(line, 0, 255); - fgets(line, 255, fp); - block_size = strtoull(line, NULL, 16); - block_size = block_size / (1024*1024); //convert to MB - fclose(fp); - - /* turn base_addr into the region number */ - base_addr = base_addr / block_size; - - for(i=0;i< (amount_allocated / block_size); i++) { - char path[50]; - - memset(path, 0, 50); - sprintf(path,"/sys/devices/system/memory/memory%d/state", - base_addr); - fp = fopen(path, "w+"); - if(fp == NULL) { - fprintf(stderr, "Could not open %s\n", path); - return -1; - } - printf("Sending \"online\" to memory%d\n", base_addr); - fprintf(fp, "online"); - fclose(fp); - base_addr++; - } - - v3_fd = open(v3_dev, O_RDONLY); - if (v3_fd == -1) { - printf("Error opening V3Vee control device\n"); - return -1; - } - - ioctl(v3_fd, V3_RESET_MEMORY, NULL); - close(v3_fd); - - return 0; -} diff --git a/linux_usr/v3_mem_reset.c b/linux_usr/v3_mem_reset.c new file mode 100644 index 0000000..79ec364 --- /dev/null +++ b/linux_usr/v3_mem_reset.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include + +#include "v3_ctrl.h" + +int main(int argc, char *argv[]) +{ + int v3_fd; + + if (argc!=2 || strcmp(argv[1],"-f")) { + printf("usage: v3_mem_reset -f\n\n" + "This will deinit and then init the memory manager.\n\nYou probably do not want to do this.\n"); + return -1; + } + + + v3_fd = open("/dev/v3vee", O_RDONLY); + if (v3_fd == -1) { + printf("Error opening V3Vee control device\n"); + return -1; + } + + ioctl(v3_fd, V3_RESET_MEMORY, NULL); + close(v3_fd); + + return 0; +}