github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/time/sampler_arm64.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build arm64 16 // +build arm64 17 18 package time 19 20 // getCNTFRQ get ARM counter-timer frequency 21 func getCNTFRQ() TSCValue 22 23 // getDefaultArchOverheadCycles get default OverheadCycles based on 24 // ARM counter-timer frequency. Usually ARM counter-timer frequency 25 // is range from 1-50Mhz which is much less than that on x86, so we 26 // calibrate defaultOverheadCycles for ARM. 27 func getDefaultArchOverheadCycles() TSCValue { 28 // estimated the clock frequency on x86 is 1Ghz. 29 // 1Ghz divided by counter-timer frequency of ARM to get 30 // frqRatio. defaultOverheadCycles of ARM equals to that on 31 // x86 divided by frqRatio 32 cntfrq := getCNTFRQ() 33 frqRatio := 1000000000 / float64(cntfrq) 34 overheadCycles := (1 * 1000) / frqRatio 35 return TSCValue(overheadCycles) 36 } 37 38 // defaultOverheadTSC is the default estimated syscall overhead in TSC cycles. 39 // It is further refined as syscalls are made. 40 var defaultOverheadCycles = getDefaultArchOverheadCycles() 41 42 // maxOverheadCycles is the maximum allowed syscall overhead in TSC cycles. 43 var maxOverheadCycles = 100 * defaultOverheadCycles