From nobody Wed Jul 9 16:00:06 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bcjNk5FSCz60c9H; Wed, 09 Jul 2025 16:00:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bcjNk33Ggz3n39; Wed, 09 Jul 2025 16:00:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752076806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cqy+XS4n6RL7eDR8af6928wUYtRglh8vM+ZBV36a+Qo=; b=NG2fHHPfSakCOVz4BYWU/MgBVgogrwjrqw6oQkJA4Jh7ineMnvofV9tWFw3mfdZnpca3p0 cA5CGRABOX7USRsjs7Tp3xavOa52B+p6JCQGcHL1ag3pxk2ptRuQmGjnP4Fw9IKEerdKVx X+/Q45oBw6S8v76WJyZEt75K/6EXM4A2d2dju0SNdZUNmdb87yVLqcPwUTQ8aoXOt4DmPK c0F3FCKlvP3eTzNLbN2tz0iIqquTRCqUq4HtEfseRKzVMbTjZBcIToWiRwieUSvQrV+S/a b38jyl2qED05/cGvRwfBjBFhNNCxi653/nDiP+hwtTGM8GFwWXfMd8yp5rRisw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752076806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cqy+XS4n6RL7eDR8af6928wUYtRglh8vM+ZBV36a+Qo=; b=r/tCdSM0eG88Siv6FH0dXKT4C1yt3Kse8RRxGIShxfrDGj5rFdLRv6UvpcTUd5C+tD1kdS 0xya/W5zCZ3hSKy6Qn/WAjqM4GfVrIQurHztHot67vmCjVAkFAAAuevg9MElyOipVttU51 vflHNnVuTI7GK/gEDSbO8feNqkWafRlgifKlZypjeXOptBL6+urb7rOiCqepuOKX3WldOX iC+Gw9TvZAHB3VUxyirB6doEyxN1tH+9fx71jVkTRrMWAvUHyZ7uptdUUdGsiW8eXNYbPF AmTVWePq0C89u/oaeqqB66xy/G0sBca6PCNDecQJA5GliY+2D4oo7Hice56Zkg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752076806; a=rsa-sha256; cv=none; b=BRmxHFuYeSfg5Fw65V+DZJGZHJFD0HPdIqLv9n2z+OpakgGV4pNX0mdlCQ1idU0K4iPZtg wGbUUhMZ7sMdCwClHuNZndGf6u8tHLDoMJXNczEJhMS5PWRq0xU1BbqGkHyGc8iYhCXUHZ GPVkL0bf+i1AR5WneafcxEKuXLtvXMScqqrjfmE2naY/MUW4KJDaU1n/oQUqQOz7h3+GSC dnCwQU6x47pwTenii1Tygq35+blbRGOYAOIo2P/JM5Pzfa0agoSXaIHe60UDAFo4mbMWA9 miH5dWV80Nl94DInhrsQrSShe9T4HzqQxZf5puFKHwn0L/mZD43xmYmo07R06Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bcjNk225JzCgk; Wed, 09 Jul 2025 16:00:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 569G06tX042242; Wed, 9 Jul 2025 16:00:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 569G06jc042237; Wed, 9 Jul 2025 16:00:06 GMT (envelope-from git) Date: Wed, 9 Jul 2025 16:00:06 GMT Message-Id: <202507091600.569G06jc042237@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ruslan Bukin Subject: git: bc2e3360107a - main - hwt(4): Add initial man page. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: br X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bc2e3360107af28fed7157d18605bd038f07e16c Auto-Submitted: auto-generated The branch main has been updated by br: URL: https://cgit.FreeBSD.org/src/commit/?id=bc2e3360107af28fed7157d18605bd038f07e16c commit bc2e3360107af28fed7157d18605bd038f07e16c Author: Ruslan Bukin AuthorDate: 2025-07-09 15:41:51 +0000 Commit: Ruslan Bukin CommitDate: 2025-07-09 15:57:07 +0000 hwt(4): Add initial man page. Reviewed by: ziaee Sponsored by: UKRI Differential Revision: https://reviews.freebsd.org/D51192 --- share/man/man4/Makefile | 12 ++++ share/man/man4/hwt.4 | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 4f12e70f2ae4..7c8a8f3afc45 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -213,6 +213,7 @@ MAN= aac.4 \ ${_hv_vmbus.4} \ ${_hv_vss.4} \ hwpmc.4 \ + ${_hwt.4} \ ${_hwpstate_intel.4} \ i2ctinyusb.4 \ iavf.4 \ @@ -926,6 +927,17 @@ _vmm.4= vmm.4 .endif .endif +.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "aarch64" +_hwt.4= hwt.4 +.if ${MACHINE_CPUARCH} == "amd64" +MLINKS+=hwt.4 intel_pt.4 +.endif +.if ${MACHINE_CPUARCH} == "aarch64" +MLINKS+=hwt.4 coresight.4 +MLINKS+=hwt.4 spe.4 +.endif +.endif + .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" || \ ${MACHINE_CPUARCH} == "aarch64" _gve.4= gve.4 diff --git a/share/man/man4/hwt.4 b/share/man/man4/hwt.4 new file mode 100644 index 000000000000..7bc8ed4b396d --- /dev/null +++ b/share/man/man4/hwt.4 @@ -0,0 +1,142 @@ +.\" +.\" Copyright (c) 2025 Ruslan Bukin +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.Dd July 7, 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 successfull 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, it's management character device accepts several IOC +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 achitecture-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's copied +out a buffer to avoid data loss/overwriting buffers. +.El +.Sh SEE ALSO +.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