Skip to content

Commit 24ee078

Browse files
authored
feat: add orin performance and hardware config (#53)
1 parent 1f52b7b commit 24ee078

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed

docker/setup_host/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,22 @@ Please use the following command to check the device (_e.g. video0_) attributes:
1212

1313
`udevadm info --attribute-walk --name /dev/video0`
1414

15+
---
16+
17+
## Run `config_system.sh`
18+
19+
#### **Standard Installation (with GUI)**:
20+
21+
This command executes all configurations but skips the step of disabling the graphical user interface (GUI). It is suitable for your development machine or for vehicles that require local debugging with a display.
22+
23+
```bash
24+
sudo ./config_system.sh
25+
```
26+
27+
#### **Headless Mode Installation (GUI disabled)**:
28+
29+
This command executes all configurations and sets the system to boot into command-line mode. This frees up maximum system resources for your autonomous driving application and is suitable for final deployment on in-vehicle computing units.
30+
31+
```bash
32+
sudo SETUP_HEADLESS_MODE=yes ./config_system.sh
33+
```

docker/setup_host/config_system.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ BAZEL_CACHE_DIR="/var/cache/bazel/repo_cache"
2525
UVCVIDEO_CONF_FILE="/etc/modprobe.d/uvcvideo.conf"
2626
UDEV_RULES_SRC_DIR="${APOLLO_ROOT_DIR}/docker/setup_host/etc/udev/rules.d"
2727
UDEV_RULES_DEST_DIR="/etc/udev/rules.d"
28+
LIMITS_CONF_SRC_DIR="${APOLLO_ROOT_DIR}/docker/setup_host/etc/security/limits.d"
29+
LIMITS_CONF_DEST_DIR="/etc/security/limits.d"
30+
NETWORK_CONF_SRC_DIR="${APOLLO_ROOT_DIR}/docker/setup_host/etc/systemd/network"
31+
NETWORK_CONF_DEST_DIR="/etc/systemd/network"
32+
SYSTEMD_SRC_DIR="${APOLLO_ROOT_DIR}/docker/setup_host/etc/systemd/system"
33+
SYSTEMD_DEST_DIR="/etc/systemd/system"
2834

2935
# Source path of the service file within the project
3036
AUTOSERVICE_SRC_FILE="${APOLLO_ROOT_DIR}/docker/setup_host/etc/systemd/system/autostart.service"
@@ -441,6 +447,92 @@ install_autostart_service() {
441447
return 0
442448
}
443449

450+
# Sets the system-wide limits for core dump file size by copying config.
451+
setup_core_limits() {
452+
info "Configuring system-wide core dump size limits..."
453+
if [ ! -d "${LIMITS_CONF_SRC_DIR}" ] || [ -z "$(ls -A "${LIMITS_CONF_SRC_DIR}")" ]; then
454+
info "Core limits source directory not found or empty. Skipping."
455+
return 0
456+
fi
457+
sudo cp -f "${LIMITS_CONF_SRC_DIR}"/* "${LIMITS_CONF_DEST_DIR}/"
458+
if [ $? -ne 0 ]; then error "Failed to copy core limits configuration." && return 1; fi
459+
success "Core dump size limits configured."
460+
return 0
461+
}
462+
463+
# Configures CAN bus using systemd-networkd for permanent setup.
464+
configure_can_bus() {
465+
info "Configuring CAN bus interfaces using systemd-networkd..."
466+
if [ ! -d "${NETWORK_CONF_SRC_DIR}" ] || [ -z "$(ls -A "${NETWORK_CONF_SRC_DIR}")" ]; then
467+
info "systemd-networkd source directory not found or empty. Skipping CAN bus setup."
468+
return 0
469+
fi
470+
471+
sudo mkdir -p "${NETWORK_CONF_DEST_DIR}"
472+
# This robustly copies any .network files present (e.g., just 10-can0.network)
473+
sudo cp -f "${NETWORK_CONF_SRC_DIR}"/*.network "${NETWORK_CONF_DEST_DIR}/"
474+
if [ $? -ne 0 ]; then error "Failed to copy systemd-networkd CAN configurations." && return 1; fi
475+
info "CAN network configuration files copied."
476+
477+
info "Enabling and restarting systemd-networkd service..."
478+
sudo systemctl enable --now systemd-networkd.service > /dev/null 2>&1
479+
sudo systemctl restart systemd-networkd.service
480+
if [ $? -ne 0 ]; then error "Failed to restart systemd-networkd. Check its status." && return 1; fi
481+
success "CAN bus interfaces configured via systemd-networkd."
482+
return 0
483+
}
484+
485+
# Sets up Jetson performance optimizations (nvpmodel, jetson_clocks).
486+
setup_jetson_performance() {
487+
if ! command -v nvpmodel &> /dev/null; then
488+
info "Not a Jetson device. Skipping Jetson performance setup."
489+
return 0
490+
fi
491+
492+
info "Configuring Jetson performance services (nvpmodel and jetson_clocks)..."
493+
local service_file="jetson-performance.service"
494+
495+
if [ ! -f "${SYSTEMD_SRC_DIR}/${service_file}" ]; then
496+
error "'${service_file}' not found in source directory. Skipping." && return 1
497+
fi
498+
499+
sudo cp -f "${SYSTEMD_SRC_DIR}/${service_file}" "${SYSTEMD_DEST_DIR}/"
500+
if [ $? -ne 0 ]; then error "Failed to copy ${service_file}." && return 1; fi
501+
502+
sudo systemctl daemon-reload
503+
sudo systemctl enable --now "${service_file}"
504+
if [ $? -ne 0 ]; then error "Failed to enable and start ${service_file}." && return 1; fi
505+
success "Jetson performance service enabled and started."
506+
return 0
507+
}
508+
509+
# Switches the system to non-graphical multi-user mode (headless).
510+
configure_headless_mode() {
511+
# This is a significant change, only run if explicitly requested.
512+
if [[ "${SETUP_HEADLESS_MODE:-no}" != "yes" ]]; then
513+
info "SETUP_HEADLESS_MODE is not 'yes'. Skipping GUI disable."
514+
return 0
515+
fi
516+
517+
info "Configuring system for headless operation (disabling GUI)..."
518+
# Check if it's already in the desired state (idempotency)
519+
if systemctl get-default | grep -q "multi-user.target"; then
520+
info "System is already set to multi-user (headless) mode."
521+
return 0
522+
fi
523+
524+
sudo systemctl set-default multi-user.target
525+
if [ $? -ne 0 ]; then
526+
error "Failed to set default target to multi-user.target."
527+
return 1
528+
fi
529+
530+
success "System configured for headless mode. GUI will be disabled on next reboot."
531+
info "To revert this change, run: sudo systemctl set-default graphical.target"
532+
return 0
533+
}
534+
535+
444536
# --- Main Host Setup Orchestration Function ---
445537
# This is the primary entry point for setting up the host machine.
446538
setup_host_machine() {
@@ -458,6 +550,11 @@ setup_host_machine() {
458550
return 1
459551
fi
460552

553+
if ! setup_core_limits; then
554+
error "Failed to configure core limits."
555+
return 1
556+
fi
557+
461558
# 3. Setup Bazel cache directory
462559
if ! setup_bazel_cache_dir; then
463560
error "Failed to set up Bazel cache directory. Aborting host setup."
@@ -482,6 +579,21 @@ setup_host_machine() {
482579
return 1
483580
fi
484581

582+
if ! configure_can_bus; then
583+
error "Failed to configure CAN bus."
584+
return 1
585+
fi
586+
587+
if ! setup_jetson_performance; then
588+
error "Failed to configure Jetson performance."
589+
return 1
590+
fi
591+
592+
if ! configure_headless_mode; then
593+
error "Failed to configure headless mode."
594+
return 1
595+
fi
596+
485597
# 7. Ensure docker permissions are set correctly
486598
if ! add_user_to_docker_group; then
487599
error "Failed to add user to Docker group. This may affect Docker permissions."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Allow all users to generate unlimited size core dump files for debugging
2+
* soft core unlimited
3+
* hard core unlimited
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Match]
2+
Name=can0
3+
4+
[CAN]
5+
BitRate=500000
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Match]
2+
Name=can1
3+
4+
[CAN]
5+
BitRate=500000
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Set Jetson Performance Mode (MAXN) and Clocks
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStartPre=nvpmodel -m 0
7+
ExecStart=jetson_clocks
8+
RemainAfterExit=yes
9+
10+
[Install]
11+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)