-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpmu.h
More file actions
130 lines (106 loc) · 4.11 KB
/
Copy pathpmu.h
File metadata and controls
130 lines (106 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2026 MoatLab, Virginia Tech. */
#ifndef PACT_PMU_H
#define PACT_PMU_H
#include <stdint.h>
#include <sys/types.h>
#include <linux/perf_event.h>
#include "minicoro.h"
#include "ring-buffer.h"
#include "pmu-platform.h"
typedef struct pact_context pact_context_t;
#define PAGE_SHIFT 12
#define PAGE_SIZE (1UL << PAGE_SHIFT)
/* page mask assuming 57-bit virtual address space */
#define VADDR_MASK ((1UL << 57) - 1)
#define PAGE_MASK ((~(PAGE_SIZE - 1)) & VADDR_MASK)
#define PERF_BUFFER_PAGES 512
#define MAX_CHAS 64 /* Maximum number of CHAs we expect to find */
typedef struct event_group {
int counters_used; /* number of counters used in each group */
int fds[4];
uint64_t ids[4]; /* IDs for read_format */
uint64_t values[4]; /* values read from the counters */
uint64_t time_enabled;
uint64_t time_running;
uint64_t last_time_enabled;
uint64_t last_time_running;
} event_group_t;
typedef struct cha_pmu_info {
int cha_id;
int pmu_type;
int core_id; /* CPU core associated with this CHA */
char device_name[64];
/* we have two groups for now */
event_group_t group_fast;
event_group_t group_slow;
} cha_pmu_info_t;
/* Event indices for core/thread counting events */
typedef enum {
CORE_EVENT_LLC_MISS_FAST = 0,
CORE_EVENT_LLC_MISS_SLOW,
CORE_EVENT_COUNT /* Total number of core counting events */
} core_event_index_t;
/* CHA TOR event indices */
typedef enum {
CHA_TOR_OCCUPANCY = 0,
CHA_TOR_CYCLES,
CHA_EVENT_COUNT /* Total number of CHA TOR events per tier */
} cha_event_index_t;
/* Event configuration for mapping enum to hardware config */
typedef struct event_config {
uint64_t config;
const char *name;
} event_config_t;
/* Structure for reading grouped PMU events */
typedef struct read_format {
uint64_t nr;
uint64_t time_enabled;
uint64_t time_running;
struct {
uint64_t value;
uint64_t id;
} values[];
} read_format_t;
typedef struct perf_event {
int fd;
uint64_t id;
uint64_t value;
uint64_t time_enabled;
uint64_t time_running;
} perf_event_t;
/* Per-CPU sampling state */
typedef struct per_cpu_state {
int cpu_id;
perf_event_t leader; /* dummy group leader owning the perf mmap */
/* we don't need ids and values for pebs, no need to use perf_event_t for now */
int fd_pebs; /* PEBS file descriptor */
uint64_t pebs_sampling_period;
void *pebs_mmap; /* PEBS buffer */
} per_cpu_state_t;
int validate_hardware_access(void);
long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd,
unsigned long flags);
int discover_cha_pmus(cha_pmu_info_t *cha_pmus, int *nr_cha, uint64_t cpu_mask);
int setup_dummy_leader_event(perf_event_t *perf_event, pid_t pid, int cpu);
int setup_pebs_event(per_cpu_state_t *cpu_state, pid_t pid, int cpu);
/* Event configuration table - populated by pmu_platform_init() */
extern event_config_t core_event_configs[CORE_EVENT_COUNT];
int setup_counting_event(perf_event_t *perf_event, pid_t pid, int cpu, perf_event_t *leader,
uint64_t config, const char *name);
void ioctl_pmu_cha_perf_events(cha_pmu_info_t *cha_pmus, int nr_cha, int request);
void ioctl_pmu_core_perf_events(per_cpu_state_t *cpu_states, int nr_target_cpus, int request);
void start_pmu_perf_events(pact_context_t *ctx);
void stop_pmu_perf_events(pact_context_t *ctx);
int setup_pmu_cha_perf_events(cha_pmu_info_t *cha_pmus, int *nr_cha); /* tor_occ + tor_cyc */
int setup_tor_events(event_group_t *event_group, int pmu_type, int tier, int core_id);
void read_pmu_cha_perf_events(cha_pmu_info_t *cha_pmus, int nr_cha);
int read_pmu_event_group(event_group_t *event_group);
void scale_multiplexed_events(event_group_t *event_group);
void read_pmu_counting_events(pact_context_t *ctx);
/* Open per-workload counting events (LLC misses) with pid=target_pid,
* cpu=-1, inherit=1, mmap=0. Single fd per event; the kernel attributes
* across all child threads automatically. */
struct pact_workload;
void setup_workload_counting_events(struct pact_workload *wl);
#endif