Skip to content

Commit

Permalink
Refactor get_tvar() into generic components
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Mar 18, 2022
1 parent f56058a commit 530dc87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bpf/Build
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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 \
Expand Down
19 changes: 15 additions & 4 deletions bpf/get_tvar.c → bpf/get_dvar.c
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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;
Expand All @@ -29,6 +27,14 @@ 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 key, uint64_t store, uint64_t nval)
{
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.
Expand Down Expand Up @@ -70,3 +76,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);
}

0 comments on commit 530dc87

Please sign in to comment.