From ff1d3962ecbfe570e4ab7e7d49a1e5acfa5b1249 Mon Sep 17 00:00:00 2001 From: Douglas Teles Date: Sat, 18 Apr 2026 14:30:31 -0300 Subject: [PATCH] FASE 1: Switch ZRAM to zstd, disable zswap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ZRAM compression: lzo-rle → zstd (better 1:3 ratio vs 1:2.5, saves ~50MB more RAM on 512MB ZRAM at cost of slightly more CPU) - Add zswap.enabled=0 to kernel cmdline (zswap intercepts before ZRAM, preventing efficient compressed swap) Co-Authored-By: Claude Opus 4.6 (1M context) --- projects/ArchR/devices/RK3326/options | 4 +- tools/bench.sh | 103 ++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100755 tools/bench.sh diff --git a/projects/ArchR/devices/RK3326/options b/projects/ArchR/devices/RK3326/options index c42c5ba20f..8b7a68b310 100644 --- a/projects/ArchR/devices/RK3326/options +++ b/projects/ArchR/devices/RK3326/options @@ -36,7 +36,7 @@ KERNEL_MAKE_EXTRACMD=" $(get_kernel_make_extracmd)" # Kernel cmdline - EXTRA_CMDLINE="quiet console=ttyS2,1500000 console=tty0 loglevel=0 vt.global_cursor_default=0 consoleblank=0 net.ifnames=0 systemd.show_status=false mitigations=off audit=0 nowatchdog threadirqs loop.max_loop=16" + EXTRA_CMDLINE="quiet console=ttyS2,1500000 console=tty0 loglevel=0 vt.global_cursor_default=0 consoleblank=0 net.ifnames=0 systemd.show_status=false mitigations=off audit=0 nowatchdog threadirqs zswap.enabled=0 loop.max_loop=16" # Bootloader to use (syslinux / u-boot) BOOTLOADER="u-boot" @@ -76,7 +76,7 @@ DEBUG_TTY="/dev/ttyS2" # ZRAM Algorithm - ZRAM_COMPRESSION_ALGO="lzo-rle" + ZRAM_COMPRESSION_ALGO="zstd" # ZRAM Size ZRAM_SWAP_SIZE="512" diff --git a/tools/bench.sh b/tools/bench.sh new file mode 100755 index 0000000000..d49cd9d62b --- /dev/null +++ b/tools/bench.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# ArchR Performance Benchmark Script +# Run on device: bash /flash/bench.sh [duration_seconds] +# Results saved to /storage/bench-results/ + +DURATION=${2:-60} +RESULTS_DIR="/storage/bench-results/$(date +%Y%m%d-%H%M%S)-${1:-general}" +mkdir -p "$RESULTS_DIR" + +echo "========================================" +echo " ArchR Benchmark: ${1:-general}" +echo " Duration: ${DURATION}s" +echo " Output: $RESULTS_DIR" +echo "========================================" + +# Metadata +cat > "$RESULTS_DIR/meta.json" << METAEOF +{ + "timestamp": "$(date -Iseconds)", + "kernel": "$(uname -r)", + "distro": "$(grep ^NAME /etc/os-release | cut -d= -f2)", + "cpu_governor": "$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null)", + "gpu_governor": "$(cat /sys/class/devfreq/ff400000.gpu/governor 2>/dev/null)", + "dmc_governor": "$(cat /sys/class/devfreq/dmc/governor 2>/dev/null)", + "mem_available_kb": $(grep MemAvailable /proc/meminfo | awk '{print $2}'), + "cma_total_kb": $(grep CmaTotal /proc/meminfo | awk '{print $2}'), + "cma_free_kb": $(grep CmaFree /proc/meminfo | awk '{print $2}'), + "zram_algo": "$(cat /sys/block/zram0/comp_algorithm 2>/dev/null | tr -d '[]')", + "swap": "$(swapon --show --noheadings 2>/dev/null | head -1)", + "swappiness": $(sysctl -n vm.swappiness 2>/dev/null), + "vfs_cache_pressure": $(sysctl -n vm.vfs_cache_pressure 2>/dev/null), + "temperature_start": $(cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null), + "sd_model": "$(cat /sys/block/mmcblk0/device/name 2>/dev/null)", + "scenario": "${1:-general}" +} +METAEOF + +# PSI monitoring (background) +echo "Starting PSI monitoring..." +( + while true; do + echo "$(date +%s.%N) $(cat /proc/pressure/cpu 2>/dev/null | head -1) $(cat /proc/pressure/memory 2>/dev/null | head -1) $(cat /proc/pressure/io 2>/dev/null | head -1)" + sleep 1 + done +) > "$RESULTS_DIR/psi.log" & +PSI_PID=$! + +# Frequency + temperature monitoring (background) +echo "Starting freq/temp monitoring..." +( + while true; do + CPU_FREQ=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq 2>/dev/null) + GPU_FREQ=$(cat /sys/class/devfreq/ff400000.gpu/cur_freq 2>/dev/null) + DMC_FREQ=$(cat /sys/class/devfreq/dmc/cur_freq 2>/dev/null) + TEMP=$(cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null) + MEM=$(grep MemAvailable /proc/meminfo | awk '{print $2}') + echo "$(date +%s.%N) cpu=$CPU_FREQ gpu=$GPU_FREQ dmc=$DMC_FREQ temp=$TEMP mem=$MEM" + sleep 1 + done +) > "$RESULTS_DIR/freq-therm.log" & +FREQ_PID=$! + +# vmstat monitoring +vmstat 1 $DURATION > "$RESULTS_DIR/vmstat.log" & +VMSTAT_PID=$! + +# dmesg monitoring +dmesg -w > "$RESULTS_DIR/dmesg.log" 2>/dev/null & +DMESG_PID=$! + +echo "" +echo "Monitors running. Now launch your game/emulator." +echo "Press Ctrl+C after ${DURATION}s or when done testing." +echo "" + +# Wait +sleep $DURATION 2>/dev/null || true + +# Cleanup +kill $PSI_PID $FREQ_PID $VMSTAT_PID $DMESG_PID 2>/dev/null +wait 2>/dev/null + +# Generate summary +TEMP_END=$(cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null) +MEM_END=$(grep MemAvailable /proc/meminfo | awk '{print $2}') + +cat > "$RESULTS_DIR/summary.json" << SUMEOF +{ + "duration_s": $DURATION, + "temperature_end": $TEMP_END, + "mem_available_end_kb": $MEM_END, + "psi_samples": $(wc -l < "$RESULTS_DIR/psi.log"), + "freq_samples": $(wc -l < "$RESULTS_DIR/freq-therm.log") +} +SUMEOF + +echo "" +echo "========================================" +echo " Benchmark complete!" +echo " Results: $RESULTS_DIR" +echo " Files: $(ls $RESULTS_DIR | wc -l)" +echo "========================================" +ls -lh "$RESULTS_DIR"