Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jul 2024 15:43:14 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 85f7c98d85e4 - main - sdt: Fix aframe handling after commit ddf0ed09bd8f
Message-ID:  <202407081543.468FhEIo032152@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=85f7c98d85e4523943f40d0fa74581e5dd774f7b

commit 85f7c98d85e4523943f40d0fa74581e5dd774f7b
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-07-08 15:40:24 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-07-08 15:40:24 +0000

    sdt: Fix aframe handling after commit ddf0ed09bd8f
    
    DTrace probes have an "aframes" attribute, used when unwinding the stack
    from dtrace_probe().  It counts the number of leading frames to skip
    when returning a stack trace, thus is used to hide internal functions.
    Commit ddf0ed09bd8f set the aframes value for SDT probes to 0, which was
    correct for an earlier iteration of the patch, but now doesn't take
    sdt_probe()/sdt_probe6() into account.
    
    Fix the aframes definition for SDT probes.  Also try to improve
    lockstat(1) output by adding an additional aframe for lockstat probes,
    which otherwise show internal mtx(9), rwlock(9), etc. functions as the
    probe "caller".  This is not quite correct as the number of frames to
    skip may differ depending on the lock type and kernel configuration (see
    e.g., the MUTEX_NOINLINE kernel option), but this is not a new problem.
    
    Reported by:    mjg
    Fixes:  ddf0ed09bd8f ("sdt: Implement SDT probes using hot-patching")
---
 sys/cddl/dev/sdt/sdt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/cddl/dev/sdt/sdt.c b/sys/cddl/dev/sdt/sdt.c
index 461f454186a3..88ceb390876b 100644
--- a/sys/cddl/dev/sdt/sdt.c
+++ b/sys/cddl/dev/sdt/sdt.c
@@ -144,6 +144,7 @@ sdt_create_probe(struct sdt_probe *probe)
 	const char *from;
 	char *to;
 	size_t len;
+	int aframes;
 
 	if (probe->version != (int)sizeof(*probe)) {
 		printf("ignoring probe %p, version %u expected %u\n",
@@ -190,7 +191,17 @@ sdt_create_probe(struct sdt_probe *probe)
 	if (dtrace_probe_lookup(prov->id, mod, func, name) != DTRACE_IDNONE)
 		return;
 
-	(void)dtrace_probe_create(prov->id, mod, func, name, 0, probe);
+	aframes = 1; /* unwind past sdt_probe() */
+	if (strcmp(prov->name, "lockstat") == 0) {
+		/*
+		 * Locking primitives instrumented by lockstat automatically
+		 * disable inlining.  Step forward an extra frame so that DTrace
+		 * variables like "caller" provide the function trying to
+		 * acquire or release the lock rather than an internal function.
+		 */
+		aframes++;
+	}
+	(void)dtrace_probe_create(prov->id, mod, func, name, aframes, probe);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407081543.468FhEIo032152>