linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] timer: Use static_branch_likely() for timers_nohz_active
@ 2021-05-13  6:33 Jisheng Zhang
  2021-06-22 15:19 ` Thomas Gleixner
  0 siblings, 1 reply; 4+ messages in thread
From: Jisheng Zhang @ 2021-05-13  6:33 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner, Stephen Boyd; +Cc: linux-kernel

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.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index d111adf4a0cb..40d4fe7fa207 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -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; }
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] timer: Use static_branch_likely() for timers_nohz_active
  2021-05-13  6:33 [PATCH] timer: Use static_branch_likely() for timers_nohz_active Jisheng Zhang
@ 2021-06-22 15:19 ` Thomas Gleixner
  2021-06-23  3:17   ` Jisheng Zhang
  2021-06-23 10:41   ` Jisheng Zhang
  0 siblings, 2 replies; 4+ messages in thread
From: Thomas Gleixner @ 2021-06-22 15:19 UTC (permalink / raw)
  To: Jisheng Zhang, John Stultz, Stephen Boyd; +Cc: linux-kernel

On Thu, May 13 2021 at 14:33, Jisheng Zhang wrote:
> 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?

> reflect this fact. This could improve the finally generated code

could improve? Either it does or it does not.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] timer: Use static_branch_likely() for timers_nohz_active
  2021-06-22 15:19 ` Thomas Gleixner
@ 2021-06-23  3:17   ` Jisheng Zhang
  2021-06-23 10:41   ` Jisheng Zhang
  1 sibling, 0 replies; 4+ messages in thread
From: Jisheng Zhang @ 2021-06-23  3:17 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: John Stultz, Stephen Boyd, linux-kernel

Hi Thomas,

On Tue, 22 Jun 2021 17:19:20 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:


> 
> On Thu, May 13 2021 at 14:33, Jisheng Zhang wrote:
> > 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.

> 
> > 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] timer: Use static_branch_likely() for timers_nohz_active
  2021-06-22 15:19 ` Thomas Gleixner
  2021-06-23  3:17   ` Jisheng Zhang
@ 2021-06-23 10:41   ` Jisheng Zhang
  1 sibling, 0 replies; 4+ messages in thread
From: Jisheng Zhang @ 2021-06-23 10:41 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: John Stultz, Stephen Boyd, linux-kernel

On Tue, 22 Jun 2021 17:19:20 +0200
Thomas Gleixner <tglx@linutronix.de> wrote:


> 
> 
> On Thu, May 13 2021 at 14:33, Jisheng Zhang wrote:
> > 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

> 
> > reflect this fact. This could improve the finally generated code  
> 
> could improve? Either it does or it does not.
> 
> Thanks,
> 
>         tglx


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-23 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13  6:33 [PATCH] timer: Use static_branch_likely() for timers_nohz_active Jisheng Zhang
2021-06-22 15:19 ` Thomas Gleixner
2021-06-23  3:17   ` Jisheng Zhang
2021-06-23 10:41   ` Jisheng Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).