Skip to content

Commit

Permalink
cpupower: use man(1) when calling "cpupower help subcommand"
Browse files Browse the repository at this point in the history
Instead of printing something non-formatted to stdout, call
man(1) to show the man page for the proper subcommand.

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
  • Loading branch information
Dominik Brodowski committed Aug 19, 2011
1 parent 47c3363 commit 498ca79
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 228 deletions.
6 changes: 3 additions & 3 deletions tools/power/cpupower/man/cpupower-frequency-info.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.TH "cpufreq-info" "1" "0.1" "Mattia Dongili" ""
.TH "cpupower-frequency-info" "1" "0.1" "Mattia Dongili" ""
.SH "NAME"
.LP
cpufreq\-info \- Utility to retrieve cpufreq kernel information
cpupower frequency\-info \- Utility to retrieve cpufreq kernel information
.SH "SYNTAX"
.LP
cpufreq\-info [\fIoptions\fP]
cpupower [ \-c cpulist ] frequency\-info [\fIoptions\fP]
.SH "DESCRIPTION"
.LP
A small tool which prints out cpufreq information helpful to developers and interested users.
Expand Down
8 changes: 4 additions & 4 deletions tools/power/cpupower/man/cpupower-frequency-set.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.TH "cpufreq-set" "1" "0.1" "Mattia Dongili" ""
.TH "cpupower-freqency-set" "1" "0.1" "Mattia Dongili" ""
.SH "NAME"
.LP
cpufreq\-set \- A small tool which allows to modify cpufreq settings.
cpupower frequency\-set \- A small tool which allows to modify cpufreq settings.
.SH "SYNTAX"
.LP
cpufreq\-set [\fIoptions\fP]
cpupower [ \-c cpu ] frequency\-set [\fIoptions\fP]
.SH "DESCRIPTION"
.LP
cpufreq\-set allows you to modify cpufreq settings without having to type e.g. "/sys/devices/system/cpu/cpu0/cpufreq/scaling_set_speed" all the time.
cpupower frequency\-set allows you to modify cpufreq settings without having to type e.g. "/sys/devices/system/cpu/cpu0/cpufreq/scaling_set_speed" all the time.
.SH "OPTIONS"
.LP
.TP
Expand Down
14 changes: 7 additions & 7 deletions tools/power/cpupower/man/cpupower.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cpupower \- Shows and sets processor power related values
.SH SYNOPSIS
.ft B
.B cpupower [ \-c cpulist ] subcommand [ARGS]
.B cpupower [ \-c cpulist ] <command> [ARGS]

.B cpupower \-v|\-\-version

Expand All @@ -13,24 +13,24 @@ cpupower \- Shows and sets processor power related values
\fBcpupower \fP is a collection of tools to examine and tune power saving
related features of your processor.

The manpages of the subcommands (cpupower\-<subcommand>(1)) provide detailed
The manpages of the commands (cpupower\-<command>(1)) provide detailed
descriptions of supported features. Run \fBcpupower help\fP to get an overview
of supported subcommands.
of supported commands.

.SH Options
.PP
\-\-help, \-h
.RS 4
Shows supported subcommands and general usage.
Shows supported commands and general usage.
.RE
.PP
\-\-cpu cpulist, \-c cpulist
.RS 4
Only show or set values for specific cores.
This option is not supported by all subcommands, details can be found in the
manpages of the subcommands.
This option is not supported by all commands, details can be found in the
manpages of the commands.

Some subcommands access all cores (typically the *\-set commands), some only
Some commands access all cores (typically the *\-set commands), some only
the first core (typically the *\-info commands) by default.

The syntax for <cpulist> is based on how the kernel exports CPU bitmasks via
Expand Down
7 changes: 0 additions & 7 deletions tools/power/cpupower/utils/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,4 @@ extern int cmd_freq_info(int argc, const char **argv);
extern int cmd_idle_info(int argc, const char **argv);
extern int cmd_monitor(int argc, const char **argv);

extern void set_help(void);
extern void info_help(void);
extern void freq_set_help(void);
extern void freq_info_help(void);
extern void idle_info_help(void);
extern void monitor_help(void);

#endif
42 changes: 1 addition & 41 deletions tools/power/cpupower/utils/cpufreq-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,37 +510,6 @@ static int get_latency(unsigned int cpu, unsigned int human)
return 0;
}

void freq_info_help(void)
{
printf(_("Usage: cpupower freqinfo [options]\n"));
printf(_("Options:\n"));
printf(_(" -e, --debug Prints out debug information [default]\n"));
printf(_(" -f, --freq Get frequency the CPU currently runs at, according\n"
" to the cpufreq core *\n"));
printf(_(" -w, --hwfreq Get frequency the CPU currently runs at, by reading\n"
" it from hardware (only available to root) *\n"));
printf(_(" -l, --hwlimits Determine the minimum and maximum CPU frequency allowed *\n"));
printf(_(" -d, --driver Determines the used cpufreq kernel driver *\n"));
printf(_(" -p, --policy Gets the currently used cpufreq policy *\n"));
printf(_(" -g, --governors Determines available cpufreq governors *\n"));
printf(_(" -r, --related-cpus Determines which CPUs run at the same hardware frequency *\n"));
printf(_(" -a, --affected-cpus Determines which CPUs need to have their frequency\n"
" coordinated by software *\n"));
printf(_(" -s, --stats Shows cpufreq statistics if available\n"));
printf(_(" -y, --latency Determines the maximum latency on CPU frequency changes *\n"));
printf(_(" -b, --boost Checks for turbo or boost modes *\n"));
printf(_(" -o, --proc Prints out information like provided by the /proc/cpufreq\n"
" interface in 2.4. and early 2.6. kernels\n"));
printf(_(" -m, --human human-readable output for the -f, -w, -s and -y parameters\n"));
printf(_(" -h, --help Prints out this screen\n"));

printf("\n");
printf(_("If no argument is given, full output about\n"
"cpufreq is printed which is useful e.g. for reporting bugs.\n\n"));
printf(_("By default info of CPU 0 is shown which can be overridden\n"
"with the cpupower --cpu main command option.\n"));
}

static struct option info_opts[] = {
{ .name = "debug", .has_arg = no_argument, .flag = NULL, .val = 'e'},
{ .name = "boost", .has_arg = no_argument, .flag = NULL, .val = 'b'},
Expand All @@ -556,7 +525,6 @@ static struct option info_opts[] = {
{ .name = "latency", .has_arg = no_argument, .flag = NULL, .val = 'y'},
{ .name = "proc", .has_arg = no_argument, .flag = NULL, .val = 'o'},
{ .name = "human", .has_arg = no_argument, .flag = NULL, .val = 'm'},
{ .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
{ },
};

Expand All @@ -570,16 +538,12 @@ int cmd_freq_info(int argc, char **argv)
int output_param = 0;

do {
ret = getopt_long(argc, argv, "hoefwldpgrasmyb", info_opts, NULL);
ret = getopt_long(argc, argv, "oefwldpgrasmyb", info_opts, NULL);
switch (ret) {
case '?':
output_param = '?';
cont = 0;
break;
case 'h':
output_param = 'h';
cont = 0;
break;
case -1:
cont = 0;
break;
Expand Down Expand Up @@ -642,11 +606,7 @@ int cmd_freq_info(int argc, char **argv)
return -EINVAL;
case '?':
printf(_("invalid or unknown argument\n"));
freq_info_help();
return -EINVAL;
case 'h':
freq_info_help();
return EXIT_SUCCESS;
case 'o':
proc_cpufreq_output();
return EXIT_SUCCESS;
Expand Down
29 changes: 1 addition & 28 deletions tools/power/cpupower/utils/cpufreq-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,11 @@

#define NORM_FREQ_LEN 32

void freq_set_help(void)
{
printf(_("Usage: cpupower frequency-set [options]\n"));
printf(_("Options:\n"));
printf(_(" -d FREQ, --min FREQ new minimum CPU frequency the governor may select\n"));
printf(_(" -u FREQ, --max FREQ new maximum CPU frequency the governor may select\n"));
printf(_(" -g GOV, --governor GOV new cpufreq governor\n"));
printf(_(" -f FREQ, --freq FREQ specific frequency to be set. Requires userspace\n"
" governor to be available and loaded\n"));
printf(_(" -r, --related Switches all hardware-related CPUs\n"));
printf(_(" -h, --help Prints out this screen\n"));
printf("\n");
printf(_("Notes:\n"
"1. Omitting the -c or --cpu argument is equivalent to setting it to \"all\"\n"));
printf(_("2. The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter\n"
" except the -c CPU, --cpu CPU parameter\n"
"3. FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz\n"
" by postfixing the value with the wanted unit name, without any space\n"
" (FREQuency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).\n"));

}

static struct option set_opts[] = {
{ .name = "min", .has_arg = required_argument, .flag = NULL, .val = 'd'},
{ .name = "max", .has_arg = required_argument, .flag = NULL, .val = 'u'},
{ .name = "governor", .has_arg = required_argument, .flag = NULL, .val = 'g'},
{ .name = "freq", .has_arg = required_argument, .flag = NULL, .val = 'f'},
{ .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
{ .name = "related", .has_arg = no_argument, .flag = NULL, .val='r'},
{ },
};
Expand Down Expand Up @@ -80,7 +57,6 @@ const struct freq_units def_units[] = {
static void print_unknown_arg(void)
{
printf(_("invalid or unknown argument\n"));
freq_set_help();
}

static unsigned long string_to_frequency(const char *str)
Expand Down Expand Up @@ -231,14 +207,11 @@ int cmd_freq_set(int argc, char **argv)

/* parameter parsing */
do {
ret = getopt_long(argc, argv, "d:u:g:f:hr", set_opts, NULL);
ret = getopt_long(argc, argv, "d:u:g:f:r", set_opts, NULL);
switch (ret) {
case '?':
print_unknown_arg();
return -EINVAL;
case 'h':
freq_set_help();
return 0;
case -1:
cont = 0;
break;
Expand Down
24 changes: 1 addition & 23 deletions tools/power/cpupower/utils/cpuidle-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,14 @@ static void proc_cpuidle_cpu_output(unsigned int cpu)
}
}

/* --freq / -f */

void idle_info_help(void)
{
printf(_ ("Usage: cpupower idleinfo [options]\n"));
printf(_ ("Options:\n"));
printf(_ (" -s, --silent Only show general C-state information\n"));
printf(_ (" -o, --proc Prints out information like provided by the /proc/acpi/processor/*/power\n"
" interface in older kernels\n"));
printf(_ (" -h, --help Prints out this screen\n"));

printf("\n");
}

static struct option info_opts[] = {
{ .name = "silent", .has_arg = no_argument, .flag = NULL, .val = 's'},
{ .name = "proc", .has_arg = no_argument, .flag = NULL, .val = 'o'},
{ .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
{ },
};

static inline void cpuidle_exit(int fail)
{
idle_info_help();
exit(EXIT_FAILURE);
}

Expand All @@ -174,18 +158,14 @@ int cmd_idle_info(int argc, char **argv)
unsigned int cpu = 0;

do {
ret = getopt_long(argc, argv, "hos", info_opts, NULL);
ret = getopt_long(argc, argv, "os", info_opts, NULL);
if (ret == -1)
break;
switch (ret) {
case '?':
output_param = '?';
cont = 0;
break;
case 'h':
output_param = 'h';
cont = 0;
break;
case 's':
verbose = 0;
break;
Expand All @@ -211,8 +191,6 @@ int cmd_idle_info(int argc, char **argv)
case '?':
printf(_("invalid or unknown argument\n"));
cpuidle_exit(EXIT_FAILURE);
case 'h':
cpuidle_exit(EXIT_SUCCESS);
}

/* Default is: show output of CPU 0 only */
Expand Down
20 changes: 1 addition & 19 deletions tools/power/cpupower/utils/cpupower-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,16 @@
#include "helpers/helpers.h"
#include "helpers/sysfs.h"

void info_help(void)
{
printf(_("Usage: cpupower info [ -b ] [ -m ] [ -s ]\n"));
printf(_("Options:\n"));
printf(_(" -b, --perf-bias Gets CPU's power vs performance policy on some\n"
" Intel models [0-15], see manpage for details\n"));
printf(_(" -m, --sched-mc Gets the kernel's multi core scheduler policy.\n"));
printf(_(" -s, --sched-smt Gets the kernel's thread sibling scheduler policy.\n"));
printf(_(" -h, --help Prints out this screen\n"));
printf(_("\nPassing no option will show all info, by default only on core 0\n"));
printf("\n");
}

static struct option set_opts[] = {
{ .name = "perf-bias", .has_arg = optional_argument, .flag = NULL, .val = 'b'},
{ .name = "sched-mc", .has_arg = optional_argument, .flag = NULL, .val = 'm'},
{ .name = "sched-smt", .has_arg = optional_argument, .flag = NULL, .val = 's'},
{ .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
{ },
};

static void print_wrong_arg_exit(void)
{
printf(_("invalid or unknown argument\n"));
info_help();
exit(EXIT_FAILURE);
}

Expand All @@ -64,11 +49,8 @@ int cmd_info(int argc, char **argv)
textdomain(PACKAGE);

/* parameter parsing */
while ((ret = getopt_long(argc, argv, "msbh", set_opts, NULL)) != -1) {
while ((ret = getopt_long(argc, argv, "msb", set_opts, NULL)) != -1) {
switch (ret) {
case 'h':
info_help();
return 0;
case 'b':
if (params.perf_bias)
print_wrong_arg_exit();
Expand Down
25 changes: 3 additions & 22 deletions tools/power/cpupower/utils/cpupower-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,16 @@
#include "helpers/sysfs.h"
#include "helpers/bitmask.h"

void set_help(void)
{
printf(_("Usage: cpupower set [ -b val ] [ -m val ] [ -s val ]\n"));
printf(_("Options:\n"));
printf(_(" -b, --perf-bias [VAL] Sets CPU's power vs performance policy on some\n"
" Intel models [0-15], see manpage for details\n"));
printf(_(" -m, --sched-mc [VAL] Sets the kernel's multi core scheduler policy.\n"));
printf(_(" -s, --sched-smt [VAL] Sets the kernel's thread sibling scheduler policy.\n"));
printf(_(" -h, --help Prints out this screen\n"));
printf("\n");
}

static struct option set_opts[] = {
{ .name = "perf-bias", .has_arg = optional_argument, .flag = NULL, .val = 'b'},
{ .name = "sched-mc", .has_arg = optional_argument, .flag = NULL, .val = 'm'},
{ .name = "sched-smt", .has_arg = optional_argument, .flag = NULL, .val = 's'},
{ .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
{ },
};

static void print_wrong_arg_exit(void)
{
printf(_("invalid or unknown argument\n"));
set_help();
exit(EXIT_FAILURE);
}

Expand All @@ -66,12 +52,9 @@ int cmd_set(int argc, char **argv)

params.params = 0;
/* parameter parsing */
while ((ret = getopt_long(argc, argv, "m:s:b:h",
while ((ret = getopt_long(argc, argv, "m:s:b:",
set_opts, NULL)) != -1) {
switch (ret) {
case 'h':
set_help();
return 0;
case 'b':
if (params.perf_bias)
print_wrong_arg_exit();
Expand Down Expand Up @@ -110,10 +93,8 @@ int cmd_set(int argc, char **argv)
}
};

if (!params.params) {
set_help();
return -EINVAL;
}
if (!params.params)
print_wrong_arg_exit();

if (params.sched_mc) {
ret = sysfs_set_sched("mc", sched_mc);
Expand Down
Loading

0 comments on commit 498ca79

Please sign in to comment.