Russ Cox | e3edfea | 2014-09-04 00:54:06 -0400 | [diff] [blame] | 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package runtime |
| 6 | |
Russ Cox | 7a524a1 | 2014-12-22 13:27:53 -0500 | [diff] [blame] | 7 | import _ "unsafe" // for go:linkname |
| 8 | |
Russ Cox | dcb2ec3 | 2014-12-05 16:24:20 -0500 | [diff] [blame] | 9 | //go:generate go run wincallback.go |
Josh Bleecher Snyder | ad36009 | 2015-03-31 09:19:10 -0700 | [diff] [blame] | 10 | //go:generate go run mkduff.go |
Russ Cox | dcb2ec3 | 2014-12-05 16:24:20 -0500 | [diff] [blame] | 11 | |
Russ Cox | e3edfea | 2014-09-04 00:54:06 -0400 | [diff] [blame] | 12 | var ticks struct { |
| 13 | lock mutex |
Austin Clements | 7a71726 | 2015-01-29 11:54:45 -0500 | [diff] [blame] | 14 | pad uint32 // ensure 8-byte alignment of val on 386 |
Russ Cox | e3edfea | 2014-09-04 00:54:06 -0400 | [diff] [blame] | 15 | val uint64 |
| 16 | } |
| 17 | |
Russ Cox | 193daab | 2014-09-24 16:55:26 -0400 | [diff] [blame] | 18 | var tls0 [8]uintptr // available storage for m0's TLS; not necessarily used; opaque to GC |
| 19 | |
Russ Cox | e3edfea | 2014-09-04 00:54:06 -0400 | [diff] [blame] | 20 | // Note: Called by runtime/pprof in addition to runtime code. |
| 21 | func tickspersecond() int64 { |
| 22 | r := int64(atomicload64(&ticks.val)) |
| 23 | if r != 0 { |
| 24 | return r |
| 25 | } |
| 26 | lock(&ticks.lock) |
| 27 | r = int64(ticks.val) |
| 28 | if r == 0 { |
| 29 | t0 := nanotime() |
| 30 | c0 := cputicks() |
| 31 | usleep(100 * 1000) |
| 32 | t1 := nanotime() |
| 33 | c1 := cputicks() |
| 34 | if t1 == t0 { |
| 35 | t1++ |
| 36 | } |
| 37 | r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0) |
| 38 | if r == 0 { |
| 39 | r++ |
| 40 | } |
| 41 | atomicstore64(&ticks.val, uint64(r)) |
| 42 | } |
| 43 | unlock(&ticks.lock) |
| 44 | return r |
| 45 | } |
Russ Cox | 4475347 | 2014-09-12 16:12:39 -0400 | [diff] [blame] | 46 | |
Russ Cox | 193daab | 2014-09-24 16:55:26 -0400 | [diff] [blame] | 47 | var envs []string |
| 48 | var argslice []string |
| 49 | |
Russ Cox | 7a524a1 | 2014-12-22 13:27:53 -0500 | [diff] [blame] | 50 | //go:linkname syscall_runtime_envs syscall.runtime_envs |
David Crawshaw | 402f71a | 2015-03-03 13:55:22 -0500 | [diff] [blame] | 51 | func syscall_runtime_envs() []string { return append([]string{}, envs...) } |
Russ Cox | 193daab | 2014-09-24 16:55:26 -0400 | [diff] [blame] | 52 | |
Russ Cox | 7a524a1 | 2014-12-22 13:27:53 -0500 | [diff] [blame] | 53 | //go:linkname os_runtime_args os.runtime_args |
David Crawshaw | 402f71a | 2015-03-03 13:55:22 -0500 | [diff] [blame] | 54 | func os_runtime_args() []string { return append([]string{}, argslice...) } |