Most Stable Raspberry Pi? Better NTP with Thermal Management
Recorded: Nov. 26, 2025, 1:03 a.m.
| Original | Summarized |
World's Most Stable Raspberry Pi? 81% Better NTP with Thermal Management - Austin's Nerdy Things Skip to the content Austin's Nerdy ThingsNerding out, one post at a time Home Menu
Search Search for: Close search Close Menu Home Home Categories Chrony Linux NTP Raspberry Pi World’s Most Stable Raspberry Pi? 81% Better NTP with Thermal Management Post author By Austin Post date November 24, 2025
8 Comments on World’s Most Stable Raspberry Pi? 818 Better NTP with Thermal Management I’ve written before about building microsecond-accurate NTP servers with Raspberry Pi and GPS PPS, and more recently about revisiting the setup in 2025. Both posts focused on the hardware setup and basic configuration to achieve sub-microsecond time synchronization using GPS Pulse Per Second (PPS) signals. Same ish graph but with CPU temp also plotted: That vertical red line marks on the first plot when I activated the “time burner” process. Notice how the frequency oscillations immediately dampen and settle into a much tighter band? Let’s dive into how this works. CPU 0: Reserved for chronyd and PPS interrupts I had AI (probably Claude Sonnet 4 ish, maybe 4.5) create a boot optimization script that runs at system startup: set -e echo "Setting up PPS NTP server performance optimizations..." # Wait for system to be ready # Set CPU governor to performance mode # Pin PPS interrupt to CPU0 (may fail if already pinned, that's OK) # Wait for chronyd to start if [ -z "$chronyd_pid" ]; then # Boost ksoftirqd/0 priority echo "PPS NTP optimization complete!" # Log current status Performance Governor: Forces all CPUs to run at maximum frequency, disabling frequency scaling This script can be added to /etc/rc.local or as a systemd service to run at boot. Read CPU temperature from /sys/class/thermal/thermal_zone0/temp Here’s the core implementation (simplified for readability): class PIDController: def update(self, measurement): if dt < self.sample_time: error = self.setpoint - measurement # Proportional # Integral with anti-windup # Derivative # Combine and clamp self._last_output = output return output def read_cpu_temperature(path='/sys/class/thermal/thermal_zone0/temp'): def burn_cpu(duration): def worker_loop(worker_id, cmd_queue, done_queue): while True: burn_time, sleep_time = cmd # Main control loop (simplified) pid = PIDController(Kp=0.05, Ki=0.02, Kd=0.0, # Start 3 worker processes for i in range(3): try: # PID control: output is fraction of time to burn (0.0 to 1.0) # Convert to burn/sleep times # Send command to all workers # Wait for workers to complete print(f"Temp={current_temp:.2f}C, Output={output:.2f}, " except KeyboardInterrupt: if __name__ == '__main__': Kp=0.05: Proportional gain – responds to current error The target temperature of 54°C was chosen empirically – high enough to keep the CPU from idling down, but low enough to avoid thermal throttling (which starts around 80°C on Raspberry Pi). MetricBeforeAfterImprovementMean RMS Offset85.44 ns43.54 ns49.0% reductionMedian RMS Offset80.13 ns37.93 ns52.7% reduction [Service] [Install] [Service] [Install] # Check chronyd CPU affinity and priority # Check time burner processes # Monitor NTP performance Frequency offset (PPM) You’ll see the frequency stabilize within a few hours as the PID controller locks onto the target temperature. Adjust PID gains – reduce Kp if oscillating, increase Ki if steady-state error High CPU usage (obviously): This is intentional – the time burner uses ~90% of 3 cores Chronyd not pinned to CPU 0: Check that the optimization script runs after chronyd starts Trade-offs and Considerations Precision timing applications (scientific instrumentation, radio astronomy) For me, this falls squarely in the “because you can” category. I had the monitoring infrastructure in place, noticed the thermal correlation, and couldn’t resist solving the problem. Plus, I learned a lot about PID control, CPU thermal characteristics, and Linux real-time scheduling. 81% reduction in frequency variability The system now maintains 38-nanosecond median RMS offset from the GPS PPS reference, with frequency drift that’s barely detectable in the noise. The CPU runs at a constant 54°C, and in steady state, the frequency offset stays within a tight ±0.14 PPM band (compared to ±0.52 PPM before optimization). Microsecond-Accurate NTP with a Raspberry Pi and PPS GPS (2021) Further Reading Chrony Documentation Have questions or suggestions? Drop a comment below. I’m particularly interested to hear if anyone has tried alternative thermal management approaches or has experience with OCXO modules for Raspberry Pi timing applications. Post Views: 23,824 Tags chrony, control theory, gps, ntp, pid, pps, python, Raspberry Pi, timekeeping ← 8 replies on “World’s Most Stable Raspberry Pi? 81% Better NTP with Thermal Management” Larssays: November 25, 2025 at 3:08 am Hi Austin, Reply Peter Fischersays: November 25, 2025 at 6:06 am > Because you can (the best reason for any homelab project) Reply Andy Markleysays: November 25, 2025 at 6:19 am Interesting! I wonder if the spacecrafts had the heaters expressly to ensure the timing is close to accurate. Reply Austinsays: November 25, 2025 at 8:13 am Wouldn’t doubt it! There are a variety of crystal oscillators. From the low end up: Basic crystal oscillator – highly temperature dependent From there, the next step up is rubidium (which is now considered an atomic clock) and cesium clocks ReplyBy Post Author Revisiting Microsecond Accurate NTP for Raspberry Pi with GPS PPS in 2025 - Austin's Nerdy Thingssays: November 25, 2025 at 8:37 am […] In the next post, we will examine how to maximize the performance (by minimizing the frequency skew!) of our Raspberry Pi/PPS combination – World’s Most Stable Raspberry Pi? 81% Better NTP with Thermal Management. […] Reply Microsecond accurate NTP with a Raspberry Pi and PPS GPS - Austin's Nerdy Thingssays: November 25, 2025 at 8:38 am […] Update 2025-11-25: See here for how to do some thermal management to improve the stability by a factor of at least 2x: https://austinsnerdythings.com/2025/11/24/worlds-most-stable-raspberry-pi-81-better-ntp-with-thermal… […] Reply Hacker News 今日TOP 20| 2025-11-25 - 出海掘金,无限可能。为独立开发者、跨境电商从业者、海外自媒体提供最新出海资讯和资源-出海掘金,无限可能。为独立开发者、跨境电商从业者、海外自媒体says: November 25, 2025 at 9:01 am […] 网站: austinsnerdythings.com HN评论: […] Reply Ian Zimmermansays: November 25, 2025 at 3:46 pm Hi. I could *almost* replicate this, and I think I’d see even a more dramatic improvement, because my ambient temp swings way wider (right now, it’s like 9 deg C in the morning vs 20 deg late afternoon … this aging carbon based system doesn’t like it either, sigh). But. You hardcode the PPS IRQ line to 200, mine is definitely not that, the 200 entry doesn’t even exist in `/proc/irq`. Do you have an idea how I can find out what it is? Some quick survey of `/proc` and `/sys` found no hints. Reply
About This Site austinsnerdythings.com is a way for me to give back to all the people who have posted something helpful to me over the years. I’ll be documenting nerdy activities for everyone to learn!
Find us elsewhere!GitHub © To the top ↑ Up ↑ |
World’s Most Stable Raspberry Pi? 81% Better NTP with Thermal Management - Austin’s Nerdy Things **Introduction** This document details a project undertaken to significantly improve the stability of an NTP (Network Time Protocol) server built around a Raspberry Pi. The primary challenge was mitigating frequency drift caused by CPU temperature fluctuations. Through a combination of CPU core isolation, thermal stabilization, and meticulous monitoring, a 81% reduction in frequency variability – and a 77% reduction in frequency standard deviation – was achieved. This is a high-level technical overview, geared toward a college graduate familiar with system administration and monitoring concepts. The ultimate aim of this project was to demonstrate the impact of focused thermal management on precision timing systems, and to provide a detailed record of the steps taken to achieve a remarkably stable and accurate NTP server. **The Problem: Thermal-Induced Timing Jitter** Modern CPUs, including those found in Raspberry Pi devices, utilize dynamic frequency scaling (also known as Active Frequency Scaling or AFS) to conserve power and manage heat. This process allows the CPU to reduce its operating frequency when it is idle or under low load. While this is beneficial for power efficiency, it introduces significant challenges for precision timekeeping. Traditional NTP servers rely on a stable system clock to discipline themselves against reference sources (like GPS or stratum 1 time servers). When the CPU frequency is constantly changing – as it does during AFS – the system clock’s tick rate varies, introducing jitter into the timing measurements. Even with a rock-solid PPS (Pulse Per Second) signal from a GPS module, this CPU frequency jitter created a significant source of instability. The core issue was that the Raspberry Pi’s crystal oscillator – the heart of its system clock – is temperature-dependent. The 19.2 MHz crystal oscillator (present in the Raspberry Pi 3B and similar models) experiences frequency shifts proportional to changes in temperature. A simple temperature fluctuation of just a few degrees could cause measurable PPM (parts per million) variations in the oscillator’s frequency – variations that directly translate into timing uncertainty and drift in the NTP server’s output. In this case, the observed thermal oscillations were correlated directly to the CPU temperature, amplifying the instability. **The Approach** The solution focused on directly addressing the root cause of the problem: the CPU’s thermal dynamics. The overall strategy was to isolate the timing-critical components, stabilize the thermal environment for the crystal oscillator, and then employ strategies to minimize additional thermal fluctuations. **Phase 1: CPU Core Isolation** The first step was to dedicate CPU core 0 exclusively to the timing-critical tasks. The Raspberry Pi 3B has four CPU cores. By pinning chronyd (the NTP daemon) and the PPS interrupt handler to only core 0, we eliminated potential interference from other processes running on the Pi. Essentially, we created a real-time environment for the most critical timing components, maximizing their stability. This required adjusting the CPU governor of all other cores to focus power on the core running chronyd. **Phase 2: Thermal Stabilization (The “Time Burner” System)** The concept behind this stage was to actively control the CPU’s temperature to maintain a consistent thermal baseline. This is where the ‘time burner’ system comes in. Three additional CPU cores were utilized to constantly cycle their frequencies – this wasn’t intended to load them with demanding tasks; it was just to create a controlled thermal load. This approach effectively 'burned' heat from the CPU, actively counteracting the temperature fluctuations caused by the Pi’s ambient environment. This was done by controlling the CPU clock speed via the CPU’s operating parameters. Essentially, this was a simple, controllable heat source, managed to maintain a constant temperature and dampen out thermal oscillations. **Technical Details** * **PID Control:** A PID (Proportional-Integral-Derivative) controller was implemented to manage the thermal load. The PID controller continuously adjusted the CPU core cycling frequency based on feedback from a temperature sensor (which was monitored via /sys/class/thermal/thermal_zone0/temp). This automated system rapidly responded to changes in temperature, maintaining the desired target temperature. **Key Metrics** * **RMS Offset:** The Root Mean Square (RMS) offset is a statistical measure of timing jitter. Lower RMS offset indicates greater timing stability. The achievable RMS offset was reduced by 49%. **Conclusion** This project demonstrates that, through careful thermal management and system optimization, it’s possible to substantially improve the stability of an NTP server based on a Raspberry Pi. While the solution isn’t without its trade-offs (e.g., increased power consumption and thermal output), the resulting impact on timing accuracy is significant. The core takeaways include: * Temperature is a critical factor in accurate timekeeping. Continued investigation and more advanced techniques (such as using an oven-controlled crystal oscillator) could yield even greater improvements. |