tell user if the system is running out of FDs

From: Jaroslav Skarvada <jskarvad@redhat.com>

complex servers can run out of FDs easily (due to perf).
In such case tell user that more FDs are needed instead
of the generic message (that kernel doesn't support
the perf).
set open files rlimit to /proc/sys/fs/nr_open

From: Jaroslav Skarvada <jskarvad@redhat.com>

we have noticed that it can only overcome soft limits, but not hard limits. E.g.
on Fedora (and probably others) there is a soft limit of 1024 and a hard limit
of 4096, so if powertop opens at least 15 file descriptors per CPU, then this
will fail on a system with >273 CPUs.

On my system NR_OPEN is 1024, but /proc/sys/fs/nr_open gives me 1048576.
It seems the linux kernel hardcodes 1024 * 1024 as the default kernel limit.
This default limit can be raised to:

sysctl_nr_open_max = min((size_t)INT_MAX, ~(size_t)0/sizeof(void *)) &
  -BITS_PER_LONG;

which is 2 Gi - 63 on my 64 bit system. I think we shouldn't
touch/increase this. It seems there is no header definition for these
limits.

I am proposing new patch, which reads the current kernel limit from the
/proc. I am not sure about the portability, but at least it shouldn't
break anything.

Finally I think, the first patch could be applied together with this patch
(probably with the changed message) to notify user that he/she reached
the FDs limit, because there is still some limit. This could also
occur if some process would decrease the /proc/sys/fs/nr_open after
it is read by powertop and before the ulimit is set

patch merge modifications by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
lib: introduce ui_notify_user()

ui_notify_user(frmt, ...) prints formatted notification string at
(x:1, y:0) WINDOW position.

use fixed UI_NOTIFY_BUFF_SZ size buffer, because there seems to be
no ncurses() *print function which takes int x, int y WINDOW
coordinates and va_list.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
tuning: print executed toggle script

report executed toggle_script back to user via ui_notify_user().

Example:
 >> 'auto' > '/sys/bus/pci/devices/0000:00:1c.1/power/control';
 >> echo 'on' > '/sys/bus/pci/devices/0000:00:1c.1/power/control';

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
power_meter: introduce discharging member
measurement: report total global_time_left()

report total capacity and discahrge rate if at least one power_meter
reports that is's discharging. previously we reported only discharging
power_meters, thus user was not aware of total time left in case of
N batteries. this is the reason why power_meter discharging member
(with getter and setter one-liners were introduced) -- we need
capacity and rate for every power_meter, regardless the fact whether
its /sys/class/power_supply/*/status reports "Discharging" or not.
report total "The battery discharge rate" and "The estimated remaining
time" back to user when at least one power_meter is discharging.

Reported-and-tested-by: Maksim Melnikau <maxposedon@gmail.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
power_supply: delete unused power_supply class

we use sysfs_power_meter or acpi_power_meter.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
parameters: report correct "base power" parameter

Reported-by: Maksim Melnikau <maxposedon@gmail.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
backlight: use process_directory() helper

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
backlight: decrease backlight() .ctor mem usage

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Fixed cpu_core::has_c1_res initialization

cpu_core::has_c1_res is left uninitialized for anything other than BYT-M,
resulting in error at startup:
	 read_msr cpu0 0x660 : Argument list too long.

Signed-off-by: David Rosca <nowrep@gmail.com>