mirror of
https://github.com/pithings/unkernel.git
synced 2026-12-05 23:39:48 +08:00
71 lines
3.7 KiB
Bash
71 lines
3.7 KiB
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
|
|
#
|
|
# The guest side of test/work-bench.mjs (Perl, Python, a C build, shell and
|
|
# dpkg, Node, Bun and Claude Code on the work disk; .agents/a64/performance.md,
|
|
# Measuring). test/ is mounted at /t and the host's generated inputs (a C
|
|
# project, a TypeScript file) at /w.
|
|
# sh /t/work-bench.sh prep copy the inputs to /tmp/wb, set ASLR
|
|
# sh /t/work-bench.sh run ROW run ROW once, timed in the guest:
|
|
# "RES ROW ms rc=N"
|
|
# ASLR=N sets kernel.randomize_va_space in prep: the base boots with 0
|
|
# (shared libraries and PIE programs load at the same addresses in every
|
|
# process) unless kw.aslr=1, and ASLR=2 turns randomization on. The sizes are
|
|
# variables too (PERL_N, PERL_START_N, PY_N, PY_TREE, CFLAGS, SH_N, BUN_CPU,
|
|
# NODE_CPU; the C project's size is the host's C_UNITS and C_FUNCS).
|
|
d=/tmp/wb
|
|
case $1 in
|
|
prep)
|
|
[ -n "$ASLR" ] && sudo sh -c "echo $ASLR > /proc/sys/kernel/randomize_va_space"
|
|
rm -rf $d && mkdir -p $d && cd $d || exit 1
|
|
cp /t/guest/work/* /t/guest/app/cpu.js $d/ && cp -r /w/cproj $d/cproj && cp /w/big.ts $d/ || exit 1
|
|
# A package tree for compileall (pure Python, no .pyc yet).
|
|
[ -d /usr/lib/python3/dist-packages/jinja2 ] && mkdir -p $d/pytree && for p in ${PY_TREE:-jinja2 docutils/parsers}; do
|
|
mkdir -p $d/pytree/$p && cp -r /usr/lib/python3/dist-packages/$p/. $d/pytree/$p/
|
|
done
|
|
[ -d $d/pytree ] && find $d/pytree -name __pycache__ -prune -exec rm -rf {} +
|
|
echo "ASLR $(cat /proc/sys/kernel/randomize_va_space)"
|
|
echo PREP-DONE
|
|
exit 0
|
|
;;
|
|
run) ;;
|
|
*) echo "usage: work-bench.sh prep | run ROW" >&2; exit 2 ;;
|
|
esac
|
|
|
|
row=$2
|
|
cd $d || exit 1
|
|
loop() { i=0; while [ $i -lt "$1" ]; do i=$((i + 1)); eval "$2"; done; }
|
|
rm -f /tmp/wb-info
|
|
s=$(date +%s%N)
|
|
case $row in
|
|
perl-k[1-6]) perl work.pl "${PERL_N:-1}" a "${row#perl-k}" ;;
|
|
# Perl start-up with a few common modules (XS ones too), many processes.
|
|
perl-start) loop "${PERL_START_N:-3}" 'perl -MPOSIX -MData::Dumper -MFile::Temp -MGetopt::Long -MList::Util -MStorable -e 1' ;;
|
|
py-start) python3 -c 'import jinja2, docutils.core, pygments.lexers.python, pygments.formatters.html, json, email.parser, http.client, argparse, decimal, asyncio' ;;
|
|
py-compile) python3 -m compileall -q -f pytree ;;
|
|
py-cpu) python3 pycpu.py "${PY_N:-30}" ;;
|
|
# Many short cc1, as and ld processes (make -j1).
|
|
cc-build) make -s -C cproj clean work CFLAGS="${CFLAGS:--O0}" ;;
|
|
# Coreutils, grep, sed and awk in a shell loop: many short PIE processes.
|
|
sh-procs) loop "${SH_N:-30}" 'ls -l /usr/bin | grep -c x; sed -n "s/:.*//p" /etc/passwd | sort | uniq | wc -l; find /etc -maxdepth 1 -name "*.conf" | xargs cat | awk "{ n += NF } END { print n }"; basename /a/b/c; dirname /a/b/c; expr 3 + 4; date +%s; head -c 4096 /usr/bin/ls | md5sum' ;;
|
|
dpkg) dpkg-query -W -f '${Package} ${Version} ${Installed-Size}\n' | sort -k3 -n | tail -3; dpkg -S /usr/bin/ls; dpkg -L perl-base | wc -l
|
|
dpkg -s libc6 | head -3; apt-cache policy gcc python3; apt-cache show perl | wc -l; apt-cache depends make; dpkg --verify coreutils ;;
|
|
# The rows of test/app-bench.sh.
|
|
claude-help) claude --help ;;
|
|
npm-version) npm --version ;;
|
|
bun-cpu) bun cpu.js "${BUN_CPU:-150}" ;;
|
|
node-cpu) node cpu.js "${NODE_CPU:-40}" ;;
|
|
node-e0) node -e 0 ;;
|
|
claude-version) loop 5 'claude --version' ;;
|
|
bun-build) bun build big.ts --outfile out.js ;;
|
|
# The desktop row (the Firefox disk, whose ~/ffprof was made by a first start).
|
|
ff-page) bash ff-run.sh ~/ffprof file://$d/ff-page.html ;;
|
|
*) echo "unknown row $row" >&2; exit 2 ;;
|
|
esac >/dev/null 2>/tmp/wb-err
|
|
rc=$?
|
|
e=$(date +%s%N)
|
|
[ -s /tmp/wb-info ] && echo "INFO $(cat /tmp/wb-info)" && rm -f /tmp/wb-info
|
|
[ $rc = 0 ] || tail -3 /tmp/wb-err >&2
|
|
echo "RES $row $(( (e - s) / 1000000 )) rc=$rc"
|