...
Run Format

Source file src/runtime/os_linux_arm64.go

Documentation: runtime

     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.hwcap
    18  var cpu_hwcap uint
    19  
    20  //go:linkname cpu_hwcap2 internal/cpu.hwcap2
    21  var cpu_hwcap2 uint
    22  
    23  func archauxv(tag, val uintptr) {
    24  	switch tag {
    25  	case _AT_RANDOM:
    26  		// sysargs filled in startupRandomData, but that
    27  		// pointer may not be word aligned, so we must treat
    28  		// it as a byte array.
    29  		randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
    30  			uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
    31  	case _AT_HWCAP:
    32  		// arm64 doesn't have a 'cpuid' instruction equivalent and relies on
    33  		// HWCAP/HWCAP2 bits for hardware capabilities.
    34  		hwcap := uint(val)
    35  		if GOOS == "android" {
    36  			// The Samsung S9+ kernel reports support for atomics, but not all cores
    37  			// actually support them, resulting in SIGILL. See issue #28431.
    38  			// TODO(elias.naur): Only disable the optimization on bad chipsets.
    39  			const hwcap_ATOMICS = 1 << 8
    40  			hwcap &= ^uint(hwcap_ATOMICS)
    41  		}
    42  		cpu_hwcap = hwcap
    43  	case _AT_HWCAP2:
    44  		cpu_hwcap2 = uint(val)
    45  	}
    46  }
    47  
    48  //go:nosplit
    49  func cputicks() int64 {
    50  	// Currently cputicks() is used in blocking profiler and to seed fastrand().
    51  	// nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
    52  	// randomNumber provides better seeding of fastrand.
    53  	return nanotime() + int64(randomNumber)
    54  }
    55  

View as plain text