summaryrefslogtreecommitdiff
path: root/sys/dev/dt/dt_prov_static.c
blob: 05828f036ffb65e18d37bc310892f7eca624fb8d (plain)
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
/*	$OpenBSD: dt_prov_static.c,v 1.8 2021/06/07 13:55:54 dv Exp $ */

/*
 * Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
#include <sys/tracepoint.h>

#include <dev/dt/dtvar.h>

int	dt_prov_static_alloc(struct dt_probe *, struct dt_softc *,
	    struct dt_pcb_list *, struct dtioc_req *);
void	dt_prov_static_hook(struct dt_provider *, ...);

struct dt_provider dt_prov_static = {
	.dtpv_name = "tracepoint",
	.dtpv_alloc = dt_prov_static_alloc,
	.dtpv_enter = dt_prov_static_hook,
};

/*
 * Scheduler
 */
DT_STATIC_PROBE2(sched, dequeue, "pid_t", "pid_t");
DT_STATIC_PROBE2(sched, enqueue, "pid_t", "pid_t");
DT_STATIC_PROBE2(sched, off__cpu, "pid_t", "pid_t");
DT_STATIC_PROBE0(sched, on__cpu);
DT_STATIC_PROBE0(sched, remain__cpu);
DT_STATIC_PROBE0(sched, sleep);
DT_STATIC_PROBE0(sched, wakeup);

/*
 * Raw syscalls
 */
DT_STATIC_PROBE1(raw_syscalls, sys_enter, "register_t");
DT_STATIC_PROBE1(raw_syscalls, sys_exit, "register_t");

/*
 * UVM
 */
DT_STATIC_PROBE3(uvm, fault, "vaddr_t", "vm_fault_t", "vm_prot_t");
DT_STATIC_PROBE3(uvm, map_insert, "vaddr_t", "vaddr_t", "vm_prot_t");
DT_STATIC_PROBE3(uvm, map_remove, "vaddr_t", "vaddr_t", "vm_prot_t");
DT_STATIC_PROBE4(uvm, malloc, "int", "void *", "size_t", "int");
DT_STATIC_PROBE3(uvm, free, "int", "void *", "size_t");
DT_STATIC_PROBE3(uvm, pool_get, "void *", "void *", "int");
DT_STATIC_PROBE2(uvm, pool_put, "void *", "void *");

/*
 * VFS
 */
DT_STATIC_PROBE3(vfs, bufcache_rel, "long", "int", "int64_t");
DT_STATIC_PROBE3(vfs, bufcache_take, "long", "int", "int64_t");
DT_STATIC_PROBE4(vfs, cleaner, "long", "int", "long", "long");

/*
 * VMM
 */
DT_STATIC_PROBE2(vmm, guest_enter, "void *", "void *");
DT_STATIC_PROBE3(vmm, guest_exit, "void *", "void *", "uint64_t");

/*
 * List of all static probes
 */
struct dt_probe *dtps_static[] = {
	/* Scheduler */
	&_DT_STATIC_P(sched, dequeue),
	&_DT_STATIC_P(sched, enqueue),
	&_DT_STATIC_P(sched, off__cpu),
	&_DT_STATIC_P(sched, on__cpu),
	&_DT_STATIC_P(sched, remain__cpu),
	&_DT_STATIC_P(sched, sleep),
	&_DT_STATIC_P(sched, wakeup),
	/* Raw syscalls */
	&_DT_STATIC_P(raw_syscalls, sys_enter),
	&_DT_STATIC_P(raw_syscalls, sys_exit),
	/* UVM */
	&_DT_STATIC_P(uvm, fault),
	&_DT_STATIC_P(uvm, map_insert),
	&_DT_STATIC_P(uvm, map_remove),
	&_DT_STATIC_P(uvm, malloc),
	&_DT_STATIC_P(uvm, free),
	&_DT_STATIC_P(uvm, pool_get),
	&_DT_STATIC_P(uvm, pool_put),
	/* VFS */
	&_DT_STATIC_P(vfs, bufcache_rel),
	&_DT_STATIC_P(vfs, bufcache_take),
	&_DT_STATIC_P(vfs, cleaner),
	/* VMM */
	&_DT_STATIC_P(vmm, guest_enter),
	&_DT_STATIC_P(vmm, guest_exit),
};

int
dt_prov_static_init(void)
{
	int i;

	for (i = 0; i < nitems(dtps_static); i++)
		dt_dev_register_probe(dtps_static[i]);

	return i;
}

int
dt_prov_static_alloc(struct dt_probe *dtp, struct dt_softc *sc,
    struct dt_pcb_list *plist, struct dtioc_req *dtrq)
{
	struct dt_pcb *dp;

	KASSERT(dtioc_req_isvalid(dtrq));
	KASSERT(TAILQ_EMPTY(plist));

	dp = dt_pcb_alloc(dtp, sc);
	if (dp == NULL)
		return ENOMEM;

	dp->dp_filter = dtrq->dtrq_filter;
	dp->dp_evtflags = dtrq->dtrq_evtflags;
	TAILQ_INSERT_HEAD(plist, dp, dp_snext);

	return 0;
}

void
dt_prov_static_hook(struct dt_provider *dtpv, ...)
{
	struct dt_probe *dtp;
	struct dt_pcb *dp;
	uintptr_t args[5];
	va_list ap;
	int i;

	va_start(ap, dtpv);
	dtp = va_arg(ap, struct dt_probe *);
	for (i = 0; i < dtp->dtp_nargs; i++) {
		args[i] = va_arg(ap, uintptr_t);
	}
	va_end(ap);

	KASSERT(dtpv == dtp->dtp_prov);

	smr_read_enter();
	SMR_SLIST_FOREACH(dp, &dtp->dtp_pcbs, dp_pnext) {
		struct dt_evt *dtev;

		dtev = dt_pcb_ring_get(dp, 0);
		if (dtev == NULL)
			continue;

		dtev->dtev_sysargs[0] = args[0];
		dtev->dtev_sysargs[1] = args[1];
		dtev->dtev_sysargs[2] = args[2];
		dtev->dtev_sysargs[3] = args[3];
		dtev->dtev_sysargs[4] = args[4];

		dt_pcb_ring_consume(dp, dtev);
	}
	smr_read_leave();
}