diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-07-08 22:09:59 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-07-08 22:14:42 -0700 |
commit | f16f5690600ea74f2d77b72bf9167cf3a74c1d2e (patch) | |
tree | a63c61f6eba005f0e529e1c28e247cf7f2b92942 /401time.mu | |
parent | 3ae9d0ed54f7cd13a1672d0f5ae29d3f9baf4027 (diff) | |
download | mu-f16f5690600ea74f2d77b72bf9167cf3a74c1d2e.tar.gz |
6622 - new syscalls: time and ntime
As a side-effect I find that my Linode can print ~100k chars/s. At 50 rows and 200 columns per screen, it's 10 frames/s.
Diffstat (limited to '401time.mu')
-rw-r--r-- | 401time.mu | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/401time.mu b/401time.mu new file mode 100644 index 00000000..c95c4e14 --- /dev/null +++ b/401time.mu @@ -0,0 +1,39 @@ +type timespec { + tv_sec: int + tv_nsec: int +} + +# TODO: y2038 +fn time -> secs/eax: int { + var t: timespec + var clock/ebx: int <- copy 0 # CLOCK_MONOTONIC + var t-addr/ecx: (addr timespec) <- address t + syscall_clock_gettime + var t-secs-addr/ecx: (addr int) <- get t-addr, tv_sec + secs <- copy *t-secs-addr +} + +fn ntime -> nsecs/eax: int { + var t: timespec + var clock/ebx: int <- copy 0 # CLOCK_MONOTONIC + var t-addr/ecx: (addr timespec) <- address t + syscall_clock_gettime + var t-nsecs-addr/ecx: (addr int) <- get t-addr, tv_nsec + nsecs <- copy *t-nsecs-addr +} + +# nsecs must be less than 999999999 or 0x3b9ac9ff nanoseconds +fn sleep secs: int, nsecs: int { + var t: timespec + # initialize t + var tmp/eax: (addr int) <- get t, tv_sec + var tmp2/ecx: int <- copy secs + copy-to *tmp, tmp2 + tmp <- get t, tv_nsec + tmp2 <- copy nsecs + copy-to *tmp, tmp2 + # perform the syscall + var t-addr/ebx: (addr timespec) <- address t + var rem-addr/ecx: (addr timespec) <- copy 0 + syscall_nanosleep +} |