This tree introduces static_call(), which is the idea of static_branch()
applied to indirect function calls. Remove a data load (indirection) by
modifying the text.

They give the flexibility of function pointers, but with better
performance. (This is especially important for cases where
retpolines would otherwise be used, as retpolines can be pretty
slow.)

API overview:

  DECLARE_STATIC_CALL(name, func);
  DEFINE_STATIC_CALL(name, func);
  DEFINE_STATIC_CALL_NULL(name, typename);

  static_call(name)(args...);
  static_call_cond(name)(args...);
  static_call_update(name, func);

x86 is supported via text patching, otherwise basic indirect calls are used,
with function pointers.

There's a second variant using inline code patching, inspired by jump-labels,
implemented on x86 as well.

The new APIs are utilized in the x86 perf code, a heavy user of function pointers,
where static calls speed up the PMU handler by 4.2% (!).

The generic implementation is not really excercised on other architectures,
outside of the trivial test_static_call_init() self-test.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
static_call: Fix return type of static_call_init

Functions that are passed to early_initcall should be of type
initcall_t, which expects a return type of int. This is not currently an
error but a patch in the Clang LTO series could change that in the
future.

Fixes: 9183c3f9ed71 ("static_call: Add inline static call infrastructure")
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Link: https://lore.kernel.org/lkml/20200903203053.3411268-17-samitolvanen@google.com/
2 files changed