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 | |
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.
-rw-r--r-- | 401sleep.mu | 21 | ||||
-rw-r--r-- | 401time.mu | 39 | ||||
-rwxr-xr-x | apps/assort | bin | 44412 -> 44420 bytes | |||
-rwxr-xr-x | apps/braces | bin | 46275 -> 46283 bytes | |||
-rwxr-xr-x | apps/calls | bin | 50922 -> 50930 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1 | bin | 43753 -> 43761 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1b | bin | 44300 -> 44308 bytes | |||
-rwxr-xr-x | apps/dquotes | bin | 48034 -> 48042 bytes | |||
-rwxr-xr-x | apps/ex1 | bin | 213 -> 221 bytes | |||
-rwxr-xr-x | apps/ex10 | bin | 280 -> 288 bytes | |||
-rwxr-xr-x | apps/ex11 | bin | 1194 -> 1202 bytes | |||
-rwxr-xr-x | apps/ex12 | bin | 250 -> 258 bytes | |||
-rwxr-xr-x | apps/ex13 | bin | 227 -> 235 bytes | |||
-rwxr-xr-x | apps/ex2 | bin | 219 -> 227 bytes | |||
-rwxr-xr-x | apps/ex3 | bin | 231 -> 239 bytes | |||
-rwxr-xr-x | apps/ex4 | bin | 252 -> 260 bytes | |||
-rwxr-xr-x | apps/ex5 | bin | 252 -> 260 bytes | |||
-rwxr-xr-x | apps/ex6 | bin | 248 -> 256 bytes | |||
-rwxr-xr-x | apps/ex7 | bin | 382 -> 390 bytes | |||
-rwxr-xr-x | apps/ex8 | bin | 250 -> 258 bytes | |||
-rwxr-xr-x | apps/ex9 | bin | 244 -> 252 bytes | |||
-rwxr-xr-x | apps/factorial | bin | 42856 -> 42864 bytes | |||
-rwxr-xr-x | apps/hex | bin | 46592 -> 46600 bytes | |||
-rwxr-xr-x | apps/mu | bin | 341155 -> 341163 bytes | |||
-rwxr-xr-x | apps/pack | bin | 56991 -> 56999 bytes | |||
-rwxr-xr-x | apps/sigils | bin | 58644 -> 58652 bytes | |||
-rwxr-xr-x | apps/survey | bin | 54344 -> 54352 bytes | |||
-rwxr-xr-x | apps/tests | bin | 43184 -> 43192 bytes | |||
-rw-r--r-- | init.linux | 7 | ||||
-rw-r--r-- | prototypes/tile/2.mu | 1 | ||||
-rw-r--r-- | prototypes/tile/3.mu | 75 |
31 files changed, 120 insertions, 23 deletions
diff --git a/401sleep.mu b/401sleep.mu deleted file mode 100644 index 79ad6bd5..00000000 --- a/401sleep.mu +++ /dev/null @@ -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 -} 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 +} diff --git a/apps/assort b/apps/assort index f61cb556..22eb2a59 100755 --- a/apps/assort +++ b/apps/assort Binary files differdiff --git a/apps/braces b/apps/braces index 1adc5fe4..e5677f93 100755 --- a/apps/braces +++ b/apps/braces Binary files differdiff --git a/apps/calls b/apps/calls index e86af3dc..455c3a7c 100755 --- a/apps/calls +++ b/apps/calls Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1 index 513e5525..ac1d1ddb 100755 --- a/apps/crenshaw2-1 +++ b/apps/crenshaw2-1 Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b index 9e0fcc06..ff3f940a 100755 --- a/apps/crenshaw2-1b +++ b/apps/crenshaw2-1b Binary files differdiff --git a/apps/dquotes b/apps/dquotes index 32c7604d..50feebd3 100755 --- a/apps/dquotes +++ b/apps/dquotes Binary files differdiff --git a/apps/ex1 b/apps/ex1 index aec15656..2aad6427 100755 --- a/apps/ex1 +++ b/apps/ex1 Binary files differdiff --git a/apps/ex10 b/apps/ex10 index 4e3a163d..7926e5db 100755 --- a/apps/ex10 +++ b/apps/ex10 Binary files differdiff --git a/apps/ex11 b/apps/ex11 index bd1b754d..697ef6d3 100755 --- a/apps/ex11 +++ b/apps/ex11 Binary files differdiff --git a/apps/ex12 b/apps/ex12 index d50e6db9..92d006ff 100755 --- a/apps/ex12 +++ b/apps/ex12 Binary files differdiff --git a/apps/ex13 b/apps/ex13 index 2f77063a..239481d4 100755 --- a/apps/ex13 +++ b/apps/ex13 Binary files differdiff --git a/apps/ex2 b/apps/ex2 index 0917c0aa..0b221cff 100755 --- a/apps/ex2 +++ b/apps/ex2 Binary files differdiff --git a/apps/ex3 b/apps/ex3 index b594a24b..9e3d3a5a 100755 --- a/apps/ex3 +++ b/apps/ex3 Binary files differdiff --git a/apps/ex4 b/apps/ex4 index 25789096..a0452d50 100755 --- a/apps/ex4 +++ b/apps/ex4 Binary files differdiff --git a/apps/ex5 b/apps/ex5 index d2874012..ec351b61 100755 --- a/apps/ex5 +++ b/apps/ex5 Binary files differdiff --git a/apps/ex6 b/apps/ex6 index c9e34a6d..58fb8b58 100755 --- a/apps/ex6 +++ b/apps/ex6 Binary files differdiff --git a/apps/ex7 b/apps/ex7 index d6d12ab8..444dc7be 100755 --- a/apps/ex7 +++ b/apps/ex7 Binary files differdiff --git a/apps/ex8 b/apps/ex8 index dc45c8eb..4eeb3f07 100755 --- a/apps/ex8 +++ b/apps/ex8 Binary files differdiff --git a/apps/ex9 b/apps/ex9 index 7d2d495e..14dd22b2 100755 --- a/apps/ex9 +++ b/apps/ex9 Binary files differdiff --git a/apps/factorial b/apps/factorial index 46909f1c..063a2f79 100755 --- a/apps/factorial +++ b/apps/factorial Binary files differdiff --git a/apps/hex b/apps/hex index 6a470eb3..98a6e819 100755 --- a/apps/hex +++ b/apps/hex Binary files differdiff --git a/apps/mu b/apps/mu index 34350d0d..3fbf8b58 100755 --- a/apps/mu +++ b/apps/mu Binary files differdiff --git a/apps/pack b/apps/pack index 3b72f273..c68ccf73 100755 --- a/apps/pack +++ b/apps/pack Binary files differdiff --git a/apps/sigils b/apps/sigils index d1bc0e91..941fd4ac 100755 --- a/apps/sigils +++ b/apps/sigils Binary files differdiff --git a/apps/survey b/apps/survey index ad4630c9..94b0e03f 100755 --- a/apps/survey +++ b/apps/survey Binary files differdiff --git a/apps/tests b/apps/tests index 4410fd93..e6874d3a 100755 --- a/apps/tests +++ b/apps/tests Binary files differdiff --git a/init.linux b/init.linux index 9893f856..6e482b96 100644 --- a/init.linux +++ b/init.linux @@ -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 diff --git a/prototypes/tile/2.mu b/prototypes/tile/2.mu index 1d399c2b..41c19d74 100644 --- a/prototypes/tile/2.mu +++ b/prototypes/tile/2.mu @@ -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 diff --git a/prototypes/tile/3.mu b/prototypes/tile/3.mu new file mode 100644 index 00000000..3ee274de --- /dev/null +++ b/prototypes/tile/3.mu @@ -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 + } +} |