powerpc/code-patching: Inline create_branch()
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Mon, 9 May 2022 05:36:03 +0000 (07:36 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 19 May 2022 13:11:28 +0000 (23:11 +1000)
create_branch() is a good candidate for inlining because:
- Flags can be folded in.
- Range tests are likely to be already done.

Hence reducing the create_branch() to only a set of instructions.

So inline it.

It improves ftrace activation by 10%.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/69851cc9a7bf8f03d025e6d29e165f2d0bd3bb6e.1652074503.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/code-patching.h
arch/powerpc/lib/code-patching.c

index 378b70545a32f4a0867c6152754a6050fcfbe3fb..947d4ae062f5828f5fe1736d3745bfc15a06fe8b 100644 (file)
@@ -51,8 +51,26 @@ static inline bool is_offset_in_cond_branch_range(long offset)
        return offset >= -0x8000 && offset <= 0x7fff && !(offset & 0x3);
 }
 
-int create_branch(ppc_inst_t *instr, const u32 *addr,
-                 unsigned long target, int flags);
+static inline int create_branch(ppc_inst_t *instr, const u32 *addr,
+                               unsigned long target, int flags)
+{
+       long offset;
+
+       *instr = ppc_inst(0);
+       offset = target;
+       if (! (flags & BRANCH_ABSOLUTE))
+               offset = offset - (unsigned long)addr;
+
+       /* Check we can represent the target in the instruction format */
+       if (!is_offset_in_branch_range(offset))
+               return 1;
+
+       /* Mask out the flags and target, so they don't step on each other. */
+       *instr = ppc_inst(0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC));
+
+       return 0;
+}
+
 int create_cond_branch(ppc_inst_t *instr, const u32 *addr,
                       unsigned long target, int flags);
 int patch_branch(u32 *addr, unsigned long target, int flags);
index 13a5a386d35b8e53ec6169fab957d58228a738fe..46ffce27135ed274c4680122279791de5a9ec87f 100644 (file)
@@ -236,26 +236,6 @@ bool is_conditional_branch(ppc_inst_t instr)
 }
 NOKPROBE_SYMBOL(is_conditional_branch);
 
-int create_branch(ppc_inst_t *instr, const u32 *addr,
-                 unsigned long target, int flags)
-{
-       long offset;
-
-       *instr = ppc_inst(0);
-       offset = target;
-       if (! (flags & BRANCH_ABSOLUTE))
-               offset = offset - (unsigned long)addr;
-
-       /* Check we can represent the target in the instruction format */
-       if (!is_offset_in_branch_range(offset))
-               return 1;
-
-       /* Mask out the flags and target, so they don't step on each other. */
-       *instr = ppc_inst(0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC));
-
-       return 0;
-}
-
 int create_cond_branch(ppc_inst_t *instr, const u32 *addr,
                       unsigned long target, int flags)
 {