cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

pmu.h (4727B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef __PMU_H
      3#define __PMU_H
      4
      5#include <linux/bitmap.h>
      6#include <linux/compiler.h>
      7#include <linux/perf_event.h>
      8#include <linux/list.h>
      9#include <stdbool.h>
     10#include "parse-events.h"
     11#include "pmu-events/pmu-events.h"
     12
     13struct evsel_config_term;
     14struct perf_cpu_map;
     15
     16enum {
     17	PERF_PMU_FORMAT_VALUE_CONFIG,
     18	PERF_PMU_FORMAT_VALUE_CONFIG1,
     19	PERF_PMU_FORMAT_VALUE_CONFIG2,
     20};
     21
     22#define PERF_PMU_FORMAT_BITS 64
     23#define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
     24#define CPUS_TEMPLATE_CPU	"%s/bus/event_source/devices/%s/cpus"
     25#define MAX_PMU_NAME_LEN 128
     26
     27struct perf_event_attr;
     28
     29struct perf_pmu_caps {
     30	char *name;
     31	char *value;
     32	struct list_head list;
     33};
     34
     35struct perf_pmu {
     36	char *name;
     37	char *alias_name;
     38	char *id;
     39	__u32 type;
     40	bool selectable;
     41	bool is_uncore;
     42	bool is_hybrid;
     43	bool auxtrace;
     44	int max_precise;
     45	struct perf_event_attr *default_config;
     46	struct perf_cpu_map *cpus;
     47	struct list_head format;  /* HEAD struct perf_pmu_format -> list */
     48	struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */
     49	struct list_head caps;    /* HEAD struct perf_pmu_caps -> list */
     50	struct list_head list;    /* ELEM */
     51	struct list_head hybrid_list;
     52
     53	struct {
     54		bool exclude_guest;
     55	} missing_features;
     56};
     57
     58extern struct perf_pmu perf_pmu__fake;
     59
     60struct perf_pmu_info {
     61	const char *unit;
     62	const char *metric_expr;
     63	const char *metric_name;
     64	double scale;
     65	bool per_pkg;
     66	bool snapshot;
     67};
     68
     69#define UNIT_MAX_LEN	31 /* max length for event unit name */
     70
     71struct perf_pmu_alias {
     72	char *name;
     73	char *desc;
     74	char *long_desc;
     75	char *topic;
     76	char *str;
     77	struct list_head terms; /* HEAD struct parse_events_term -> list */
     78	struct list_head list;  /* ELEM */
     79	char unit[UNIT_MAX_LEN+1];
     80	double scale;
     81	bool per_pkg;
     82	bool snapshot;
     83	bool deprecated;
     84	char *metric_expr;
     85	char *metric_name;
     86	char *pmu_name;
     87};
     88
     89struct perf_pmu *perf_pmu__find(const char *name);
     90struct perf_pmu *perf_pmu__find_by_type(unsigned int type);
     91void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu);
     92int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
     93		     struct list_head *head_terms,
     94		     struct parse_events_error *error);
     95int perf_pmu__config_terms(const char *pmu_name, struct list_head *formats,
     96			   struct perf_event_attr *attr,
     97			   struct list_head *head_terms,
     98			   bool zero, struct parse_events_error *error);
     99__u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
    100int perf_pmu__format_type(struct list_head *formats, const char *name);
    101int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
    102			  struct perf_pmu_info *info);
    103struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
    104				  struct list_head *head_terms);
    105void perf_pmu_error(struct list_head *list, char *name, char const *msg);
    106
    107int perf_pmu__new_format(struct list_head *list, char *name,
    108			 int config, unsigned long *bits);
    109void perf_pmu__set_format(unsigned long *bits, long from, long to);
    110int perf_pmu__format_parse(char *dir, struct list_head *head);
    111void perf_pmu__del_formats(struct list_head *formats);
    112
    113struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
    114
    115bool is_pmu_core(const char *name);
    116void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
    117		      bool long_desc, bool details_flag,
    118		      bool deprecated, const char *pmu_name);
    119bool pmu_have_event(const char *pname, const char *name);
    120
    121int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
    122
    123int perf_pmu__test(void);
    124
    125struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
    126void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
    127			     const struct pmu_events_map *map);
    128
    129const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu);
    130const struct pmu_events_map *pmu_events_map__find(void);
    131bool pmu_uncore_alias_match(const char *pmu_name, const char *name);
    132void perf_pmu_free_alias(struct perf_pmu_alias *alias);
    133
    134typedef int (*pmu_sys_event_iter_fn)(const struct pmu_event *pe, void *data);
    135void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data);
    136int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
    137
    138int perf_pmu__caps_parse(struct perf_pmu *pmu);
    139
    140void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
    141				   const char *name);
    142
    143bool perf_pmu__has_hybrid(void);
    144int perf_pmu__match(char *pattern, char *name, char *tok);
    145
    146int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus,
    147			 struct perf_cpu_map **mcpus_ptr,
    148			 struct perf_cpu_map **ucpus_ptr);
    149
    150char *pmu_find_real_name(const char *name);
    151char *pmu_find_alias_name(const char *name);
    152#endif /* __PMU_H */