public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 05/13] hrtimer: optimize hrtimer_run_queues
@ 2006-02-13  1:10 Roman Zippel
  2006-02-13 13:39 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Roman Zippel @ 2006-02-13  1:10 UTC (permalink / raw)
  To: Andrew Morton, tglx, linux-kernel


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]);
 }
 
 /*

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

* Re: [PATCH 05/13] hrtimer: optimize hrtimer_run_queues
  2006-02-13  1:10 [PATCH 05/13] hrtimer: optimize hrtimer_run_queues Roman Zippel
@ 2006-02-13 13:39 ` Ingo Molnar
  2006-02-13 15:57   ` Roman Zippel
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2006-02-13 13:39 UTC (permalink / raw)
  To: Roman Zippel; +Cc: Andrew Morton, tglx, linux-kernel


* 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

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

* Re: [PATCH 05/13] hrtimer: optimize hrtimer_run_queues
  2006-02-13 13:39 ` Ingo Molnar
@ 2006-02-13 15:57   ` Roman Zippel
  2006-02-13 19:50     ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Roman Zippel @ 2006-02-13 15:57 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, tglx, linux-kernel

Hi,

On Mon, 13 Feb 2006, Ingo Molnar wrote:

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

I could also call this perfomance regressions to 2.6.15, unless there is 
a good reason not to include them, I'd prefer to see it in 2.6.16.

bye, Roman

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

* Re: [PATCH 05/13] hrtimer: optimize hrtimer_run_queues
  2006-02-13 15:57   ` Roman Zippel
@ 2006-02-13 19:50     ` Ingo Molnar
  2006-02-13 21:45       ` Roman Zippel
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2006-02-13 19:50 UTC (permalink / raw)
  To: Roman Zippel; +Cc: Andrew Morton, tglx, linux-kernel


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

> > 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.
> 
> I could also call this perfomance regressions to 2.6.15, unless there 
> is a good reason not to include them, I'd prefer to see it in 2.6.16.

can you measure it? This is tricky code, we definitely dont want to 
change it this late in the v2.6.16 cycles, execpt if it's some 
measurable performance issue that users will see. (or if it's some 
regression, which it isnt.)

	Ingo

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

* Re: [PATCH 05/13] hrtimer: optimize hrtimer_run_queues
  2006-02-13 19:50     ` Ingo Molnar
@ 2006-02-13 21:45       ` Roman Zippel
  0 siblings, 0 replies; 5+ messages in thread
From: Roman Zippel @ 2006-02-13 21:45 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, tglx, linux-kernel

Hi,

On Mon, 13 Feb 2006, Ingo Molnar wrote:

> > I could also call this perfomance regressions to 2.6.15, unless there 
> > is a good reason not to include them, I'd prefer to see it in 2.6.16.
> 
> can you measure it? This is tricky code, we definitely dont want to 
> change it this late in the v2.6.16 cycles, execpt if it's some 
> measurable performance issue that users will see. (or if it's some 
> regression, which it isnt.)

Why is not a regression?
I'm busy enough with m68k as is just to catch up and you're not making it 
easier. Such repetitive task have a tendency to show up pretty high when I 
occasionally run an profile test run, e.g. a much simpler vertical blank 
interrupt at 50Hz is noticable. The new hrtimer code is much heavier and 
runs twice as much.

bye, Roman

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

end of thread, other threads:[~2006-02-13 21:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-13  1:10 [PATCH 05/13] hrtimer: optimize hrtimer_run_queues Roman Zippel
2006-02-13 13:39 ` Ingo Molnar
2006-02-13 15:57   ` Roman Zippel
2006-02-13 19:50     ` Ingo Molnar
2006-02-13 21:45       ` Roman Zippel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox