Blame SOURCES/powertop-2.3-auto-tune.patch

480824
diff --git a/doc/powertop.8 b/doc/powertop.8
480824
index 4a2f0b0..0f460ec 100644
480824
--- a/doc/powertop.8
480824
+++ b/doc/powertop.8
480824
@@ -14,7 +14,10 @@ experiment with various power management settings. When invoking powertop
480824
 without arguments powertop starts in interactive mode.
480824
 .SH OPTIONS
480824
 .TP
480824
-\fB\-\-calibrate
480824
+.B \-\-auto\-tune
480824
+Set all tunable options to their good setting without interaction.
480824
+.TP
480824
+.BR \-c ", " \-\-calibrate
480824
 runs powertop in calibration mode. When running on battery, powertop
480824
 can track power consumption as well as system activity. When there
480824
 are enough measurements, powertop can start to report power estimates. One
480824
diff --git a/src/main.cpp b/src/main.cpp
480824
index 16b1613..9da3167 100644
480824
--- a/src/main.cpp
480824
+++ b/src/main.cpp
480824
@@ -75,6 +75,7 @@ static const struct option long_options[] =
480824
 	{"version", no_argument, NULL, 'V'},
480824
 	{"help",no_argument, NULL, 'u'}, /* u for usage */
480824
 	{"calibrate",no_argument, NULL, 'c'},
480824
+	{"auto-tune",no_argument, NULL, 'a'},
480824
 	{"html", optional_argument, NULL, 'h'},
480824
 	{"csv", optional_argument, NULL, 'C'},
480824
 	{"extech", optional_argument, NULL, 'e'},
480824
@@ -110,6 +111,7 @@ static void print_usage()
480824
 	printf("--debug \t\t %s\n",_("run in \"debug\" mode"));
480824
 	printf("--version \t\t %s\n",_("print version information"));
480824
 	printf("--calibrate \t\t %s\n",_("runs powertop in calibration mode"));
480824
+	printf("--auto-tune \t\t %s\n",_("Sets all tunable options to their GOOD setting"));
480824
 	printf("--extech%s \t %s\n",_("[=devnode]"),_("uses an Extech Power Analyzer for measurements"));
480824
 	printf("--html%s \t %s\n",_("[=FILENAME]"),_("generate a html report"));
480824
 	printf("--csv%s \t %s\n",_("[=FILENAME]"),_("generate a csv report"));
480824
@@ -362,7 +364,7 @@ int main(int argc, char **argv)
480824
 	int c;
480824
 	char filename[4096];
480824
 	char workload[4096] = {0,};
480824
-	int  iterations = 1;
480824
+	int  iterations = 1, auto_tune = 0;
480824
 
480824
 	set_new_handler(out_of_memory);
480824
 
480824
@@ -390,7 +392,10 @@ int main(int argc, char **argv)
480824
 				print_usage();
480824
 				exit(0);
480824
 				break;
480824
-
480824
+			case 'a':
480824
+				auto_tune = 1;
480824
+				leave_powertop = 1;
480824
+				break;
480824
 			case 'c':
480824
 				powertop_init();
480824
 				calibrate();
480824
@@ -446,20 +451,27 @@ int main(int argc, char **argv)
480824
 		end_pci_access();
480824
 		exit(0);
480824
 	}
480824
-
480824
+	if (!auto_tune)
480824
+		init_display();
480824
+	initialize_tuning();
480824
 	/* first one is short to not let the user wait too long */
480824
-	init_display();
480824
 	one_measurement(1, NULL);
480824
-	initialize_tuning();
480824
-	tuning_update_display();
480824
-	show_tab(0);
480824
+
480824
+	if (!auto_tune) {
480824
+		tuning_update_display();
480824
+		show_tab(0);
480824
+	} else {
480824
+		auto_toggle_tuning();
480824
+	}
480824
 
480824
 	while (!leave_powertop) {
480824
-		show_cur_tab();
480824
+		if (!auto_tune)
480824
+			show_cur_tab();
480824
 		one_measurement(time_out, NULL);
480824
 		learn_parameters(15, 0);
480824
 	}
480824
-	endwin();
480824
+	if (!auto_tune)
480824
+		endwin();
480824
 	printf("%s\n", _("Leaving PowerTOP"));
480824
 
480824
 	end_process_data();
480824
diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
480824
index 08d8251..ff3d715 100644
480824
--- a/src/tuning/tuning.cpp
480824
+++ b/src/tuning/tuning.cpp
480824
@@ -273,3 +273,11 @@ void clear_tuning()
480824
 	}
480824
 	all_untunables.clear();
480824
 }
480824
+
480824
+void auto_toggle_tuning()
480824
+{
480824
+	for (unsigned int i = 0; i < all_tunables.size(); i++) {
480824
+		if (all_tunables[i]->good_bad() == TUNE_BAD)
480824
+			all_tunables[i]->toggle();
480824
+	}
480824
+}
480824
diff --git a/src/tuning/tuning.h b/src/tuning/tuning.h
480824
index 7c4921f..f70001b 100644
480824
--- a/src/tuning/tuning.h
480824
+++ b/src/tuning/tuning.h
480824
@@ -29,7 +29,5 @@ extern void initialize_tuning(void);
480824
 extern void tuning_update_display(void);
480824
 extern void report_show_tunables(void);
480824
 extern void clear_tuning(void);
480824
-
480824
-
480824
-
480824
+extern void auto_toggle_tuning(void);
480824
 #endif