From: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
To: powertop@lists.01.org
Subject: [Powertop] [PATCH] factor out powertop_init() function [was "Segmentation fault occurs with --calibrate"]
Date: Thu, 17 May 2012 19:44:58 +0300 [thread overview]
Message-ID: <20120517164458.GA3486@swordfish> (raw)
In-Reply-To: 3231880.1xuGnurXlG@penguin
[-- Attachment #1: Type: text/plain, Size: 5002 bytes --]
[PATCH] factor out powertop_init() function
Factor out powertop_init() function to perform basic initialization on
powertop start up.
Commit 057d6126eb6329c86b29a2e0219c0d0e49a84191 moved init after
commandline options parsing. However, in some cases we need it before
parsing, e.g. -- calibration.
Reported-by: Lekensteyn <lekensteyn(a)gmail.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
---
src/main.cpp | 110 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 58 insertions(+), 52 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 433fea6..b5720f0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -280,15 +280,68 @@ static void checkroot() {
}
}
-int main(int argc, char **argv)
+
+static void powertop_init(void)
{
+ static char initialized = 0;
int ret;
+ struct statfs st_fs;
+
+ if (initialized)
+ return;
+
+ checkroot();
+ ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
+ ret = system("/sbin/modprobe msr > /dev/null 2>&1");
+ statfs("/sys/kernel/debug", &st_fs);
+
+ if (st_fs.f_type != (long) DEBUGFS_MAGIC) {
+ if (access("/bin/mount", X_OK) == 0) {
+ ret = system("/bin/mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
+ } else {
+ ret = system("mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
+ }
+ if (ret != 0) {
+ printf(_("Failed to mount debugfs!\n"));
+ printf(_("exiting...\n"));
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ srand(time(NULL));
+
+ if (access("/var/cache/", W_OK) == 0)
+ mkdir("/var/cache/powertop", 0600);
+ else
+ mkdir("/data/local/powertop", 0600);
+
+ load_results("saved_results.powertop");
+ load_parameters("saved_parameters.powertop");
+
+ enumerate_cpus();
+ create_all_devices();
+ detect_power_meters();
+
+ register_parameter("base power", 100, 0.5);
+ register_parameter("cpu-wakeups", 39.5);
+ register_parameter("cpu-consumption", 1.56);
+ register_parameter("gpu-operations", 0.5576);
+ register_parameter("disk-operations-hard", 0.2);
+ register_parameter("disk-operations", 0.0);
+ register_parameter("xwakes", 0.1);
+
+ load_board_params();
+ initialized = 1;
+}
+
+
+int main(int argc, char **argv)
+{
int option_index;
int c;
bool wantreport = FALSE;
char filename[4096];
int iterations = 1;
- struct statfs st_fs;
#ifndef DISABLE_TRYCATCH
set_new_handler(out_of_memory);
@@ -322,6 +375,7 @@ int main(int argc, char **argv)
break;
case 'c':
+ powertop_init();
calibrate();
break;
@@ -350,48 +404,8 @@ int main(int argc, char **argv)
break;
}
}
-
- checkroot();
- ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
- ret = system("/sbin/modprobe msr > /dev/null 2>&1");
-
- statfs("/sys/kernel/debug", &st_fs);
- if (st_fs.f_type != (long) DEBUGFS_MAGIC) {
- if (access("/bin/mount", X_OK) == 0) {
- ret = system("/bin/mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
- } else {
- ret = system("mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
- }
- if (ret != 0) {
- printf(_("Failed to mount debugfs!\n"));
- printf(_("exiting...\n"));
- exit(EXIT_FAILURE);
- }
- }
-
- srand(time(NULL));
-
- if (access("/var/cache/", W_OK) == 0)
- mkdir("/var/cache/powertop", 0600);
- else
- mkdir("/data/local/powertop", 0600);
- load_results("saved_results.powertop");
- load_parameters("saved_parameters.powertop");
-
- enumerate_cpus();
- create_all_devices();
- detect_power_meters();
-
- register_parameter("base power", 100, 0.5);
- register_parameter("cpu-wakeups", 39.5);
- register_parameter("cpu-consumption", 1.56);
- register_parameter("gpu-operations", 0.5576);
- register_parameter("disk-operations-hard", 0.2);
- register_parameter("disk-operations", 0.0);
- register_parameter("xwakes", 0.1);
-
- load_board_params();
+ powertop_init();
if (wantreport)
report(time_out, iterations, filename);
@@ -399,8 +413,6 @@ int main(int argc, char **argv)
if (debug_learning)
printf("Learning debugging enabled\n");
-
-
learn_parameters(250, 0);
save_parameters("saved_parameters.powertop");
@@ -412,7 +424,6 @@ int main(int argc, char **argv)
exit(0);
}
-
/* first one is short to not let the user wait too long */
init_display();
one_measurement(1);
@@ -420,11 +431,9 @@ int main(int argc, char **argv)
tuning_update_display();
show_tab(0);
-
-
while (!leave_powertop) {
- one_measurement(time_out);
show_cur_tab();
+ one_measurement(time_out);
learn_parameters(15, 0);
}
#ifndef DISABLE_NCURSES
@@ -432,7 +441,6 @@ int main(int argc, char **argv)
#endif
printf(_("Leaving PowerTOP\n"));
-
end_process_data();
clear_process_data();
end_cpu_data();
@@ -450,6 +458,4 @@ int main(int argc, char **argv)
clear_all_cpus();
return 0;
-
-
}
next reply other threads:[~2012-05-17 16:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-17 16:44 Sergey Senozhatsky [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-05-18 10:13 [Powertop] [PATCH] factor out powertop_init() function [was "Segmentation fault occurs with --calibrate"] Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120517164458.GA3486@swordfish \
--to=powertop@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.