Skip to content

Instantly share code, notes, and snippets.

@christos68k
christos68k / monotonic.go
Last active March 30, 2024 04:03
monotonic clock sync tests
package main
import (
"fmt"
"sort"
"time"
_ "unsafe"
"golang.org/x/sys/unix"
)
/*
* Given a test pattern (number in base10), for each digit D starting from the right,
* spawn D threads to burn cpu in separate dynamically allocated executable pages,
* sleep for user-configurable delay, cancel all threads and revert executable pages
* to PROT_NONE.
*
* Example for pattern 432:
* spawn 2 threads, sleep, cancel/mprotect, sleep, spawn 3 threads, sleep, cancel/mprotect..
*
* The addresses used for the executable mappings are of the form:
$ ./map 987 2
Reserved 0x2000000000 bytes at 0x10000000000
PID: 1237837
Code len: 40
Page size: 4096
=== ARGS:
Test pattern: 987
Delay: 2
Page gap: 1