OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 #include "defs_GOOS_GOARCH.h" | 7 #include "defs_GOOS_GOARCH.h" |
8 #include "malloc.h" | 8 #include "malloc.h" |
9 #include "os_GOOS.h" | 9 #include "os_GOOS.h" |
10 #include "stack.h" | 10 #include "stack.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 { | 331 { |
332 m->id = runtime·sched.mcount++; | 332 m->id = runtime·sched.mcount++; |
333 m->fastrand = 0x49f6428aUL + m->id + runtime·cputicks(); | 333 m->fastrand = 0x49f6428aUL + m->id + runtime·cputicks(); |
334 m->stackalloc = runtime·malloc(sizeof(*m->stackalloc)); | 334 m->stackalloc = runtime·malloc(sizeof(*m->stackalloc)); |
335 runtime·FixAlloc_Init(m->stackalloc, FixedStack, runtime·SysAlloc, nil,
nil); | 335 runtime·FixAlloc_Init(m->stackalloc, FixedStack, runtime·SysAlloc, nil,
nil); |
336 | 336 |
337 if(m->mcache == nil) | 337 if(m->mcache == nil) |
338 m->mcache = runtime·allocmcache(); | 338 m->mcache = runtime·allocmcache(); |
339 | 339 |
340 runtime·callers(1, m->createstack, nelem(m->createstack)); | 340 runtime·callers(1, m->createstack, nelem(m->createstack)); |
341 » | 341 |
342 // Add to runtime·allm so garbage collector doesn't free m | 342 // Add to runtime·allm so garbage collector doesn't free m |
343 // when it is just in a register or thread-local storage. | 343 // when it is just in a register or thread-local storage. |
344 m->alllink = runtime·allm; | 344 m->alllink = runtime·allm; |
345 // runtime·NumCgoCall() iterates over allm w/o schedlock, | 345 // runtime·NumCgoCall() iterates over allm w/o schedlock, |
346 // so we need to publish it safely. | 346 // so we need to publish it safely. |
347 runtime·atomicstorep(&runtime·allm, m); | 347 runtime·atomicstorep(&runtime·allm, m); |
348 } | 348 } |
349 | 349 |
350 // Try to increment mcpu. Report whether succeeded. | 350 // Try to increment mcpu. Report whether succeeded. |
351 static bool | 351 static bool |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 runtime·mstart(void) | 721 runtime·mstart(void) |
722 { | 722 { |
723 if(g != m->g0) | 723 if(g != m->g0) |
724 runtime·throw("bad runtime·mstart"); | 724 runtime·throw("bad runtime·mstart"); |
725 | 725 |
726 // Record top of stack for use by mcall. | 726 // Record top of stack for use by mcall. |
727 // Once we call schedule we're never coming back, | 727 // Once we call schedule we're never coming back, |
728 // so other calls can reuse this stack space. | 728 // so other calls can reuse this stack space. |
729 runtime·gosave(&m->g0->sched); | 729 runtime·gosave(&m->g0->sched); |
730 m->g0->sched.pc = (void*)-1; // make sure it is never used | 730 m->g0->sched.pc = (void*)-1; // make sure it is never used |
731 | |
732 runtime·asminit(); | 731 runtime·asminit(); |
733 runtime·minit(); | 732 runtime·minit(); |
734 schedule(nil); | 733 schedule(nil); |
735 } | 734 } |
736 | 735 |
737 // When running with cgo, we call libcgo_thread_start | 736 // When running with cgo, we call libcgo_thread_start |
738 // to start threads for us so that we can play nicely with | 737 // to start threads for us so that we can play nicely with |
739 // foreign code. | 738 // foreign code. |
740 void (*libcgo_thread_start)(void*); | 739 void (*libcgo_thread_start)(void*); |
741 | 740 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 // entersyscall is going to return immediately after. | 908 // entersyscall is going to return immediately after. |
910 // It's okay to call matchmg and notewakeup even after | 909 // It's okay to call matchmg and notewakeup even after |
911 // decrementing mcpu, because we haven't released the | 910 // decrementing mcpu, because we haven't released the |
912 // sched lock yet, so the garbage collector cannot be running. | 911 // sched lock yet, so the garbage collector cannot be running. |
913 #pragma textflag 7 | 912 #pragma textflag 7 |
914 void | 913 void |
915 runtime·entersyscall(void) | 914 runtime·entersyscall(void) |
916 { | 915 { |
917 uint32 v; | 916 uint32 v; |
918 | 917 |
| 918 if(m->profilehz > 0) |
| 919 runtime·setprof(false); |
| 920 |
919 // Leave SP around for gc and traceback. | 921 // Leave SP around for gc and traceback. |
920 runtime·gosave(&g->sched); | 922 runtime·gosave(&g->sched); |
921 g->gcsp = g->sched.sp; | 923 g->gcsp = g->sched.sp; |
922 g->gcstack = g->stackbase; | 924 g->gcstack = g->stackbase; |
923 g->gcguard = g->stackguard; | 925 g->gcguard = g->stackguard; |
924 g->status = Gsyscall; | 926 g->status = Gsyscall; |
925 if(g->gcsp < g->gcguard-StackGuard || g->gcstack < g->gcsp) { | 927 if(g->gcsp < g->gcguard-StackGuard || g->gcstack < g->gcsp) { |
926 // runtime·printf("entersyscall inconsistent %p [%p,%p]\n", | 928 // runtime·printf("entersyscall inconsistent %p [%p,%p]\n", |
927 // g->gcsp, g->gcguard-StackGuard, g->gcstack); | 929 // g->gcsp, g->gcguard-StackGuard, g->gcstack); |
928 runtime·throw("entersyscall"); | 930 runtime·throw("entersyscall"); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 // find that we still have mcpu <= mcpumax, then we can | 974 // find that we still have mcpu <= mcpumax, then we can |
973 // start executing Go code immediately, without having to | 975 // start executing Go code immediately, without having to |
974 // schedlock/schedunlock. | 976 // schedlock/schedunlock. |
975 v = runtime·xadd(&runtime·sched.atomic, (1<<mcpuShift)); | 977 v = runtime·xadd(&runtime·sched.atomic, (1<<mcpuShift)); |
976 if(m->profilehz == runtime·sched.profilehz && atomic_mcpu(v) <= atomic_m
cpumax(v)) { | 978 if(m->profilehz == runtime·sched.profilehz && atomic_mcpu(v) <= atomic_m
cpumax(v)) { |
977 // There's a cpu for us, so we can run. | 979 // There's a cpu for us, so we can run. |
978 g->status = Grunning; | 980 g->status = Grunning; |
979 // Garbage collector isn't running (since we are), | 981 // Garbage collector isn't running (since we are), |
980 // so okay to clear gcstack. | 982 // so okay to clear gcstack. |
981 g->gcstack = nil; | 983 g->gcstack = nil; |
| 984 |
| 985 if(m->profilehz > 0) |
| 986 runtime·setprof(true); |
982 return; | 987 return; |
983 } | 988 } |
984 | 989 |
985 // Tell scheduler to put g back on the run queue: | 990 // Tell scheduler to put g back on the run queue: |
986 // mostly equivalent to g->status = Grunning, | 991 // mostly equivalent to g->status = Grunning, |
987 // but keeps the garbage collector from thinking | 992 // but keeps the garbage collector from thinking |
988 // that g is running right now, which it's not. | 993 // that g is running right now, which it's not. |
989 g->readyonstop = 1; | 994 g->readyonstop = 1; |
990 | 995 |
991 // All the cpus are taken. | 996 // All the cpus are taken. |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 arg[0][k.len] = 0; | 1766 arg[0][k.len] = 0; |
1762 | 1767 |
1763 arg[1] = runtime·malloc(v.len + 1); | 1768 arg[1] = runtime·malloc(v.len + 1); |
1764 runtime·memmove(arg[1], v.str, v.len); | 1769 runtime·memmove(arg[1], v.str, v.len); |
1765 arg[1][v.len] = 0; | 1770 arg[1][v.len] = 0; |
1766 | 1771 |
1767 runtime·asmcgocall((void*)libcgo_setenv, arg); | 1772 runtime·asmcgocall((void*)libcgo_setenv, arg); |
1768 runtime·free(arg[0]); | 1773 runtime·free(arg[0]); |
1769 runtime·free(arg[1]); | 1774 runtime·free(arg[1]); |
1770 } | 1775 } |
OLD | NEW |