cpu: clean intel cpu model out of cpu

Move all the model checking for intel cpus out of cpu.cpp and
intel intel_cpu.cpp.  Add a constructor for nehalem cpu and
initialize some flags there based on model.
Suppress decimal constant compilation warning

From: Paul Menzel <paulepanter@users.sourceforge.net>

g++ reports the following warning:
	warning: this decimal constant is unsigned only in ISO C90
	[enabled by default]

Reported-by: Paul Menzel <paulepanter@users.sourceforge.net>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Seg Fault due to function format_watts in file src/lib.cpp

Use
size_t mbsrtowcs (wchar t *restrict dst, const char **restrict src,
        size t len, mbstate t *restrict ps)

which explicitly handles dst == NULL case:

	If dst is not a null pointer, the result is stored in the array pointed to by dst; otherwise,
	the conversion result is not available since it is stored in an internal buffer.

while

size_t mbstowcs (wchar t *wstring, const char *string, size t size)

does not (at least not in my glibc 2.17 docs), thus is free to cause undefined behavior.

Reported-by: Ganapati Bhat <life.mytake@gmail.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Use symbolic instead of numeric constants for keys

This improves the readability of the key handling code.

Since there is no symbolic constant for Escape, a comment with an
explanation is added.

Signed-off-by: Hans-Peter Deifel <hpdeifel@gmx.de>
Document key bindings in man page

Signed-off-by: Hans-Peter Deifel <hpdeifel@gmx.de>
Do not leak fd in perf_bundle read_file()

- Do not leak file descriptor in perf_bundle read_file().
- Clear perf event (unmap memory and close fd) on event destruction.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
README: add CONFIG_DEBUG_FS to Kernel Parameters

Add CONFIG_DEBUG_FS to the Kernel Parameters README section.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Fix running failure when > 69 CPUs for open file limitation

Powertop 2.3 fails to run on machine with > 69 CPUs because system open files
limitation of one process is 1024 default,  While powertop will open one file
for every monitored perf_event (at least 15) each CPU.

Like on 80 CPUs Westmere-EX machine, powertop will fail to run with below:

PowerTOP v2.3 needs the kernel to support the 'perf' subsystem
as well as support for trace points in the kernel:
CONFIG_PERF_EVENTS=y
CONFIG_PERF_COUNTERS=y
CONFIG_TRACEPOINTS=y
CONFIG_TRACING=y

This patch is to change RLIMIT_NOFILE from default (1024) to max limition.

Signed-off-by: Youquan Song <youquan.song@intel.com>
Introduce --auto-tune mode

Original idea by Mark Boorer <markboo99@gmail.com>

Introduce --auto-tune mode.
Auto tune toggles all existing tunables to GOOD state and finishes
powertop execution.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Embed self-contained javascript

using self-contained javascript offers several improvements:

 * powertop html report can be viewed offline
 * less overall javascript code is loaded when online
 * no opportunity for report leakage or modification by third parties

These changes also make it simpler to update the html report when a
new section is added: just add a new entry to powertop.blocks
dictionary, with the section's human-readable string as its value.
lib: unify process_directory()

remove `lo' check from process_directory() and force net callers
to check for passed d_name. since process_directory() called
from different sites `lo' check is overhead.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
alsa: use process_directory()

use process_directory() helper

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
calibrate: use process_directory()

use process_directory() helper

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
network: use updated process_directory()

check for passed `lo' d_name

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
rfkill: use process_directory()

use process_directory() helper

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
usb: use process_directory()

use process_directory() helper

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
tuning ethernet: use updated process_directory()

check for `lo' d_name in ethtunable_callback()

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
tuningusb: use process_directory()

use process_directory() helper

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
cpu: clean intel cpu model out of cpu

Move all the model checking for intel cpus out of cpu.cpp and
intel intel_cpu.cpp.  Add a constructor for nehalem cpu and
initialize some flags there based on model.
perf_bundle: introduce fixup_sample_trace_cpu()

struct perf_sample's trace cpu is a raw_smp_processor_id()
(as requsted by PERF_SAMPLE_CPU) by the time of perf_event_output()
call, which may differ from original struct perf_event's cpu.
thus we need to fix sample->trace.cpu via fixup_sample_trace_cpu()
call.

debugging output has demonstrated that some events (namely cpu_frequency)
were routed incorrectly (sample->trace.cpu != pevent_get_field_val("cpu_id")):
fix [cpu_frequency] cpu_nr from 1 to 0
fix [cpu_frequency] cpu_nr from 1 to 0
fix [cpu_frequency] cpu_nr from 1 to 2
fix [cpu_frequency] cpu_nr from 1 to 2
fix [cpu_frequency] cpu_nr from 1 to 3
fix [cpu_frequency] cpu_nr from 1 to 3
fix [cpu_frequency] cpu_nr from 1 to 0
fix [cpu_frequency] cpu_nr from 1 to 0
fix [cpu_frequency] cpu_nr from 1 to 2
fix [cpu_frequency] cpu_nr from 1 to 2
fix [cpu_frequency] cpu_nr from 1 to 0
fix [cpu_frequency] cpu_nr from 1 to 0
fix [cpu_frequency] cpu_nr from 1 to 0

Thanks for reporting and tracking this down to (not in any particular
order): Shaojie Sun, Jon Medhurst, Sanjay Rawat, SunShaoJie.

Cc: Shaojie Sun <shaojie.sun@linaro.org>
Cc: Jon Medhurst <jon.medhurst@linaro.org>
Cc: Sanjay Rawat <sanjay.rawat@linaro.org>
Cc: SunShaoJie <sunshaojie@huawei.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>