aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/runtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/runtime.c')
-rw-r--r--libgo/runtime/runtime.c127
1 files changed, 38 insertions, 89 deletions
diff --git a/libgo/runtime/runtime.c b/libgo/runtime/runtime.c
index 8611596..c5716ab 100644
--- a/libgo/runtime/runtime.c
+++ b/libgo/runtime/runtime.c
@@ -4,13 +4,13 @@
#include <unistd.h>
+#include "config.h"
+
#include "runtime.h"
#include "array.h"
#include "go-panic.h"
#include "go-string.h"
-uint32 runtime_panicking;
-
int32
runtime_gotraceback(void)
{
@@ -22,84 +22,6 @@ runtime_gotraceback(void)
return runtime_atoi(p);
}
-static Lock paniclk;
-
-void
-runtime_startpanic(void)
-{
- M *m;
-
- m = runtime_m();
- if(m->dying) {
- runtime_printf("panic during panic\n");
- runtime_exit(3);
- }
- m->dying = 1;
- runtime_xadd(&runtime_panicking, 1);
- runtime_lock(&paniclk);
-}
-
-void
-runtime_dopanic(int32 unused __attribute__ ((unused)))
-{
- G* g;
- static bool didothers;
-
- g = runtime_g();
- if(g->sig != 0)
- runtime_printf("[signal %x code=%p addr=%p]\n",
- g->sig, (void*)(g->sigcode0), (void*)(g->sigcode1));
-
- if(runtime_gotraceback()){
- if(g != runtime_m()->g0) {
- runtime_printf("\n");
- runtime_goroutineheader(g);
- runtime_traceback();
- runtime_goroutinetrailer(g);
- }
- if(!didothers) {
- didothers = true;
- runtime_tracebackothers(g);
- }
- }
-
- runtime_unlock(&paniclk);
- if(runtime_xadd(&runtime_panicking, -1) != 0) {
- // Some other m is panicking too.
- // Let it print what it needs to print.
- // Wait forever without chewing up cpu.
- // It will exit when it's done.
- static Lock deadlock;
- runtime_lock(&deadlock);
- runtime_lock(&deadlock);
- }
-
- runtime_exit(2);
-}
-
-void
-runtime_throw(const char *s)
-{
- runtime_startpanic();
- runtime_printf("throw: %s\n", s);
- runtime_dopanic(0);
- *(int32*)0 = 0; // not reached
- runtime_exit(1); // even more not reached
-}
-
-void
-runtime_panicstring(const char *s)
-{
- Eface err;
-
- if(runtime_m()->gcing) {
- runtime_printf("panic: %s\n", s);
- runtime_throw("panic during gc");
- }
- runtime_newErrorString(runtime_gostringnocopy((const byte*)s), &err);
- runtime_panic(err);
-}
-
static int32 argc;
static byte** argv;
@@ -247,14 +169,41 @@ runtime_showframe(const unsigned char *s)
return traceback > 1 || (s != nil && __builtin_strchr((const char*)s, '.') != nil && __builtin_memcmp(s, "runtime.", 7) != 0);
}
-bool
-runtime_isInf(float64 f, int32 sign)
+static Lock ticksLock;
+static int64 ticks;
+
+int64
+runtime_tickspersecond(void)
+{
+ int64 res, t0, t1, c0, c1;
+
+ res = (int64)runtime_atomicload64((uint64*)&ticks);
+ if(res != 0)
+ return ticks;
+ runtime_lock(&ticksLock);
+ res = ticks;
+ if(res == 0) {
+ t0 = runtime_nanotime();
+ c0 = runtime_cputicks();
+ runtime_usleep(100*1000);
+ t1 = runtime_nanotime();
+ c1 = runtime_cputicks();
+ if(t1 == t0)
+ t1++;
+ res = (c1-c0)*1000*1000*1000/(t1-t0);
+ if(res == 0)
+ res++;
+ runtime_atomicstore64((uint64*)&ticks, res);
+ }
+ runtime_unlock(&ticksLock);
+ return res;
+}
+
+int64 runtime_pprof_runtime_cyclesPerSecond(void)
+ asm("runtime_pprof.runtime_cyclesPerSecond");
+
+int64
+runtime_pprof_runtime_cyclesPerSecond(void)
{
- if(!__builtin_isinf(f))
- return false;
- if(sign == 0)
- return true;
- if(sign > 0)
- return f > 0;
- return f < 0;
+ return runtime_tickspersecond();
}