...

Source file src/runtime/os_linux_arm64.go

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

View as plain text