Fix includes: do not include intel_cpus.h inside cpu.h

The file "cpu.h" is generic (unlike "intel_cpus.h"), so the existing order seems
illogical.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: move is_turbo() function to lib

Trivial: remove 4 identical static definitions of is_turbo().

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()

Trivial: unify identical in-class private definitions in the common base class.

The only override left is nhm_cpu::account_freq() which is almost identical but
ignores the "Turbo Mode" state.
Seems like a hidden bug to me, but will remove it in a separate commit so one can revert
it easily in case something goes wrong.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: remove nhm_cpu::account_freq() almost identical to abstract_cpu::account_freq()

See previous commit for explanation.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: remove nhm_{cpu, core, package}::change_effective_frequency() identical to cpu_{linux, core, package}::change_effective_frequency()

Trivial: remove identical overrides wrt. direct base classes.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: merge cpu_{core, linux, package}::change_effective_frequency() into abstract_cpu::change_effective_frequency()

The mentioned overrides differ only in assigning 0 to effective_frequency
prior to calling abstract_cpu::change_effective_frequency(), which reassigns real frequency
to the same field.
Moreover, the field value is never used between assignments.

So it shall be safe to merge these overrides into the base definition as shown:
* immediately assign real frequency to field effective_frequency;
* remove post-assignment to the same field.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: remove {cpu, nhm}_core::calculate_freq() identical to abstract_cpu::calculate_freq()

Trivial: remove identical overrides wrt. direct base class.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: remove nhm_package::calculate_freq() identical to cpu_package::calculate_freq()

Trivial - remove an identical override wrt. direct base class.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: properly merge cpu_package::calculate_freq() into abstract_cpu::calculate_freq()

The overridden method "cpu_package::calculate_freq()" differs from a generic implementation in
that it propagates the package's frequency to all in-package cores by
calling change_effective_frequency().

Instead of duplicating the code, introduce a small virtual function
freq_updated() which normally propagates frequency changes upwards and
override it for cpu_package, retaining the correct behavior. Then remove the override of
calculate_freq().

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
Deduplication: merge go_idle()/go_unidle()/change_freq() overrides into abstract_cpu() class

When merging, also (while at it) use the new freq_updated() method in
these functions.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
tab_window: null members on construction

introduce tab_window ctor and null memebers during construction. show_tab() may be
called before window_refresh() [which sets ypad_pos and xpad_pos to 0], causing prefresh()
call with uninit win->ypad_pos, win->xpad_pos args.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
parameters: fix uninitialized values in param/result getters

-- get_param_index()/get_result_index() may be called for unknown parameter,
causing new map entry creation via operator[] access. it's not safe to check
returned pair->second value for newly created map entry, since there is no default
ctor for int type. use map::find() instead.

-- get_parameter_value(char *) now uses get_parameter_value(uint), which performs
parameters overflow detection and prevents illegal read. this one was affecting
power_device_sort(), returning garbage to compare function.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
runtime_pm: register parameters

register parameter during runtime_pmdevice() construction, making
call to get_parameter_value() in power_usage() valid.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
csstoh.sh shell script fixes cross compiling issues

Added the csstoh.sh shell script from Igor Zhbanov found here:
http://lists.01.org/pipermail/powertop/2012-July/000151.html
also patched the Makefile.am to use the csstoh.sh script.
The compiled csstoh binary doesn't work for cross compiling,
however Igors Patch never got applied upstream.
process: Get rid of unused dbg_printf_pevent_info()

This function is not used, just remove it.
This fixes following warning:

  CXX    process/powertop-do_process.o
process/do_process.cpp:190: warning: ‘void dbg_printf_pevent_info(event_format*, pevent_record*)’ defined but not used

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
main: 'quiet' option does not take an argument

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
main: Fix output when running workload

Currently one_measurement() function prints following message after
a successful run of the workload.

  $ sudo powertop --html --workload="sleep 1"
  Loaded 1 prior measurements
  Preparing to take measurements
  Measuring workload sleep 1.
  Unknown issue running workload!                         <-- here
  PowerTOP outputing using base filename powertop.html

It seems this was because it wrongly checks return value of system.
The return value of the system() call is the status of wait() call
so that it should be zero if things went well.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Do not call abstract_cpu::wiggle for GPU

first_cpu is uninitialized there which results in:
open("/sys/devices/system/cpu/cpu1330597711/cpufreq/scaling_max_freq", O_RDONLY)
V2: Fix C states and P states presentation issue.

If using '10' in this 'for' loop, for P states, once the processor
provides more than 10 P states, those additional ones cannot been
presented; and for C states, once the processor provides maximize
C states level more than 9, for example, it only has POLL, C1, C3,
C6, C10, the additional one like C10 also cannot be presented.

Now we get the loop numbers from the system information we had got
before.

Changes from V1:
Using std:max to simplify codes

Signed-off-by: Austin Zhang <zhang.austin@gmail.com>
Using std::max to handle all such kind of logic

Signed-off-by: Austin Zhang <zhang.austin@gmail.com>