All of lore.kernel.org
 help / color / mirror / Atom feed
* Help: Using cpufreq from kernel level
@ 2005-12-17 18:10 Claudio Scordino
  2005-12-17 18:27   ` Mattia Dongili
  2005-12-17 20:58 ` Dominik Brodowski
  0 siblings, 2 replies; 5+ messages in thread
From: Claudio Scordino @ 2005-12-17 18:10 UTC (permalink / raw)
  To: cpufreq; +Cc: kernelnewbies, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help: Using cpufreq from kernel level
       [not found] <5kOPa-5vo-23@gated-at.bofh.it>
@ 2005-12-17 18:24 ` Robert Hancock
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Hancock @ 2005-12-17 18:24 UTC (permalink / raw)
  To: linux-kernel

Claudio Scordino wrote:
> 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 ?

For one thing, you cannot put such a huge buffer on the kernel stack.

-- 
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help: Using cpufreq from kernel level
  2005-12-17 18:10 Claudio Scordino
@ 2005-12-17 18:27   ` Mattia Dongili
  2005-12-17 20:58 ` Dominik Brodowski
  1 sibling, 0 replies; 5+ messages in thread
From: Mattia Dongili @ 2005-12-17 18:27 UTC (permalink / raw)
  To: Claudio Scordino; +Cc: kernelnewbies, cpufreq, linux-kernel

On Sat, Dec 17, 2005 at 01:10:33PM -0500, Claudio Scordino wrote:
> 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. See
Documentation/cpu-freq/governors.txt and
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_ondemand.c
drivers/cpufreq/cpufreq_performance.c
drivers/cpufreq/cpufreq_powersave.c
drivers/cpufreq/cpufreq_userspace.c

for a first reference.

> 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.

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
-- 
mattia
:wq!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help: Using cpufreq from kernel level
@ 2005-12-17 18:27   ` Mattia Dongili
  0 siblings, 0 replies; 5+ messages in thread
From: Mattia Dongili @ 2005-12-17 18:27 UTC (permalink / raw)
  To: Claudio Scordino; +Cc: cpufreq, kernelnewbies, linux-kernel

On Sat, Dec 17, 2005 at 01:10:33PM -0500, Claudio Scordino wrote:
> 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. See
Documentation/cpu-freq/governors.txt and
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_ondemand.c
drivers/cpufreq/cpufreq_performance.c
drivers/cpufreq/cpufreq_powersave.c
drivers/cpufreq/cpufreq_userspace.c

for a first reference.

> 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.

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
-- 
mattia
:wq!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help: Using cpufreq from kernel level
  2005-12-17 18:10 Claudio Scordino
  2005-12-17 18:27   ` Mattia Dongili
@ 2005-12-17 20:58 ` Dominik Brodowski
  1 sibling, 0 replies; 5+ messages in thread
From: Dominik Brodowski @ 2005-12-17 20:58 UTC (permalink / raw)
  To: Claudio Scordino; +Cc: cpufreq

Hi,

On Sat, Dec 17, 2005 at 01:10:33PM -0500, Claudio Scordino wrote:
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-12-17 20:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <5kOPa-5vo-23@gated-at.bofh.it>
2005-12-17 18:24 ` Help: Using cpufreq from kernel level Robert Hancock
2005-12-17 18:10 Claudio Scordino
2005-12-17 18:27 ` Mattia Dongili
2005-12-17 18:27   ` Mattia Dongili
2005-12-17 20:58 ` Dominik Brodowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.