[DTrace-devel] [PATCH 12/12] Implement TLS variables
Eugene Loh
eugene.loh at oracle.com
Wed Nov 24 15:37:01 UTC 2021
On 11/24/21 12:20 AM, Kris Van Hees wrote:
> On Tue, Nov 23, 2021 at 08:52:45PM -0500, Eugene Loh via DTrace-devel wrote:
>> On 11/23/21 2:45 AM, Kris Van Hees wrote:
>>> On Mon, Nov 22, 2021 at 06:08:18PM -0500, Eugene Loh via DTrace-devel wrote:
>>>> On 11/20/21 12:44 AM, Kris Van Hees via DTrace-devel wrote:
>>>>> diff --git a/bpf/get_tvar.c b/bpf/get_tvar.c
>>>>> @@ -10,12 +10,40 @@
>>>>> # define noinline __attribute__((noinline))
>>>>> #endif
>>>>> -extern struct bpf_map_def tvars;
>>>>> +extern struct bpf_map_def dvars;
>>>>> +extern uint64_t NCPUS;
>>>>> -noinline uint64_t dt_get_tvar(uint32_t id)
>>>>> +noinline void *dt_get_tvar(uint32_t id)
>>>>> {
>>>>> - uint64_t *val;
>>>>> + uint64_t key;
>>>>> + uint64_t dflt_key = 0;;
>>>>> + void *val;
>>>>> - val = bpf_map_lookup_elem(&tvars, &id);
>>>>> - return val ? *val : 0;
>>>>> + key = bpf_get_current_pid_tgid();
>>>>> + key &= 0x00000000ffffffffUL;
>>>>> + if (key == 0)
>>>>> + key = bpf_get_smp_processor_id();
>>>>> + else
>>>>> + key += (uint32_t)(uint64_t)&NCPUS;
>>>>> +
>>>>> + key++;
>>>>> + key = (key << 32) | id;
>>>>> diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
>>>>> @@ -213,36 +213,21 @@ populate_probes_map(dtrace_hdl_t *dtp, int fd)
>>>>> * use.
>>>>> * - gvars: Global variables map. This is a global map with a singleton
>>>>> * element (key 0) addressed by variable offset.
>>>>> + * - dvars: Dynamic variables map. This is a global hash map index with
>>>>> + * a unique numeric identifier for each variable.
>>>> Well, variable/pid combo.
>> again not just per variable but also per pid
> No, we look at it as distict variables, and thus each numeric identifier relates
> to a single variable. So, a single variable name (identifier) maps to multiple
> variables (internally).
There is apparently some point here that I'm not getting but that I'd
like to understand. The BPF map is indexed by keys that combine varid
with pid. The map knows nothing about varid apart from pid. As far as
the BPF map is concerned, there is nothing magic about varid apart from
pid. One could exchange varid and pid in the key, interweave varid and
pid bits to form the key, etc. None of that would impact the BPF map.
More information about the DTrace-devel
mailing list