unsigned int cpunr = 0;
fp = fopen("/proc/stat", "r");
- if(!fp) {
+ if (!fp) {
printf(_("Couldn't count the number of CPUs (%s: %s), assuming 1\n"), "/proc/stat", strerror(errno));
return 1;
}
fclose(fp);
/* cpu count starts from 0, on error return 1 (UP) */
- return (ret+1);
+ return ret + 1;
}
printf(_(" minimum CPU frequency - maximum CPU frequency - governor\n"));
nr_cpus = count_cpus();
- for (cpu=0; cpu < nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
policy = cpufreq_get_policy(cpu);
if (!policy)
continue;
max_pctg = (policy->max * 100) / max;
}
printf("CPU%3d %9lu kHz (%3d %%) - %9lu kHz (%3d %%) - %s\n",
- cpu , policy->min, max ? min_pctg : 0, policy->max, max ? max_pctg : 0, policy->governor);
+ cpu , policy->min, max ? min_pctg : 0, policy->max,
+ max ? max_pctg : 0, policy->governor);
cpufreq_put_policy(policy);
}
tmp = speed % 10000;
if (tmp >= 5000)
speed += 10000;
- printf ("%u.%02u GHz", ((unsigned int) speed/1000000),
+ printf("%u.%02u GHz", ((unsigned int) speed/1000000),
((unsigned int) (speed%1000000)/10000));
} else if (speed > 100000) {
tmp = speed % 1000;
if (tmp >= 500)
speed += 1000;
- printf ("%u MHz", ((unsigned int) speed / 1000));
+ printf("%u MHz", ((unsigned int) speed / 1000));
} else if (speed > 1000) {
tmp = speed % 100;
if (tmp >= 50)
speed += 100;
- printf ("%u.%01u MHz", ((unsigned int) speed/1000),
+ printf("%u.%01u MHz", ((unsigned int) speed/1000),
((unsigned int) (speed%1000)/100));
} else
- printf ("%lu kHz", speed);
+ printf("%lu kHz", speed);
return;
}
tmp = duration % 10000;
if (tmp >= 5000)
duration += 10000;
- printf ("%u.%02u ms", ((unsigned int) duration/1000000),
+ printf("%u.%02u ms", ((unsigned int) duration/1000000),
((unsigned int) (duration%1000000)/10000));
} else if (duration > 100000) {
tmp = duration % 1000;
if (tmp >= 500)
duration += 1000;
- printf ("%u us", ((unsigned int) duration / 1000));
+ printf("%u us", ((unsigned int) duration / 1000));
} else if (duration > 1000) {
tmp = duration % 100;
if (tmp >= 50)
duration += 100;
- printf ("%u.%01u us", ((unsigned int) duration/1000),
+ printf("%u.%01u us", ((unsigned int) duration/1000),
((unsigned int) (duration%1000)/100));
} else
- printf ("%lu ns", duration);
+ printf("%lu ns", duration);
return;
}
/* --boost / -b */
-static int get_boost_mode(unsigned int cpu) {
+static int get_boost_mode(unsigned int cpu)
+{
int support, active, b_states = 0, ret, pstate_no, i;
/* ToDo: Make this more global */
unsigned long pstates[MAX_HW_PSTATES] = {0,};
&& (cpuid_edx(0x80000007) & (1 << 7)))
*/
- printf(_(" boost state support: \n"));
+ printf(_(" boost state support:\n"));
printf(_(" Supported: %s\n"), support ? _("yes") : _("no"));
printf(_(" Active: %s\n"), active ? _("yes") : _("no"));
/* ToDo: Only works for AMD for now... */
-
+
if (cpupower_cpu_info.vendor == X86_VENDOR_AMD &&
cpupower_cpu_info.family >= 0x10) {
ret = decode_pstates(cpu, cpupower_cpu_info.family, b_states,
unsigned long total_trans, latency;
unsigned long long total_time;
struct cpufreq_policy *policy;
- struct cpufreq_available_governors * governors;
+ struct cpufreq_available_governors *governors;
struct cpufreq_stats *stats;
- if (cpufreq_cpu_exists(cpu)) {
+ if (cpufreq_cpu_exists(cpu))
return;
- }
freq_kernel = cpufreq_get_freq_kernel(cpu);
freq_hardware = cpufreq_get_freq_hardware(cpu);
if (freq_hardware) {
print_speed(freq_hardware);
printf(_(" (asserted by call to hardware)"));
- }
- else
+ } else
print_speed(freq_kernel);
printf(".\n");
}
/* --freq / -f */
-static int get_freq_kernel(unsigned int cpu, unsigned int human) {
+static int get_freq_kernel(unsigned int cpu, unsigned int human)
+{
unsigned long freq = cpufreq_get_freq_kernel(cpu);
if (!freq)
return -EINVAL;
/* --hwfreq / -w */
-static int get_freq_hardware(unsigned int cpu, unsigned int human) {
+static int get_freq_hardware(unsigned int cpu, unsigned int human)
+{
unsigned long freq = cpufreq_get_freq_hardware(cpu);
if (!freq)
return -EINVAL;
/* --hwlimits / -l */
-static int get_hardware_limits(unsigned int cpu) {
+static int get_hardware_limits(unsigned int cpu)
+{
unsigned long min, max;
if (cpufreq_get_hardware_limits(cpu, &min, &max))
return -EINVAL;
/* --driver / -d */
-static int get_driver(unsigned int cpu) {
+static int get_driver(unsigned int cpu)
+{
char *driver = cpufreq_get_driver(cpu);
if (!driver)
return -EINVAL;
/* --policy / -p */
-static int get_policy(unsigned int cpu) {
+static int get_policy(unsigned int cpu)
+{
struct cpufreq_policy *policy = cpufreq_get_policy(cpu);
if (!policy)
return -EINVAL;
/* --governors / -g */
-static int get_available_governors(unsigned int cpu) {
- struct cpufreq_available_governors *governors = cpufreq_get_available_governors(cpu);
+static int get_available_governors(unsigned int cpu)
+{
+ struct cpufreq_available_governors *governors =
+ cpufreq_get_available_governors(cpu);
if (!governors)
return -EINVAL;
/* --affected-cpus / -a */
-static int get_affected_cpus(unsigned int cpu) {
+static int get_affected_cpus(unsigned int cpu)
+{
struct cpufreq_affected_cpus *cpus = cpufreq_get_affected_cpus(cpu);
if (!cpus)
return -EINVAL;
/* --related-cpus / -r */
-static int get_related_cpus(unsigned int cpu) {
+static int get_related_cpus(unsigned int cpu)
+{
struct cpufreq_affected_cpus *cpus = cpufreq_get_related_cpus(cpu);
if (!cpus)
return -EINVAL;
/* --stats / -s */
-static int get_freq_stats(unsigned int cpu, unsigned int human) {
+static int get_freq_stats(unsigned int cpu, unsigned int human)
+{
unsigned long total_trans = cpufreq_get_transitions(cpu);
unsigned long long total_time;
struct cpufreq_stats *stats = cpufreq_get_stats(cpu, &total_time);
while (stats) {
if (human) {
print_speed(stats->frequency);
- printf(":%.2f%%", (100.0 * stats->time_in_state) / total_time);
- }
- else
- printf("%lu:%llu", stats->frequency, stats->time_in_state);
+ printf(":%.2f%%",
+ (100.0 * stats->time_in_state) / total_time);
+ } else
+ printf("%lu:%llu",
+ stats->frequency, stats->time_in_state);
stats = stats->next;
if (stats)
printf(", ");
/* --latency / -y */
-static int get_latency(unsigned int cpu, unsigned int human) {
+static int get_latency(unsigned int cpu, unsigned int human)
+{
unsigned long latency = cpufreq_get_transition_latency(cpu);
if (!latency)
return -EINVAL;
return 0;
}
-void freq_info_help(void) {
+void freq_info_help(void)
+{
printf(_("Usage: cpupower freqinfo [options]\n"));
printf(_("Options:\n"));
printf(_(" -e, --debug Prints out debug information [default]\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"
+ 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'},
- { .name="freq", .has_arg=no_argument, .flag=NULL, .val='f'},
- { .name="hwfreq", .has_arg=no_argument, .flag=NULL, .val='w'},
- { .name="hwlimits", .has_arg=no_argument, .flag=NULL, .val='l'},
- { .name="driver", .has_arg=no_argument, .flag=NULL, .val='d'},
- { .name="policy", .has_arg=no_argument, .flag=NULL, .val='p'},
- { .name="governors", .has_arg=no_argument, .flag=NULL, .val='g'},
- { .name="related-cpus", .has_arg=no_argument, .flag=NULL, .val='r'},
- { .name="affected-cpus",.has_arg=no_argument, .flag=NULL, .val='a'},
- { .name="stats", .has_arg=no_argument, .flag=NULL, .val='s'},
- { .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'},
+ { .name = "debug", .has_arg = no_argument, .flag = NULL, .val = 'e'},
+ { .name = "boost", .has_arg = no_argument, .flag = NULL, .val = 'b'},
+ { .name = "freq", .has_arg = no_argument, .flag = NULL, .val = 'f'},
+ { .name = "hwfreq", .has_arg = no_argument, .flag = NULL, .val = 'w'},
+ { .name = "hwlimits", .has_arg = no_argument, .flag = NULL, .val = 'l'},
+ { .name = "driver", .has_arg = no_argument, .flag = NULL, .val = 'd'},
+ { .name = "policy", .has_arg = no_argument, .flag = NULL, .val = 'p'},
+ { .name = "governors", .has_arg = no_argument, .flag = NULL, .val = 'g'},
+ { .name = "related-cpus", .has_arg = no_argument, .flag = NULL, .val = 'r'},
+ { .name = "affected-cpus",.has_arg = no_argument, .flag = NULL, .val = 'a'},
+ { .name = "stats", .has_arg = no_argument, .flag = NULL, .val = 's'},
+ { .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'},
{ },
};
fprintf(stderr, "invalid or unknown argument\n");
return EXIT_FAILURE;
}
- } while(cont);
+ } while (cont);
switch (output_param) {
case 'o':
/* Default is: show output of CPU 0 only */
if (bitmask_isallclear(cpus_chosen))
bitmask_setbit(cpus_chosen, 0);
-
+
switch (output_param) {
case -1:
printf(_("You can't specify more than one --cpu parameter and/or\n"
break;
}
if (ret)
- return (ret);
+ return ret;
}
return ret;
}
{ "set", cmd_set, set_help, 1 },
{ "info", cmd_info, info_help, 0 },
{ "monitor", cmd_monitor, monitor_help, 0 },
- { "help", cmd_help, print_help, 0 },
- // { "bench", cmd_bench, NULL, 1 },
+ { "help", cmd_help, print_help, 0 },
+ /* { "bench", cmd_bench, NULL, 1 }, */
};
int cmd_help(int argc, const char **argv)
printf(_("\nUse cpupower help subcommand for getting help for above subcommands.\n"));
}
-static void print_version(void) {
- printf(PACKAGE " " VERSION "\n");
+static void print_version(void)
+{
+ printf(PACKAGE " " VERSION "\n");
printf(_("Report errors and bugs to %s, please.\n"), PACKAGE_BUGREPORT);
}
for (x = 0; x < *argc && ((*argv)[x])[0] == '-'; x++) {
const char *param = (*argv)[x];
- if (!strcmp(param, "-h") || !strcmp(param, "--help")){
+ if (!strcmp(param, "-h") || !strcmp(param, "--help")) {
print_help();
exit(EXIT_SUCCESS);
- } else if (!strcmp(param, "-c") || !strcmp(param, "--cpu")){
+ } else if (!strcmp(param, "-c") || !strcmp(param, "--cpu")) {
if (*argc < 2) {
print_help();
exit(EXIT_FAILURE);
/* Cut out param: cpupower -c 1 info -> cpupower info */
new_argc += 2;
continue;
- } else if (!strcmp(param, "-v") || !strcmp(param, "--version")){
+ } else if (!strcmp(param, "-v") ||
+ !strcmp(param, "--version")) {
print_version();
exit(EXIT_SUCCESS);
#ifdef DEBUG
- } else if (!strcmp(param, "-d") || !strcmp(param, "--debug")){
+ } else if (!strcmp(param, "-d") || !strcmp(param, "--debug")) {
be_verbose = 1;
- new_argc ++;
+ new_argc++;
continue;
#endif
} else {
}
setlocale(LC_ALL, "");
- textdomain (PACKAGE);
+ textdomain(PACKAGE);
/* Turn "perf cmd --help" into "perf help cmd" */
if (argc > 1 && !strcmp(argv[1], "--help")) {