All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: Zhongqiu Han <quic_zhonhan@quicinc.com>
Cc: anna-maria@linutronix.de, tglx@linutronix.de,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] timers: Optimize get_timer_cpu_base() to reduce potentially redundant per_cpu_ptr() calls
Date: Tue, 31 Dec 2024 17:08:05 +0100	[thread overview]
Message-ID: <Z3QW5aT_6vyHu_cq@localhost.localdomain> (raw)
In-Reply-To: <20241231150115.1978342-1-quic_zhonhan@quicinc.com>

Le Tue, Dec 31, 2024 at 11:01:15PM +0800, Zhongqiu Han a écrit :
> If the timer is deferrable and NO_HZ_COMMON is enabled, the function
> get_timer_cpu_base() will call per_cpu_ptr() twice. Optimize the function
> to avoid potentially redundant per_cpu_ptr() calls.
> 
> One of the call paths of the get_timer_cpu_base() function is through the
> lock_timer_base() function, which contains a loop. Within this loop, the
> get_timer_base() func is called, and in turn, it calls the
> get_timer_cpu_base() function. And in such a path, get_timer_cpu_base is
> a hotspot function. It is called approximately 13,000 times in 12 seconds
> on test x86 KVM machines.
> 
> lock_timer_base(){
>     for(;;) {
>     ...
>     --> get_timer_base() [inline]
>         --> get_timer_cpu_base() [inline]
>     ...
>     }
> }
> 
> With the patch, assembly code(on x86 and ARM64) to be executed in loop is
> reduced. And conducting comparative tests on x86 KVM virtual machines,
> comparison of runtime before and after optimization (in nanoseconds), we
> can see that the distribution of runtime tends to favor smaller time
> intervals.
> 
>       Before                  After
> [0-19]:      0    	[0-19]:      0
> [20-39]:     6    	[20-39]:     1014
> [40-59]:     41   	[40-59]:     2198
> [60-79]:     93   	[60-79]:     2073
> [80-99]:     814  	[80-99]:     3081
> [100-119]:   5262 	[100-119]:   3268
> [120-139]:   4510 	[120-139]:   671
> [140-159]:   2202 	[140-159]:   468
> [160-179]:   81   	[160-179]:   158
> [180-199]:   15   	[180-199]:   160
> [200-219]:   3    	[200-219]:   54
> [220-239]:   2    	[220-239]:   7
> [240-259]:   2    	[240-259]:   3
> [260-279]:   0    	[260-279]:   0
> [280-299]:   0    	[280-299]:   1
> [300-319]:   0    	[300-319]:   0
> total:       13031      total:       13156
> 
> Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

  reply	other threads:[~2024-12-31 16:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-31 15:01 [PATCH] timers: Optimize get_timer_cpu_base() to reduce potentially redundant per_cpu_ptr() calls Zhongqiu Han
2024-12-31 16:08 ` Frederic Weisbecker [this message]
2025-01-15 21:12 ` Thomas Gleixner
2025-01-16  3:36   ` Zhongqiu Han
2025-01-16  8:08 ` [tip: timers/core] timers: Optimize get_timer_[this_]cpu_base() tip-bot2 for Zhongqiu Han

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z3QW5aT_6vyHu_cq@localhost.localdomain \
    --to=frederic@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_zhonhan@quicinc.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.