github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/src/runtime/os_linux_arm64.go (about)

     1  // Copyright 2015 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  // +build arm64
     6  
     7  package runtime
     8  
     9  // For go:linkname
    10  import _ "unsafe"
    11  
    12  var randomNumber uint32
    13  
    14  // arm64 doesn't have a 'cpuid' instruction equivalent and relies on
    15  // HWCAP/HWCAP2 bits for hardware capabilities.
    16  
    17  //go:linkname cpu_hwcap internal/cpu.arm64_hwcap
    18  //go:linkname cpu_hwcap2 internal/cpu.arm64_hwcap2
    19  var cpu_hwcap uint
    20  var cpu_hwcap2 uint
    21  
    22  func archauxv(tag, val uintptr) {
    23  	switch tag {
    24  	case _AT_RANDOM:
    25  		// sysargs filled in startupRandomData, but that
    26  		// pointer may not be word aligned, so we must treat
    27  		// it as a byte array.
    28  		randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
    29  			uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
    30  	case _AT_HWCAP:
    31  		cpu_hwcap = uint(val)
    32  	case _AT_HWCAP2:
    33  		cpu_hwcap2 = uint(val)
    34  	}
    35  }
    36  
    37  //go:nosplit
    38  func cputicks() int64 {
    39  	// Currently cputicks() is used in blocking profiler and to seed fastrand().
    40  	// nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
    41  	// randomNumber provides better seeding of fastrand.
    42  	return nanotime() + int64(randomNumber)
    43  }