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, there are several approaches to achieve energy-saving states for specific processes or cgroups in Linux, though most involve indirect methods since CPU frequency control is typically per-core rather than per-process:
1. CPU Affinity + Per-Core Frequency Control
Bind your process to specific cores and set those cores to lower frequencies:
bash
# Set CPU affinity to cores 2-3
taskset -c 2,3 your_process
# Set frequency for those cores (requires userspace governor)
echo userspace > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo 1600000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_setspeed
2. Intel RAPL (Running Average Power Limit)
For Intel CPUs, you can use RAPL to set power limits via cgroups or directly:
bash
# Using powercap interface
echo 15000000 > /sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw
3. Cgroups v2 with CPU Controller
While cgroups v2 doesn't directly control frequency, you can use the cpu.weight to give processes lower priority, which indirectly reduces power consumption:
bash
# Create a low-priority cgroup
mkdir /sys/fs/cgroup/lowpower
echo 100 > /sys/fs/cgroup/lowpower/cpu.weight # Default is 100, lower = less priority
# Add process to cgroup
echo $PID > /sys/fs/cgroup/lowpower/cgroup.procs
4. Intel Speed Select Technology (SST)
On newer Intel Xeon processors, SST allows per-core frequency control:
bash
# Check if available
intel-speed-select --info
# Configure specific cores for lower power
intel-speed-select core-power --enable
5. cpupower and schedutil Governor
The schedutil governor can adjust frequency based on process load:
bash
# Enable schedutil governor
cpupower frequency-set -g schedutil
# Use nice values or cgroup cpu.weight to influence frequency decisions
nice -n 19 your_process
6. Custom Solution with cpuset
Create a dedicated CPU set with lower frequency:
bash
# Create cpuset cgroup
mkdir /sys/fs/cgroup/cpuset/lowpower
echo 4-7 > /sys/fs/cgroup/cpuset/lowpower/cpuset.cpus
echo 0 > /sys/fs/cgroup/cpuset/lowpower/cpuset.mems
# Set those CPUs to lower frequency
for cpu in 4 5 6 7; do
echo powersave > /sys/devices/system/cpu/cpu$cpu/cpufreq/scaling_governor
done
# Add process to cpuset
echo $PID > /sys/fs/cgroup/cpuset/lowpower/tasks
The most practical approach depends on your specific hardware and requirements. For modern systems, combining CPU affinity with per-core frequency control or using the schedutil governor with process priorities often works best. Note that you'll need appropriate permissions (usually root) to modify these settings.