powerpc/code-patching: Use jump_label to check if poking_init() is done
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 22 Mar 2022 15:40:21 +0000 (16:40 +0100)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 11 May 2022 13:06:39 +0000 (23:06 +1000)
It's only during early startup that poking_init() is not done yet,
for instance when calling ftrace_init().

Once poking_init() has been called there must be a poking area, no
need to check it everytime patch_instruction() is called.

ftrace activation time is reduced by 7% with the change on an 8xx.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/8d6088aca7b63247377b6d9e4897d08d935fbe93.1647962456.git.christophe.leroy@csgroup.eu
arch/powerpc/lib/code-patching.c

index 1ecd166091c9bd87988d5638c0a1ae9cb1bebcf2..be670e1abafaae8aaed3f9ef3c0e257091f57d20 100644 (file)
@@ -79,6 +79,8 @@ static int text_area_cpu_down(unsigned int cpu)
        return 0;
 }
 
+static __ro_after_init DEFINE_STATIC_KEY_FALSE(poking_init_done);
+
 /*
  * Although BUG_ON() is rude, in this case it should only happen if ENOMEM, and
  * we judge it as being preferable to a kernel that will crash later when
@@ -89,6 +91,7 @@ void __init poking_init(void)
        BUG_ON(!cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
                "powerpc/text_poke:online", text_area_cpu_up,
                text_area_cpu_down));
+       static_branch_enable(&poking_init_done);
 }
 
 /*
@@ -171,7 +174,7 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
         * when text_poke_area is not ready, but we still need
         * to allow patching. We just do the plain old patching
         */
-       if (!this_cpu_read(text_poke_area))
+       if (!static_branch_likely(&poking_init_done))
                return raw_patch_instruction(addr, instr);
 
        local_irq_save(flags);