[DTrace-devel] [PATCH 3/6] Refactor get_tvar() into generic components

Kris Van Hees kris.van.hees at oracle.com
Mon Mar 7 19:50:00 UTC 2022


The TLS variable support function get_tvar() contained the machinery for
accessing a dynamic variable.  This is now refactored to make the TLS
key calculation and the dynamic variable retrieval separate functions so
they can be used in the associative array implementation.
---
 bpf/Build                      |  4 ++--
 bpf/{get_tvar.c => get_dvar.c} | 20 ++++++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)
 rename bpf/{get_tvar.c => get_dvar.c} (83%)

diff --git a/bpf/Build b/bpf/Build
index 062381b8..d986fd7e 100644
--- a/bpf/Build
+++ b/bpf/Build
@@ -1,5 +1,5 @@
 # Oracle Linux DTrace.
-# Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2020, 2022, 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.
 
@@ -26,7 +26,7 @@ bpf_dlib_SOURCES = \
 	basename.S \
 	dirname.S \
 	get_bvar.c \
-	get_tvar.c \
+	get_dvar.c \
 	index.S \
 	lltostr.S \
 	probe_error.c \
diff --git a/bpf/get_tvar.c b/bpf/get_dvar.c
similarity index 83%
rename from bpf/get_tvar.c
rename to bpf/get_dvar.c
index 87e6a79d..d0f1dc8a 100644
--- a/bpf/get_tvar.c
+++ b/bpf/get_dvar.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 #include <linux/bpf.h>
 #include <stdint.h>
@@ -13,11 +13,9 @@
 extern struct bpf_map_def dvars;
 extern uint64_t NCPUS;
 
-noinline void *dt_get_tvar(uint32_t id, uint64_t store, uint64_t nval)
+noinline uint64_t dt_tlskey(uint32_t id)
 {
 	uint64_t	key;
-	uint64_t	dflt_key = 0;
-	void		*val;
 
 	key = bpf_get_current_pid_tgid();
 	key &= 0x00000000ffffffffUL;
@@ -29,6 +27,15 @@ noinline void *dt_get_tvar(uint32_t id, uint64_t store, uint64_t nval)
 	key++;
 	key = (key << 32) | id;
 
+	return key;
+}
+
+noinline void *dt_get_dvar(uint64_t id, uint64_t store, uint64_t nval)
+{
+	uint64_t	key = id;
+	uint64_t	dflt_key = 0;
+	void		*val;
+
 	/*
 	 * If we are going to store a zero-value, it is a request to delete the
 	 * TLS variable.
@@ -70,3 +77,8 @@ noinline void *dt_get_tvar(uint32_t id, uint64_t store, uint64_t nval)
 
 	return 0;
 }
+
+noinline void *dt_get_tvar(uint32_t id, uint64_t store, uint64_t nval)
+{
+	return dt_get_dvar(dt_tlskey(id), store, nval);
+}
-- 
2.34.1




More information about the DTrace-devel mailing list