Hi, short question:
What is (in technical terms) CPU workload, and how do you measure it?
Thanks!
Measuring CPU usage / workload
Re: Measuring CPU usage / workload
Hi,
Consider the term "CPU utilization". This is a well-defined term - it's the amount of time a CPU spends doing something compared to the amount of time it spends doing nothing. If a CPU spends half of it's time doing nothing (e.g. "HLT") then it is 50% utilized.
Workload is different. If the CPU spends 50% of it's time doing some work, but half of that work is unimportant and could be skipped without consequence, then the CPU is 50% utilised but it's workload is only 25%. An example of this would be testing for faulty memory in idle time.
Similarly, if you give a CPU twice as much work as it can actually handle, then the workload would be 200% (but the utilization would only be 100%).
In a "perfect" system, the CPU workload would always be close to zero while the CPU utilization would always be close to 100% (i.e. the CPU spends all of it's time doing things in advance, so that nothing needs to be done when it's required).
Cheers,
Brendan
IMHO there is no simple answer to this question...BastiX wrote:What is (in technical terms) CPU workload, and how do you measure it?
Consider the term "CPU utilization". This is a well-defined term - it's the amount of time a CPU spends doing something compared to the amount of time it spends doing nothing. If a CPU spends half of it's time doing nothing (e.g. "HLT") then it is 50% utilized.
Workload is different. If the CPU spends 50% of it's time doing some work, but half of that work is unimportant and could be skipped without consequence, then the CPU is 50% utilised but it's workload is only 25%. An example of this would be testing for faulty memory in idle time.
Similarly, if you give a CPU twice as much work as it can actually handle, then the workload would be 200% (but the utilization would only be 100%).
In a "perfect" system, the CPU workload would always be close to zero while the CPU utilization would always be close to 100% (i.e. the CPU spends all of it's time doing things in advance, so that nothing needs to be done when it's required).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Measuring CPU usage / workload
...and ignoring things like power usage / battery life...Brendan wrote:In a "perfect" system...
Every good solution is obvious once you've found it.
Re: Measuring CPU usage / workload
Hi,
If you give every "unimportant" thing a rating from "worthwhile" to "waste of power", then you could progressively throttle the CPU's voltage/frequency down according to the relative unimportance of the work being done. For example, for things that are very likely to save power later you'd run them at 75% CPU throttling and for things that will probably only save a little power later you'd run at 25% CPU throttling.
This seems dodgy, but it isn't. The reason for this is that the relationship between CPU power consumption and CPU performance is not linear, and a CPU consumes power while doing nothing.
For example, consider a CPU that consumes 100 watts of power at 100% performance, 20 watts of power at 25% performance, and 10 watts of power in a HLT state. Now assume you've got some work to do that takes 1 second (at 100% performance), but there's a 10% chance it might not be needed.
The maths works out a little like this...
If you do the work in advance at 25% performance, then it'd take 4 seconds to complete and you'd use 20 watts for those 4 seconds. Then when the work is needed you'd spend that time idle because the work is already done. Total cost for the entire 5 seconds is 20 * 4 + 10 watts, or 90 watts.
If you wait until you know the work is needed, then you'd spend those first 4 seconds doing nothing. When you do find out that the work is needed you'd want to get it done fast, so you'd use 100% CPU performance for it. In this case total cost for those 5 seconds is 10 * 4 + 100 watts, or 140 watts.
If you do the work in advance but the work is never needed, then it'd still cost you 90 watts for those 5 seconds. If you don't do the work in advance and it's not needed, then you've spent 5 seconds doing nothing, or 5 * 10 = 50 watts.
Now we know that there's a 10% chance that this work won't be needed and need to adjust for that....
On average, doing the work in advance costs 90 * 0.9 + 90 * 0.1 watts, or 90 watts. Also on average, doing the work when necessary costs 140 * 0.9 + 50 * 0.1 watts, or 131 watts.
For this (admittedly contrived) example, doing the work in advance without knowing if it's actually necessary saves a significant amount of power, and when the user says "do the work" it looks like it's completed immediately.
Of course the real problem is finding things that can be done in advance that are likely to be needed later....
Cheers,
Brendan
Power usage could be taken into account...Solar wrote:...and ignoring things like power usage / battery life...Brendan wrote:In a "perfect" system...
If you give every "unimportant" thing a rating from "worthwhile" to "waste of power", then you could progressively throttle the CPU's voltage/frequency down according to the relative unimportance of the work being done. For example, for things that are very likely to save power later you'd run them at 75% CPU throttling and for things that will probably only save a little power later you'd run at 25% CPU throttling.
This seems dodgy, but it isn't. The reason for this is that the relationship between CPU power consumption and CPU performance is not linear, and a CPU consumes power while doing nothing.
For example, consider a CPU that consumes 100 watts of power at 100% performance, 20 watts of power at 25% performance, and 10 watts of power in a HLT state. Now assume you've got some work to do that takes 1 second (at 100% performance), but there's a 10% chance it might not be needed.
The maths works out a little like this...
If you do the work in advance at 25% performance, then it'd take 4 seconds to complete and you'd use 20 watts for those 4 seconds. Then when the work is needed you'd spend that time idle because the work is already done. Total cost for the entire 5 seconds is 20 * 4 + 10 watts, or 90 watts.
If you wait until you know the work is needed, then you'd spend those first 4 seconds doing nothing. When you do find out that the work is needed you'd want to get it done fast, so you'd use 100% CPU performance for it. In this case total cost for those 5 seconds is 10 * 4 + 100 watts, or 140 watts.
If you do the work in advance but the work is never needed, then it'd still cost you 90 watts for those 5 seconds. If you don't do the work in advance and it's not needed, then you've spent 5 seconds doing nothing, or 5 * 10 = 50 watts.
Now we know that there's a 10% chance that this work won't be needed and need to adjust for that....
On average, doing the work in advance costs 90 * 0.9 + 90 * 0.1 watts, or 90 watts. Also on average, doing the work when necessary costs 140 * 0.9 + 50 * 0.1 watts, or 131 watts.
For this (admittedly contrived) example, doing the work in advance without knowing if it's actually necessary saves a significant amount of power, and when the user says "do the work" it looks like it's completed immediately.
Of course the real problem is finding things that can be done in advance that are likely to be needed later....
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
It depends what you want to do with this information.
For me the most useful thing is the time spend running each process (including the idle thread).
You can then have information like the time ratio spent in the idle thread during the last minute for example. You could also separate cpu time spend for system and for user thread. That's pretty useful for profiling roughly.
For me the most useful thing is the time spend running each process (including the idle thread).
You can then have information like the time ratio spent in the idle thread during the last minute for example. You could also separate cpu time spend for system and for user thread. That's pretty useful for profiling roughly.