Added command line arg for overriding default heap pagesize.
authorSimon Gerber <simon.gerber@hp.com>
Mon, 4 Aug 2014 22:50:23 +0000 (15:50 -0700)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Mon, 4 May 2015 09:28:13 +0000 (11:28 +0200)
Also removed the vregion flags #define for the heap region as we can infer the
necessary flags from the alignment argument to morecore_init(). We now choose
the pagesize that matches the alignment or 4kB if no match found.

Signed-off-by: Simon Gerber <simon.gerber@hp.com>

lib/barrelfish/Hakefile
lib/barrelfish/init.c
lib/barrelfish/morecore.c

index 15a9470..3d005e8 100644 (file)
@@ -37,6 +37,7 @@
             getsrcs "multihop" = [ "multihop_chan.c" ]
             getsrcs _ = []
 
+      -- configure default morecore pagesize based on Config.hs
       morecore_pagesize "x86_64" = case Config.morecore_pagesize of
           "large" -> "LARGE_PAGE_SIZE"
           "huge"  -> "HUGE_PAGE_SIZE"
           _       -> "BASE_PAGE_SIZE"
       morecore_pagesize _ = "BASE_PAGE_SIZE"
 
-      morecore_vregion_flags "x86_64" = case Config.morecore_pagesize of
-          "large" -> "VREGION_FLAGS_LARGE"
-          "huge"  -> "VREGION_FLAGS_HUGE"
-          _       -> ""
-      morecore_vregion_flags "x86_32" = case Config.morecore_pagesize of
-          "large" -> "VREGION_FLAGS_LARGE"
-          _       -> ""
-      morecore_vregion_flags _ = ""
-
 
       -- sources specific to the architecture family
       archfam_srcs "x86_32"  = [ "arch/x86_32/debug.c" ,
                                               ("mem", ["rpcclient"]),
                                               ("octopus", ["rpcclient"]),
                                               ("spawn", ["rpcclient"])],
-                    addCFlags = [ "-DMORECORE_PAGESIZE="++(morecore_pagesize arch),
-                                  "-DMORECORE_VREGION_FLAGS="++(morecore_vregion_flags arch)
-                                ],
+                    addCFlags = [ "-DMORECORE_PAGESIZE="++(morecore_pagesize arch) ],
                     addIncludes = [ "include", "include" ./. arch_dir ],
                     addGeneratedDependencies = [ "/include/asmoffsets.h" ]
                   }
index 3131f92..dc60c4b 100644 (file)
@@ -199,7 +199,37 @@ errval_t barrelfish_init_onthread(struct spawn_domain_params *params)
         // in the base cn.
         err = morecore_init(BASE_PAGE_SIZE);
     } else {
-        err = morecore_init(MORECORE_PAGESIZE);
+        // grab pagesize config from argv if available
+        size_t morecore_pagesize = MORECORE_PAGESIZE;
+        int i = 1;
+        bool found = false;
+        for (; i < params->argc; i++) {
+            if (!found) {
+                if (!strncmp(params->argv[i], "morecore=", 9)) {
+                    morecore_pagesize = atoi(params->argv[i]+9);
+                    // check for valid page size
+                    switch (morecore_pagesize) {
+#ifdef __x86_64__
+                        case HUGE_PAGE_SIZE:
+#endif
+                        case BASE_PAGE_SIZE:
+                        case LARGE_PAGE_SIZE:
+                            break;
+                        default:
+                            morecore_pagesize = MORECORE_PAGESIZE;
+                    }
+                    found = true;
+                }
+            } else {
+                // found so move all other args one to the front
+                params->argv[i-1] = params->argv[i];
+            }
+        }
+        if (found) {
+            params->argc -= 1;
+        }
+
+        err = morecore_init(morecore_pagesize);
     }
     if (err_is_fail(err)) {
         return err_push(err, LIB_ERR_MORECORE_INIT);
index de81db2..1a9eba0 100644 (file)
@@ -115,8 +115,15 @@ errval_t morecore_init(size_t alignment)
 
     thread_mutex_init(&state->mutex);
 
+    // setup flags that match the alignment
+    vregion_flags_t morecore_flags = VREGION_FLAGS_READ_WRITE;
+#if __x86_64__
+    morecore_flags |= (alignment == HUGE_PAGE_SIZE ? VREGION_FLAGS_HUGE : 0);
+#endif
+    morecore_flags |= (alignment == LARGE_PAGE_SIZE ? VREGION_FLAGS_LARGE : 0);
+
     err = vspace_mmu_aware_init_aligned(&state->mmu_state, HEAP_REGION,
-            alignment, VREGION_FLAGS_READ_WRITE | MORECORE_VREGION_FLAGS);
+            alignment, morecore_flags);
     if (err_is_fail(err)) {
         return err_push(err, LIB_ERR_VSPACE_MMU_AWARE_INIT);
     }