If you are getting an "invalid argument" error while trying to set the CPU scaling governor to "ondemand", it could be due to a variety of reasons such as the governor not being available or not being supported by your kernel or hardware configuration.
Here are some steps to debug and solve the issue:
Step 1: Check Available Governors
First, check which governors are available on your system:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
This command will show you a list of governors that are available. If "ondemand" is not listed, it means your system does not support it, and you cannot use it.
Step 2: Verify Modules Are Loaded
For some governors like "ondemand", you might need to make sure that the corresponding kernel module is loaded:
lsmod | grep cpufreq
If you don't see cpufreq_ondemand, you might try loading it manually:
sudo modprobe cpufreq_ondemand
Step 3: Setting the Governor
If "ondemand" is listed in the available governors, you should be able to set it using the following command:
echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Step 4: Check Permissions and SELinux/AppArmor
Ensure that you have the correct permissions and that SELinux or AppArmor is not blocking the operation. You can temporarily set SELinux to permissive mode (if SELinux is installed) to see if that resolves the issue:
sudo setenforce 0
Then try setting the governor again. If it works, you might need to adjust SELinux policies.
Step 5: Specific Core
Sometimes, setting the governor on one core might help identify if the issue is general or specific:
echo ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
Step 6: Kernel Version and Configuration
Make sure your kernel is up-to-date and properly configured to support the "ondemand" governor. Upgrading the kernel or recompiling it with specific configurations might be necessary in rare cases.
Example Script to Cycle Through Steps
Here's a script to run through some of the steps above:
#!/bin/bash
# Check available governors
echo "Available governors on cpu0:"
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
# Attempt to load ondemand module if necessary
if ! lsmod | grep -q cpufreq_ondemand; then
echo "Loading cpufreq_ondemand module..."
sudo modprobe cpufreq_ondemand
fi
# Set governor and check each attempt
echo "Attempting to set governor to ondemand:"
if echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; then
echo "Successfully set governor to ondemand"
else
echo "Failed to set governor to ondemand - checking permissions and SELinux"
echo "Setting SELinux to permissive (this might be temporary)"
sudo setenforce 0
if echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; then
echo "Successfully set governor to ondemand with SELinux permissive"
else
echo "Failed to set governor to ondemand even with SELinux permissive"
fi
fi
Run the script to cycle through the steps and identify where it might be failing.
If none of these steps solve your problem, it might be worth checking the documentation for your specific kernel and hardware, as there might be additional configuration required to support different governors.