tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
Source file repositories/reference/linux-study-clean/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c- Extension
.c- Size
- 43710 bytes
- Lines
- 1798
- 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.hunistd.hsys/types.hsched.hsys/stat.hsys/resource.hgetopt.herr.hfcntl.hsignal.hsys/time.hlimits.hstdlib.hstring.hcpuid.herrno.h
Detected Declarations
struct msr_hwp_capstruct msr_hwp_requestfunction usagefunction ratio_2_msr_perffunction msr_perf_2_ratiofunction parse_cmdline_epbfunction parse_cmdline_hwp_minfunction parse_cmdline_hwp_maxfunction parse_cmdline_hwp_desiredfunction parse_cmdline_hwp_windowfunction parse_cmdline_hwp_eppfunction parse_cmdline_turbofunction parse_optarg_stringfunction parse_cmdline_allfunction validate_cpu_selected_setfunction parse_cmdline_cpufunction parse_cmdline_pkgfunction for_packagesfunction parse_cmdline_intfunction print_versionfunction platform_profile_accessfunction platform_profile_name_isfunction soc_slider_accessfunction cmdlinefunction err_on_hypervisorfunction get_msrfunction put_msrfunction read_sysfsfunction write_sysfsfunction sysfs_read_stringfunction sysfs_write_stringfunction print_hwp_capfunction read_hwp_capfunction print_hwp_requestfunction print_hwp_request_pkgfunction read_hwp_request_msrfunction write_hwp_request_msrfunction get_epb_sysfsfunction set_epb_sysfsfunction print_soc_sliderfunction print_platform_profilefunction update_soc_sliderfunction print_cpu_msrsfunction print_pkg_msrsfunction ratio_2_sysfs_khzfunction update_cpufreq_scaling_freqfunction update_sysfsfunction verify_hwp_req_self_consistency
Annotated Snippet
struct msr_hwp_cap {
unsigned char highest;
unsigned char guaranteed;
unsigned char efficient;
unsigned char lowest;
};
struct msr_hwp_request {
unsigned char hwp_min;
unsigned char hwp_max;
unsigned char hwp_desired;
unsigned char hwp_epp;
unsigned int hwp_window;
unsigned char hwp_use_pkg;
} req_update;
unsigned int debug;
unsigned int verbose;
unsigned int force;
char *progname;
int base_cpu;
unsigned char update_epb;
unsigned long long new_epb;
unsigned char turbo_is_enabled;
unsigned char update_turbo;
unsigned char turbo_update_value;
unsigned char update_hwp_epp;
unsigned char update_hwp_min;
unsigned char update_hwp_max;
unsigned char hwp_limits_done_via_sysfs;
unsigned char update_hwp_desired;
unsigned char update_hwp_window;
unsigned char update_hwp_use_pkg;
unsigned char update_hwp_enable;
#define hwp_update_enabled() (update_hwp_enable | update_hwp_epp | update_hwp_max | update_hwp_min | update_hwp_desired | update_hwp_window | update_hwp_use_pkg)
int max_cpu_num;
int max_pkg_num;
#define MAX_PACKAGES 64
unsigned int first_cpu_in_pkg[MAX_PACKAGES];
unsigned long long pkg_present_set;
unsigned long long pkg_selected_set;
cpu_set_t *cpu_present_set;
cpu_set_t *cpu_selected_set;
int genuine_intel;
size_t cpu_setsize;
char *proc_stat = "/proc/stat";
unsigned int has_epb; /* MSR_IA32_ENERGY_PERF_BIAS */
unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */
/* IA32_HWP_REQUEST, IA32_HWP_STATUS */
unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */
unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */
unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */
unsigned int has_hwp_request_pkg; /* IA32_HWP_REQUEST_PKG */
unsigned int bdx_highest_ratio;
unsigned char update_soc_slider_balance;
unsigned char update_soc_slider_offset;
unsigned char update_platform_profile;
int soc_slider_balance;
int soc_slider_offset;
char platform_profile[64];
#define PATH_TO_CPU "/sys/devices/system/cpu/"
#define SYSFS_PATH_MAX 255
#define PATH_SOC_SLIDER_BALANCE "/sys/module/processor_thermal_soc_slider/parameters/slider_balance"
#define PATH_SOC_SLIDER_OFFSET "/sys/module/processor_thermal_soc_slider/parameters/slider_offset"
#define PATH_PLATFORM_PROFILE "/sys/class/platform-profile/platform-profile-0/profile"
#define PATH_PLATFORM_PROFILE_NAME "/sys/class/platform-profile/platform-profile-0/name"
#define POWER_SLIDER_NAME "SoC Power Slider"
static int use_android_msr_path;
static unsigned int read_sysfs(const char *, char *, size_t);
static int sysfs_read_string(const char *, char *, size_t);
/*
* maintain compatibility with original implementation, but don't document it:
*/
void usage(void)
{
fprintf(stderr, "%s [options] [scope][field value]\n", progname);
fprintf(stderr, "scope: --cpu cpu-list [--hwp-use-pkg #] | --pkg pkg-list\n");
fprintf(stderr, "field: --all | --epb | --hwp-epp | --hwp-min | --hwp-max | --hwp-desired\n");
fprintf(stderr, "other: --hwp-enable | --turbo-enable (0 | 1) | --help | --force\n");
fprintf(stderr, "soc-slider: --soc-slider-balance # | --soc-slider-offset # | --platform-profile <name>\n");
fprintf(stderr, "value: ( # | \"normal\" | \"performance\" | \"balance-performance\" | \"balance-power\"| \"power\")\n");
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `sys/types.h`, `sched.h`, `sys/stat.h`, `sys/resource.h`, `getopt.h`, `err.h`.
- Detected declarations: `struct msr_hwp_cap`, `struct msr_hwp_request`, `function usage`, `function ratio_2_msr_perf`, `function msr_perf_2_ratio`, `function parse_cmdline_epb`, `function parse_cmdline_hwp_min`, `function parse_cmdline_hwp_max`, `function parse_cmdline_hwp_desired`, `function parse_cmdline_hwp_window`.
- 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.