Skip to contentSkip to conversation

fbt: performance improvements

PATCH In review Kris Van Hees 2 participants 2 messages Mar 12, 2025 – Mar 18, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 6/8 fbt: performance improvements

Up until now, FBT probes were registered for every symbol that was listed as traceable. Most tracing session do not use most or even any of these, and the process of registering them all was quite slow.

Going forward, FBT probes are registered on demand.

If any FBT probes are to be registered, the first will incur the cost of reading the entire list of traceable symbols. Any further FBT probe registration will be able to be satisfied based on that initial processing. The performance improvement is therefore quite significant for tracing sessions that do not trigger any FBT probe registration, and if FBT probes are used, the improvement is still quite noticable because only the probes that are actually needed get registered.

---
 libdtrace/dt_module.c   |  78 ++++++++++++++
 libdtrace/dt_module.h   |   2 +
 libdtrace/dt_prov_fbt.c | 219 +++++++++++++++++++++++++++-------------
 3 files changed, 229 insertions(+), 70 deletions(-)
libdtrace/dt_module.c +78 -0
index 2e915e2f..e7553a07 100644
@@ -22,6 +22,7 @@
 #include <port.h>
 
 #include <zlib.h>
+#include <tracefs.h>
 
 #include <dt_kernel_module.h>
 #include <dt_module.h>
@@ -1044,6 +1045,83 @@ dt_kern_module_find_ctf(dtrace_hdl_t *dtp, dt_module_t *dmp)
 	}
 }
 
+#define PROBE_LIST		TRACEFS "available_filter_functions"
+
+/*
+ * Determine which kernel functions are traceable and mark them.
+ */
+void
+dt_modsym_mark_traceable(dtrace_hdl_t *dtp)
+{
+	FILE			*f;
+	char			*buf = NULL;
+	size_t			len = 0;
+
+	if (dt_symtab_traceable(dtp->dt_exec->dm_kernsyms))
+		return;
+
+	f = fopen(PROBE_LIST, "r");
+	if (f == NULL)
+		return;
+
+	while (getline(&buf, &len, f) >= 0) {
+		char			*p;
+		dt_symbol_t		*sym = NULL;
+
+		/*
+		 * Here buf is either "funcname\n" or "funcname [modname]\n".
+		 * The last line may not have a linefeed.
+		 */
+		p = strchr(buf, '\n');
+		if (p) {
+			*p = '\0';
+			if (p > buf && *(--p) == ']')
+				*p = '\0';
+		}
+
+		/*
+		 * Now buf is either "funcname" or "funcname [modname".  If
+		 * there is no module name provided, we will use the default.
+		 */
+		p = strchr(buf, ' ');
+		if (p) {
+			*p++ = '\0';
+			if (*p == '[')
+				p++;
+		}
+
+#define strstarts(var, x) (strncmp(var, x, strlen (x)) == 0)
+		/* Weed out __ftrace_invalid_address___* entries. */
+		if (strstarts(buf, "__ftrace_invalid_address__") ||
+		    strstarts(buf, "__probestub_") ||
+		    strstarts(buf, "__traceiter_"))
+			continue;
+#undef strstarts
+
+		/*
+		 * If we have a module name, look for the symbol in that
+		 * module.
+		 * If not, perform a general symbol lookup to find its first
+		 * instance.
+		 */
+		if (p) {
+			dt_module_t	*dmp = dt_module_lookup_by_name(dtp, p);
+
+			if (dmp)
+				sym = dt_module_symbol_by_name(dtp, dmp, buf);
+		} else
+			sym = dt_symbol_by_name(dtp, buf);
+
+		if (sym)
+			dt_symbol_set_traceable(sym);
+	}
+
+	free(buf);
+	fclose(f);
+
+	dt_symtab_set_traceable(dtp->dt_exec->dm_kernsyms);
+}
+
 /*
  * Symbol data can be collected in three ways:
  *  - kallmodsyms
libdtrace/dt_module.h +2 -0
index 56df17a6..dd3ad17c 100644
@@ -25,6 +25,8 @@ extern dt_ident_t *dt_module_extern(dtrace_hdl_t *, dt_module_t *,
 
 extern const char *dt_module_modelname(dt_module_t *);
 
+extern void dt_modsym_mark_traceable(dtrace_hdl_t *);
+
 #ifdef	__cplusplus
 }
 #endif
libdtrace/dt_prov_fbt.c +149 -70

275 lines not on this page · raw message

Signature · 1 line
2.45.2
Reviewed-by on v2 6/8
#1 lore raw

Also...

One patch or another needs to update the dt_module.[c|h] copyright years.

Quoted 2 lines · Kris Van Hees

Up until now, FBT probes were registered for every symbol that was listed as traceable. Most tracing session do not use most or even

s/session/sessions/

Quoted 36 lines

any of these, and the process of registering them all was quite slow.

libdtrace/dt_module.c +28 -0
@@ -1044,6 +1045,83 @@ dt_kern_module_find_ctf(dtrace_hdl_t *dtp, dt_module_t *dmp)
  	}
  }
 
+#define PROBE_LIST		TRACEFS "available_filter_functions"
+
+/*
+ * Determine which kernel functions are traceable and mark them.
+ */
+void
+dt_modsym_mark_traceable(dtrace_hdl_t *dtp)
+{
+	FILE			*f;
+	char			*buf = NULL;
+	size_t			len = 0;
+
+	if (dt_symtab_traceable(dtp->dt_exec->dm_kernsyms))
+		return;
+
+	f = fopen(PROBE_LIST, "r");
+	if (f == NULL)
+		return;
+
+	while (getline(&buf, &len, f) >= 0) {
+		char			*p;
+		dt_symbol_t		*sym = NULL;
+
+		/*
+		 * Here buf is either "funcname\n" or "funcname [modname]\n".
+		 * The last line may not have a linefeed.
+		 */
+		p = strchr(buf, '\n');

libdtrace/dt_module.c dt_kern_module_find_ctf(dtrace_hdl_t *dtp, dt_module_t *dmp) · line 1085

Quoted 10 lines
libdtrace/dt_module.c +10 -0
+		if (p) {
+			*p = '\0';
+			if (p > buf && *(--p) == ']')
+				*p = '\0';
+		}
+
+		/*
+		 * Now buf is either "funcname" or "funcname [modname".  If
+		 * there is no module name provided, we will use the default.
+		 */

Maybe that second sentence is now orphaned?

Quoted 35 lines
libdtrace/dt_module.c +7 -0
+		p = strchr(buf, ' ');
+		if (p) {
+			*p++ = '\0';
+			if (*p == '[')
+				p++;
+		}
+
libdtrace/dt_prov_fbt.c +13 -8
@@ -81,79 +71,166 @@ static int populate(dtrace_hdl_t *dtp)
  	if (prv == NULL)
  		return -1;			/* errno already set */
 
-	f = fopen(PROBE_LIST, "r");
-	if (f == NULL)
+	return 0;
+}
+
+/* Create a probe (if it does not exist yet). */
+static int provide_probe(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp)
+{
+	dt_provider_t	*prv = dt_provider_lookup(dtp, pdp->prv);
+
+	if (prv == NULL)
+		return 0;
+	if (dt_probe_lookup(dtp, pdp) != NULL)
  		return 0;
+	if (dt_tp_probe_insert(dtp, prv, pdp->prv, pdp->mod, pdp->fun, pdp->prb))
+		return 1;
 
-	while (getline(&buf, &n, f) >= 0) {
-		/*
-		 * Here buf is either "funcname\n" or "funcname [modname]\n".
-		 * The last line may not have a linefeed.
-		 */
-		p = strchr(buf, '\n');

libdtrace/dt_prov_fbt.c static int populate(dtrace_hdl_t *dtp) · line 94

Quoted 10 lines
libdtrace/dt_prov_fbt.c +6 -4
-		if (p) {
-			*p = '\0';
-			if (p > buf && *(--p) == ']')
-				*p = '\0';
+	return 0;
+}
+
+/*
+ * Try to provide probes for the given probe description.  The caller ensures
+ * that the provider name in probe desxcription (if any) is a match for this

desxcription
description

Quoted 3 lines
libdtrace/dt_prov_fbt.c +3 -0
+ * provider.  When this is called, we already know that this provider matches
+ * the provider component of the probe specification.
+ */