Skip to contentSkip to conversation

timer: Use static_branch_likely() for timers_nohz_active

PATCH Superseded Jisheng Zhang 2 participants 4 messages May 13, 2021 – Jun 23, 2021 High-resolution timers, timer wheel, clockevents

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timer: Use static_branch_likely() for timers_nohz_active

NOHZ is likely to be enabled, so use static_branch_likely() to reflect this fact. This could improve the finally generated code a bit for the most likely scenario, I.E save two "jmp" instructions.

---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/timer.c +1 -1
index d111adf4a0cb..40d4fe7fa207 100644
@@ -265,7 +265,7 @@ int timer_migration_handler(struct ctl_table *table, int write,
 
 static inline bool is_timers_nohz_active(void)
 {
-	return static_branch_unlikely(&timers_nohz_active);
+	return static_branch_likely(&timers_nohz_active);
 }
 #else
 static inline bool is_timers_nohz_active(void) { return false; }
Signature · 1 line
2.31.0
#1 lore raw
Quoted 1 line · Jisheng Zhang

NOHZ is likely to be enabled, so use static_branch_likely() to

Why is it likely to be enabled? Did you make a survey of the wider distro universe or what?

Quoted 1 line

reflect this fact. This could improve the finally generated code

could improve? Either it does or it does not.

Thanks,

tglx

#2 lore raw

Hi Thomas,

Quoted 6 lines · On Tue, 22 Jun 2021 17:19:20 +0200 Thomas Gleixner <[email protected]> wrote:
Quoted 1 line · Jisheng Zhang

NOHZ is likely to be enabled, so use static_branch_likely() to

Why is it likely to be enabled? Did you make a survey of the wider distro universe or what?

No, I didn't make any survey. I only checked debian and ubuntu kernel image config file, both have CONFIG_NO_HZ_COMMON=y
So IMHO, if CONFIG_NO_HZ_COMMON=y, the static key timers_nohz_active is true in most cases.

Quoted 4 lines
Quoted 2 lines

reflect this fact. This could improve the finally generated code

could improve? Either it does or it does not.

Per include/linux/jump_label.h, if the timers_nohz_active is true, it can save two jmp instructions.

* type\branch| likely (1) | unlikely (0)
* -----------+-----------------------+------------------

 *            |                       |
 *  true (1)  |    ...                |    ...
 *            |    NOP                |    JMP L
 *            |    <br-stmts>         | 1: ...
 *            | L: ...                |
 *            |                       |
 *            |                       | L: <br-stmts>
 *            |                       |    jmp 1b

Thanks

#3 lore raw
In reply to Thomas Gleixner
Quoted 7 lines · On Tue, 22 Jun 2021 17:19:20 +0200 Thomas Gleixner <[email protected]> wrote:
Quoted 1 line · Jisheng Zhang

NOHZ is likely to be enabled, so use static_branch_likely() to

Why is it likely to be enabled? Did you make a survey of the wider distro universe or what?

One more thought: maybe NOHZ is confusing, what I mean here is:
timers_nohz_active is likely to be true.

If I update the commit msg as the following, is it acceptable?

"timers_nohz_active is likely to be true, so use static_branch_likely() to reflect this fact. This could improve the finally generated code a bit for the most likely scenario, I.E save two "jmp" instructions."

Thanks

Quoted 8 lines
Quoted 2 lines

reflect this fact. This could improve the finally generated code

could improve? Either it does or it does not.

Thanks,

tglx