tools/power/cpupower/utils/cpupower.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/cpupower.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/cpupower.c- Extension
.c- Size
- 5625 bytes
- Lines
- 247
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstring.hunistd.herrno.hsched.hsys/types.hsys/stat.hsys/utsname.hbuiltin.hhelpers/helpers.hhelpers/bitmask.h
Detected Declarations
struct cmd_structfunction print_helpfunction print_man_pagefunction cmd_helpfunction print_versionfunction handle_optionsfunction main
Annotated Snippet
struct cmd_struct {
const char *cmd;
int (*main)(int, const char **);
int needs_root;
};
static struct cmd_struct commands[] = {
{ "frequency-info", cmd_freq_info, 0 },
{ "frequency-set", cmd_freq_set, 1 },
{ "idle-info", cmd_idle_info, 0 },
{ "idle-set", cmd_idle_set, 1 },
{ "powercap-info", cmd_cap_info, 0 },
{ "set", cmd_set, 1 },
{ "info", cmd_info, 0 },
{ "monitor", cmd_monitor, 0 },
{ "help", cmd_help, 0 },
/* { "bench", cmd_bench, 1 }, */
};
static void print_help(void)
{
unsigned int i;
#ifdef DEBUG
printf(_("Usage:\tcpupower [-d|--debug] [-c|--cpu cpulist ] <command> [<args>]\n"));
#else
printf(_("Usage:\tcpupower [-c|--cpu cpulist ] <command> [<args>]\n"));
#endif
printf(_("Supported commands are:\n"));
for (i = 0; i < ARRAY_SIZE(commands); i++)
printf("\t%s\n", commands[i].cmd);
printf(_("\nNot all commands can make use of the -c cpulist option.\n"));
printf(_("\nUse 'cpupower help <command>' for getting help for above commands.\n"));
}
static int print_man_page(const char *subpage)
{
int len;
char *page;
len = 10; /* enough for "cpupower-" */
if (subpage != NULL)
len += strlen(subpage);
page = malloc(len);
if (!page)
return -ENOMEM;
sprintf(page, "cpupower");
if ((subpage != NULL) && strcmp(subpage, "help")) {
strcat(page, "-");
strcat(page, subpage);
}
execlp("man", "man", page, NULL);
/* should not be reached */
return -EINVAL;
}
static int cmd_help(int argc, const char **argv)
{
if (argc > 1) {
print_man_page(argv[1]); /* exits within execlp() */
return EXIT_FAILURE;
}
print_help();
return EXIT_SUCCESS;
}
static void print_version(void)
{
printf(PACKAGE " " VERSION "\n");
printf(_("Report errors and bugs to %s, please.\n"), PACKAGE_BUGREPORT);
}
static void handle_options(int *argc, const char ***argv)
{
int ret, x, new_argc = 0;
if (*argc < 1)
return;
for (x = 0; x < *argc && ((*argv)[x])[0] == '-'; x++) {
const char *param = (*argv)[x];
if (!strcmp(param, "-h") || !strcmp(param, "--help")) {
print_help();
exit(EXIT_SUCCESS);
} else if (!strcmp(param, "-c") || !strcmp(param, "--cpu")) {
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `errno.h`, `sched.h`, `sys/types.h`, `sys/stat.h`.
- Detected declarations: `struct cmd_struct`, `function print_help`, `function print_man_page`, `function cmd_help`, `function print_version`, `function handle_options`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.