github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/src/runtime/runtime.go (about) 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 7 import _ "unsafe" // for go:linkname 8 9 //go:generate go run wincallback.go 10 //go:generate go run mkduff.go 11 //go:generate go run mkfastlog2table.go 12 13 var ticks struct { 14 lock mutex 15 pad uint32 // ensure 8-byte alignment of val on 386 16 val uint64 17 } 18 19 var tls0 [8]uintptr // available storage for m0's TLS; not necessarily used; opaque to GC 20 21 // Note: Called by runtime/pprof in addition to runtime code. 22 func tickspersecond() int64 { 23 r := int64(atomicload64(&ticks.val)) 24 if r != 0 { 25 return r 26 } 27 lock(&ticks.lock) 28 r = int64(ticks.val) 29 if r == 0 { 30 t0 := nanotime() 31 c0 := cputicks() 32 usleep(100 * 1000) 33 t1 := nanotime() 34 c1 := cputicks() 35 if t1 == t0 { 36 t1++ 37 } 38 r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0) 39 if r == 0 { 40 r++ 41 } 42 atomicstore64(&ticks.val, uint64(r)) 43 } 44 unlock(&ticks.lock) 45 return r 46 } 47 48 var envs []string 49 var argslice []string 50 51 //go:linkname syscall_runtime_envs syscall.runtime_envs 52 func syscall_runtime_envs() []string { return append([]string{}, envs...) } 53 54 //go:linkname os_runtime_args os.runtime_args 55 func os_runtime_args() []string { return append([]string{}, argslice...) }