public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
	Roman Zippel <zippel@linux-m68k.org>
Subject: [patch 1/8] hrtimer optimize softirq runqueues
Date: Sun, 12 Mar 2006 10:37:13 -0000	[thread overview]
Message-ID: <20060312080331.390704000@localhost.localdomain> (raw)
In-Reply-To: 20060312080316.826824000@localhost.localdomain

[-- Attachment #1: hrtimer-optimize-run-queues.patch --]
[-- Type: text/plain, Size: 4066 bytes --]


The hrtimer softirq is called from the timer softirq every tick. 
Retrieve the current time from xtime and wall_to_monotonic instead of
calling base->get_time() for each timer base. Store the time in the
base structure and provide a hook once clock source abstractions are in 
place and to keep the code open for new base clocks.

Based on a patch from: Roman Zippel <zippel@linux-m68k.org>

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

 include/linux/hrtimer.h |   20 ++++++++++++--------
 kernel/hrtimer.c        |   28 ++++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 10 deletions(-)

Index: linux-2.6.16-updates/kernel/hrtimer.c
===================================================================
--- linux-2.6.16-updates.orig/kernel/hrtimer.c
+++ linux-2.6.16-updates/kernel/hrtimer.c
@@ -123,6 +123,26 @@ void ktime_get_ts(struct timespec *ts)
 EXPORT_SYMBOL_GPL(ktime_get_ts);
 
 /*
+ * Get the coarse grained time at the softirq based on xtime and
+ * wall_to_monotonic.
+ */
+static void hrtimer_get_softirq_time(struct hrtimer_base *base)
+{
+	ktime_t xtim, tomono;
+	unsigned long seq;
+
+	do {
+		seq = read_seqbegin(&xtime_lock);
+		xtim = timespec_to_ktime(xtime);
+		tomono = timespec_to_ktime(wall_to_monotonic);
+
+	} while (read_seqretry(&xtime_lock, seq));
+
+	base[CLOCK_REALTIME].softirq_time = xtim;
+	base[CLOCK_MONOTONIC].softirq_time = ktime_add(xtim, tomono);
+}
+
+/*
  * Functions and macros which are different for UP/SMP systems are kept in a
  * single place
  */
@@ -586,9 +606,11 @@ int hrtimer_get_res(const clockid_t whic
  */
 static inline void run_hrtimer_queue(struct hrtimer_base *base)
 {
-	ktime_t now = base->get_time();
 	struct rb_node *node;
 
+	if (base->get_softirq_time)
+		base->softirq_time = base->get_softirq_time();
+
 	spin_lock_irq(&base->lock);
 
 	while ((node = base->first)) {
@@ -598,7 +620,7 @@ static inline void run_hrtimer_queue(str
 		void *data;
 
 		timer = rb_entry(node, struct hrtimer, node);
-		if (now.tv64 <= timer->expires.tv64)
+		if (base->softirq_time.tv64 <= timer->expires.tv64)
 			break;
 
 		fn = timer->function;
@@ -641,6 +663,8 @@ void hrtimer_run_queues(void)
 	struct hrtimer_base *base = __get_cpu_var(hrtimer_bases);
 	int i;
 
+	hrtimer_get_softirq_time(base);
+
 	for (i = 0; i < MAX_HRTIMER_BASES; i++)
 		run_hrtimer_queue(&base[i]);
 }
Index: linux-2.6.16-updates/include/linux/hrtimer.h
===================================================================
--- linux-2.6.16-updates.orig/include/linux/hrtimer.h
+++ linux-2.6.16-updates/include/linux/hrtimer.h
@@ -72,14 +72,16 @@ struct hrtimer {
 /**
  * struct hrtimer_base - the timer base for a specific clock
  *
- * @index:	clock type index for per_cpu support when moving a timer
- *		to a base on another cpu.
- * @lock:	lock protecting the base and associated timers
- * @active:	red black tree root node for the active timers
- * @first:	pointer to the timer node which expires first
- * @resolution:	the resolution of the clock, in nanoseconds
- * @get_time:	function to retrieve the current time of the clock
- * @curr_timer:	the timer which is executing a callback right now
+ * @index:		clock type index for per_cpu support when moving a timer
+ *			to a base on another cpu.
+ * @lock:		lock protecting the base and associated timers
+ * @active:		red black tree root node for the active timers
+ * @first:		pointer to the timer node which expires first
+ * @resolution:		the resolution of the clock, in nanoseconds
+ * @get_time:		function to retrieve the current time of the clock
+ * @get_sofirq_time:	function to retrieve the current time from the softirq
+ * @curr_timer:		the timer which is executing a callback right now
+ * @softirq_time:	the time when running the hrtimer queue in the softirq
  */
 struct hrtimer_base {
 	clockid_t		index;
@@ -88,7 +90,9 @@ struct hrtimer_base {
 	struct rb_node		*first;
 	ktime_t			resolution;
 	ktime_t			(*get_time)(void);
+	ktime_t			(*get_softirq_time)(void);
 	struct hrtimer		*curr_timer;
+	ktime_t			softirq_time;
 };
 
 /*

--


  reply	other threads:[~2006-03-12 10:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-12 10:37 [patch 0/8] hrtimer updates Thomas Gleixner
2006-03-12 10:37 ` Thomas Gleixner [this message]
2006-03-12 10:37 ` [patch 2/8] Pass current time to hrtimer_forward() Thomas Gleixner
2006-03-12 10:37 ` [patch 3/8] posix-timer cleanup common_timer_get() Thomas Gleixner
2006-03-12 10:37 ` [patch 4/8] hrtimer simplify nanosleep Thomas Gleixner
2006-03-12 10:37 ` [patch 5/8] hrtimer remove state field Thomas Gleixner
2006-03-12 12:13   ` Roman Zippel
2006-03-12 13:10     ` Thomas Gleixner
2006-03-12 13:26       ` Roman Zippel
2006-03-12 13:35         ` Thomas Gleixner
2006-03-12 13:55           ` Roman Zippel
2006-03-12 14:15             ` Thomas Gleixner
2006-03-12 14:30               ` Roman Zippel
2006-03-12 14:54                 ` Thomas Gleixner
2006-03-12 15:17                   ` Roman Zippel
2006-03-12 15:41                     ` Thomas Gleixner
2006-03-12 16:00                       ` Roman Zippel
2006-03-12 16:26                         ` Thomas Gleixner
2006-03-12 16:57                           ` [patch] hrtimer remove replace state check by BUG_ON Thomas Gleixner
2006-03-16  1:05                           ` [patch 5/8] hrtimer remove state field Roman Zippel
2006-03-16  9:01                             ` Thomas Gleixner
2006-03-17 22:07                               ` Roman Zippel
2006-03-18  8:46                                 ` Thomas Gleixner
2006-03-12 10:37 ` [patch 6/8] Remove it_real_value calculation from proc/*/stat Thomas Gleixner
2006-03-12 10:37 ` [patch 7/8] Remove DEFINE_KTIME and ktime_to_clock_t() Thomas Gleixner
2006-03-12 10:37 ` [patch 8/8] Remove nsec_t typedef Thomas Gleixner

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=20060312080331.390704000@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox