From 82fa33ddf153e35c80d6dbecc9105e5ce99f0f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdurrahman=20Kaan=20Dike=C3=A7?= Date: Thu, 17 Sep 2026 20:00:06 +0300 Subject: [PATCH] Toolkit stress tests, one-step kernel build, VPN IPv4-only default, fix broken kernel patches - mu300-toolkit stress [cpu,gpu,net|all] [minutes]: CPU workers on all cores, Mali OpenCL loop, speed test loop (Ookla CLI after EULA acceptance, otherwise speed.cloudflare.com) under the live monitor, then a summary of temperatures, throttling, frequency caps, GPU throughput drift, network results and new kernel warnings - cltest loop [SEC]: GPU stress mode with per-second throughput - kernel/build-all.sh: fetch the pinned ZTE kernel and realme module sources, apply the patches and build Image, in-tree and Wi-Fi/Bluetooth/Mali modules into out/ (verified from an empty docker volume) - of-reserved-mem-skip.patch had a truncated fdt.c header and bluetooth-marlin3-link-policy.patch did not apply: regenerated from the working tree - mu300-vpn: the TUN had an IPv6 address although the tunnel carries no IPv6, so every dual-stack HTTPS connection failed; IPv4-only DNS and TUN unless IPV6=1 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_017Z17MBkdHmZPvNPNSLxcHk --- kernel/build-all.sh | 81 ++++++++ .../bluetooth-marlin3-link-policy.patch | 2 + kernel/patches/of-reserved-mem-skip.patch | 18 +- rootfs/overlay/etc/mu300/vpn.conf.example | 2 + rootfs/overlay/opt/mu300/bin/mu300-toolkit | 194 +++++++++++++++++- rootfs/overlay/opt/mu300/bin/mu300-vpn | 10 +- tools/gpu/cltest.c | 36 ++++ 7 files changed, 324 insertions(+), 19 deletions(-) create mode 100755 kernel/build-all.sh diff --git a/kernel/build-all.sh b/kernel/build-all.sh new file mode 100755 index 00000000..7a4152dd --- /dev/null +++ b/kernel/build-all.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# Build everything install.sh --build and tools/make-release.sh need from public sources, in one step: +# kernel/build-all.sh -> out/Image, out/modules/*.ko, out/modules.builtin* +# Sources (pinned commits, downloaded into the docker volume $MU300_KBUILD_VOLUME on first run): +# ZTE UMS9620 MiFi 5.4.254 kernel (GPL release published by Enceka) +# realme C51/C53 AndroidT kernel_modules: wlan_combo (Wi-Fi), bluetooth tty-pcie, Mali kbase (sparse checkout) +# Needs docker (arm64 host or emulation). Rebuilds incrementally when run again. +set -eu +TOP=$(cd "$(dirname "$0")/.." && pwd) +VOL=${MU300_KBUILD_VOLUME:-mu300-kernel} +OUT=${MU300_KERNEL_OUT:-$TOP/out} +KERNEL_REPO=https://github.com/Enceka/android_kernel_zte_ums9620_mifi_u30air.git +KERNEL_REV=b50db5b6224c11db42a246e8fcdaad1e1d59f478 +MODULES_REPO=https://github.com/realme-kernel-opensource/realme_C51_C53_Narzo-N53-AndroidT-kernel-source.git +MODULES_REV=4381465ccaf87fcf3215b9cd42f4a685df40e5e0 + +docker build -q -t mu300-kbuild "$TOP/kernel" >/dev/null +docker volume create "$VOL" >/dev/null +W=$(mktemp -d) +trap 'rm -rf "$W"' EXIT +# build-linux.sh writes its logs next to the config: give it a scratch copy of kernel/ +cp -R "$TOP/kernel/." "$W/" +cp "$TOP/kernel/f50-stock-B09.config" "$W/device.config" + +docker run --rm -v "$VOL":/src -v "$W":/work \ + -e KERNEL_REPO=$KERNEL_REPO -e KERNEL_REV=$KERNEL_REV -e MODULES_REPO=$MODULES_REPO -e MODULES_REV=$MODULES_REV \ + mu300-kbuild bash -euc ' +fetch() { # fetch DIR REPO REV [sparse paths...]: shallow checkout of one commit + d=$1 repo=$2 rev=$3; shift 3 + [ "$(git -C "$d" rev-parse HEAD 2>/dev/null)" = "$rev" ] && return 0 + rm -rf "$d"; git init -q "$d"; git -C "$d" remote add origin "$repo" + if [ $# -gt 0 ]; then + git -C "$d" sparse-checkout init --cone; git -C "$d" sparse-checkout set "$@" + # partial clone (git 2.25 needs the promisor settings before the first filtered fetch) + git -C "$d" config extensions.partialClone origin + git -C "$d" config remote.origin.promisor true + git -C "$d" config remote.origin.partialclonefilter blob:none + git -C "$d" fetch -q --depth 1 --filter=blob:none origin "$rev" + else + git -C "$d" fetch -q --depth 1 origin "$rev" + fi + git -C "$d" checkout -q FETCH_HEAD +} +echo "==> sources" +fetch /src/zte-u30air "$KERNEL_REPO" "$KERNEL_REV" +cd /src/zte-u30air +# the tree is the pinned commit plus exactly these patches: reapply from a clean checkout whenever they change +KPATCHES="bluetooth-marlin3-link-policy of-reserved-mem-skip regdb-wens-certificate" +sum=$(cd /work/patches && cat $(for p in $KPATCHES; do echo $p.patch; done) | sha256sum | cut -d" " -f1) +if [ "$(cat .mu300-patches 2>/dev/null)" != "$sum" ]; then + git checkout -q -f "$KERNEL_REV" && git clean -q -fdx -e .mu300-patches + for p in $KPATCHES; do patch -p1 -s -f < /work/patches/$p.patch; done + echo "$sum" > .mu300-patches +fi +echo -gb50db5b6224c > .scmversion +M=kernel_modules/kernel5.4 +fetch /src/realme "$MODULES_REPO" "$MODULES_REV" $M/wcn/wlan/wlan_combo $M/wcn/bluetooth/driver $M/gpu/natt/mali +[ -d /src/ext-wlan_combo ] || cp -r /src/realme/$M/wcn/wlan/wlan_combo /src/ext-wlan_combo +[ -d /src/ext-sprdbt ] || cp -r /src/realme/$M/wcn/bluetooth/driver /src/ext-sprdbt +[ -d /src/ext-mali ] || cp -r /src/realme/$M/gpu/natt/mali /src/ext-mali + +echo "==> kernel" +bash /work/build-linux.sh +echo "==> Wi-Fi, Bluetooth, GPU modules" +bash /work/build-wlan.sh >/dev/null +make O=/src/out-linux ARCH=arm64 LLVM=1 LLVM_IAS=1 CC=clang LD=ld.lld -j"$(nproc)" M=/src/ext-sprdbt \ + BSP_BOARD_UNISOC_WCN_SOCKET=pcie modules >/dev/null +bash /work/build-mali.sh >/dev/null + +echo "==> collecting" +rm -rf /work/out && mkdir -p /work/out/modules +cp /src/out-linux/arch/arm64/boot/Image /src/out-linux/modules.builtin /src/out-linux/modules.builtin.modinfo /work/out/ +find /src/out-linux -name "*.ko" -exec cp {} /work/out/modules/ \; +cp /src/ext-wlan_combo/sprd_wlan_combo.ko /src/ext-sprdbt/sprdbt_tty.ko /work/out/modules/ +llvm-strip --strip-debug /work/out/modules/*.ko +echo "$(ls /work/out/modules | wc -l) modules, $(strings /work/out/Image | grep -m1 "^Linux version 5" | cut -d" " -f1-3)" +' +mkdir -p "$OUT" +rm -rf "$OUT/modules" +cp -R "$W/out/." "$OUT/" +echo "kernel outputs in $OUT" diff --git a/kernel/patches/bluetooth-marlin3-link-policy.patch b/kernel/patches/bluetooth-marlin3-link-policy.patch index 3a43d97e..ac025fa9 100644 --- a/kernel/patches/bluetooth-marlin3-link-policy.patch +++ b/kernel/patches/bluetooth-marlin3-link-policy.patch @@ -10,6 +10,8 @@ is rejected). The failure aborts the controller init and makes Park State was removed from the Core specification in 5.0 and Hold Mode is not used by BlueZ, so never request either. +diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c +index 21469934f..2f5b14861 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -504,12 +504,8 @@ static void hci_setup_link_policy(struct hci_request *req) diff --git a/kernel/patches/of-reserved-mem-skip.patch b/kernel/patches/of-reserved-mem-skip.patch index ea7129a3..3248ed8d 100644 --- a/kernel/patches/of-reserved-mem-skip.patch +++ b/kernel/patches/of-reserved-mem-skip.patch @@ -5,9 +5,11 @@ display) and a 16 MiB bootloader sysdump area. CONFIG_OF_RESERVED_MEM_SKIP (or reserved_mem_skip= on the command line) lists node names that are left as normal RAM. The 464 MiB modem and 24 MiB Trusty regions must stay. ---- a/drivers/of/Kconfig 2026-09-16 22:12:33.438467000 +0000 -+++ b/drivers/of/Kconfig 2026-09-16 22:12:33.440151958 +0000 -@@ -81,6 +81,15 @@ +diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig +index d91618641..f36e17ded 100644 +--- a/drivers/of/Kconfig ++++ b/drivers/of/Kconfig +@@ -81,6 +81,15 @@ config OF_MDIO help OpenFirmware MDIO bus (Ethernet PHY) accessors @@ -23,9 +25,11 @@ as normal RAM. The 464 MiB modem and 24 MiB Trusty regions must stay. config OF_RESERVED_MEM bool depends on OF_EARLY_FLATTREE ---- a/drivers/of/fd -+++ b/drivers/of/fd -@@ -539,6 +539,33 @@ +diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c +index 109619c1f..a26685669 100644 +--- a/drivers/of/fdt.c ++++ b/drivers/of/fdt.c +@@ -539,6 +539,33 @@ static int __init __reserved_mem_check_root(unsigned long node) return 0; } @@ -59,7 +63,7 @@ as normal RAM. The 464 MiB modem and 24 MiB Trusty regions must stay. /** * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory */ -@@ -568,6 +595,11 @@ +@@ -568,6 +595,11 @@ static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname, if (!of_fdt_device_is_available(initial_boot_params, node)) return 0; diff --git a/rootfs/overlay/etc/mu300/vpn.conf.example b/rootfs/overlay/etc/mu300/vpn.conf.example index bf437c64..1092affe 100644 --- a/rootfs/overlay/etc/mu300/vpn.conf.example +++ b/rootfs/overlay/etc/mu300/vpn.conf.example @@ -11,5 +11,7 @@ REMOTE_DNS=1.1.1.1 BOOTSTRAP_DNS=1.1.1.1 # networks that stay local (USB/Wi-Fi LAN) LAN_CIDRS=192.168.77.0/24 +# 1: also carry IPv6 (only if the server has IPv6 connectivity; 0 keeps DNS and the tunnel IPv4-only) +IPV6=0 # optional: reach the VPN server through an HTTP proxy (host:port), e.g. for testing over a PC's connection UPSTREAM_HTTP_PROXY= diff --git a/rootfs/overlay/opt/mu300/bin/mu300-toolkit b/rootfs/overlay/opt/mu300/bin/mu300-toolkit index 6bae73ba..3057a30f 100755 --- a/rootfs/overlay/opt/mu300/bin/mu300-toolkit +++ b/rootfs/overlay/opt/mu300/bin/mu300-toolkit @@ -4,6 +4,7 @@ # mu300-toolkit top live monitor: CPU/core load and frequency, RAM, temperatures, network rates, processes # mu300-toolkit info one-shot summary # mu300-toolkit profile [eco|balanced|performance] +# mu300-toolkit stress [cpu,gpu,net|all] [MINUTES] stress test with live monitor and a summary (0 = until q) # mu300-toolkit apply apply the saved settings (boot service) export PATH="$PATH:/opt/mu300/bin:/opt/mu300/busybox-bin:/usr/sbin:/sbin" CONF=/etc/mu300/toolkit.conf @@ -126,6 +127,7 @@ snapshot() { "$CPUFREQ"/policy*/related_cpus "$CPUFREQ"/policy*/scaling_governor \ ${GPU:+"$GPU/cur_freq"} 2>/dev/null echo @proc; cat /proc/[0-9]*/stat 2>/dev/null + if [ -n "$STRESS_DIR" ]; then echo @extra; stress_status; fi echo @end } @@ -174,6 +176,7 @@ sec == "sys" { else if (leaf == "scaling_governor") pgov[node] = val else if (leaf == "cur_freq") gpuf = val } +sec == "extra" { nextra++; extra[nextra] = $0; next } sec == "proc" { o = index($0, " ("); c = 0; for (i = length($0); i > 0; i--) if (substr($0, i, 1) == ")") { c = i; break } if (!o || !c) next @@ -189,6 +192,7 @@ END { row = 0 printf "\033[H" line(sprintf("%s mu300-toolkit %s %s up %dd %02dh%02dm load %s profile %s%s%s %s[q] quit%s", BO CY, NO BO, host, up / 86400, up % 86400 / 3600, up % 3600 / 60, load, CY, profile, NO, DI, NO)) + for (i = 1; i <= nextra; i++) line(YE extra[i] NO) line("") thrs = thr ? YE "throttling (" thr " limits)" NO : GR "not throttling" NO line(sprintf("%sCPU%s %s %5.1f%% %s", BO, NO, bar(busy["cpu"], 30), busy["cpu"], thrs)) @@ -241,7 +245,8 @@ monitor() { hz=$(getconf CLK_TCK 2>/dev/null || echo 100) host=$(cat /proc/sys/kernel/hostname) old=$(stty -g 2>/dev/null) - trap 'stty "$old" 2>/dev/null; printf "\033[?25h\n"; rm -f "$state"; exit 0' INT TERM + MON_STOP= + trap 'MON_STOP=1' INT TERM stty -icanon -echo min 0 time $((interval * 10)) 2>/dev/null printf '\033[?25l\033[2J' dt=$interval @@ -251,11 +256,178 @@ monitor() { snapshot | awk -v prevfile="$state" -v dt="$dt" -v hz="$hz" -v rows="$rows" -v host="$host" -v profile="$profile" "$MONITOR_AWK" key=$(dd bs=1 count=1 2>/dev/null) case $key in q|Q) break ;; esac + [ -n "$MON_STOP" ] && break + [ -n "${MON_UNTIL:-}" ] && [ "$(date +%s)" -ge "$MON_UNTIL" ] && break done stty "$old" 2>/dev/null; printf '\033[?25h\033[2J\033[H'; rm -f "$state" trap - INT TERM } +# ---------------------------------------------------------------- stress tests +STRESS_DIR= +CLTEST=/opt/mu300/android/system/bin/cltest + +kill_tree() { # kill_tree PID: the process and all of its descendants + for c in $(cat /proc/[0-9]*/stat 2>/dev/null | awk -v p="$1" '{ r = substr($0, index($0, ") ") + 2); split(r, f, " "); if (f[2] == p) print $1 }'); do + kill_tree "$c" + done + kill "$1" 2>/dev/null +} +fmt_dur() { printf '%02d:%02d' $(($1 / 60)) $(($1 % 60)); } + +stress_cpu() { + n=$(grep -c '^processor' /proc/cpuinfo) + if command -v stress-ng >/dev/null; then + stress-ng --cpu "$n" --cpu-method matrixprod >/dev/null 2>&1 & echo $! >> "$STRESS_DIR/pids" + else + i=0 + while [ "$i" -lt "$n" ]; do + awk 'BEGIN { for (;;) x = sin(x) + sqrt(x * x + 1) }' & echo $! >> "$STRESS_DIR/pids" + i=$((i + 1)) + done + fi +} + +# Mali GPU through Android's OpenCL driver in the vendor chroot (tools/gpu/cltest loop) +stress_gpu() { + /opt/mu300/bin/android-gpu-run /system/bin/cltest loop 0 > "$STRESS_DIR/gpu.log" 2>&1 & echo $! >> "$STRESS_DIR/pids" +} + +net_once() { + t=$(date +%H:%M:%S) + if [ "$NET_TOOL" = ookla ]; then + # tsv: server, id, latency ms, jitter, loss, download B/s, upload B/s, ... + r=$(speedtest --accept-license --accept-gdpr -f tsv 2>/dev/null | awk -F'\t' -v t="$t" \ + 'NF >= 7 && $6 > 0 { printf "%s down %.1f up %.1f Mbit/s ping %.0f ms (%s)\n", t, $6 * 8 / 1e6, $7 * 8 / 1e6, $3, $1 }') + else + # speed.cloudflare.com refuses downloads above 50 MB (403); -f turns HTTP errors into a failed run + d=$(curl -fs -o /dev/null -m 30 -w '%{speed_download}' 'https://speed.cloudflare.com/__down?bytes=50000000'); rc=$? + [ "$rc" = 0 ] || [ "$rc" = 28 ] || d=0 + u=$(head -c 25000000 /dev/zero | curl -fs -o /dev/null -m 30 -w '%{speed_upload}' --data-binary @- https://speed.cloudflare.com/__up) || u=0 + r=$(awk -v t="$t" -v d="${d:-0}" -v u="${u:-0}" 'BEGIN { if (d + u > 0) printf "%s down %.1f up %.1f Mbit/s (speed.cloudflare.com)\n", t, d * 8 / 1e6, u * 8 / 1e6 }') + # curl exit 28 is the time limit: the average speed is still valid + [ -n "$r" ] || r="$t failed (curl exit $rc)" + fi + echo "${r:-$t failed}" +} +stress_net() { + ( while [ ! -e "$STRESS_DIR/stop" ]; do net_once >> "$STRESS_DIR/net.log"; sleep 2; done ) & echo $! >> "$STRESS_DIR/pids" +} + +# every 2 s: time, hottest sensor, active cooling devices, cur freq per policy, max freq per policy +stress_sampler() { + ( while [ ! -e "$STRESS_DIR/stop" ]; do + hot=$(cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null | sort -n | tail -n1) + echo "$(date +%s) $hot $(throttle_state | wc -w) $(cat "$CPUFREQ"/policy*/scaling_cur_freq | tr '\n' ' ')$(cat "$CPUFREQ"/policy*/scaling_max_freq | tr '\n' ' ')" + sleep 2 + done > "$STRESS_DIR/samples" ) & echo $! >> "$STRESS_DIR/pids" +} + +stress_status() { + el=$(( $(date +%s) - STRESS_START )) + printf 'STRESS %s %s / %s [q] stop\n' "$STRESS_WHAT" "$(fmt_dur "$el")" "$( [ "$STRESS_SECS" -gt 0 ] && fmt_dur "$STRESS_SECS" || echo "until q")" + case ",$STRESS_WHAT," in *,gpu,*) printf ' %s\n' "$(tail -n1 "$STRESS_DIR/gpu.log" 2>/dev/null | cut -c1-100)" ;; esac + case ",$STRESS_WHAT," in *,net,*) printf ' net: %s (%s runs)\n' "$(tail -n1 "$STRESS_DIR/net.log" 2>/dev/null)" "$(wc -l < "$STRESS_DIR/net.log" 2>/dev/null || echo 0)" ;; esac +} + +stress_summary() { + el=$(( $(date +%s) - STRESS_START )) + hw=$(cat "$CPUFREQ"/policy*/cpuinfo_max_freq | tr '\n' ' ') + printf 'mu300-toolkit stress test: %s, %s, profile %s, %s\n\n' "$STRESS_WHAT" "$(fmt_dur "$el")" "$(current_profile)" "$(date '+%Y-%m-%d %H:%M')" + awk -v hw="$hw" ' + { n++; t = $2 / 1000; if (n == 1) first = t; last = t; if (t > max) max = t; if ($3 > 0) thr++ + np = (NF - 3) / 2 + for (i = 1; i <= np; i++) { sum[i] += $(3 + i); c = $(3 + np + i); if (!(i in cap) || c < cap[i]) cap[i] = c } } + END { + if (!n) { print "no samples"; exit } + printf "Temperature start %.0f C, max %.0f C, end %.0f C\n", first, max, last + printf "Throttling %.0f%% of the time\n", 100 * thr / n + split(hw, h, " "); split("little mid big", lbl, " ") + for (i = 1; i <= np; i++) + printf "CPU %-7s avg %4.0f MHz, lowest cap %4.0f MHz of %4.0f MHz\n", (np == 3 ? lbl[i] : "policy" i), sum[i] / n / 1000, cap[i] / 1000, h[i] / 1000 + }' "$STRESS_DIR/samples" + if [ -s "$STRESS_DIR/gpu.log" ]; then + awk '/runs\/s/ { v = $3 + 0; n++; a[n] = v; s += v } + END { + if (!n) { print "GPU no result (OpenCL not available?)"; exit } + k = n < 30 ? n : 30; for (i = 1; i <= k; i++) { f += a[i]; l += a[n - k + i] } + printf "GPU avg %.2f runs/s, first %ds %.2f, last %ds %.2f (%+.0f%%)\n", s / n, k, f / k, k, l / k, f ? 100 * (l - f) / f : 0 + }' "$STRESS_DIR/gpu.log" + grep -v 'runs/s' "$STRESS_DIR/gpu.log" | grep -iE 'error|fail|enqueue|clBuild' | head -n3 | sed 's/^/ /' + fi + if [ -s "$STRESS_DIR/net.log" ]; then + awk '/ down / { n++; d = $3; u = $5; sd += d; su += u; if (n == 1 || d < mind) mind = d; if (d > maxd) maxd = d; if (n == 1 || u < minu) minu = u; if (u > maxu) maxu = u } + / failed$/ { fail++ } + END { printf "Network %d runs, %d failed", n, fail + if (n) printf "; down avg %.1f (%.1f-%.1f), up avg %.1f (%.1f-%.1f) Mbit/s", sd / n, mind, maxd, su / n, minu, maxu + printf "\n" }' "$STRESS_DIR/net.log" + fi + kmsg=$(dmesg 2>/dev/null | tail -n +"$((STRESS_DMESG + 1))" | grep -iE 'error|fail|warn|oops|bug|watchdog|hung|lockup|over.?temp|critical' | grep -v 'hw csum') + printf 'Kernel %s new warning/error lines\n' "$(printf '%s' "$kmsg" | grep -c .)" + printf '%s' "$kmsg" | head -n5 | cut -c1-150 | sed 's/^/ /' + if command -v systemctl >/dev/null; then + f=$(systemctl --failed --no-legend --plain 2>/dev/null | awk '{print $1}' | tr '\n' ' ') + printf 'Services failed: %s\n' "${f:-none}" + fi +} + +stress_run() { # stress_run WHAT(cpu,gpu,net|all) SECONDS + STRESS_WHAT=$1; [ "$STRESS_WHAT" = all ] && STRESS_WHAT=cpu,gpu,net + STRESS_SECS=${2:-600} + case ",$STRESS_WHAT," in *,gpu,*) + [ -x "$CLTEST" ] || { echo "GPU test needs $CLTEST (tools/gpu/cltest) and the Android GPU subset" >&2; return 1; } ;; + esac + NET_TOOL= + case ",$STRESS_WHAT," in *,net,*) + if command -v speedtest >/dev/null && speedtest --version 2>/dev/null | grep -q Ookla && [ "$(conf_get OOKLA_ACCEPTED)" = 1 ]; then NET_TOOL=ookla + elif command -v curl >/dev/null; then NET_TOOL=curl + else echo "network test needs curl or the Ookla speedtest CLI" >&2; return 1; fi ;; + esac + STRESS_DIR=$(mktemp -d "${TMPDIR:-/tmp}/mu300-stress.XXXXXX") + STRESS_START=$(date +%s) + STRESS_DMESG=$(dmesg 2>/dev/null | wc -l) + stress_sampler + case ",$STRESS_WHAT," in *,cpu,*) stress_cpu ;; esac + case ",$STRESS_WHAT," in *,gpu,*) stress_gpu ;; esac + case ",$STRESS_WHAT," in *,net,*) stress_net ;; esac + MON_UNTIL=; [ "$STRESS_SECS" -gt 0 ] && MON_UNTIL=$((STRESS_START + STRESS_SECS)) + if [ -t 0 ] && [ -t 1 ]; then + monitor 2 + else + while [ -z "$MON_UNTIL" ] || [ "$(date +%s)" -lt "$MON_UNTIL" ]; do sleep 5; done + fi + MON_UNTIL= + touch "$STRESS_DIR/stop" + for pid in $(cat "$STRESS_DIR/pids"); do kill_tree "$pid"; done + wait 2>/dev/null + out=/var/log/mu300-stress-$(date +%Y%m%d-%H%M%S).txt + stress_summary | tee "$out" + printf '\nsaved to %s\n' "$out" + rm -rf "$STRESS_DIR"; STRESS_DIR= +} + +menu_stress() { + title "Stress test" + printf ' Loads the device while the monitor runs, then prints a summary (temperatures, throttling,\n' + printf ' frequencies, GPU throughput, speed test results, new kernel warnings). q stops early.\n\n' + printf ' %s1%s CPU, all cores\n %s2%s GPU (Mali, OpenCL)\n %s3%s Network (speed test in a loop)\n' "$C" "$N" "$C" "$N" "$C" "$N" + printf ' %s4%s CPU + GPU\n %s5%s Everything (CPU + GPU + network)\n\n %s0%s Back\n\n > ' "$C" "$N" "$C" "$N" "$C" "$N" + read -r c || return + case $c in 1) w=cpu ;; 2) w=gpu ;; 3) w=net ;; 4) w=cpu,gpu ;; 5) w=all ;; *) return ;; esac + printf ' Duration in minutes [10, 0 = until q]: '; read -r m + m=${m:-10}; [ "$m" -ge 0 ] 2>/dev/null || m=10 + case $w in *net*|all) + if command -v speedtest >/dev/null && speedtest --version 2>/dev/null | grep -q Ookla && [ "$(conf_get OOKLA_ACCEPTED)" != 1 ]; then + printf '\n The Ookla Speedtest CLI is installed. Using it means accepting Ookla'"'"'s EULA and privacy policy\n' + printf ' (https://www.speedtest.net/about/eula, https://www.speedtest.net/about/privacy).\n' + printf ' Accept and use Speedtest? [y/N] (N uses speed.cloudflare.com instead) '; read -r a + case $a in y|Y) conf_set OOKLA_ACCEPTED 1 ;; esac + fi ;; + esac + stress_run "$w" $((m * 60)) + pause +} + # ---------------------------------------------------------------- info info() { . /etc/os-release 2>/dev/null @@ -411,15 +583,16 @@ menu_system() { main_menu() { while :; do - menu "Main menu" "Monitor (task manager)" "Performance profile (CPU/GPU)" "Network, mobile data, VPN" \ - "Services" "System (password, hostname, timezone, reboot)" "Summary" + menu "Main menu" "Monitor (task manager)" "Performance profile (CPU/GPU)" "Stress test (CPU/GPU/network)" \ + "Network, mobile data, VPN" "Services" "System (password, hostname, timezone, reboot)" "Summary" case $CHOICE in 1) monitor ;; 2) menu_performance ;; - 3) menu_network ;; - 4) menu_services ;; - 5) menu_system ;; - 6) title "Summary"; info; pause ;; + 3) menu_stress ;; + 4) menu_network ;; + 5) menu_services ;; + 6) menu_system ;; + 7) title "Summary"; info; pause ;; *) printf '\033[H\033[2J'; exit 0 ;; esac done @@ -432,9 +605,12 @@ case ${1:-menu} in profile) if [ -z "${2:-}" ]; then profile_show; exit 0; fi need_root "$@"; profile_apply "$2" && conf_set CPU_PROFILE "$2" && profile_show ;; + stress) + need_root "$@" + stress_run "${2:-all}" $(( ${3:-10} * 60 )) ;; apply) p=$(conf_get CPU_PROFILE) [ -n "$p" ] && profile_apply "$p" && echo "applied profile $p" ;; - -h|--help|help) sed -n '2,7s/^# \{0,1\}//p' "$0" ;; - *) echo "usage: mu300-toolkit [menu|top [seconds]|info|profile [eco|balanced|performance]|apply]" >&2; exit 2 ;; + -h|--help|help) sed -n '2,8s/^# \{0,1\}//p' "$0" ;; + *) echo "usage: mu300-toolkit [menu|top [seconds]|info|profile [eco|balanced|performance]|stress [cpu,gpu,net|all] [minutes]|apply]" >&2; exit 2 ;; esac diff --git a/rootfs/overlay/opt/mu300/bin/mu300-vpn b/rootfs/overlay/opt/mu300/bin/mu300-vpn index d1404830..30ec14ec 100755 --- a/rootfs/overlay/opt/mu300/bin/mu300-vpn +++ b/rootfs/overlay/opt/mu300/bin/mu300-vpn @@ -13,7 +13,7 @@ TUN=sbtun MARK=0x2d0 # routing mark on sing-box's own connections: they bypass the tunnel and the kill switch [ -r "$CONF" ] && . "$CONF" ENABLE=${ENABLE:-0}; KILL_SWITCH=${KILL_SWITCH:-1}; REMOTE_DNS=${REMOTE_DNS:-1.1.1.1} -BOOTSTRAP_DNS=${BOOTSTRAP_DNS:-1.1.1.1}; LAN_CIDRS=${LAN_CIDRS:-192.168.77.0/24} +BOOTSTRAP_DNS=${BOOTSTRAP_DNS:-1.1.1.1}; LAN_CIDRS=${LAN_CIDRS:-192.168.77.0/24}; IPV6=${IPV6:-0} # json_str VALUE : JSON string literal json_str() { printf '"%s"' "$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')"; } @@ -95,8 +95,12 @@ gen() { else printf '{"type":"udp","tag":"bootstrap","server":%s}],' "$(json_str "$BOOTSTRAP_DNS")" fi - printf '"final":"remote","strategy":"prefer_ipv4"},\n' - printf '"inbounds":[{"type":"tun","tag":"tun-in","interface_name":"%s","address":["172.19.0.1/30","fdfe:dcba:9876::1/126"],"mtu":1400,' "$TUN" + # IPv6 through the tunnel only when the server side has it: otherwise programs prefer the (dead) IPv6 route and + # every connection to a dual-stack host fails first, so DNS answers only A records and the TUN gets no IPv6 address + if [ "$IPV6" = 1 ]; then strategy=prefer_ipv4; addrs='"172.19.0.1/30","fdfe:dcba:9876::1/126"' + else strategy=ipv4_only; addrs='"172.19.0.1/30"'; fi + printf '"final":"remote","strategy":"%s"},\n' "$strategy" + printf '"inbounds":[{"type":"tun","tag":"tun-in","interface_name":"%s","address":[%s],"mtu":1400,' "$TUN" "$addrs" printf '"auto_route":true,"strict_route":true,"route_exclude_address":%s}],\n' "$excl" printf '"outbounds":['; outbound_json [ -n "$UPSTREAM_HTTP_PROXY" ] && printf ',{"type":"http","tag":"upstream","server":%s,"server_port":%s}' "$(json_str "${UPSTREAM_HTTP_PROXY%:*}")" "${UPSTREAM_HTTP_PROXY##*:}" diff --git a/tools/gpu/cltest.c b/tools/gpu/cltest.c index fbd00112..1c1eb29f 100644 --- a/tools/gpu/cltest.c +++ b/tools/gpu/cltest.c @@ -1,12 +1,18 @@ /* * cltest: probe the Mali GPU through Android's OpenCL driver and run a vector addition. * Built for bionic without the NDK (see build.sh); runs inside the Android vendor chroot. + * cltest probe and one verified vector addition + * cltest loop [SEC] GPU stress: run a heavy kernel repeatedly for SEC seconds (0 = until killed), + * printing the throughput every second * SPDX-License-Identifier: MIT */ #include #include int printf(const char *, ...); +int atoi(const char *); +int strcmp(const char *, const char *); +int fflush(void *); void *malloc(size_t); struct timespec { long tv_sec; long tv_nsec; }; int clock_gettime(int, struct timespec *); @@ -48,6 +54,12 @@ static const char *src = "__kernel void add(__global float *a, __global float *b, __global float *c) {" " size_t i = get_global_id(0); c[i] = a[i] * a[i] + b[i]; }"; +static const char *burn_src = + "__kernel void burn(__global float *a, __global float *c) {" + " float x = a[get_global_id(0)];" + " for (int k = 0; k < 48; k++) x = sqrt(x * x + 1.0f) * 0.5f + sin(x) * cos(x * 0.5f);" + " c[get_global_id(0)] = x; }"; + static double now(void) { struct timespec t; @@ -84,6 +96,30 @@ int main(int argc, char **argv, char **envp) cl_mem bc = clCreateBuffer(ctx, CL_MEM_WRITE_ONLY, N * sizeof(float), NULL, &err); cl_program p = clCreateProgramWithSource(ctx, 1, &src, NULL, &err); if ((err = clBuildProgram(p, 1, &dev, "", NULL, NULL))) { printf("clBuildProgram: %d\n", err); return 1; } + if (argc > 1 && !strcmp(argv[1], "loop")) { + int secs = argc > 2 ? atoi(argv[2]) : 60; + cl_program bp = clCreateProgramWithSource(ctx, 1, &burn_src, NULL, &err); + if ((err = clBuildProgram(bp, 1, &dev, "", NULL, NULL))) { printf("clBuildProgram: %d\n", err); return 1; } + cl_kernel bk = clCreateKernel(bp, "burn", &err); + clSetKernelArg(bk, 0, sizeof(cl_mem), &ba); + clSetKernelArg(bk, 1, sizeof(cl_mem), &bc); + size_t n = N; + double start = now(), mark = start; + long runs = 0, total = 0; + for (;;) { + if ((err = clEnqueueNDRangeKernel(q, bk, 1, NULL, &n, NULL, 0, NULL, NULL))) { printf("enqueue: %d\n", err); return 1; } + clFinish(q); + runs++; total++; + double t = now(); + if (t - mark >= 1.0) { + printf("gpu stress: %.2f runs/s (%.1f M elements/s), %ld runs in %.0f s\n", + runs / (t - mark), runs * (double)N / 1e6 / (t - mark), total, t - start); + fflush(NULL); + runs = 0; mark = t; + } + if (secs > 0 && t - start >= secs) return 0; + } + } cl_kernel k = clCreateKernel(p, "add", &err); clSetKernelArg(k, 0, sizeof(cl_mem), &ba); clSetKernelArg(k, 1, sizeof(cl_mem), &bb);