Linux DTrace development list
 help / color / mirror / Atom feed
From: Kris Van Hees <kris.van.hees@oracle.com>
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH 13/20] libdtrace: use module address index for aggregation
Date: Fri, 30 Oct 2026 19:36:51 +0000	[thread overview]
Message-ID: <10f66def218e32acd6292b104f7f4cb8@oracle.com> (raw)

Share dt_module_by_addr() with dt_aggregate_mod() to avoid scanning every
module when normalizing aggregation keys. Preserve the representative module
address and reuse the indexed lookup, including overlap precedence and its
allocation-failure fallback.
---
 libdtrace/dt_aggregate.c | 38 ++++++++++----------------------------
 libdtrace/dt_module.c    |  2 +-
 libdtrace/dt_module.h    |  1 +
 3 files changed, 12 insertions(+), 29 deletions(-)

diff --git a/libdtrace/dt_aggregate.c b/libdtrace/dt_aggregate.c
index 1fc8294d..f04c39b6 100644
--- a/libdtrace/dt_aggregate.c
+++ b/libdtrace/dt_aggregate.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2026, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -18,6 +18,7 @@
 #include <port.h>
 #include <dt_aggregate.h>
 #include <dt_bpf.h>
+#include <dt_module.h>
 
 typedef struct dt_ahashent {
 	struct dt_ahashent *dtahe_prev;		/* prev on hash chain */
@@ -394,34 +395,15 @@ dt_aggregate_mod(dtrace_hdl_t *dtp, uint64_t *addr)
 		return;
 	}
 
-	for (dmp = dt_list_next(&dtp->dt_modlist); dmp != NULL;
-	    dmp = dt_list_next(dmp)) {
-		/*
-		 * Check text and data ranges for match.  If there is a range
-		 * that covers the given address, normalize it.
-		 */
-		if (dmp->dm_text_addrs != NULL &&
-		    bsearch(addr, dmp->dm_text_addrs, dmp->dm_text_addrs_size,
-			    sizeof(struct dtrace_addr_range),
-			    dtrace_addr_range_cmp) != NULL) {
-
-			*addr = dmp->dm_text_addrs[0].dar_va;
-			return;
-		}
-
-		if (dmp->dm_data_addrs != NULL &&
-		    bsearch(addr, dmp->dm_data_addrs, dmp->dm_data_addrs_size,
-			    sizeof(struct dtrace_addr_range),
-			    dtrace_addr_range_cmp) != NULL) {
-
-			if (dmp->dm_text_addrs != NULL)
-				*addr = dmp->dm_text_addrs[0].dar_va;
-			else
-				*addr = dmp->dm_data_addrs[0].dar_va;
+	dmp = dt_module_by_addr(dtp, *addr);
+	if (dmp == NULL)
+		return;
 
-			return;
-		}
-	}
+	/* Normalize text and data addresses to the same module address. */
+	if (dmp->dm_text_addrs != NULL)
+		*addr = dmp->dm_text_addrs[0].dar_va;
+	else
+		*addr = dmp->dm_data_addrs[0].dar_va;
 }
 
 static dtrace_aggid_t
diff --git a/libdtrace/dt_module.c b/libdtrace/dt_module.c
index 9d93b9d8..3b40c1cb 100644
--- a/libdtrace/dt_module.c
+++ b/libdtrace/dt_module.c
@@ -2421,7 +2421,7 @@ dt_module_ranges_build(dtrace_hdl_t *dtp)
 	return 0;
 }
 
-static dt_module_t *
+dt_module_t *
 dt_module_by_addr(dtrace_hdl_t *dtp, GElf_Addr addr)
 {
 	dt_module_range_t *index;
diff --git a/libdtrace/dt_module.h b/libdtrace/dt_module.h
index c94cf7b5..73be7144 100644
--- a/libdtrace/dt_module.h
+++ b/libdtrace/dt_module.h
@@ -20,6 +20,7 @@ extern void dt_user_path_destroy(dtrace_hdl_t *);
 
 extern dt_module_t *dt_module_lookup_by_name(dtrace_hdl_t *, const char *);
 extern dt_module_t *dt_module_lookup_by_ctf(dtrace_hdl_t *, ctf_file_t *);
+extern dt_module_t *dt_module_by_addr(dtrace_hdl_t *, GElf_Addr);
 extern int dt_module_sym_iter(const dt_module_t *, proc_sym_f *, void *);
 
 extern ctf_file_t *dt_module_shared_ctf(dtrace_hdl_t *);
-- 
2.52.0


             reply	other threads:[~2026-10-30 19:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 19:36 Kris Van Hees [this message]
2026-11-06 13:07 ` [PATCH 13/20] libdtrace: use module address index for aggregation Nick Alcock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10f66def218e32acd6292b104f7f4cb8@oracle.com \
    --to=kris.van.hees@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox