summaryrefslogtreecommitdiff
path: root/static/freebsd/man4/hwt.4
blob: 299332c72542a9a1c48341bb3707f3cef29ffdbd (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
.\"
.\" Copyright (c) 2025 Ruslan Bukin <br@bsdpad.com>
.\"
.\" SPDX-License-Identifier: BSD-2-Clause
.\"
.Dd July 12, 2025
.Dt HWT 4
.Os
.Sh NAME
.Nm hwt
.Nd Hardware Trace Framework
.Sh SYNOPSIS
.Cd "options HWT_HOOKS"
.Cd "device hwt"
.Pp
At least one of:
.Cd "device intel_pt"
.Pq amd64
.Cd "device coresight"
.Pq arm64
.Cd "device spe"
.Pq arm64
.Pp
In
.Xr rc.conf 5 :
.Cd kld_list="hwt"
.Sh DESCRIPTION
The
.Nm
framework provides infrastructure for hardware-assisted tracing.
It collects detailed information about software execution and stores it as
events in highly compressed format into DRAM.
The events cover information about control flow changes of a program, whether
branches taken or not, exceptions taken, timing information, cycles elapsed and
more.
The information collected allows to reconstruct entire program flow of a given
application without noticeable performance impact.
.Sh HARDWARE
The framework supports several tracing technologies found on
.Cd arm64
and
.Cd amd64
systems:
.Pp
.Bl -bullet -compact
.It
ARM Coresight
.It
ARM Statistical Profiling Extension (SPE)
.It
Intel Processor Trace (PT)
.El
.Pp
The
.Nm
framework supports two modes of operation:
.Bl -tag -width "Thread mode"
.It Em CPU mode
Capture CPU activity in kernel mode.
.It Em Thread mode
Capture activity of each of a process's threads in user mode.
.El
.Sh MANAGEMENT
When loaded into kernel, the
.Nm
framework provides
.Pa /dev/hwt
character device.
The only
.Xr ioctl 2
request it accepts is
.Dv HWT_IOC_ALLOC .
This request allocates kernel tracing context (CTX) based on requested mode of
operation, set of CPUs and/or pid.
.Pp
Upon successful CTX allocation, the ioctl returns a CTX identification
number (ident).
.Pp
Each CTX is then managed using its own dedicated character device found at
.Pa "/dev/hwt_${ident}_${d}",
where ident is a unique identification number of tracing context, d is either
cpu_id (in HWT CPU mode) or process pid (in HWT Thread mode).
.Sh HOOKS
During tracing of a target process, HWT records runtime events such as threads
creation, exec and mmap system calls.
These events are logged as "records" within a particular CTX associated with
traced process.
.Pp
Additionally, HWT can suspend the target thread upon exec or mmap system calls
if requested by the user.
This pause allows user-space tools to retrieve the records and adjust tracing
settings before execution continues.
This feature is especially useful when address range filtering is enabled,
allowing tracing of specific functions within the target executable or a
dynamic library.
.Sh KERNEL OPTIONS
The following options in the kernel configuration file are mandatory and
related to
.Nm
operation:
.Pp
.Bl -tag -width ".Dv HWT_HOOKS" -compact
.It Dv HWT_HOOKS
Enable kernel hooks.
.El
.Sh IOCTL INTERFACE
Once a CTX is allocated, its management character device accepts several
.Xr ioctl 2
requests:
.Bl -tag -width "HWT_IOC_RECORD_GET"
.It Dv HWT_IOC_START
Start tracing.
In HWT CPU mode the tracing does actually start with this
.Xr ioctl 2
request.
In the Thread mode, the tracing "running" flag set, but tracing begins after
scheduler switches the target thread onto CPU and return to user mode.
.It Dv HWT_IOC_STOP
Stop tracing of the particular CTX.
.It Dv HWT_IOC_RECORD_GET
Copy all or part of records collected during hook invocation and associated
with this CTX to userspace.
.It Dv HWT_IOC_BUFPTR_GET
Get current pointer in buffer that is filled by tracing units in real-time.
.It Dv HWT_IOC_SET_CONFIG
Set architecture-specific config (optional).
.It Dv HWT_IOC_WAKEUP
Wake up a thread that has been put to sleep by HWT framework hooks.
.It Dv HWT_IOC_SVC_BUF
For SPE-only, the kernel is waiting for userspace to notify that it has copied
out a buffer to avoid data loss/overwriting buffers.
.El
.Sh SEE ALSO
.Xr tracing 7 ,
.Xr hwt 8
.Sh HISTORY
The
.Nm
framework first appeared in
.Fx 15.0 .
.Sh AUTHORS
.An Ruslan Bukin Aq Mt br@FreeBSD.org
.An Bojan Novković Aq Mt bnovkov@freebsd.org
.An Zachary Leaf Aq Mt zachary.leaf@arm.com