about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-07-08 22:09:59 -0700
committerKartik Agaram <vc@akkartik.com>2020-07-08 22:14:42 -0700
commitf16f5690600ea74f2d77b72bf9167cf3a74c1d2e (patch)
treea63c61f6eba005f0e529e1c28e247cf7f2b92942
parent3ae9d0ed54f7cd13a1672d0f5ae29d3f9baf4027 (diff)
downloadmu-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.mu21
-rw-r--r--401time.mu39
-rwxr-xr-xapps/assortbin44412 -> 44420 bytes
-rwxr-xr-xapps/bracesbin46275 -> 46283 bytes
-rwxr-xr-xapps/callsbin50922 -> 50930 bytes
-rwxr-xr-xapps/crenshaw2-1bin43753 -> 43761 bytes
-rwxr-xr-xapps/crenshaw2-1bbin44300 -> 44308 bytes
-rwxr-xr-xapps/dquotesbin48034 -> 48042 bytes
-rwxr-xr-xapps/ex1bin213 -> 221 bytes
-rwxr-xr-xapps/ex10bin280 -> 288 bytes
-rwxr-xr-xapps/ex11bin1194 -> 1202 bytes
-rwxr-xr-xapps/ex12bin250 -> 258 bytes
-rwxr-xr-xapps/ex13bin227 -> 235 bytes
-rwxr-xr-xapps/ex2bin219 -> 227 bytes
-rwxr-xr-xapps/ex3bin231 -> 239 bytes
-rwxr-xr-xapps/ex4bin252 -> 260 bytes
-rwxr-xr-xapps/ex5bin252 -> 260 bytes
-rwxr-xr-xapps/ex6bin248 -> 256 bytes
-rwxr-xr-xapps/ex7bin382 -> 390 bytes
-rwxr-xr-xapps/ex8bin250 -> 258 bytes
-rwxr-xr-xapps/ex9bin244 -> 252 bytes
-rwxr-xr-xapps/factorialbin42856 -> 42864 bytes
-rwxr-xr-xapps/hexbin46592 -> 46600 bytes
-rwxr-xr-xapps/mubin341155 -> 341163 bytes
-rwxr-xr-xapps/packbin56991 -> 56999 bytes
-rwxr-xr-xapps/sigilsbin58644 -> 58652 bytes
-rwxr-xr-xapps/surveybin54344 -> 54352 bytes
-rwxr-xr-xapps/testsbin43184 -> 43192 bytes
-rw-r--r--init.linux7
-rw-r--r--prototypes/tile/2.mu1
-rw-r--r--prototypes/tile/3.mu75
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
+  }
+}