ref: 37ecbb55c333772f4f5be0deaa950fd263d7bd54
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jul 12 18:47:30 EDT 2025
initial ocmmit
--- /dev/null
+++ b/fcall.c
@@ -1,0 +1,42 @@
+#include <u.h>
+#include <libc.h>
+
+#include "bench.h"
+#include "fns.h"
+
+void
+f0(void)
+{
+}
+
+void
+f1(int)
+{
+}
+
+void
+f16(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)
+{
+}
+
+void
+fcall0(B *b)
+{
+ int i;
+ for(i = 0; i < b->N; i++)
+ f0();
+}
+void
+fcall1(B *b)
+{
+ int i;
+ for(i = 0; i < b->N; i++)
+ f1(i);
+}
+void
+fcall16(B *b)
+{
+ int i;
+ for(i = 0; i < b->N; i++)
+ f16(i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
+}
\ No newline at end of file
--- /dev/null
+++ b/fns.h
@@ -1,0 +1,73 @@
+
+#define BMARKS \
+ \
+ H("== fork/exec ==\n")\
+ BM(benchfork1)\
+ BM(benchrforkm1)\
+ BM(benchexec1)\
+ BM(benchexecm1)\
+ BM(benchforkN)\
+ BM(benchrforkmN)\
+ BM(benchexecN)\
+ BM(benchexecmN)\
+ \
+ H("== nop io ==\n") \
+ BM(benchsysr1)\
+ BM(benchreadzero)\
+ BM(benchwritenull)\
+ BM(benchreadmordor)\
+ BM(benchwritemordor)\
+ \
+ H("== pipe io ==\n") \
+ BM(benchpipe1)\
+ BM(benchpipe16)\
+ BM(benchpipe256)\
+ BM(benchpipe4096)\
+ BM(benchpipe4097)\
+ BM(benchpipe32768)\
+ \
+ H("== locking (fast work) ==\n") \
+ BM(benchlock1)\
+ BM(benchqlock1)\
+ BM(benchslock1)\
+ BM(benchlock4)\
+ BM(benchqlock4)\
+ BM(benchslock4)\
+ BM(benchlock16)\
+ BM(benchqlock16)\
+ BM(benchslock16)\
+ BM(benchlock64)\
+ BM(benchqlock64)\
+ BM(benchslock64)\
+ BM(benchlock512)\
+ BM(benchqlock512)\
+ BM(benchslock512)\
+ \
+ H("== locking (slow work) ==\n") \
+ BM(benchlock1_w)\
+ BM(benchqlock1_w)\
+ BM(benchslock1_w)\
+ BM(benchlock4_w)\
+ BM(benchqlock4_w)\
+ BM(benchslock4_w)\
+ BM(benchlock16_w)\
+ BM(benchqlock16_w)\
+ BM(benchslock16_w)\
+ BM(benchlock64_w)\
+ BM(benchqlock64_w)\
+ BM(benchslock64_w)\
+ BM(benchlock512_w)\
+ BM(benchqlock512_w)\
+ BM(benchslock512_w)\
+ \
+ H("== locking (slow work) ==\n") \
+ BM(fcall0)\
+ BM(fcall1)\
+ BM(fcall16)\
+
+#define H(x)
+#define BM(n) void n(B *b);
+BMARKS
+#undef BM
+#undef H
+
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,28 @@
+</$objtype/mkfile
+
+TARG=bench
+
+OFILES=\
+ main.$O\
+ bench.$O\
+ \
+ rdwr.$O\
+ lock.$O\
+ spawn.$O\
+ fcall.$O\
+
+HFILES=\
+ bench.h\
+ fns.h
+
+bench:V: all $O.nop
+ $O.out
+
+</sys/src/cmd/mkone
+
+nop.$O: nop.c
+ $CC $CFLAGS nop.c
+
+$O.nop: nop.$O
+ $LD -o $target $prereq
+
--- /dev/null
+++ b/rdwr.c
@@ -1,0 +1,82 @@
+#include <u.h>
+#include <libc.h>
+
+#include "bench.h"
+#include "fns.h"
+
+void
+benchsysr1(B *b)
+{
+ int i;
+
+ extern int sysr1(void);
+ for(i = 0; i < b->N; i++)
+ sysr1();
+}
+
+void
+benchread(B *b, char *path, int n)
+{
+ int i, fd;
+ char buf[128*IOUNIT];
+
+ if((fd = open(path, OREAD)) == -1)
+ sysfatal("open %s: %r", path);
+ for(i = 0; i < b->N; i++)
+ pread(fd, buf, n, 0);
+ close(fd);
+}
+
+void
+benchwrite(B *b, char *path, int n)
+{
+ int i, fd;
+ char buf[128*IOUNIT];
+
+ if((fd = open(path, OWRITE)) == -1)
+ sysfatal("open %s: %r", path);
+ for(i = 0; i < b->N; i++)
+ pwrite(fd, buf, n, 0);
+ close(fd);
+}
+
+void
+benchpipe(B *b, int n)
+{
+ char buf[128*IOUNIT];
+ int i, pfd[2];
+
+ if(pipe(pfd) == -1)
+ sysfatal("pipe: %r");
+
+ switch(rfork(RFPROC|RFMEM)){
+ case -1:
+ sysfatal("fork: %r");
+ case 0:
+ for(i = 0; i < b->N; i++)
+ if(write(pfd[0], buf, n) == -1)
+ sysfatal("write: %r");
+ exits(nil);
+ break;
+ default:
+ for(i = 0; i < b->N; i++)
+ if(read(pfd[1], buf, n) == -1)
+ sysfatal("read: %r");
+ free(wait());
+ close(pfd[0]);
+ close(pfd[1]);
+ break;
+ }
+}
+
+
+void benchreadzero(B *b) { benchread(b, "/dev/zero", 4); }
+void benchwritenull(B *b) { benchwrite(b, "/dev/null", 4); }
+void benchreadmordor(B *b) { benchread(b, "/dev/mordor", 4); }
+void benchwritemordor(B *b) { benchwrite(b, "/dev/mordor", 4); }
+void benchpipe1(B *b) { benchpipe(b, 1); }
+void benchpipe16(B *b) { benchpipe(b, 16); }
+void benchpipe256(B *b) { benchpipe(b, 256); }
+void benchpipe4096(B *b) { benchpipe(b, 4096); }
+void benchpipe4097(B *b) { benchpipe(b, 4097); }
+void benchpipe32768(B *b) { benchpipe(b, 32768); }
--
⑨