#include <linux/module.h>
#include <linux/slab.h>
#include <linux/perf_event.h>
#include <linux/nospec.h>
#include <asm/cpu_device_id.h>
#include <asm/intel-family.h>
#include "../perf_event.h"
#include "../probe.h"
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
#define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) …
static ssize_t cstate_get_attr_cpumask(struct device *dev,
struct device_attribute *attr,
char *buf);
struct cstate_model { … };
#define SLM_PKG_C6_USE_C7_MSR …
#define KNL_CORE_C6_MSR …
static struct pmu cstate_core_pmu;
static bool has_cstate_core;
enum perf_cstate_core_events { … };
PMU_EVENT_ATTR_STRING(c1-residency, attr_cstate_core_c1, "event=0x00");
PMU_EVENT_ATTR_STRING(c3-residency, attr_cstate_core_c3, "event=0x01");
PMU_EVENT_ATTR_STRING(c6-residency, attr_cstate_core_c6, "event=0x02");
PMU_EVENT_ATTR_STRING(c7-residency, attr_cstate_core_c7, "event=0x03");
static unsigned long core_msr_mask;
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
static bool test_msr(int idx, void *data)
{ … }
static struct perf_msr core_msr[] = …;
static struct attribute *attrs_empty[] = …;
static struct attribute_group cstate_events_attr_group = …;
DEFINE_CSTATE_FORMAT_ATTR(…);
static struct attribute *cstate_format_attrs[] = …;
static struct attribute_group cstate_format_attr_group = …;
static cpumask_t cstate_core_cpu_mask;
static DEVICE_ATTR(cpumask, S_IRUGO, cstate_get_attr_cpumask, NULL);
static struct attribute *cstate_cpumask_attrs[] = …;
static struct attribute_group cpumask_attr_group = …;
static const struct attribute_group *cstate_attr_groups[] = …;
static struct pmu cstate_pkg_pmu;
static bool has_cstate_pkg;
enum perf_cstate_pkg_events { … };
PMU_EVENT_ATTR_STRING(c2-residency, attr_cstate_pkg_c2, "event=0x00");
PMU_EVENT_ATTR_STRING(c3-residency, attr_cstate_pkg_c3, "event=0x01");
PMU_EVENT_ATTR_STRING(c6-residency, attr_cstate_pkg_c6, "event=0x02");
PMU_EVENT_ATTR_STRING(c7-residency, attr_cstate_pkg_c7, "event=0x03");
PMU_EVENT_ATTR_STRING(c8-residency, attr_cstate_pkg_c8, "event=0x04");
PMU_EVENT_ATTR_STRING(c9-residency, attr_cstate_pkg_c9, "event=0x05");
PMU_EVENT_ATTR_STRING(c10-residency, attr_cstate_pkg_c10, "event=0x06");
static unsigned long pkg_msr_mask;
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
PMU_EVENT_GROUP(…);
static struct perf_msr pkg_msr[] = …;
static cpumask_t cstate_pkg_cpu_mask;
static struct pmu cstate_module_pmu;
static bool has_cstate_module;
enum perf_cstate_module_events { … };
PMU_EVENT_ATTR_STRING(c6-residency, attr_cstate_module_c6, "event=0x00");
static unsigned long module_msr_mask;
PMU_EVENT_GROUP(…);
static struct perf_msr module_msr[] = …;
static cpumask_t cstate_module_cpu_mask;
static ssize_t cstate_get_attr_cpumask(struct device *dev,
struct device_attribute *attr,
char *buf)
{ … }
static int cstate_pmu_event_init(struct perf_event *event)
{ … }
static inline u64 cstate_pmu_read_counter(struct perf_event *event)
{ … }
static void cstate_pmu_event_update(struct perf_event *event)
{ … }
static void cstate_pmu_event_start(struct perf_event *event, int mode)
{ … }
static void cstate_pmu_event_stop(struct perf_event *event, int mode)
{ … }
static void cstate_pmu_event_del(struct perf_event *event, int mode)
{ … }
static int cstate_pmu_event_add(struct perf_event *event, int mode)
{ … }
static int cstate_cpu_exit(unsigned int cpu)
{ … }
static int cstate_cpu_init(unsigned int cpu)
{ … }
static const struct attribute_group *core_attr_update[] = …;
static const struct attribute_group *pkg_attr_update[] = …;
static const struct attribute_group *module_attr_update[] = …;
static struct pmu cstate_core_pmu = …;
static struct pmu cstate_pkg_pmu = …;
static struct pmu cstate_module_pmu = …;
static const struct cstate_model nhm_cstates __initconst = …;
static const struct cstate_model snb_cstates __initconst = …;
static const struct cstate_model hswult_cstates __initconst = …;
static const struct cstate_model cnl_cstates __initconst = …;
static const struct cstate_model icl_cstates __initconst = …;
static const struct cstate_model icx_cstates __initconst = …;
static const struct cstate_model adl_cstates __initconst = …;
static const struct cstate_model lnl_cstates __initconst = …;
static const struct cstate_model slm_cstates __initconst = …;
static const struct cstate_model knl_cstates __initconst = …;
static const struct cstate_model glm_cstates __initconst = …;
static const struct cstate_model grr_cstates __initconst = …;
static const struct cstate_model srf_cstates __initconst = …;
static const struct x86_cpu_id intel_cstates_match[] __initconst = …;
MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match);
static int __init cstate_probe(const struct cstate_model *cm)
{ … }
static inline void cstate_cleanup(void)
{ … }
static int __init cstate_init(void)
{ … }
static int __init cstate_pmu_init(void)
{ … }
module_init(…) …;
static void __exit cstate_pmu_exit(void)
{ … }
module_exit(cstate_pmu_exit);