Adds a tests/vmm subdirectory
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 15 Jun 2015 19:00:29 +0000 (15:00 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 18 Jun 2015 20:10:48 +0000 (16:10 -0400)
We're going to have a bunch of these; makes sense to compartmentalize them.

Btw, don't use the same name for a program in the subdirectory as in the main
tests/ directory.  They'll collide at fill-kfs time.

tests/Makefile
tests/hlt.s [deleted file]
tests/vmm/Makefrag [new file with mode: 0644]
tests/vmm/hlt.s [new file with mode: 0644]
tests/vmm/vmmcp.c [new file with mode: 0644]
tests/vmmcp.c [deleted file]

index 07be47a..8f3845c 100644 (file)
@@ -24,9 +24,10 @@ TESTS_EXECS_CPP  = $(patsubst $(TESTS_DIR)/%.cc, \
                               $(OBJDIR)/$(TESTS_DIR)/%, \
                               $(TESTS_SRCS_CPP))
 
-TESTS_EXECS = $(TESTS_EXECS_C) $(TESTS_EXECS_CPP)
-
 include $(TESTS_DIR)/openmp/Makefrag
+include $(TESTS_DIR)/vmm/Makefrag
+
+TESTS_EXECS = $(TESTS_EXECS_C) $(TESTS_EXECS_CPP)
 
 STATIC := $(findstring static,$(CFLAGS_TESTS))
 $(OBJDIR)/$(TESTS_DIR)/%: $(TESTS_LDDEPENDS_C)
diff --git a/tests/hlt.s b/tests/hlt.s
deleted file mode 100644 (file)
index 2c9fdf5..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-.=0x2000
-_start: hlt
-/* as -o hlt.o hlt.s && ld --nostdlib -o hlt hlt.o */
diff --git a/tests/vmm/Makefrag b/tests/vmm/Makefrag
new file mode 100644 (file)
index 0000000..4208f63
--- /dev/null
@@ -0,0 +1,25 @@
+VMM_TESTS_DIR = $(TESTS_DIR)/vmm
+
+VMM_TESTS_CFLAGS += $(CFLAGS_TESTS)
+
+ALL_VMM_TEST_FILES := $(wildcard $(VMM_TESTS_DIR)/*.c)
+
+VMM_TESTS_LDLIBS := $(TESTS_LDLIBS)
+
+VMM_TESTS_SRCS := $(ALL_VMM_TEST_FILES)
+
+VMM_TESTS_LDDEPENDS := $(VMM_TESTS_DIR)/%.c 
+
+TESTS_EXECS_C  += $(patsubst $(VMM_TESTS_DIR)/%.c, \
+                      $(OBJDIR)/$(VMM_TESTS_DIR)/%, \
+                      $(VMM_TESTS_SRCS))
+
+STATIC := $(findstring static,$(VMM_TESTS_CFLAGS))
+$(OBJDIR)/$(VMM_TESTS_DIR)/%: $(VMM_TESTS_LDDEPENDS)
+       @echo + cc [VMM_TESTS] $<
+       @mkdir -p $(@D)
+       $(Q)$(CC) $(VMM_TESTS_CFLAGS) -o $@ $< $(VMM_TESTS_LDLIBS)
+       @if [ "$(STATIC)" != "static" ]; then \
+               $(OBJDUMP) -S $@ > $@.asm; \
+               $(NM) -n $@ > $@.sym; \
+       fi
diff --git a/tests/vmm/hlt.s b/tests/vmm/hlt.s
new file mode 100644 (file)
index 0000000..2c9fdf5
--- /dev/null
@@ -0,0 +1,3 @@
+.=0x2000
+_start: hlt
+/* as -o hlt.o hlt.s && ld --nostdlib -o hlt hlt.o */
diff --git a/tests/vmm/vmmcp.c b/tests/vmm/vmmcp.c
new file mode 100644 (file)
index 0000000..f192a4d
--- /dev/null
@@ -0,0 +1,145 @@
+#include <stdio.h> 
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <parlib/arch/arch.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ros/syscall.h>
+#include <sys/mman.h>
+
+int *mmap_blob;
+unsigned long long stack[1024];
+volatile int shared = 0;
+int mcp = 1;
+#define V(x, t) (*((volatile t*)(x)))
+
+static void *fail(void*arg)
+{
+
+       *mmap_blob = 1337;
+       if (mcp)
+       while (V(&shared, int) < 31) {
+               if (! (V(&shared, int) & 1))
+                       V(&shared, int) = V(&shared, int) + 1;
+//             cpu_relax();
+       }
+       V(&shared, int) = 55;
+
+       __asm__ __volatile__("vmcall\n");
+       __asm__ __volatile__("mov $0xdeadbeef, %rbx; mov 5, %rax\n");   
+}
+
+unsigned long long *p512, *p1, *p2m;
+
+void *talk_thread(void *arg)
+{
+       printf("talk thread ..\n");
+       for(; V(&shared, int) < 32; ){
+               if (V(&shared, int) & 1) {
+                       printf("shared %d\n", V(&shared, int) );
+                       V(&shared, int) = V(&shared, int) + 1;
+               }
+               cpu_relax();
+       }
+       printf("All done, read %d\n", *mmap_blob);
+       return NULL;
+}
+
+pthread_t *my_threads;
+void **my_retvals;
+int nr_threads = 2;
+
+int main(int argc, char **argv)
+{
+       int nr_gpcs = 1;
+       int fd = open("#c/sysctl", O_RDWR), ret;
+       void * x;
+       static char cmd[512];
+       if (fd < 0) {
+               perror("#c/sysctl");
+               exit(1);
+       }
+       if (ros_syscall(SYS_setup_vmm, nr_gpcs, 0, 0, 0, 0, 0) != nr_gpcs) {
+               perror("Guest pcore setup failed");
+               exit(1);
+       }
+       /* blob that is faulted in from the EPT first.  we need this to be in low
+        * memory (not above the normal mmap_break), so the EPT can look it up.
+        * Note that we won't get 4096.  The min is 1MB now, and ld is there. */
+       mmap_blob = mmap((int*)4096, PGSIZE, PROT_READ | PROT_WRITE,
+                        MAP_ANONYMOUS, -1, 0);
+       if (mmap_blob == MAP_FAILED) {
+               perror("Unable to mmap");
+               exit(1);
+       }
+
+       mcp = 1; //argc - 1;
+       if (mcp) {
+               my_threads = malloc(sizeof(pthread_t) * nr_threads);
+               my_retvals = malloc(sizeof(void*) * nr_threads);
+               if (!(my_retvals && my_threads))
+                       perror("Init threads/malloc");
+
+               pthread_can_vcore_request(FALSE);       /* 2LS won't manage vcores */
+               pthread_need_tls(FALSE);
+               pthread_lib_init();                                     /* gives us one vcore */
+               vcore_request(nr_threads - 1);          /* ghetto incremental interface */
+               for (int i = 0; i < nr_threads; i++) {
+                       x = __procinfo.vcoremap;
+                       printf("%p\n", __procinfo.vcoremap);
+                       printf("Vcore %d mapped to pcore %d\n", i,
+                               __procinfo.vcoremap[i].pcoreid);
+               }
+       }
+
+       if (mcp) {
+               if (pthread_create(&my_threads[0], NULL, &talk_thread, NULL))
+                       perror("pth_create failed");
+//             if (pthread_create(&my_threads[1], NULL, &fail, NULL))
+//                     perror("pth_create failed");
+       }
+       printf("threads started\n");
+
+       if (0) for (int i = 0; i < nr_threads-1; i++) {
+               int ret;
+               if (pthread_join(my_threads[i], &my_retvals[i]))
+                       perror("pth_join failed");
+               printf("%d %d\n", i, ret);
+       }
+       
+
+       ret = syscall(33, 1);
+       if (ret < 0) {
+               perror("vm setup");
+               exit(1);
+       }
+       ret = posix_memalign((void **)&p512, 4096, 3*4096);
+       if (ret) {
+               perror("ptp alloc");
+               exit(1);
+       }
+       p1 = &p512[512];
+       p2m = &p512[1024];
+       p512[0] = (unsigned long long)p1 | 7;
+       p1[0] = /*0x87; */(unsigned long long)p2m | 7;
+       p2m[0] = 0x87;
+       p2m[1] = 0x200000 | 0x87;
+       p2m[2] = 0x400000 | 0x87;
+       p2m[3] = 0x600000 | 0x87;
+
+       printf("p512 %p p512[0] is 0x%lx p1 %p p1[0] is 0x%x\n", p512, p512[0], p1, p1[0]);
+       sprintf(cmd, "V 0x%x 0x%x 0x%x", (unsigned long long)fail, (unsigned long long) &stack[1024], (unsigned long long) p512);
+       printf("Writing command :%s:\n", cmd);
+       ret = write(fd, cmd, strlen(cmd));
+       if (ret != strlen(cmd)) {
+               perror(cmd);
+       }
+       printf("shared is %d, blob is %d\n", shared, *mmap_blob);
+
+       return 0;
+}
diff --git a/tests/vmmcp.c b/tests/vmmcp.c
deleted file mode 100644 (file)
index f192a4d..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <stdio.h> 
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <parlib/arch/arch.h>
-#include <unistd.h>
-#include <errno.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ros/syscall.h>
-#include <sys/mman.h>
-
-int *mmap_blob;
-unsigned long long stack[1024];
-volatile int shared = 0;
-int mcp = 1;
-#define V(x, t) (*((volatile t*)(x)))
-
-static void *fail(void*arg)
-{
-
-       *mmap_blob = 1337;
-       if (mcp)
-       while (V(&shared, int) < 31) {
-               if (! (V(&shared, int) & 1))
-                       V(&shared, int) = V(&shared, int) + 1;
-//             cpu_relax();
-       }
-       V(&shared, int) = 55;
-
-       __asm__ __volatile__("vmcall\n");
-       __asm__ __volatile__("mov $0xdeadbeef, %rbx; mov 5, %rax\n");   
-}
-
-unsigned long long *p512, *p1, *p2m;
-
-void *talk_thread(void *arg)
-{
-       printf("talk thread ..\n");
-       for(; V(&shared, int) < 32; ){
-               if (V(&shared, int) & 1) {
-                       printf("shared %d\n", V(&shared, int) );
-                       V(&shared, int) = V(&shared, int) + 1;
-               }
-               cpu_relax();
-       }
-       printf("All done, read %d\n", *mmap_blob);
-       return NULL;
-}
-
-pthread_t *my_threads;
-void **my_retvals;
-int nr_threads = 2;
-
-int main(int argc, char **argv)
-{
-       int nr_gpcs = 1;
-       int fd = open("#c/sysctl", O_RDWR), ret;
-       void * x;
-       static char cmd[512];
-       if (fd < 0) {
-               perror("#c/sysctl");
-               exit(1);
-       }
-       if (ros_syscall(SYS_setup_vmm, nr_gpcs, 0, 0, 0, 0, 0) != nr_gpcs) {
-               perror("Guest pcore setup failed");
-               exit(1);
-       }
-       /* blob that is faulted in from the EPT first.  we need this to be in low
-        * memory (not above the normal mmap_break), so the EPT can look it up.
-        * Note that we won't get 4096.  The min is 1MB now, and ld is there. */
-       mmap_blob = mmap((int*)4096, PGSIZE, PROT_READ | PROT_WRITE,
-                        MAP_ANONYMOUS, -1, 0);
-       if (mmap_blob == MAP_FAILED) {
-               perror("Unable to mmap");
-               exit(1);
-       }
-
-       mcp = 1; //argc - 1;
-       if (mcp) {
-               my_threads = malloc(sizeof(pthread_t) * nr_threads);
-               my_retvals = malloc(sizeof(void*) * nr_threads);
-               if (!(my_retvals && my_threads))
-                       perror("Init threads/malloc");
-
-               pthread_can_vcore_request(FALSE);       /* 2LS won't manage vcores */
-               pthread_need_tls(FALSE);
-               pthread_lib_init();                                     /* gives us one vcore */
-               vcore_request(nr_threads - 1);          /* ghetto incremental interface */
-               for (int i = 0; i < nr_threads; i++) {
-                       x = __procinfo.vcoremap;
-                       printf("%p\n", __procinfo.vcoremap);
-                       printf("Vcore %d mapped to pcore %d\n", i,
-                               __procinfo.vcoremap[i].pcoreid);
-               }
-       }
-
-       if (mcp) {
-               if (pthread_create(&my_threads[0], NULL, &talk_thread, NULL))
-                       perror("pth_create failed");
-//             if (pthread_create(&my_threads[1], NULL, &fail, NULL))
-//                     perror("pth_create failed");
-       }
-       printf("threads started\n");
-
-       if (0) for (int i = 0; i < nr_threads-1; i++) {
-               int ret;
-               if (pthread_join(my_threads[i], &my_retvals[i]))
-                       perror("pth_join failed");
-               printf("%d %d\n", i, ret);
-       }
-       
-
-       ret = syscall(33, 1);
-       if (ret < 0) {
-               perror("vm setup");
-               exit(1);
-       }
-       ret = posix_memalign((void **)&p512, 4096, 3*4096);
-       if (ret) {
-               perror("ptp alloc");
-               exit(1);
-       }
-       p1 = &p512[512];
-       p2m = &p512[1024];
-       p512[0] = (unsigned long long)p1 | 7;
-       p1[0] = /*0x87; */(unsigned long long)p2m | 7;
-       p2m[0] = 0x87;
-       p2m[1] = 0x200000 | 0x87;
-       p2m[2] = 0x400000 | 0x87;
-       p2m[3] = 0x600000 | 0x87;
-
-       printf("p512 %p p512[0] is 0x%lx p1 %p p1[0] is 0x%x\n", p512, p512[0], p1, p1[0]);
-       sprintf(cmd, "V 0x%x 0x%x 0x%x", (unsigned long long)fail, (unsigned long long) &stack[1024], (unsigned long long) p512);
-       printf("Writing command :%s:\n", cmd);
-       ret = write(fd, cmd, strlen(cmd));
-       if (ret != strlen(cmd)) {
-               perror(cmd);
-       }
-       printf("shared is %d, blob is %d\n", shared, *mmap_blob);
-
-       return 0;
-}