[DTrace-devel] [PATCH 03/10] Exclude %r0 from automatic register allocation

Eugene Loh eugene.loh at oracle.com
Sat Mar 19 22:35:59 UTC 2022


On 3/18/22 7:43 PM, Kris Van Hees wrote:

> On Fri, Mar 18, 2022 at 07:30:03PM -0400, Eugene Loh via DTrace-devel wrote:
>> On 3/18/22 7:11 PM, Kris Van Hees wrote:
>>
>>> On Fri, Mar 18, 2022 at 05:06:10PM -0400, Eugene Loh via DTrace-devel wrote:
>>>> On 3/18/22 3:04 PM, Kris Van Hees via DTrace-devel wrote:
>>>>> be allocated when dt_regset_alloc() is called.
>>>> So this patch should also:
>>>> *) in dt_cg.c, remove those dozens of dt_regset_xalloc() calls along with
>>>> their corresponding frees
>>>> *) in dt_regset.h, remove dt_regset_xalloc()
>>>> *) in dt_regset.c, make dt_regset_xalloc() static
>>> No, no, and no :)  We still want to be able to alloc and free %r0 explicitly.
>> Why?
>>
>> Or e.g. why do we use BPF_REG_0 explicitly in dt_cg_ternary_op() without
>> xalloc'ing it?
> Because we should have and we didn't.
During the code review of that code, this issue came up. Presumably, %r0 
was being used explicitly because one "knew" that it would not need to 
be checked.  So at least at that time, this reasoning was rejected.
> We probably can stop doing explici
> allocs for it, if we are careful to only use %r0 as a scratch register in
> cases where we do not call any other cg functions while we are using it.
> That is the main reason I still use xalloc/free for %r0 in code that might
> get called in that situation (or that might make calls).  Careful audit
> probably allows us to reduce most of those, but I don't mind being rather
> safe than sorry.
>
> But in a code sequence where nothing else gets called, i.e. really using it
> as a scratch register (or a temp reg), not doing the alloc is usually safe.
> Unless we might have been called by some other cg function that decides to
> allocate it for its own use, across calling our function.
>
>>> But perhaps I should add an explicit check to ensure that we do not alloc %r0
>>> when it is already in use.  I will do that.
Or, instead of allocating %r0 explicitly, just allocate a register (let 
dt_regset_alloc decide which one) and use that.



More information about the DTrace-devel mailing list