Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/code-patching: Inline create_branch()

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

authored by

Christophe Leroy and committed by
Michael Ellerman
d2f47dab a1facd25

+20 -22
+20 -2
arch/powerpc/include/asm/code-patching.h
··· 51 51 return offset >= -0x8000 && offset <= 0x7fff && !(offset & 0x3); 52 52 } 53 53 54 - int create_branch(ppc_inst_t *instr, const u32 *addr, 55 - unsigned long target, int flags); 54 + static inline int create_branch(ppc_inst_t *instr, const u32 *addr, 55 + unsigned long target, int flags) 56 + { 57 + long offset; 58 + 59 + *instr = ppc_inst(0); 60 + offset = target; 61 + if (! (flags & BRANCH_ABSOLUTE)) 62 + offset = offset - (unsigned long)addr; 63 + 64 + /* Check we can represent the target in the instruction format */ 65 + if (!is_offset_in_branch_range(offset)) 66 + return 1; 67 + 68 + /* Mask out the flags and target, so they don't step on each other. */ 69 + *instr = ppc_inst(0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC)); 70 + 71 + return 0; 72 + } 73 + 56 74 int create_cond_branch(ppc_inst_t *instr, const u32 *addr, 57 75 unsigned long target, int flags); 58 76 int patch_branch(u32 *addr, unsigned long target, int flags);
-20
arch/powerpc/lib/code-patching.c
··· 236 236 } 237 237 NOKPROBE_SYMBOL(is_conditional_branch); 238 238 239 - int create_branch(ppc_inst_t *instr, const u32 *addr, 240 - unsigned long target, int flags) 241 - { 242 - long offset; 243 - 244 - *instr = ppc_inst(0); 245 - offset = target; 246 - if (! (flags & BRANCH_ABSOLUTE)) 247 - offset = offset - (unsigned long)addr; 248 - 249 - /* Check we can represent the target in the instruction format */ 250 - if (!is_offset_in_branch_range(offset)) 251 - return 1; 252 - 253 - /* Mask out the flags and target, so they don't step on each other. */ 254 - *instr = ppc_inst(0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC)); 255 - 256 - return 0; 257 - } 258 - 259 239 int create_cond_branch(ppc_inst_t *instr, const u32 *addr, 260 240 unsigned long target, int flags) 261 241 {