Run a Local SLM Without Overheating - Using RAPL on Linux

Run a Local SLM Without Overheating - Using RAPL on Linux

Leader ●2 ●4 ●22
calendar_today ago • schedule8 min read

Recently, I was testing a small language model (SLM) locally. My PC is an HP ENVY 17m laptop with an Intel Core i7-1165G7 (4 cores, 8 threads), Debian 12, and llama.cpp installed. It doesn't have the ability to run anything larger than an 8B, so I must do this in CPU-only mode. The model in this article is Lunaris, a Llama 3 8B model quantized to Q4_K_M, which is a 4.9 GB file.

My experience with SLMs 8B and smaller is that they're virtually useless for logic and code. I chose Lunaris with a task of writing fiction. My goal here wasn't to write fiction, but to see what my particular PC was capable of handling during prolonged SLM inference in CPU-only mode. The first time I gave it a real task, a short story of about 400 words, the CPU package reached 94 °C and the CPU throttled itself to stay safe - something I didn't want happening again and again.

It turned out the fix was already on the laptop. Intel CPUs have a hardware power limiter called RAPL, and Linux exposes it as plain files you can read and write. With nothing installed and a few lines of bash, the same task peaked at 70 °C with no throttling, and the output was identical.

This article covers what RAPL is, how Linux exposes it, why it suits SLM inference so well, and the small setup I built on top of it.


Why a CPU-only SLM runs so hot

A language model writes one token (a word-piece) at a time. To produce each token, the CPU has to read the entire model out of RAM: 4.9 GB for every token. During a reply the processor sits at full load, often for minutes at a time. That is a very different load from a browser or a compile job, which comes in bursts. Inference is a long, flat, maximum load, and that is exactly the kind of load that heat-soaks a laptop.

The useful detail is that the bottleneck is memory bandwidth, not compute. The cores spend much of their time waiting for data from RAM. On this machine, 6.1 tokens/s × 4.9 GB comes to about 30 GB/s, which is close to what dual-channel DDR4 actually delivers. When the cores can't be fed any faster, letting them boost to high clocks mostly turns electricity into heat.

So you can make the CPU draw much less power and lose surprisingly little speed. RAPL is the tool for doing that.


What RAPL is

RAPL (Running Average Power Limit) is built into Intel processors from Sandy Bridge onward. It caps how much power the CPU package may draw, averaged over a time window. The two limits that matter are:

  • PL1 (long-term): the power the chip may draw indefinitely.
  • PL2 (short-term): a higher figure the chip may boost to briefly before it has to fall back to PL1.

Less power means less heat, directly, and the CPU enforces the limit itself in hardware. No daemon has to keep up with the load.

How Linux exposes it

The kernel's powercap framework turns RAPL into ordinary files under /sys/class/powercap/. On my HP:

$ ls /sys/class/powercap/
intel-rapl  intel-rapl:0  intel-rapl:0:0  intel-rapl:0:1  intel-rapl-mmio  intel-rapl-mmio:0

$ cd /sys/class/powercap/intel-rapl/intel-rapl:0
$ cat name constraint_0_name constraint_1_name
package-0
long_term
short_term

$ cat constraint_0_power_limit_uw constraint_1_power_limit_uw
15000000
18000000

intel-rapl:0 is the whole CPU package. constraint_0 is PL1 and constraint_1 is PL2. Values are in microwatts, so 15000000 means 15 W. The subzones intel-rapl:0:0 and :0:1 are the cores and the uncore.

The same folder also has a live energy counter. That means you can measure the package's real power draw with nothing but cat:

f=/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj
a=$(sudo cat $f); sleep 1; b=$(sudo cat $f); echo "$(( (b - a) / 1000000 )) W"

(Since kernel 5.10, energy_uj is readable only by root.)

Setting a limit is one line:

echo 12000000 | sudo tee /sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw

That one command caps PL1 at 12 W. It takes effect immediately and needs no reboot. It also resets at the next boot, so you can experiment without risk: if a value feels wrong, reboot and you're back to the firmware defaults.

Note: many laptops also have intel-rapl-mmio:0, a second copy of the limits that the firmware sets (30/51 W on this HP). The CPU obeys whichever limit is lower, so a lower value written to intel-rapl:0 still takes effect, as the measurements below show.

Two more knobs Linux gives you

With the intel_pstate driver (the default on modern Intel), Linux also exposes:

  • Turbo: /sys/devices/system/cpu/intel_pstate/no_turbo. Write 1 to keep the cores at base clock.
  • Energy preference (EPP): /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference. The choices are default, performance, balance_performance, balance_power and power. EPP tells the chip how to trade speed against efficiency.

RAPL sets the ceiling, and turbo and EPP shape how the chip behaves underneath it. Together they make a complete "low-heat mode", and all of it is already in the kernel.


The setup: two power levels

I run the laptop at one of two levels.

1. Everyday level: PL1 15 W, PL2 18 W. This is applied at every boot by a small systemd service, and normal desktop use doesn't notice it.

2. Cool mode, only while a model runs: turbo off, EPP power, and PL1 = PL2 = 12 W, so there is no boost window at all.

The cool-mode script

/usr/local/sbin/slm-cool:

#!/bin/bash
# slm-cool on|off|status - low-heat CPU mode for running a language model (Intel CPUs).
set -euo pipefail
RAPL=/sys/class/powercap/intel-rapl/intel-rapl:0
PSTATE=/sys/devices/system/cpu/intel_pstate
COOL_W=12; PL1_W=15; PL2_W=18
[ -r /etc/slm-cool.conf ] && . /etc/slm-cool.conf

epp() { for f in /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference; do echo "$1" > "$f"; done; }
cap() { echo $(( $1 * 1000000 )) > "$RAPL/constraint_0_power_limit_uw"
        echo $(( $2 * 1000000 )) > "$RAPL/constraint_1_power_limit_uw"; }

case "${1:-}" in
  on)     echo 1 > "$PSTATE/no_turbo"; epp power;               cap "$COOL_W" "$COOL_W" ;;
  off)    echo 0 > "$PSTATE/no_turbo"; epp balance_performance; cap "$PL1_W" "$PL2_W" ;;
  status) ;;
  *)      echo "usage: slm-cool on|off|status" >&2; exit 2 ;;
esac
printf 'turbo %s | epp %s | PL1 %sW PL2 %sW\n' \
  "$([ "$(cat "$PSTATE/no_turbo")" = 1 ] && echo off || echo on)" \
  "$(cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference)" \
  $(( $(cat "$RAPL/constraint_0_power_limit_uw") / 1000000 )) \
  $(( $(cat "$RAPL/constraint_1_power_limit_uw") / 1000000 ))

The whole script is writes to sysfs. There's nothing to compile and no dependencies.

The settings file

/etc/slm-cool.conf:

COOL_W=12   # cap while a model runs (slm-cool on)
PL1_W=15    # everyday long-term cap
PL2_W=18    # everyday short-term boost

Applying the everyday level at boot

Because RAPL values reset on reboot, a oneshot service reapplies them. /usr/local/sbin/cpu-powercap:

#!/bin/bash
set -euo pipefail
RAPL=/sys/class/powercap/intel-rapl/intel-rapl:0
PL1_W=15; PL2_W=18
[ -r /etc/slm-cool.conf ] && . /etc/slm-cool.conf
echo $(( PL1_W * 1000000 )) > "$RAPL/constraint_0_power_limit_uw"
echo $(( PL2_W * 1000000 )) > "$RAPL/constraint_1_power_limit_uw"

/etc/systemd/system/cpu-powercap.service:

[Unit]
Description=CPU package power cap (RAPL PL1/PL2)
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/cpu-powercap
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now cpu-powercap

Letting the launcher switch modes without a password

Writing to these files needs root. I wanted the model launcher to switch cool mode on and off by itself, so I added a sudoers rule that allows that one script and nothing else. Create it with sudo visudo -f /etc/sudoers.d/slm-cool:

ben ALL=(root) NOPASSWD: /usr/local/sbin/slm-cool on, /usr/local/sbin/slm-cool off, /usr/local/sbin/slm-cool status

The launcher: cool mode on at start, off at exit

~/bin/lunaris is a short wrapper around llama-cli. The important part is the trap:

#!/bin/bash
set -euo pipefail
MODEL="${MODEL:-$HOME/.llama/models/L3-8B-Lunaris-v1-Q4_K_M.gguf}"
THREADS="${THREADS:-3}"; COOL="${COOL:-1}"
COOLER=/usr/local/sbin/slm-cool

if [ "$COOL" = 1 ]; then
  if sudo -n "$COOLER" on >/dev/null 2>&1; then
    trap 'sudo -n "$COOLER" off >/dev/null 2>&1 || true' EXIT
    trap 'exit 130' INT TERM HUP
  else
    echo "WARNING: cool mode not available - running hot" >&2
  fi
fi

# not exec: the EXIT trap has to run after llama-cli quits
llama-cli -m "$MODEL" -ngl 0 -t "$THREADS" -tb "$THREADS" \
  -c 8192 -fa on -ctk q8_0 -ctv q8_0 -n 1536 \
  --temp 0.9 --min-p 0.05 --repeat-penalty 1.05 "$@"

sudo -n means "fail instead of asking for a password", so if the rule is missing the model still runs and you get a warning. The trap means that when llama-cli ends, whether through /exit, Ctrl+C, a closed terminal or an error, cool mode is switched off and the everyday level comes back. The script deliberately doesn't exec llama-cli, because exec would replace the script and the trap could never run.

Now I type lunaris and the cooling takes care of itself.

A few llama.cpp flags that help a little

RAPL does the real work. These flags help a bit on top of it:

  • -ngl 0: everything runs on the CPU.
  • -t 3 -tb 3: three threads. Since the job is memory-bound, a fourth core adds heat and almost no speed.
  • -fa on -ctk q8_0 -ctv q8_0: flash attention plus an 8-bit KV cache, which halves the cache's memory traffic. The 8-bit cache needs flash attention.
  • -n: a cap on reply length, because a shorter reply means less time at full load.

The results

These are one-shot runs of the same kind of prompt, logged once a second. Temperatures are the CPU package (Package id 0 in sensors).

Run Setup Peak °C Avg °C Speed Result
Story, ~410 words Lunaris, stock 94 82 6.1 tok/s throttled ~13 s
Story, ~410 words Lunaris, cool mode 70 62 4.2 tok/s no throttling

Cool mode cost me about 30% of the generation speed and nothing in quality, because the model does exactly the same maths, only more slowly. Prompt processing stayed at about 14 tok/s either way. The temperature also levels off instead of climbing, so long sessions settle around 65–75 °C.

For comparison, a pure stress test (stress-ng --matrixprod on all 8 threads for 60 s) at the everyday 15/18 W level peaked at 81 °C with no throttling. That tells me the laptop's cooling hardware is fine, and the 94 °C was simply what happens when a CPU-only SLM is allowed unlimited power.

Checking the state at any time:

$ sudo slm-cool status          # while Lunaris runs
turbo off | epp power | PL1 12W PL2 12W

$ sudo slm-cool status          # after quitting
turbo on | epp balance_performance | PL1 15W PL2 18W

Tuning it for your machine

Every laptop cools differently, so treat 12 / 15 / 18 W as a starting point. Change one value at a time in /etc/slm-cool.conf, run the same prompt, and compare two numbers: the peak temperature from sensors, and the Generation: x t/s line that llama.cpp prints at the end. Lower watts give a cooler, slower run. Because everything resets on reboot, a bad value can't do lasting harm.

A few things to know:

  • This is Intel-specific. AMD CPUs have RAPL-style energy reporting too, but the power-limit controls are different, and this setup doesn't cover them.
  • Other power tools can override you. If you run TLP, thermald or power-profiles-daemon, check what they set so you aren't fighting them.
  • This isn't only for SLMs. sudo slm-cool on before a long render or a big compile works the same way.

The takeaway

If you run models CPU-only on an Intel laptop, look in /sys/class/powercap/ - the limiter is already there.


Ben Santora - November 2026

Want more #linux-intel-rapl-slm deep dives?

Join 6,143+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

Local-First: The Browser as the Vault

Pocket Portfolio - Apr 20

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

The Audit Trail of Things: Using Hashgraph as a Digital Caliper for Provenance

Ken W. Algerverified - Apr 28

Architecting a Local-First Hybrid RAG for Finance

Pocket Portfolio - Feb 25

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23
chevron_left
1.2k Points • 28 Badges
Montserrat MA • xiralinux.pages.dev
5Posts
21Comments
10Connections
Linux and AI Advocate - Creator of xiralinux - a lightweight Debian 12 + Openbox live distro built t... Show more

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!