Commit graph

66 commits

Author SHA1 Message Date
Prarit Bhargava
d0e4a193c3 tools/power/cpupower: allow running without cpu0
Linux-3.7 added CONFIG_BOOTPARAM_HOTPLUG_CPU0,
allowing systems to offline cpu0.

But when cpu0 is offline, cpupower monitor will not display all
processor and Mperf information:

[root@intel-skylake-dh-03 cpupower]# ./cpupower monitor
WARNING: at least one cpu is offline
    |Idle_Stats
CPU | POLL | C1-S | C1E- | C3-S | C6-S | C7s- | C8-S
   4|  0.00|  0.00|  0.00|  0.00|  0.90|  0.00| 96.13
   1|  0.00|  0.00|  5.49|  0.00|  0.01|  0.00| 92.26
   5|  0.00|  0.00|  0.00|  0.00|  0.46|  0.00| 99.50
   2| 45.42|  0.00|  0.00|  0.00| 22.94|  0.00| 28.84
   6|  0.00| 37.54|  0.00|  0.00|  0.00|  0.00|  0.00
   3|  0.00|  0.00|  0.00|  0.00|  0.30|  0.00| 91.99
   7|  0.00|  0.00|  0.00|  0.00|  4.70|  0.00|  0.70

This patch replaces the hard-coded use of cpu0 in cpupower with the
current cpu, allowing it to run without a cpu0.

After the patch is applied,

[root@intel-skylake-dh-03 cpupower]# ./cpupower monitor
WARNING: at least one cpu is offline
    |Nehalem                    || Mperf              || Idle_Stats
CPU | C3   | C6   | PC3  | PC6  || C0   | Cx   | Freq || POLL | C1-S | C1E- | C3-S | C6-S | C7s- | C8-S
   4|  0.01|  1.27|  0.00|  0.00||  0.04| 99.96|  3957||  0.00|  0.00|  0.00|  0.00|  1.43|  0.00| 98.52
   1|  0.00| 98.82|  0.00|  0.00||  0.05| 99.95|  3361||  0.00|  0.00|  0.01|  0.00|  0.03|  0.00| 99.88
   5|  0.00| 98.82|  0.00|  0.00||  0.09| 99.91|  3917||  0.00|  0.00|  0.00|  0.00| 99.38|  0.00|  0.50
   2|  0.33|  0.00|  0.00|  0.00||  0.00|100.00|  3890||  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|100.00
   6|  0.33|  0.00|  0.00|  0.00||  0.01| 99.99|  3903||  0.00|  0.00|  0.00|  0.00|  0.00|  0.00| 99.99
   3|  0.01|  0.71|  0.00|  0.00||  0.06| 99.94|  3678||  0.00|  0.00|  0.00|  0.00|  0.80|  0.00| 99.13
   7|  0.01|  0.71|  0.00|  0.00||  0.03| 99.97|  3538||  0.00|  0.69| 11.70|  0.00|  0.00|  0.00| 87.57

There are some minor cleanups included in this patch.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-07-31 14:17:30 +02:00
Sherry Hurwitz
902bef73fa cpupower: Add support for new AMD family 0x17
Add support for new AMD family 0x17
- Add bit field changes to the msr_pstate structure
- Add the new formula for the  calculation of cof
- Changed method to access to CpbDis

Signed-off-by: Sherry Hurwitz <sherry.hurwitz@amd.com>
Acked-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-06-27 01:43:22 +02:00
Sherry Hurwitz
6ae78b4e7c cpupower: Fix bug where return value was not used
Save return value from amd_pci_get_num_boost_states
and remove redundant setting of *support

Signed-off-by: Sherry Hurwitz <sherry.hurwitz@amd.com>
Reviewed-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-06-27 01:43:21 +02:00
Ben Hutchings
4cca045768 cpupower: Fix turbo frequency reporting for pre-Sandy Bridge cores
The switch that conditionally sets CPUPOWER_CAP_HAS_TURBO_RATIO and
CPUPOWER_CAP_IS_SNB flags is missing a break, so all cores get both
flags set and an assumed base clock of 100 MHz for turbo values.

Reported-by: GSR <gsr.bugs@infernal-iceberg.com>
Tested-by: GSR <gsr.bugs@infernal-iceberg.com>
References: https://bugs.debian.org/859978
Fixes: 8fb2e440b2 (cpupower: Show Intel turbo ratio support via ...)
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-04-13 14:51:10 +02:00
Stafford Horne
4da39ceb26 cpupower: Restore format of frequency-info limit
The intel_pstate kselftest expects that the output of
`cpupower frequency-info -l | tail -1 | awk ' { print $1 } '`
to get frequency limits.  This does not work after the following two
changes.

 - 562e5f1a3: rework the "cpupower frequency-info" command
   (Jacob Tanenbaum) removed parsable limit output
 - ce512b840: Do not analyse offlined cpus
   (Thomas Renninger) added newline to break limit parsing more

This change preserves human readable output if wanted as well as
parsable output for scripts/tests.

Cc: Thomas Renninger <trenn@suse.com>
Cc: "Shreyas B. Prabhu" <shreyas@linux.vnet.ibm.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Stafford Horne <shorne@gmail.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-01-19 10:30:28 -07:00
Laura Abbott
c25badc9ce cpupower: Correct return type of cpu_power_is_cpu_online() in cpufreq-set
When converting to a shared library in ac5a181d06 ("cpupower: Add
cpuidle parts into library"), cpu_freq_cpu_exists() was converted to
cpupower_is_cpu_online(). cpu_req_cpu_exists() returned 0 on success and
-ENOSYS on failure whereas cpupower_is_cpu_online returns 1 on success.
Check for the correct return value in cpufreq-set.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=1374212
Fixes: ac5a181d06 (cpupower: Add cpuidle parts into library)
Reported-by: Julian Seward <jseward@acm.org>
Signed-off-by: Laura Abbott <labbott@redhat.com>
Acked-by: Thomas Renninger <trenn@suse.com>
Cc: 4.7+ <stable@vger.kernel.org> # 4.7+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2016-11-01 06:16:52 +01:00
Thomas Renninger
ac5a181d06 cpupower: Add cpuidle parts into library
This more or less is a renaming and moving of functions and should not
introduce any functional change.

cpupower was built from cpufrequtils (which had a C library providing easy
access to cpu frequency platform info). In the meantime it got enhanced
by quite some neat cpuidle userspace tools.

Now the cpu idle functions have been separated and added to the cpupower.so
library.
So beside an already existing public header file:
cpufreq.h
cpupower now also exports these cpu idle functions in:
cpuidle.h

Here again pasted for better review of the interfaces:

======================================
int cpuidle_is_state_disabled(unsigned int cpu,
                                       unsigned int idlestate);
int cpuidle_state_disable(unsigned int cpu, unsigned int idlestate,
                                   unsigned int disable);
unsigned long cpuidle_state_latency(unsigned int cpu,
                                                unsigned int idlestate);
unsigned long cpuidle_state_usage(unsigned int cpu,
                                        unsigned int idlestate);
unsigned long long cpuidle_state_time(unsigned int cpu,
                                                unsigned int idlestate);
char *cpuidle_state_name(unsigned int cpu,
                                unsigned int idlestate);
char *cpuidle_state_desc(unsigned int cpu,
                                unsigned int idlestate);
unsigned int cpuidle_state_count(unsigned int cpu);

char *cpuidle_get_governor(void);
char *cpuidle_get_driver(void);

======================================

Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2016-04-28 16:02:29 +02:00
Shreyas B. Prabhu
38cb76a307 cpupower: Fix build error in cpufreq-info
Fix the following build error by including limits.h -

utils/cpufreq-info.c: In function ‘get_latency’:
utils/cpufreq-info.c:437:29: error: ‘UINT_MAX’ undeclared (first use in
this function)
  if (!latency || latency == UINT_MAX) {
                             ^
Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Fixes: e98f033f94 (cpupower: fix how "cpupower frequency-info" interprets latency)
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2016-01-19 01:17:23 +01:00
Jacob Tanenbaum
e98f033f94 cpupower: fix how "cpupower frequency-info" interprets latency
the intel-pstate driver does not support the ondemand governor and does not
have a valid value in
/sys/devices/system/cpu/cpu[x]/cpufreq/cpuinfo_transition_latency. The
intel-pstate driver sets cpuinfo_transition_latency to CPUFREQ_ETERNAL (-1),
the value written into cpuinfo_transition_latency is defind as an unsigned
int so checking the read value against max unsigned int will determine if the
value is valid.

Signed-off-by: Jacob Tanenbaum <jtanenba@redhat.com>
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-12-03 02:30:30 +01:00
Jacob Tanenbaum
562e5f1a35 cpupower: rework the "cpupower frequency-info" command
this patch makes two changes to the way that "cpupower
frequancy-info" operates

1. make it so that querying individual values always returns a
   message to the user

currently cpupower frequency info doesn't return anything to the user when
querying an individual value cannot be returned

[root@amd-dinar-09 cpupower]# cpupower -c 4 frequency-info -d
analyzing CPU 4:
[root@amd-dinar-09 cpupower]#

I added messages so that each query prints a message to the terminal

[root@amd-dinar-09 cpupower]# ./cpupower -c 4 frequency-info -d
analyzing CPU 4:
  no or unknown cpufreq driver is active on this CPU
[root@amd-dinar-09 cpupower]#

(this is just one example)

2. change debug_output_one() to use the functions already provided
   by cpufreq-info.c to query individual values of interest.

Signed-off-by: Jacob Tanenbaum <jtanenba@redhat.com>
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-12-03 02:30:30 +01:00
Thomas Renninger
ce512b8404 cpupower: Do not analyse offlined cpus
Use sysfs_is_cpu_online(cpu) instead of cpufreq_cpu_exists(cpu) to detect offlined cpus.

Re-arrange printfs slightly to have a consistent output even if you have multiple CPUs
as output and even if offlined cores are in between.

Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-12-03 02:30:30 +01:00
Thomas Renninger
7b0e1bf171 cpupower: Fix precedence issue
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-12-03 02:30:29 +01:00
Sriram Raghunathan
57ab3b0872 Creating a common structure initialization pattern for struct option
This patch tries to creates a common structure initialization
within the cpupower tool.

Previously the ``struct option`` was initialized
using `designated initializer` technique which was
not needed. There were conflicting initialization methods seen with

bench/main.c & others.

Signed-off-by: Sriram Raghunathan <sriram@marirs.net.in>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-11-02 02:28:59 +01:00
Thomas Renninger
19c9fb896f cpupower: Enable disabled Cstates if they are below max latency
cpupower idle-set -D <latency>
currently only disables all C-states that have a higher latency than the
specified <latency>. But if deep sleep states were already disabled and
have a lower latency, they should get enabled again.

For example:
This call:
cpupower idle-set -D 30
disables all C-states with a higher or equal latency than 30.
If one then calls:
cpupower idle-set -D 100
C-states with a latency between 30-99 will get enabled again with this patch
now. It is ensured that only C-states with a latency of 100 and higher are
disabled.

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-11-02 02:28:59 +01:00
Thomas Renninger
645209472d cpupower: Remove debug message when using cpupower idle-set -D switch
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-11-02 02:28:59 +01:00
Jacob Tanenbaum
20102ac5be cpupower: cpupower monitor reports uninitialized values for offline cpus
[root@hp-dl980g7-02 linux]# cpupower monitor
...
5472|   0|   1|******|******|******|******|| 0.00|  0.00|  0.00|  0.00|  0.00 *is offline
10567|   0| 159|******|******|******|******||  0.00|  0.00|  0.00|  0.00|  0.00 *is offline
1661206560|859272560| 150|******|******|******|******|| 0.00|  0.00|  0.00|  0.00|  0.00 *is offline
1661206560|943093104| 140|******|******|******|******|| 0.00|  0.00|  0.00|  0.00|  0.00 *is offline

because of this cpupower also holds the incorrect value for the number
of physical packages in the machine

Changed cpupower to initialize the values of an offline cpu's socket and
core to -1, warn the user that one or more cpus is/are
offline and not print statistics for offline cpus.

This fix hides offlined cores where topology cannot be accessed.
With a recent kernel patch suggested from Prarit Bhargava it may be possible
that soft offlined cores' topology can still be parsed.
This patch would then show which cores in which package/socket are offline,
when sane toplogoy information is available.

Signed-off-by: Jacob Tanenbaum <jtanenba@redhat.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-11-02 02:28:59 +01:00
Shreyas B. Prabhu
404c2db635 tools: cpupower: Fix error when running cpupower monitor
get_cpu_topology() tries to get topology info from all cpus by reading
files in the topology sysfs dir. If a cpu is offlined, since it doesn't
have topology dir, this function fails and returns -1. This causes
functions relying on get_cpu_topology() to fail. For example-

$ cpupower monitor
Cannot read number of available processors

Fix this by skipping fetching topology info for offline cpus.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Reported-by: Pavaman Subramaniyam <pavsubra@linux.vnet.ibm.com>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-08-29 01:38:16 +02:00
Shilpasri G Bhat
2e5e8fd1ff cpupower: Do not change the frequency of offline cpu
Check if the cpu is online before changing the frequency/governor of
the cpu.

Reported-by: Pavaman Subramaniyam <pavsubra@linux.vnet.ibm.com>
Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Acked-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-07-23 20:40:51 +02:00
Herton R. Krzesinski
47b98c74fa cpupower: mperf monitor: fix output in MAX_FREQ_SYSFS mode
There is clearly wrong output when mperf monitor runs in MAX_FREQ_SYSFS mode:
average frequency shows in kHz unit (despite the intended output to be in MHz),
and percentages for C state information are all wrong (including high/negative
values shown).

The problem is that the max_frequency read on initialization isn't used where it
should have been used on mperf_get_count_percent (to estimate the number of
ticks in the given time period), and the value we read from sysfs is in kHz, so
we must divide it to get the MHz value to use in current calculations.

While at it, also I fixed another small issues in the debug output of
max_frequency value in mperf_get_count_freq.

Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-05-30 02:21:31 +02:00
Lucas Stach
06b230e3dd cpupower: fix breakage from libpci API change
libpci 3.3.0 introduced an additional member in the pci_filter struct
which needs to be initialized to -1 to get the same behavior as before
the API change. The libpci internal helpers got updated accordingly,
but as the cpupower pci helpers initialized the struct themselves the
behavior changed.

Use the libpci helper pci_filter_init() to fix this and guard against
similar breakages in the future.

This fixes probing of the AMD fam12h/14h cpuidle monitor on systems
with libpci >= 3.3.0.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-04-15 21:54:26 +02:00
Prarit Bhargava
a59e5109f6 tools / cpupower: Fix no idle state information return value
sysfs_get_idlestate_count() returns an unsigned int.  Returning -ENODEV
is not the right thing to do here, and in any case is handled the same
way as if there are no states found.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-12-19 23:01:12 +01:00
Michal Privoznik
ad1d8313cd tools / cpupower: Correctly detect if running as root
Some operations, like frequency-set, need root privileges. However,
the way that this is detected is not correct. The getuid() is called,
while in fact geteuid() should be. This way we can allow
distributions or users to set SETUID flags on the cpupower binary if
they want to and let regular users change the cpu frequency governor.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-12-19 23:01:03 +01:00
Prarit Bhargava
2a813f1aaa Revert "tools: cpupower: fix return checks for sysfs_get_idlestate_count()"
This reverts commit 16b7c275c0.

My previous commit 16b7c275c0 ("tools: cpupower: fix return checks for
sysfs_get_idlestate_count()") was not correct.  After looking
at the changelog for cpupower I noticed that Thomas had changed the return of
sysfs_get_idlestate_count() to an unsigned int to simplify the code.  The
problem is really that both he (in his original change) and I (in my new
change) missed the obvious that sysfs_get_idlestate_count()
can't return -ENODEV.  It should just return 0 for "no c-states".

Fixes: 16b7c275c0 (tools: cpupower: fix return checks for ...)
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-12-14 22:14:16 +01:00
Prarit Bhargava
16b7c275c0 tools: cpupower: fix return checks for sysfs_get_idlestate_count()
Red Hat and Fedora use a bug reporting tool that gathers data about
"broken" systems called sosreport.  Among other things, it includes the
output of 'cpupower idle-info'.  Executing 'cpupower idle-info' on a
system that has cpuidle disabled via 'cpuidle.off=1' results in a 300
second hang in the cpupower application.

ie)
[root@intel-brickland-05]# cpupower idle-info
Could not determine cpuidle driver

Analyzing CPU 0:
Number of idle states: -19
[hang]

The problem is that the cpupower code only checks for a zero return from
sysfs_get_idlestate_count().  The function can return -ENODEV (-19) as
above.  This patch fixes callers to sysfs_get_idlestate_count() to check
the right return values.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-12-05 03:12:34 +01:00
Peter Senna Tschudin
059802f961 cpupower: Remove redundant error check
Remove double checks, and move the call to print_error to the
first check. Replace break by return, and return 0 on success.
The simplified version of the coccinelle semantic patch that
fixes this issue is as follows:

// <smpl>
@@
expression E; identifier pr; expression list es;
@@
for(...;...;...){
...
-	if (E) break;
+	if (E){
+		pr(es);
+		break;
+	}
...
}
- if(E) pr(es);
// </smpl>

Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-07-30 01:57:13 +02:00
Himangi Saraogi
97fa1c5ca6 cpupower: mperf monitor: Correct use of ! and &
In commit ae91d60ba8, a bug was fixed that
involved converting !x & y to !(x & y).  The code below shows the same
pattern, and thus should perhaps be fixed in the same way.

The Coccinelle semantic patch that makes this change is as follows:

// <smpl>
@@ expression E1,E2; @@
(
  !E1 & !E2
|
- !E1 & E2
+ !(E1 & E2)
)
// </smpl>

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-07-30 01:57:12 +02:00
Andrey Utkin
788606cb88 PM / tools: cpupower: drop negativity check on unsigned value
Link: https://bugzilla.kernel.org/show_bug.cgi?id=80621
Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Andrey Utkin <andrey.krieger.utkin@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-07-19 21:41:17 +02:00
Thomas Renninger
7ea1bdb8e1 cpupower: Remove mc and smt power aware scheduler info/settings
These kernel interfaces got removed by:

commit 8e7fbcbc22
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Mon Jan 9 11:28:35 2012 +0100

    sched: Remove stale power aware scheduling remnants and dysfunctional knobs

No need to further keep them as userspace configurations.

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-05-17 00:36:37 +02:00
Thomas Renninger
3fc5a0e51a cpupower: cpupower info -b should return 0 on success, not the perf bias value
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-05-17 00:36:37 +02:00
Thomas Renninger
8a19cb5867 cpupower: If root, try to load msr driver on x86 if /dev/cpu/0/msr is not available
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-05-17 00:36:36 +02:00
Thomas Renninger
69cd502dd8 cpupower: Introduce idle state disable-by-latency and enable-all
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-05-17 00:36:36 +02:00
Prarit Bhargava
e091abc7f9 PM / tools: cpupower: add option to display values without round offs
The command "cpupower frequency-info" can be used when using cpupower to
monitor and test processor behaviour to determine if the processor is
behaving as expected.  This data can be compared to the output of
/proc/cpuinfo or the output of
/sys/devices/system/cpu/cpuX/cpufreq/scaling_available_frequencies
to determine if the cpu is in an expected state.

When doing this I noticed comparison test failures due to the way the
data is displayed in cpupower.  For example,

[root@intel-s3e37-02 cpupower]# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
2262000 2261000 2128000 1995000 1862000 1729000 1596000 1463000 1330000
1197000 1064000

compared to

[root@intel-s3e37-02 cpupower]# cpupower frequency-info
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 10.0 us.
  hardware limits: 1.06 GHz - 2.26 GHz
  available frequency steps: 2.26 GHz, 2.26 GHz, 2.13 GHz, 2.00 GHz, 1.86 GHz, 1.73 GHz, 1.60 GHz, 1.46 GHz, 1.33 GHz, 1.20 GHz, 1.06 GHz
  available cpufreq governors: conservative, userspace, powersave, ondemand, performance
  current policy: frequency should be within 1.06 GHz and 2.26 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.26 GHz (asserted by call to hardware).
  boost state support:
    Supported: yes
    Active: yes

shows very different values for the available frequency steps.  The cpupower
output rounds off values at 2 decimal points and this causes problems with
test scripts.  For example, with the data above,

1.064 is 1.06
1.197 is 1.20
1.596 is 1.60
1.995 is 2.00
2.128 is 2.13

and most confusingly,

2.261 is 2.26
2.262 is 2.26

Truncating these values serves no real purpose other than making the output
pretty.  Since the default has been to round off these values I am adding
a -n/--no-rounding option to the cpupower utility that will display the
data without rounding off the still significant digits.

After patch,

analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 10.000 us.
  hardware limits: 1.064000 GHz - 2.262000 GHz
  available frequency steps: 2.262000 GHz, 2.261000 GHz, 2.128000 GHz, 1.995000 GHz, 1.862000 GHz, 1.729000 GHz, 1.596000 GHz, 1.463000 GHz, 1.330000 GHz, 1.197000 GHz, 1.064000 GHz
  available cpufreq governors: conservative, userspace, powersave, ondemand, performance
  current policy: frequency should be within 1.064000 GHz and 2.262000 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.262000 GHz (asserted by call to hardware).
  boost state support:
    Supported: yes
    Active: yes

Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
[rjw: Subject]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-05-07 00:19:06 +02:00
Rafael J. Wysocki
df34ca72ed Merge branches 'acpi-tools' and 'pm-tools'
* acpi-tools:
  ACPICA: acpidump: Update MAINTAINERS file to include tools folder for ACPI/ACPICA.
  ACPICA: acpidump: Enable tools Makefile to include acpi tools.
  ACPICA: acpidump: Cleanup tools/power/acpi makefiles.

* pm-tools:
  PM / tools: new tool for suspend/resume performance optimization
  cpupower: Fix sscanf robustness in cpufreq-set
2014-01-17 01:59:48 +01:00
One Thousand Gnomes
fdfe840e48 cpupower: Fix sscanf robustness in cpufreq-set
The cpufreq-set tool has a missing length check. This is basically
just correctness but still should get fixed.

One of a set of sscanf problems reported by Jackie Chang

Signed-off-by: Alan Cox <alan@linux.intel.com>
[rjw: Subject]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-01-08 15:10:39 +01:00
Josh Boyer
f447ef4a56 cpupower: Fix segfault due to incorrect getopt_long arugments
If a user calls 'cpupower set --perf-bias 15', the process will end with
a SIGSEGV in libc because cpupower-set passes a NULL optarg to the atoi
call.  This is because the getopt_long structure currently has all of
the options as having an optional_argument when they really have a
required argument.  We change the structure to use required_argument to
match the short options and it resolves the issue.

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1000439

Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Thomas Renninger <trenn@suse.de>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-12-17 11:29:30 -08:00
Thomas Renninger
f4a5d17efe tools: cpupower: fix wrong err msg not supported vs not available
idlestates in sysfs are counted from 0.

This fixes a wrong error message.
Current behavior on a machine with 4 sleep states is:

cpupower idle-set -e 4
Idlestate 4 enabled on CPU 0

-----Wrong---------------------
cpupower idle-set -e 5
Idlestate enabling not supported by kernel
-----Must and now will be -----
cpupower idle-set -e 5
Idlestate 6 not available on CPU 0
-------------------------------

cpupower idle-set -e 6
Idlestate 6 not available on CPU 0

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-11-25 23:10:50 +01:00
Thomas Renninger
7ee767b69b cpupower: Add Haswell family 0x45 specific idle monitor to show PC8,9,10 states
This specific processor supports 3 new package sleep states.
Provide a monitor, so that the user can see their usage.

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-07-05 01:52:19 +02:00
Thomas Renninger
2aa1ca75c4 cpupower: Haswell also supports the C-states introduced with SandyBridge
Add Haswell model numbers to snb_register() as it also supports the
C-states introduced in SandyBridge processors.

[rjw: Changelog]
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-07-05 01:52:19 +02:00
Thomas Renninger
c4f3610eba cpupower: Introduce idle-set subcommand and C-state enabling/disabling
Example:

cpupower idle-set -d 3

will disable C-state 3 on all processors (set commands are active on
all CPUs by default), same as:

cpupower -c all idle-set -d 3

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-07-05 01:52:19 +02:00
Thomas Renninger
0924c369bc cpupower: Implement disabling of cstate interface
Latest kernel allows to disable C-states via:
/sys/devices/system/cpu/cpuX/cpuidle/stateY/disable

This patch provides lower level sysfs access functions to make use of
this interface.  A later patch will implement the higher level stuff.

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-07-05 01:52:19 +02:00
Thomas Renninger
f605181abd cpupower: Make idlestate usage unsigned
Use unsigned int as the data type for some variables related to CPU
idle states which allows the code to be simplified slightly.

[rjw: Changelog]
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-07-05 01:52:19 +02:00
Thomas Renninger
8d219e3658 cpupower: IvyBridge (0x3a and 0x3e models) support
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-27 23:07:20 +01:00
Thomas Renninger
c8cfc3c6bf cpupower: Provide -c param for cpupower monitor to schedule process on all cores
If an MSR based monitor is run in parallel this is not needed. This is the
default case on all/most Intel machines.

But when only sysfs info is read via cpupower monitor -m Idle_Stats (typically
the case for non root users) or when other monitors are PCI based (AMD),
Idle_Stats, read from sysfs can be totally bogus:

cpupower monitor -m Idle_Stats
PKG |CORE|CPU | POLL | C1-N | C3-N | C6-N
   0|   0|   0|  0.00|  0.00|  0.24| 99.81
   0|   0|  32|  0.00|  0.00|  0.00| 100.7
...
   0|  17|  20|  0.00|  0.00|  0.00| 173.1
   0|  17|  52|  0.00|  0.00|  0.07| 173.0
   0|  18|  68|  0.00|  0.00|  0.00|  0.00
   0|  18|  76|  0.00|  0.00|  0.00|  0.00
...

With the -c option all cores are woken up and the kernel
did update cpuidle statistics before reading out sysfs.
This causes some overhead. Therefore avoid if possible, use
if needed:

cpupower monitor -c -m Idle_Stats
PKG |CORE|CPU | POLL | C1-N | C3-N | C6-N
   0|   0|   0|  0.00|  0.00|  0.00| 100.2
   0|   0|  32|  0.00|  0.00|  0.00| 100.2
...
   0|   8|   8|  0.00|  0.00|  0.00| 99.82
   0|   8|  40|  0.00|  0.00|  0.00| 99.81
   0|   9|  24|  0.00|  0.00|  0.00| 100.3
   0|   9|  56|  0.00|  0.00|  0.00| 100.2
   0|  16|   4|  0.00|  0.00|  0.00| 99.75
   0|  16|  36|  0.00|  0.00|  0.00| 99.38
...

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-27 23:07:20 +01:00
Palmer Cox
ea1021ffa6 cpupower tools: Fix warning and a bug with the cpu package count
The pkgs member of cpupower_topology is being used as the number of
cpu packages. As the comment in get_cpu_topology notes, the package ids
are not guaranteed to be contiguous. So, simply setting pkgs to the value
of the highest physical_package_id doesn't actually provide a count of
the number of cpu packages. Instead, calculate pkgs by setting it to
the number of distinct physical_packge_id values which is pretty easy
to do after the core_info structs are sorted. Calculating pkgs this
way also has the nice benefit of getting rid of a sign comparison warning
that GCC 4.6 was reporting.

Signed-off-by: Palmer Cox <p@lmercox.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-27 23:07:19 +01:00
Palmer Cox
35a169737c cpupower tools: Fix malloc of cpu_info structure
The cpu_info member of cpupower_topology was being declared as an unnamed
structure. This member was then being malloced using the size of the
parent cpupower_topology * the number of cpus. This works
because cpu_info is smaller than cpupower_topology. However, there is
no guarantee that will always be the case. Making cpu_info its own
top level structure (named cpuid_core_info) allows for mallocing the actual
size of this structure. This also lets us get rid of a redefinition of
the structure in topology.c with slightly different field names.

Signed-off-by: Palmer Cox <p@lmercox.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-27 23:07:19 +01:00
Palmer Cox
53d2000ebe cpupower tools: Fix issues with sysfs_topology_read_file
Fix a variety of issues with sysfs_topology_read_file:
* The return value of sysfs_topology_read_file function was not properly
  being checked for failure.
* The function was reading int valued sysfs variables and then returning
  their value. So, even if a function was trying to check the return value
  of this function, a caller would not be able to tell an failure code apart
  from reading a negative value. This also conflicted with the comment on the
  function which said that a return value of 0 indicated success.
* The function was parsing int valued sysfs values with strtoul instead of
  strtol.
* The function was non-static even though it was only used in the
  file it was declared in.

Signed-off-by: Palmer Cox <p@lmercox.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-27 23:07:19 +01:00
Palmer Cox
fb8eaeb7ab cpupower tools: Fix minor warnings
Fix minor warnings reported with GCC 4.6:
* The sysfs_write_file function is unused - remove it.
* The pr_mon_len in the print_header function is unsed - remove it.

Signed-off-by: Palmer Cox <p@lmercox.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-27 23:07:18 +01:00
Peter Zijlstra
8e7fbcbc22 sched: Remove stale power aware scheduling remnants and dysfunctional knobs
It's been broken forever (i.e. it's not scheduling in a power
aware fashion), as reported by Suresh and others sending
patches, and nobody cares enough to fix it properly ...
so remove it to make space free for something better.

There's various problems with the code as it stands today, first
and foremost the user interface which is bound to topology
levels and has multiple values per level. This results in a
state explosion which the administrator or distro needs to
master and almost nobody does.

Furthermore large configuration state spaces aren't good, it
means the thing doesn't just work right because it's either
under so many impossibe to meet constraints, or even if
there's an achievable state workloads have to be aware of
it precisely and can never meet it for dynamic workloads.

So pushing this kind of decision to user-space was a bad idea
even with a single knob - it's exponentially worse with knobs
on every node of the topology.

There is a proposal to replace the user interface with a single
3 state knob:

 sched_balance_policy := { performance, power, auto }

where 'auto' would be the preferred default which looks at things
like Battery/AC mode and possible cpufreq state or whatever the hw
exposes to show us power use expectations - but there's been no
progress on it in the past many months.

Aside from that, the actual implementation of the various knobs
is known to be broken. There have been sporadic attempts at
fixing things but these always stop short of reaching a mergable
state.

Therefore this wholesale removal with the hopes of spurring
people who care to come forward once again and work on a
coherent replacement.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/1326104915.2442.53.camel@twins
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2012-05-17 13:48:56 +02:00
Thomas Renninger
62d5a67d65 cpupower: Fix broken mask values
Signed-off-by: Thomas Renninger <trenn@suse.de>
Tested-by: Dave Jones <davej@redhat.com>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
2012-03-03 14:40:11 +01:00
Thomas Renninger
e0c6082dae cpupower: Remove unneeded code and by that fix a memleak
Looks like some not needed debug code slipped in.
Also this code:
tmp = sysfs_get_idlestate_name(cpu, idlestates - 1);
performs a strdup and the mem was not freed again.
-> delete it.

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
2012-03-03 14:40:10 +01:00