Discussion:
[PATCH] tuning sysfs: allow toggle to BAD
Sergey Senozhatsky
2012-05-01 19:40:45 UTC
Permalink
If powertop has been started with sysfs tunable tuned to GOOD there is no way
to toggle it to BAD.

sysfs_tunable::good_bad() will always return TUNE_GOOD, so bad_value will never
be set (apart from default value set in .ctor). That blocks sysfs_tunable::toggle()
on GOOD-to-BAD path.

The question is:
Should there be possibility to toggle BAD again, like, for example, enable NMI back?

If powertop has been started with sysfs tunable tuned to BAD, it saves current (BAD)
sysfs value which make it possible to toggle BAD->GOOD->BAD*.

This patch extends tuningsysfs with toggle_content param, which is opposite of
target_content for the case when target sysfs tunable is already in TUNE_GOOD state.

If toggle_content is set to NULL (e.g. VM writeback timeout), GOOD->BAD toggle attempt
will be ignored.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky-***@public.gmane.org>

---

src/tuning/tuning.cpp | 10 +++++-----
src/tuning/tuningsysfs.cpp | 12 ++++++++----
src/tuning/tuningsysfs.h | 6 ++----
3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
index 1064f51..e98f59a 100644
--- a/src/tuning/tuning.cpp
+++ b/src/tuning/tuning.cpp
@@ -57,11 +57,11 @@ public:

static void init_tuning(void)
{
- add_sysfs_tunable(_("Enable Audio codec power management"), "/sys/module/snd_hda_intel/parameters/power_save", "1");
- add_sysfs_tunable(_("Enable SATA link power management for /dev/sda"), "/sys/class/scsi_host/host0/link_power_management_policy", "min_power");
- add_sysfs_tunable(_("NMI watchdog should be turned off"), "/proc/sys/kernel/nmi_watchdog", "0");
- add_sysfs_tunable(_("Power Aware CPU scheduler"), "/sys/devices/system/cpu/sched_mc_power_savings", "1");
- add_sysfs_tunable(_("VM writeback timeout"), "/proc/sys/vm/dirty_writeback_centisecs", "1500");
+ add_sysfs_tunable(_("Enable Audio codec power management"), "/sys/module/snd_hda_intel/parameters/power_save", "1", "0");
+ add_sysfs_tunable(_("Enable SATA link power management for /dev/sda"), "/sys/class/scsi_host/host0/link_power_management_policy", "min_power", "max_performance");
+ add_sysfs_tunable(_("NMI watchdog should be turned off"), "/proc/sys/kernel/nmi_watchdog", "0", "1");
+ add_sysfs_tunable(_("Power Aware CPU scheduler"), "/sys/devices/system/cpu/sched_mc_power_savings", "1", "0");
+ add_sysfs_tunable(_("VM writeback timeout"), "/proc/sys/vm/dirty_writeback_centisecs", "1500", NULL);

add_usb_tunables();
add_runtime_tunables("pci");
diff --git a/src/tuning/tuningsysfs.cpp b/src/tuning/tuningsysfs.cpp
index 602d62d..266eefc 100644
--- a/src/tuning/tuningsysfs.cpp
+++ b/src/tuning/tuningsysfs.cpp
@@ -34,11 +34,15 @@

#include "../lib.h"

-sysfs_tunable::sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content) : tunable(str, 1.0, _("Good"), _("Bad"), _("Unknown"))
+sysfs_tunable::sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content, const char *_toggle_content)
+ : tunable(str, 1.0, _("Good"), _("Bad"), _("Unknown"))
{
strcpy(sysfs_path, _sysfs_path);
strcpy(target_value, _target_content);
- bad_value[0] = 0;
+ if (_toggle_content)
+ strcpy(bad_value, _toggle_content);
+ else
+ bad_value[0] = 0;
sprintf(toggle_good, "echo '%s' > '%s';", target_value, sysfs_path);
sprintf(toggle_bad, "echo '%s' > '%s';", bad_value, sysfs_path);
}
@@ -93,14 +97,14 @@ const char *sysfs_tunable::toggle_script(void) {
}


-void add_sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content)
+void add_sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content, const char *_toggle_content)
{
class sysfs_tunable *tunable;

if (access(_sysfs_path, R_OK) != 0)
return;

- tunable = new class sysfs_tunable(str, _sysfs_path, _target_content);
+ tunable = new class sysfs_tunable(str, _sysfs_path, _target_content, _toggle_content);


all_tunables.push_back(tunable);
diff --git a/src/tuning/tuningsysfs.h b/src/tuning/tuningsysfs.h
index ac7938c..d7df887 100644
--- a/src/tuning/tuningsysfs.h
+++ b/src/tuning/tuningsysfs.h
@@ -36,17 +36,15 @@ class sysfs_tunable : public tunable {
char target_value[4096];
char bad_value[4096];
public:
- sysfs_tunable(const char *str, const char *sysfs_path, const char *target_content);
+ sysfs_tunable(const char *str, const char *sysfs_path, const char *target_content, const char *toggle_content);

virtual int good_bad(void);

virtual void toggle(void);

virtual const char *toggle_script(void);
-
};

-extern void add_sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content);
-
+extern void add_sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content, const char *_toggle_content);

#endif

Loading...