-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78da201
commit 907d376
Showing
5 changed files
with
309 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build uefi | ||
|
||
package uefi | ||
|
||
import ( | ||
"device/x86" | ||
"sync" | ||
) | ||
|
||
var calibrateMutex sync.Mutex | ||
var calculatedFrequency uint64 | ||
|
||
func GetTscFrequency() uint64 { | ||
frequence := x86.InternalGetPerformanceCounterFrequency() | ||
if frequence > 0 { | ||
return frequence | ||
} | ||
|
||
var event EFI_EVENT | ||
var status EFI_STATUS | ||
var index UINTN | ||
|
||
calibrateMutex.Lock() | ||
defer calibrateMutex.Unlock() | ||
|
||
freq := calculatedFrequency | ||
if freq > 0 { | ||
return freq | ||
} | ||
|
||
bs := systemTable.BootServices | ||
|
||
status = bs.CreateEvent(EVT_TIMER, TPL_CALLBACK, nil, nil, &event) | ||
if status != EFI_SUCCESS { | ||
return 0 | ||
} | ||
defer bs.CloseEvent(event) | ||
|
||
st := x86.AsmReadRdtsc() | ||
status = bs.SetTimer(event, TimerPeriodic, 250*10000) | ||
if status != EFI_SUCCESS { | ||
return 0 | ||
} | ||
status = bs.WaitForEvent(1, &event, &index) | ||
diff := x86.AsmReadRdtsc() - st | ||
|
||
calculatedFrequency = diff * 4 | ||
|
||
return calculatedFrequency | ||
} | ||
|
||
func GetTime() (EFI_TIME, EFI_STATUS) { | ||
var status EFI_STATUS | ||
var time EFI_TIME | ||
|
||
status = systemTable.RuntimeServices.GetTime(&time, nil) | ||
|
||
return time, status | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.