...
Run Format

Source file src/runtime/runtime.go

     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 struct {
    17		lock mutex
    18		pad  uint32 // ensure 8-byte alignment of val on 386
    19		val  uint64
    20	}
    21	
    22	// Note: Called by runtime/pprof in addition to runtime code.
    23	func tickspersecond() int64 {
    24		r := int64(atomic.Load64(&ticks.val))
    25		if r != 0 {
    26			return r
    27		}
    28		lock(&ticks.lock)
    29		r = int64(ticks.val)
    30		if r == 0 {
    31			t0 := nanotime()
    32			c0 := cputicks()
    33			usleep(100 * 1000)
    34			t1 := nanotime()
    35			c1 := cputicks()
    36			if t1 == t0 {
    37				t1++
    38			}
    39			r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0)
    40			if r == 0 {
    41				r++
    42			}
    43			atomic.Store64(&ticks.val, uint64(r))
    44		}
    45		unlock(&ticks.lock)
    46		return r
    47	}
    48	
    49	var envs []string
    50	var argslice []string
    51	
    52	//go:linkname syscall_runtime_envs syscall.runtime_envs
    53	func syscall_runtime_envs() []string { return append([]string{}, envs...) }
    54	
    55	//go:linkname syscall_Getpagesize syscall.Getpagesize
    56	func syscall_Getpagesize() int { return int(physPageSize) }
    57	
    58	//go:linkname os_runtime_args os.runtime_args
    59	func os_runtime_args() []string { return append([]string{}, argslice...) }
    60	

View as plain text