runtime.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. package runtime
  5. var ticks struct {
  6. lock mutex
  7. val uint64
  8. }
  9. var tls0 [8]uintptr // available storage for m0's TLS; not necessarily used; opaque to GC
  10. // Note: Called by runtime/pprof in addition to runtime code.
  11. func tickspersecond() int64 {
  12. r := int64(atomicload64(&ticks.val))
  13. if r != 0 {
  14. return r
  15. }
  16. lock(&ticks.lock)
  17. r = int64(ticks.val)
  18. if r == 0 {
  19. t0 := nanotime()
  20. c0 := cputicks()
  21. usleep(100 * 1000)
  22. t1 := nanotime()
  23. c1 := cputicks()
  24. if t1 == t0 {
  25. t1++
  26. }
  27. r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0)
  28. if r == 0 {
  29. r++
  30. }
  31. atomicstore64(&ticks.val, uint64(r))
  32. }
  33. unlock(&ticks.lock)
  34. return r
  35. }
  36. func makeStringSlice(n int) []string {
  37. return make([]string, n)
  38. }
  39. // TODO: Move to parfor.go when parfor.c becomes parfor.go.
  40. func parforalloc(nthrmax uint32) *parfor {
  41. return &parfor{
  42. thr: &make([]parforthread, nthrmax)[0],
  43. nthrmax: nthrmax,
  44. }
  45. }
  46. var envs []string
  47. var argslice []string
  48. // called from syscall
  49. func runtime_envs() []string { return envs }
  50. // called from os
  51. func runtime_args() []string { return argslice }