tools/power/cpupower/utils/idle_monitor/nhm_idle.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/idle_monitor/nhm_idle.c- Extension
.c- Size
- 4907 bytes
- Lines
- 216
- 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.hstdint.hstdlib.hstring.hhelpers/helpers.hidle_monitor/cpupower-monitor.h
Detected Declarations
enum intel_nhm_idfunction nhm_get_countfunction nhm_get_count_percentfunction nhm_startfunction nhm_stopfunction intel_nhm_unregister
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
*
* Based on Len Brown's <lenb@kernel.org> turbostat tool.
*/
#if defined(__i386__) || defined(__x86_64__)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/helpers.h"
#include "idle_monitor/cpupower-monitor.h"
#define MSR_PKG_C3_RESIDENCY 0x3F8
#define MSR_PKG_C6_RESIDENCY 0x3F9
#define MSR_CORE_C3_RESIDENCY 0x3FC
#define MSR_CORE_C6_RESIDENCY 0x3FD
#define MSR_TSC 0x10
#define NHM_CSTATE_COUNT 4
enum intel_nhm_id { C3 = 0, C6, PC3, PC6, TSC = 0xFFFF };
static int nhm_get_count_percent(unsigned int self_id, double *percent,
unsigned int cpu);
static cstate_t nhm_cstates[NHM_CSTATE_COUNT] = {
{
.name = "C3",
.desc = N_("Processor Core C3"),
.id = C3,
.range = RANGE_CORE,
.get_count_percent = nhm_get_count_percent,
},
{
.name = "C6",
.desc = N_("Processor Core C6"),
.id = C6,
.range = RANGE_CORE,
.get_count_percent = nhm_get_count_percent,
},
{
.name = "PC3",
.desc = N_("Processor Package C3"),
.id = PC3,
.range = RANGE_PACKAGE,
.get_count_percent = nhm_get_count_percent,
},
{
.name = "PC6",
.desc = N_("Processor Package C6"),
.id = PC6,
.range = RANGE_PACKAGE,
.get_count_percent = nhm_get_count_percent,
},
};
static unsigned long long tsc_at_measure_start;
static unsigned long long tsc_at_measure_end;
static unsigned long long *previous_count[NHM_CSTATE_COUNT];
static unsigned long long *current_count[NHM_CSTATE_COUNT];
/* valid flag for all CPUs. If a MSR read failed it will be zero */
static int *is_valid;
static int nhm_get_count(enum intel_nhm_id id, unsigned long long *val,
unsigned int cpu)
{
int msr;
switch (id) {
case C3:
msr = MSR_CORE_C3_RESIDENCY;
break;
case C6:
msr = MSR_CORE_C6_RESIDENCY;
break;
case PC3:
msr = MSR_PKG_C3_RESIDENCY;
break;
case PC6:
msr = MSR_PKG_C6_RESIDENCY;
break;
case TSC:
msr = MSR_TSC;
Annotation
- Immediate include surface: `stdio.h`, `stdint.h`, `stdlib.h`, `string.h`, `helpers/helpers.h`, `idle_monitor/cpupower-monitor.h`.
- Detected declarations: `enum intel_nhm_id`, `function nhm_get_count`, `function nhm_get_count_percent`, `function nhm_start`, `function nhm_stop`, `function intel_nhm_unregister`.
- 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.