Is there a way to run a process in an energy saving state in linux? In a per-process or per-cgroup manner. I'd like to not limit the CPU time/bandwidth but set an upper bound of the CPU power/frequency instead.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Yes, it's possible to control CPU frequency or power limits on a per-process or per-cgroup basis in Linux, although this is a somewhat advanced and system-dependent area. Most standard CPU governors operate at the global or per-policy level, but newer tools and methods, particularly with cgroups v2, offer better granularity.
🧠 Goal: Energy-efficient process execution
You do not want to limit CPU usage, but instead want to let the process use as much CPU time as it needs, while restricting the CPU frequency or power used for its execution. That is: limit CPU power, not CPU time.
🔧 Options
✅ 1. Cgroups v2 + Energy-Aware Scheduling (EAS)
On systems with recent kernels and using cgroups v2, you can benefit from the Energy-Aware Scheduler (EAS), particularly on ARM big.LITTLE systems or newer x86 CPUs with intel_pstate enabled.
While EAS doesn't give exact control, it lets the kernel schedule processes more "energy consciously", especially when grouped via cgroups. You can use:
Then configure certain parameters in the /sys/fs/cgroup/my_group/ directory.
However: setting power/frequency upper bounds directly is not a standard feature of EAS, but it lays groundwork for energy behavior optimization.
✅ 2. cpufreq Limits via cpufreq-set (Per-core)
You can set upper frequency limits per CPU core, and then pin your process to specific cores.
bash
# Set max frequency for CPU 3 to 1GHz
cpufreq-set -c 3 -u 1GHz
Then:
bash
# Pin process to CPU 3
taskset -c 3 your_process
This way, your process can use 100% CPU time on that core, but only within the 1GHz frequency.
Pros:
Simple and effective
Frequency enforced
Cons:
Not scalable for many processes
Manual CPU affinity management required
✅ 3. Using intel_cpufreq or amd-pstate Driver Features
If you're on a modern system using intel_pstate or amd-pstate, frequency limits can be controlled using:
bash
# Check available frequencies
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies
# Set max frequency globally or per-core
echo <max_freq> > /sys/devices/system/cpu/cpuX/cpufreq/scaling_max_freq
You can combine this with cset or taskset to "assign" low-power cores to processes.
✅ 4. cpufreq-governor + Affinity
Use the powersave governor on selected CPUs and run your process on these CPUs:
Intel platforms expose Running Average Power Limit (RAPL) via intel_rapl driver. With tools like powercap or rapl-read, you can control power domains (e.g., CPU package or core) limits.
Usage is more high-level and domain-specific than per-process, but indirect per-process control is possible via core binding.
✅ 6. Custom cgroup Hooks with eBPF (Advanced)
Using eBPF and cgroups, you could attach eBPF hooks to apply custom policies (e.g., tag a process and restrict available CPUFreq states). This is advanced and requires kernel support and programming knowledge.
🧪 Example: Restrict frequency via cgroup and affinity
bash
# Create a new cgroup
mkdir -p /sys/fs/cgroup/myenergygroup
echo $$ > /sys/fs/cgroup/myenergygroup/cgroup.procs
# Set up CPU affinity (say, CPU 2)
taskset -cp 2 $$
# Restrict CPU 2 max frequency
cpufreq-set -c 2 -u 1GHz
Then launch your energy-sensitive process in this environment.
🛑 What doesn't work:
nice or cgroup.cpu.weight – These prioritize or de-prioritize CPU time usage, but do not cap energy or frequency.
cpulimit – This throttles runtime, not frequency/power.
📌 Summary
Method
Per-Process?
Controls Frequency?
Notes
cpufreq-set + taskset
✅
✅
Manual CPU pinning
Cgroups v2 + EAS
✅ (grouped)
⚠️ Indirect
Needs kernel & scheduler support
intel_pstate / amd_pstate
⚠️ (per-core)
✅
Can emulate per-process effect
RAPL interface
❌
⚠️ (per-package)
Domain-level control
eBPF + cgroup BPF
✅
✅ (theoretical)
Advanced custom control
🔚 Conclusion
While there's no pure per-process CPU frequency cap API in mainline Linux, you can simulate this effectively by:
Setting per-core frequency limits
Binding a process to those cores
Optionally using cgroups for grouping
Would you like a script or daemon that automates this behavior (e.g., energy-capping a specific process)?