mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stanislav Fomichev <stfomichev@yandex-team.ru>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: viresh.kumar@linaro.org, paul.gortmaker@windriver.com,
	peterz@infradead.org, stuart.w.hayes@gmail.com,
	david.vrabel@citrix.com, linux-kernel@vger.kernel.org
Subject: [PATCH v2] hrtimers: add fast path to hrtimer_get_next_event
Date: Mon, 9 Jun 2014 16:59:31 +0400	[thread overview]
Message-ID: <20140609125931.GL26511@stfomichev-desktop.yandex.net> (raw)
In-Reply-To: <20140609111115.GK26511@stfomichev-desktop.yandex.net>

In hrtimer_get_next_event we unconditionally lock/unlock spinlock, even if it's
not required (hrtimer_hres_active() != 0). This patch adds fast path
when highres is active so we don't execute unnecessary operations.

We can safely do lockless check because:
- hrtimer_get_next_event is always called with interrupts disabled;
- we may switch to hres only from softirq handler with disabled interrupts.

Because we only care about hres_active which may be changed only from
local CPU, we can use interrupt context for synchronization.

run_timer_softirq
  hrtimer_run_pending
    hrtimer_switch_to_hres
      local_irq_save <-
      base->hres_active = 0

tick_nohz_idle_enter
  local_irq_disable <-
  __tick_nohz_idle_enter
    tick_nohz_stop_sched_tick
      get_next_timer_interrupt
        cmp_next_hrtimer_event
          hrtimer_get_next_event
          check base->hres_active

irq_exit <- irq context
  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_stop_tick
        tick_nohz_stop_sched_tick
            ... <see above>
      __tick_nohz_idle_enter
        ... <see above>

Signed-off-by: Stanislav Fomichev <stfomichev@yandex-team.ru>
---
 kernel/hrtimer.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index ba340739c701..731be91e927f 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -1167,23 +1167,24 @@ ktime_t hrtimer_get_next_event(void)
 	unsigned long flags;
 	int i;
 
+	if (hrtimer_hres_active())
+		return mindelta;
+
 	raw_spin_lock_irqsave(&cpu_base->lock, flags);
 
-	if (!hrtimer_hres_active()) {
-		for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
-			struct hrtimer *timer;
-			struct timerqueue_node *next;
+	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
+		struct hrtimer *timer;
+		struct timerqueue_node *next;
 
-			next = timerqueue_getnext(&base->active);
-			if (!next)
-				continue;
+		next = timerqueue_getnext(&base->active);
+		if (!next)
+			continue;
 
-			timer = container_of(next, struct hrtimer, node);
-			delta.tv64 = hrtimer_get_expires_tv64(timer);
-			delta = ktime_sub(delta, base->get_time());
-			if (delta.tv64 < mindelta.tv64)
-				mindelta.tv64 = delta.tv64;
-		}
+		timer = container_of(next, struct hrtimer, node);
+		delta.tv64 = hrtimer_get_expires_tv64(timer);
+		delta = ktime_sub(delta, base->get_time());
+		if (delta.tv64 < mindelta.tv64)
+			mindelta.tv64 = delta.tv64;
 	}
 
 	raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
-- 
1.8.3.2


  reply	other threads:[~2014-06-09 12:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09  9:23 [PATCH] hrtimers: conditionally lock/unlock spinlock in hrtimer_get_next_event Stanislav Fomichev
2014-06-09  9:27 ` Viresh Kumar
2014-06-09 11:06 ` Thomas Gleixner
2014-06-09 11:11   ` Stanislav Fomichev
2014-06-09 12:59     ` Stanislav Fomichev [this message]
2014-06-09 13:28       ` [PATCH v2] hrtimers: add fast path to hrtimer_get_next_event Viresh Kumar
2014-06-10  7:42         ` Peter Zijlstra
2014-06-09 14:44       ` Thomas Gleixner
2014-06-10  9:46         ` [PATCH v3] " Stanislav Fomichev

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=20140609125931.GL26511@stfomichev-desktop.yandex.net \
    --to=stfomichev@yandex-team.ru \
    --cc=david.vrabel@citrix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=peterz@infradead.org \
    --cc=stuart.w.hayes@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.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

all inboxes | Powered by JetHome®