func compilemain(t *testing.T, libgo string) {
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main.c")
if GOOS == "windows" {
- ccArgs = append(ccArgs, "main_windows.c", libgo, "-lntdll", "-lws2_32")
+ ccArgs = append(ccArgs, "main_windows.c", libgo, "-lntdll", "-lws2_32", "-lwinmm")
} else {
ccArgs = append(ccArgs, "main_unix.c", libgo)
}
//go:cgo_import_dynamic runtime._WaitForSingleObject WaitForSingleObject%2 "kernel32.dll"
//go:cgo_import_dynamic runtime._WriteConsoleW WriteConsoleW%5 "kernel32.dll"
//go:cgo_import_dynamic runtime._WriteFile WriteFile%5 "kernel32.dll"
+//go:cgo_import_dynamic runtime._timeBeginPeriod timeBeginPeriod%1 "winmm.dll"
type stdFunction unsafe.Pointer
_WSAGetOverlappedResult,
_WaitForSingleObject,
_WriteConsoleW,
- _WriteFile stdFunction
+ _WriteFile,
+ _timeBeginPeriod,
+ _ stdFunction
// Following syscalls are only available on some Windows PCs.
// We will load syscalls, if available, before using them.
// flags can be used with LoadLibraryEx."
var useLoadLibraryEx bool
+var timeBeginPeriodRetValue uint32
+
func osinit() {
asmstdcallAddr = unsafe.Pointer(funcPC(asmstdcall))
usleep2Addr = unsafe.Pointer(funcPC(usleep2))
stdcall2(_SetConsoleCtrlHandler, funcPC(ctrlhandler), 1)
+ timeBeginPeriodRetValue = uint32(stdcall1(_timeBeginPeriod, 1))
+
ncpu = getproccount()
// Windows dynamic priority boosting assumes that a process has different types
}
}
+func TestTimeBeginPeriod(t *testing.T) {
+ const TIMERR_NOERROR = 0
+ if *runtime.TimeBeginPeriodRetValue != TIMERR_NOERROR {
+ t.Fatalf("timeBeginPeriod failed: it returned %d", *runtime.TimeBeginPeriodRetValue)
+ }
+}
+
// removeOneCPU removes one (any) cpu from affinity mask.
// It returns new affinity mask.
func removeOneCPU(mask uintptr) (uintptr, error) {
modwinmm = syscall.NewLazyDLL("winmm.dll")
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
- proctimeBeginPeriod = modwinmm.NewProc("timeBeginPeriod")
- proctimeEndPeriod = modwinmm.NewProc("timeEndPeriod")
-
procCreateEvent = modkernel32.NewProc("CreateEventW")
procSetEvent = modkernel32.NewProc("SetEvent")
)
-func timeBeginPeriod(period uint32) {
- syscall.Syscall(proctimeBeginPeriod.Addr(), 1, uintptr(period), 0, 0)
-}
-
-func timeEndPeriod(period uint32) {
- syscall.Syscall(proctimeEndPeriod.Addr(), 1, uintptr(period), 0, 0)
-}
-
func createEvent() (syscall.Handle, error) {
r0, _, e0 := syscall.Syscall6(procCreateEvent.Addr(), 4, 0, 0, 0, 0, 0, 0)
if r0 == 0 {
return nil
}
-func benchChanToSyscallPing(b *testing.B) {
+func BenchmarkChanToSyscallPing(b *testing.B) {
n := b.N
ch := make(chan int)
event, err := createEvent()
}
}
-func BenchmarkChanToSyscallPing1ms(b *testing.B) {
- timeBeginPeriod(1)
- benchChanToSyscallPing(b)
- timeEndPeriod(1)
-}
-
-func BenchmarkChanToSyscallPing15ms(b *testing.B) {
- benchChanToSyscallPing(b)
-}
-
-func benchSyscallToSyscallPing(b *testing.B) {
+func BenchmarkSyscallToSyscallPing(b *testing.B) {
n := b.N
event1, err := createEvent()
if err != nil {
}
}
-func BenchmarkSyscallToSyscallPing1ms(b *testing.B) {
- timeBeginPeriod(1)
- benchSyscallToSyscallPing(b)
- timeEndPeriod(1)
-}
-
-func BenchmarkSyscallToSyscallPing15ms(b *testing.B) {
- benchSyscallToSyscallPing(b)
-}
-
-func benchChanToChanPing(b *testing.B) {
+func BenchmarkChanToChanPing(b *testing.B) {
n := b.N
ch1 := make(chan int)
ch2 := make(chan int)
}
}
-func BenchmarkChanToChanPing1ms(b *testing.B) {
- timeBeginPeriod(1)
- benchChanToChanPing(b)
- timeEndPeriod(1)
-}
-
-func BenchmarkChanToChanPing15ms(b *testing.B) {
- benchChanToChanPing(b)
-}
-
-func benchOsYield(b *testing.B) {
+func BenchmarkOsYield(b *testing.B) {
for i := 0; i < b.N; i++ {
runtime.OsYield()
}
}
-
-func BenchmarkOsYield1ms(b *testing.B) {
- timeBeginPeriod(1)
- benchOsYield(b)
- timeEndPeriod(1)
-}
-
-func BenchmarkOsYield15ms(b *testing.B) {
- benchOsYield(b)
-}