All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Roman Zippel <zippel@linux-m68k.org>
Cc: Andrew Morton <akpm@osdl.org>,
	tglx@linutronix.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 05/13] hrtimer: optimize hrtimer_run_queues
Date: Mon, 13 Feb 2006 14:39:44 +0100	[thread overview]
Message-ID: <20060213133944.GA12923@elte.hu> (raw)
In-Reply-To: <Pine.LNX.4.61.0602130210120.23827@scrub.home>


* Roman Zippel <zippel@linux-m68k.org> wrote:

> Every time hrtimer_run_queues() is called, get_time() is called twice, 
> which can be quite expensive, just reading xtime is much cheaper and 
> does the same job (at least for the current low resolution timer, for 
> high resolution timer we can something different later). Cache the 
> expiry time in last_expired, so run_hrtimer_queue() doesn't has to 
> calculate it (clock sources usually know when their expired).
> 
> Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
> 
> ---
> 
>  include/linux/hrtimer.h |    1 +
>  kernel/hrtimer.c        |   17 +++++++++++++----
>  2 files changed, 14 insertions(+), 4 deletions(-)
> 
> Index: linux-2.6-git/include/linux/hrtimer.h
> ===================================================================
> --- linux-2.6-git.orig/include/linux/hrtimer.h	2006-02-12 18:33:07.000000000 +0100
> +++ linux-2.6-git/include/linux/hrtimer.h	2006-02-12 18:33:21.000000000 +0100
> @@ -89,6 +89,7 @@ struct hrtimer_base {
>  	ktime_t			resolution;
>  	ktime_t			(*get_time)(void);
>  	struct hrtimer		*curr_timer;
> +	ktime_t			last_expired;
>  };
>  
>  /*
> Index: linux-2.6-git/kernel/hrtimer.c
> ===================================================================
> --- linux-2.6-git.orig/kernel/hrtimer.c	2006-02-12 18:33:16.000000000 +0100
> +++ linux-2.6-git/kernel/hrtimer.c	2006-02-12 18:33:21.000000000 +0100
> @@ -541,7 +541,7 @@ int hrtimer_get_res(clockid_t which_cloc
>   */
>  static inline void run_hrtimer_queue(struct hrtimer_base *base)
>  {
> -	ktime_t now = base->get_time();
> +	ktime_t now = base->last_expired;
>  	struct rb_node *node;
>  
>  	spin_lock_irq(&base->lock);
> @@ -594,10 +594,19 @@ static inline void run_hrtimer_queue(str
>  void hrtimer_run_queues(void)
>  {
>  	struct hrtimer_base *base = __get_cpu_var(hrtimer_bases);
> -	int i;
> +	ktime_t now, mono;
> +	int seq;
>  
> -	for (i = 0; i < MAX_HRTIMER_BASES; i++)
> -		run_hrtimer_queue(&base[i]);
> +	do {
> +		seq = read_seqbegin(&xtime_lock);
> +		now = timespec_to_ktime(xtime);
> +		mono = timespec_to_ktime(wall_to_monotonic);
> +	} while (read_seqretry(&xtime_lock, seq));
> +
> +	base[CLOCK_REALTIME].last_expired = now;
> +	run_hrtimer_queue(&base[CLOCK_REALTIME]);
> +	base[CLOCK_MONOTONIC].last_expired = ktime_add(now, mono);
> +	run_hrtimer_queue(&base[CLOCK_MONOTONIC]);

hm, we can do this - although the open-coded loop looks ugly. In any 
case, this is an optimization, and not necessary for v2.6.16. It is 
certainly ok for -mm.

Acked-by: Ingo Molnar <mingo@elte.hu>

	Ingo

  reply	other threads:[~2006-02-13 13:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-13  1:10 [PATCH 05/13] hrtimer: optimize hrtimer_run_queues Roman Zippel
2006-02-13 13:39 ` Ingo Molnar [this message]
2006-02-13 15:57   ` Roman Zippel
2006-02-13 19:50     ` Ingo Molnar
2006-02-13 21:45       ` Roman Zippel

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=20060213133944.GA12923@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=zippel@linux-m68k.org \
    /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.