tools/power/cpupower/utils/helpers/amd.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/helpers/amd.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/helpers/amd.c- Extension
.c- Size
- 6603 bytes
- Lines
- 257
- 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
unistd.herrno.hstdio.hstdint.hpci/pci.hhelpers/helpers.hcpufreq.hacpi_cppc.h
Detected Declarations
enum amd_pstate_valuefunction get_didfunction get_coffunction pstatesfunction amd_pci_get_num_boost_statesfunction amd_pstate_get_datafunction amd_pstate_boost_initfunction amd_pstate_show_perf_and_freq
Annotated Snippet
if (cpupower_cpu_info.family >= 0x1A) {
fid = pstate.pstatedef2.fid;
if (fid > 0x0f)
cof = (fid * 5);
} else {
fid = pstate.pstatedef.fid;
cof = 200 * fid / did;
}
} else {
t = 0x10;
fid = pstate.pstate.fid;
if (cpupower_cpu_info.family == 0x11)
t = 0x8;
cof = (100 * (fid + t)) >> did;
}
return cof;
}
/* Needs:
* cpu -> the cpu that gets evaluated
* boost_states -> how much boost states the machines support
*
* Fills up:
* pstates -> a pointer to an array of size MAX_HW_PSTATES
* must be initialized with zeros.
* All available HW pstates (including boost states)
* no -> amount of pstates above array got filled up with
*
* returns zero on success, -1 on failure
*/
int decode_pstates(unsigned int cpu, int boost_states,
unsigned long *pstates, int *no)
{
int i, psmax;
union core_pstate pstate;
unsigned long long val;
/* Only read out frequencies from HW if HW Pstate is supported,
* otherwise frequencies are exported via ACPI tables.
*/
if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_HW_PSTATE))
return -1;
if (read_msr(cpu, MSR_AMD_PSTATE_LIMIT, &val))
return -1;
psmax = (val >> 4) & 0x7;
psmax += boost_states;
for (i = 0; i <= psmax; i++) {
if (i >= MAX_HW_PSTATES) {
fprintf(stderr, "HW pstates [%d] exceeding max [%d]\n",
psmax, MAX_HW_PSTATES);
return -1;
}
if (read_msr(cpu, MSR_AMD_PSTATE + i, &pstate.val))
return -1;
/* The enabled bit (bit 63) is common for all families */
if (!pstate.pstatedef.en)
continue;
pstates[i] = get_cof(pstate);
}
*no = i;
return 0;
}
int amd_pci_get_num_boost_states(int *active, int *states)
{
struct pci_access *pci_acc;
struct pci_dev *device;
uint8_t val = 0;
*active = *states = 0;
device = pci_slot_func_init(&pci_acc, 0x18, 4);
if (device == NULL)
return -ENODEV;
val = pci_read_byte(device, 0x15c);
if (val & 3)
*active = 1;
else
*active = 0;
*states = (val >> 2) & 7;
pci_cleanup(pci_acc);
return 0;
}
Annotation
- Immediate include surface: `unistd.h`, `errno.h`, `stdio.h`, `stdint.h`, `pci/pci.h`, `helpers/helpers.h`, `cpufreq.h`, `acpi_cppc.h`.
- Detected declarations: `enum amd_pstate_value`, `function get_did`, `function get_cof`, `function pstates`, `function amd_pci_get_num_boost_states`, `function amd_pstate_get_data`, `function amd_pstate_boost_init`, `function amd_pstate_show_perf_and_freq`.
- 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.