[DTrace-devel] [PATCH v2 09/20] Use str2hval() instead of dt_strtab_hash() in non-strtab code

Kris Van Hees kris.van.hees at oracle.com
Thu Jun 3 08:16:44 PDT 2021


An earlier patch ensured that str2hval() and dt_strtab_hash() provide
the same hash function implementation.  All code that used to call
dt_strtab_hash() to get a hash value for a string should and will now
use the generic str2hval() function.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_ident.c         | 12 +++++-------
 libdtrace/dt_kernel_module.c |  8 ++++----
 libdtrace/dt_module.c        | 11 +++++------
 libdtrace/dt_printf.c        |  6 +++---
 libdtrace/dt_provider.c      |  8 ++++----
 libdtrace/dt_symtab.c        | 19 ++++++++++---------
 6 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/libdtrace/dt_ident.c b/libdtrace/dt_ident.c
index 48a97954..2cc5450f 100644
--- a/libdtrace/dt_ident.c
+++ b/libdtrace/dt_ident.c
@@ -17,7 +17,7 @@
 #include <dt_parser.h>
 #include <dt_provider.h>
 #include <dt_probe.h>
-#include <dt_strtab.h>
+#include <dt_string.h>
 #include <dt_impl.h>
 
 static void
@@ -723,8 +723,7 @@ dt_idhash_update(dt_idhash_t *dhp)
 dt_ident_t *
 dt_idhash_lookup(dt_idhash_t *dhp, const char *name)
 {
-	size_t len;
-	ulong_t h = dt_strtab_hash(name, &len) % dhp->dh_hashsz;
+	ulong_t h = str2hval(name, 0) % dhp->dh_hashsz;
 	dt_ident_t *idp;
 
 	if (dhp->dh_tmpl != NULL)
@@ -788,7 +787,7 @@ dt_idhash_insert(dt_idhash_t *dhp, const char *name, ushort_t kind,
 	if (idp == NULL)
 		return NULL;
 
-	h = dt_strtab_hash(name, NULL) % dhp->dh_hashsz;
+	h = str2hval(name, 0) % dhp->dh_hashsz;
 	idp->di_next = dhp->dh_hash[h];
 	idp->di_hash = dhp;
 
@@ -809,7 +808,7 @@ dt_idhash_xinsert(dt_idhash_t *dhp, dt_ident_t *idp)
 	if (dhp->dh_tmpl != NULL)
 		dt_idhash_populate(dhp); /* fill hash w/ initial population */
 
-	h = dt_strtab_hash(idp->di_name, NULL) % dhp->dh_hashsz;
+	h = str2hval(idp->di_name, 0) % dhp->dh_hashsz;
 	idp->di_next = dhp->dh_hash[h];
 	idp->di_hash = dhp;
 	idp->di_flags &= ~DT_IDFLG_ORPHAN;
@@ -824,8 +823,7 @@ dt_idhash_xinsert(dt_idhash_t *dhp, dt_ident_t *idp)
 void
 dt_idhash_delete(dt_idhash_t *dhp, dt_ident_t *key)
 {
-	size_t len;
-	ulong_t h = dt_strtab_hash(key->di_name, &len) % dhp->dh_hashsz;
+	ulong_t h = str2hval(key->di_name, 0) % dhp->dh_hashsz;
 	dt_ident_t **pp = &dhp->dh_hash[h];
 	dt_ident_t *idp;
 
diff --git a/libdtrace/dt_kernel_module.c b/libdtrace/dt_kernel_module.c
index 4bf44532..bdd15986 100644
--- a/libdtrace/dt_kernel_module.c
+++ b/libdtrace/dt_kernel_module.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2021, 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.
  */
@@ -39,7 +39,7 @@ static pthread_mutex_t kern_path_update_lock = PTHREAD_MUTEX_INITIALIZER;
 dt_kern_path_t *
 dt_kern_path_create(dtrace_hdl_t *dtp, char *name, char *path)
 {
-	uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_kernpathbuckets;
+	uint_t h = str2hval(name, 0) % dtp->dt_kernpathbuckets;
 	dt_kern_path_t *dkpp;
 
 	for (dkpp = dtp->dt_kernpaths[h]; dkpp != NULL; dkpp = dkpp->dkp_next) {
@@ -69,7 +69,7 @@ dt_kern_path_create(dtrace_hdl_t *dtp, char *name, char *path)
 void
 dt_kern_path_destroy(dtrace_hdl_t *dtp, dt_kern_path_t *dkpp)
 {
-	uint_t h = dt_strtab_hash(dkpp->dkp_name, NULL) % dtp->dt_kernpathbuckets;
+	uint_t h = str2hval(dkpp->dkp_name, 0) % dtp->dt_kernpathbuckets;
 	dt_kern_path_t *scan_dkpp;
 	dt_kern_path_t *prev_dkpp = NULL;
 
@@ -178,7 +178,7 @@ dt_kern_path_update(dtrace_hdl_t *dtp)
 dt_kern_path_t *
 dt_kern_path_lookup_by_name(dtrace_hdl_t *dtp, const char *name)
 {
-	uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_kernpathbuckets;
+	uint_t h = str2hval(name, 0) % dtp->dt_kernpathbuckets;
 	dt_kern_path_t *dkpp;
 
 	if (dtp->dt_nkernpaths == 0) {
diff --git a/libdtrace/dt_module.c b/libdtrace/dt_module.c
index 80c5ac48..aaf125b8 100644
--- a/libdtrace/dt_module.c
+++ b/libdtrace/dt_module.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2021, 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.
  */
@@ -23,7 +23,6 @@
 
 #include <zlib.h>
 
-#include <dt_strtab.h>
 #include <dt_kernel_module.h>
 #include <dt_module.h>
 #include <dt_impl.h>
@@ -54,7 +53,7 @@ dt_module_symhash_insert(dt_module_t *dmp, const char *name, uint_t id)
 	assert(dmp->dm_symfree < dmp->dm_nsymelems + 1);
 
 	dsp->dms_symid = id;
-	h = dt_strtab_hash(name, NULL) % dmp->dm_nsymbuckets;
+	h = str2hval(name, 0) % dmp->dm_nsymbuckets;
 	dsp->dms_next = dmp->dm_symbuckets[h];
 	dmp->dm_symbuckets[h] = dmp->dm_symfree++;
 }
@@ -97,7 +96,7 @@ dt_module_symgelf64(const Elf64_Sym *src, GElf_Sym *dst)
 dt_module_t *
 dt_module_create(dtrace_hdl_t *dtp, const char *name)
 {
-	uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_modbuckets;
+	uint_t h = str2hval(name, 0) % dtp->dt_modbuckets;
 	dt_module_t *dmp;
 
 	for (dmp = dtp->dt_mods[h]; dmp != NULL; dmp = dmp->dm_next)
@@ -125,7 +124,7 @@ dt_module_create(dtrace_hdl_t *dtp, const char *name)
 dt_module_t *
 dt_module_lookup_by_name(dtrace_hdl_t *dtp, const char *name)
 {
-	uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_modbuckets;
+	uint_t h = str2hval(name, 0) % dtp->dt_modbuckets;
 	dt_module_t *dmp;
 
 	/* 'genunix' is an alias for 'vmlinux'. */
@@ -672,7 +671,7 @@ dt_module_unload(dtrace_hdl_t *dtp, dt_module_t *dmp)
 void
 dt_module_destroy(dtrace_hdl_t *dtp, dt_module_t *dmp)
 {
-	uint_t h = dt_strtab_hash(dmp->dm_name, NULL) % dtp->dt_modbuckets;
+	uint_t h = str2hval(dmp->dm_name, 0) % dtp->dt_modbuckets;
 	dt_module_t *scan_dmp;
 	dt_module_t *prev_dmp = NULL;
 
diff --git a/libdtrace/dt_printf.c b/libdtrace/dt_printf.c
index ce6d495f..a93044a6 100644
--- a/libdtrace/dt_printf.c
+++ b/libdtrace/dt_printf.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2021, 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.
  */
@@ -652,7 +652,7 @@ dt_pfdict_create(dtrace_hdl_t *dtp)
 		}
 
 		memcpy(pfc, pfd, sizeof(dt_pfconv_t));
-		h = dt_strtab_hash(pfc->pfc_name, NULL) % n;
+		h = str2hval(pfc->pfc_name, 0) % n;
 		pfc->pfc_next = pdi->pdi_buckets[h];
 		pdi->pdi_buckets[h] = pfc;
 
@@ -725,7 +725,7 @@ static const dt_pfconv_t *
 dt_pfdict_lookup(dtrace_hdl_t *dtp, const char *name)
 {
 	dt_pfdict_t *pdi = dtp->dt_pfdict;
-	uint_t h = dt_strtab_hash(name, NULL) % pdi->pdi_nbuckets;
+	uint_t h = str2hval(name, 0) % pdi->pdi_nbuckets;
 	const dt_pfconv_t *pfc;
 
 	for (pfc = pdi->pdi_buckets[h]; pfc != NULL; pfc = pfc->pfc_next) {
diff --git a/libdtrace/dt_provider.c b/libdtrace/dt_provider.c
index 6821ac6e..3d083671 100644
--- a/libdtrace/dt_provider.c
+++ b/libdtrace/dt_provider.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2021, 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.
  */
@@ -37,7 +37,7 @@ dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h)
 dt_provider_t *
 dt_provider_lookup(dtrace_hdl_t *dtp, const char *name)
 {
-	uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_provbuckets;
+	uint_t h = str2hval(name, 0) % dtp->dt_provbuckets;
 	dt_provider_t *pvp;
 
 	for (pvp = dtp->dt_provs[h]; pvp != NULL; pvp = pvp->pv_next) {
@@ -72,7 +72,7 @@ dt_provider_create(dtrace_hdl_t *dtp, const char *name,
 	memcpy(&pvp->desc.dtvd_attr, pattr, sizeof(dtrace_pattr_t));
 
 	return dt_provider_insert(dtp, pvp,
-	    dt_strtab_hash(name, NULL) % dtp->dt_provbuckets);
+				  str2hval(name, 0) % dtp->dt_provbuckets);
 }
 
 void
@@ -83,7 +83,7 @@ dt_provider_destroy(dtrace_hdl_t *dtp, dt_provider_t *pvp)
 
 	assert(pvp->pv_hdl == dtp);
 
-	h = dt_strtab_hash(pvp->desc.dtvd_name, NULL) % dtp->dt_provbuckets;
+	h = str2hval(pvp->desc.dtvd_name, 0) % dtp->dt_provbuckets;
 	pp = &dtp->dt_provs[h];
 
 	while (*pp != NULL && *pp != pvp)
diff --git a/libdtrace/dt_symtab.c b/libdtrace/dt_symtab.c
index aa511169..4b7f8b9d 100644
--- a/libdtrace/dt_symtab.c
+++ b/libdtrace/dt_symtab.c
@@ -1,3 +1,10 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2012, 2021, 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.
+ */
+
 /*
  * Symbol table support for DTrace.
  *
@@ -8,18 +15,12 @@
  * TODO: increase efficiency (perhaps Huffman-coding symbol names?)
  */
 
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2012, 2020, 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.
- */
-
 #include <stdlib.h>
 #include <string.h>
 #include <dt_symtab.h>
 #include <dt_impl.h>
 #include <dt_list.h>
+#include <dt_string.h>
 #include <unistd.h>
 
 #define DT_ST_SORTED 0x01		/* Sorted, ready for searching. */
@@ -245,7 +246,7 @@ dt_symbol_insert(dt_symtab_t *symtab, const char *name,
 	/*
 	 * Add to lookup-by-name hash table.
 	 */
-	h = dt_strtab_hash(name, NULL) % symtab->dtst_symbuckets;
+	h = str2hval(name, 0) % symtab->dtst_symbuckets;
 	dtsp->dts_next = symtab->dtst_syms_by_name[h];
 	symtab->dtst_syms_by_name[h] = dtsp;
 
@@ -257,7 +258,7 @@ dt_symbol_insert(dt_symtab_t *symtab, const char *name,
 dt_symbol_t *
 dt_symbol_by_name(dt_symtab_t *symtab, const char *name)
 {
-	uint_t h = dt_strtab_hash(name, NULL) % symtab->dtst_symbuckets;
+	uint_t h = str2hval(name, 0) % symtab->dtst_symbuckets;
 	dt_symbol_t *dtsp;
 	int packed = symtab->dtst_flags & DT_ST_PACKED;
 
-- 
2.31.1




More information about the DTrace-devel mailing list