LEFT | RIGHT |
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 "zaexperiment.h" | 7 #include "zaexperiment.h" |
8 #include "malloc.h" | 8 #include "malloc.h" |
9 #include "stack.h" | 9 #include "stack.h" |
10 #include "race.h" | 10 #include "race.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void | 139 void |
140 runtime·schedinit(void) | 140 runtime·schedinit(void) |
141 { | 141 { |
142 int32 n, procs; | 142 int32 n, procs; |
143 byte *p; | 143 byte *p; |
144 Eface i; | 144 Eface i; |
145 | 145 |
146 runtime·sched.maxmcount = 10000; | 146 runtime·sched.maxmcount = 10000; |
147 runtime·precisestack = true; // haveexperiment("precisestack"); | 147 runtime·precisestack = true; // haveexperiment("precisestack"); |
148 | 148 |
| 149 runtime·symtabinit(); |
149 runtime·mallocinit(); | 150 runtime·mallocinit(); |
150 mcommoninit(m); | 151 mcommoninit(m); |
151 ········ | 152 ········ |
152 // Initialize the itable value for newErrorCString, | 153 // Initialize the itable value for newErrorCString, |
153 // so that the next time it gets called, possibly | 154 // so that the next time it gets called, possibly |
154 // in a fault during a garbage collection, it will not | 155 // in a fault during a garbage collection, it will not |
155 // need to allocated memory. | 156 // need to allocated memory. |
156 runtime·newErrorCString(0, &i); | 157 runtime·newErrorCString(0, &i); |
157 | 158 |
158 runtime·goargs(); | 159 runtime·goargs(); |
159 runtime·goenvs(); | 160 runtime·goenvs(); |
160 runtime·parsedebugvars(); | 161 runtime·parsedebugvars(); |
161 | |
162 // Allocate internal symbol table representation now, we need it for GC
anyway. | |
163 runtime·symtabinit(); | |
164 | 162 |
165 runtime·sched.lastpoll = runtime·nanotime(); | 163 runtime·sched.lastpoll = runtime·nanotime(); |
166 procs = 1; | 164 procs = 1; |
167 p = runtime·getenv("GOMAXPROCS"); | 165 p = runtime·getenv("GOMAXPROCS"); |
168 if(p != nil && (n = runtime·atoi(p)) > 0) { | 166 if(p != nil && (n = runtime·atoi(p)) > 0) { |
169 if(n > MaxGomaxprocs) | 167 if(n > MaxGomaxprocs) |
170 n = MaxGomaxprocs; | 168 n = MaxGomaxprocs; |
171 procs = n; | 169 procs = n; |
172 } | 170 } |
173 runtime·allp = runtime·malloc((MaxGomaxprocs+1)*sizeof(runtime·allp[0]))
; | 171 runtime·allp = runtime·malloc((MaxGomaxprocs+1)*sizeof(runtime·allp[0]))
; |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 if(m->lockedg) { | 1667 if(m->lockedg) { |
1670 // Wait until another thread schedules gp and so m again. | 1668 // Wait until another thread schedules gp and so m again. |
1671 stoplockedm(); | 1669 stoplockedm(); |
1672 execute(gp); // Never returns. | 1670 execute(gp); // Never returns. |
1673 } | 1671 } |
1674 stopm(); | 1672 stopm(); |
1675 schedule(); // Never returns. | 1673 schedule(); // Never returns. |
1676 } | 1674 } |
1677 | 1675 |
1678 // Called from syscall package before fork. | 1676 // Called from syscall package before fork. |
| 1677 #pragma textflag NOSPLIT |
1679 void | 1678 void |
1680 syscall·runtime_BeforeFork(void) | 1679 syscall·runtime_BeforeFork(void) |
1681 { | 1680 { |
1682 // Fork can hang if preempted with signals frequently enough (see issue
5517). | 1681 // Fork can hang if preempted with signals frequently enough (see issue
5517). |
1683 // Ensure that we stay on the same M where we disable profiling. | 1682 // Ensure that we stay on the same M where we disable profiling. |
1684 m->locks++; | 1683 m->locks++; |
1685 if(m->profilehz != 0) | 1684 if(m->profilehz != 0) |
1686 runtime·resetcpuprofiler(0); | 1685 runtime·resetcpuprofiler(0); |
| 1686 |
| 1687 // This function is called before fork in syscall package. |
| 1688 // Code between fork and exec must not allocate memory nor even try to g
row stack. |
| 1689 // Here we spoil g->stackguard to reliably detect any attempts to grow s
tack. |
| 1690 // runtime_AfterFork will undo this in parent process, but not in child. |
| 1691 m->forkstackguard = g->stackguard; |
| 1692 g->stackguard0 = StackPreempt-1; |
| 1693 g->stackguard = StackPreempt-1; |
1687 } | 1694 } |
1688 | 1695 |
1689 // Called from syscall package after fork in parent. | 1696 // Called from syscall package after fork in parent. |
| 1697 #pragma textflag NOSPLIT |
1690 void | 1698 void |
1691 syscall·runtime_AfterFork(void) | 1699 syscall·runtime_AfterFork(void) |
1692 { | 1700 { |
1693 int32 hz; | 1701 int32 hz; |
| 1702 |
| 1703 // See the comment in runtime_BeforeFork. |
| 1704 g->stackguard0 = m->forkstackguard; |
| 1705 g->stackguard = m->forkstackguard; |
| 1706 m->forkstackguard = 0; |
1694 | 1707 |
1695 hz = runtime·sched.profilehz; | 1708 hz = runtime·sched.profilehz; |
1696 if(hz != 0) | 1709 if(hz != 0) |
1697 runtime·resetcpuprofiler(hz); | 1710 runtime·resetcpuprofiler(hz); |
1698 m->locks--; | 1711 m->locks--; |
1699 } | 1712 } |
1700 | 1713 |
1701 // Hook used by runtime·malg to call runtime·stackalloc on the | 1714 // Hook used by runtime·malg to call runtime·stackalloc on the |
1702 // scheduler stack. This exists because runtime·stackalloc insists | 1715 // scheduler stack. This exists because runtime·stackalloc insists |
1703 // on being called on the scheduler stack, to avoid trying to grow | 1716 // on being called on the scheduler stack, to avoid trying to grow |
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3089 if(experiment[i+j] != name[j]) | 3102 if(experiment[i+j] != name[j]) |
3090 goto nomatch; | 3103 goto nomatch; |
3091 if(experiment[i+j] != '\0' && experiment[i+j] != ',') | 3104 if(experiment[i+j] != '\0' && experiment[i+j] != ',') |
3092 goto nomatch; | 3105 goto nomatch; |
3093 return 1; | 3106 return 1; |
3094 } | 3107 } |
3095 nomatch:; | 3108 nomatch:; |
3096 } | 3109 } |
3097 return 0; | 3110 return 0; |
3098 } | 3111 } |
LEFT | RIGHT |