🎯 Optimization Overview
This guide provides comprehensive optimization strategies for Raspberry Pi 4 in RFS-Portable-BTS applications. Follow these steps to achieve maximum performance and stability.
✅ Expected Performance Gains
Following this optimization guide can improve system performance by 20-40% and reduce thermal throttling significantly.
🔧 System Configuration
Boot Configuration (config.txt)
# GPU Memory Split (optimize for headless operation) gpu_mem=16 # Overclocking (stable for most units) arm_freq=1800 gpu_freq=500 over_voltage=2 # Enable hardware acceleration dtparam=audio=off dtparam=spi=on dtparam=i2c_arm=on # USB Configuration dtparam=usb=on usb_max_current_enable=1 # Thermal Management temp_limit=75 avoid_warnings=1 # Boot Configuration disable_splash=1 boot_delay=0
Kernel Parameters
# Add to /boot/cmdline.txt console=serial0,115200 console=tty1 root=PARTUUID=xxx rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles # Performance optimizations isolcpus=3 rcu_nocbs=3 nohz_full=3 irqaffinity=0,1,2
⚡ CPU Optimization
🎛️ CPU Governor
- Set to 'performance' mode
- Disable CPU frequency scaling
- Lock CPU to maximum frequency
- Reduce latency for real-time apps
- Improve consistent performance
🔄 Process Scheduling
- Use real-time scheduling (RT)
- Set process priorities
- CPU affinity for critical processes
- Reduce context switching
- Optimize for low latency
🌡️ Thermal Management
- Monitor CPU temperature
- Configure thermal throttling
- Optimize fan curves
- Prevent thermal shutdown
- Maintain stable performance
CPU Governor Configuration
# Install cpufrequtils sudo apt install cpufrequtils # Set performance governor echo 'GOVERNOR="performance"' | sudo tee /etc/default/cpufrequtils # Apply settings sudo systemctl enable cpufrequtils sudo systemctl start cpufrequtils # Verify settings cpufreq-info
💾 Memory Optimization
🧠 Memory Management
- Optimize GPU memory split
- Configure swap settings
- Enable memory overcommit
- Optimize buffer sizes
- Monitor memory usage
📊 Buffer Tuning
- Increase network buffers
- Optimize TCP settings
- Configure kernel buffers
- Adjust cache sizes
- Optimize for throughput
Memory Configuration
# Add to /etc/sysctl.conf # Network buffer optimization net.core.rmem_max = 134217728 net.core.wmem_max = 134217728 net.core.rmem_default = 262144 net.core.wmem_default = 262144 # TCP optimization net.ipv4.tcp_rmem = 4096 65536 134217728 net.ipv4.tcp_wmem = 4096 65536 134217728 net.ipv4.tcp_congestion_control = bbr # Memory management vm.swappiness = 10 vm.dirty_ratio = 15 vm.dirty_background_ratio = 5 # Apply settings sudo sysctl -p
🔌 I/O Optimization
💿 Storage Optimization
- Use M.2 SSD for storage
- Enable TRIM support
- Optimize filesystem settings
- Configure I/O scheduler
- Enable write caching
🌐 Network Optimization
- Optimize Ethernet settings
- Configure WiFi parameters
- Enable hardware offloading
- Optimize buffer sizes
- Reduce network latency
🔌 USB Optimization
- Enable USB 3.0 mode
- Optimize USB power management
- Configure USB buffer sizes
- Reduce USB latency
- Optimize for BladeRF
Storage Optimization
# Check current I/O scheduler cat /sys/block/mmcblk0/queue/scheduler # Set deadline scheduler for better performance echo deadline | sudo tee /sys/block/mmcblk0/queue/scheduler # For M.2 SSD, use mq-deadline echo mq-deadline | sudo tee /sys/block/nvme0n1/queue/scheduler # Enable TRIM for SSD sudo fstrim -av # Add to /etc/fstab for automatic TRIM UUID=xxx / ext4 defaults,noatime,discard 0 1
🌡️ Thermal Management
⚠️ Thermal Warning
Proper thermal management is critical for sustained performance. Monitor temperatures and ensure adequate cooling.
🌡️ Temperature Monitoring
- Install temperature monitoring
- Set up temperature alerts
- Monitor thermal throttling
- Log temperature data
- Configure automatic shutdown
🌀 Fan Control
- Configure PWM fan curves
- Set temperature thresholds
- Optimize fan speed
- Reduce noise levels
- Extend fan lifespan
Temperature Monitoring Script
#!/bin/bash
# Create /usr/local/bin/temp-monitor.sh
while true; do
temp=$(vcgencmd measure_temp | cut -d= -f2 | cut -d\' -f1)
echo "$(date): CPU Temperature: ${temp}°C"
if (( $(echo "$temp > 70" | bc -l) )); then
echo "WARNING: High temperature detected!"
# Add fan control or throttling here
fi
sleep 30
done
Fan Control Configuration
# Install fan control software
sudo apt install python3-rpi.gpio
# Create fan control script
cat > /usr/local/bin/fan-control.py << 'EOF'
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
import subprocess
FAN_PIN = 18 # PWM pin for fan
MIN_TEMP = 50
MAX_TEMP = 70
GPIO.setmode(GPIO.BCM)
GPIO.setup(FAN_PIN, GPIO.OUT)
pwm = GPIO.PWM(FAN_PIN, 1000)
pwm.start(0)
def get_temp():
result = subprocess.run(['vcgencmd', 'measure_temp'],
capture_output=True, text=True)
temp_str = result.stdout.strip()
temp = float(temp_str.split('=')[1].split("'")[0])
return temp
while True:
temp = get_temp()
if temp < MIN_TEMP:
pwm.ChangeDutyCycle(0) # Fan off
elif temp > MAX_TEMP:
pwm.ChangeDutyCycle(100) # Fan full speed
else:
# Linear scaling between MIN_TEMP and MAX_TEMP
duty_cycle = ((temp - MIN_TEMP) / (MAX_TEMP - MIN_TEMP)) * 100
pwm.ChangeDutyCycle(duty_cycle)
time.sleep(10)
EOF
chmod +x /usr/local/bin/fan-control.py
🔧 Service Optimization
🚫 Disable Unnecessary Services
- Bluetooth service
- WiFi power management
- Unused system services
- Desktop environment
- Audio services
⚡ Optimize Critical Services
- YateBTS process priority
- Network service optimization
- System logging configuration
- Cron job optimization
- Service startup order
Service Management
# Disable unnecessary services sudo systemctl disable bluetooth sudo systemctl disable hciuart sudo systemctl disable wpa_supplicant sudo systemctl disable avahi-daemon sudo systemctl disable cups sudo systemctl disable cups-browsed # Optimize YateBTS service sudo systemctl edit yatebts # Add: [Service] Nice=-10 IOSchedulingClass=1 IOSchedulingPriority=7 CPUSchedulingPolicy=2 CPUSchedulingPriority=99
📊 Performance Monitoring
| Metric | Command | Target Value | Notes |
|---|---|---|---|
| CPU Temperature | vcgencmd measure_temp | < 70°C | Monitor continuously |
| CPU Frequency | cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq | 1800000 Hz | Should be at max |
| Memory Usage | free -h | < 80% | Monitor for leaks |
| Disk I/O | iostat -x 1 | < 80% util | Check for bottlenecks |
| Network Latency | ping -c 10 8.8.8.8 | < 50ms | Test connectivity |
Performance Monitoring Script
#!/bin/bash
# Create /usr/local/bin/performance-monitor.sh
LOG_FILE="/var/log/performance-monitor.log"
while true; do
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
# CPU Temperature
temp=$(vcgencmd measure_temp | cut -d= -f2 | cut -d\' -f1)
# CPU Frequency
freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
freq_mhz=$((freq / 1000))
# Memory Usage
memory=$(free | grep Mem | awk '{printf "%.1f", $3/$2 * 100.0}')
# Load Average
load=$(uptime | awk -F'load average:' '{print $2}')
# Log to file
echo "$timestamp - Temp: ${temp}°C, Freq: ${freq_mhz}MHz, Memory: ${memory}%, Load: $load" >> $LOG_FILE
sleep 60
done
🎯 YateBTS Specific Optimizations
📡 YateBTS Configuration
- Optimize thread priorities
- Configure memory pools
- Set process affinity
- Optimize buffer sizes
- Configure real-time scheduling
🔌 BladeRF Optimization
- USB 3.0 configuration
- Buffer size optimization
- Latency reduction
- Power management
- Driver optimization
YateBTS Optimization
# Add to yatebts.conf [general] # Optimize for performance maxcalls=100 maxusers=1000 threads=4 # Memory optimization memory_pool_size=64MB buffer_size=8192 # Real-time optimization realtime=yes priority=high # Network optimization tcp_nodelay=yes tcp_keepalive=yes
🚀 Boot Optimization
⚡ Fast Boot
- Disable splash screen
- Reduce boot delay
- Optimize service startup
- Use systemd-analyze
- Parallel service loading
🔄 Auto-optimization
- Create startup scripts
- Apply optimizations on boot
- Monitor system health
- Automatic fan control
- Performance logging
Boot Optimization Script
#!/bin/bash # Create /usr/local/bin/boot-optimize.sh # Set CPU governor to performance echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor # Set I/O scheduler echo deadline | sudo tee /sys/block/mmcblk0/queue/scheduler # Optimize network settings sudo sysctl -w net.core.rmem_max=134217728 sudo sysctl -w net.core.wmem_max=134217728 # Start fan control /usr/local/bin/fan-control.py & # Start performance monitoring /usr/local/bin/performance-monitor.sh & echo "Boot optimization completed"
🚀 Optimize Your System
Apply these optimizations to maximize RFS-Portable-BTS performance
📖 Installation Guide 🔧 Troubleshooting 💬 Community Support