public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolai Stange <nicstange@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>,
	linux-kernel@vger.kernel.org,
	Nicolai Stange <nicstange@gmail.com>
Subject: [RFC v3 2/3] kernel/time/clockevents: make setting of ->mult and ->mult_mono atomic
Date: Wed, 13 Jul 2016 15:00:16 +0200	[thread overview]
Message-ID: <20160713130017.8202-3-nicstange@gmail.com> (raw)
In-Reply-To: <20160713130017.8202-1-nicstange@gmail.com>

In order to avoid races between setting a struct clock_event_device's
->mult_mono in clockevents_update_freq() and yet to be implemented updates
triggered from the timekeeping core, the setting of ->mult and ->mult_mono
should be made atomic.

Protect the update in clockevents_update_freq() by locking the
clockevents_lock spinlock. Frequency updates are expected to be done
seldomly and thus, taking this subsystem lock should not have any impact
on performance.

Use a raw_spin_lock_irq_save()/raw_spin_unlock_irq_restore() pair for
locking/unlocking the clockevents_lock spinlock.
Purge the now redundant local_irq_save()/local_irq_restore() pair from
clockevents_update_freq(). Since the call to tick_broadcast_update_freq()
isn't done with interrupts disabled anymore,  its
raw_spin_lock()/raw_spin_unlock() pair must be converted to
raw_spin_lock_irq_save()/raw_spin_unlock_irq_restore().

Signed-off-by: Nicolai Stange <nicstange@gmail.com>
---
 kernel/time/clockevents.c    | 7 ++++---
 kernel/time/tick-broadcast.c | 5 +++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index ba7fea4..ec01375 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -589,11 +589,12 @@ int clockevents_update_freq(struct clock_event_device *dev, u32 freq)
 	unsigned long flags;
 	int ret;
 
-	local_irq_save(flags);
 	ret = tick_broadcast_update_freq(dev, freq);
-	if (ret == -ENODEV)
+	if (ret == -ENODEV) {
+		raw_spin_lock_irqsave(&clockevents_lock, flags);
 		ret = __clockevents_update_freq(dev, freq);
-	local_irq_restore(flags);
+		raw_spin_unlock_irqrestore(&clockevents_lock, flags);
+	}
 	return ret;
 }
 
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
index f6aae79..9c94c41 100644
--- a/kernel/time/tick-broadcast.c
+++ b/kernel/time/tick-broadcast.c
@@ -125,11 +125,12 @@ int tick_is_broadcast_device(struct clock_event_device *dev)
 int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq)
 {
 	int ret = -ENODEV;
+	unsigned long flags;
 
 	if (tick_is_broadcast_device(dev)) {
-		raw_spin_lock(&tick_broadcast_lock);
+		raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 		ret = __clockevents_update_freq(dev, freq);
-		raw_spin_unlock(&tick_broadcast_lock);
+		raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 	}
 	return ret;
 }
-- 
2.9.0

  parent reply	other threads:[~2016-07-13 13:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-13 13:00 [RFC v3 0/3] adapt clockevents frequencies to mono clock Nicolai Stange
2016-07-13 13:00 ` [RFC v3 1/3] kernel/time/clockevents: initial support for mono to raw time conversion Nicolai Stange
2016-07-21 18:08   ` John Stultz
2016-07-21 19:11     ` Nicolai Stange
2016-07-13 13:00 ` Nicolai Stange [this message]
2016-07-21 18:16   ` [RFC v3 2/3] kernel/time/clockevents: make setting of ->mult and ->mult_mono atomic John Stultz
2016-07-21 19:24     ` Nicolai Stange
2016-07-21 19:31       ` John Stultz
2016-07-13 13:00 ` [RFC v3 3/3] kernel/time/timekeeping: inform clockevents about freq adjustments Nicolai Stange

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=20160713130017.8202-3-nicstange@gmail.com \
    --to=nicstange@gmail.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox