sunnypilot v2026.003.000 release

date: 2026-08-19T09:43:43
master commit: ba29a38507
This commit is contained in:
github-actions[bot]
2026-08-19 09:43:44 +00:00
commit e01ac7f80f
4046 changed files with 997234 additions and 0 deletions
View File
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo "usage: $0 <pull-request-number>"
exit 1
fi
BASE="https://github.com/commaai/openpilot/pull/"
PR_NUM="$(echo $1 | grep -o -E '[0-9]+')"
curl -L $BASE/$PR_NUM.patch | git apply -3
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
if [ $# -eq 0 ]; then
echo "usage: $0 <pull-request-number>"
exit 1
fi
BASE="https://github.com/commaai/openpilot/pull/"
PR_NUM="$(echo $1 | grep -o -E '[0-9]+')"
BRANCH=tmp-pr${PR_NUM}
git branch -D -f $BRANCH || true
git fetch -u -f origin pull/$PR_NUM/head:$BRANCH
git switch $BRANCH
git reset --hard FETCH_HEAD
+212
View File
@@ -0,0 +1,212 @@
#!/usr/bin/env python3
"""Fetch CI results from GitHub Actions and Jenkins."""
import argparse
import json
import subprocess
import time
import urllib.error
import urllib.request
from datetime import datetime
JENKINS_URL = "https://jenkins.comma.life"
DEFAULT_TIMEOUT = 1800 # 30 minutes
POLL_INTERVAL = 30 # seconds
LOG_TAIL_LINES = 10 # lines of log to include for failed jobs
def get_git_info():
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True).strip()
commit = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip()
return branch, commit
def get_github_actions_status(commit_sha):
result = subprocess.run(
["gh", "run", "list", "--commit", commit_sha, "--workflow", "tests.yaml", "--json", "databaseId,status,conclusion"],
capture_output=True, text=True, check=True
)
runs = json.loads(result.stdout)
if not runs:
return None, None
run_id = runs[0]["databaseId"]
result = subprocess.run(
["gh", "run", "view", str(run_id), "--json", "jobs"],
capture_output=True, text=True, check=True
)
data = json.loads(result.stdout)
jobs = {job["name"]: {"status": job["status"], "conclusion": job["conclusion"],
"duration": format_duration(job) if job["conclusion"] not in ("skipped", None) and job.get("startedAt") else "",
"id": job["databaseId"]}
for job in data.get("jobs", [])}
return jobs, run_id
def get_github_job_log(run_id, job_id):
result = subprocess.run(
["gh", "run", "view", str(run_id), "--job", str(job_id), "--log-failed"],
capture_output=True, text=True
)
lines = result.stdout.strip().split('\n')
return '\n'.join(lines[-LOG_TAIL_LINES:]) if len(lines) > LOG_TAIL_LINES else result.stdout.strip()
def format_duration(job):
start = datetime.fromisoformat(job["startedAt"].replace("Z", "+00:00"))
end = datetime.fromisoformat(job["completedAt"].replace("Z", "+00:00"))
secs = int((end - start).total_seconds())
return f"{secs // 60}m {secs % 60}s"
def get_jenkins_status(branch, commit_sha):
base_url = f"{JENKINS_URL}/job/openpilot/job/{branch}"
try:
# Get list of recent builds
with urllib.request.urlopen(f"{base_url}/api/json?tree=builds[number,url]", timeout=10) as resp:
builds = json.loads(resp.read().decode()).get("builds", [])
# Find build matching commit
for build in builds[:20]: # check last 20 builds
with urllib.request.urlopen(f"{build['url']}api/json", timeout=10) as resp:
data = json.loads(resp.read().decode())
for action in data.get("actions", []):
if action.get("_class") == "hudson.plugins.git.util.BuildData":
build_sha = action.get("lastBuiltRevision", {}).get("SHA1", "")
if build_sha.startswith(commit_sha) or commit_sha.startswith(build_sha):
# Get stages info
stages = []
try:
with urllib.request.urlopen(f"{build['url']}wfapi/describe", timeout=10) as resp2:
wf_data = json.loads(resp2.read().decode())
stages = [{"name": s["name"], "status": s["status"]} for s in wf_data.get("stages", [])]
except urllib.error.HTTPError:
pass
return {
"number": data["number"],
"in_progress": data.get("inProgress", False),
"result": data.get("result"),
"url": data.get("url", ""),
"stages": stages,
}
return None # no build found for this commit
except urllib.error.HTTPError:
return None # branch doesn't exist on Jenkins
def get_jenkins_log(build_url):
url = f"{build_url}consoleText"
with urllib.request.urlopen(url, timeout=30) as resp:
text = resp.read().decode(errors='replace')
lines = text.strip().split('\n')
return '\n'.join(lines[-LOG_TAIL_LINES:]) if len(lines) > LOG_TAIL_LINES else text.strip()
def is_complete(gh_status, jenkins_status):
gh_done = gh_status is None or all(j["status"] == "completed" for j in gh_status.values())
jenkins_done = jenkins_status is None or not jenkins_status.get("in_progress", True)
return gh_done and jenkins_done
def status_icon(status, conclusion=None):
if status == "completed":
return ":white_check_mark:" if conclusion == "success" else ":x:"
return ":hourglass:" if status == "in_progress" else ":grey_question:"
def format_markdown(gh_status, gh_run_id, jenkins_status, commit_sha, branch):
lines = ["# CI Results", "",
f"**Branch**: {branch}",
f"**Commit**: {commit_sha[:7]}",
f"**Generated**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}", ""]
lines.extend(["## GitHub Actions", "", "| Job | Status | Duration |", "|-----|--------|----------|"])
failed_gh_jobs = []
if gh_status:
for job_name, job in gh_status.items():
icon = status_icon(job["status"], job.get("conclusion"))
conclusion = job.get("conclusion") or job["status"]
lines.append(f"| {job_name} | {icon} {conclusion} | {job.get('duration', '')} |")
if job.get("conclusion") == "failure":
failed_gh_jobs.append((job_name, job.get("id")))
else:
lines.append("| - | No workflow runs found | |")
lines.extend(["", "## Jenkins", "", "| Stage | Status |", "|-------|--------|"])
failed_jenkins_stages = []
if jenkins_status:
stages = jenkins_status.get("stages", [])
if stages:
for stage in stages:
icon = ":white_check_mark:" if stage["status"] == "SUCCESS" else (
":x:" if stage["status"] == "FAILED" else ":hourglass:")
lines.append(f"| {stage['name']} | {icon} {stage['status'].lower()} |")
if stage["status"] == "FAILED":
failed_jenkins_stages.append(stage["name"])
# Show overall build status if still in progress
if jenkins_status["in_progress"]:
lines.append("| (build in progress) | :hourglass: in_progress |")
else:
icon = ":hourglass:" if jenkins_status["in_progress"] else (
":white_check_mark:" if jenkins_status["result"] == "SUCCESS" else ":x:")
status = "in progress" if jenkins_status["in_progress"] else (jenkins_status["result"] or "unknown")
lines.append(f"| #{jenkins_status['number']} | {icon} {status.lower()} |")
if jenkins_status.get("url"):
lines.append(f"\n[View build]({jenkins_status['url']})")
else:
lines.append("| - | No builds found for branch |")
if failed_gh_jobs or failed_jenkins_stages:
lines.extend(["", "## Failure Logs", ""])
for job_name, job_id in failed_gh_jobs:
lines.append(f"### GitHub Actions: {job_name}")
log = get_github_job_log(gh_run_id, job_id)
lines.extend(["", "```", log, "```", ""])
for stage_name in failed_jenkins_stages:
lines.append(f"### Jenkins: {stage_name}")
log = get_jenkins_log(jenkins_status["url"])
lines.extend(["", "```", log, "```", ""])
return "\n".join(lines) + "\n"
def main():
parser = argparse.ArgumentParser(description="Fetch CI results from GitHub Actions and Jenkins")
parser.add_argument("--wait", action="store_true", help="Wait for CI to complete")
parser.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT, help="Timeout in seconds (default: 1800)")
parser.add_argument("-o", "--output", default="ci_results.md", help="Output file (default: ci_results.md)")
parser.add_argument("--branch", help="Branch to check (default: current branch)")
parser.add_argument("--commit", help="Commit SHA to check (default: HEAD)")
args = parser.parse_args()
branch, commit = get_git_info()
branch = args.branch or branch
commit = args.commit or commit
print(f"Fetching CI results for {branch} @ {commit[:7]}")
start_time = time.monotonic()
while True:
gh_status, gh_run_id = get_github_actions_status(commit)
jenkins_status = get_jenkins_status(branch, commit) if branch != "HEAD" else None
if not args.wait or is_complete(gh_status, jenkins_status):
break
elapsed = time.monotonic() - start_time
if elapsed >= args.timeout:
print(f"Timeout after {int(elapsed)}s")
break
print(f"CI still running, waiting {POLL_INTERVAL}s... ({int(elapsed)}s elapsed)")
time.sleep(POLL_INTERVAL)
content = format_markdown(gh_status, gh_run_id, jenkins_status, commit, branch)
with open(args.output, "w") as f:
f.write(content)
print(f"Results written to {args.output}")
if __name__ == "__main__":
main()
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env python3
from openpilot.common.hardware import HARDWARE
if __name__ == "__main__":
HARDWARE.set_power_save(False)
+129
View File
@@ -0,0 +1,129 @@
#!/usr/bin/env bash
set -e
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
UNDERLINE='\033[4m'
BOLD='\033[1m'
NC='\033[0m'
BRANCH="master"
RUNS="20"
COOKIE_JAR=/tmp/cookies
CRUMB=$(curl -s --cookie-jar $COOKIE_JAR 'https://jenkins.comma.life/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
FIRST_LOOP=1
function loop() {
JENKINS_BRANCH="__jenkins_loop_${BRANCH}_$(date +%s)"
API_ROUTE="https://jenkins.comma.life/job/openpilot/job/$JENKINS_BRANCH"
for run in $(seq 1 $((RUNS / 2))); do
N=2
if [[ $FIRST_LOOP ]]; then
TEMP_DIR=$(mktemp -d)
GIT_LFS_SKIP_SMUDGE=1 git clone --quiet -b $BRANCH --depth=1 --no-tags git@github.com:commaai/openpilot $TEMP_DIR
git -C $TEMP_DIR checkout --quiet -b $JENKINS_BRANCH
echo "TESTING: $(date)" >> $TEMP_DIR/testing_jenkins
git -C $TEMP_DIR add testing_jenkins
git -C $TEMP_DIR commit --quiet -m "testing"
git -C $TEMP_DIR push --quiet -f origin $JENKINS_BRANCH
rm -rf $TEMP_DIR
FIRST_BUILD=1
echo ''
echo 'waiting on Jenkins...'
echo ''
sleep 90
FIRST_LOOP=""
fi
FIRST_BUILD=$(curl -s $API_ROUTE/api/json | jq .nextBuildNumber)
LAST_BUILD=$((FIRST_BUILD+N-1))
TEST_BUILDS=( $(seq $FIRST_BUILD $LAST_BUILD) )
# Start N new builds
for i in ${TEST_BUILDS[@]};
do
echo "Starting build $i"
curl -s --output /dev/null --cookie $COOKIE_JAR -H "$CRUMB" -X POST $API_ROUTE/build?delay=0sec
sleep 5
done
echo ""
# Wait for all builds to end
while true; do
sleep 30
count=0
for i in ${TEST_BUILDS[@]};
do
RES=$(curl -s -w "\n%{http_code}" --cookie $COOKIE_JAR -H "$CRUMB" $API_ROUTE/$i/api/json)
HTTP_CODE=$(tail -n1 <<< "$RES")
JSON=$(sed '$ d' <<< "$RES")
if [[ $HTTP_CODE == "200" ]]; then
STILL_RUNNING=$(echo $JSON | jq .inProgress)
if [[ $STILL_RUNNING == "true" ]]; then
echo -e "Build $i: ${YELLOW}still running${NC}"
continue
else
count=$((count+1))
echo -e "Build $i: ${GREEN}done${NC}"
fi
else
echo "No status for build $i"
fi
done
echo "See live results: ${API_ROUTE}/buildTimeTrend"
echo ""
if [[ $count -ge $N ]]; then
break
fi
done
done
}
function usage() {
echo ""
echo "Run the Jenkins tests multiple times on a specific branch"
echo ""
echo -e "${BOLD}${UNDERLINE}Options:${NC}"
echo -e " ${BOLD}-n, --n${NC}"
echo -e " Specify how many runs to do (default to ${BOLD}20${NC})"
echo -e " ${BOLD}-b, --branch${NC}"
echo -e " Specify which branch to run the tests against (default to ${BOLD}master${NC})"
echo ""
}
function _looper() {
if [[ $# -eq 0 ]]; then
usage
exit 0
fi
# parse Options
while [[ $# -gt 0 ]]; do
case $1 in
-n | --n ) shift 1; RUNS="$1"; shift 1 ;;
-b | --b | --branch | -branch ) shift 1; BRANCH="$1"; shift 1 ;;
* ) usage; exit 0 ;;
esac
done
echo ""
echo -e "You are about to start $RUNS Jenkins builds against the $BRANCH branch."
echo -e "If you expect this to run overnight, ${UNDERLINE}${BOLD}unplug the cold reboot power switch${NC} from the testing closet before."
echo ""
read -p "Press (y/Y) to confirm: " choice
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
loop
fi
}
_looper $@
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
export FINGERPRINT="TOYOTA_COROLLA_TSS2"
export SKIP_FW_QUERY="1"
$DIR/../launch_openpilot.sh
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
import argparse
import math
import os
import subprocess
def lfs_files(filenames: list[str]) -> set[str]:
if not filenames:
return set()
result = subprocess.run(
("git", "check-attr", "filter", "-z", "--stdin"),
input="\0".join(filenames),
check=True,
capture_output=True,
text=True,
)
fields = result.stdout.rstrip("\0").split("\0") if result.stdout else []
return {fields[i] for i in range(0, len(fields), 3) if fields[i + 2] == "lfs"}
def check_added_large_files(filenames: list[str], max_kb: int) -> int:
failed = False
ignored = lfs_files(filenames)
for filename in filenames:
if filename in ignored:
continue
size_kb = math.ceil(os.stat(filename).st_size / 1024)
if size_kb > max_kb:
print(f"{filename} ({size_kb} KB) exceeds {max_kb} KB.")
failed = True
return int(failed)
def main() -> int:
parser = argparse.ArgumentParser(description="Check that tracked files do not exceed a size limit.")
parser.add_argument("filenames", nargs="*")
parser.add_argument("--maxkb", type=int, default=500, help="maximum allowable size in KiB")
args = parser.parse_args()
return check_added_large_files(args.filenames, args.maxkb)
if __name__ == "__main__":
raise SystemExit(main())
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import argparse
import tokenize
# TODO: remove this once https://github.com/astral-sh/ruff/issues/8705 is closed
def check_indentation(filename: str, indent_width: int = 2) -> bool:
failed = False
indent_stack = [0]
with tokenize.open(filename) as f:
tokens = tokenize.generate_tokens(f.readline)
for token in tokens:
if token.type == tokenize.INDENT:
indentation = token.string
width = len(indentation)
expected = indent_stack[-1] + indent_width
if indentation != " " * expected:
found = "indentation containing tabs" if "\t" in indentation else f"{width} spaces"
print(f"{filename}:{token.start[0]}:1: expected {expected} spaces, found {found}")
failed = True
indent_stack.append(width)
elif token.type == tokenize.DEDENT:
indent_stack.pop()
return failed
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Check Python block indentation.")
parser.add_argument("filenames", nargs="+")
args = parser.parse_args()
failed = False
for filename in args.filenames:
failed |= check_indentation(filename)
raise SystemExit(failed)
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
FAIL=0
if grep -n '\(#\|//\)\([[:space:]]*\)NOMERGE' $@; then
echo -e "NOMERGE comments found! Remove them before merging\n"
FAIL=1
fi
exit $FAIL
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
FAIL=0
if grep '^#!.*python' $@ | grep -v '#!/usr/bin/env python3$'; then
echo -e "Invalid shebang! Must use '#!/usr/bin/env python3'\n"
FAIL=1
fi
if grep '^#!.*bash' $@ | grep -v '#!/usr/bin/env bash$'; then
echo -e "Invalid shebang! Must use '#!/usr/bin/env bash'"
FAIL=1
fi
exit $FAIL
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
import argparse
import shlex
import subprocess
import sys
def staged_modes(filenames: list[str]) -> list[tuple[str, str]]:
if not filenames:
return []
result = subprocess.run(
("git", "ls-files", "-z", "--stage", "--", *filenames),
check=True,
capture_output=True,
text=True,
)
entries = result.stdout.rstrip("\0").split("\0") if result.stdout else []
return [(entry.split(" ", 1)[0], entry.split("\t", 1)[1]) for entry in entries]
def has_shebang(filename: str) -> bool:
with open(filename, "rb") as f:
return f.read(2) == b"#!"
def check_shebang_scripts_are_executable(filenames: list[str]) -> int:
failed = False
for mode, filename in staged_modes(filenames):
if mode != "100755" and has_shebang(filename):
quoted = shlex.quote(filename)
print("\n".join((
f"{filename}: has a shebang but is not marked executable!",
f" If it is supposed to be executable, try: `chmod +x {quoted}`",
" If it is not supposed to be executable, double-check its shebang is wanted.\n",
)), file=sys.stderr)
failed = True
return int(failed)
def main() -> int:
parser = argparse.ArgumentParser(description="Check that tracked files with shebangs are executable.")
parser.add_argument("filenames", nargs="*")
args = parser.parse_args()
return check_shebang_scripts_are_executable(args.filenames)
if __name__ == "__main__":
raise SystemExit(main())
+117
View File
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
UNDERLINE='\033[4m'
BOLD='\033[1m'
NC='\033[0m'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
ROOT="$DIR/../../"
cd $ROOT
FAILED=0
function run() {
shopt -s extglob
case $1 in
$SKIP | $RUN ) return 0 ;;
esac
echo -en "$1"
for ((i=0; i<$((50 - ${#1})); i++)); do
echo -n "."
done
shift 1;
CMD="$@"
set +e
log="$((eval "$CMD" ) 2>&1)"
if [[ $? -eq 0 ]]; then
echo -e "[${GREEN}${NC}]"
else
echo -e "[${RED}${NC}]"
echo "$log"
FAILED=1
fi
set -e
}
function run_tests() {
ALL_FILES=$1
PYTHON_FILES=$2
run "ruff" ruff check openpilot --quiet
run "check_indentation" $DIR/check_indentation.py $PYTHON_FILES
run "check_added_large_files" $DIR/check_added_large_files.py --maxkb=120 $ALL_FILES
run "check_shebang_scripts_are_executable" $DIR/check_shebang_scripts_are_executable.py $ALL_FILES
run "check_shebang_format" $DIR/check_shebang_format.sh $ALL_FILES
run "check_nomerge_comments" $DIR/check_nomerge_comments.sh $ALL_FILES
if [[ -z "$FAST" ]]; then
run "ty" ty check openpilot
run "codespell" codespell $ALL_FILES --ignore-words=$ROOT/.codespellignore
fi
return $FAILED
}
function help() {
echo "A fast linter"
echo ""
echo -e "${BOLD}${UNDERLINE}Usage:${NC} op lint [TESTS] [OPTIONS]"
echo ""
echo -e "${BOLD}${UNDERLINE}Tests:${NC}"
echo -e " ${BOLD}ruff${NC}"
echo -e " ${BOLD}check_indentation${NC}"
echo -e " ${BOLD}ty${NC}"
echo -e " ${BOLD}codespell${NC}"
echo -e " ${BOLD}check_added_large_files${NC}"
echo -e " ${BOLD}check_shebang_scripts_are_executable${NC}"
echo ""
echo -e "${BOLD}${UNDERLINE}Options:${NC}"
echo -e " ${BOLD}-f, --fast${NC}"
echo " Skip slow tests"
echo -e " ${BOLD}-s, --skip${NC}"
echo " Specify tests to skip separated by spaces"
echo ""
echo -e "${BOLD}${UNDERLINE}Examples:${NC}"
echo " op lint ty ruff"
echo " Only run the ty and ruff tests"
echo ""
echo " op lint --skip ty ruff"
echo " Skip the ty and ruff tests"
echo ""
echo " op lint"
echo " Run all the tests"
}
SKIP=""
RUN=""
while [[ $# -gt 0 ]]; do
case $1 in
-f | --fast ) shift 1; FAST="1" ;;
-s | --skip ) shift 1; SKIP=" " ;;
-h | --help | -help | --h ) help; exit 0 ;;
* ) if [[ -n $SKIP ]]; then SKIP+="$1 "; else RUN+="$1 "; fi; shift 1 ;;
esac
done
RUN=$([ -z "$RUN" ] && echo "" || echo "!($(echo $RUN | sed 's/ /|/g'))")
SKIP="@($(echo $SKIP | sed 's/ /|/g'))"
IGNORED_DIRS="^openpilot/third_party/.*"
GIT_FILES="$(git ls-files openpilot | grep -vE "$IGNORED_DIRS")"
ALL_FILES=""
for f in $GIT_FILES; do
if [[ -f $f ]]; then
ALL_FILES+="$f"$'\n'
fi
done
PYTHON_FILES=$(echo "$ALL_FILES" | grep --color=never '.py$' || true)
run_tests "$ALL_FILES" "$PYTHON_FILES"
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
import argparse
import multiprocessing
from openpilot.common.hardware import HARDWARE
def main():
parser = argparse.ArgumentParser(description='Control power saving mode')
parser.add_argument('--enable', action='store_true', help='Enable power saving mode')
parser.add_argument('--disable', action='store_true', help='Disable power saving mode')
args = parser.parse_args()
if args.enable and args.disable:
parser.error("Cannot specify both --enable and --disable")
elif not (args.enable or args.disable):
parser.error("Must specify either --enable or --disable")
print(f"Number of CPU cores available before: [{multiprocessing.cpu_count()}]")
HARDWARE.set_power_save(args.enable)
state = "enabled" if args.enable else "disabled"
print(f"Power save mode set to: [{state}]")
print(f"Number of CPU cores available now: [{multiprocessing.cpu_count()}]")
if __name__ == "__main__":
main()
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
if [[ -f .git/hooks/post-commit.d/post-commit ]]; then
.git/hooks/post-commit.d/post-commit
fi
tools/op.sh lint --fast
echo ""
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
function fail {
echo $1 >&2
exit 1
}
function retry {
local n=1
local max=3 # 3 retries before failure
local delay=5 # delay between retries, 5 seconds
while true; do
echo "Running command '$@' with retry, attempt $n/$max"
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
retry "$@"
fi
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(git -C "$SCRIPT_DIR/.." rev-parse --show-toplevel)"
PYTHON_VERSION="$(cat "$REPO_ROOT/.python-version")"
PACKAGE="${1:-$REPO_ROOT}"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
cd "$TMPDIR"
uv venv --python "$PYTHON_VERSION"
source .venv/bin/activate
uv pip install "$PACKAGE"
python3 - <<'PY'
from openpilot.tools.lib.logreader import LogReader
assert LogReader.__name__ == "LogReader"
print("ok: imported LogReader")
PY
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
# Send SIGHUP to updater
pkill -1 -f system.updated
+88
View File
@@ -0,0 +1,88 @@
// gcc -O2 waste.c -lpthread -owaste
// gcc -O2 waste.c -lpthread -owaste -DMEM
#define _GNU_SOURCE
#include <stdio.h>
#include <math.h>
#include <sched.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <arm_neon.h>
#include <sys/sysinfo.h>
#include "../openpilot/common/timing.h"
int get_nprocs(void);
double *ttime, *oout;
void waste(int pid) {
cpu_set_t my_set;
CPU_ZERO(&my_set);
CPU_SET(pid, &my_set);
int ret = sched_setaffinity(0, sizeof(cpu_set_t), &my_set);
printf("set affinity to %d: %d\n", pid, ret);
// 128 MB
float32x4_t *tmp = (float32x4_t *)malloc(0x800000*sizeof(float32x4_t));
// comment out the memset for CPU only and not RAM
// otherwise we need this to avoid the zero page
#ifdef MEM
memset(tmp, 0xaa, 0x800000*sizeof(float32x4_t));
#endif
float32x4_t out;
double sec = seconds_since_boot();
while (1) {
for (int i = 0; i < 0x10; i++) {
for (int j = 0; j < 0x800000; j+=0x20) {
out = vmlaq_f32(out, tmp[j+0], tmp[j+1]);
out = vmlaq_f32(out, tmp[j+2], tmp[j+3]);
out = vmlaq_f32(out, tmp[j+4], tmp[j+5]);
out = vmlaq_f32(out, tmp[j+6], tmp[j+7]);
out = vmlaq_f32(out, tmp[j+8], tmp[j+9]);
out = vmlaq_f32(out, tmp[j+10], tmp[j+11]);
out = vmlaq_f32(out, tmp[j+12], tmp[j+13]);
out = vmlaq_f32(out, tmp[j+14], tmp[j+15]);
out = vmlaq_f32(out, tmp[j+16], tmp[j+17]);
out = vmlaq_f32(out, tmp[j+18], tmp[j+19]);
out = vmlaq_f32(out, tmp[j+20], tmp[j+21]);
out = vmlaq_f32(out, tmp[j+22], tmp[j+23]);
out = vmlaq_f32(out, tmp[j+24], tmp[j+25]);
out = vmlaq_f32(out, tmp[j+26], tmp[j+27]);
out = vmlaq_f32(out, tmp[j+28], tmp[j+29]);
out = vmlaq_f32(out, tmp[j+30], tmp[j+31]);
}
}
double nsec = seconds_since_boot();
ttime[pid] = nsec-sec;
oout[pid] = out[0] + out[1] + out[2] + out[3];
sec = nsec;
}
}
int main() {
int CORES = get_nprocs();
ttime = (double *)malloc(CORES*sizeof(double));
oout = (double *)malloc(CORES*sizeof(double));
pthread_t waster[CORES];
for (long i = 0; i < CORES; i++) {
ttime[i] = NAN;
pthread_create(&waster[i], NULL, (void *(*)(void *))waste, (void*)i);
}
while (1) {
double avg = 0.0;
double iavg = 0.0;
for (int i = 0; i < CORES; i++) {
avg += ttime[i];
iavg += 1/ttime[i];
printf("%4.2f ", ttime[i]);
}
double mb_per_sec = (16.*0x800000/(1024*1024))*sizeof(float32x4_t)*iavg;
printf("-- %4.2f -- %.2f MB/s \n", avg/CORES, mb_per_sec);
sleep(1);
}
}
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
import os
import time
import numpy as np
from multiprocessing import Process
from setproctitle import setproctitle
def waste(core):
os.sched_setaffinity(0, [core,])
m1 = np.zeros((200, 200)) + 0.8
m2 = np.zeros((200, 200)) + 1.2
i = 1
st = time.monotonic()
j = 0
while 1:
if (i % 100) == 0:
setproctitle(f"{core:3d}: {i:8d}")
lt = time.monotonic()
print(f"{core:3d}: {i:8d} {lt-st:f} {j:.2f}")
st = lt
i += 1
j = np.sum(np.matmul(m1, m2))
def main(gctx=None):
print("1-2 seconds is baseline")
for i in range(os.cpu_count()):
p = Process(target=waste, args=(i,))
p.start()
if __name__ == "__main__":
main()