Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
APFS benchmarks: the cores at full speed, and the checker's own hashing kept apart
vcvkk2b0103edd7c0
diff --git a/tools/apfs/bench-phone.sh b/tools/apfs/bench-phone.shindex 8325017..b9c04bf 100755--- a/tools/apfs/bench-phone.sh+++ b/tools/apfs/bench-phone.sh@@ -6,19 +6,24 @@# usage: tools/apfs/bench-phone.sh "1 2 4 8" [extra boot-args]# env: BENCH_KERNEL a kernel to put in place first (default: whatever is built)# BENCH_CPUS cpus=N for the kernel (default 8)+# BENCH_FREQ cpufreq=N (default 1: every group of cores at its top speed). Without it the+# cores keep whatever speed the run before left them at -- the loader does not+# reset it -- and the same kernel measured 3.4 times slower one evening than+# the afternoon before.set -uHERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)ROOT=$(cd "$HERE/../.." && pwd)COUNTS=${1:-"1 2 4 8"}EXTRA=${2:-}CPUS=${BENCH_CPUS:-8}+FREQ=${BENCH_FREQ:-1}cd "$ROOT" || exit 1K=xnu-src/xnu-8796.121.2/BUILD/obj/DEVELOPMENT_ARM64_BCM2837/mach.development.bcm2837[ -n "${BENCH_KERNEL:-}" ] && cp -p "$BENCH_KERNEL" "$K"-printf "%-7s %9s %8s %12s %12s %10s %4s %s\n" readers wall_ms MB/s lock_wait_ms lock_held_ms inflate_ms bad sums+printf "%-7s %9s %8s %12s %12s %10s %8s %4s %s\n" readers wall_ms MB/s lock_wait_ms lock_held_ms inflate_ms hash_ms bad sumsfor n in $COUNTS; do- out=$(XL_CMDLINE="cpus=$CPUS apfs_check=5 apfs_threads=$n $EXTRA" XL_SECS=300 \+ out=$(XL_CMDLINE="cpus=$CPUS cpufreq=$FREQ apfs_check=5 apfs_threads=$n $EXTRA" XL_SECS=300 \timeout 500 ./xl run 2>&1)log=$(echo "$out" | grep -o 'logs/[0-9]*-run.log' | tail -1)if [ -z "$log" ] || ! grep -aq "readers done in" "$log" 2>/dev/null; then@@ -29,9 +34,14 @@ for n in $COUNTS; dokbs=$(grep -ao "bytes [0-9]* KB/s" "$log" | head -1 | awk '{print $2}')lock=$(grep -a "apfs: lock" "$log" | head -1 | sed 's/^\[[^]]*\]: //')infl=$(grep -a "apfs: inflate" "$log" | head -1 | sed 's/^\[[^]]*\]: //' | awk '{print $5}')+ # the checker's own FNV time, all readers together ("off" with apfs_hash=0)+ hash=$(grep -ao "ms hash [a-z ]*[0-9]* ms" "$log" | awk '{ if ($3 == "off") off = 1; t += $(NF-1) }+ END { if (NR == 0) print "-"; else if (off) print "off"; else print t }')bad=$(grep -ao "readers that disagreed or failed: [0-9]*" "$log" | head -1 | awk '{print $6}')sums=$(grep -ao "sum [0-9a-f]\{16\}" "$log" | sort -u | awk '{print $2}' | tr '\n' ' ')- printf "%-7s %9s %8s %12s %12s %10s %4s %s [%s]\n" "$n" "$wall" \+ freq=$(grep -ao "cpufreq: on core [0-9]* a loop ran at [0-9]*, now at [0-9]*" "$log" | head -1 |+ awk '{print $9 $12}' | tr ',' '>')+ printf "%-7s %9s %8s %12s %12s %10s %8s %4s %s [%s %s]\n" "$n" "$wall" \"$(echo "scale=1; $kbs / 1024" | bc)" "$(echo "$lock" | awk '{print $5}')" \- "$(echo "$lock" | awk '{print $8}')" "$infl" "$bad" "$sums" "$log"+ "$(echo "$lock" | awk '{print $8}')" "$infl" "$hash" "$bad" "$sums" "$log" "${freq:-freq?}"donediff --git a/xnu/files/bsd/dev/redwood_apfs_check.c b/xnu/files/bsd/dev/redwood_apfs_check.cindex 7be62d0..573a4a8 100644--- a/xnu/files/bsd/dev/redwood_apfs_check.c+++ b/xnu/files/bsd/dev/redwood_apfs_check.c@@ -149,6 +149,15 @@ struct census {uint64_t max_entries; /* 0: no limit */bool stop;uint64_t t0; /* when the walk started, for the progress line */+ /*+ * FNV-1a goes a byte at a time, each step waiting on the one before: about three+ * cycles a byte, more than a second over the restore ramdisk -- the checker's own+ * time, not the filesystem's. Boot-arg apfs_hash=0 reads every byte all the same and+ * does not hash it (the sums are then not the ones to compare); hash_ticks is how+ * long the hashing took otherwise.+ */+ bool no_hash;+ uint64_t hash_ticks;};/* The format bits of a mode, which vnode_getattr does not report in va_mode. */@@ -186,7 +195,12 @@ hash_file(struct census *cs, vnode_t vp, uint64_t size, uint64_t *out)if (resid == want) {break; /* nothing more to be had */}- h = fnv1a(cs->buf, (size_t)(want - resid), h);+ if (!cs->no_hash) {+ uint64_t t0 = mach_absolute_time();++ h = fnv1a(cs->buf, (size_t)(want - resid), h);+ cs->hash_ticks += mach_absolute_time() - t0;+ }cs->bytes += (uint64_t)(want - resid);off += (uint64_t)(want - resid);}@@ -574,10 +588,13 @@ apfs_walk_one(void *arg, __unused wait_result_t wr){struct walk_job *job = arg;struct census cs;- uint64_t start, end, ns = 0;+ uint64_t start, end, ns = 0, hash_ns = 0;+ uint32_t hash = 1;bzero(&cs, sizeof(cs));cs.ctx = vfs_context_kernel();+ PE_parse_boot_argn("apfs_hash", &hash, sizeof(hash));+ cs.no_hash = (hash == 0);PE_parse_boot_argn("apfs_depth", &cs.max_depth, sizeof(cs.max_depth));PE_parse_boot_argn("apfs_max", &cs.max_entries, sizeof(cs.max_entries));{@@ -600,6 +617,7 @@ apfs_walk_one(void *arg, __unused wait_result_t wr)census_dir(&cs);end = mach_absolute_time();absolutetime_to_nanoseconds(end - start, &ns);+ absolutetime_to_nanoseconds(cs.hash_ticks, &hash_ns);job->ms = ns / 1000000;job->entries = cs.entries;@@ -607,8 +625,9 @@ apfs_walk_one(void *arg, __unused wait_result_t wr)job->sum = cs.sum;job->errors = cs.errors;printf("apfs-check: reader %d: %llu entries %llu bytes sum %016llx errors %u "- "%llu ms\n", job->index, cs.entries, cs.bytes,- (unsigned long long)cs.sum, cs.errors, job->ms);+ "%llu ms hash %s%llu ms\n", job->index, cs.entries, cs.bytes,+ (unsigned long long)cs.sum, cs.errors, job->ms, cs.no_hash ? "off " : "",+ hash_ns / 1000000);kfree_data(cs.path, PATH_CAP);kfree_data(cs.buf, READ_CHUNK);