linux/arch/x86/events/amd/power.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Performance events - AMD Processor Power Reporting Mechanism
 *
 * Copyright (C) 2016 Advanced Micro Devices, Inc.
 *
 * Author: Huang Rui <[email protected]>
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/perf_event.h>
#include <asm/cpu_device_id.h>
#include "../perf_event.h"

/* Event code: LSB 8 bits, passed in attr->config any other bit is reserved. */
#define AMD_POWER_EVENT_MASK

/*
 * Accumulated power status counters.
 */
#define AMD_POWER_EVENTSEL_PKG

/*
 * The ratio of compute unit power accumulator sample period to the
 * PTSC period.
 */
static unsigned int cpu_pwr_sample_ratio;

/* Maximum accumulated power of a compute unit. */
static u64 max_cu_acc_power;

static struct pmu pmu_class;

/*
 * Accumulated power represents the sum of each compute unit's (CU) power
 * consumption. On any core of each CU we read the total accumulated power from
 * MSR_F15H_CU_PWR_ACCUMULATOR. cpu_mask represents CPU bit map of all cores
 * which are picked to measure the power for the CUs they belong to.
 */
static cpumask_t cpu_mask;

static void event_update(struct perf_event *event)
{}

static void __pmu_event_start(struct perf_event *event)
{}

static void pmu_event_start(struct perf_event *event, int mode)
{}

static void pmu_event_stop(struct perf_event *event, int mode)
{}

static int pmu_event_add(struct perf_event *event, int mode)
{}

static void pmu_event_del(struct perf_event *event, int flags)
{}

static int pmu_event_init(struct perf_event *event)
{}

static void pmu_event_read(struct perf_event *event)
{}

static ssize_t
get_attr_cpumask(struct device *dev, struct device_attribute *attr, char *buf)
{}

static DEVICE_ATTR(cpumask, S_IRUGO, get_attr_cpumask, NULL);

static struct attribute *pmu_attrs[] =;

static struct attribute_group pmu_attr_group =;

/*
 * Currently it only supports to report the power of each
 * processor/package.
 */
EVENT_ATTR_STR(power-pkg, power_pkg, "event=0x01");

EVENT_ATTR_STR(power-pkg.unit, power_pkg_unit, "mWatts");

/* Convert the count from micro-Watts to milli-Watts. */
EVENT_ATTR_STR(power-pkg.scale, power_pkg_scale, "1.000000e-3");

static struct attribute *events_attr[] =;

static struct attribute_group pmu_events_group =;

PMU_FORMAT_ATTR();

static struct attribute *formats_attr[] =;

static struct attribute_group pmu_format_group =;

static const struct attribute_group *attr_groups[] =;

static struct pmu pmu_class =;

static int power_cpu_exit(unsigned int cpu)
{}

static int power_cpu_init(unsigned int cpu)
{}

static const struct x86_cpu_id cpu_match[] =;

static int __init amd_power_pmu_init(void)
{}
module_init();

static void __exit amd_power_pmu_exit(void)
{}
module_exit(amd_power_pmu_exit);

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();