Skip to contentSkip to conversation

[2.5.32] CPU frequency and voltage scaling (0/4)

PATCH In review Dominik Brodowski 14 participants 39 messages Aug 28, 2002 – Sep 6, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 [2.5.32] CPU frequency and voltage scaling (0/4)

Hi Linus, lkml,

The following patches add CPU frequency and volatage scaling support (Intel SpeedStep, AMD PowerNow, etc.) to kernel 2.5.32

Patch 1/4: cpufreq-core
-----------------------
The cpufreq core offers a common interface to the CPU clock speed features of ARM, PPC and x86 CPUs.

For communication with user space, sysctl entries are placed in /proc/sys/cpu/{0,1,...,NR_CPUS-1}/ . Entries provided are:

speed-min (readonly)
speed-max (readonly)
speed-sync (readonly - all CPUs need the same frequency,
changes affect all CPUs)
speed (read/write)

In order for this code to be built, an architecture must define the CONFIG_CPU_FREQ configuration symbol. The merged ARM code already has the necessary configuration in place, the i386 code follows in parts 2 and 3.

Specifically on ARM CPUs, the core is especially important, since various ARM system on a chip implementations derive peripheral clocks from the CPU clock (eg, LCD controllers, SDRAM controllers, etc). The core allows these peripherals to take action either prior and/or after the actual CPU clock adjustment so we don't go out of tolerance.

Patch 2/4: cpufreq-i386-core
----------------------------
The main part of this patch is a CPUFreq notifier in arch/i386/kernel/time.c. It updates the i386-specific cpu_khz, cpu_data[].loops_per_jiffy and fast_gettimeoffset_quotient on each frequency change.

Additionally, this patch allows "cpu_khz" to be exported (it is needed for some cpufreq drivers) and adds some MSR #defines to asm-i386/msr.h

Patch 3/4: cpufreq-i386-drivers
-------------------------------
Four i386 CPUFreq drivers are ready to be merged this time. These are:
elanfreq.c: The AMD Elan CPU family offers extensive clock scaling
longhaul.c: VIA Longhaul processor clock + voltage scaling
powernow-k6.c: mobile AMD K6-2+ / mobile AMD K6-3+ clock scaling
speedstep.c: clock and voltage scaling on mobile Intel Pentium 3 and 4s,
but (unfortunately) only on ICH2-M or ICH3-M based chipsets.

Support for mobile AMD K7 processors is still in development.

Patch 4/4: cpufreq-doc
----------------------
an entry to the CREDITS and the MAINTAINERS file, Config.help texts, and extensive documentation in linux/Documentation/cpufreq

Comments welcome; however please ensure that the cpufreq development list at [email protected] receives a copy of all comments.

Dominik

#1 lore raw
Quoted 3 lines · Dominik Brodowski

The following patches add CPU frequency and volatage scaling support (Intel SpeedStep, AMD PowerNow, etc.) to kernel 2.5.32

The thing is, this interface appears fundamentally broken with respect to CPU's that change their frequency on the fly. I happen to know one such CPU rather well myself.

What is this interface supposed to do about a CPU that can change its frequency dynamically several hundred times a second? Having the OS control it simply isn't an option - the overhead of the control is _way_ more than is acceptable at that level.

In short, this interface is too broken to be called generic.

A quote from Peter Anvin:

"What is worse is that the interface is, in my opinion, fundamentally
broken for *ALL* CPUs. It doesn't present a policy interface to the kernel, instead it presents a frequency-setting interface and expect the policy to be done in userspace. The kernel is the only part of the system which has sufficient information (idle times of all CPUs, for example) to do a decent job managing the CPU frequency efficiently. On Transmeta CPUs this policy should simply be passed down to CMS, of course; on other CPUs the kernel needs to manage it."

In other words: there is no valid way that a _user_ can set the policy right now: the user can set the frequency, but since any sane policy depends on how busy the CPU is, the user isn't even, the right person to _do_ that, since the user doesn't _know_.

Also note that policy is not just about how busy the CPU is, but also about how _hot_ the CPU is. Again, a user-mode application (that maybe polls the situation every minute or so), simply _cannot_ handle this situation. You need to have the ability to poll the CPU tens of times a second to react to heat events, and clearly user mode cannot do that without impacting performance in a big way.

The interface needs to be improved upon. It is simply _not_ valid to say "run at this speed" as the primary policy.

Linus

#2 lore raw

It's even worse for some of the very new P4's that don't have their heatsink seated properly. They heat up every few minutes and then throttle themselves due to thermal overload. I think this situation is going to become more and more common, now. We're at the mercy of every BIOS and micro-code programmer now-a-days. That situation needs to be improved upon, as well.

} The interface needs to be improved upon. It is simply _not_ valid to say } "run at this speed" as the primary policy.

#3 lore raw
Quoted 4 lines · Cort Dougan

It's even worse for some of the very new P4's that don't have their heatsink seated properly. They heat up every few minutes and then throttle themselves due to thermal overload. I think this situation is going to become more and more common, now. We're at the mercy of every BIOS and

Systems designers are designing on the basis of thermal slowdowns being the optimal way to build some systems. Its actually quite reasonable for many workloads.

Quoted 2 lines

micro-code programmer now-a-days. That situation needs to be improved upon, as well.

Cpufreq doesn't handle this case yet in the 2.4 code but it already includes the needed udelay correction. Not everything CPUfreq has to deal with need be user initiated

#4 lore raw

My frustration comes from the fact that my CPU time is being stolen from me because of bad mechanical and software design. I'm not even notified of it. If there were some way for the OS to over-ride or even be notified of these events I'd have less of a problem with it. As it is now, poor system design is affecting OS design more and more.

} Systems designers are designing on the basis of thermal slowdowns being } the optimal way to build some systems. Its actually quite reasonable for } many workloads.
}
} > micro-code programmer now-a-days. That situation needs to be improved } > upon, as well.
}
} Cpufreq doesn't handle this case yet in the 2.4 code but it already } includes the needed udelay correction. Not everything CPUfreq has to } deal with need be user initiated
}

#5 lore raw
Quoted 5 lines · Cort Dougan

My frustration comes from the fact that my CPU time is being stolen from me because of bad mechanical and software design. I'm not even notified of it. If there were some way for the OS to over-ride or even be notified of these events I'd have less of a problem with it. As it is now, poor system design is affecting OS design more and more.

The P4 processor does send a notification (interrupt), there is support for this interrupt in newer kernels. I'm not sure about other processors.

Zwane

Signature · 1 line
function.linuxpower.ca
#6 lore raw
In reply to Alan Cox
Quoted 9 lines · Alan Cox
Quoted 4 lines · Cort Dougan

It's even worse for some of the very new P4's that don't have their heatsink seated properly. They heat up every few minutes and then throttle themselves due to thermal overload. I think this situation is going to become more and more common, now. We're at the mercy of every BIOS and

Systems designers are designing on the basis of thermal slowdowns being the optimal way to build some systems. Its actually quite reasonable for many workloads.

Don't forget the low end of the scale too...

An interface of this type even has applicability in the absence of a clock. Research in the Amulet group at Manchester University (home of the Amulet processors - self-timed ARM cores) and elsewhere is looking at management of /maximum/ power consumption (instantaneous power consumption is a function of the work to be done) by constraining the maximum number of instructions in flight, rather than the clocked equivalent of capping the clock frequency. This might be done where the power supply's capability is very limited (solar, wireless induction, smartcard, wind, etc).

This number can be managed by the processor if you build the right peripheral into the system, and this would need an equivalent interface for control - it wouldn't be a clock frequency, but it would be a number controlling the /maximum/ speed of the processor.

Peter

#7 lore raw
In reply to Alan Cox
Quoted 4 lines · Alan Cox

Systems designers are designing on the basis of thermal slowdowns being the optimal way to build some systems. Its actually quite reasonable for many workloads.

Absolutely. Thermal policy is often an overriding thing, where even non-transmeta CPU's will simply do the decision "on their own", without input from the OS. That's simply because some designs will literally not work above certain temperatures and do not have the heat sink capacity to get out of a tight spot by purely external cooling.

But that's just one part of it. Even aside from thermal concerns, you want to drop frequency aggressively when the machine is idle, because dropping the frequency allows you to drop the voltage and effetively gets you a cubed power reduction (which not only saves your battery, but also cools the chip down so that when you _do_ start going full speed again you have more thermal headroom).

So in order to avoid the thermal shutdown, you need to be proactive about the frequency. Which again means that a user-level "once a second" or "once in a blue moon" approach is fundamentally flawed.

I don't disagree with _also_ being able to set the frequency statically. However, I do disagree with an interface that seems to be _purely_ designed for this, and nothing else.

Linus

#8 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Alan Cox

Systems designers are designing on the basis of thermal slowdowns being the optimal way to build some systems. Its actually quite reasonable for many workloads.

Absolutely. Thermal policy is often an overriding thing, where even non-transmeta CPU's will simply do the decision "on their own", without input from the OS. That's simply because some designs will literally not work above certain temperatures and do not have the heat sink capacity to get out of a tight spot by purely external cooling.

But that's just one part of it. Even aside from thermal concerns, you want to drop frequency aggressively when the machine is idle, because dropping the frequency allows you to drop the voltage and effetively gets you a cubed power reduction (which not only saves your battery, but also cools the chip down so that when you _do_ start going full speed again you have more thermal headroom).

So in order to avoid the thermal shutdown, you need to be proactive about the frequency. Which again means that a user-level "once a second" or "once in a blue moon" approach is fundamentally flawed.

Just a data point from my application. First of all with VIA CPUs there is a 1ms delay per change when it resyncs things, so it's not practical to do it very often or for realtime apps etc.
My application was purely a heat reduction exercise where the timescale from 0°C to 70°C was around 10 minutes at max voltage/frequency, so it could easily be controlled by a userspace application. In fact I didn't control it manually and only set the frequency (for which the appropriate voltage was chosen by the cpufreq code) at system startup.

Quoted 3 lines

I don't disagree with _also_ being able to set the frequency statically. However, I do disagree with an interface that seems to be _purely_ designed for this, and nothing else.

Linus

Pádraig.

#9 lore raw
In reply to Cort Dougan
Quoted 6 lines · Cort Dougan

It's even worse for some of the very new P4's that don't have their heatsink seated properly. They heat up every few minutes and then throttle themselves due to thermal overload. I think this situation is going to become more and more common, now. We're at the mercy of every BIOS and micro-code programmer now-a-days. That situation needs to be improved upon, as well.

The P4 clock modulation driver was aware of that condition and in fact the processor would not allow changing the speed in a thermal throttled state anyway.

Zwane

Signature · 1 line
function.linuxpower.ca
#10 lore raw
In reply to Linus Torvalds
Quoted 9 lines

"What is worse is that the interface is, in my opinion, fundamentally
broken for *ALL* CPUs. It doesn't present a policy interface to the kernel, instead it presents a frequency-setting interface and expect the policy to be done in userspace. The kernel is the only part of the system which has sufficient information (idle times of all CPUs, for example) to do a decent job managing the CPU frequency efficiently. On Transmeta CPUs this policy should simply be passed down to CMS, of course; on other CPUs the kernel needs to manage it."

You might want to read the paper on the original cpufreq for ARM. It gives real world cases where the user -needs- to be able to control the policy. I think you misunderstand what the interface is about. Large numbers of systems benefit from usermode policy engines.

cpufreq is an interface that allows the user to control the processor speed. Period. It is not a policy, it is not a management system. Its business stops at "don't blow up the computer". It enables user space policies to be handled. It sequences events and notifies device drivers so they can handle speed changes that affect them. (eg reclocking the serial ports on the AMD Elan)

If you need a kernel policy engine then that should be a completely seperate module. The cpufreq interface hs to provide "please change speed" methods to the kernel. We already have one example of a kernel policy engine that wants this facility. That is ACPI with native processor speed control. ACPI is simply one possible policy engine.

Cpufreq is to power management as /dev/hda is to file systems.

Alan

#11 lore raw
Quoted 5 lines · Alan Cox

You might want to read the paper on the original cpufreq for ARM. It gives real world cases where the user -needs- to be able to control the policy. I think you misunderstand what the interface is about. Large numbers of systems benefit from usermode policy engines.

That's not the point.

The point is that the _policy_ (not the end result) needs to be pushed down to the kernel, so that the kernel can do the right thing with it.

That policy can be updated in "real time" from user space, of course. But the fact is that you cannot just set a frequency and leave it at that, it doesn't work.

Linus

#12 lore raw
Quoted 6 lines · Linus Torvalds

The point is that the _policy_ (not the end result) needs to be pushed down to the kernel, so that the kernel can do the right thing with it.

That policy can be updated in "real time" from user space, of course. But the fact is that you cannot just set a frequency and leave it at that, it doesn't work.

If you look at the papers on the original ARM cpufreq code you'll see a case where very long granuality user driven policy is pretty much essential. The kernel sometimes does not have enough information.

Take a trivial example. My CPU is 99% idle. Should you drop the clock speed right down. On a generic system yes, on a system which has to meet very tight real time deadlines quite possibly not. In fact some processors (eg the MediaGX) actually have hardware assists for speeding the CPU clock up for realtime interrupt processing paths.

That argument ultimately boils down to "should the /proc interface to cpufreq" be a seperate module to the core cpu_freq code called by kernel policy engines like ACPI. The answer is obviously "yes" - /proc is just one of the policy engines.

#13 lore raw
Quoted 4 lines · Alan Cox

If you look at the papers on the original ARM cpufreq code you'll see a case where very long granuality user driven policy is pretty much essential. The kernel sometimes does not have enough information.

Alan, that is _not_ the point here.

It's ok to tell the kernel these "long-term" policies. But it has to be told as a POLICY, not as a random number. Because I can show you a hundred other cases where the user mode code does _not_have_a_clue_.

That's my argument. The kernel should be given a _policy_, not a "this frequency". Because a frequency is provably not enough, and can be quite hurtful.

And I do not want to get people used to passing in frequencies, when I can absolutely _prove_ that it's the wrong thing for 99% of all uses.

Linus

#14 lore raw
Quoted 3 lines · Linus Torvalds

It's ok to tell the kernel these "long-term" policies. But it has to be told as a POLICY, not as a random number. Because I can show you a hundred other cases where the user mode code does _not_have_a_clue_.

Right and for the one in one hundred that is does I need a policy that suits it

Quoted 3 lines

That's my argument. The kernel should be given a _policy_, not a "this frequency". Because a frequency is provably not enough, and can be quite hurtful.

One of the policies I need from the kernel is "run at the frequency I told you to run". Its a policy, its not the general case policy. The /proc file is that policy.

Quoted 2 lines

And I do not want to get people used to passing in frequencies, when I can absolutely _prove_ that it's the wrong thing for 99% of all uses.

99% of people should be using something like ACPI.

cpufreq is cpu speed control not power management policy. I agree entirely that most people should not be using echo "500" >/proc/... as a power management policy.

Likewise /dev/hda is not a file system and peopel should not be using dd to store there files.

In both cases the ability to do so is sometimes useful and shouldnt be excluded.

#15 lore raw
Quoted 4 lines · Alan Cox

One of the policies I need from the kernel is "run at the frequency I told you to run". Its a policy, its not the general case policy. The /proc file is that policy.

That's ok, but the current code DOES NOT DO THAT.

The current code has no support at all for the notion of policies, and gives absolutely _zero_ support for it. It blindly assumes that the CPU can (and should) run at one frequency, and as long as it does that, I don't want it in the kernel.

Quoted 6 lines

cpufreq is cpu speed control not power management policy. I agree entirely that most people should not be using echo "500" >/proc/... as a power management policy.

Likewise /dev/hda is not a file system and peopel should not be using dd to store there files.

You've had that argument before, and it was bogus then - and it is bogus now.

It is possible to put a filesystem on top of /dev/hda - because the block layer is designed to allow it. It is not possible to build sane policy upon the current frequency patches, because it is _not_ designed for passing down the policy.

Exactly because some chips _need_ to have the policy passed down, the lowest levels need to be able to pass it down.

It is _then_ ok to say that "if you do a 'echo 500 > /proc/cpu/freq', that will also imply a policy of a fixed frequency". But if the frequency setting code does not allow for any policy interface AT ALL, then it is fundamentally broken.

That's my beef with it. We should not have "generic" interfaces that are known to be fundamentally broken. As it is, the code - as designed - is useless for a growing class of devices.

Think of it as a layering issue:
- user level policy
- kernel interface (possibly many - for different policies)
- low-level driver

Ok?

Now, what the current patches do is (a) one kernel interface (the fixed-frequency one) and (b) low-level drivers.

The kernel interface is fine - it doesn't do what I think many people might want to do, but it's simple and I agree that other policies can be implemented with other interfaces. Fine.

But the fact that low-level drivers don't even support the notion of a policy means that they are useless for any other interface. And I'm saying that it's a clear design bug, and for no good reason.

Linus

#16 lore raw
Quoted 46 lines · Linus Torvalds
Quoted 4 lines · Alan Cox

One of the policies I need from the kernel is "run at the frequency I told you to run". Its a policy, its not the general case policy. The /proc file is that policy.

That's ok, but the current code DOES NOT DO THAT.

The current code has no support at all for the notion of policies, and gives absolutely _zero_ support for it. It blindly assumes that the CPU can (and should) run at one frequency, and as long as it does that, I don't want it in the kernel.

Quoted 6 lines

cpufreq is cpu speed control not power management policy. I agree entirely that most people should not be using echo "500" >/proc/... as a power management policy.

Likewise /dev/hda is not a file system and peopel should not be using dd to store there files.

You've had that argument before, and it was bogus then - and it is bogus now.

Exactly because some chips _need_ to have the policy passed down, the lowest levels need to be able to pass it down.

It is _then_ ok to say that "if you do a 'echo 500 > /proc/cpu/freq', that will also imply a policy of a fixed frequency". But if the frequency setting code does not allow for any policy interface AT ALL, then it is fundamentally broken.

That's my beef with it. We should not have "generic" interfaces that are known to be fundamentally broken. As it is, the code - as designed - is useless for a growing class of devices.

Think of it as a layering issue:
- user level policy
- kernel interface (possibly many - for different policies)
- low-level driver

Ok?

Now, what the current patches do is (a) one kernel interface (the fixed-frequency one) and (b) low-level drivers.

Quoted 7 lines

The kernel interface is fine - it doesn't do what I think many people might want to do, but it's simple and I agree that other policies can be implemented with other interfaces. Fine.

But the fact that low-level drivers don't even support the notion of a policy means that they are useless for any other interface. And I'm saying that it's a clear design bug, and for no good reason.

As a user (for the sake of argument) i don't want to see an uneccesary proliferation of interfaces. There is no reason why the interface cannot be made policy aware from the beginning even if it starts out only supporting the one policy of fixed.

Something like 'echo "fixed 500M" >/proc/cpu/freak' would allow the addition of new policies without having to add new interfaces. Notice that i give the policy as the first parameter. Each policy should register itself with its callbacks (read, write, ?).

Probably should have a something like /proc/filesystems that reports supported policies since supportable policies would vary according to hardware + emulation.

Signature · 5 lines
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		[email protected]

		Remember Cernan and Schmitt
#17 lore raw
In reply to Alan Cox
Quoted 4 lines · Alan Cox
Quoted 2 lines

And I do not want to get people used to passing in frequencies, when I can absolutely _prove_ that it's the wrong thing for 99% of all uses.

99% of people should be using something like ACPI.

Current ACPI code does not adjust frequencies on its own, it relies on user input too.

Dominik

#18 lore raw
In reply to Alan Cox
Quoted 5 lines · Alan Cox

On Wed, 2002-08-28 at 20:49, Linus Torvalds wrote:
That argument ultimately boils down to "should the /proc interface to cpufreq" be a seperate module to the core cpu_freq code called by kernel policy engines like ACPI. The answer is obviously "yes" - /proc is just one of the policy engines.

So, what do all of you think of the following implementation?

#1 The "policy modules" (/proc-interface, kernel-based frequency selector, ...) determine the target CPU frequency.

#2 This is then passed to the cpufreq core. There it is validated, loops_per_jiffy and other values are adjusted.

#3 Then the cpufreq driver is called to actually set the CPU frequency.

#3 is absolutely ready, #2 in parts (the "policy module" interface is missing, and the /proc-interface needs to be removed), and #1 is TBD.

Comments?

Dominik

#19 lore raw
Quoted 4 lines · Dominik Brodowski

#3 Then the cpufreq driver is called to actually set the CPU frequency.

#3 is absolutely ready

#3 is _not_ ready, if it doesn't include a "policy" part in addition to the frequency. That was what I started off talking about: on some CPU's you absolutely do _not_ want to set a hard frequency, you want to tell the CPU how to behave (possibly together with a frequency _range_).

Until that is done, no other upper layers can use this low-level functionality, since all upper layers would be forced to come up with a hard frequency goal.

THAT is the problem. If you want to build infrastructure for upper layers, then that infrastructure has to be able to pass down sufficient information from those upper layers.

Think of this as a driver abstraction layer. Some hardware will do more for you, some will do less. Some hardware is the equivalent of a dumb frame buffer (where software has to change frequency and voltage by hand, and be careful about every single step and the delays in between), while some other hardware contains internal accelerators where you just tell them what you want, and the hardware will do it for you asynchronously.

The current abstraction layer _thinks_ that all hardware is stupid, and is thus not actually usable with smart hardware. See?

Linus

#20 lore raw

Hi!

Quoted 9 lines
Quoted 3 lines

#3 Then the cpufreq driver is called to actually set the CPU frequency.

#3 is absolutely ready

#3 is _not_ ready, if it doesn't include a "policy" part in addition to the frequency. That was what I started off talking about: on some CPU's you absolutely do _not_ want to set a hard frequency, you want to tell the CPU how to behave (possibly together with a frequency _range_).

Quoted 7 lines

Until that is done, no other upper layers can use this low-level functionality, since all upper layers would be forced to come up with a hard frequency goal.

THAT is the problem. If you want to build infrastructure for upper layers, then that infrastructure has to be able to pass down sufficient information from those upper layers.

So... would you take a patch that passed range down to cpufreq "core"?

Dumb cpus would set speed to upper limit while smart cpus would get all the info...

Pavel

Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt,
details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.
#21 lore raw
In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds
Quoted 5 lines · Alan Cox

You might want to read the paper on the original cpufreq for ARM. It gives real world cases where the user -needs- to be able to control the policy. I think you misunderstand what the interface is about. Large numbers of systems benefit from usermode policy engines.

Quoted 8 lines

That's not the point.

The point is that the _policy_ (not the end result) needs to be pushed down to the kernel, so that the kernel can do the right thing with it.

That policy can be updated in "real time" from user space, of course. But the fact is that you cannot just set a frequency and leave it at that, it doesn't work.

On the long term, maybe. But cpufreq is only the driver, which lets you have such a policy engine in the kernel. And as long as this policy engine doesn't exist, why not offer the user some control over his system?

Dominik

#22 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Dominik Brodowski

The following patches add CPU frequency and volatage scaling support (Intel SpeedStep, AMD PowerNow, etc.) to kernel 2.5.32

The thing is, this interface appears fundamentally broken with respect to CPU's that change their frequency on the fly. I happen to know one such CPU rather well myself.

Do these CPUs need kernel support? E.g. do udelay() calls work as expected? If so, there's no need to make a driver aware of something which isn't in its scope to control. CPUFreq is basically for those many systems where frequency switches need to be called from the OS.

Quoted 4 lines

What is this interface supposed to do about a CPU that can change its frequency dynamically several hundred times a second? Having the OS control it simply isn't an option - the overhead of the control is _way_ more than is acceptable at that level.

Well, that's probably the idea that's behind the microcode approach of certain CPUs. However, for many voltage-scaling-able CPUs there is no such microcode, and so the OS _needs_ to do it.

Quoted 4 lines

In other words: there is no valid way that a _user_ can set the policy right now: the user can set the frequency, but since any sane policy depends on how busy the CPU is, the user isn't even, the right person to _do_ that, since the user doesn't _know_.

This is only true on CPUs where frequency switches can occur "on the fly" with very low latency. Most voltage-scaling CPUs are currently found on mobile systems. For those notebook users it is a big step forward to have this ability of switching between "full speed" and "low speed" depending on the power source. And on LART systems even dynamic switching _from userspace_ has proven to be successful (see OLS talk my Erik Mouw). Please note that even a "kernel-based frequency selector" needs large parts of the cpufreq core and drivers: udelay() calls need to be accurate, external limitations (like on ARM systems) need to be integrated, and the frequency and voltage switching mechanisms need to be implemented -- so is there any reason why this "kernel-based frequency selector" couldn't just use the existing interface: cpufreq_set()?

Quoted 6 lines

Also note that policy is not just about how busy the CPU is, but also about how _hot_ the CPU is. Again, a user-mode application (that maybe polls the situation every minute or so), simply _cannot_ handle this situation. You need to have the ability to poll the CPU tens of times a second to react to heat events, and clearly user mode cannot do that without impacting performance in a big way.

IMHO a cpufreq interface shouldn't become too bloated. If it would try to drop the frequency quite aggressively this should be enough, critical-temperature shutdown / throttling mechanisms will take care of emergenices.

Quoted 2 lines

The interface needs to be improved upon. It is simply _not_ valid to say "run at this speed" as the primary policy.

This is right. But a sane kernel-based frequency selector doesn't exist yet. Even if it existed, it would need large parts of the cpufreq patches submitted today. And these offer some support which isn't the best thing since sliced bread but still is happily used by users.

Dominik

#23 lore raw
Quoted 3 lines · Dominik Brodowski

Do these CPUs need kernel support? E.g. do udelay() calls work as expected?

Crusoe CPU's do not.

But Intel CPU's _do_ need this, for example (since they change the TSC frequency).

And Intel CPU's do _not_ want to have user mode telling them what to do several times a second - yet it's entirely reasonable to have a kernel timer function that estimates processor load at every timer tick, and reacts to that a few times a second.

Which is why such a CPU needs to be passed in a _policy_. Which is my whole argument.

Let's put it another way, because I've seen people at Transmeta scramble when Microsoft thought it was a good idea to have the OS tell what frequency the CPU should run at, and trust me, they got it wrong. From my contacts at Intel, I can promise you that they got it wrong wrt Intel's chips too, so this is not a Transmeta-only issue.

All I'm saying is that instead of a frequency, you should take more of a "what is the goal of this" approach, and pass in _that_. Then, in user land, you might have a situation where you know that "the goal is to run at 300MHz, and nothing else". That may sometimes be the right goal, but quite often it isn't.

And THAT IS MY POINT. If you have a more policy-oriented interface, everybody can work with it. If you have a strict "this frequency" approach, some people literally _cannot_ live with it, and will end up throttling behind your back.

The goals may be:
- "low power" vs "high performance"
Obvious. "Aggressive power management" vs "Power management with performance as the primary goal"

- "strive for max 20% idle"

The kernel may slow down the clock if the timer tick shows lots of idle time. Tell the rest of the system when you do so.

- "RT latency - 300MHz minimum"
The idle loop might drop the frequency, but not past a certain point.

- "run at exactly 500 MHz"

Notice how only the _last_ goal is expressible in the "frequency" space. Everything else needs at least one additional piece of information, ie the policy the kernel/CPU should take wrt the power management.

Linus

#24 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Dominik Brodowski

Do these CPUs need kernel support? E.g. do udelay() calls work as expected?

Crusoe CPU's do not.

Great.

Quoted 2 lines

But Intel CPU's _do_ need this, for example (since they change the TSC frequency).

And that's why there is some need for a cpufreq core (which manages loops_per_jiffy etc.) and the need for the cpufreq drivers (#2 and #3 in my previous mail).

Quoted 2 lines

Which is why such a CPU needs to be passed in a _policy_. Which is my whole argument.

Which is #1 - the "input" to the cpufreq core. This can be seperated from the cpufreq core. So basically

"policy input" --> "frequency input" --> cpufreq core --> cpufreq driver
user-space | k e r n e l - s p a c e

instead of

"policy input" --> "frequency input" --> cpufreq core --> cpufreq driver
u s e r - s p a c e | k e r n e l - s p a c e

Linus, would you agree to the /proc interface as one of several frequency "input"/management options? It's good for testing, for some workloads (LART), and it's (almost) done (just needs seperating from the cpufreq core)...

Dominik

#25 lore raw
Quoted 3 lines · Dominik Brodowski

"policy input" --> "frequency input" --> cpufreq core --> cpufreq driver
user-space | k e r n e l - s p a c e

No.

The "policy input" has to filter down ALL THE WAY. If you turn it into a frequency-only input at _any_ time, you've lost information that the lowest levels need.

THAT is the problem with the current #3 - it _assumes_ that the policy input has already been converted to frequency, and since it assumes that, it cannot handle the case where the hardware itself wants to know what the policy was.

Linus

#26 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Dominik Brodowski

"policy input" --> "frequency input" --> cpufreq core --> cpufreq driver
user-space | k e r n e l - s p a c e

No.

Quoted 8 lines

The "policy input" has to filter down ALL THE WAY. If you turn it into a frequency-only input at _any_ time, you've lost information that the lowest levels need.

THAT is the problem with the current #3 - it _assumes_ that the policy input has already been converted to frequency, and since it assumes that, it cannot handle the case where the hardware itself wants to know what the policy was.

I wonder about converting it to frequency at most any level. Why not some abstract such as % of full speed, or % of full power. I, for one, don't want to have to think absolute numbers. First thing you know I will have a new box with different numbers. Then what?

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#27 lore raw
In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Dominik Brodowski

"policy input" --> "frequency input" --> cpufreq core --> cpufreq driver
user-space | k e r n e l - s p a c e

No.

The "policy input" has to filter down ALL THE WAY. If you turn it into a frequency-only input at _any_ time, you've lost information that the lowest levels need.

So what you are saying is that you want to be sure that something like "please run at a low speed to save battery" is translated by smarter cpus into "please save battery" and on spudstop the CPU would go "umm duh ok 300MHz"

Ok now I think I understand your gripe.

#28 lore raw
Quoted 5 lines · Alan Cox

So what you are saying is that you want to be sure that something like "please run at a low speed to save battery" is translated by smarter cpus into "please save battery" and on spudstop the CPU would go "umm duh ok 300MHz"

Yup, exactly.

I suspect that this is also what most people actually want to use anyway:
you don't care that your CPU is a speedstep 1GHz/500Mhz or a 700/300 (or whatever the combinations are), you really want to just say "go to power save mode" vs "go to performance mode".

Sure, for speedstep, you can obviously trivially _emulate_ this in user mode with the frequency approach, but for the generic case it isn't.

I don't know how many policies would be needed (too many just adds complexity for no gain), but I _suspect_ that something like a

{ min-Hz, max-Hz, policy }

triple with "policy" being just a few different values ("performance", "powersave") is sufficient. Clearly this triple trivially _becomes_ the "single MHz" by just making min and max be the same if you really want one particular MHz (at which time "policy" doesn't matter).

With something like the above, you could do something like

	{ 0, ~0UL, "performance" }	=> generic highest performance setting
	{ 0, ~0UL, "power-save" }	=> generic power-save setting
	{ 300, 500, "performance" }	=> give me a performance setting in the specified range
	{ 1700, 1700, "performance" }	=> run at a fixed 1.7GHz

(maybe the "policy" thing actually makes a difference even for the fixed-frequency case: it can give hints about whether to allow C1-C3 states when idle etc).

Linus

#29 lore raw
Quoted 2 lines · Linus Torvalds

I don't know how many policies would be needed (too many just adds complexity for no gain), but I _suspect_ that something like a

<snip>

Quoted 3 lines

(maybe the "policy" thing actually makes a difference even for the fixed-frequency case: it can give hints about whether to allow C1-C3 states when idle etc).

OK, I see the problems you mention wrt current cpufreq. But let's keep the next version simple: and whether to allow C1-C3 is really nothing cpufreq should take care of, as this is pure ACPI policy.

Dominik

#30 lore raw
In reply to Linus Torvalds
Quoted 25 lines · Linus Torvalds
Quoted 4 lines · Alan Cox

So what you are saying is that you want to be sure that something like "please run at a low speed to save battery" is translated by smarter cpus into "please save battery" and on spudstop the CPU would go "umm duh ok 300MHz"

Yup, exactly.

I suspect that this is also what most people actually want to use anyway: you don't care that your CPU is a speedstep 1GHz/500Mhz or a 700/300 (or whatever the combinations are), you really want to just say "go to power
save mode" vs "go to performance mode".

Sure, for speedstep, you can obviously trivially _emulate_ this in user mode with the frequency approach, but for the generic case it isn't.

I don't know how many policies would be needed (too many just adds complexity for no gain), but I _suspect_ that something like a

{ min-Hz, max-Hz, policy }

triple with "policy" being just a few different values ("performance", "powersave") is sufficient. Clearly this triple trivially _becomes_ the "single MHz" by just making min and max be the same if you really want one particular MHz (at which time "policy" doesn't matter).

Quoted 6 lines

With something like the above, you could do something like

	{ 0, ~0UL, "performance" }	=> generic highest performance setting
	{ 0, ~0UL, "power-save" }	=> generic power-save setting
	{ 300, 500, "performance" }	=> give me a performance setting in the specified range
	{ 1700, 1700, "performance" }	=> run at a fixed 1.7GHz

I would go for a quadruple:

{ 0, ~0UL, 0, "performance" } => generic highest performance setting
{ 0, ~0UL, 0, "power-save" } => generic power-save setting
{ 300, 500, 0, "performance" } => give me a performance setting in the {
1700, 1700, 70"performance" } => run at a fixed 1.7GHz
{ 0, ~0UL, 70, "performance" } => performance but don't go above 70°C

would you also want a hysteris value?

Pádraig.

Quoted 5 lines

(maybe the "policy" thing actually makes a difference even for the fixed-frequency case: it can give hints about whether to allow C1-C3 states when idle etc).

Linus

#31 lore raw
In reply to Linus Torvalds
Quoted 2 lines

{ min-Hz, max-Hz, policy }

For a few of the processors "event-hz" or similar would be nice. The Geode supports hardware assisted bursting to full processor speed when doing SMM, I/O and IRQ handling.

#32 lore raw
Quoted 4 lines · Alan Cox
Quoted 1 line

{ min-Hz, max-Hz, policy }

For a few of the processors "event-hz" or similar would be nice. The Geode supports hardware assisted bursting to full processor speed when doing SMM, I/O and IRQ handling.

If we do implement (for sake of argument) /proc/sys/performance or whatever, changing the cpufreq interface so it performs 'stacking' would be a good idea too.
Eg, on a K6-3+ system, we could do cpu scaling and chipset throttling just by doing a echo "min" > /proc/sys/perf or whatever, and have the code call 'chains' of performance related features.

Comments?

Dave

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs
#33 lore raw
In reply to Alan Cox

In article <[email protected]>,

Quoted 6 lines · Alan Cox
Quoted 2 lines

{ min-Hz, max-Hz, policy }

For a few of the processors "event-hz" or similar would be nice. The Geode supports hardware assisted bursting to full processor speed when doing SMM, I/O and IRQ handling.

Hmm.. I would assume that you'd just use the high frequency for that? So, for example, assuming you have a 600/300 Geode, when you do

	{ 0, ~0UL, "power-save" }

that would tell the Geode driver to run at 300MHz normally ("power-save"), and at 600Mhz when doing critical events.

In contrast, a

	{ 0, ~0UL, "performance" }

mode would mean that it always runs at 600MHz (modulo heat throttling, of course).

And a

	{ 300, 300, "power-save" }

means that you want the chip to always run at 300MHz, even when handling critical events.

I don't know the exact details of what kinds of frequencies the Geode supports, but it sounds to me like you don't really need another frequency value..

Linus

#34 lore raw
Quoted 1 line · Linus Torvalds

Hmm.. I would assume that you'd just use the high frequency for that?

That doesnt work if Im trying to keep the machine running slowly at low power but still want the I/O to work. I guess its fudgeable however and the battery policy is enough info.

Quoted 3 lines

I don't know the exact details of what kinds of frequencies the Geode supports, but it sounds to me like you don't really need another frequency value..

It tops out at about 300Mhz. Life gets excessively interesting because about half the I/O on the Geode is imaginary and caused by SMM traps. When power saving you normally set the geode to run slowly but spike hard to full power when faking hardware. WIthout that some stuff like the SB emulation doesnt work very well.

Alan

#35 lore raw
In reply to Linus Torvalds
Quoted 20 lines · Linus Torvalds

In article <[email protected]>,

Quoted 6 lines · Alan Cox
Quoted 2 lines

{ min-Hz, max-Hz, policy }

For a few of the processors "event-hz" or similar would be nice. The Geode supports hardware assisted bursting to full processor speed when doing SMM, I/O and IRQ handling.

Hmm.. I would assume that you'd just use the high frequency for that? So, for example, assuming you have a 600/300 Geode, when you do

        { 0, ~0UL, "power-save" }

that would tell the Geode driver to run at 300MHz normally ("power-save"), and at 600Mhz when doing critical events.

In contrast, a

Quoted 8 lines
        { 0, ~0UL, "performance" }

mode would mean that it always runs at 600MHz (modulo heat throttling, of course).

And a

        { 300, 300, "power-save" }

How about { 50, 50, "power-save" } where the number refers to percent of full?
I.e. same meaning IFF full is 600, but suppose it is 800.

Quoted 14 lines

means that you want the chip to always run at 300MHz, even when handling critical events.

I don't know the exact details of what kinds of frequencies the Geode supports, but it sounds to me like you don't really need another frequency value..

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#36 lore raw
Quoted 26 lines · george anzinger
Quoted 25 lines · Linus Torvalds

In article <[email protected]>,

Quoted 6 lines · Alan Cox
Quoted 2 lines

{ min-Hz, max-Hz, policy }

For a few of the processors "event-hz" or similar would be nice. The Geode supports hardware assisted bursting to full processor speed when doing SMM, I/O and IRQ handling.

Hmm.. I would assume that you'd just use the high frequency for that? So, for example, assuming you have a 600/300 Geode, when you do

        { 0, ~0UL, "power-save" }

that would tell the Geode driver to run at 300MHz normally ("power-save"), and at 600Mhz when doing critical events.

In contrast, a

        { 0, ~0UL, "performance" }

mode would mean that it always runs at 600MHz (modulo heat throttling, of course).

Quoted 7 lines
Quoted 3 lines

And a

        { 300, 300, "power-save" }

How about { 50, 50, "power-save" } where the number refers to percent of full?
I.e. same meaning IFF full is 600, but suppose it is 800.

Um... how about not. I can't think of a single situation in which specifying this as a percentage of full speed is useful. It's even less useful than raw MHz.

Signature · 4 lines
David Gibson			| For every complex problem there is a
[email protected]	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson
#37 lore raw
In reply to george anzinger
Quoted 3 lines · george anzinger

How about { 50, 50, "power-save" } where the number refers to percent of full?
I.e. same meaning IFF full is 600, but suppose it is 800.

Percentages don't buy you anything. Sure, a new cpu has a different max setting, but you may get the same problem with your percentages:

The "old" cpu ran well with 50% for power saving and 100% for performance. The "new" might want 30% for power to work well. So, the numbers change anyway.

Helge Hafting

#38 lore raw
In reply to Alan Cox

be careful here, it's not unreasonable to imagine a power saving mode that shuts down one CPU of a SMP machine.

don't make assumptions about what parameters make sense for all possible policies, try to find some way for the parameters to depend on the policy selected.

David Lang

Quoted 20 lines · Alan Cox

Date: 29 Aug 2002 11:53:40 +0100
From: Alan Cox <[email protected]>
To: Linus Torvalds <[email protected]>
Cc: Dominik Brodowski <[email protected]>, [email protected],
[email protected]
Subject: Re: [PATCH][2.5.32] CPU frequency and voltage scaling (0/4)

Quoted 2 lines

{ min-Hz, max-Hz, policy }

For a few of the processors "event-hz" or similar would be nice. The Geode supports hardware assisted bursting to full processor speed when doing SMM, I/O and IRQ handling.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/