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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/* $NetBSD: tprof_armv8.c,v 1.1 2018/07/15 16:25:31 jmcneill Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <dev/tprof/tprof_ioctl.h>
#include "../tprof.h"
struct pmu_event {
uint16_t event;
const char *name;
};
struct pmu_event_table {
const char *name;
struct pmu_event *events;
u_int nevents;
struct pmu_event_table *next;
};
/*
* Common event numbers, from ARMv8 ARM.
*/
static struct pmu_event pmu_armv8_common_events[] = {
{ 0x0000, "SW_INCR" },
{ 0x0001, "L1I_CACHE_REFILL" },
{ 0x0002, "L1I_TLB_REFILL" },
{ 0x0003, "L1D_CACHE_REFILL" },
{ 0x0004, "L1D_CACHE" },
{ 0x0005, "L1D_TLB_REFILL" },
{ 0x0006, "LD_RETIRED" },
{ 0x0007, "ST_RETIRED" },
{ 0x0008, "INST_RETIRED" },
{ 0x0009, "EXC_TAKEN" },
{ 0x000a, "EXC_RETURN" },
{ 0x000b, "CID_WRITE_RETIRED" },
{ 0x000c, "PC_WRITE_RETIRED" },
{ 0x000d, "BR_IMMED_RETIRED" },
{ 0x000e, "BR_RETURN_RETIRED" },
{ 0x000f, "UNALIGNED_LDST_RETIRED" },
{ 0x0010, "BR_MIS_PRED" },
{ 0x0011, "CPU_CYCLES" },
{ 0x0012, "BR_PRED" },
{ 0x0013, "MEM_ACCESS" },
{ 0x0014, "L1I_CACHE" },
{ 0x0015, "L1D_CACHE_WB" },
{ 0x0016, "L2D_CACHE" },
{ 0x0017, "L2D_CACHE_REFILL" },
{ 0x0018, "L2D_CACHE_WB" },
{ 0x0019, "BUS_ACCESS" },
{ 0x001a, "MEMORY_ERROR" },
{ 0x001b, "INST_SPEC" },
{ 0x001c, "TTBR_WRITE_RETIRED" },
{ 0x001d, "BUS_CYCLES" },
{ 0x001e, "CHAIN" },
{ 0x001f, "L1D_CACHE_ALLOCATE" },
{ 0x0020, "L2D_CACHE_ALLOCATE" },
{ 0x0021, "BR_RETIRED" },
{ 0x0022, "BR_MIS_PRED_RETIRED" },
{ 0x0023, "STALL_FRONTEND" },
{ 0x0024, "STALL_BACKEND" },
{ 0x0025, "L1D_TLB" },
{ 0x0026, "L1I_TLB" },
{ 0x0027, "L2I_CACHE" },
{ 0x0028, "L2I_CACHE_REFILL" },
{ 0x0029, "L3D_CACHE_ALLOCATE" },
{ 0x002a, "L3D_CACHE_REFILL" },
{ 0x002b, "L3D_CACHE" },
{ 0x002c, "L3D_CACHE_WB" },
{ 0x002d, "L2D_TLB_REFILL" },
{ 0x002e, "L2I_TLB_REFILL" },
{ 0x002f, "L2D_TLB" },
{ 0x0030, "L2I_TLB" },
{ 0x0031, "REMOTE_ACCESS" },
{ 0x0032, "LL_CACHE" },
{ 0x0033, "LL_CACHE_MISS" },
{ 0x0034, "DTLB_WALK" },
{ 0x0035, "ITLB_WALK" },
{ 0x0036, "LL_CACHE_RD" },
{ 0x0037, "LL_CACHE_MISS_RD" },
{ 0x0038, "REMOTE_ACCESS_RD" },
};
static struct pmu_event_table pmu_armv8 = {
.name = "ARMv8 common architectural and microarchitectural events",
.events = pmu_armv8_common_events,
.nevents = __arraycount(pmu_armv8_common_events),
.next = NULL
};
static struct pmu_event_table *events = NULL;
int
tprof_event_init(uint32_t ident)
{
if (ident != TPROF_IDENT_ARMV8_GENERIC)
return -1;
events = &pmu_armv8;
return 0;
}
static void
tprof_event_list_table(struct pmu_event_table *tbl)
{
u_int n;
printf("%s:\n", tbl->name);
for (n = 0; n < tbl->nevents; n++) {
printf("\t%s\n", tbl->events[n].name);
}
if (tbl->next)
tprof_event_list_table(tbl->next);
}
void
tprof_event_list(void)
{
tprof_event_list_table(events);
}
static void
tprof_event_lookup_table(const char *name, struct tprof_param *param,
struct pmu_event_table *tbl)
{
u_int n;
for (n = 0; n < tbl->nevents; n++) {
if (strcmp(tbl->events[n].name, name) == 0) {
param->p_event = tbl->events[n].event;
param->p_unit = 0;
return;
}
}
if (tbl->next)
tprof_event_lookup_table(name, param, tbl->next);
else
errx(EXIT_FAILURE, "event '%s' unknown", name);
}
void
tprof_event_lookup(const char *name, struct tprof_param *param)
{
tprof_event_lookup_table(name, param, events);
}
|