[DTrace-devel] [PATCH v2 1/5] Add storage offset support in dt_ident_t and dt_idhash_t

Kris Van Hees kris.van.hees at oracle.com
Tue Nov 24 13:50:52 PST 2020


Variables (especially of a complex type) and aggregations will need
to be allocated from a memory block.  They will therefore require a
storage offset to be associated with them so that the code generator
can access the correct memory locations.

The dt_ident_t structure now has a di_offset member to hold the
storage offset for the identifier (if applicable) and the dt_idhash_t
structure has a dh_nextoff member to hold the offset to allocate the
next item at.

The dt_idhash_nextoff(dt_idhash_t *dhp, uint_t alignment, uint_t size)
function will return the offset where the next data item is to be
allocated.  The size argument specifies the size (in bytes) of the
data item.  The returned value is guaranteed to be properly aligned to
the number of bytes specified by the alignment argument, and the next
offset member (dh_nextoff in dt_idhash_t) will be advanced by the
given number of bytes.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_ident.c | 12 ++++++++++++
 libdtrace/dt_ident.h |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/libdtrace/dt_ident.c b/libdtrace/dt_ident.c
index 392f8e56..34b49728 100644
--- a/libdtrace/dt_ident.c
+++ b/libdtrace/dt_ident.c
@@ -669,6 +669,7 @@ dt_idhash_create(const char *name, const dt_ident_t *tmpl,
 	dhp->dh_nextid = min;
 	dhp->dh_minid = min;
 	dhp->dh_maxid = max;
+	dhp->dh_nextoff = 0;
 	dhp->dh_hashsz = _dtrace_strbuckets;
 
 	return (dhp);
@@ -768,6 +769,16 @@ dt_idhash_peekid(dt_idhash_t *dhp)
 	return dhp->dh_nextid;
 }
 
+uint_t
+dt_idhash_nextoff(dt_idhash_t *dhp, uint_t alignment, uint_t size)
+{
+	uint_t	off = (dhp->dh_nextoff + (alignment - 1)) & ~(alignment - 1);
+
+	dhp->dh_nextoff = off + size;
+
+	return off;
+}
+
 ulong_t
 dt_idhash_size(const dt_idhash_t *dhp)
 {
@@ -947,6 +958,7 @@ dt_ident_create(const char *name, ushort_t kind, ushort_t flags, uint_t id,
 	idp->di_data = NULL;
 	idp->di_ctfp = NULL;
 	idp->di_type = CTF_ERR;
+	idp->di_offset = -1;
 	idp->di_next = NULL;
 	idp->di_gen = gen;
 	idp->di_lineno = yylineno;
diff --git a/libdtrace/dt_ident.h b/libdtrace/dt_ident.h
index c74aa10c..99f16ad5 100644
--- a/libdtrace/dt_ident.h
+++ b/libdtrace/dt_ident.h
@@ -58,6 +58,7 @@ typedef struct dt_ident {
 	void *di_data;		/* private data pointer for ops vector */
 	ctf_file_t *di_ctfp;	/* CTF container for the variable data type */
 	ctf_id_t di_type;	/* CTF identifier for the variable data type */
+	int di_offset;		/* storage offset */
 	struct dt_ident *di_next; /* pointer to next ident in hash chain */
 	ulong_t di_gen;		/* generation number (pass that created me) */
 	int di_lineno;		/* line number that defined this identifier */
@@ -102,6 +103,7 @@ typedef struct dt_idhash {
 	uint_t dh_nextid;	/* next id to be returned by idhash_nextid() */
 	uint_t dh_minid;	/* min id to be returned by idhash_nextid() */
 	uint_t dh_maxid;	/* max id to be returned by idhash_nextid() */
+	uint_t dh_nextoff;	/* next offset to return at idhash_nextoff() */
 	ulong_t dh_nelems;	/* number of identifiers in hash table */
 	ulong_t dh_hashsz;	/* number of entries in dh_buckets array */
 	dt_ident_t *dh_hash[1];	/* array of hash table bucket pointers */
@@ -128,6 +130,7 @@ extern void dt_idhash_update(dt_idhash_t *);
 extern dt_ident_t *dt_idhash_lookup(dt_idhash_t *, const char *);
 extern int dt_idhash_nextid(dt_idhash_t *, uint_t *);
 extern uint_t dt_idhash_peekid(dt_idhash_t *);
+extern uint_t dt_idhash_nextoff(dt_idhash_t *, uint_t, uint_t);
 extern ulong_t dt_idhash_size(const dt_idhash_t *);
 extern const char *dt_idhash_name(const dt_idhash_t *);
 
-- 
2.28.0




More information about the DTrace-devel mailing list