...

Source file src/runtime/runtime.go

Documentation: runtime

     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 (
     8  	"runtime/internal/atomic"
     9  	_ "unsafe" // for go:linkname
    10  )
    11  
    12  //go:generate go run wincallback.go
    13  //go:generate go run mkduff.go
    14  //go:generate go run mkfastlog2table.go
    15  
    16  var ticks ticksType
    17  
    18  type ticksType struct {
    19  	lock mutex
    20  	pad  uint32 // ensure 8-byte alignment of val on 386
    21  	val  uint64
    22  }
    23  
    24  // Note: Called by runtime/pprof in addition to runtime code.
    25  func tickspersecond() int64 {
    26  	r := int64(atomic.Load64(&ticks.val))
    27  	if r != 0 {
    28  		return r
    29  	}
    30  	lock(&ticks.lock)
    31  	r = int64(ticks.val)
    32  	if r == 0 {
    33  		t0 := nanotime()
    34  		c0 := cputicks()
    35  		usleep(100 * 1000)
    36  		t1 := nanotime()
    37  		c1 := cputicks()
    38  		if t1 == t0 {
    39  			t1++
    40  		}
    41  		r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0)
    42  		if r == 0 {
    43  			r++
    44  		}
    45  		atomic.Store64(&ticks.val, uint64(r))
    46  	}
    47  	unlock(&ticks.lock)
    48  	return r
    49  }
    50  
    51  var envs []string
    52  var argslice []string
    53  
    54  //go:linkname syscall_runtime_envs syscall.runtime_envs
    55  func syscall_runtime_envs() []string { return append([]string{}, envs...) }
    56  
    57  //go:linkname syscall_Getpagesize syscall.Getpagesize
    58  func syscall_Getpagesize() int { return int(physPageSize) }
    59  
    60  //go:linkname os_runtime_args os.runtime_args
    61  func os_runtime_args() []string { return append([]string{}, argslice...) }
    62  
    63  //go:linkname syscall_Exit syscall.Exit
    64  //go:nosplit
    65  func syscall_Exit(code int) {
    66  	exit(int32(code))
    67  }
    68  

View as plain text