tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c

Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c

File Facts

System
Linux kernel
Corpus path
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
Extension
.c
Size
8630 bytes
Lines
335
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 *  (C) 2010,2011      Thomas Renninger <trenn@suse.de>, Novell Inc.
 *
 *  PCI initialization based on example code from:
 *  Andreas Herrmann <andreas.herrmann3@amd.com>
 */

#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"

#define PCI_NON_PC0_OFFSET	0xb0
#define PCI_PC1_OFFSET		0xb4
#define PCI_PC6_OFFSET		0xb8

#define PCI_MONITOR_ENABLE_REG  0xe0

#define PCI_NON_PC0_ENABLE_BIT	0
#define PCI_PC1_ENABLE_BIT	1
#define PCI_PC6_ENABLE_BIT	2

#define PCI_NBP1_STAT_OFFSET	0x98
#define PCI_NBP1_ACTIVE_BIT	2
#define PCI_NBP1_ENTERED_BIT	1

#define PCI_NBP1_CAP_OFFSET	0x90
#define PCI_NBP1_CAPABLE_BIT    31

#define OVERFLOW_MS		343597 /* 32 bit register filled at 12500 HZ
					  (1 tick per 80ns) */

enum amd_fam14h_states {NON_PC0 = 0, PC1, PC6, NBP1,
			AMD_FAM14H_STATE_NUM};

static int fam14h_get_count_percent(unsigned int self_id, double *percent,
				    unsigned int cpu);
static int fam14h_nbp1_count(unsigned int id, unsigned long long *count,
			     unsigned int cpu);

static cstate_t amd_fam14h_cstates[AMD_FAM14H_STATE_NUM] = {
	{
		.name			= "!PC0",
		.desc			= N_("Package in sleep state (PC1 or deeper)"),
		.id			= NON_PC0,
		.range			= RANGE_PACKAGE,
		.get_count_percent	= fam14h_get_count_percent,
	},
	{
		.name			= "PC1",
		.desc			= N_("Processor Package C1"),
		.id			= PC1,
		.range			= RANGE_PACKAGE,
		.get_count_percent	= fam14h_get_count_percent,
	},
	{
		.name			= "PC6",
		.desc			= N_("Processor Package C6"),
		.id			= PC6,
		.range			= RANGE_PACKAGE,
		.get_count_percent	= fam14h_get_count_percent,
	},
	{
		.name			= "NBP1",
		.desc			= N_("North Bridge P1 boolean counter (returns 0 or 1)"),
		.id			= NBP1,
		.range			= RANGE_PACKAGE,
		.get_count		= fam14h_nbp1_count,
	},
};

static struct pci_access *pci_acc;
static struct pci_dev *amd_fam14h_pci_dev;
static int nbp1_entered;

static struct timespec start_time;
static unsigned long long timediff;

#ifdef DEBUG
struct timespec dbg_time;
long dbg_timediff;

Annotation

Implementation Notes