Help: Using cpufreq from kernel level
Hi all,
I'm writing a kernel module that needs to get info about the available
frequencies on the current processor and to periodically change the current frequency.
At user level it can be done through
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
but I have no idea how to implement it at kernel level.
I tried to declare
extern struct cpufreq_driver *cpufreq_driver;
extern struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS];
extern spinlock_t cpufreq_driver_lock;
extern ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf);
and to do
char buffer [100000] = "\n"; spin_lock_irqsave(&cpufreq_driver_lock, flags); show_available_freqs(cpufreq_cpu_data[0], buffer); spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
but it crashes the system.
Please, can somebody tell me how this can be done ?
Many thanks,
Claudio Scordino
Quoted 5 lines · Claudio Scordino
Hi all,
I'm writing a kernel module that needs to get info about the available
frequencies on the current processor and to periodically change the current frequency.
So it seems you're writing a governor. SeeDocumentation/cpu-freq/governors.txt anddrivers/cpufreq/cpufreq_conservative.cdrivers/cpufreq/cpufreq_ondemand.cdrivers/cpufreq/cpufreq_performance.cdrivers/cpufreq/cpufreq_powersave.cdrivers/cpufreq/cpufreq_userspace.c
for a first reference.
Quoted 16 lines
At user level it can be done through
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeedbut I have no idea how to implement it at kernel level.
I tried to declare
extern struct
cpufreq_driver*cpufreq_driver;
extern structcpufreq_policy*cpufreq_cpu_data[NR_CPUS];
externspinlock_tcpufreq_driver_lock;
externssize_tshow_available_freqs(structcpufreq_policy*policy, char *buf);
Quoted 8 lines
and to do
char buffer [100000] = "\n";
spin_lock_irqsave(&cpufreq_driver_lock, flags);show_available_freqs(cpufreq_cpu_data[0], buffer);spin_unlock_irqrestore(&cpufreq_driver_lock, flags);but it crashes the system.
of course it does, this is just the sysfs -show function and you're passing it a null pointer as first parameter. If you look at show_available_freqs code you'll see that cpufreq_cpu_data is dereferenced and this happening with interrupts disabled..
hth
Signature · 2 lines
mattia :wq!
Hi,
Quoted 3 lines · Claudio Scordino
At user level it can be done through
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
Only on _some_ CPUs, and therefore it isn't part of the information available to governors.
Dominik
PS: Please use only the cpufreq mailing list for cpufreq-related questions in future