Re: [PATCH v2 0/4] Static calls
From: Nadav Amit
Date: Wed Dec 12 2018 - 16:46:40 EST
> On Dec 12, 2018, at 1:36 PM, Edward Cree <ecree@xxxxxxxxxxxxxx> wrote:
> On 12/12/18 21:15, Nadav Amit wrote:
>>> On Dec 12, 2018, at 10:33 AM, Edward Cree <ecree@xxxxxxxxxxxxxx> wrote:
>>> AIUI the outline version uses a tail-call (i.e. jmpq *target) rather than an
>>> additional call and ret. So I wouldn't expect it to be too expensive.
>>> More to the point, it seems like it's easier to get right than the inline
>>> version, and if we get the inline version working later we can introduce it
>>> without any API change, much as Josh's existing patches have both versions
>>> behind a Kconfig switch.
>> I see. For my outlined blocks I used the opposite approach - a call followed
>> by jmp
> That's what Josh did too. I.e. caller calls the trampoline, which jmps to the
> callee; later it rets, taking it back to the caller. Perhaps I wasn't clear.
> The point is that there's still only one call and one ret.
Sorry for the misunderstanding.
>>> I was working on the assumption that it would be opt-in, wrapping a macro
>>> around indirect calls that are known to have a fairly small number of hot
>>> targets. There are plenty of indirect calls in the kernel that are only
>>> called once in a blue moon, e.g. in control-plane operations like ethtool;
>>> we don't really need to bulk up .text with trampolines for all of them.
>> On the other hand, Iâm not sure the static_call interface is so intuitive.
>> And extending it into âdynamic_callâ might be even worse. As I initially
>> used an opt-in approach, I can tell you that it was very exhausting.
> Well, if it's done with a gcc plugin after all, then it wouldn't be too hard
> to make it opt-out.
> One advantage of the explicit opt-in dynamic_call, though, which can be seen
> in my patch is that multiple call sites can share the same learning-state,
> if they're expected to call the same set of functions. An opt-out approach
> would automatically give each indirect call statement its own individual BTB.
> Either way, I think the question is orthogonal to what the trampolines
> themselves look like (and even to the inline vs outline question).
Not entirely. If the mechanism is opt-out and outlined, and especially if it
also supports multiple targets, you may not want to allocate all the memory
for them during build-time, and instead use module memory to allocate them
dynamically (thatâs what we did).