tools/power/cpupower/utils/idle_monitor/rapl_monitor.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/idle_monitor/rapl_monitor.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/idle_monitor/rapl_monitor.c- Extension
.c- Size
- 3168 bytes
- Lines
- 149
- 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.hstdint.htime.hstring.hpci/pci.hidle_monitor/cpupower-monitor.hhelpers/helpers.hpowercap.h
Detected Declarations
function rapl_get_count_ujfunction powercap_count_zonesfunction rapl_startfunction rapl_stop
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* (C) 2016 SUSE Software Solutions GmbH
* Thomas Renninger <trenn@suse.de>
*/
#if defined(__i386__) || defined(__x86_64__)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <pci/pci.h>
#include "idle_monitor/cpupower-monitor.h"
#include "helpers/helpers.h"
#include "powercap.h"
#define MAX_RAPL_ZONES 10
int rapl_zone_count;
cstate_t rapl_zones[MAX_RAPL_ZONES];
struct powercap_zone *rapl_zones_pt[MAX_RAPL_ZONES] = { 0 };
unsigned long long rapl_zone_previous_count[MAX_RAPL_ZONES];
unsigned long long rapl_zone_current_count[MAX_RAPL_ZONES];
unsigned long long rapl_max_count;
static int rapl_get_count_uj(unsigned int id, unsigned long long *count,
unsigned int cpu)
{
if (rapl_zones_pt[id] == NULL)
/* error */
return -1;
*count = rapl_zone_current_count[id] - rapl_zone_previous_count[id];
return 0;
}
static int powercap_count_zones(struct powercap_zone *zone)
{
uint64_t val;
int uj;
if (rapl_zone_count >= MAX_RAPL_ZONES)
return -1;
if (!zone->has_energy_uj)
return 0;
printf("%s\n", zone->sys_name);
uj = powercap_get_energy_uj(zone, &val);
printf("%d\n", uj);
strncpy(rapl_zones[rapl_zone_count].name, zone->name, CSTATE_NAME_LEN - 1);
strcpy(rapl_zones[rapl_zone_count].desc, "");
rapl_zones[rapl_zone_count].id = rapl_zone_count;
rapl_zones[rapl_zone_count].range = RANGE_MACHINE;
rapl_zones[rapl_zone_count].get_count = rapl_get_count_uj;
rapl_zones_pt[rapl_zone_count] = zone;
rapl_zone_count++;
return 0;
}
static int rapl_start(void)
{
int i, ret;
uint64_t uj_val;
for (i = 0; i < rapl_zone_count; i++) {
ret = powercap_get_energy_uj(rapl_zones_pt[i], &uj_val);
if (ret)
return ret;
rapl_zone_previous_count[i] = uj_val;
}
return 0;
}
static int rapl_stop(void)
{
int i;
uint64_t uj_val;
for (i = 0; i < rapl_zone_count; i++) {
int ret;
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `stdint.h`, `time.h`, `string.h`, `pci/pci.h`, `idle_monitor/cpupower-monitor.h`, `helpers/helpers.h`.
- Detected declarations: `function rapl_get_count_uj`, `function powercap_count_zones`, `function rapl_start`, `function rapl_stop`.
- 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.