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.
This commit is contained in:
parent
3ae9d0ed54
commit
f16f569060
21
401sleep.mu
21
401sleep.mu
|
@ -1,21 +0,0 @@
|
|||
type timespec {
|
||||
tv_sec: int
|
||||
tv_nsec: int
|
||||
}
|
||||
|
||||
# prototype wrapper around syscall_nanosleep
|
||||
# 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
|
||||
}
|
|
@ -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
|
||||
}
|
BIN
apps/assort
BIN
apps/assort
Binary file not shown.
BIN
apps/braces
BIN
apps/braces
Binary file not shown.
BIN
apps/calls
BIN
apps/calls
Binary file not shown.
BIN
apps/crenshaw2-1
BIN
apps/crenshaw2-1
Binary file not shown.
Binary file not shown.
BIN
apps/dquotes
BIN
apps/dquotes
Binary file not shown.
BIN
apps/factorial
BIN
apps/factorial
Binary file not shown.
BIN
apps/sigils
BIN
apps/sigils
Binary file not shown.
BIN
apps/survey
BIN
apps/survey
Binary file not shown.
BIN
apps/tests
BIN
apps/tests
Binary file not shown.
|
@ -73,7 +73,12 @@ syscall_ioctl: # fd/ebx: int, cmd/ecx: int, arg/edx: (addr _)
|
|||
cd/syscall 0x80/imm8
|
||||
c3/return
|
||||
|
||||
syscall_nanosleep:
|
||||
syscall_nanosleep: # req/ebx: (addr timespec)
|
||||
b8/copy-to-eax 0xa2/imm32 # 162
|
||||
cd/syscall 0x80/imm8
|
||||
c3/return
|
||||
|
||||
syscall_clock_gettime: # clock/ebx: int, out/ecx: (addr timespec)
|
||||
b8/copy-to-eax 0x109/imm32 # 265
|
||||
cd/syscall 0x80/imm8
|
||||
c3/return
|
||||
|
|
|
@ -42,7 +42,6 @@ fn main -> exit-status/ebx: int {
|
|||
|
||||
fn render f: (addr buffered-file), start-row: int, num-rows: int {
|
||||
var num-cols/ecx: int <- copy 0xb9 # 185
|
||||
rewind-stream f
|
||||
# if necessary, clear the row above
|
||||
$render:clear-loop: {
|
||||
compare start-row, 1
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# benchmark: how fast can we print characters to screen?
|
||||
#
|
||||
# Requires a large file called "x" containing just ascii characters. One way
|
||||
# to generate it:
|
||||
# cat /dev/urandom |base64 - |head -n 10000 > x
|
||||
# then merge pairs of lines.
|
||||
|
||||
fn main -> exit-status/ebx: int {
|
||||
var num-lines/ecx: int <- copy 0x64 # 100
|
||||
clear-screen
|
||||
# open a file
|
||||
var f: (addr buffered-file)
|
||||
{
|
||||
var f-handle: (handle buffered-file)
|
||||
var f-in/eax: (addr handle buffered-file) <- address f-handle
|
||||
open "x", 0, f-in # for reading
|
||||
var f-out/eax: (addr buffered-file) <- lookup f-handle
|
||||
copy-to f, f-out
|
||||
}
|
||||
# initial time
|
||||
var t1_/eax: int <- time
|
||||
var t1/edx: int <- copy t1_
|
||||
# main loop
|
||||
var iter/eax: int <- copy 1
|
||||
{
|
||||
compare iter, 0x640 # 1600
|
||||
break-if->
|
||||
render f, num-lines
|
||||
iter <- increment
|
||||
loop
|
||||
}
|
||||
# final time
|
||||
var t2_/eax: int <- time
|
||||
var t2/ebx: int <- copy t2_
|
||||
# time taken
|
||||
var t3/esi: int <- copy t2
|
||||
t3 <- subtract t1
|
||||
# clean up
|
||||
clear-screen
|
||||
# results
|
||||
print-int32-hex-to-screen t1
|
||||
print-string-to-screen "\n"
|
||||
print-int32-hex-to-screen t2
|
||||
print-string-to-screen "\n"
|
||||
print-int32-hex-to-screen t3
|
||||
print-string-to-screen "\n"
|
||||
#
|
||||
exit-status <- copy 0
|
||||
}
|
||||
|
||||
fn render f: (addr buffered-file), num-rows: int {
|
||||
var num-cols/ecx: int <- copy 0x64 # 100
|
||||
# render screen
|
||||
var row/edx: int <- copy 1
|
||||
var col/ebx: int <- copy 1
|
||||
move-cursor-on-screen row, col
|
||||
$render:render-loop: {
|
||||
compare row, num-rows
|
||||
break-if->=
|
||||
var c/eax: byte <- read-byte-buffered f
|
||||
compare c, 0xffffffff # EOF marker
|
||||
break-if-=
|
||||
compare c, 0xa # newline
|
||||
{
|
||||
break-if-!=
|
||||
row <- increment
|
||||
col <- copy 0
|
||||
move-cursor-on-screen row, col
|
||||
loop $render:render-loop
|
||||
}
|
||||
print-byte-to-screen c
|
||||
col <- increment
|
||||
loop
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue