[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/LIBGO PATCH 05/11] Add patches to enable runtime



libgo uses backtracking but it leads to page faults. For the time being
it is disabled but it should be revisited in the future.

The second patch decreases the amount of memory maps, cause it was
exceeding 1G.

At last Go uses context switching to manage goroutines. This patch add
some changes to the way contexts are handled so they can be compatible
with threading in Unikraft.

Signed-off-by: Charalampos Mainas <Charalampos.Mainas@xxxxxxxxx>
---
 patches/0003-libgo-Disable-backtracing.patch  | 28 +++++++++
 ...004-libgo-Reduce-maximum-memory-size.patch | 27 +++++++++
 .../0005-libgo-Use-our-context-logic.patch    | 57 +++++++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100644 patches/0003-libgo-Disable-backtracing.patch
 create mode 100644 patches/0004-libgo-Reduce-maximum-memory-size.patch
 create mode 100644 patches/0005-libgo-Use-our-context-logic.patch

diff --git a/patches/0003-libgo-Disable-backtracing.patch 
b/patches/0003-libgo-Disable-backtracing.patch
new file mode 100644
index 0000000..5194363
--- /dev/null
+++ b/patches/0003-libgo-Disable-backtracing.patch
@@ -0,0 +1,28 @@
+From 173b07db3b85d565d650e9368132e311617ea3f1 Mon Sep 17 00:00:00 2001
+From: Costin Lupu <costin.lup@xxxxxxxxx>
+Date: Wed, 21 Aug 2019 17:03:25 +0300
+Subject: [PATCH 1/3] libgo: Disable backtracing
+
+Signed-off-by: Charalampos Mainas <charalampos.mainas@xxxxxxxxx>
+---
+ libgo/runtime/go-callers.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/libgo/runtime/go-callers.c b/libgo/runtime/go-callers.c
+index 0c1c60314..a80bc56f5 100644
+--- a/libgo/runtime/go-callers.c
++++ b/libgo/runtime/go-callers.c
+@@ -167,8 +167,8 @@ runtime_callers (int32 skip, Location *locbuf, int32 m, 
bool keep_thunks)
+   data.max = m;
+   data.keep_thunks = keep_thunks;
+   runtime_xadd (&runtime_in_callers, 1);
+-  backtrace_full (__go_get_backtrace_state (), 0, callback, error_callback,
+-                &data);
++//  backtrace_full (__go_get_backtrace_state (), 0, callback, error_callback,
++//              &data);
+   runtime_xadd (&runtime_in_callers, -1);
+   return data.index;
+ }
+-- 
+2.20.1
+
diff --git a/patches/0004-libgo-Reduce-maximum-memory-size.patch 
b/patches/0004-libgo-Reduce-maximum-memory-size.patch
new file mode 100644
index 0000000..7fbf4ea
--- /dev/null
+++ b/patches/0004-libgo-Reduce-maximum-memory-size.patch
@@ -0,0 +1,27 @@
+From caaef739ecf4e87b9994747cbe6c7e627c8678d9 Mon Sep 17 00:00:00 2001
+From: Costin Lupu <costin.lup@xxxxxxxxx>
+Date: Wed, 21 Aug 2019 17:03:49 +0300
+Subject: [PATCH 2/3] libgo: Reduce maximum memory size
+
+Signed-off-by: Charalampos Mainas <charalampos.mainas@xxxxxxxxx>
+---
+ libgo/runtime/malloc.goc | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/libgo/runtime/malloc.goc b/libgo/runtime/malloc.goc
+index 232210fc4..211b84748 100644
+--- a/libgo/runtime/malloc.goc
++++ b/libgo/runtime/malloc.goc
+@@ -448,7 +448,8 @@ runtime_mallocinit(void)
+               // but it hardly matters: e0 00 is not valid UTF-8 either.
+               //
+               // If this fails we fall back to the 32 bit memory mechanism
+-              arena_size = MaxMem;
++              //arena_size = MaxMem;
++              arena_size = 104857600;
+               bitmap_size = arena_size / (sizeof(void*)*8/4);
+               spans_size = arena_size / PageSize * 
sizeof(runtime_mheap.spans[0]);
+               spans_size = ROUND(spans_size, PageSize);
+-- 
+2.20.1
+
diff --git a/patches/0005-libgo-Use-our-context-logic.patch 
b/patches/0005-libgo-Use-our-context-logic.patch
new file mode 100644
index 0000000..239058f
--- /dev/null
+++ b/patches/0005-libgo-Use-our-context-logic.patch
@@ -0,0 +1,57 @@
+From 8e22dedf2df725d256235d9bd22fb97f290fd12d Mon Sep 17 00:00:00 2001
+From: Costin Lupu <costin.lup@xxxxxxxxx>
+Date: Wed, 21 Aug 2019 17:04:13 +0300
+Subject: [PATCH 3/3] libgo: Use our context logic
+
+Signed-off-by: Charalampos Mainas <charalampos.mainas@xxxxxxxxx>
+---
+ libgo/runtime/proc.c | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c
+index 06a9c2ad6..e8a43272e 100644
+--- a/libgo/runtime/proc.c
++++ b/libgo/runtime/proc.c
+@@ -43,6 +43,10 @@ extern void __splitstack_block_signals_context (void 
*context[10], int *,
+ 
+ #endif
+ 
++extern size_t get_stack_size();
++extern void makecontext1(ucontext_t *, void *, int);
++extern void *alloc_stack();
++
+ #ifndef PTHREAD_STACK_MIN
+ # define PTHREAD_STACK_MIN 8192
+ #endif
+@@ -831,7 +835,7 @@ makeGContext(G* gp, byte* sp, uintptr spsize) {
+       getcontext(uc);
+       uc->uc_stack.ss_sp = sp;
+       uc->uc_stack.ss_size = (size_t)spsize;
+-      makecontext(uc, kickoff, 0);
++      makecontext1(uc, kickoff, 0);
+ }
+ 
+ // Create a new m.  It will start off with a call to fn, or else the 
scheduler.
+@@ -1348,7 +1352,8 @@ runtime_malg(bool allocatestack, bool signalstack, 
byte** ret_stack, uintptr* re
+       }
+       newg = allocg();
+       if(allocatestack) {
+-              stacksize = StackMin;
++              //stacksize = StackMin;
++              stacksize = get_stack_size();
+               if(signalstack) {
+                       stacksize = 32 * 1024; // OS X wants >= 8K, GNU/Linux 
>= 2K
+ #ifdef SIGSTKSZ
+@@ -1372,7 +1377,8 @@ runtime_malg(bool allocatestack, bool signalstack, 
byte** ret_stack, uintptr* re
+                 // 32-bit mode, the Go allocation space is all of
+                 // memory anyhow.
+               if(sizeof(void*) == 8) {
+-                      void *p = runtime_SysAlloc(stacksize, 
&mstats()->other_sys);
++                      //void *p = runtime_SysAlloc(stacksize, 
&mstats()->other_sys);
++                      void *p = alloc_stack();
+                       if(p == nil)
+                               runtime_throw("runtime: cannot allocate memory 
for goroutine stack");
+                       *ret_stack = (byte*)p;
+-- 
+2.20.1
+
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.